How to find the signal frequency?

3 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2021-3-7
Either ignore the first output bin, or else subtract off the mean before further processing.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Analysis 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by