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

1 Ansicht (letzte 30 Tage)
Mike Pierie am 22 Aug. 2022
Kommentiert: Mike Pierie am 22 Aug. 2022
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
figure(1)
f = Fs*(0:(L/2))/L;
plot(f,P1)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
axis([0 300 ylim])
figure(2)
[pks, locs]=findpeaks(P1, 'MinPeakDistance',50, 'minpeakheight',0.01);
plot(P1(locs), pks, 'or')
MFFT=[pks, locs];
m = size(pks);
n = size(locs);
disp(m);
disp(n);
disp(MFFT);
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?
##### 2 KommentareKeine anzeigenKeine ausblenden
John D'Errico am 22 Aug. 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 am 22 Aug. 2022
Bearbeitet: Mike Pierie am 22 Aug. 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.

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Michael am 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);
##### 11 Kommentare9 ältere Kommentare anzeigen9 ältere Kommentare ausblenden
Michael am 22 Aug. 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 am 22 Aug. 2022
Many thanks again! Ill do as you said.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Discrete Fourier and Cosine Transforms finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by