Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your third course assignment involves numerical implementation of the Fourier tr

ID: 2083257 • Letter: Y

Question

Your third course assignment involves numerical implementation of the Fourier transform of continuous-time signals and inverse Fourier transform. The Fourier transform of a continuous-time signal x(t) is given by the following relation: X(j omega) = integral_infinity^infinity x(t) e^-j omega t dt Also, the relation for the inverse Fourier transform is as follows: x(t) = 1/2 pi integral_-infinity^infinity X(j omega) e^j omega t d omega You will write two MATLAB functions: contft() that numerically computes the Fourier transform X(j omega) of a continuous-time signal x(t). The function should take as input a vector of time points omega a vector of signal values x and a vector of frequency points, omega. The output of the function should be the transform values X. The function should also plot the magnitude and the phase spectrum against the frequency omega. icontft () that numerically computes the inverse Fourier transform x(t) of X(omega). The function should take as input a vector of frequency points a), a vector of transform values X and a vector of time points t. The output of the function should be the vector of signal values x. The function should plot the time-domain signal x against the time vector t. Exercise: a. Use the function contft () to plot the CTFT of: x_1(t) = u(t + 4)-u(t-4) and x_2(t) = sin pi/3 t/pi t b. Use the transform results of the two signals given above in exercise (a) and the inverse FT function icontf t () to plot the inverse Fourier transforms.

Explanation / Answer

Copy the following code to a new function file in MATLAB. Name the file contft.m.

function [X] = contft(x,t,w)

T = abs(t(2)-t(1));
N_w = length(w);
N_t = length(t);
X = zeros(1,N_w);
for i=1:N_w
for j=1:N_t
X(i) = X(i) + x(j)*exp(-1i*w(i)*t(j))*T;
end
end
mag = abs(X); % Magnitude of fourier trasform
phs = angle(X); % Phase of fourier transform
figure; subplot(2,1,1); plot(w,mag); axis tight;
title('Fourier trasform of x(t) = X(j omega)');
ylabel('|X(j omega)|'); xlabel('Frequency omega (rad/s)');
subplot(2,1,2); plot(w,phs); axis tight
ylabel('ngle X(j omega) (in radians)');
xlabel('Frequency omega (rad/s)');

end

Copy the following code to a new function file in MATLAB. Name the file icontft.m.

function [x] = icontft(X,t,w)

W = abs(w(2)-w(1));
N_w = length(w);
N_t = length(t);
x = zeros(1,N_t);
for i=1:N_t
for j=1:N_w
x(i) = x(i) + X(j)*exp(1i*w(j)*t(i))*W;
end
end
x = abs(x)/(2*pi*max(abs(x)));
figure; plot(t,x); axis tight;
title('Inverse fourier trasform of X(j omega) = x(t)');
xlabel('t (s)');
end

Copy the following code to a new script file in MATLAB.

close all; clear all; clc;
% Part (a)
t1 = -10:0.05:10;
w1 = -20*pi:0.1:20*pi;
x1 = (t1>=-4) - (t1>=4);
X1 = contft(x1,t1,w1);

t2 = -15:0.05:15-0.05;
w2 = -20*pi:0.1:20*pi;
x2 = sin((pi*t2)/3)./(pi*t2);
X2 = contft(x2,t2,w2);

% Part (b)
inv_X1 = icontft(X1,t1,w1);
inv_X2 = icontft(X2,t2,w2);