It's right the next code
1 回表示 (過去 30 日間)
古いコメントを表示
Hello I'm trying to grahp the frecuency spectrum of 3 diffente signal. What do you think about the next code? It's right that the first armonic of the last signal has a bigger amplitude than the signal?
if true
a=[1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 ];
b=[ 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1];
c=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1];
n=1:1:101;
n2=1:1:118;
f=0:1:50;
f2=0:1:59;
x=fft(a);
P2 = abs(x/(length(a)));
P1 = P2(1:(length(a))/2+1);
P1(2:end-1) = 2*P1(2:end-1);
x2=fft(b);
P4 = abs(x2/(length(b)));
P3 = P4(1:(length(b))/2+1);
P3(2:end-1) = 2*P3(2:end-1);
x3=fft(c);
P6 = abs(x3/(length(c)));
P5 = P6(1:(length(c))/2+1);
P5(2:end-1) = 2*P5(2:end-1);
subplot(6,1,1)
plot(n,a);
subplot(6,1,2)
plot(f,P1);
subplot(6,1,3)
plot(n2, b);
subplot(6,1,4)
plot(f2,P3);
subplot(6,1,5)
plot(n2,c)
subplot(6,1,6)
plot(f2,abs(P5));
end
0 件のコメント
回答 (1 件)
David Goodmanson
2016 年 11 月 16 日
編集済み: David Goodmanson
2016 年 11 月 16 日
Hi Julian,
Good plots. Taking the fft of the square wave in c as an example, abs(amplitude) of the first harmonic should be close to 2/pi as you are getting. For the first harmonic, if you combine the positive and negative frequency fft components to get a sine wave, abs(amplitude) of that sine wave is close to 4/pi. So yes, the amplitude is larger than the height of the square wave.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Statistics and Linear Algebra についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!