I need help with Matlab - FFT - getting pairs of peaks-freq in array - urgently need help
1 view (last 30 days)
I need help with Matlab - FFT of electrical signal in order to get pairs of peaks-freq in array.
After that store those data into file which will be used afterwards to analyze new signal in the way of comparing amplitude of peaks harmonics.
That is small experiment in order to support master thesis I am working on it.
Optionaly I am ready to pay to someone who will support me in this.
here is starting code
Fs = 40000; % Sampling frequency 40kHz je dovoljno i za 40ti harmonik
T = 1/Fs; % Sampling period
L = 80000; % Length of signal
t = (0:L-1)*T; % Time vector
X = 2.7*sin(2*pi*50*t) + 1.5*sin(2*pi*150*t) + 0.6*sin(2*pi*250*t);
Y = fft(X); % Compute the Fourier transform of the signal
P2 = abs(Y/L); % Compute the two-sided spectrum P2.
P1 = P2(1:L/2+1); % Then compute the single-sided spectrum P1 based on P2
P1(2:end-1) = 2*P1(2:end-1); % and the even-valued signal length L.
- If here anyone have explanation please provide to me
f = Fs*(0:(L/2))/L;
title('Single-Sided Amplitude Spectrum of X(t)')
axis([0 300 ylim])
[pks, locs]=findpeaks(P1, 'MinPeakDistance',50, 'minpeakheight',0.01);
plot(P1(locs), pks, 'or')
m = size(pks);
n = size(locs);
I added findpek function but output is like this:
2.7000 1.5000 0.6000 101.0000 301.0000 501.0000 - 1st 3 values coresponding to amplitudes and thats OK but last 3 values should show correct frequencies but thats not the case.
Do anyone have sugggestion or idea whats wrong in the implementation of findpeak function?
Many thanks in advance.
Michael on 22 Aug 2022
I think you need to specify the x locations (frequency in your case) in the findpeaks function, otherwise it just gives you the index number.
[pks, locs]=findpeaks(P1,f, 'MinPeakDistance',50, 'minpeakheight',0.01);