Borrar filtros
Borrar filtros

I want to find the peak values of the out put signal.

2 visualizaciones (últimos 30 días)
rohail khan
rohail khan el 9 de Abr. de 2018
Respondida: Birdman el 9 de Abr. de 2018
I have generated a waveform ,added some noise to it and then used fft to recover the signal. The code is below
% Generate example time series
t = 0:1/1000:0.2-1/1000;
% Sampled at 1 ms for .2 sec. Make the sample nuber even.
% This works better for FFT
% 3 freqeuncies
w1 = 2*pi*60;
w2 = 2*pi*71;
w3 = 2*pi*89;
% 3 amplitudes
A1 = 1;
A2 = 1/2;
A3 = 1/3;
% generate the three sinusoides
f1 = A1*sin(w1*t);
f2 = A2*sin(w2*t);
f3 = A3*sin(w3*t);
f=f1+f2+f3;
Then, add noise to the amplitude of each sinusoid and shift its phase randomly. I will leave the variance of the noise to your decision. Plot the resulting sum of the three waves.
% 3 seperate frequency curve
plot(t,f1,t,f2,t,f3)
title ('3 seperate curves')
xlabel('sec')
hold off
% 3 combined frequency plot
plot(t,f)
title('Combined frequency plot')
xlabel('sec') % f is the combined wave
hold off
Use fft to find the frequencies, 60 Hz, 71Hz, and 89 Hz.
F = fft(f);
W = (0:length(F)-1)*1000/length(F);
% Complet the rest
len=length(t);
fshift=(-len/2:len/2-1)*(1000/len)
yshift=fftshift(F)
plot(fshift,abs(yshift)./100)
title('recovered')
xlabel('Hz')
ylabel('amplitude')
hold off
I get the waveform
I can see the peak values from the plot but I want to use findpeaks command to get them.Each time I try to use findpeaks, I get an error message. How can I find the peak values using findpeaks in this question
  2 comentarios
Star Strider
Star Strider el 9 de Abr. de 2018
‘Each time I try to use findpeaks, I get an error message.’
I do not see where in your code you have called findpeaks.
What is the error message? Please copy all the red text from your Command Window and paste it to a Comment here.
rohail khan
rohail khan el 9 de Abr. de 2018
Editada: rohail khan el 9 de Abr. de 2018
thanks Star, here is the code
[pks,locs] = findpeaks(fshift,abs(yshift));
and I get the following error message.

Iniciar sesión para comentar.

Respuestas (1)

Birdman
Birdman el 9 de Abr. de 2018
Your input order should be like:
[pks,locs] = findpeaks(abs(yshift),fshift)
if you check the documentation. With this, you perfectly get what you want, the peak values and their corresponding frequency values.

Community Treasure Hunt

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

Start Hunting!

Translated by