I want to find the peak values of the out put signal.
1 回表示 (過去 30 日間)
古いコメントを表示
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
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.
回答 (1 件)
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!