meeting 12 - electrical engineering and computer science · meeting 12 summer 2009 doing dsp...
TRANSCRIPT
Meeting 12
Summer 2009 Doing DSP Workshop
Today:
◮ Motivate Fourier Series to DFT.
◮ Properties of DFT.
◮ Using DFT to compute the IDFT.
◮ Dealing with discontinuities.
Many graphics from TI materials.
The essence of mathematics is not to make simple things complicated, but to
make complicated things simple. — S. Gudder
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 1/54 Thursday – June 11, 2009
Projects
Audio waveform synthesizer –
sine, square wave, triangle, etc.
◮ Darin Rajabian
OFDM.
◮ Yu Wang
Motor speed control lab demon
stration.
◮ Zharori Cong
◮ B.K. Kim
Remote camera using ZigBee.
◮ James Kim
◮ Jordan Adams
Digital Filter Study.
◮ Vindhya Reddy
◮ Joanna Widjaja
Ultrasonic Vision Aide.
◮ Ronald Deang
Not cast in concrete.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 2/54 Thursday – June 11, 2009
Suggested Project Phases
◮ Start up.
◮ Basically define the task, locate useful resources, and verbalize
a possible plan of attack.
◮ Initial Start.
◮ Develop the initial proposal. If applicable, do MATLAB
simulation. Identify required parts and other resources needed
to be purchased. Should have a reasonably clear understanding
of what is to be done and how. Set up goals and time line.
◮ Work in earnest.
◮ Program, build, debug. Repeat.
◮ Completion. Sometime in August.
◮ Demonstration to the workshop.◮ Poster.
Feel free to use ChihWei and myself as resources.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 3/54 Thursday – June 11, 2009
Updated tentative schedule
Week of June 8: One Day Workshop continued.
Tuesday – discuss and decide on project topics.
Thursday – The DFT.
Week of June 15: Exercise 5, controlSTICK ADC, DAC, xfer meas..
Tuesday – FFTs using the controlSTICK.
Thursday – Xilinx 8bit PicoBlaze microcomputer (VHDL).
Week of June 22: Exercise 6, realtime FFT and waveform evaluation.
Tuesday – TBD. KM away.
Thursday – TBD. KM away.
Weeks following —
Lecture and lab complete, focus on projects.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 4/54 Thursday – June 11, 2009
Lab floor to be done next week
The floors in EECS 4341 are scheduled to be stripped and waxed next
week.
Except for the tables we will be getting everything up off of the floor on
Friday.
Hope to keep the lab functional. Will move the computers onto the
tables so as to retain access.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 5/54 Thursday – June 11, 2009
Today
◮ Will attempt to evolve continuous time Fourier Series into the
discrete time Fourier Transform (DFT). Some what hand wavy. Goal
is to develop some intuition. Can you do a development that is
intuitive, simple, direct and rigorous?
◮ Next define the DFT and it’s inverse, present some properties.
◮ Parseval’s theorem. Energy in the input time waveform is equal
energy in the frequency domain. (Not surprising.)
◮ Use of the DFT to compute the IDFT.
◮ Mapping DFT indices to realworld frequencies.
◮ Leakage and it’s mitigation.
We will consider fast algorithms for calculating the DFT next discussion
period.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 6/54 Thursday – June 11, 2009
Recall Fourier Series
Given a periodic function x(t) with period T one can write
x(t) = a0 +
∞∑
k=1
ak cos(2πkt/T)+
∞∑
k=1
bk sin(2πkt/T).
where
a0 =1
T
∫
Tx(t)dt,
ak =2
T
∫
Tx(t) cos(2πkt/T)dt,
bk =2
T
∫
Tx(t) sin(2πkt/T)dt.
Some restrictions apply.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 7/54 Thursday – June 11, 2009
Rewrite in complex form
Replace the sine and cosine with their complex exponential
representations and group terms to get
x(t) =
∞∑
k=−∞
cke−j2πkt/T .
Where
ck =1
T
∫
Tx(t)ej2πkt/Tdt.
Somewhat more concise.
The k/T can be interpreted as the complex exponential’s frequencies,
fk = k/T .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 8/54 Thursday – June 11, 2009
If waveform is bandlimited
Things get a bit hand wavy here. There is no such thing as a band limited
waveform, just models.
Assume that there is negligible energy outside of a band of frequencies
(B, B) Hz.
Then it is claimed that there are finite K such that K/T > B such all
cK = 0. Let K = ⌈B/T⌉. Then
x(t) =
K∑
k=−K
cke−j2πkt/T .
and we only need to calculate 2K values of ck.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 9/54 Thursday – June 11, 2009
Let’s sample
Assume that x(t) is sampled at rate fs . Write the sample times as n/fs .
x(n/fs) =
K∑
k=−K
cke−j2πkn/(Tfs ).
Restrict fs such that T = N/fs where N is integer. Then
x(n/fs) = x(n) =
K∑
k=−K
cke−j2πkn/N .
We now have a finite number of sample values and a finite number of
frequencies.
How to find the ck?
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 10/54 Thursday – June 11, 2009
Guess the answer?
For a given k′ we certainly can write
N−1∑
n=0
x(n)ej2πk′n/N =
N−1∑
n=0
K∑
k=−K
ckej2πk′n/Ne−j2πkn/N .
Many proofs/demonstrations interchange operation order as soon as
possible.
N−1∑
n=0
x(n)ej2πk′n/N =
K∑
k=−K
ck
N−1∑
n=0
ej2π(k′−k)n/N .
The right most sum is the sum of geometric series. Leaving this as an
exercise, the value will be N when k = k′ and zero otherwise. Thus
ck =1
N
N−1∑
n=0
x(n)ej2πkn/N .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 11/54 Thursday – June 11, 2009
Almost there
We now have
x(n) =
K∑
k=−K
cke−j2πkn/N ,
ck =1
N
N−1∑
n=0
x(n)ej2πkn/N .
Recall also that T = N/fs .
If K/T > B to avoid aliasing then K > BT , K > BN/f2.
To avoid aliasing we need B < fs/2. So if B = fs/2 then K ≥ N/2. Let’s
choose K = N/2.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 12/54 Thursday – June 11, 2009
Finally
We now have
x(n) =
N/2∑
k=−N/2
cke−j2πkn/N ,
ck =1
N
N−1∑
n=0
x(n)ej2πkn/N .
Note that e−j2π(N−k)n/N = e−j2π(−k)n/N .
Without thinking too hard about one missing term we can write
x(n) =
N−1∑
k=0
cke−j2πkn/N ,
ck =1
N
N−1∑
n=0
x(n)ej2πkn/N .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 13/54 Thursday – June 11, 2009
This was meant to be motivational
◮ Assumes one has a good background in continuous time.
◮ That one believes “the” sampling theorem.
◮ Band limitness allows Fourier series terms to be dropped. If not
bandlimited then the energy is aliased when we sample.
◮ Note that the 1/N naturally shows up when computing the ck.
◮ Always it is true that T = N/fs .
◮ Discrete time reconstruction from coefficients is analogous with
continue time reconstruction.
◮ The assertion is made that the waveform is periodic outside of the
interval not included!
Rigor, and proper style, was somewhat lacking.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 14/54 Thursday – June 11, 2009
What happens if
the waveform is not band limited?
the waveform has a discontinuity?
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 15/54 Thursday – June 11, 2009
The Discrete Fourier Transform (DFT)
The DFT is most commonly defined as
X[k] =
N−1∑
n=0
x[n]e−j2πkn/N , k = 0,1, . . . , N − 1.
The inverse DFT is
x[n] =1
N
N−1∑
k=0
X[k]ej2πkn/N , n = 0,1, . . . , N − 1.
In practice one often uses (my preference)
X[k] =1
N
N−1∑
n=0
x[n]e−j2πkn/N , k = 0,1, . . . , N − 1.
The associated inverse DFT is
x[n] =
N−1∑
k=0
X[k]ej2πkn/N , n = 0,1, . . . , N − 1.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 16/54 Thursday – June 11, 2009
A few DFT properties
The DFT is linear:
DFT(ax[n]+ by[n]) = aDFT(x[n])+ bDFT(y[n]) = aX[k]+ bY[k].
If x[n],n = 0,1,2, . . . , N − 1, is real then
X[−k] = X∗[k] = X[N − k], k = 0,1,2, . . . , N − 1.
This implies for real valued waveforms that:
For N even : the first N/2+ 1 values define the DFT.
For N odd : the first (N − 1)/2+ 1 values define the DFT.
For x[n] real: for N even let M = N/2 and for N odd let M = (N − 1)/2.
Writing X[k] = |X[k]ejφ[k] we have
|X[k]| = |X[N − k]| and φ[k] = −φ[N − k] for k = 1,2, . . . ,M − 1.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 17/54 Thursday – June 11, 2009
A few more DFT propertiesPeriodicity:
X[k] = X[k+N], ∀k and x[n] = x[n+N], ∀n.
Circular convolution:
DFT−1(H[k]X[k]) = h[n]⊗
x[n]
=
N−1∑
m=0
x[m]h[〈n−m〉N]
=
N−1∑
m=0
h[m]x[〈n−m〉N]
Shifting:
x[〈n−n0〉N] ⇔ Wkn0N X[k]
W−k0nN x[n] ⇔ X[〈k− k0〉N]
where WN = e−j2π/N .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 18/54 Thursday – June 11, 2009
Yet a few more properties
For an arbitrary x[n] of length N :
x[n] ⇔ X[k]
x∗[n] ⇔ X∗[〈−k〉N]
x∗[〈−n〉N] ⇔ X∗[k]
Re{x[n]} ⇔12 {X[〈k〉N]+X
∗[〈−k〉N]}
Im{x[n]} ⇔12 {X[〈k〉N]−X
∗[〈−k〉N]}
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 19/54 Thursday – June 11, 2009
Parseval’s theorem for the DFT
Parseval’s theorem relates the energy in a finite duration time
waveform to the energy in its frequency domain representation.
For the standard definition of the DFT we have
N−1∑
n=0
|x[n]|2 =1
N
N−1∑
k=0
|X(k)|2 .
For the alternate normalization (my preferred) Parseval’s
theorem becomes
1
N
N−1∑
n=0
|x[n]|2 =
N−1∑
k=0
|X(k)|2 .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 20/54 Thursday – June 11, 2009
DFT: 2 N-pt real using 1 N-pt complex
The standard definition of the DFT/IDFT assumes the use of
complex values. Consider the DFT of a set of complex values
z[n] = x[n]+ jy[n] where x[n] and y[n] are real:
DFT(z[n]) = DFT(x[n])+ jDFT(y[n]).
DFT(z∗[n]) = Z∗[N − k].
Recall that x[n] and y[n] are real and that
z[n] = x[n]+ jy[n].
DFT(x[n]) =DFT(z[n]+ z∗[n])
2=
Z[k]+ Z∗[N − k]
2,
DFT(y[n]) =DFT(z[n]− z∗[n])
j2=
Z[k]− Z∗[N − k]
j2.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 21/54 Thursday – June 11, 2009
N/2 complex transform for N real values
For {x[n]}, 0 ≤ n < N , real valued and N even the DFT of the {x[n]} is
XN[k] =
N−1∑
n=0
x[n]e−j2πkn/N ,
=
N/2−1∑
n=0
x[2n]e−j2π2kn/N +
N/2−1∑
n=0
x[2n+ 1]e−j2π(2n+1)k/N .
Write the even numbered sample values as xE[m] = x[2m] and the odd
numbered sample values as xO[m] = x[2m+ 1]. Then
XN[k] =
N/2−1∑
m=0
xE[m]e−j2πkm/(N/2)
+ e−j2πk/NN/2−1∑
m=0
xO[m]e−j2πmk/(N/2),
= XE,N/2[k]+ e−j2πk/NXO,N/2[k].
Because x[n] is real we only need to consider k = 0,1, . . . , N/2.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 22/54 Thursday – June 11, 2009
N real in N/2 complex continued
The positive frequency portion of the DFT of N real values can be
written as a weighted sum of two k = N/2 value transforms. A few
slides back it was shown how an N/2 value complex DFT can
accomplish this task.
Combining the previous slide’s result with the procedure for using an
N value DFT to compute the individual DFTs of two real N valued data
sets gives
XN[k] =XN/2[k]+X
∗N/2[N/2− k]
2+ e−j2πk/N
XN/2[k]−X∗N/2[N/2− k]
j2
for k = 0,1, . . . , N/2. The k = N/2 value is calculated as the difference
of the k = 0 values of the two N/2 value DFTs.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 23/54 Thursday – June 11, 2009
Yet another detail
Assume we wish to use a N/2 element complex array to hold
the frequencies and yet wish to be able to reconstruct the
complete N value transform. There is a problem with where to
put the k = N/2 value.
The input array has N real values and produces N/2 complex
values, k = 0,1, . . . , N − 1. Fortunately the k = N/2 value is real
as is the k = 0 value. Simply use the imaginary part of the k = 0
value to hold the k = N/2 value.
This procedure, using an N/2 value transform to compute the
DFT of a N real valued data set, has an overhead associated
with it. The speed up is not going to be 2 times, but slightly
less. However, it still is generally very much worth doing.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 24/54 Thursday – June 11, 2009
There are many ways to slice bread
I have seen an article developing an algorithm for use with real valued
waveforms that uses an N complex DFT to simultaneously form the
direct transform of N samples of a real valued waveform while also
computing an N value inverse transform of a real valued waveform.
This would be very useful in an FPGA. One could overlap flowing data
through the steps of DFT, processing in the frequency domain and IDFT.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 25/54 Thursday – June 11, 2009
Using the DFT to compute the IDFT
The conventional form of the forward transform is
X[k] =
N−1∑
n=0
x[n]e−j2πkn/N , k = 0,1, . . . , N − 1.
The conventional form of the inverse transform is
x[n] =1
N
N−1∑
k=0
X[k]ej2πkn/N , n = 0,1, . . . , N − 1.
Let n = N −n′, n′ = 0,1, . . . , N − 1.
x[N −n′] =1
N
N−1∑
k=0
X[k]ej2πk(N−n′)/N =
1
N
N−1∑
k=0
X[k]e−j2πkn′/Nej2πN/N
Thus
DFT(X[k]) is Nx[N −n′] where n′ = 0,1, . . . , N − 1.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 26/54 Thursday – June 11, 2009
Second method
Conjugate X[k] and form the DFT.
N−1∑
k=0
X∗[k]e−j2πkn/N =
N−1∑
k=0
N−1∑
m=0
x∗[m]ej2πkm/N
e−j2πkn/N
=
N−1∑
m=0
x∗[m]
N−1∑
k=0
ej2πk(m−n)/N .
N−1∑
k=0
ej2πk(m−n)/N = N for m = n and 0 otherwise.
DFT{
X∗[k]}
= Nx∗[n], n = 0,1, . . . , N − 1.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 27/54 Thursday – June 11, 2009
Third method
Consider the inverse DFT of X[k] = Xr [k]+ jXi[k]
IDFT {X[k]} =1
N
N−1∑
k=0
X[k]ej2πkn/N , n = 0,1, . . . , N − 1
=1
N
N−1∑
k=0
{Xr [k] cos(2πkn/N)−Xi[k] sin(2πkn/N)}+
j {Xr [m] sin(2πkn/N)+Xi[k] cos(2πkn/N)} .
Consider forming the DFT{
Xi[k]+ jXr [k]}
=
N−1∑
k=0
{
Xi[k]+ jXr [k]}
e−j2πkn/N
=
N−1∑
k=0
{Xr [k] sin(2πkn/N)+Xi[k] cos(2πkn/N)}+
j {Xr [k] cos(2πkn/N)−Xi[k] sin(2πkn/N)} .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 28/54 Thursday – June 11, 2009
Third method continued
Comparing the two expressions we see that
x[n] =1
Nswap{FFT[swap(X[k])]}.
Where swap interchanges the real and imaginary parts of a complex
value.(Swap notation from the Wikepedia.)
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 29/54 Thursday – June 11, 2009
Short summary
All three methods:
can easily be accomplished when moving data and results,
require dividing the (inverse) DFT values by N .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 30/54 Thursday – June 11, 2009
Making light
Bill Hoest
“Question: How many signal processing engineers does it take to
change a light bulb?
Answer: Three.
One to Fourier transform the light bulb, one to apply a complex
exponential rotational shifting operator, and one to inverse transform
the removed light bulb. ”
Drawing from the web via Google, joke from the November 2006 IEEE Signal Processing Magazine.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 31/54 Thursday – June 11, 2009
How do we program complex numbers?
As pairs of real numbers. Even indices are the real part and the
odd indices are the imaginary part. For example to access the
kth complex element in the y array,
yr = y[2*k]; yi = y[2*k+1];
How do we conjugate a complex number? Change the sign of
the imaginary part.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 32/54 Thursday – June 11, 2009
Consider a cosine waveformGiven a cosine waveform:
cos(2πft) =ej2πft + e−j2πft
2.
The DFT is linear · · · superposition applies.
Consider only the positive frequency term.
Acquire N samples using a sample rate of fs Hz.
Data set duration is T = N/fs .
Sample times are
tn = 0/fs ,1/fs ,2/fs , . . . , (N − 1)/fs .
The DFT is
X[k] =1
2
N−1∑
n=0
ej2πnf/fs e−j2πkn/N =1
2
N−1∑
n=0
ej2πn(f/fs−k/N) .
When f/fs − k/N = 0 it is clear that X[k] = N/2.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 33/54 Thursday – June 11, 2009
DFT frequency step size
This implies that there is an integer k′ such as f = k′fs/N .
For this frequency it can be shown that X[k] = 0 for all other k
in the given range.
Frequencies that are integer multiples of fs/N are sometimes
termed the eigenfrequencies or, alternatively, analysis
frequencies of the DFT.
What happens if f 6= k′fs/N?
If we define the duration of a data set as T = N/fs then the
frequency step size ∆f between DFT values is
∆f = 1/T = fs/N .
ALWAYS!
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 34/54 Thursday – June 11, 2009
Negative frequencies
Consider k′ = N − k.
X[N − k′] =1
2
N−1∑
n=0
ej2πn[f/fs−(N−k′)/N]
=1
2
N−1∑
n=0
e−j2πnej2πn(f/fs+k′/N)
X[−k′] =1
2
N−1∑
n=0
ej2πn(f/fs+k′/N)
Negative frequencies of the form f = −k′fs/N are also
eigenfrequencies of the DFT.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 35/54 Thursday – June 11, 2009
Naming
We could name DFT analysis frequencies for k = 0,1, . . . , N − 1
as
0, fs/N,2fs/N, . . . , (N − 2)fs/N, (N − 1)fs/N
or
0,−(N − 1)fs/N,−(N − 2)fs/N, . . . ,−2fs/N,−fs/N
or
0, fs/N,2fs/N, . . . ,−(N − 2)fs/N,−(N − 1)fs/N
or
0, fs/N,2fs/N, . . . ,−2fs/N,−fs/N
The last of these namings is the most common.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 36/54 Thursday – June 11, 2009
fftshift — even and odd
Two cases, N even, and N odd.
Let’s see what MATLAB does.
For the N = 8 input values [1 0 0 0 0 0 0 0]
MATLAB’s fftshift gives [0 0 0 0 1 0 0 0]
For the N = 9 input values [1 0 0 0 0 0 0 0 0]
MATLAB’s fftshift gives [0 0 0 0 1 0 0 0 0]
After doing a fftshift the analysis frequencies are:
(-floor(N/2)+[0:N-1])*fs/N.
If you aren’t sure, try it out.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 37/54 Thursday – June 11, 2009
End values
For N even, the range includes
−fs/2 through (fs/2)(N − 2)/N .
For N odd, the range includes
−(fs/2)(N − 1)/N through (fs/2)(N − 1)/N .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 38/54 Thursday – June 11, 2009
Be careful when using linspace
Want 10 samples of one period of a sine wave.
What is wrong with using
sin(linspace(0, 2*pi, 10))?
The last value returned is actually the first value in the
immediately following period!
Use
sin(linspace(0, 2*pi*(N-1)/N, N))
It’s so easy to misuse linspace that you might as well do the
required calculations yourself. If you don’t know how, you
shouldn’t be using linspace anyway.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 39/54 Thursday – June 11, 2009
Summary
Analysis frequencies are integer multiples of 1/T = fs/N .
Only two of T , fs , and N can be chosen independently.
Analysis range is nominally from −fs/2 to fs/2 Hz.
For N even:
there are N/2 nonnegative analysis frequencies.
there are N/2 negative analysis frequencies.
For N odd:
there are (N + 1)/2 nonnegative analysis frequencies.
There are (N − 1)/2 negative analysis frequencies.
After using MATLAB’s fftshift analysis frequencies will be:
(-floor(N/2)+[0:N-1])*fs/N .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 40/54 Thursday – June 11, 2009
Leakage, no leakage
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 41/54 Thursday – June 11, 2009
Recall
Analysis frequencies are integer multiples of 1/T = fs/N .
Only two of T , fs , and N can be chosen independently.
Analysis range is nominally from −fs/2 to fs/2 Hz.
For N even:
there are N/2 nonnegative analysis frequencies.
there are N/2 negative analysis frequencies.
For N odd:
there are (N + 1)/2 nonnegative analysis frequencies.
There are (N − 1)/2 negative analysis frequencies.
After using MATLAB’s fftshift analysis frequencies will be:
(-floor(N/2)+[0:N-1])*fs/N .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 42/54 Thursday – June 11, 2009
Sampling a cosine waveform
Given a cosine waveform:
cos(2πft) =ej2πft + e−j2πft
2.
The DFT is linear · · · superposition applies. Consider only the
positive frequency term. Acquire N samples using a sample rate
of fs Hz. The data set duration is T = N/fs .
Sample times are
tn = 0/fs ,1/fs ,2/fs , . . . , (N − 1)/fs .
The DFT is
X[k] =1
2
N−1∑
n=0
ej2πnf/fse−j2πkn/N =1
2
N−1∑
n=0
ej2πn(f/fs−k/N) .
When f/fs −k/N = 0 it is clear that X[k] = N/2. Otherwise · · · .
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 43/54 Thursday – June 11, 2009
Arbitrary frequency sinusoidal input to DFT
◮ Fix the index value being looked at.
◮ Slowly tune an oscillator from 0 Hz to fs/2.
◮ Plot. xaxis is the frequency of the oscillator and the yaxis
is the magnitude of the selected DFT “bin”.
On the following sheet the complex exponential input was
sampled at 48000 Hz.
The frequency of the top goes from −fs/2 to fs/2.
The magnitude of the value at index k equal to 21 was plotted.
The lower plot expands the plot.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 44/54 Thursday – June 11, 2009
DFT as a filter
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2
x 104
−80
−60
−40
−20
0
dB
N = 1024, k = 21
DFT as a Filter
0 500 1000 1500 2000−80
−60
−40
−20
0N = 1024, k = 21
dB
Hz
Magnitude of bin 21 output as ej2πft sweeps through
frequencies from −fs/2 to fs/2.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 45/54 Thursday – June 11, 2009
Windowing
Select portion of waveform to analyze.
DFT enforces periodicity. . . what happens at the ends?
Weight or shade the data to minimize end effects.
Multiplication in time corresponds to convolution in frequency.
X(k) =
N−1∑
n=0
w[n]x[n]e−j2πkn/N , k = 0,1, . . . , N − 1.
Multiplication in the time domain corresponds to convolution
(filtering) in the frequency domain.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 46/54 Thursday – June 11, 2009
Window functions (shades) used in lab
0 200 400 600 800 10000
0.2
0.4
0.6
0.8
1rectangle
Hamming
Chebyshev
sample index
ampl
itude
Window Functions
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 47/54 Thursday – June 11, 2009
Rectangle (no) window
Plot of samples and the
window function.
Weighted samples shown
recentered at end point
splice.
dB plot of the spectrum
of the windowed samples.
200 400 600 800 1000−1
−0.5
0
0.5
1
Rectangle (No) Window
−500 0 500−1
−0.5
0
0.5
1
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2
x 104
−80
−60
−40
−20
0
dB
Hz
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 48/54 Thursday – June 11, 2009
Hamming window
Plot of samples and the
window function.
Weighted samples shown
recentered at end point
splice.
dB plot of the spectrum
of the windowed samples.
200 400 600 800 1000−1
−0.5
0
0.5
1
Hamming Window
−500 0 500−1
−0.5
0
0.5
1
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2
x 104
−80
−60
−40
−20
0
dB
Hz
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 49/54 Thursday – June 11, 2009
Chebyshev 72 dB window
Plot of samples and the
window function.
Weighted samples shown
recentered at end point
splice.
dB plot of the spectrum
of the windowed samples.
200 400 600 800 1000−1
−0.5
0
0.5
1
Chebyshev 72 dB Window
−500 0 500−1
−0.5
0
0.5
1
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2
x 104
−80
−60
−40
−20
0
dB
Hz
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 50/54 Thursday – June 11, 2009
Windowed DFT as a filter
0 500 1000 1500 2000−100
−80
−60
−40
−20
0
dB
Unwindowed
N = 1024, k = 21
0 500 1000 1500 2000−100
−80
−60
−40
−20
0
dB
HzDFT as a Filter
Chebyshev 72 dB Window
N = 1024, k = 21
Magnitude of bin 21 output as ej2πft sweeps through
frequencies from −fs/2 to fs/2.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 51/54 Thursday – June 11, 2009
Unmasking a low level sinewave
0 0.1 0.2 0.3 0.4 0.5−100
−90
−80
−70
−60
−50
−40
−30
−20
−10
0Raw DFT magnitude (N=256)
normalized frequency
dB
0 0.1 0.2 0.3 0.4 0.5−100
−90
−80
−70
−60
−50
−40
−30
−20
−10
0Hamming windowed DFT magnitude (N=256)
normalized frequency
dB
0 0.1 0.2 0.3 0.4 0.5−100
−90
−80
−70
−60
−50
−40
−30
−20
−10
0Chebyshev windowed DFT magnitude (N=256)
normalized frequency
dB
0 0.1 0.2 0.3 0.4 0.5−100
−90
−80
−70
−60
−50
−40
−30
−20
−10
0Chebyshev windowed DFT magnitude (N=512)
normalized frequency
dB
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 52/54 Thursday – June 11, 2009
Leakage and windowing examples
jçîáÉ jçîáÉ
jçîáÉ jçîáÉ
jçîáÉ jçîáÉ
0 200 400 600 800 10000
0.5
1
ampl
itude Rectangle window
0 200 400 600 800 10000
0.5
1
ampl
itude Hamming window
0 200 400 600 800 10000
0.5
1
ampl
itude Chebyshev window
0 200 400 600 800 10000
0.5
1
bin index
ampl
itude R, H and C windows
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 53/54 Thursday – June 11, 2009
What are the Windowing Costs?
Main lobe width Spreading of energy near a line. . . loss of nearby
resolution.
Line amplitudes are reduced.
Scalloping loss . . . apparent attenuation when line falls midway
between adjacent lines.
May need increased numeric precision. Especially for the more
effective windows.
Doing DSP Workshop – Summer 2009 Meeting 12 – Page 54/54 Thursday – June 11, 2009