Docsity

Lab 2: Sampling - Digital Signal Processing | ECE 158, Lab Reports of Digital Signal Processing

Toggle sidebar
bg1
Copyright 2006 Bob L. Sturm
Lab 2
Sampling
0. Preface
Now that you have learned MATLAB to a sufficient and necessary level, in this
lab you will use it to explore sampling.
Your lab report should answer all questions in all sections.
1. Are you down with DFT? How about the FFT?
The DFT
€
X[k]
of a finite-length sequence
€
x[n]
of length
€
N
, defined over
€
0≤n≤N−1
, is given by:
€
X[k]=x[n]e−j2
π
kn /N, 0 ≤k≤N−1
n=0
N−1
∑
. (1)
The sequence
€
x[n]
is created by sampling a continuous signal
€
xa(t)
at a
sampling rate of
:
€
x[n]=xa(nTs)
, for some range of
€
n
. The significance of
the DFT is more apparent written in the following way:
€
X[k]=xa(nTs)e−j2
π
kFs
NnTs, 0 ≤k≤N−1
n=0
N−1
∑
. (2)
It can be seen in equation (2) that the samples of
€
x[n]
are being correlated with
N samples of N sampled complex sinusoids having different angular frequencies.
The value of
€
X[k]
is the (complex) amplitude of the
€
kth
“frequency bin”; the
corresponding frequency of this bin in radians per second is given by
€
ω
k=2
π
kFs
N
,
when the sampling rate is in Hz. For instance
€
X[0]
is the zero-frequency, or D.C.,
term;
€
X[1]
is the frequency at
€
ω
1=2
π
Fs
N
Hz, and so on. For real signals
€
X[k]
is
only “meaningful” for
€
0≤k≤N/2 +1
for N even. All other
€
k
signify negative
frequencies; their values for can be inferred from the positive ones.
pf3
pf4
pf5

Partial preview of the text

Download Lab 2: Sampling - Digital Signal Processing | ECE 158 and more Lab Reports Digital Signal Processing in PDF only on Docsity!

Lab 2

Sampling

0. Preface

Now that you have learned MATLAB to a sufficient and necessary level, in this lab you will use it to explore sampling. Your lab report should answer all questions in all sections.

1. Are you down with DFT? How about the FFT?

The DFT € X [ k ] of^ a^ finite-length^ sequence € x [ n ] of^ length € N , defined over € 0 ≤ n ≤ N − 1 , is given by: € X [ k ] = x [ n ] e −^ j^^2 π kn^ /^ N^ , 0 ≤ k ≤ N − 1 n = 0 N − 1

∑.^ (1)

The sequence € x [ n ] is created by sampling a continuous signal € xa ( t ) at a sampling rate of € Fs = 1 / Ts : € x [ n ] = xa ( nTs ), for some range of € n. The significance of the DFT is more apparent written in the following way: € X [ k ] = xa ( nTs ) e − j 2 π kF Ns nTs , 0 ≤ k ≤ N − 1 n = 0 N − 1

∑.^ (2)

It can be seen in equation (2) that the samples of € x [ n ] are being correlated with N samples of N sampled complex sinusoids having different angular frequencies. The value of € X [ k ] is the (complex) amplitude of the € k th “frequency bin”; the corresponding frequency of this bin in radians per second is given by € ω k = 2 π kFs N

when the sampling rate is in Hz. For instance € X [0] is the zero-frequency, or D.C., term; € X [ 1 ] is the frequency at € ω 1 = 2 π Fs N Hz, and so on. For real signals € X [ k ] is only “meaningful” for € 0 ≤ k ≤ N / 2 + 1 for N even. All other € k signify negative frequencies; their values for can be inferred from the positive ones.

You will now perform your first DFT using the fast Fourier transform (FFT)—which is an implementation of the DFT. 1.1 Sample a sinusoidal signal with amplitude 1 and frequency of 128 Hz at a sampling rate of 2,048 Hz indexed by € 0 ≤ n ≤ N − 1 , where € N = 32. That means sample the following: € x [ n ] = sin( 2 π 128 n / 2048 ), (3) at the points n=[0:31]. Plot it using stem and include your code and plot in your report. 1.2 Now find the DFT of the sequence created in 1.1 using the fft MATLAB routine (just call fft with the sequence as an argument). Plot the magnitude spectrum of the result, abs(X), versus the corresponding frequency (in Hertz and not k). Plot only the frequencies between 0 and the Nyquist frequency (Fs/2). Your plot should look like Figure 1. That means use stem instead of plot. Include your code. Figure 1: The magnitude spectrum of a real 128 Hz sinusoid sampled at 2048 Hz over € 0 ≤ n ≤ 31 1.3 What is the phase in pi radians at the frequency 128 Hz? Do this using the angle routine on the relevant value of X[k]. Why does this answer make sense?

Figure 2: A Leicester County worker listens for spectral leakage Now we are going to perform a trick. If the frequencies of the DFT are integer multiples of € fk = kFs N , one way to make the spacing of the bins closer together is to increase € N. So instead of taking 32 samples of the sinusoid in equation (3), we can generate 512 samples, which gives a frequency spacing of 4 Hz. Theoretically we could then get rid of spectral leakage for our sinusoids of 220 Hz because it falls right in bin number 56. Let’s prove this now. 1.8 Create a 512-length sequence of the sinusoid in equation (3) at a frequency of 220 Hz, amplitude of 1, and a sampling rate of 2,048 Hz. As in 1.2 find the DFT of this signal and plot the magnitude of the result versus frequency. Include this plot in your report. Problem solved? Well what if we only had the 32-sample version created in 1. and there was no way to extend it or get more data? We will return to this problem in a later lab called “windowing.” Through learning the FFT implementation of the DFT you have taken your first steps to understanding not only the frequency domain representation of signals, but also the concept of sampling. When you evaluate some continuous function at uniformly spaced “samples,” you are in effect sampling that signal. To gain a

much clearer understanding of this process, let’s move to the next portion of this lab.

2. Sampling

Much more than walking through Costco TM on food promotion day, sampling is essential to any digital system. Sampling, and specifically the Shannon-Nyquist sampling theorem, makes it possible to represent a continuous signal exactly with a finite number of observations of it. Did I say “ exactly ”? I meant, exactly , meaning no difference, no error, nothing, nada, exactamundo. Let’s see how! 2.1 Sample the sinusoid € x ( t ) = cos( 2 π ft ) having frequencies of f=100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 Hz, at a sampling rate of 1 kHz. Plot using stem each signal over € 0 ≤ n ≤ N − 1 , where N=128. Use subplot to make it look fancy! Include your code. 2.2 What do you notice about these plots? For instance, can you distinguish between the sinusoids that have frequencies of 400 and 600 Hz? What is going on when f=1000 Hz? 2.3 For each of the sinusoids sampled in 2.1, evaluate its DFT and plot the normalized magnitude spectrum with stem. Normalize the magnitude spectrum by dividing it with the largest magnitude. Include your figure and code. 2.4 What do you notice about these plots? For instance, can you distinguish between the sinusoids that have frequencies of 400 and 600 Hz? At what frequency is most of the energy located for the sampled sinusoid have f=700? Hopefully by now you have come to realize that the sampling rate has dire consequences for the output if you are unsure as to the frequency content of the continuous signal being sampled. As above, a 700 Hz sinusoid produces the same output as a 300 Hz sinusoid when both are sampled at 1000 Hz. And God forbid if you try to sample a signal having a frequency that is the same as the sampling rate—all you get in that case is a constant!