Discrete Signal Processing (DSP):
Discrete Time Fourier Transformation (DTFT)
Table of Contents
$$-\pi \leq \omega_k = \frac{2\pi}{N}k \leq \pi$$
Forward
$$\langle x,y\rangle = \sum_{n=-\infty}^{\infty}x[n]y[n]^*$$
Inverse
$$x[n] = \frac{1}{N}\sum \limits_{k=-\frac{N}{2}}^{\frac{N}{2}-1}X[k]\, e^{j\frac{2 \pi}{N}kn} \quad \rightarrow \quad x[n]= \frac{1}{2\pi} \int_{-\pi}^{\pi}X(\omega)e^{j\omega n}\, d \omega$$
Summary
$$ \begin{align*} X(\omega) &= \sum_{n=-\infty}^{\infty}x[n]e^{-j\omega n}, \;\;\qquad \qquad -\pi \leq \omega < \pi\\\\ x[n] &= \frac{1}{2\pi} \int_{-\pi}^{\pi}X(\omega)e^{j\omega n}\, d \omega, \qquad -\infty <n< \infty \end{align*}$$%plot -s 560,300
% dtft from definition
n = 0:3;
x = [1 1 1 1];
N = 200;
w = [0:N-1]*2*pi/N;
Xdtft = 1*exp(-1j*w*0) + 1*exp(-1j*w*1) + 1*exp(-1j*w*2) + 1*exp(-1j*w*3);
plot(w/pi, abs(Xdtft))
xlabel('\omega in \pi unit', 'fontsize', 8),
title('DTFT in (0, 2\pi)', 'fontsize', 8)
k = [0:N/2-1 -N/2:-1];
w = k*2*pi/N;
ws = fftshift(w);
Xdtfts = fftshift(Xdtft);
plot(ws/pi, abs(Xdtfts))
xlabel('\omega in \pi unit', 'fontsize', 8),
title('DTFT in (-\pi, \pi)', 'fontsize', 8)
x = [1,1,1,1];
N = length(x);
k = [0:N/2-1 -N/2:-1];
ks = fftshift(k);
X = dft(x,N);
Xs = fftshift(X);
stem(ks,abs(Xs),'filled'),
xlabel('freq in k','fontsize',8), ylabel('X[k]','fontsize',8),
xlim([-N/2,N/2]), hold on
c = [0 0.4470 0.7410];
plot(ws*N/(2*pi),abs(Xdtfts),'--', 'color', c), hold off
x = [1,1,1,1,zeros(1,4)];
N = length(x);
k = [0:N/2-1 -N/2:-1];
ks = fftshift(k);
X = dft(x,N);
Xs = fftshift(X);
stem(ks,abs(Xs),'filled'),
xlabel('freq in k','fontsize',8), ylabel('X[k]','fontsize',8),
xlim([-N/2,N/2]), hold on
plot(ws*N/(2*pi),abs(Xdtfts),'--', 'color', c), hold off
x = [1,1,1,1,zeros(1,12)];
N = length(x);
k = [0:N/2-1 -N/2:-1];
ks = fftshift(k);
X = dft(x,N);
Xs = fftshift(X);
stem(ks,abs(Xs),'filled'),
xlabel('freq in k'), ylabel('X[k]'), xlim([-N/2,N/2]), hold on
plot(ws*N/(2*pi),abs(Xdtfts),'--', 'color', c), hold off
% DTFT using the output of FFT (or DFT)
x = [1,1,1,1,zeros(1,2^6-4)];
N = length(x);
k = [0:N/2-1 -N/2:-1];
ks = fftshift(k);
X = dft(x,N);
Xs = fftshift(X);
stem(ks,abs(Xs),'filled')
xlabel('freq in k'), ylabel('X[k]'), xlim([-N/2,N/2]), hold on
plot(ws*N/(2*pi),abs(Xdtfts),'--', 'color', c), hold off
% DTFT using the output of FFT (or DFT)
x = [1,1,1,1,zeros(1,2^7-4)];
N = length(x);
k = [0:N/2-1 -N/2:-1];
ks = fftshift(k);
X = dft(x,N);
Xs = fftshift(X);
stem(ks,abs(Xs),'filled')
xlabel('freq in k'), ylabel('X[k]'), xlim([-N/2,N/2]), hold on
plot(ws*N/(2*pi),abs(Xdtfts),'--', 'color', c), hold off
function X = dtft(x,n,w)
% X = dtft(x, n, w)
%
% X = DTFT values computed at w frequencies
% x = finite duration sequence over n (row vector)
% n = sample position vector
% w = frequency location vector (row vector)
X = exp(-1j*(w'*n))*x';
end
DTFT of the impulse
%plot -s 560,420
[x, n] = impseq(0, -10, 10);
w = linspace(-1,1,2^10)*pi;
X = dtft(x,n,w);
subplot(2,1,1),
stem(n,x,'filled')
subplot(2,1,2),
plot(w/pi,abs(X),'linewidth',2), ylim([0, 1.3])
xlabel('Freq. in \pi units')
DTFT of $e^{j\omega_0 n}$
DTFT of the unit pulse
$$
p[n]\, =\, \begin{cases}
1\quad -M\, \leq\, n\, \leq \, M\\
0\quad \text{otherwise}
\end{cases}
$$
$$
\begin{align*}
P(\omega)\, &=\, \sum_{n=-\infty}^\infty \, p[n]\, e^{-j\omega n}\, =\, \sum_{n=-M}^M \,e^{-j\omega n}\, = \, \frac{e^{j\omega M}\, -\, e^{-j\omega (M+1)}}{1\, -\, e^{-j\omega}}\, \\&=\, \frac{e^{-j\omega /2}\left(e^{j\omega \frac{2M+1}{2}}\, -\, e^{-j\omega \frac{2M+1}{2}}\right)}{e^{-j\omega /2} \left(e^{j\omega /2}\, -\, e^{-j\omega /2}\right)}\, =\, \frac{2j\, \sin \left(\omega \frac{2M+1}{2} \right)}{2j\, \sin \left(\frac{\omega}{2} \right)}
\end{align*}$$
%plot -s 560,420
x = [1 1 1 1 1 1 1];
n = -3:3;
w = linspace(-2,2,2^10)*pi;
X = dtft(x,n,w);
xd = zeros(1,31);
nd = -15:15;
[y,ny] = sigadd(xd,nd,x,n);
subplot(2,1,1), stem(ny,y,'filled')
subplot(2,1,2), plot(w/pi,abs(X)), xlabel('Freq. in \pi units')
DTFT of triangle
%plot -s 560,420
x = [1 2 3 4 3 2 1];
n = -3:3;
w = linspace(-2,2,2^10)*pi;
X = dtft(x,n,w);
xd = zeros(1,31);
nd = -15:15;
[y,ny] = sigadd(xd,nd,x,n);
subplot(2,1,1), stem(ny,y,'filled')
subplot(2,1,2), plot(w/pi,abs(X)), xlabel('Freq. in \pi units')
DTFT of a one-sided exponential
%plot -s 560,600
N = 30;
x = zeros(1,N);
for i = 1:N
x(i) = 0.8^(i-1);
end
n = 0:N-1;
w = linspace(-2,2,2^10)*pi;
X = dtft(x,n,w);
nd = -8:N;
xd = zeros(size(nd));
[y,ny] = sigadd(xd,nd,x,n);
subplot(3,1,1), stem(ny,y,'filled'), xlabel('n')
subplot(3,1,2), plot(w/pi,abs(X)), ylabel('|X(\omega)|')
subplot(3,1,3), plot(w/pi,phase(X)), xlabel('Freq. in \pi units'), ylabel('\angle X(\omega)')
DTFT and Modulation
$$ e^{j\omega_0 n}x[n] \qquad \longleftrightarrow \qquad X(\omega - \omega_0) $$
%plot -s 560,600
N = 30;
nd = -8:N;
xd = zeros(size(nd));
x = zeros(1,N);
for i = 1:N
x(i) = (-0.8)^(i-1);
end
n = 0:N-1;
%w = linspace(-1,1,2^10)*pi;
w = linspace(-2,2,2^10)*pi;
X = dtft(x,n,w);
subplot(3,1,1), stem(nd,sigadd(xd,nd,x,n),'filled'), xlabel('n')
subplot(3,1,2), plot(w/pi,abs(X)), ylabel('|X(\omega)|')
subplot(3,1,3), plot(w/pi,phase(X)), xlabel('Freq. in \pi units'), ylabel('\angle X(\omega)')
DTFT and Time Shift
$$ x[n-m] \qquad \longleftrightarrow \qquad e^{-j\omega m}X(\omega) $$%plot -s 560,600
N = 30;
nd = -8:N;
xd = zeros(size(nd));
x = zeros(1,N);
for i = 1:N
x(i) = 0.8^(i-1);
end
m = 1;
n = 0+m:N-1+m;
[y,ny] = sigadd(xd,nd,x,n);
w = linspace(-2,2,2^10)*pi;
X = dtft(x,n,w);
subplot(3,1,1), stem(ny,y,'filled'), xlabel('n')
subplot(3,1,2), plot(w/pi,abs(X)),
subplot(3,1,3), plot(w/pi,phase(X)), xlabel('Freq. in \pi units')
DTFT and Convolution
Low-Pass Filter
%plot -s 560,420
nd = -5:10;
hd = zeros(1,length(nd));
N = 2;
h = ones(1,N);
n = 0:N-1;
w = linspace(-1,1,2^10)*pi;
X = dtft(h,n,w);
[y,ny] = sigadd(hd,nd,h,n);
subplot(2,1,1), stem(ny,y,'filled')
subplot(2,1,2), plot(w/pi,abs(X)), xlabel('freq in \pi units')
High-Pass Filter
%plot -s 560,420
nd = -5:10;
hd = zeros(1,length(nd));
N = 2;
h = [1 -1];
n = 0:N-1;
w = linspace(-1,1,2^10)*pi;
X = dtft(h,n,w);
[y,ny] = sigadd(hd,nd,h,n);
subplot(2,1,1), stem(ny,y,'filled')
subplot(2,1,2), plot(w/pi,abs(X)), xlabel('freq in \pi units')
Band-Pass Filter
%plot -s 560,420
nd = -5:10;
hd = zeros(1,length(nd));
N = 4;
h = [1 1 -1 -1];
n = 0:N-1;
w = linspace(-1,1,2^10)*pi;
X = dtft(h,n,w);
[y,ny] = sigadd(hd,nd,h,n);
subplot(2,1,1), stem(ny,y,'filled')
subplot(2,1,2), plot(w/pi,abs(X)), xlabel('freq in \pi units')
Band-Pass Filter
%plot -s 560,420
nd = -5:10;
hd = zeros(1,length(nd));
N = 3;
h = [1 0 -1];
n = 0:N-1;
w = linspace(-1,1,2^10)*pi;
X = dtft(h,n,w);
[y,ny] = sigadd(hd,nd,h,n);
subplot(2,1,1), stem(ny,y,'filled')
subplot(2,1,2), plot(w/pi,abs(X)), xlabel('freq in \pi units')
Impulse Response of the Ideal Low-pass Filter
%plot -s 560,600
wc = pi/6;
N = 30;
n = -N:N;
h = zeros(1,length(n));
for i = 1:length(n)
h(i) = 2*wc*sinc(1/pi*wc*(i-N-1));
end
w = linspace(-1,1,2^10)*pi;
X = dtft(h,n,w);
subplot(2,1,1), stem(n,h,'filled','markersize',4), ylabel('x[n]')
subplot(2,1,2), plot(w/pi,abs(X)), ylabel('X(\omega)')
xlabel('Freq. in \pi units'), ylabel('X(\omega)')
%plot -s 560,600
wc = pi/6;
N = 100;
n = -N:N;
h = zeros(1,length(n));
for i = 1:length(n)
h(i) = 2*wc*sinc(1/pi*wc*(i-N-1));
end
w = linspace(-1,1,2^10)*pi;
X = dtft(h,n,w);
subplot(2,1,1), stem(n,h,'filled','markersize',4), ylabel('x[n]')
subplot(2,1,2), plot(w/pi,abs(X)), ylabel('X(\omega)')
xlabel('Freq. in \pi units'), ylabel('X(\omega)')
%plot -s 560,600
wc = pi/6;
N = 30;
n = -N:N;
d = zeros(1,length(n));
h = zeros(1,length(n));
d(N+1) = d(N+1) + 1;
for i = 1:length(n)
h(i) = (-1)^(i-N-1)*2*wc*sinc(1/pi*wc*(i-N-1));
end
w = linspace(-1,1,2^10)*pi;
X = dtft(h,n,w);
subplot(2,1,1), stem(n,h,'filled','markersize',4), ylabel('x[n]')
subplot(2,1,2), plot(w/pi,abs(X)), ylabel('X(\omega)')
xlabel('Freq. in \pi units'), ylabel('X(\omega)')
$$ x[n] = \cos(0.48 \pi n) + \cos(0.52 \pi n)$$
N = 100;
n = 0:N-1;
x = cos(0.48*pi*n) + cos(0.52*pi*n);
Use 100 samples of $x[n]$
%plot -s 560,420
k = n;
X = dft(x,N);
w = 2*pi/100*k;
subplot(2,1,1), stem(n,x,'filled')
subplot(2,1,2), stem(w/pi,abs(X),'filled')
use only 10-point DFT of $x[n]$
%plot -s 560,420
n1 = 0:9;
y1 = x(1:10);
Y1 = dft(y1,10);
k1 = n1;
w1 = 2*pi/10*k1;
subplot(2,1,1), stem(n1,y1,'filled')
subplot(2,1,2), stem(w1/pi,abs(Y1),'filled')
Pad 90 zeros to obtain a dense spectrum
%plot -s 560,420
n2 = 0:N-1;
y2 = [x(1:10), zeros(1,90)];
Y2 = dft(y2,N);
k2 = n2;
w2 = 2*pi/100*k2;
subplot(2,1,1), stem(n2,y2,'filled')
subplot(2,1,2), stem(w2/pi,abs(Y2),'filled')
Conclusion:
Padding more zeros to the 100-point sequence will result in a smoother rendition of the spectrum but will not reveal any new information.
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')