Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

ECE 3300 MATLAB Assignment 4 This assignment gives an overview of matrix manipulation techniques in MATLAB. It then ex- plains how to use MATLAB to determine the Fourier transform of...

1 answer below »
ECE 3300
MATLAB Assignment 4
This assignment gives an overview of matrix manipulation techniques in MATLAB. It then ex-
plains how to use MATLAB to determine the Fourier transform of continuous-time and discrete-
time signals. The approach simply implements sums directly and implements integrals as sums
of rectangles, similar to the approach of previous assignments.
It should be noted that MATLAB has an implementation of the Fast Fourier Transform (FFT)
that is significantly more computationally efficient. We choose not to use the FFT approach be-
cause it requires additional theory normally taught in a Digital Signal Processing (DSP) course
and because applying the FFT to the Fourier transform requires additional manipulations of
the FFT output that are difficult to explain simply. The approach presented in this assignment,
although computationally inefficient, works quite satisfactorily and is relatively simple to under-
stand.
Matrices in Matla
A matrix in Matlab is essentially a two-dimensional list. The command b=[1 2 3; 4 5 6]
produces the matrix [
1 2 3
4 5 6
]
The transpose of a Matrix converts the first row into the first column, the second row into
the second column, and so on. In mathematics, the transpose of a matrix A is denoted AT .
In MATLAB, a transpose is obtained by following the variable with a period followed by an
apostrophe, .’. For example, with b as defined above, the command b.’ produces the matrix 1 42 5
3 6

Matrix multiplication produces a matrix in which the element in the ith row and jth column is
equal to the sum of the element-by-element products of the ith row of the first matrix and the
jth column of the second. Two examples are
[
1 2 3
4 5 6
] 1 42 5
3 6
 = [ XXXXXXXXXX XXXXXXXXXX6)
XXXXXXXXXX XXXXXXXXXX6)
]
=
[
14 32
32 77
]
and 1 42 5
3 6
[ 1 2 3
4 5 6
]
=
 XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX)(6)
XXXXXXXXXX XXXXXXXXXX6)
 =
 XXXXXXXXXX
XXXXXXXXXX

In MATLAB the asterisk * is used for matrix multiplication. Thus the first example is equal to
*b.’ and the second is equal to b.’*b.
1
Discrete-Time Fourier Transform
The discrete-time Fourier transform of x[n] is defined X(ejω) =
∑∞
n=−∞ x[n]e
−jωn. Suppose
we represent x[n] in MATLAB via n and x, and using vecto
matrix notation let us write
n = [n1 n2 · · · nL] and x = [x1 x2 · · · xL]. Similarly, let us use w = [ω1 ω2 · · · ωK ] to
denote the frequencies at which we wish to determine the Fourier transform, and let us use
X = [X1 X2 · · · XK ] to denote the co
esponding Fourier transform values at these frequencies.
Using these definitions, the Fourier transform definition can be written as Xk =
∑L
`=1 x`e
−jn`ωk .
Our goal is to determine an expression for the vector X in terms of the other vectors. We can
egin by writing
nTw =

n1
n2
...
nL
 [ ω1 ω2 · · · ωK ] =

n1ω1 n1ω2 · · · n1ωK
n2ω1 n2ω2 · · · n2ωK
...
...
. . .
...
nLω1 nLω2 · · · nLωK

If A is a matrix, we use the notation eA = exp(A) to mean that we take the exponential function
on each term in the matrix. (This is exactly what MATLAB does.) Also note that a constant
times a matrix means that every element in the matrix is multiplied by that constant. Then we
can write
x exp(−jnTw) =
[
x1 x2 · · · xL
]

e−jn1ω1 e−jn1ω2 · · · e−jn1ωK
e−jn2ω1 e−jn2ω2 · · · e−jn2ωK
...
...
. . .
...
e−jnLω1 e−jnLω2 · · · e−jnLωK

=
[ ∑L
`=1 x`e
−jn`ω1
∑L
`=1 x`e
−jn`ω2 · · ·
∑L
`=1 x`e
−jn`ωK
]
This is our desired list of Fourier transform values! Thus X=x exp(−jnTw). In MATLAB, this
is implemented via X=x*exp(-i*n.’*w).
Continuous-Time Fourier Transform
The continuous-time Fourier transform X(jω) can be approximated by replacing the integral in
its definition with a sum of areas of rectangles, much akin to the method used with integrals in
previous assignments. Denote the list of time values and signal values as t = [t1 t2 · · · tL] and
x = [x1 x2 · · · xL], respectively, and define the list of frequency values and transform values as
w = [ω1 ω2 · · · ωK ] and X = [X1 X2 · · · XK ]. If the time between time samples is b, we can
write
X(jω) =
∫ ∞
−∞
x(t)e−jωtdt ≈
L∑
`=1
x`e
−jωt`
and at frequency ωk this expression becomes Xk =
∑L
`=1 x`e
−jωkt`b. Except for replacing n with
t and multiplying by b, this is identical to the discrete-time result. Thus X= x exp(−jtTw)b,
and in MATLAB, this is implemented via X=x*exp(-i*t.’*w).*b.
Inverse Transforms
The inverse continuous-time and discrete-time Fourier transforms are defined via
x(t) = 12Ï€
∫ ∞
−∞
X(jω)ejωtdω and x[n] = 12π
∫ π
−π
X(ejω)ejωtdω
If the frequency spacing is d, a similar analysis shows that x(t) can be obtained from X(jω)
via x=X exp(jwT t) d2Ï€ and x[n] can be obtained from X(e
jω) via x=X exp(jwTn) d2π . These
expressions can be implemented in MATLAB with the code x=X*exp(i*w.’*t).*d./(2.*pi)
and x=X*exp(i*w.’*n).*d./(2.*pi), respectively.
2
However, note that whereas many signals are limited to cover a finite amount of time, fewer are
limited in frequency. If a signal has infinite frequency duration, the frequency values will need
to be truncated beyond a certain point, and this may introduce additional e
or beyond that
caused by sampling. One effect of this e
or is that the inverse transforms may produce signals
that are not purely real even if the transforms were in fact transforms of real signals. In prac-
tice, one may wish to take the real part of an inverse transform obtained in MATLAB just in case.
Magnitude and Phase of Fourier Transforms
Recall that a Fourier transform is complex-valued in general. We can use abs(X) to obtain the
magnitude of the Fourier transform and angle(X) to obtain the phase. If phase unwrapping is
desired, one should use unwrap(angle(X)).
PROBLEM STATEMENT
Suppose x(t) = (2 cos(2πt)+5 sin(4πt)+cos(6πt+ π4 ))(u(t+20)−u(t−20)). Note that this signal
is a truncation of a periodic signal with three components. If it were not truncated, the Fourie
transform would consist of three spikes (deltas). If the truncation window is large enough, we
would expect the Fourier transform to contain rounded approximations to these deltas.
Throughout this assignment use a sampling time of 0.01 and a frequency spacing of 0.01. Take
t to go from −20 to 20, and take ω to go from −40 to 40.
1. Plot x(t) and separately plot the magnitude of the Fourier transform |X(jω)|.
2. Plot the phase ∠X(jω) twice (separately), once with phase unwrapping and once without.
3. Determine the energy in x(t) twice, once using the time-domain formula and once using
Parseval’s relation for the energy using the Fourier transform. The two should give roughly
the same answer. Determine the percentage difference between your answers using the
formula Emax−EminEmax × 100%, where Emax is the larger of your two answers and Emin is the
smaller of your two answers.
3
Answered Same Day Oct 30, 2022

Solution

Baljit answered on Oct 31 2022
51 Votes
ASSIGNMENT -4
Given Signal
x(t) = (2 cos(2πt)+5 sin(4πt)+cos(6πt+ π 4 ))(u(t+20)−u(t−20))
Fourier Transform of signal
X(jw)=
Matlab Code:-
clc;
clear all;
close all;
%sampling time
ts=0.01;
%frequemcy spacing
fs=0.01;
%time
t=-20:0.01:20;
%w matrix
w=-40:0.01:40;
f=w/(2*pi)
%given...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here