Detecting fundamental frequency of a signal using Fast Fourier transform
19 views (last 30 days)
Show older comments

I found fft of a signal for half of the samples which can be seen in the above image. Now i need to find the frequency of the 1st harmonic in the signal. How can i find?? The code i used to find fft till now is attached below
[x,fs]=audioread(file); %read sound file to x, and sampling frequency to fs
Ns = length(x); % get length of the signal sequence
t = (1/fs)*(1:Ns); % get the duration of the signal knowing the sampling period 1/fs and the number of %sample points
Xk = abs(fft(x)); % do the fourier transform and take only the amplitude using abs()
Xk = Xk(1:Ns/2); % take only the first half of the transform due to the symmetry about the center
f = fs*(0:Ns/2-1)/Ns; % generate the vector of frequencies knowing the sampling frequency and reaching fs/2
% plot the waveform of the signal
figure('color','white')
plot(t, x,'color','blue')
xlabel('Time (s)')
ylabel('Amplitude')
%plot the Fourier transform of the signal
figure('color','white')
plot(f, Xk/max(Xk))
xlim([0 4000])
xlabel('Frequency (Hz)')
ylabel('Amplitude')
The fundamental frequency of this signal is 440 Hz. But i'm not getting this value. How can i solve this to get fundamental frequency ??
2 Comments
Image Analyst
on 11 Nov 2018
You forgot to attach your signal, or your code. Also, do you have reference sound files for the notes you want to identify? If so, attach those too. Otherwise at least say what frequency each note should be at.
Raja Fawad afsar
on 4 Feb 2025
Hopefully this video will be helpfull for you. https://www.youtube.com/watch?v=KT7C8ZPjkW0
Answers (1)
Star Strider
on 11 Nov 2018
You have not actually described the problem you are having.
If your audio signal consists of different notes, the spectrogram (link) function may help you visualise your signal and its components, since it produces a time-frequency analysis. The outputs it produces can also help you analyse your signal.
1 Comment
Star Strider
on 12 Nov 2018
To find the peaks of your Fourier transformed data, use the Signal Processing Toolbox findpeaks (link) function. That will give you the peak amplitudes and their locations on your frequency axis.
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!