EEL 6502 ‑ DIGITAL SIGNAL PROCESSING I

Computer Assignment #2 (due date: See Course Homepage)

 

I.  Basic Sampling Theory

 

Background Reading:  Oppenheim & Schafer: Chapter 4.

 

Overview:  Aliasing and Reconstruction, the two basic principles of sampling can be illustrated by using MATLAB.   Since it is not possible to have an analog signal in MATLAB, simulation of the real‑time axis ‘t’ is needed.  The dt of the simulation should therefore be distinguished from the sampling period Ts.  

 

Demonstration Example:  To simulate an analog signal, a sampling rate that is at least five times the highest frequency in the analog signal, should be used.  Thus there will be two sampling rates in the problem ‑ one for the actual sampling under study and the other for simulating the continuous‑time signals.  A second issue is how to display the Fourier transform of the continuous‑time signals.  Again, this can only be simulated.  The following M‑file should be used to plot the analog spectra.

 

function fplot (xa,dt)

%

%  xa is the analog signal

%  dt is the sampling interval for the simulation of xa(t)

%

L = length (xa);

Nfft = round(2.^round(log2(5*L)) );            % next power of 2

Xa = fft (xa,Nfft);

range = 0:(Nfft/4);

ff = range/Nfft/dt;

plot(ff/1000, abs (Xa(1+range)))

title('CONTINUOUS‑TIME FOURIER TRANSFORM (MAG)')

xlabel('FREQUENCY (kHz)'), grid

end

 

Problem I:

 

(a)   Signal Generation

 

i)      Generate a simulated analog signal that is a cosine wave with analog frequency f0 = 2 kHz.

        Take fsim , the 'simulation sampling frequency' to be 80 kHz.

                    x(t) = cos(2pf0 t + j)    ,  0 £ t £ T (T is the time duration)

Take the phase to be arbitrary and choose T such that you generate about 400 samples of the analog signal.

 

ii)     Plot the time signal with plot so that the samples are connected.  Label your time axis with the true analog time.

 

iii)    Plot the Fourier transform of this signal using fplot in the example above.

(b)   A/D Conversion

 

The A/D converter takes samples spaced by Ts.  It is simulated by taking a subset of the samples generated for x(t).  If n is the ratio of the simulation frequency and the A/D sampling frequency, then every nth sample of the x(t) vector can be selected to simulate the A/D conversion.

 

i)      Plot the resulting discrete‑time signal when the sampling frequency is 8 kHz.

 

ii)     Compute the DTFT of the discrete‑time signal and observe how it is related to the Fourier transform of the analog signal in part (a)(iii).

 

(c)   Design a Reconstruction Filter

 

The D/A section consists of two parts:  a spacing of the discrete‑time samples by the sampling time interval Ts, followed by an analog reconstruction filter.  The actual D/A conversion phase consists of creating an analog signal xh(t) from the discrete time signal x[n] and then filtering with the Chebyshev filter.  The MATLAB vector simulating the analog signal xh(t) is reconstructed from the discrete time signal vector x[n] by inserting a number of zeros between each sample.  The number of zeros depends on the ratio fsim/fs.

 

i)      Carry out this zero insert operation on the signal generated in part (a) and sampled in part (b).  Then apply the Chebyshev reconstruction filter to get the smoothed output xr(t). 

 

ii)     The reconstruction filter will, of course, have to be a digital filter to simulate the true analog filter.  Use the MATLAB filter design function cheby2 to design this filter:

                    [b, a] = cheby2(9, 60, fcut)

This will design a ninth‑order filter with 60‑dB of stopband attenuation.  The analog cutoff frequency has to be at 0.5fs.  For MATLAB, this has to be scaled to fcut = 2*(fs/2)/fsim.

 

iii)    Now use freqz to plot the frequency response of the simulated reconstruction filter.  To get its true analog cutoff frequency on the plot, you must remember that this is a digital filter where the frequency w=p is mapped to 0.5fsim.

 

iv)    Plot the reconstructed continuous-time output signal xr(t) and its Fourier transform.

 

(d)   Test for Aliasing

 

Now try a number of different input signal frequencies:  f0 = 7 kHz and 10 kHz.  Sketch and compare the input and output Fourier transforms and examine the effects of aliasing.

 


II.   Rate Changing 

 

Background Reading:  Oppenheim & Schafer: Section 4.6.

 

Overview:  Multirate processing brings the unique advantages to signal processing because certain filtering applications can be performed much more efficiently using multi-rate implementations.  Decimation and interpolation are used for changing the sampling rates by an integer factor.  Rate changing for non-integer factors can be obtained by using combinations of decimation and interpolation. 

 

In the problem, we will study how decimation may cause aliasing, how a pre-decimation filter may prevent aliasing (at a cost of some loss of information, however), and changing the sampling rate by a non-integer factor. 

 

PROBLEM II:

 

(a)        Decimation of a Two‑Component Signal

 

Generate a signal that is a sum of two sinusoidal components, one with a frequency of 0.01 times the sampling frequency (and amplitude = 1) and the other with a frequency of 0.03 times the sampling frequency (and amplitude = 0.3).  Plot this as a continuous function (plot) and as discrete samples (stem) for 96 samples.  Identify the cycles by eye.

 

i)      Decimate the signal obtained above by a 4:1 factor (M=4) and compare the spectra of the original signal and the decimated signal using a 256-point dtft.  Repeat for a 6:1 decimation factor  (M=6).

 

ii)     Decimate 6:1, but prior to decimation, low pass filter the input sequence.  This low pass filter serves as an anti-aliasing filter; you may use the Butterworth filter, butter in MATLAB (choose wc=p/M=p/6). Compare the decimated output to both the original input signal and the output of the low pass filter. (Note: Since the sampling rate is 33.3 times the highest signal frequency, no aliasing effect will be observed by 4:1 or 6:1 decimation.)

 

(b) Interpolation and Decimation

 

i)        Interpolation is achieved by upsampling and filtering with a lowpass filter.

        Generate the following signal with 24 samples.

                    z = 0.8*cos(2p(24/240)n)

 

Upsample the signal x(n) by a factor of  L=4 and then low pass filter the resulting sequence x(n/4).  Downsample the output of the filter by a factor of M=6 to obtain y(nM/L). The low pass filter between the upsampler and downsampler should have a gain (L)=4 and ωc=min [p/M,p/L].   

Compare the sequences the outputs of the filter and the downsampler.  Compare the input and output frequency spectra and see the effect of rate increase or decrease by a non-integer factor.

 

ii) Repeat part (i) with L=6 and M=4.

 

iii) In parts (i) and (ii), determine the rate increase/decrease.