根据MATLAB中的信号数据确定频率 [英] Determine frequency from signal data in MATLAB

查看:1766
本文介绍了根据MATLAB中的信号数据确定频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自传感器的数据,我需要找到它的频率.看来fft()似乎是可行的方法,但是MATLAB文档仅显示如何获取频率图,我不知道该怎么做.

I have data from a sensor and I need to find the frequency of it. It looks like fft() seems to be the way to go, but the MATLAB docs only show how to get a graph of the frequencies, I don't know what to do from there.

这是我的数据:

推荐答案

一种可行的方法确实是使用fft.由于fft为您提供信号的频率表示,因此您要寻找最大值,并且由于fft是复数信号,因此您将需要首先获取绝对值.该指数将对应于具有最大能量的归一化频率.最后,如果您的信号具有偏移(如您所显示的那样),则您希望在进行fft之前消除该偏移,以免在代表DC分量的原点处获得最大值.

One way to go is indeed to use an fft. Since the fft gives you the frequency representation of the signal, you want to look for the maximum, and since the fft is a complex signal, you will want to take the absolute value first. The index will correspond to the normalized frequency with maximum energy. Last, if your signal has an offset, as is the case with the one you show, you want to get rid of that offset before taking the fft so that you do not get a max at the origin representing the DC component.

我描述的所有内容都将是:

Everything I described put in one line would be:

[maxValue,indexMax] = max(abs(fft(signal-mean(signal))));

其中indexMax是可以找到最大fft值的索引.

where indexMax is the index where the max fft value can be found.

注意:要从indexMax到感兴趣的实际频率,您将需要知道fft的长度L(与信号的长度相同)以及采样频率Fs.信号频率将为:

Note: to get from indexMax to the actual frequency of interest, you will need to know the length L of the fft (same as the length of your signal), and the sampling frequency Fs. The signal frequency will then be:

frequency = indexMax * Fs / L;

或者,根据您所拥有的信号,更快,也相当不错地工作,对信号进行自相关:

Alternatively, faster and working fairly well too depending on the signal you have, take the autocorrelation of your signal:

autocorrelation = xcorr(signal);

并找到在自相关中心点之后出现的第一个最大值. (自相关将在中间具有最大值的对称关系.)通过找到最大值,可以找到移位信号看上去或多或少与自身相似的第一个位置. IE.您会找到信号周期.由于信号以其周期的倍数移动总是看起来像自己,因此您需要确保找到的最大值确实与信号的周期相对应,而不是其倍数之一.

and find the first maximum occurring after the center point of the autocorrelation. (The autocorrelation will be symmetric with its maximum in the middle.) By finding that maximum, you find the first place where the shifted signal looks more or less like itself. I.e. you find the period of your signal. Since the signal shifted by a multiple of its period will always look like itself, you need to make sure that the maximum you find indeed corresponds to the period of the signal and not one of its multiples.

由于信号中的噪声,绝对最大值很可能发生在周期的倍数而不是周期本身.因此,要考虑该噪声,您将获取自相关的绝对最大值(autocorrelation(length(autocorrelation)/2 + 1),然后查找自相关大于第一个最大值的95%的位置在信号后半部分的时间是95%,99%还是其他一些数字,取决于多少噪声会破坏您的信号.

Because of the noise in your signal, the absolute maximum could very well occur at a multiple of your period instead of the period itself. So to account for that noise, you would take the absolute max of the autocorrelation (autocorrelation(length(autocorrelation)/2+1), and then find where the autocorrelation is larger than, say, 95% of that maximum value for the first time in the second half of the signal. 95%, 99%, or some other number would depend on how much noise corrupts your signal.

更新:我意识到我假设您是指信号的频率"是指音调或基频谐波或​​能量最大的频率,但是您要查看它.如果用频率表示信号的频率表示,那么近似地,您只想绘制FFT的绝对值即可了解能量在哪里:

UPDATE: I realize that I assumed you meant by "frequency" of your signal the pitch or base harmonic or frequency with the most energy, however you want to look at it. If by frequency you meant the frequency representation of your signal, then to a first approximation, you just want to plot the abs of the FFT to get an idea of where the energy is:

plot(abs(fft));

如果您想通过不代表fft的相位来了解为什么存在abs或丢失了哪些相关信息,则可能需要阅读更多有关DFT变换的信息,以准确地了解所得到的.

If you want to understand why there is an abs, or what relevant info you are losing by not representing the phase of the fft, you may want to read a bit more about the DFT transform to understand exactly what you get.

这篇关于根据MATLAB中的信号数据确定频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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