I've a noisy signal, which is the sound of motor with a constant speed, so the sound "should" be periodic, I know that there is a way to use the autocorrelation function to get the period,I did it, but I can't figure out the period. Any idea how to do that bellow the signal and the result of the autocorrelation : the signal
the autocorrelation result :
Answer
Here's an attempt to do what you need in scilab.
The top plot shows some data that I synthesized. The second plot shows the auto-correlation of the raw data (zoomed in around the central peak of the auto-correlation). The red circles show the peaks found using this find_peaks
function.
The final plot shows the difference between all the peak locations. This will be an estimate of the period. Because you're not really guaranteed that the underlying period will be an integer number of samples, you should probably find the mean of these values.
In this case, the "true" period is 1/f0 = 11.191996
, and taking diffs = diff(peaks);
and then mean(diffs(10:173))
yields 11.195122
.
Code below.
N = 1000;
f0 = 0.0893495634;
phi = rand(1,1,'uniform')*2*%pi;
sigma = 0.5;
x = sin(2*%pi*[0:N-1]*f0 + phi) + sigma*rand(1,N,'normal');
XC = xcorr(x);
clf
subplot(311)
plot(x);
subplot(312)
plot(XC);
peaks=peak_detect(XC,0);
plot(peaks,XC(peaks),'ro')
a = get('current_axes');
a.data_bounds=[950 1050 -500 800];
subplot(313)
plot(diff(peaks));
No comments:
Post a Comment