Fourier Ex

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

% FourierEx.

m
% Example - pulse 0 to 2 s size 10; zero 2 to 8
% period 8 s.
N=input('Input number of Terms: -N to +N, N= ')
sN=num2str(N);
k=(1:N);
ck=(10/4)*exp(-j*pi*k/4).*sinc(k/4);
fk=k/8;
freq=[0 fk]; ckk=[2.5 ck];

figure(1)
subplot(211)
stem(freq,abs(ckk))
xlabel('Frequency - Hz')
ylabel('|c_k| - Volts')
title('Amplitude Spectrum')

subplot(212)
stem(freq,angle(ckk))
xlabel('Frequency - Hz')
ylabel('\angle(c_k) - radians')
title('Phase Spectrum')

figure(2)
subplot(111)
clear x t
fs=N*(1/8)*10;
t=(0:1/fs:4*8);

% Set up DC term
x=2.5*ones(size(t));
%
% Add +k and -k terms for k=1 to N.
for kk=1:N;
x=x+ck(kk)*exp(j*2*pi*kk*t/8) + conj(ck(kk))*exp(-j*2*pi*kk*t/8);
end
xr=real(x);
plot(t,xr)
xlabel('Time - Seconds')
ylabel(['x_{' sN '}(t) - volts'])
title(['Reconstruction: k = - ' sN ' to + ' sN ])

You might also like