How to find the signal frequency?

2 views (last 30 days)
Miguel Minga
Miguel Minga on 7 Mar 2021
Commented: Walter Roberson on 7 Mar 2021
Hi all, how can I find the signal frequency?
I'm using this code:
Nsamps = 27377;
fsamp = 60; %Freq device freematics One+:50-60[Hz]
Tsamp = 1/fsamp;
t = (0:Nsamps-1)*Tsamp;
x = Altf; %input signal
% Plot time-domain signal
subplot(2,1,1);
plot(t, x);
ylabel('Amplitude'); xlabel('Time (secs)');
% axis tight;
title('Input signal');
% Choose FFT size and calculate spectrum
Nfft =1024; %1024
[Pxx,f] = pwelch(x,gausswin(Nfft),Nfft/2,Nfft,fsamp);
% Plot frequency spectrum
subplot(2,1,2);
plot(f,Pxx);
ylabel('PSD');
xlabel('Frequency (Hz)');
grid on;
% Get frequency estimate (spectral peak)
[~,loc] = max(Pxx);
FREQ_ESTIMATE = f(loc)
title(['Frequency estimate = ',num2str(FREQ_ESTIMATE),' Hz']);
When running the program I get a frequency of zero
  1 Comment
Walter Roberson
Walter Roberson on 7 Mar 2021
Either ignore the first output bin, or else subtract off the mean before further processing.

Sign in to comment.

Answers (0)

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!