I need help with Matlab - FFT - getting pairs of peaks-freq in array - urgently need help

1 vue (au cours des 30 derniers jours)
Dear all,
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)')
xlabel('f (Hz)')
axis([0 300 ylim])
[pks, locs]=findpeaks(P1, 'MinPeakDistance',50, 'minpeakheight',0.01);
plot(P1(locs), pks, 'or')
MFFT=[pks, locs];
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.
  2 commentaires
John D'Errico
John D'Errico le 22 Août 2022
Answers is NOT a pay for support site. It is a purely volunteer forum. It is not even appropriate to advertise for help where you offer to pay for tht support, since that makes Answers into a for fee consulting service.
Mike Pierie
Mike Pierie le 22 Août 2022
Modifié(e) : Mike Pierie le 22 Août 2022
OK, Ive got it. Sorry for such kind of advertisement. I put the code if anyone willing to help will be really welcomed as it is pretty urgent now. I changed the subject.

Connectez-vous pour commenter.

Réponse acceptée

Michael le 22 Août 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);
  11 commentaires
Michael le 22 Août 2022
If you have other questions, it is best to post them separately. This helps others in the future sort out specific questions. You can always put a link in one question back you your last question. And yes, just accepting the answer is best.
Mike Pierie
Mike Pierie le 22 Août 2022
Many thanks again! Ill do as you said.

Connectez-vous pour commenter.

Plus de réponses (0)


Community Treasure Hunt

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

Start Hunting!

Translated by