使用 python 进行 fft 缩放

问题描述 投票:0回答:1

我有一个给定的信号 ds,我想计算它的缩放 FFT。我的意思是我想要获得 FFT,但我希望频率轴在 [-1,1] 范围内。我的问题是我怎样才能做到这一点?

这是我的代码:

contour_fft = np.fft.fft(ds)
contour_fft = np.fft.fftshift(contour_fft)
magnitude = abs(contour_fft)
sample_rate = 1.0
N = len(ds)
freq = np.fft.fftfreq(N, sample_rate)
freq = np.fft.fftshift(freq)

# Plot the magnitude
plt.figure(figsize=(50, 5))
plt.plot(freq, magnitude)
plt.axhline(0, color='black', linestyle='--', linewidth=1, label='Zero Magnitude')
plt.xlabel('Frequency')
plt.ylabel('Contour FFT Magnitude')
plt.legend()
plt.title('Contour FFT Magnitude Plot')
plt.grid(True)
plt.show()

我尝试更改 freq=np.fft.fftfreq(N,sample_rate) 的采样率,它确实对 fft 进行了不同的缩放,但我不知道如何将其更改为 [-1,1 范围内].

python fft scaling
1个回答
0
投票

可以生成

N
这个范围内的随机数,
fftfreq
可以在
d
参数中得到一个标量

N = len(ds)
sample_rate = np.random.uniform(-1, 1, N).round(2)

# sample_rate = [ 0.81  0.06  0.34 -0.28 -0.35  0.96 -0.77  0.48  0.07 -0.09]
© www.soinside.com 2019 - 2024. All rights reserved.