问题
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