DFT & DTFT Matlab Demonstrations

advertisement
DFT
Matlab Demonstrations
Relationship Between DFT and DTFT
x=[1 ; 2 ; 4 ; 3];
DFT Example
x=[1 2 4 3]’;
n=0:3; stem(n,x); xlabel('n'), ylabel('x[n]');
4
x[n]
3
2
1
0
0
1
2
n
3
w=0:0.01:(2*pi);
N=length(x);
n=(0:(N-1) )';
DTFT Computation in MATLAB
plot(w,abs(Xdtft))
xlabel('\omega'),
ylabel('X_{DTFT}(\omega)')
axis([0,2*pi,0,10])
XDTFT( )
Xdtft=[];
for wi=w
Xdtft=[Xdtft sum(x.*exp(-1j*wi*n))];
end
10
5
0
0
2

4
6
>> N = length(x);
>> D=dftmtx(N)
DFT Computation in MATLAB
D=
1.0000
1.0000
1.0000
1.0000
1.0000
0 - 1.0000i
-1.0000
0 + 1.0000i
1.0000
-1.0000
1.0000
-1.0000
1.0000
0 + 1.0000i
-1.0000
0 - 1.0000i
>> Xdft=D*x
>> Xdft=fft(x)
Xdft =
Xdft =
10.0000
-3.0000 + 1.0000i
0
-3.0000 - 1.0000i
10.0000
-3.0000 + 1.0000i
0
-3.0000 - 1.0000i
k=0:(N-1);
stem(k, abs(Xdft))
xlabel('k');ylabel('X[k]');
X[k]
10
5
0
0
1
2
k
3
wk=2*pi./N.*k;
stem(wk, abs(Xdft))
XDFT
10
5
0
0
2
k
4
6
What’s the relationship
between the
DFT and DTFT?
5
10
0
0
2

4
XDFT
XDTFT( )
10
6
5
0
0
2
k
4
6
plot(w, abs(Xdtft), wk, abs(Xdft),'ro')
xlabel('\omega'); ylabel('X(e^{j\omega})')
j
X(e )
10
5
0
0
2

4
6
DEMO
Applying DFT to analyze an audio signal
Listen to tone440.wav file
0
DFT
-0.5
-1
100
1000
200 300
n
X[k]
x[n]
0.5
400
500
-What type of signal is this?
-Can you get the
frequency in Hz?
0
0
2000
k
4000
DFT
0
100
-0.5
0
500
n
X[k]
x[n]
0.5
Listen to dtmf.wav file
-What type of signal is this?
-Can you get the
frequency in Hz?
1000
50
0
0
500
k
1000
X[k]
1000
500
k
0
0
2000
k

Converting the index
k to frequency in Hz
4000
 (rad/sec)
2
f (Hz)
fs/2
440 Hz
4000 Hz
Circular vs. Linear Convolution
12
Linear vs. Circular
Convolution
10
8
x[n]
6
4
2
0
-2
-4
12
-6
10
-8
-1
8
x=[1 2 3 4 5];h=[1 -3 2];
0
1
2
3
4
5
6
7
8
9
10
0
1
2
3
4
5
6
7
8
9
10
6
4
h[n]
2
0
-2
-4
-6
-8
-1
Linear Convolution
12
y1=conv(x,h);
ny1=0:length(y1)-1;
stem(ny1,y1);
10
8
6
4
2
0
-2
-4
-6
-8
-1
0
1
2
3
4
5
6
7
8
9
10
Circular Convolution
12
h2=[h , zeros(1,2)];
y2=ifft(fft(x).*fft(h2));
ny2=0:length(y2)-1;
stem(ny2,y2);
10
8
6
4
2
0
-2
-4
-6
-8
-1
0
1
2
3
4
5
6
7
8
9
10
Circular convolution with
zero-padding
12
10
N=length(x);
M=length(h);
x3=[x , zeros(1,M-1)];
h3=[h , zeros(1,N-1)];
y3=ifft(fft(x3).*fft(h3));
ny3=0:length(y3)-1;
stem(ny3,y3);
8
6
4
2
0
-2
-4
-6
-8
-1
0
1
2
3
4
5
6
7
8
9
10
Complexity: Direct Convolution vs. FFT convolution
Download