- 41

- 0

Code:

Fs=1000; %Sampling rate (Hz)

T=1/Fs; %Sampling time interval

P=10; %Period of pulse

t=0:1/Fs:P/2; %Time axis

N=length(t);

x=rectpuls(t,P); %Pulse amplitude

n=pow2(nextpow2(N)); %Number of frequency components

Y=fft(x,n);

freq=Fs/2*linspace(0,1,n/2+1);

subplot(1,2,1)

plot(t,x)

subplot(1,2,2)

plot(freq, 2/N *abs((Y(1 : n/2+1))));

xlim([0 2])

Magnitude at the first frequency component should be 10, but is giving a result of 2. Why is this occurring?

Thanks