Source code 1:
clc;
clear all;
close all;
t=-5:.01:5;
x=[zeros(1,300) ones(1,401) zeros(1,300)]; % Generate the input signal – square wave
figure;
plot(t,x);
axis([-5 5 0 2]);
xlabel('time');
ylabel('amplitude');
title('continuous time signal');
k=0;
for f=-5:.01:5
k=k+1;
X(k)=trapz(t,x.*exp(-j*2*pi*f*t)); % Fourier transform of x(t)
end
f=-5:.01:5;
figure;
plot(f,X);
xlabel('frequency');
ylabel('magnitude');
title('Frequency response');
Source code 2:
clc;
close all;
N=250;
ts=.0002;
t=[0:N-1]*ts;
x=cos(2*pi*100*t)+cos(2*pi*500*t); % Generate the input signal – signal consist of
two frequency components
figure;
plot(t,x)
xlabel('time');
ylabel('amplitude');
title('continuous time signal');
k=0;
for f=0:1:800
k=k+1;
X(k)=trapz(t,x.*exp(-j*2*pi*f*t)); % Fourier transform of x(t)
End
f=0:800;
figure;
plot(f,X);
xlabel('frequency');
ylabel('magnitude');
title('Frequency response');