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

查看:134
本文介绍了从 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 的 abs 以了解能量的位置:

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));

如果您想了解为什么存在 abs,或者您因不表示 fft 的相位而丢失了哪些相关信息,您可能需要阅读更多有关 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天全站免登陆