Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
1
5
1
Given: [2,2,3,1,8]
and ( ) ( ) * , k=1,2,3,4,5
Write a Matlab code to get the value of y
n
x
y k x n k
QUIZ
x=[2,2,3,1,8];
y=zeros(1,5);
for k=1:5;
Sum=0;
for n=1:5;
y(k)=y(k)+x(n)*k;
end
y1(k)=sum;
end
y = 16 32 48 64 80
5
6
21
100
22
100
23
100
2
100100
2 k
N
k
1 2 3
7
DTFT DFT
Discrete Fourier Transform (DFT)
( ) ( ) ( ) | ( ) j
j j n
z e n
DTFT X e X z x n e
2
1( ) ( ) ( )
2
j j ninverse DTFT x n X e e d
21
0
21
0
(DFT) ( ) ( ) , k=0,1,2,.......,N 1
1(inverse DFT) x(n)= ( ) , n=0,1,2,.......,N 1
nkN jN
n
nkN jN
k
X k x n e
X k eN
2
( ) ( ) |k
N
X k X
Write your own Matlab function to implement
the DFT of equation X = DFTsum(x)
21
0
k=0,1,2,..(DFT) ( ) ( ) , .....,N 1 nkN j
N
n
X k x n e
Part1: DFTsum and IDFTsum
LOGOfunction Y=DFTsum(x)
N=length(x);
Y=zeros(1,N);
for k=0:N-1;
for n=0:N-1;
Y(k+1)=Y(k+1)+x(n+1).*exp(-2*j*n*k*pi/N);
end
end
•Test your routine DFTsum by computing
X (k) for:
(a) x(n) = {1,2,3,1}
(b) x(n) = cos(2πn/10) for N = 10.
(a) x(n) = {1,2,3,1}
(b) x(n) = cos(2πn/10) for N = 10.
(b)
n=0:9
x=cos(2*pi*n/10);
XK=DFTSum(x)
stem(n,abs(XK))
%XK=fft(x)
(a)
n=0:3
x=[1,2,3,1];
XK=DFTSum(x)
stem(n,abs(XK))
%XK=fft(x)
XK={ 7 , -2- 1i , 1 , -2+ 1i}
14
1 2 3
2 3
2 32 2 2
2
2
x(n)= (n)+2 (n 1)+3 (n 2)+ (n 3)
X(z)=1+2Z +3Z Z
X( ) | =1+2e 3e e
( ) ( ) | ( ) | 1+2e 3e e , k=0,1,2,3
j
j j j
z e
k k kj j j
kk
N
X k X X
DTFT :
DFT :
x(n)={ ,1 2,3,1}
15
32 2
32 2
( ) 1+2e 3e e , k=0,1,2,3
1 2 3 1 7
1 1+2e 3e e 2
2 1
3 2
( ) {7, 2 ,1, 2 }
k kj j
j k
j jj
X k
X(k = 0) =
X(k = ) = j
X(k = ) =
X(k = ) = j
X k j j
Write a matlab function for computing the inverse DFT.
x = IDFTsum(X)
21
0
1(inverse DFT) x(n)= ( ) , n=0,1,2,.......,N 1
nkN jN
k
X k eN
function y=IDFTsum(X)
N=length(X)
y=zeros(1,N);
for n=0:N-1
for k=0:N-1
y(n+1)=y(n+1)+(X(k+1).*exp(2*j*n*k*pi/N)/N);
end
end
XK=[ 7 , -2- 1i , 1 , -2+ 1i]
x=IDFTSum(XK)
%x=ifft(XK)
x = ,21 ,3,1
19
(A)
(B) Choose
then Check by Matlab
20
Part2: Circular convolution
21
Circular symmetries of a sequence
Circular convolution
The circular convolution is very similar to normal
convolution apart from that the signal is shifted using
circular shift.
3 1 2
1
3 1 2
0
3 1 2
( ) ( ) ( )
( ) ( ) (( ))
( ) ( ) ( )
N
N
n
x m x n x n
x m x n x m n
X k X k X k
23
1 2
Determine the circular convolution
x (n)={ ,2,3,1} , 1 4 x (n)={ ,3,2,2}
3 1 2
3 1 2
( ) ( ) ( )
( ) ( ) ( )
x m x n x n
X k X k X k
fft(x1) fft(x2)
24
3 1 2 3 1 2
1
2
3 1 2
3 1 2
3 1 2
3 1 2
( ) ( ) ( ) ( ) ( ) ( )
( ) { 7 , 2 , 1 , 2 }
( ) { 11 , 2 , 1 , 2 }
(0) (0) (0) (7)(11) 77
(1) (1) (1) ( 2 )(2 ) 5
(2) (2) (2) (1)(1) 1
(3) (3) (3) (
x m x n x n X k X k X k
X k j j
X k j j
X X X
X X X j j
X X X
X X X
3
3
( ) { 77 , 5 , 1 ,
( ) {17,19,
2 )(
5 }
22,19}
2 ) 5
X
x m
j
k
j
ifft(X)
x1=[1 2 3 1] ; % sequence x1(n)
x2=[4 3 2 2] ; % sequence x2(n)
X1=fft(x1) ; % DFT of x1(n)
X2=fft(x2) ; % DFT of x2(n)
X=X1.*X2 ; % DFT of x(n)
x3=ifft(X) ; % IDFT of X(k)
3
1
3
2
3
1
2
[7 , 2 , 1 , 2 ] ( )
[ 11 , 2
( ) [17,19,22,19
[
, 1
77 ,
,
5 , 1 , 5 ]
2 ] (
(
)
]
)
X j j X k
X j j X
X X k
x
k
m
27
x1=[1 2 3 1] ;x2=[4 3 2 2] ;cconv(x1,x2,4)
Or
ans = 17 19 22 19
Note: try to find the result of:
cconv(x1,x2) = ??????
28
Let: h(n)={ ,2,3} , x(n)={ ,2,2,1} , f ind
(a) h(n)*x(n) using conv
(b) h(n) x(n) using fft and ifft
(c) h(n) x(n) using DFTsum and IDFTsum
(d) h(n) x(n) using c n
1
o
1
c v
29
3 1 2
3 1 2
( ) ( ) ( )
( ) ( ) ( )
x m x n x n
X k X k X k
3 1 2
3 1 2
( ) ( )* ( )
( ) ( ) ( )
x n x n x n
X z X z X z
Part3:
30
x1=[1 2 3 1] ;x2=[4 3 2 2] ;conv(x1,x2)
ans = 4 11 20 19 13 8 2
x1=[1 2 3 1] ;x2=[4 3 2 2] ;cconv(x1,x2,4)
ans = 17 19 22 19
31
32
x1=[1 2 3 1 0 0 0] ;x2=[4 3 2 2 0 0 0] ;cconv(x1,x2,7)
ans = 4 11 20 19 13 8 2
Zero padding
Circular convolution gives the same results as linear convolution
L=4M=4L+M-1=7Length of x1 and x2=7
33
34
36
37
38
39
DFT repeats itself every N points (Period = N) but we usually display it for n = 0 ,…, N-1
Part4: Periodicity of DFT
40
41
42
Our plot of the DFT has two disadvantages
•Plotting of the DFT
(1) The DFT values are plotted against k rather than
the frequency w.
(2) DFT goes from 0 to 2π rather than from -π to π
44
n=0:127
x=cos(2*pi*n/10);
y=fft(x)
stem(n,abs(y))
N=128;
k=0:127;
w=2*pi*k/N;
stem(w,abs(y))
w(w>=pi)=w(w>=pi)-2*pi
w=sort(w)
y2=fftshift(y)
Stem(w,abs(y2))
:Example
n=0:127
x=cos(2*pi*n/10);
y=fft(x)
stem(n,abs(y))
0 20 40 60 80 100 120 1400
10
20
30
40
50
60
70
0 127k
N=128;
k=0:127;
w=2*pi*k/N;
stem(w,abs(y))
0 1 2 3 4 5 6 70
10
20
30
40
50
60
70
2
0 2 Part1
w(w>=pi)=w(w>=pi)-2*pi
w=sort(w)
y2=fftshift(y)
Stem(w,abs(y2))
Part2
-4 -3 -2 -1 0 1 2 3 40
10
20
30
40
50
60
70
48
20
49
>>y=[1 2 3 4 5 6]
>>fftshift(y)
4 5 6 1 2 3
50
0 1 2 3 4 5 6 70
5
10
15
20
25
30
n=[1,2,3,4,5,6];
y=[30,20,10,5,15,20];
stem(n,y)
n2=[1,2,3,-2,-1,0] % n(n>3)-6
n3=[-2,-1,0 ,1 ,2 ,3] % sort(n2)
y2=[5 ,15,20,30,20,10]; % fftshift(y)
stem(n3,y2)
NOTE
>> x=[3,2,1];
>> sort(x)
ans =1 2 3
51
0 1 2 3 4 5 6 70
5
10
15
20
25
30
-3 -2 -1 0 1 2 3 40
5
10
15
20
25
30
( )y n
2 3( )y n
52
LOGO
53