ECE 5650/4650 MATLAB Project 2

17
Introduction 1 ECE 5650/4650 MATLAB Project 2 This project is to be treated as a take-home exam, meaning each student is to due his/her own work. The project due date target is Tuesday November 29, 2011. To work the project you will need access to MATLAB and at minimum the signal processing toolbox. Introduction In this second Matlab computer simulation project we will consider: Sampling theory Basic modeling to study aliasing and reconstruction Quantization effects Filter design Filter design basics Group delay Quantization effects in filters Applications Problems Sampling Theory In the first few problems we deal with basic sampling theory and modeling in MATLAB. Consider the A/D- -D/A DSP system shown in Figure 1. In lowpass sampling the continuous-time or analog signal, , is first passed through an anti-aliasing filter to remove signals that lie above the Nyquist frequency . The A/D converter produces a sampled version of its input, in this case the sequence . A digital filter, or some discrete-time system then processes the signal to form the output . Assuming the signal needs to be returned to the continuous-time domain, a D/A converter converts the signal samples to an analog waveform, which needs further analog sig- nal processing to return it to a signal containing just the fundamental spectral translate. To model this system in Matlab, we will make some assumptions and simplifications. To Hz x a t f s 2 xn yn H(z) A/D Anti-aliasing Filter Reconstruction Filter D/A f s f s x a (t) x aa (t) y a (t) x[n] y[n] y ZOH (t) Figure 1: A basic A/D- -D/A DSP system. Hz

Transcript of ECE 5650/4650 MATLAB Project 2

Page 1: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2 This project is to be treated as a take-home exam, meaning each student is to due his/her ownwork. The project due date target is Tuesday November 29, 2011. To work the project you willneed access to MATLAB and at minimum the signal processing toolbox.

IntroductionIn this second Matlab computer simulation project we will consider:

• Sampling theory

– Basic modeling to study aliasing and reconstruction

– Quantization effects

• Filter design

– Filter design basics

– Group delay

– Quantization effects in filters

• Applications

• Problems

• Sampling Theory

In the first few problems we deal with basic sampling theory and modeling in MATLAB. Considerthe A/D- -D/A DSP system shown in Figure 1. In lowpass sampling the continuous-time oranalog signal, , is first passed through an anti-aliasing filter to remove signals that lie abovethe Nyquist frequency . The A/D converter produces a sampled version of its input, in thiscase the sequence . A digital filter, or some discrete-time system then processes the signal toform the output . Assuming the signal needs to be returned to the continuous-time domain, aD/A converter converts the signal samples to an analog waveform, which needs further analog sig-nal processing to return it to a signal containing just the fundamental spectral translate.

To model this system in Matlab, we will make some assumptions and simplifications. To

H z xa t

fs 2x n

y n

H(z)A/DAnti-aliasingFilter

ReconstructionFilter

D/A

fs

fs

xa(t)

xaa

(t)ya(t)

x[n] y[n] yZOH

(t)

Figure 1: A basic A/D- -D/A DSP system.H z

Introduction 1

Page 2: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

begin with we will approximate as a highly over sampled discrete-time signal. The sam-pling rate used to approximate the analog input signal will be denoted . For all of the prob-lems in this section kHz. The analog anti-aliasing filter will be a third order Butterworhlowpass digital filter of the form

>> [ba,aa] = butter(3,2*(fs/2)/96000);

where fs is the sampling rate in Hz used in the A/D. Note the 3dB cutoff frequency of the filter isat the folding or Nyquist frequency, .

Next we model the A/D as a downsampler followed by a bit quantizer. The quantizer isa nonlinearity represented as . Since all signals in the model are discrete, the input to theanti-aliasing filter is really and the output of the anti-aliasing filter is

, so the A/D output is

(1)

The block diagram of the A/D model is shown in Figure 2. In MATLAB the upsampling operation

performed by the Signal Processing Toolbox (SPTB) function

>> y = downsample(x,M);

The sequence is the true discrete-time signal in the DSP system. It nominally enters a signalprocessing function block, e.g., , and returns the sequence . In the sampling theoryproblems we will assume that the DSP function block is simply a through connection, i.e.,

(2)

The output signal (in this case also ) next enters the D/A model. This model is com-posed of an upsampler followed by a filter having a rectangular impulse response. A digital filterhaving a rectangular pulse shape for its impulse response, approximates in the discrete-time sense,the zero-order-hold of a typical successive approximation or flash D/A. The block diagram of thisD/A model is shown in Figure 3. Note that here , since we are assuming a single samplingrate is present. In MATLAB the upsampling operation is performed by the SPTB function

>> y = upsample(x,L);

The quantizer is implemented via the custom function

>> xq = simpleQuant(x,Btot,Xmax,Limit);

xa t fsim

fsim 96=

fs 2

B 1+Q xa t xa n

xaa t xaa n

x n Q xaa Mn =

M

Simplified A/D for Simulation

fsim

fs = f

sim/M

xaa

[n] x[n]B + 1 BitQuantizer

Figure 2: Simple A/D model with a downsampler serving as a sampling device.

x n H z y n

H z 1=

y n x n

L M=

Introduction 2

Page 3: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

The function listing below describes the features of the quantizer.

function xq = simpleQuant(x,Btot,Xmax,Limit)

% xq = simpleQuant(x,Btot,Xmax,Limit)% A simple rounding quantizer for bipolar signals having Btot = B + 1 bits%========================== Inputs =================================%% x = input signal vector to be quantized% Btot = total number of bits in the quantizer% Xmax = quantizer full-scale dynamic range since bipolar the total% range is [-Xmax, Xmax]% Limit = Limiting of the form ‘sat’, ‘over’, ‘none’%%-------------------------- Outputs --------------------------------% xq = quantized output%% Mark Wickert October 2008

B = Btot-1;

x = x/Xmax;

if strcmp(Limit, ‘over’) xq = (mod(round(x*2^B)+2^B,2^Btot)-2^B)/2^B;elseif strcmp(Limit, ‘sat’) xq = round(x*2^B)+2^B; s1 = find(xq >= 2^Btot-1); s2 = find(xq < 0); xq(s1) = (2^Btot - 1)*ones(size(s1)); xq(s2) = zeros(size(s2)); xq = (xq - 2^B)/2^B;elseif strcmp(Limit, ‘none’) xq = round(x*2^B)/2^B;else error(‘limit must be the string over, sat, or none’)endxq = xq*Xmax;

In particular note that the quantizer implements bit rounding ( bits) with afull-scale dynamic range of . Saturation limits the quantizer output to the fullscale

L

Simplified D/A for Simulation

Zero-OrderHold

fs

fsim

= Lfs

yZOH

[n]y[n]y

up[n]

Figure 3: Simple D/A model with an upsampler serving as a reconstructiondevice.

B 1+ Btot B 1+=Xmax– Xmax

Introduction 3

Page 4: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

range (less one quantization level at the top) and overflow emulates the two’s complement arith-metic wrap-around effect. You will explore this in one of the problems below.

Performance of the A/D- -D/A DSP system is limited by the effects of input signal andnoise aliasing, quantization errors, dynamic range, and filter design, to name a few. In what fol-lows you will explore some of these aspects via MATLAB modeling. Being able to view the powerspectral density at various points with this system is important in understanding system perfor-mance. A custom support function for this is simpleSA() which has source listing below:

function [Px,F] = simpleSA(x,N,fs,min_dB,max_dB,color)% [Px,F] = simpleSA(x,N,fs,min_dB,max_dB,color)% Plot the estimated power spectrum of real and complex baseband signals% using the toolbox function psd(). This replaces the use of psd().%% x = complex baseband data record, at least N samples in length% N = FFT length% fs = Sampling frequency in Hz% min_dB = floor of spectral plot in dB% max_dB = ceiling of spectral plot in dB% color = line color and type as a string, e.g., ‘r’ or ‘r--’%%%////////// Optional output variables ///////////////////////////////////% Px = power spectrum estimate values on two-sided frequency axis% F = the corresponding frequency axis values%% Mark Wickert, November 2008

% while length(x) < N% N = N/2;% end

warning offif isreal(x) [Px,F] = psd(x,N,fs);else [Px,F] = psd(x,[],[],N,fs); N = fix(length(F)/2); F = [F(end-N+1:end)-fs; F(1:N)]; Px = [Px(end-N+1:end); Px(1:N)];endwarning on

if nargout == 2 returnend

if nargin == 3 || nargin == 5, plot(F,10*log10(Px))else plot(F,10*log10(Px),color)end

if nargin >= 5

H z

Introduction 4

Page 5: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

axis([F(1) F(end) min_dB max_dB]);end

xlabel(‘Frequency (Hz)’)ylabel(‘Power Spectrum in dB’)grid on

The key ingredient of this function is the SPTB function psd(). To demonstrate the use of thisfunction and a portion of the workflow you will be experiencing as you work through the sam-pling theory problems, consider a simulation sampling rate of kHz. The target sam-pling rate in the system model is say 11.025 kHz (this is a moderate over sampling rate). As aninput we will generate a single sinusoid at 1 kHz plus additive white Gaussian background noise.An operating signal-to-noise ratio (SNR) of 60 dB is set, where here we define the SNR to be

, (3)

with A is the amplitude of the sinusoid and is the variance of the noise process. To make it eas-ier to add white Gaussian noise of prescribed SNR to a single sinusoid, the helper function

y = sinsoidAWGN(x, SNRdB);

was written.

function y = sinusoidAWGN(x,SNRdB)% y = sinusoidAWGN(x,SNRdB)% Add white Gaussian noise to a single real sinusoid%======================================================================%% x = Input signal consisting of a single sinusoid% SNRdB = SNR in dB for output sinusoid%%----------------------------------------------------------------------%% y = Noisy sinusoid return vector%% Mark Wickert, October 2008

% Estimate signal powerx_pwr = var(x);

% Create noise vectornoise = sqrt(x_pwr/10^(SNRdB/10))*randn(size(x));

y = x + noise;

We will utilize simpleSA() to obtain spectrum plots of the input, the anti-aliasing filter out-put, and the output of the quantizer (without downsampling in this case). The command windowinputs are listed below:

>> t = 0:1/44100:1; % time vector for 1s simulation @ fsim = 44.1 kHz>> n = 0:length(t)-1; % time index vector if needed later>> xa = cos(2*pi*1000*t); % A 1kHz sinusoid

fsim 44.1=

SNR A2

2

n2

-------------=

n2

Introduction 5

Page 6: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

>> xan = sinusoidAWGN(xa, 60); % SNR of 60 dB>> [ba,aa] = butter(3,2*(11025/2)/44100); % Simple antialiasing filter>> xaan = filter(ba,aa,xan); % Filter signal + noise>> simpleSA(xan,2^12,44.1,-100,40); % Input spectrum of sig + noise>> holdCurrent plot held>> simpleSA(xaan,2^12,44.1,-100,40,’r’); % Filtered input spectrum>> % Quantize filtered input using 12 bits, Xmax = 1.25, overflow>> simpleSA(simpleQuant(xaan,12,1.25,’over’),2^12,44.1,-100,40,’g’);>> print -depsc -tiff spec_in.eps % export plot to eps graphics file

The corresponding power spectrum plot is given in Figure 4. Notice that the strength of the sinu-soid spectral line remains almost unchanged. This is expected as the signals falls within the passband of the lowpass filter, and there is no overflow in the quantizer, just the introduction of quan-tization noise. The noise floor due to the additive noise at the input changes as a result of the low-pass filter. If the A/D was actually sampling the input (downsampling) the input signal plus noise,in spite of being filtered, the noise will still fold on the frequency axis (alias) down into the

band to some extent. Think about it.

Suppose now that the A/D sample rate is 11.025 kHz. We consider the signal plus noise signalat kHz and send it through a downsample by four and into a 12-bit quantizer.

>> % Utilize xan, the signal + noise input from before>> xd = downsample(xan,4); % downsample the signal by 4

0 fsim 2

0 5 10 15 20−100

−80

−60

−40

−20

0

20

40

Frequency (Hz)

Pow

er S

pect

rum

in d

B

Figure 4: Power spectrum results for a single sinusoid in noise moving from theinput, through an anti-aliasing filter, then through a quantizer (no downsampling).

1 kHz sinusoid remainsapproximately unchanged

Input signal plus noise (blue)

12-bit quantizer output(green)

Anti-alias filtered inputsignal plus noise

fs 44.1=

Introduction 6

Page 7: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

>> xq = simpleQuant(xd,12,1.25,’over’); % quantize the signal>> simpleSA(x,2^12,44.1/4,-100,40); % spectrum following downsample by 4>> hold>> simpleSA(xq,2^12,44.1/4,-100,40,’r’); % the inclusion of 12-bit quant>> print -depsc -tiff spec_out.eps

The plot of the downsampler and quantizer output spectra is shown in Figure 5.

Problems1. In this first problem you will consider quantization of a single sinusoid plus noise, i.e., a

sinusoid in additive white Gaussian noise (AWGN). Assume that kHz and thesinusoid frequency is 1205 Hz. Generate a 1s time record of this signal with the peak ampli-tude set to one. Name this vector xa. Next apply noise to this signal with the SNR set to 100dB. Name this vector xan. Create the quantizer output as

>> xq = simpleQuant(xan,Btot,Xmax,Limit);>> e = xq - xan; % quantizer error sequence

a) Working just in the time domain, observe xan before and after a quantizer. Plot a fewcycles (about 100 samples) of the sinusoid plus noise signal before quantization and thenafter quantization. The cases to consider are given in the Table 1 below.

0 1 2 3 4 5−100

−80

−60

−40

−20

0

20

40

Frequency (kHz)

Pow

er S

pect

rum

in d

B

Figure 5: Power spectrum results for a single sinusoid in noise following thedownsampler and quantizer.

Again the 1 kHzsinusoid is clear

Following quantizationthe overall noise level isonly slightly raised

Quantizer output (red)

Downsampler output (blue)

fsim 96=

Problems 7

Page 8: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

Comment first on the xq plots. The quantization levels will be just barely visible at 8bits and invisible at 14 bits in the time domain. The impact of the limiting (saturation andoverflow) deserve special comment. Which form of limiting is most practical for an A/D? Why? Comment on the error sequences. Are the peak errors what you would expectgiven the input waveform and the quantizer settings?

b) Using simpleSA() plot the power spectral density at the input to the quantizer for theconfiguration of part (a). Then plot the output power spectrum for each of the caseslisted in the Table of part (a). You can overlay plots here if you wish. A good dynamicrange to plot over is -120 to 40 dB. We are particularly interested in how the noise floorchanges. Does the noise floor shift as expected (for the non-limiting cases)?

c) It should be clear from parts (a) and (b) that limiting in the A/D should be avoided. Theanswer is providing headroom in setting up the A/D value relative to the expectedinput level. Headroom (see Figure 6) just refers to setting the A/D saturation/clipping

Table 1: Quantizer simulation results to obtain.

SNR Limit Plots

96 kHz 1205 Hz 100 dB 4 bits 1.5 ‘none’ xq, e=xq-xan

96 kHz 1205 Hz 100 dB 8 bits 1.5 ‘none’ xq, e=xq-xan

96 kHz 1205 Hz 100 dB 12 bits 1.5 ‘over’ xq, e=xq-xan

96 kHz 1205 Hz 100 dB 12 bits 0.75 ‘over’ xq, e=xq-xan

96 kHz 1205 Hz 100 dB 12 bits 0.75 ‘sat’ xq, e=xq-xan

fsim f0 Btot Xmax

Xmax

Noise Floor

Limiting/Distortion

0 dB

+M dB

-N dB

HeadroomX dB

A/D Dynamic Range

System SNR

Nominal Input Level

Figure 6: A/D SNR and dynamic range relationship assuming quantization noisedominates.

Problems 8

Page 9: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

point X dB above the expected signal level. In parts (a) and (b) the signal consisted of asingle sinusoid of unit amplitude plus a small amount of noise. As a final experimentinvolving quantization, start with row three of the table from part (a), but change‘over’ to ‘none’. Collect data on the noise floor level as is increased from 1.0up to an effective headroom level of 15 dB. How many effective A/D bits are lost as aresult of the 15 dB headroom? The formula

(4)

from the notes/book may be useful in arriving at how many bits are lost. Note here.

2. Now we are ready to assemble an end-to-end model starting with the signal plus noisesource and ending with a reconstruction filter. Start with kHz, Hz,SNR = 110 dB, and bits. The clipping mode should be set to ‘sat’.Generate 1s of data as before. Set the downsampler up so that the actual sampling rate is

Hz.

a) Observe the output of the A/D model, denoted , in both the time domain using thestem function and in the frequency domain via the power spectrum (simpleSA). Arethe results what you would expect? Is any aliasing present?

b) Construct the D/A model by first upsampling the signal by the factor L, toachieve the original rate. You may denote this signal as . Observe the outputsignal in the time domain and frequency domain as in part (a).

c) Next filter the upsampled signal with a zero-order-hold (ZOH) digital filter havingimpulse response

(5)

Recall that in practice this filtering action is accomplished in the D/A. Since this is anFIR filter, it is easy to load the coefficients into filter(). Again observe the outputsignal, , in the time domain and frequency domain as in part (a). At this pointyou should switch back to using plot() instead of stem(). The filtering action of theZOH should be evident in the spectrum plot, namely the presence of spectral zeros. Toverify this, overlay a plot of the magnitude response of the ZOH filter along with thespectrum plot of the ZOH output.

d) The final step is to implement a digital filter representation of the analog reconstructionfilter. Here the design is an Elliptic filter of the form

>> [br,ar] = ellip(9,1,80,2*(fc)/fsim);

Choose the filter value accordingly. Plot the filter magnitude, phase, and group delay

Xmax

SNRQ 6.02B 10.8 20log10

Xmax

x----------- –+=

B Btot 1–=

fsim 96= f0 1206=Xmax 1.5= Btot 16=

fs 8000=

x n

y n x n =fsim yup n

h n 1, 0 n L 1– 0, otherwise

=

yZOH n

fc

Problems 9

Page 10: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

response and the pole-zero plot for your filter. Note that you can do all of this usingfvtool(). Finally observe the output signal, , which approximates , in thetime domain and frequency domain. In the time domain you should see a filter transientand then a nice reconstructed output. In the frequency domain you should see strongattenuation of the sampling related harmonics. What are some pros and cons associatedwith this high order reconstruction filter? Note that in the present model, this filterwould be implemented in the analog domain.

Comment on Frequency Selection

You may have noticed that the sinusoid frequencies used in this section are not simple numberslike 1000 or 4500 Hz. When working with nonlinearites such as a quantizer, in combination withspectral analysis, harmonic relationships between the sampling rate clock frequency, the power oftwo period of the FFT based spectrum analyzer, and the period of the sinusoid itself, make thegeneration of spurious signals (spurs) a strong possibility. In real systems this can occur too.Dither signals are sometimes employed to reduce the generation of these spurs. The simulationenvironment is special since synchronous signals and sampling clocks occur readily. In practicalscenarios this is less likely, since the clocks contain jitter and the signals flowing through a systemare generated from independent clock sources. To see spurs try replacing the 1206 Hz signal with1000 Hz or even 1200 Hz.

Filter DesignIn this section we will investigate filter design using MATLAB’s filter design tools. We will con-sider designs based on amplitude response requirements as shown in Figure 7. In this section we

will also integrate the use of MATLAB’s filter design and analysis (FDA) tool together with a studyof group delay and pulse distortion.

ya n ya t

w

ω (rad)

F (Hz)

wp

ωp

ωs

ws

Fp

Fs

0

0

0

1

π

fs/2

-Rs

-Rp

0

Gai

n (d

B)

-Rp/2

Rp/20Alternate definition

Figure 7: Digital filter design based on amplitude response requirements.

Problems 10

Page 11: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

The filter design tools in MATLAB are contained in the Signal Processing Toolbox® (SPTB)and also in the new DSP System Toolbox® (DSPSTB). The SPTB contains the core filter designfunctions, including the core functionality of FDA tool. When the DSPSTB is present anexpanded set of filter design functions is available, as well as finite precision arithmetic modelingand design, multi-rate filters, adaptive filters, various filter topologies, and more. The FDA toolGUI expands accordingly when the additional toolbox is present. A screen-shot of the FDA GUIis shown in Figure 8. This tool can be started by entering fdatool at the command line.

3. Command line functions can also be used for filter design. In this problem you will use thecommand line function to first obtain the filter and the obtain the actual IIR filter coeffi-cients for Butterworth, Chebyshev type I, Chebyshev type II, and elliptic lowpass filterdesigns. Filter order determining functions are:

>> [N, Wn] = buttord(Wp, Ws, Rp, Rs);>> [N, Wn] = cheb1ord(Wp, Ws, Rp, Rs);

Figure 8: The FDA tool GUI showing particular the design of a 51-tap linearphase FIR filter.

Problems 11

Page 12: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

>> [N, Wn] = cheb2ord(Wp, Ws, Rp, Rs);>> [N, Wn] = ellipord(Wp, Ws, Rp, Rs);

where N is the filter order and Wn is the filter cutoff frequency. In MATLAB’s filter designnotation recall that 0 < W < 1 corresponds to . The frequency and gain param-eters in dB entered into these functions, corresponds to the desired amplitude response maskof Figure 7. With the filter order and cutoff frequency determined, the digital filter coeffi-cients can be obtained using the corresponding design functions:

>> [num, den] = butter(N, Wn);>> [num, den] = cheby1(N, Rp, Wn);>> [num, den] = cheby2(N, Rs, Wn);>> [num, den] = ellip(N, Rp, Rs, Wn);

a) Design digital filters (two in total), using any two of the filter design functions listedabove, starting with a determination of the filter order. The amplitude response require-ments, relative to a sampling rate of 96 kHz, are dB, dB,

kHz and kHz. Obtain and record the filter order, N, for each design,the filter coefficients, numerator and denominator, and plot the amplitude response in dBversus analog frequency F in (kHz) for . When plotting the filter gain re-scale the amplitude axis so the minimum gain is no smaller that -100 dB. Similarly plotthe phase, and group delay. Also plot the pole-zero plot for each filter. Note: Once youhave the filter coefficients you can use fvtool() to do all of the plotting, including theproper frequency axis scaling via

>> fvtool(num,den,’fs’,96) % The 96 makes the frequency units kHz

You might notice errors in the pole-zero plots and errors in the group delay, dependingupon the filter types you choose. MATLAB does make numerical errors. You may want torefer to Chapter 9 of the notes for an understanding of the characteristics of the filtertypes. In particular the Butterworth and Chebyshev type filters have all of their zeros at

.

b) Using the same amplitude response requirements as part (a), design an eqirriple FIR fil-ter, this time using FDA tool (see the settings of Figure 8). Take a screenshot of the finalFDAtool setting for your soution. What do you think of the complexity of this filter rela-tive to say the elliptic design of part (a). Which design is more desirable from the groupdelay characteristics?

c) For the FIR filter of part (b) create plots as was done in part (a). Does the filter have lin-ear phase? Constant group delay? From the pole zero plot is it obvious that the filter haslinear phase? The plots can be created directly in FDAtool or you can export the filtercoefficients to the MATLAB workspace and once again use fvtool, if you wish.

0

Rp 1= Rs 80=Fp 20= Fs 25=

0 F Fs 2

z 1–=

Problems 12

Page 13: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

Coefficient Quantization

4. In this problem you will revisit the FIR filter designed in Problem 3b. Assume that the filtercoefficients have been exported from FDA tool to the MATLAB workspace as vector variableb. You will use simpleQuant() to quantize the coefficients and compare filter character-istics before and after quantization. If the MATLAB DSPSTB was readily available to all, wecould use its quantization capability here as well.

a) From the b coefficient vector corresponding to the filter of Problem 3b, place the quan-tized coefficients in vector bq16 as follows

>> bq16 = simplequant(b,16,1.0,’sat’); % 16-bit coefficient quantization

First observe whether of not it is reasonable to quantize the coefficients with. Is there any unnecessary loss of precision?

b) Compare the two filters in terms of magnitude response in dB, phase, group delay, andpole-zero plots. Overlay plots are the best way to see the impact of quantization. Thefvtool() function makes this comparison very easy, as you can load multiple filtersin the function call, e.g.,

>> fvtool(b,1,bq16,1,’fs’,96); % a & b vectors for two filters + 96k fs

Is linear phase maintained in spite the coefficient quantization? Why or why not?

Application: D/A ZOH Droop Compensation

5. In [1] Leland Jackson presents two simple filters that can be used to compensate for the fre-quency domain droop introduced by the ZOH filtering action of many D/As. Simple FIRand IIR design are given below:

(6)

Recall that the D/A model described in Figure 3, contains in reality an analog ZOH filter.Each of the filters described above can be implemented prior to the D/A, in the discrete-timedomain, to provide gain flattening for output analog frequencies on the interval .Using MATLAB plot the magnitude response in dB of the ZOH filter, each of the compensa-tion filters, and the cascade of each of the compensation filters with the ZOH response. Thefrequency axis should be scaled to the normalized sampling rate, ,where here F denotes the analog frequency axis in Hz (recall from the text/notes rad/s). Make note of the gain droop at ( ) both before and after the inclusion ofthe compensation filters. You should find that both filters work quite well.

To properly model the cascade you need to jointly manage frequency responses in both thediscrete-time domain and the continuous-time domain, since the droop compensation filter

Xmax 1.0=

HFIR z 116------ 1– 18z

1–z

2––+ =

HIIR z 9

8 z1–

+----------------=

0 fs 2

f F fs 2 = = 2F=

fs 2 f 0.5=

Problems 13

Page 14: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

is discrete-time and the ZOH is a continuous-time filter:

Application: RADAR/SONAR Target TrackingIn Project 1 a pulse train generator function was created. In this problem we will use the pulsetrain function to create a baseband RADAR waveform. A full complex baseband model could alsobe created, but to keep things simple, it will be left out of this problem. The RADAR waveformenters a channel (filter), which has a time-varying impulse response to model moving targets(reflectors) that the radar signal impinges on, with a portion of the signal being reflected back tothe RADAR receiver, collocated with the RADAR transmitter.

At baseband we model the channel/targets, as having impulse response

(7)

where m is the independent variable for evaluating the impulse response at time n. The sum runsover K targets with being the round-trip path gain, the round-trip phase, and the round-trip time delay in samples. The path gain should actually be a function of distance,which here is in terms of path delay, but this added complexity is ignored for now. To further sim-plify matters, we also assume that the gain is a constant and the phase shift is zero. Thephase shift term would be particularly important if we were modeling a complex carrier with Dop-pler shifts.

In the simplified model we now have

(8)

A MATLAB function which allows signals to be filtered by the time-varying impulse responsemodel given above is listed below

function y = targetSim(x,alpha,dStart,aSlope,dMax,dMin)% y = targetSim(x,alpha,dStart,aSlope,dMax,dMin)%%=================== Inputs ===========================================%% x = input signal to be filtered% alpha = vector of target gains% dStart = vector of target location start values as sample delay% aSlope = slope of target motion as samples moved per time step sample

Hc z D/C

fs

z ej

ej2f j j2F j2 f fs =

HZOH j y n yc t

0 f 2------ 0.5=

h m n k n ejk n

m dk n – k 1=

K

=

k n ejk n dk n

k n

h m n k m dk n – k 1=

K

=

Problems 14

Page 15: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

% dMax = maximum target round-trip delay range% dMin = minimum target round-trip delay range%%---------------------------------------------------------------------%% y = target filter return or output%%---------------------------------------------------------------------% Mark Wickert October 2008

y = zeros(size(x));K = length(alpha);x_vec = zeros(1,dMax + 1);

for n=1:length(x) h = zeros(1,dMax+1); for k = 1:K dIdx = max(min(round(dStart(k) + (n-1)*aSlope(k)), dMax),dMin); h(dIdx) = h(dIdx) + alpha(k); end x_vec = [x(n) x_vec(1:end-1)]; % load tapped delay line y(n) = h*x_vec’; % filter output is inner product of h with x_vecend

This model allows multiple targets having simple linear motion to be created. Linear motionmeans that the target has initial round-trip delay offset of dStart and delay slope of sam-ples/sample, i.e.,

. (9)

The motion of each target is constrained to lie between dMin and dMax, which logically fitswithin the pulse repetition period of the RADAR pulse train.

To demonstrate the operation of the target simulator consider the transmitted pulse train

>> [x,n] = discrete_pulse_train(10,500,0,0,10000);

Here the period is 500 samples, so we must choose both dMin and dMax to lie inside [0, 500].The pulse sent into the channel each period is 10 samples wide. In an actual application a carrierwave either radio frequencies (RADAR) or ultrasound (SONAR) would also be present. We nowconstruct a target composed of a fixed object with delay 240 samples (120 sample delay one-way)and a moving target that starts with a 100 delay time and accumulates 300 more samples of delayover 8000 samples. We set the min and max delay values at 100 and 400 respectively. The slopeneeded for the moving target is 300/8000 = 0.0375.

>> y = targetSim(x,[1.0 1.0],[240 100],[0 0.0375],400,10);

The Matlab plotting function strips() is useful in plotting the received waveform a verticalstack of traces, one per pulse period in this case, so that the time-varying nature of the target(s)/channel can be visualized.

>> strips(y,500)>> xlabel(‘Samples within Strip’)

aslope

dk n dstart aslopen+=

x n

y n

Problems 15

Page 16: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

>> ylabel(‘Amplitude within Strip & Strip Index’)>> print -depsc -tiff SONAR1.eps

The results are shown in Figure 9. If noise is present on the received signal, an optimum filter forprocessing the received signal would be a filter having pulse shape matching the transmitted sig-nal, in this case a pulse of width 10 samples.

6. Repeat the example above where strips() was used to plot the receiver output. Now youwill matched filter the output y to form z. Design the matched filter to have unity gain at dc.Display the output now using MATLAB’s waterfall plot function. With waterfall() youcan get a 3D plot as shown in Figure 10. Note that the x, y, and z axes can be scaled to yourown choosing. In particular you can scale the axis corresponding to one period of the pulsetrain, to have units of distance. In Figure 10 the axis is scaled as if the full range distance is1m. Reproduce Figure 10 by manipulating the z vector data and incorporating x and y axisscale vectors into the function call waterfall(x_vec,y_vec,z_matrix). Also off-

0 50 100 150 200 250 300 350 400 450 500

9500

9000

8500

8000

7500

7000

6500

6000

5500

5000

4500

4000

3500

3000

2500

2000

1500

1000

500

0

Samples within Strip

Am

plitu

de w

ithin

Str

ip &

Str

ip In

dex

Figure 9: Plot of the channel output for a fixed target at a delay of 240 sam-ples and a moving target with slope 0.0375 samples/sample.

Problems 16

Page 17: ECE 5650/4650 MATLAB Project 2

ECE 5650/4650 MATLAB Project 2

set the distance axis so that the peak of the matched filter is calibrated to display theintended delay/distance.

c) Add noise to y such that

>> r = y + 0.25*randn(size(y));

Now matched filter this signal and again display the results using a waterfall plot as inpart (b).

Bibliography/References[1] L.B. Jackson, Digital Filters and Signal Processing, third edition, Kluwer, Boston, MA,

1996.

[2] J. H. McClellan, C.S. Burrus, A.V. Oppenheim, T.W. Parks, R.W. Schafer, and H.W.Schuessler, Computer-Based Exercises for Signal Processing Using MATLAB 5, PrenticeHall, New Jersey, 1998.

[3] S.K. Mitra, Digital Signal Processing: A Computer Based Approach, third edition, Mc GrawHill, New York, 2006.

[4] S.K. Mitra, Digital Signal Processing Laboratory Using MATLAB, Mc Graw Hill, NewYork, 1999.

[5] M.J. Smith and R.M. Mersereau, Introduction to Digital Signal Processing: A ComputerLaboratory Textbook, John Wiley, New York, 1992.

0 0.2 0.4 0.6 0.8 1

0

5

10

15

20

0

0.5

1

Scaled Distance (full range 1m)

Period N

umber

Am

plitu

de

To re-orient a 3D plot click on this tool in

Figure 10: Waterfall plot of the matched filter channel output scaled so that thefull scale range corresponds to 1m range offset correction.

The matchedfilter hasconverted therectangles totriangles

Bibliography/References 17