How do i calculate the frequency of signal with low sampling rate
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I've got a sinusoidal signal with a low sampling rate:
x = 0:0.2*pi:6*pi;
y = sin(x) -0.25 + 0.5* rand(size(x));
Is the a fast and accurate way to determine the frequency of this signal? The only way I can think of is to make a fit, but with 4 parameters:
A*sin(B *x + C) + D
it is quite hard to make a good guess and therefore have a fast program. Are there other methods to determine the frequency, like e.g. pulse counting?
2 commentaires
Réponses (1)
Star Strider
le 26 Mai 2014
Plotting it, the sampling rate is significantly higher than the Nyquist frequency, so the FFT will be reasonably accurate:
x = 0:0.2*pi:6*pi;
t = x/(2*pi); % Time vector (added)
y = sin(x) -0.25 + 0.5* rand(size(x));
figure(1)
plot(x, y, '.-')
grid
fty = fft(y);
afty = abs(fty);
fvrs = [0:fix(size(fty,2)/2)]*0.2*pi; % Frequency rad/t
fvHz = [0:fix(size(fty,2)/2)]*0.1; % Frequency Hz
lenv = 1:size(fvHz,2);
figure(2)
plot(fvHz, afty(lenv))
grid
I display the fft here in cycles/time (assume Hz). Substitute the frequency vector ‘fvrs’ in the plot to see it in radians/time. The frequency is about 0.25 Hz.
It’s not difficult to do a nonlinear regression using fminsearch or any of the other nonlinear regression routines. You can express your function as an ‘anonymous function’ and use it to fit your data. The function name ‘fitsin’ is already a function handle, so you don’t have to use the initial ‘@’ when referring to it in your code or as an argument to the fitting function.
fitsin = @(b,x) b(1).*sin(b(2).*x + b(3)) + b(4);
Use the frequency data from the fft for your initial estimate for b(2), and define the others as 1, unless you already have an idea of their values.
2 commentaires
Star Strider
le 27 Mai 2014
I’ve fit periodic functions using regression functions similar to ‘fitsin’ with the various nonlinear solvers and fminsearch (with an OLS objective function). The advantage of starting with the FFT is that it gives you a reliable estimate of the predominant frequency as one of your initial parameter estimates. I’ve had nonlinear solvers fit harmonics instead, the reason I suggested the FFT.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!