如何使用FFT检测信号中存在的时间周期?

发布于 2025-01-19 09:15:57 字数 2127 浏览 2 评论 0原文

我正在尝试确定给定波形中存在的周期性。

This is my signal, which is a sinusoidal waveform:

t_week = np.linspace(1,480, 480)
t_weekend=np.linspace(1,192,192)
T=96 #Time Period
x_weekday = 10*np.sin(2*np.pi*t_week/T)+10
x_weekend = 2*np.sin(2*np.pi*t_weekend/T)+10
x_daily_weekly_sinu = np.concatenate((x_weekday, x_weekend)) 

#Creating the Signal
x_daily_weekly_long_sinu = np.concatenate((x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu))

#Visualization
plt.plot(x_daily_weekly_long_sinu)
plt.show()

enter image description here

In order to determine the two periods present, which are 96 & 672, I'm creating the FFT of the waveform as follows:

f, Pxx = signal.periodogram(x_daily_weekly_long_sinu, fs = 96, window='hanning', scaling='spectrum')

#Visualization
plt.figure(figsize = (10, 8))
plt.plot(f, Pxx)
plt.xlim(0, 10)
plt.yscale('log')
plt.xlabel('Frequency (cycles/day)')
plt.ylabel('Spectrum Amplitude')

The following is the plot of frequencies that I get.

任何人都可以告诉为什么它显示出如此多的频率,而不仅仅是两个不同的96& 672?

enter image description here

I then try to extract the top frequencies from the FFT:

for amp_arg in np.argsort(np.abs(Pxx))[::-1][1:6]:
    day = 1 / f[amp_arg]
    print(day)

But my output gives the following values as the top frequencies instead of 96 & 672:

1.0144927536231885
0.9859154929577465
1.1666666666666667
0.875
1.4

Why is this happening? Can anyone please help me to determine the correct periods?

It would be great if I just get a final list of values representing the exact set of periods only.

I'm trying to determine the periodicities present in a given waveform.

This is my signal, which is a sinusoidal waveform:

t_week = np.linspace(1,480, 480)
t_weekend=np.linspace(1,192,192)
T=96 #Time Period
x_weekday = 10*np.sin(2*np.pi*t_week/T)+10
x_weekend = 2*np.sin(2*np.pi*t_weekend/T)+10
x_daily_weekly_sinu = np.concatenate((x_weekday, x_weekend)) 

#Creating the Signal
x_daily_weekly_long_sinu = np.concatenate((x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu,x_daily_weekly_sinu))

#Visualization
plt.plot(x_daily_weekly_long_sinu)
plt.show()

enter image description here

In order to determine the two periods present, which are 96 & 672, I'm creating the FFT of the waveform as follows:

f, Pxx = signal.periodogram(x_daily_weekly_long_sinu, fs = 96, window='hanning', scaling='spectrum')

#Visualization
plt.figure(figsize = (10, 8))
plt.plot(f, Pxx)
plt.xlim(0, 10)
plt.yscale('log')
plt.xlabel('Frequency (cycles/day)')
plt.ylabel('Spectrum Amplitude')

The following is the plot of frequencies that I get.

Can anyone tell why is it showing so many frequencies instead of just two distinct frequencies of 96 & 672?

enter image description here

I then try to extract the top frequencies from the FFT:

for amp_arg in np.argsort(np.abs(Pxx))[::-1][1:6]:
    day = 1 / f[amp_arg]
    print(day)

But my output gives the following values as the top frequencies instead of 96 & 672:

1.0144927536231885
0.9859154929577465
1.1666666666666667
0.875
1.4

Why is this happening? Can anyone please help me to determine the correct periods?

It would be great if I just get a final list of values representing the exact set of periods only.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文