使用 Octave 估算数据周期的最快方法是什么?

发布于 2024-08-27 06:01:53 字数 443 浏览 13 评论 0原文

我有一组周期性的数据(但不是正弦曲线)。我在一个向量中有一组时间值,在第二个向量中有一组幅度。我想快速估算出函数的周期。有什么建议吗?

具体来说,这是我当前的代码。我想近似向量 x(:,2) 相对于向量 t 的周期。最终,我想对许多初始条件执行此操作,并计算每个条件的周期并绘制结果。

function xdot = f (x,t)
         xdot(1) =x(2);
         xdot(2) =-sin(x(1));
endfunction

x0=[1;1.75];     #eventually, I'd like to try lots of values for x0(2)
t = linspace (0, 50, 200);


x = lsode ("f", x0, t)

plot(x(:,1),x(:,2));

谢谢你!

约翰

I have a set of data that is periodic (but not sinusoidal). I have a set of time values in one vector and a set of amplitudes in a second vector. I'd like to quickly approximate the period of the function. Any suggestions?

Specifically, here's my current code. I'd like to approximate the period of the vector x(:,2) against the vector t. Ultimately, I'd like to do this for lots of initial conditions and calculate the period of each and plot the result.

function xdot = f (x,t)
         xdot(1) =x(2);
         xdot(2) =-sin(x(1));
endfunction

x0=[1;1.75];     #eventually, I'd like to try lots of values for x0(2)
t = linspace (0, 50, 200);


x = lsode ("f", x0, t)

plot(x(:,1),x(:,2));

Thank you!

John

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魔法少女 2024-09-03 06:01:53

看一下自相关函数。

来自 维基百科

自相关是
信号与的互相关
本身。非正式地,它是
观测值之间的相似性
时间间隔函数
他们之间。它是一个数学
寻找重复模式的工具,
例如周期性的存在
信号已被掩埋
噪音,或识别失踪的
信号的基频
由其谐波频率暗示。
常用于信号处理
用于分析函数或系列
值,例如时域信号。

Paul Bourke 描述了如何基于快速傅里叶变换有效计算自相关函数(链接 )。

Take a look at the auto correlation function.

From Wikipedia

Autocorrelation is the
cross-correlation of a signal with
itself. Informally, it is the
similarity between observations as a
function of the time separation
between them. It is a mathematical
tool for finding repeating patterns,
such as the presence of a periodic
signal which has been buried under
noise, or identifying the missing
fundamental frequency in a signal
implied by its harmonic frequencies.
It is often used in signal processing
for analyzing functions or series of
values, such as time domain signals.

Paul Bourke has a description of how to calculate the autocorrelation function effectively based on the fast fourier transform (link).

献世佛 2024-09-03 06:01:53

离散傅立叶变换可以给出周期性。较长的时间窗口可以提供更高的频率分辨率,因此我将您的 t 定义更改为 t = linspace(0, 500, 2000)
时域 http://img402.imageshack.us/img402/8775/timedomain.png< /a> (这里有一个绘图链接,它在托管站点)。
你可以这样做:

h = hann(length(x), 'periodic'); %# use a Hann window to reduce leakage
y = fft(x .* [h h]); %# window each time signal and calculate FFT
df = 1/t(end); %# if t is in seconds, df is in Hz
ym = abs(y(1:(length(y)/2), :)); %# we just want amplitude of 0..pi frequency components
semilogy(((1:length(ym))-1)*df, ym);

频域 http://img406.imageshack.us/img406/2696/ freqdomain.png 绘图链接。

查看图表,第一个峰值位于 0.06 Hz 左右,对应于 plot(t,x) 中看到的 16 秒周期。

但这在计算上并没有那么快。 FFT是N*log(N)运算。

The Discrete Fourier Transform can give you the periodicity. A longer time window gives you more frequency resolution so I changed your t definition to t = linspace(0, 500, 2000).
time domain http://img402.imageshack.us/img402/8775/timedomain.png (here's a link to the plot, it looks better on the hosting site).
You could do:

h = hann(length(x), 'periodic'); %# use a Hann window to reduce leakage
y = fft(x .* [h h]); %# window each time signal and calculate FFT
df = 1/t(end); %# if t is in seconds, df is in Hz
ym = abs(y(1:(length(y)/2), :)); %# we just want amplitude of 0..pi frequency components
semilogy(((1:length(ym))-1)*df, ym);

frequency domain http://img406.imageshack.us/img406/2696/freqdomain.png Plot link.

Looking at the graph, the first peak is at around 0.06 Hz, corresponding to the 16 second period seen in plot(t,x).

This isn't computationally that fast though. The FFT is N*log(N) operations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文