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

조회 수: 1 (최근 30일)
rohail khan
rohail khan 2018년 4월 9일
답변: Birdman 2018년 4월 9일
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
Star Strider
Star Strider 2018년 4월 9일
‘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 2018년 4월 9일
편집: rohail khan 2018년 4월 9일
thanks Star, here is the code
[pks,locs] = findpeaks(fshift,abs(yshift));
and I get the following error message.

댓글을 달려면 로그인하십시오.

답변 (1개)

Birdman
Birdman 2018년 4월 9일
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.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by