You are on page 1of 8

The Digital Fourier Transform

The Digital Fourier Transform

EE16B131
Dept. of Electrical Engineering

April 4, 2017

1 Introduction:
F(θ ) is continuous and periodic. f [n] is discrete and aperiodic. Suppose now f [n]
is itself periodic with a period N, i.e.,
f [n+N] = f [n] ∀n
Then, it should have samples for its DTFT. This is true, and leads to the Discrete
Fourier Transform or the DFT:
Suppose f [n] is a periodic sequence of samples, with a period N. Then
the DTFT of the sequence is also a periodic sequence F[k] with the same
period N. (You will prove this in the DSP course). So we have
P
F[k] = f [n]exp(−2πnkj/N )
1P −nk
f[n] =
N
F [k]W
In this assignment, we want to explore how to obtain the DFT.

2 Codes:
for problems 1 to 3,

from pylab import ∗


x=r a n d ( 1 0 0 )
X= f f t ( x )
y= i f f t (X)
c_ [ x , y ]
print a b s ( x−y ) . max ( )

N = 512
x=l i n s p a c e ( − 4 ∗ p i , 4 ∗ p i , N+1)
x= x [ : −1]

def fun ( x , y ,N) :


Y= f f t ( y )
Y = f f t s h i f t (Y ) ∗ ( 1 . 0 /N)
w = f f t f r e q ( l e n ( x ) , d=4) ∗ l e n ( x )
w = f f t s h i f t (w)
figure ()
subplot (2 ,1 ,1)
p l o t (w , a b s (Y) , l w =2)
t i t l e ( " Spectrum of y ")
y l a b e l ( " |Y| " )
xlim ( −40 ,40)
g r i d ( True )
subplot (2 ,1 ,2)
p l o t (w , a n g l e (Y) , " r o " , lw =2)
y l a b e l ( " Phase o f Y" )
xlim ( −40 ,40)
g r i d ( True )
show ( )

y1=s i n ( 5 ∗ x )
y2 = cos (10∗ x )+0.1∗ cos ( x )∗ cos (10∗ x )
y3 = ( 3 ∗ s i n ( x)− s i n ( 3 ∗ x ) ) ∗ ( 0 . 2 5 )
y4 = ( 3 ∗ c o s ( x)+ c o s ( 3 ∗ x ) ) ∗ ( 0 . 2 5 )
y5 = c o s ( 2 0 ∗ x +5∗ c o s ( x ) )
f u n ( x , y1 , N)
f u n ( x , y2 , N)
f u n ( x , y3 , N)
f u n ( x , y4 , N)
f u n ( x , y5 , N)

...
for problem 4:

from pylab import ∗

N = 1024
x=l i n s p a c e ( − 10 ∗ p i , 1 0 ∗ p i , N+1)
x= x [ : −1]
y = e x p ( −( x ∗ ∗ ( 2 ) ) / 2 . 0 )
Y= f f t ( y )
Y = f f t s h i f t (Y ) ∗ ( 1 . 0 /N)
w = f f t f r e q ( l e n ( x ) , d =10) ∗ l e n ( x )
w = f f t s h i f t (w)
figure ()
subplot (2 ,1 ,1)
p l o t (w , a b s (Y) ∗ 2 0 ∗ p i , lw =2)
t i t l e ( " Spectrum of y ")
y l a b e l ( " |Y| " )
xlim ( −10 ,10)
g r i d ( True )
subplot (2 ,1 ,2)
p l o t (w , a n g l e (Y) , " r o " , lw =2)
y l a b e l ( " Phase o f Y" )
xlim ( −10 ,10)
g r i d ( True )
show ( )

d = Y∗ 2 0 ∗ p i
s = ( ( 2 ∗ p i ) ∗ ∗ ( 0 . 5 ) ) ∗ e x p ( − (w ∗ ∗ ( 2 ) ) / 2 . 0 )
e r r = a b s ( a b s ( d)− s ) . max ( )
print " errror " , err

2.1 Problem 1:
e5jx −e−5jx
y = sin(5x) =
2j

2
So the expected spectrum is
1
Y(w) =
2j
[δ(ω − 5) − δ(ω + 5)]
plots are,

..
The peaks are at exactly -5 and 5.And the phase at -5 is Π/2 ,and at 5 is -Π/2.

2.2 problem 1.2

Suppose we now look at AM modulation. The function we want to analyse is


f(t) = (1+0.1 cos(t)) cos(10t)
And we get ...
0.1 cos(10t) cos(t) = 0.05(cos 11t +cos 9t)
and plots are,

3
..
We have three clear spikes. The phases at those spikes are zero to machine
precision. The location of the spikes are 9, 10 and 11 radians per sec.

2.3 problem 2:

3
sin x = (3*sin(x)-sin(3*x))*(0.25)
and
3
cos x = (3*cos(x)+cos(3*x))*(0.25)
plots are,
5
..
..
for (3*sin(x)-sin(3*x))*(0.25) the peaks are expected to be at -3,-1,1,3 as in we got in the plot.And
phase at -1 is π/2, at 1 is -π/2.And at -3 is -π/2 ,at 3 is π/2.
next for ,
3
(3*cos(x)+cos(3*x))*(0.25) the peaks are at the same values of sin x.But the phase becomes zero(0)
at all peaks.

2.4 problem 3:

spectrum of cos(20t +5 cos(t)),


..we have for cos(20t +5 cos(t)),
The sinsoidal peaks are located in the range of 10 to 30 and also at -10 to -30.

2.5 problem 4:

−ax2
The Fourier transform of a Gaussian function f(x)=e is given by,

..so for a = 2 we get


√ 2
2π e−w /2
plots are,
..
for range x=linspace(-10π ,10π ,1025)
√ 1
at w=0 the value is 2π . Fourier coecients have
T
factor so,we need to multiply with the interval
(4x = (20π )).
Since Gaussian is not bandlimited in frequency which is obtained by multipling the 4x = (20π )
,resulting in |Y| = abs(Y)(20π ) .And
−15
the calculated erroor is 2.77555756156e-15 (which is so small) order of 10 .

You might also like