3

After calculating the Fourier transform of a signal, I would like to recover the fundamental frequency as well as the harmonics of the recorded sound to determine its timbre.

Here is my code :

[signal,fe] = audioread('Flute6.wav');
subplot(2,1,1);
plot(signal);

N = length(signal);
t=(0:N-1)/fe;
f = (0:N-1)/N *fe;
f(f>=fe/2)=f(f>=fe/2)-fe;
f=fftshift(f);
X = fft(signal)/N;
X=fftshift(X);
%*************************************************%
xlim([10000,11000])
title('tracer du signal de base en fonction du temps');  
subplot(2,1,2);
plot(f,abs(X));

xlim([-5000,5000]);
xlabel('frequence en hz');
ylabel('|signal(t)|');  
title('tracer de la transformée de fourier');

enter image description here

The first high peak, named Fo, is the fundamental frequency, the other peaks are the harmonics that appear at k*Fo k in {1,...,N} .

I want a method that returns the amplitude of the fundamental as well as its frequency, and all the amplitudes and frequencies of the other peaks.

How can I find the peaks in my signal, as well as their frequencies and amplitudes?

Moussa Sow
  • 31
  • 2
  • 1
    Welcome to Stack Overflow! Your question is slightly unclear, but it looks like [`findpeaks()`](https://mathworks.com/help/signal/ref/findpeaks.html) should do the trick for you. This finds the indices of peaks, which are directly related to the frequency in your case. Then use that index to find the amplitude from `X(index)`. – Adriaan Jan 08 '20 at 14:11
  • I tried find peaks like this test = fo:fo:3000 [points, location] = findpeaks(abs(X)); harmonic = mod(f(location),fo) == 0; But this gave me only one harmonic not all of them – Moussa Sow Jan 08 '20 at 14:24
  • Is your input music? Is it monophonic or polyphonic? – Jon Nordby Jan 08 '20 at 19:45
  • Bienvenue sur Stackoverflow! Take a look at my answer to https://stackoverflow.com/questions/54714169/why-are-frequency-values-rounded-in-signal-using-fft/54775867#54775867 : it makes use of windowing to limit effects of spectral leakage and makes use of scipy's find_peaks(). Another option is to use autocorelation: see my recent answer to https://stackoverflow.com/questions/59604595/how-to-extract-features-from-fft/59637162#59637162 – francis Jan 08 '20 at 20:51
  • The input music is polyphonic – Moussa Sow Jan 09 '20 at 13:21

0 Answers0