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

%Objective: To compute the Fourier Transform of a continuous non-periodic signal (rectangular pulse).

T1 = 1.0; % time duration of the pulse being 1

% time duration for which signal is being generated


NumberOfSampesPerT1 =3;
t = -1.0*T1:T1/NumberOfSampesPerT1:1.0*T1;

% generating the rectangular pulse x(t)


x(t >= -T1) = 1.0;
x(t >= T1) = 0.0;

% parameters for approximated numerical integration to compute Fourier Transform


dt = T1/NumberOfSampesPerT1;

%defintion of the range of values for the omega and X(omega)


omega = -4*pi: pi/10: 4*pi;
X_omega = zeros(size(omega));

for ind = 1:length(t)


X_omega = X_omega + x(ind)*exp(-1i*omega*t(ind))*dt;
end

% This examples will have X(omega) as completely real but since there might
% be small values of imaginary part, we completely set them to zero
X_omega = real(X_omega);

% The original mathematical expression of the Fourier Transform


% of the rectangular pulse
X_omega_o = 2 * sin(omega*T1)./omega*T1;
% explicitly setting the value of X(omega) for omega = 0 frequency
X_omega_o(omega==0) = 2*T1;

% Error between orginal and numerically computed Fourier transform


err = norm(X_omega_o - X_omega,2)/norm(X_omega,2);

% Plot of the spectral content


figure;
plot(omega,X_omega,'Linewidth',2);
hold on
plot(omega,X_omega_o,'r--','Linewidth',3);
axis([min(omega) max(omega) 1.1*min(X_omega_o) 1.1*max(X_omega_o)]);
grid on
legend('Analytically Computed','Numerically Computed')
title(horzcat('Fourier Transform with relative error=',num2str(err)))
xlabel('\omega')
ylabel('X(\omega)')

% The x-axis is being changed in the plot to have tick points at different
% values of pi
set(gca,'xtick',[-4*pi:pi:4*pi])
set(gca,'xticklabels',{'4\pi','3\pi','2\pi','\pi','0','\pi','2\pi','3\pi','4\pi'})

You might also like