How to extract a frequency from a signal

元气小坏坏 提交于 2019-12-11 11:38:12

问题


Is there a simple way to extract the main frequency/period from a signal (without resorting to the FFT)?

For my requirements, this can result in either a value for the main frequency (e.g. 3Hz) or a value representing the strength of a target frequency. For example, in the following 1-D signal the frequency is about 4Hz, assuming the sampling rate is 50ms.

How can this be extracted from the data programmatically?

10 2 1 2 8 10 8 2 1 1 8 10 7 1 1 2 7 10 5 1


回答1:


Use Auto Correlation !

%using Matlab

%convert sample rate to hertz

fs = 1/(50/1000) % result = 20hz

vector = [10 2 1 2 8 10 8 2 1 1 8 10 7 1 1 2 7 10 5 1];

R = xcorr(vector);

[pks,locs]=findpeaks(R);

%result in hertz

fs./(diff(locs))

ans =

3.3333    4.0000    3.3333    3.3333    4.0000    3.3333

max(fs./diff(locs))

ans =

4
  • Apply Autocorrelation on the signal, you can find a lot of source code in the web in defferent languages to do autocorrelation, a pseudo code:

    TotalSamples = length(signal)
    for z=1:TotalSamples
     sum = 0;
    
     for i=1:TotalSamples
    
               sum = sum + (signal(i)*signal(i + pos));
    
     end
    
     Xcorre(z) = Xcorre(z) + sum;
    end
    
  • Find all local peaks from result of autocorrelation

  • Compute the difference between local peaks locs[k+1] - locs[k]

  • Divide your frame rate by the difference between local peaks

  • The Frequency is the Maximum value



来源:https://stackoverflow.com/questions/18145936/how-to-extract-a-frequency-from-a-signal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!