It's right the next code

2 次查看(过去 30 天)
Julian Oviedo
Julian Oviedo 2016-11-15
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

回答(1 个)

David Goodmanson
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.

类别

Help CenterFile Exchange 中查找有关 Statistics and Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by