Design of Lth Band FIR Filter Using the % Windowed Fourier Series Approach % clf; K = 11; n = -K:K; % Generate the

truncated impulse response of % the ideal lowpass filter b = sinc(n/2)/2; % Generate the window sequence win = hamming(23); % Generate the coefficients of the windowed filter fil = b.*win¶; c = fil/sum(fil); % Plot the gain response of the windowed filter [h,w] = freqz(c,1,256); g = 20*log10(abs(h)); plot(w/pi,g);axis([0 1 -90 10]); grid xlabel(¶\omega/\pi¶);ylabel(¶Gain, dB¶);

.axis([0 29 -2. L = input(¶Up-sampling factor = ¶). ylabel(¶Amplitude¶). x = sin(2*pi*0. xlabel(¶Time index n¶).1. title(¶Input Sequence¶).Program 10_7 % Illustration of Sampling Rate Alteration by % a Ratio of Two Integers % clf. subplot(2.L.43*n) + sin(2*pi*0.2). ylabel(¶Amplitude¶).1). n = 0:29. xlabel(¶Time index n¶).2]).2 2. m = 0:(30*L/M)-1.y(1:30*L/M)). M = input(¶Down-sampling factor = ¶).1. subplot(2.31*n). y = resample(x. stem(m. title(¶Output Sequence¶).x(1:30)).2 2.2]).M).axis([0 (30*L/M)-1 -2. stem(n.

M)/M.1.031*n).y(1:50*L)).1). stem(n.6]). y = 2*fc*sinc(2*fc*n). ylabel(¶Amplitude¶). M = 2. grid Questions: Program P4_2 % Gain Response of a Moving-Average Lowpass Filter clf.grid axis([0 1 -50 0. [g. num2str(M)]) Questions: . m = 0:(50*L)-1.1). plot(w/pi.5]) xlabel(¶\omega /\pi¶). % Plot the input and the output sequences subplot(2.5. ylabel(¶Amplitude¶). n = [-6.043*n) + sin(2*pi*0.w] = gain(num. title(¶Output Sequence¶). title([¶M = ¶.ylabel(¶Gain in dB¶).y). Program P4_1 % Impulse Response of Truncated Ideal Lowpass Filter clf. x = sin(2*pi*0.5].title(¶N = 13¶).L).1.25.2).k = n+6. % Generate the interpolated output sequence y = interp(x. stem(k. stem(m.5:1:6. fc = 0. num = ones(1. xlabel(¶Time index n¶).axis([0 13 -0.x(1:50)). xlabel(¶Time index n¶).Program P10_6 % Illustration of Interpolation Process % clf. subplot(2. % Generate the input sequence n = 0:49. L = input(¶Up-sampling factor = ¶). xlabel(¶Time index n¶).2 0.g).ylabel(¶Amplitude¶). title(¶Input Sequence¶).

xa).2 1. grid xlabel(¶Time index n¶). Questions: Program P5_1 % Illustration of the Sampling Process % in the Time Domain clf. axis([0 (length(n)-1) -1.1.2 1.Program P4_4 % Stability Test clf.2]) subplot(2.1) plot(t.ylabel(¶Amplitude¶).2]) .1. subplot(2.xs). title(¶Continuous-time signal x_{a}(t)¶). den = input(¶Denominator coefficients = ¶). disp(¶Stability test parameters are¶). f = 13.grid xlabel(¶Time. xa = cos(2*pi*f*t). title(¶Discrete-time signal x[n]¶). ki = poly2rc(den). msec¶). stem(k.1. k = 0:length(n)-1. n = 0:T:1. xs = cos(2*pi*f*n).2).0005:1. disp(ki).ylabel(¶Amplitude¶). T = 0. axis([0 1 -1. t = 0:0.

2. hd = freqz(xs.(1/T)*n(:.1) plot(t.grid. title(¶Reconstructed continuous-time signal y_{a}(t)¶).ones(size(t)))¶)*xs.ya).5. Program P5_3 % Illustration of the Aliasing Effect % in the Frequency Domain clf. ha = freqs(2. MA.*exp(-n).1.*exp(-t). title(¶|X(e^{j\omega})|¶).xs).ylabel(¶Amplitude¶). xa = 2*t. xs = cos(2*pi*f*n).2. kHz¶). .¶o¶. subplot(2.1. xs = 2*n. plot(n.1.2. subplot(2..ylabel(¶Amplitude¶).005:10.2) wa = 0:10/511:10. ya = sinc((1/T)*t(:.abs(ha)).Program P5_2 % Illustration of Aliasing Effect in the Time Domain % Program adapted from [Kra94] with permission from % The Mathworks. xlabel(¶Time.500)¶. T*abs(hd)). k = 0:length(n)-1. axis([0 1 -1.grid xlabel(¶Time. plot(wa/(2*pi).wa).xa). Natick.f = 13.3) T = 1. xlabel(¶Time index n¶).ylabel(¶Amplitude¶).4) wd = 0:pi/255:pi. T = 0.grid. t = 0:0. stem(k.[1 2 1]. subplot(2.ylabel(¶Amplitude¶).ylabel(¶Amplitude¶). clf.5.2 1.wd). Inc. title(¶Continuous-time signal x_{a}(t)¶). n = (0:T:1)¶. title(¶Discrete-time signal x[n]¶).2. kHz¶). msec¶).ones(size(n))) . n = 0:T:10. t = linspace(-0. xlabel(¶Frequency.xs. plot(wd/(T*pi). msec¶).2]). subplot(2.grid. axis([0 5/pi 0 2]).t. xlabel(¶Frequency. title(¶|X_{a}(j\Omega)|¶).grid.

int. disp(bin) Questions Program P6_2 . Hz¶). b = input(¶Type in the desired wordlength = ¶).wa). h = freqs(b.grid xlabel(¶Frequency. else bin = [0 beq]. Wn. 20*log10(abs(h))).a. Wp = 2*pi*Fp.ylabel(¶Gain. title(¶Gain response¶). for k = 1:b int = fix(2*d1).a] = butter(N. [N. Ws. Fp = 3500. d1 = 2*d1 . d1 = abs(d). [b. end if sign(d) == -1.axis([0 1/T 0 2]) Program P5_4 % Design of Analog Lowpass Filter clf. Program P5_5 % Determines the binary equivalent of a % decimal number in sign-magnitude form d = input(¶Type in the decimal fraction = ¶).b)]. dB¶). Ws = 2*pi*Fs. plot(wa/(2*pi). bin = [1 beq]. end disp(¶The binary equivalent is¶).¶s¶). beq(k) = int.Fs = 4500. beq = [zeros(1. Wn] = buttord(Wp. axis([0 3*Fs -60 5]). wa = 0:(3*Ws)/511:3*Ws. 30.5. 0. ¶s¶).

H = zeros(2*N+1.disp(k1). Rp. Rp = 0.k2] = residue(num.den).1) = ir¶.disp(r1). title(¶Gain Response of a Butterworth Bandstop Filter¶). Rs).¶stop¶).disp(num).% Parallel Form Realizations of an IIR Transfer Function num = input(¶Numerator coefficient vector = ¶).disp(p1).disp(den).den] = butter(N1. ylabel(¶Gain. [r2. H(:. % Compute the gain response [g. disp(¶Poles are at¶). Program P7_1 % Design of a Butterworth Bandstop Digital Filter Ws = [0. for n = 2:N+1. disp(¶Constant value¶). disp(¶Denominator coefficients are ¶). Wp = [0.k1] = residuez(num.4. disp(¶Constant value¶). % Design the Filter [num. disp(¶Parallel Form II¶) disp(¶Residues are¶). % Estimate the Filter Order [N1. [r1.den).disp(k2). % Plot the gain response plot(w/pi.4 0.6].g). dB¶).3 0. .disp(p2).N+1). function [p.N). xlabel(¶\omega /\pi¶).w] = gain(num.p1.p2.Wn1. Wn1] = buttord(Wp. Rs = 50. den = input(¶Denominator coefficient vector = ¶).grid axis([0 1 -60 5]).disp(r2).7].d] = strucver(ir. disp(¶Poles are at¶). disp(¶Parallel Form I¶) disp(¶Residues are¶). % Display the transfer function disp(¶Numerator coefficients are ¶). Ws.den).

disp(den). % Compute the denominator coefficients d = -(inv(H2))*hf.2*pi. % Program P8_1 Wp = [0. disp(p¶).w1 = 0.den.25.Wn).:).[1 zeros(1. end H2 = H3(:.H(:. disp(¶Numerator coefficients are ¶).disp(num). end H3 = zeros(N.5. for k = 1:N+1.N+1).n) = [zeros(1. % Determine the filter transfer function [N. . [num. hf = H3(:.N+1).0. 0.1). Rp.d].2*N1).4*N1)]). Program P8_3 % Illustration of Filtering by an IIR Filter % clf. [num. x2 = 2*cos(w2*k). 0.:) = H(k+N+1.7*pi. [p. Rp = 1.5.1 0. Program P8 1 illustrates the design of a causal IIR filter and its simulation in Direct Form II. Wn] = ellipord(0.5]. 50. den] = ellip(N. d = [1. end H1 = zeros(N+1.:) = H(k.d] = strucver(impres. % Generate the input sequence k = 0:50.:).Wn1). Rs).5*cos(w1*k). x = x1+x2. 50).55. disp(d¶). H1(k.2:N+1). % Compute the numerator coefficients p = H1*[1. It employs the functions strucver and direct2 described earlier. w2 = 0. disp(¶Actual numerator coeffs are ¶). disp(¶Denominator coefficients are ¶).4 0. disp(¶Actual denominator coeffs are ¶). impres = direct2(num.den] = butter(N1.8]. for k = 1:N. d]. Ws. H3(k. x1 = 1. Wn1] = buttord(Wp. [N1. Ws = [0. Rs = 30.n-1) ir(1:2*(N+1)-n)]¶.

stem(k. ylabel(¶Amplitude¶). axis([0 50 -4 4]).x). Questions: . xlabel(¶Time index n¶). % Plot the input and the output sequences subplot(2.y). subplot(2. xlabel(¶Time index n¶).den. axis([0 50 -4 4]). title(¶Input Sequence¶).x).1.% Generate the output sequence y = filter(num. stem(k.2). ylabel(¶Amplitude¶).1.1). title(¶Output Sequence¶).

Sign up to vote on this title
UsefulNot useful