How to know the frequency of the signal from fft
Afficher commentaires plus anciens
How do i know the frequency of the signal from fft ?
First graph is signal and second is fft of the same .

Piece of code for fft is here.
%%z is the signal
nfft=length(z); %Number of samples
FTSignal=2*fft(z)/nfft; %FFT of the signal y-axis
FTSignal=FTSignal(1:nfft/2); %FFT till for nyquist frequency
%take magniutde
AbsFFT=abs(FTSignal);
f=(0:(nfft/2)-1)*fs/nfft; %Frequency range x-axis
phase=angle(FTSignal); %Phase spectru
figure(4)
plot(f,AbsFFT);
title('FFT of signal')
xlabel('Frequency in Hz')
ylabel('Amplitude');
Any changes in the code or in my understanding of fft (or frequency ) ?
3 commentaires
dpb
le 13 Juin 2021
You've not defined the sampling frequency in the above code so we don't know the sample rate. Hence, we can't tell what Nyquist frequency should be.
Your code also doubles both the DC and Nyquist frequency components that are unique in the returned FFT and thus shouldn't be. This helps to mask any other frequency components irrespective of actual scalling to real frequency values by doubling the DC component.
The normal thing to do would be to remove the mean, first..
signal=signal-mean(signal);
then do the FFT.
I'd recommend to read the example in doc fft carefully to see the generation of frequency vector and scaling used there; the technique there is more straightforward in getting to the end result I think.
dpb
le 13 Juin 2021
Well, your plot is the right range, then, but we also don't know what numel(signal) is so we can't tell what the frequency resolution would be.
If you look at your signal, you have (barely) one cycle of a sine wave with a distended second half-cycle and just a tiny wiggle in it. There is little frequency content there to be found; rightfully you should have a time sample some 3-4X as long to have a long enough sample to see the frequency content over at least 3-4 cycles of the lowest frequency of interest.
If there is anything else in the weeds, try converting the output amplitude to dB or just turn the y axis to logarithmic (alto then zeros will disappear). On the linear scale, there simply isn't enough dynamic range to see anything except the rolloff near the DC component which what I'd expect the output to reflect given the input.
Réponses (0)
Catégories
En savoir plus sur Fourier Analysis and Filtering dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
