如何使矩阵中从一个点到另一个点的线性最佳拟合多次,以使一系列趋势下降? [英] How can I do a linear best fit from one point to another in a matrix multiple times in order to detrend a series?

查看:121
本文介绍了如何使矩阵中从一个点到另一个点的线性最佳拟合多次,以使一系列趋势下降?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这种类型的数据,我想进行插值,例如从一个最大值到一个最小值进行拟合,依此类推,因此我可以寻找叠加的高频:

For this type of data I want to do an interpolation like fit from one maxima to a minima and so on, so I can look for superimposed high frequencies:

我有一个值矩阵,例如:

I have a matrix of values such as:

a=[ 3 7 10 3 1 5 10 5  3 2 4 8 10 7 4 3 4 2 1 4 5 7 10 8 7 6 6 4 3 2];

现在我要选择相对值,最大值和最小值以使

Now I want to choose the relative and maximum and minimum values such that

a=[ 3 0 10 0 1 0 10 0  0 2 0 0 10 0 0 0 0 0 1 0 0 0 10 0 0 0 0 0 0 2];

我本质上是想拟合从a(1)a(3)的直线,然后从a(3)a(5)的直线,依此类推,然后从数据中减去拟合值.

I essentially want to fit a straight line from a(1) to a(3) and then from a(3) to a(5) and so on, and then subtract the fit from the data.

我知道有一个函数"detrend"使用一个断点方法,它表示为"bp",这是我发现的最接近目标的东西.

I know there is a function "detrend" that uses a breakpoint method it denotes as "bp", and that is the closest thing I found resembling my goal.

如果您知道MATLAB可以做到的方式,我将不胜感激,否则看来我必须编写一个m文件来做到这一点.

If you know of a way MATLAB can do this I will greatly appreciate it, otherwise it seems like I have to write an m-file to do it.

推荐答案

我认为您的问题是在局部最小值局部最大值之间进行插值时间序列(您称为相对最小值和最大值".)

I think what your question is asking for is interpolation between the local minima and local maxima of a time series (what you call the "relative minimum and maximum values".)

参见此类似问题,并添加一些内容在局部最小值和最大值之间进行线性插值的代码.

See this similar question and add some code that does a linear interpolation between the local minima and maxima.

interp1()将方便地执行此操作.不需要输入点或输出点均匀分布.

interp1() will do this handily. There is no need for the input points or the output points to be evenly spaced.

>> x = sort(rand(1,10));
>> y = rand(1,10);
>> plot (x,y,'r.');
>> xx = 0:0.01:1;
>> yy = interp1(x,y,xx);
>> hold on;
>> plot (xx,yy,'b-')

我想您确实要做的是根据本地时间标度将信号分解为分量. (即频率随时间变化的位置).使用经验模式分解.小波方法可能是一种替代方法,但是EMD的输出很容易从视觉上解释.

What I think you really want to do is decompose the signal into components based on local time scale. (that is, where the frequencies change with time). Use the empirical mode decomposition. Wavelet methods might be an alternative, but the output of the EMD is very easy to interpret visually.

顺便说一句,如果将纯FFT应用于随时间变化的信号的整个长度,则FFT将不起作用-FFT假定信号是固定的(不变).

Incidentally, the plain FFT won't work if applied to the entire length of a signal that is time varying - the FFT assumes a stationary (non-varying) signal.

您需要应用短时傅立叶变换,即对数据的滑动窗口应用的FFT,以获取随时间变化的频率图像.请参见spectrogram()函数.

You need to apply the Short-Time Fourier Transform, which is the FFT applied over sliding windows of the data to get a picture of frequency over time. See the spectrogram() function.

>> plot (x,y)
>> x=0:0.001:1;
>> y = chirp(x);
>> plot (x,y);
>> figure;
>> spectrogram(y);

当您的采样率低于数据频率时,短时傅立叶变换的时间与频率分辨率存在问题,从而限制了它的应用.您发布图片的示例数据不太可能很好地工作.

There are issues with time vs. frequency resolution of the short-time Fourier transform that limit its application when your sampling rate is low compared to the frequency of the data. It would would be unlikely to work well for the example data you posted a picture of.

这篇关于如何使矩阵中从一个点到另一个点的线性最佳拟合多次,以使一系列趋势下降?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆