Discrete Signal Processing (DSP):

Discrete Time Fourier Transformation (DTFT)


By Prof. Seungchul Lee
http://iai.postech.ac.kr/
Industrial AI Lab at POSTECH

Table of Contents

1. DFT and DTFT

  • DTFT is the Fourier transform of choice for analyzing infinite-length signals and systems
  • Useful for conceptual, but not Matlab friendly (infinitely-long vectors)
  • We will derive DTFT as the limit of the DFT as the signal length $N \rightarrow \infty$
$$ \omega = \frac{2\pi}{N}k$$

1.1. The Centered DFT

  • Both $x[n]$ and $X[k]$ can be interpreted as periodic with period $N$, we will shift the intervals of interest in time and frequency to be centered around $n,k=0$


$$-\frac{N}{2} \leq n,k \leq \frac{N}{2}-1$$


  • The modified forward and inverse DFT formulas are
$$ \begin{align*}X_u[k] &= \sum \limits_{n=-\frac{N}{2}}^{\frac{N}{2}-1} x[n]\,e^{-j\frac{2 \pi}{N}kn}\\\\ x[n] &= \frac{1}{N}\sum \limits_{k=-\frac{N}{2}}^{\frac{N}{2}-1}X[k]\, e^{j\frac{2 \pi}{N}kn} \end{align*} $$

1.2. Take it to the Limits


$$X_u[k] = \sum \limits_{n=-\frac{N}{2}}^{\frac{N}{2}-1} x[n]\,e^{-j\frac{2 \pi}{N}kn}, \quad \qquad -\frac{N}{2} \leq k \leq \frac{N}{2}$$


  • Let the signal length $N$ increase towards $\infty$ and study what happens to $X_u[k]$
  • Key fact: No matter how large $N$ grows, the frequencies of the DFT sinusoids remain in the interval


$$-\pi \leq \omega_k = \frac{2\pi}{N}k \leq \pi$$

1.3. Discrete Time Fourier Transform

Forward

  • As $N \rightarrow \infty$, the forward DFT converges to a function of the continuous frequency variable $\omega$ that we will call the forward discrete time Fourier transform (DTFT)


$$\sum \limits_{n=-\frac{N}{2}}^{\frac{N}{2}-1} x[n]\,e^{-j\frac{2 \pi}{N}kn} \quad \rightarrow \quad \sum_{n=-\infty}^{\infty}x[n]e^{-j\omega n}=X(\omega), \quad \qquad -\pi \leq \omega \leq \pi$$


  • Recall: inner product for infinite-length signals


$$\langle x,y\rangle = \sum_{n=-\infty}^{\infty}x[n]y[n]^*$$

  • Analysis interpretation: the value of the DFFT $X(\omega)$ at frequency $\omega$ measures the similarity of the infinite-length signal $x[n]$ to the infinite-length sinusoid $e^{j\omega n}$

Inverse

  • Inverse unnormalized DFT


$$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$$

  • Synthesis interpretation: Build up the signal $x$ as an infinite linear combination of sinusoids $e^{j\omega n}$ weighted by the DTFT $X(\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*}$$
In [2]:
%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)

In [3]:
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)

In [4]:
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

In [5]:
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

In [6]:
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

In [7]:
% 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

In [8]:
% 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

2. DTFT

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

  • Fact: the impulse signal contains all the frequency components with 1


$$X(\omega) = \sum_{n=-\infty}^{\infty}x[n]e^{-j\omega n} = e^{-j\omega 0} = 1$$
In [9]:
%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}$


$$\frac{1}{2\pi} \int_{-\pi}^{\pi}2\pi \delta(\omega - \omega_0) e^{j\omega n}\, d\omega = e^{j\omega_0 n}$$


$$e^{j\omega_0 n} \quad \longleftrightarrow \quad 2\pi \delta(\omega - \omega_0)$$

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*}$$

In [10]:
%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

In [11]:
%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


$$ h[n] = \alpha ^n u[n] \qquad \longleftrightarrow \qquad H(\omega) = \frac{1}{1-\alpha e^{-j\omega}}$$
In [12]:
%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)')

3. DTFT Property

DTFT and Modulation


$$ e^{j\omega_0 n}x[n] \qquad \longleftrightarrow \qquad X(\omega - \omega_0) $$


$$ e^{j\omega_0 n}x[n] =(-1)^n x[n] \qquad \text{when} \quad \omega_0 = \frac{2\pi}{N}\frac{N}{2}=\pi $$
In [13]:
%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) $$
  • same amplitude
  • phase changed (linearly $-\angle\omega m$)
In [14]:
%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

  • Convolution in time domain = multiplication in frequency domain


$$ \begin{align*} x[n] \quad &\longleftrightarrow \quad X(\omega) \\ h[n] \quad &\longleftrightarrow \quad H(\omega) \\\\ y[n] = x[n]*h[n] \quad &\longleftrightarrow \quad H(\omega)X(\omega) \end{align*} $$

4. Filters

Low-Pass Filter

In [15]:
%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

In [16]:
%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

In [17]:
%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

In [18]:
%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

  • The frequency response $H(\omega)$ of the ideal low-pass filter passes low frequencies (near $\omega = 0$), but blocks high frequencies (near $\omega = \pm \pi$)


$$H(\omega) = \begin{cases} 1 & -\omega_c \leq \omega \leq \omega_c \\ 0 & \mbox{otherwise} \end{cases} $$


  • Compute the impulse response $h[n]$ given this $H(\omega)$


$$h[n]\, =\, \int_{-\pi}^{\pi} H(\omega)\, e^{j\omega n} \frac{d\omega}{2\pi}\, =\, \int_{-\omega _c}^{\omega _c} e^{j\omega n} \frac{d\omega}{2\pi}\, = \, \frac{e^{j\omega _c n}\, -\, e^{-j\omega _c n}}{jn}\, = 2\omega _c \frac{\sin(\omega _c n)}{\omega _c n}$$


  • Ideal low-pass filter in MATLAB


$$\text{sinc}(x) = \frac{\sin(\pi x)}{\pi x}$$
In [19]:
%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)')

In [20]:
%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)')

In [21]:
%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)')

5. High-Density Spectrum and High-Resolution Spectrum


$$ x[n] = \cos(0.48 \pi n) + \cos(0.52 \pi n)$$

In [22]:
N = 100;
n = 0:N-1;
x = cos(0.48*pi*n) + cos(0.52*pi*n);

Use 100 samples of $x[n]$

In [23]:
%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]$

In [24]:
%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

In [25]:
%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.

In [26]:
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')