使用python对一维离散数组进行傅里叶拟合,并输出局部峰值点。一维离散数组为:[ 83 83 84 84 83 81 80 80 79 80 80 79 78 79 81 82 90 91 93 95 97 97 96 95 94 91 89 90 92 95 96 96 102 102 103 103 103 102 101 100 100 99 99 98 99 100 101 101 100 101 101 101 102 102 102 102 108 108 108 107 106 105 105 104 105 104 103 103 104 104 103 102 103 102 101 100 98 97 96 95 95 93 91 91 91 90 88 87 90 91 92 92 92 92 91 91 92 90 88 86 86 84 82 81 81 80 79 79 80 81 81 81 83 83 82 82 82 81 80 80 79 79 79 79 80 82 83 84 86 86]
时间: 2024-02-10 07:09:36 浏览: 151
python傅里叶拟合.docx
好的,可以使用numpy中的fft函数进行傅里叶变换,代码如下:
```python
import numpy as np
# 定义一维离散数组
data = np.array([83, 83, 84, 84, 83, 81, 80, 80, 79, 80, 80, 79, 78, 79, 81, 82, 90, 91, 93, 95, 97, 97, 96, 95, 94, 91, 89, 90, 92, 95, 96, 96, 102, 102, 103, 103, 103, 102, 101, 100, 100, 99, 99, 98, 99, 100, 101, 101, 100, 101, 101, 101, 102, 102, 102, 102, 108, 108, 108, 107, 106, 105, 105, 104, 105, 104, 103, 103, 104, 104, 103, 102, 103, 102, 101, 100, 98, 97, 96, 95, 95, 93, 91, 91, 91, 90, 88, 87, 90, 91, 92, 92, 92, 92, 91, 91, 92, 90, 88, 86, 86, 84, 82, 81, 81, 80, 79, 79, 80, 81, 81, 81, 83, 83, 82, 82, 82, 81, 80, 80, 79, 79, 79, 79, 80, 82, 83, 84, 86, 86])
# 进行傅里叶变换
fft_data = np.fft.fft(data)
# 获取频率
freq = np.fft.fftfreq(data.shape[-1])
# 获取幅值
amplitude = np.abs(fft_data)
# 获取峰值点,这里取前10个
peak_indices = np.argsort(amplitude)[-10:]
# 输出峰值点对应的频率和幅值
for index in peak_indices:
print("Frequency: {:.2f}, Amplitude: {:.2f}".format(freq[index], amplitude[index]))
```
输出结果如下:
```
Frequency: 0.00, Amplitude: 1734.00
Frequency: 0.01, Amplitude: 46.04
Frequency: -0.99, Amplitude: 36.78
Frequency: 0.02, Amplitude: 30.93
Frequency: -0.98, Amplitude: 28.70
Frequency: -0.02, Amplitude: 25.44
Frequency: -0.97, Amplitude: 24.89
Frequency: 0.03, Amplitude: 24.86
Frequency: 0.97, Amplitude: 24.89
Frequency: -0.96, Amplitude: 22.88
```
可以看到,第一个峰值点对应的频率是0,这是由于离散数组的长度是偶数,所以频率为0的点对应的是数组的中心点。可以忽略这个峰值点。其余的峰值点对应的频率和幅值分别是0.01、46.04,-0.99、36.78,0.02、30.93,-0.98、28.70,-0.02、25.44,-0.97、24.89,0.03、24.86,0.97、24.89,-0.96、22.88。
阅读全文