CHAPTER 2

 

 

 

2.1

 

Problem

 

A signal whose spectrum is shown in Figure P2.1 is to be sampled so that no

aliasing results. Determine the minimum sampling rate that can be used to

sample the signal. If the sampling rate must be 8 KHz, determine the type and

the cutoff frequency of the anti-aliasing filter.

 

 

Figure P2.1 Magnitude spectrum for the signal in Problem 2.1

 

 

Solution

 

The highest frequency, fmax, as determined from Figure P2.1 is 5 KHz. Therefore the sampling frequency, fs, should be greater than 10 KHz. If the sampling frequency is to be 8 KHz, the low pass anti-aliasing filter cutoff frequency must be less than 4 KHz.

 

 

 

2.2

 

Problem

 

Redraw the frequency spectrum for the signal in 2.1 using the digital frequency

as the horizontal axis. Let the sampling frequency be 8 KHz. Determine

the analog frequencies for the digital frequencies 0, p/4, p/2, 3p/4, and p

radian.

Solution

 

Draw Figure P2.1 with magnitude 0 for frequencies 4 KHz to 5 KHz.

Aliasing occurs between 4 KHz and 5 KHz because of sampling below the Nyquist rate. The rest of the spectrum is as shown in Fig. P2.1.

 

q in radians

f = fs.q /2p

0

0

p/4

1 KHz

p/2

2 KHz

3p/4

3 KHz

p

4 KHz

 

 

 

2.3               

 

Problem

 

Determine the period for the periodic sequences: (a) e_jnp/8, (b) e_jn3p/8.

 

 

Solution

 

a) Period = 16.

b)      Period = 16.

 

 

 

2.4

 

Problem

 

The signal in 2.1 is filtered and sampled using the sampling rate of 8 KHz. If

512 samples of this signal are used to compute the Fourier transform X(k),

determine the frequency spacing between adjacent X(k) elements. What is the

analog frequency corresponding to k = 64, 128, and 200. Repeat this problem

using 1024 samples and an 8 KHz sampling rate.

 

 

Solution

 

Frequency spacing Df = fs/N = 8000/512 = 15.625 Hz.

 

 

K

f in Hz

64

64 x 15.625 = 1000

128

128 x 15.625 = 2000

200

200 x 15.625 = 3125

 

For N = 1024, values for Df and all frequencies become half of the above values.

 

 

 

2.5

 

Problem

 

Assuming X(k) as a complex sequence, determine the number of complex and

real multiplies for computing IDFT using direct and radix-2 FFT algorithms.

 

 

Solution

 

Method

Complex Multiplies

Real Multiplies

Direct

5122 = 262,144

4 x 262,144 = 1,048,576

Radix-2 FFT

(512 / 2) x log2 512 = 2304

4 x 2304 = 9216

 

 

 

2.6

 

 

Problem

 

For the FIR filter

y(n) = (x(n) + x(n -1) + x(n - 2))/3

determine the (a) system function, (b) magnitude response function, (c) phase

response function, (d) impulse response, (e) step response, and (f) poles and

zeros.

 

 

Solution

 


 

 

c)P(q ) = -q + phase contributed by (1 + 2cosq )



 

e)y(n) = (u(n) + u(n-1) + u(n-2))/3

 

f) Poles: 0.0

Zeros: -.5 + j0.866, -.5 j0.866

 

2.7

 

Problem

 

For the IIR filter

 

 

determine the (a) magnitude response function, (b) phase response function,

(c) impulse response, (d) step response, and (e) poles and zeros.

 

 

Solution

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


2.8

 

Problem

 

Determine the low pass filter cutoff frequency that must be used to decimate to

reduce the sampling rate from 8 KHz to 4 KHz.

 

 

Solution

 

Low pass filter cutoff frequency must be < 2 KHz.

 

 

2.9

 

Problem

 

The signal sequence x(n) = [0 2 4 6 8] is interpolated using the interpolation

filter sequence bk = [.5 1 .5] and the interpolation factor is 2. Determine

the interpolated sequence y(m).

 

Solution

 

Zero inserted sequence: [0 0 2 0 4 0 6 0 8]

Interpolated sequence: [0 1 2 3 4 5 6 7 8]


Laboratory Assignments

 

L2.7

 

Problem

 

Find and plot the (a) impulse, (b) unit step, (c) magnitude, (d) phase, and (e)

group delay responses for the system with transfer function

 

 

Solution

 

function[]=lab2p7()

 

% Find and plot the (a) impulse, (b) unit step,

% (c) magnitude, (d) phase, and (e) group delay responses for

% the system with transfer function

% H(z) = (z-1) / (z-.25) (z-.5)

 

num = [1 -1]; % Defining the numerator coefficients

den = [1 -0.75 0.125]; % Defining the denominator coefficients

 

n = 0:1:20;

x = [1 zeros(1,20)]; % Defining impulse input

y = filter(num,den,x); % Computing impulse response

plot(n,y) % Plotting the impulse response

title('L2.7(a) --- Impulse Response of H(z) = (z-1) / (z-.25) (z-.5)');

xlabel('n'), ylabel('y(n)');

pause

 

x = [ones(1,21)]; % Defining unit step input

y = filter(num,den,x); % Computing step response

plot(n,y) % Plotting the step response

title('L2.7(b) --- Step Response of H(z) = (z-1) / (z-.25) (z-.5)');

xlabel('n'), ylabel('y(n)');

pause

 

[h,w] = freqz(num,den,32); % Computing the frequency response

 

 

plot(w,abs(h)) % Plotting the magnitude

title('L2.7(c) --- Magnitude Response of H(z) = (z-1) / (z-.25) (z-.5)');

xlabel('w (rad)'), ylabel('Mag');

pause

 

subplot(211), plot(w,angle(h)) % Plotting the phase response

title('L2.7(d) --- Phase Response of H(z) = (z-1) / (z-.25) (z-.5)');

xlabel('w (rad)'), ylabel('Phase (rad)');

 

subplot(212), plot(w,grpdelay(num,den,32)) % Plotting the group delay response

title('L2.7(e) --- Group Delay Response of H(z) = (z-1) / (z-.25) (z-.5)');

xlabel('w (rad)'), ylabel('Group Delay (sec)');

subplot

return

 

 

 

L2.8

 

Problem

 

Given a three-tap averaging filter

y(n) = [(x(n) + x(n - 1) + x(n - 2)]/3

obtain and plot the (a) magnitude, (b) dB magnitude, (c) phase, and (d) group delay frequency response for the filter. Comment on the lowpass filtering nature of the filter.

Solution

 

function[] = lab2p8()

 

% Analysis of a three tap averaging filter

% y(n+1) = [ x(n) + x(n-1) + x(n-2) ] / 3

 

b = [1/3 1/3 1/3];

a = 1;

[h,w] = freqz(b,a,32);

 

plot(w,abs(h))

xlabel('w');

ylabel('Mag');

title('L2.8 --- Magnitude Plot');

pause

 

semilogy(w,abs(h))

xlabel('w');

ylabel('dB');

title('L2.8 --- dB Magnitude Plot');

pause

 

plot(w,angle(h))

xlabel('w');

ylabel('Phase');

title('L2.8 --- Phase Plot');

pause

 

plot(w,grpdelay(b,a,32))

xlabel('w');

ylabel('Group Delay');

title('L2.8 --- Group Delay Plot');

return

 

It is more of a notch filter rather than a low pass with a notch at w=2 and has linear phase.

 

 

L2.9

 

Problem

 

Repeat Problem L2.8 for the filter

y(n) = -3x(n) + 12x(n - 1) + 17x(n - 2) + 12x(n - 3) - 3x(n - 4)]/35

 

 

 

Solution

 

function[] = lab2p9()

 

% Analysis of a given filter

% y(n) = [-3x(n) +12x(n-1) +17x(n-2) +12x(n-3) -3x(n-4)] / 35

 

b = [-3/35 12/35 17/35 12/35 -3/35];

% Defining the numerator officients

a = 1; % Defining the Denominator cofficients

 

[h,w] = freqz(b,a,32);

 

plot(w,abs(h))

xlabel('w');

ylabel('Mag');

title('L2.9 --- Magnitude Plot');

pause

 

semilogy(w,abs(h))

xlabel('w');

ylabel('dB');

title('L2.9 --- dB Magnitude Plot');

pause

 

plot(w,angle(h))

xlabel('w');

ylabel('Phase');

title('L2.9 --- Phase Plot');

pause

 

plot(w,grpdelay(b,a,32))

xlabel('w');

ylabel('Group Delay');

title('L2.9 --- Group Delay Plot');

return

 

 

 

L2.10

 

Problem

 

Design a 31 tap band pass FIR filter with cutoff frequencies of 25 and 75 Hz and sampling frequency of 200 Hz. Calculate the pass band ripple and the stop band attenuation for the designed filter.

Use this filter to filter the noisy signal

x(t) =2 sin(100pt) + w(t)

where w(t) is a uniformly distributed noise with amplitude range from -.25 to +.25. Evaluate the performance using FFT.

 

 

 

Solution

 

% This is a program to design a 31 tap band pass FIR filter

% Cutoff frequencies: 25Hz, 75Hz

% Sampling frequency: 200Hz

% This filter is used with a noisy signal x(t) = 2sin(100t) + w(t)

% w(t) is a uniformly distributed noise with amplitude ranging

% from -.25 to .25.

% The Power Spectral Density is computed for the Unfiltered &

% Filtered signal.

% The performance of the filter is evaluated using FFT

% To calculate pass band ripple and stop band attenuation

% to evaluate performance using FFT - done by PSD calculation

 

function[]=lab2p10()

 

fs=200 % Sampling frequency

freq = 50; % Input signal frequency

x = 2 * sin(2*pi*freq*(0:1:100)/fs); % Generate signal x

r = 0.5*rand(1,length(x)) - 0.25 ; % Generate noise w

xn = x + r; % Generate the noisy signal xn

 

f = [0 0.048 0.05 0.15 0.152 1]; % Filter spec

m = [0 0 1 1 0 0];

b = remez(30,f,m); % Design 31 tap FIR filter

 

y = filter(b,1,xn); % Filter the noisy signal

[h,w] = freqz(b,1,512); % Compute filter freq. response

 

yn = y(30:100); % Clip filtered output

 

N = 128; % FFT size

k = 0:1:N/2-1;

YN = fft(yn,N); % Compute FFT of output

Y1= YN.*conj(YN)/N; % Compute PSD for output

Y1=Y1(1:N/2);

Y1=10*log10(Y1);

 

X = fft(x,N); % Compute FFT of input

X1= X.*conj(X)/N; % Compute PSD for input

X1=X1(1:N/2);

X1=10*log10(X1);

 

f1=fs/N*(0:(N/2-1)); % Compute frequency axis

 

 

d = 0; % Selection control

while d < 8

clc;

c = 1;

d=menu('choose your option','NOISELESS INPUT SIGNAL','NOISY INPUT SIGNAL','FILTER FREQUENCY RESPONSE','FILTERED SIGNAL','NOISELESS/FILTERED SIGNAL PSD','NOISELESS/FILTERED SIGNAL FFT','EXIT');

c=uicontrol('style','pushbutton','position',[420 350 40 15],'string','NEXT');

 

if d==1

t=0:1:length(x)-1; % Plot input signal

plot(t,x);

title('L2.10 --- Noiseless Input Signal');

xlabel('t');

ylabel('Amplitude');

while c~=0

c=waitforbuttonpress;

end

end

 

if d==2

t=0:1:length(xn)-1;

plot(t,xn); % Plot noisy input signal

title('L2.10 --- Noisy Input Signal');

xlabel('t');

ylabel('Amplitude');

c = 1;

while c~=0

c=waitforbuttonpress;

end

end

 

if d==3

plot(f,m,w/pi,abs(h)); % Plot frequency response

axis([0 0.5 0 1.5]);

title('L2.10 --- Actual/Desired FIR Filter Frequeny Response');

xlabel('w/pi');

ylabel('Amplitude');

c = 1;

while c~=0

c=waitforbuttonpress;

end

end

 

if d==4

t=0:1:length(y)-1;

plot(t,y); % Plot filtered signal

axis('auto');

title('L2.10 --- Filtered Signal');

xlabel('t');

ylabel('Amplitude');

c = 1;

while c~=0

c=waitforbuttonpress;

end

end

 

if d==5

% Plot the PSD of filtered and noiseless signals

plot(f1,X1,'r',f1,Y1,'g');

title('L2.10 --- Filtered(Green) & Noiseless Input(Red) Signal PSD');

xlabel('Frequency');

ylabel('Amplitude');

c = 1;

while c~=0

c=waitforbuttonpress;

end

end

 

if d==6

plot(k,X1,'r',k,Y1,'g'); % Plot noiseless and filtered signal FFTs

title('L2.10 --- FFT of Noiseless(Red) & Filtered(Green) Signal');

k = 0:1:length(YN)-1;

xlabel('k')

ylabel('Amplitude');

c = 1;

while c~=0

c=waitforbuttonpress;

end

end

 

if d==7

close; % Exit

return;

end

end

 

 

 

 

 

 

L2.11

 

Problem

 

For the filter of Problem L2.10, determine the transition widths, when gain drops from 90% to 10%, around the cutoff frequencies. How will you reduce these to obtain a sharper response? Demonstrate with an example.

 

 

Solution

 

 

First part to be calculated from graph.

Second part - use a remez filter with more sets of transition points

 

 

 

L2.12

 

Problem

 

Design a second-order Butterworth IIR lowpass filter with a cutoff frequency of 50 Hz for a signal sampled at 250 Hz. Determine its dc gain, poles, and zeros.

 

Solution

 

function[] = lab2p12()

% Design a second-order Butterworth IIR lowpass filter with

% cut off frequency = 50Hz; sampling frequency = 250Hz;

% Poles & Zeros and DC gain are computed for the designed filter.

 

% Filter specifications

fs = 250; % Sampling frequency

fc = 50; % Cut-off frequency

N = 2; % Order of the filter

% Filter design

[b,a] = butter(N,fc/(fs/2)) % Design the filter

 

% Compute poles, zeros, and DC gain

[P,Z,K] = butter(N,fc/(fs/2))

pause

 

[h,w] = freqz(b,a,128); % View the frequency response

semilogy(w,abs(h));

title('L2.12 --- Frequency Response of the Designed Filter');

xlabel('w');

ylabel('Mag');

 

end

 

L2.13

 

Problem

 

Design an elliptic IIR lowpass filter with cutoff frequency of 50 Hz for a signal sampled at 250 Hz. The filter order should be such that the passband ripple is less than .2 dB and the stopband attenuation is more than 20 dB.

 

 

Solution

 

function[] = lab2p12();

 

% Design an elliptic IIR lowpass filter with

% cut off frequency = 50Hz; sampling frequency = 250Hz;

% pass band ripple < 0.2 dB; and stop band attenuation > 30 dB.

% A minimum order filter is used to achieve the specifications.

% Poles & Zeros and DC gain are computed for the designed filter.

 

% Filter specifications

fs = 250; % Sampling frequency

fc = 50; % Cut-off frequency

Rp = 0.2; % Passband ripple

Rs = 30; % Stopband attenuation

 

% Filter design

N = 2 % Choose the filter order

[b,a] = ellip(N,Rp,Rs,fc/(fs/2)) % Design the filter

 

% Compute poles, zeros, and DC gain

[P,Z,K] = ellip(N,Rp,Rs,fc/(fs/2))

pause

 

[h,w] = freqz(b,a,128); % View the frequency response

semilogy(w,abs(h));

title('L2.13 --- Frequency Response of the Designed Filter');

xlabel('w');

ylabel('Mag');

 

end