├── CHAP_02 ├── .gitignore ├── ex020100.m ├── ex020200.m ├── ex020300.m ├── ex020400.m ├── ex020500.m ├── ex020600.m ├── ex020700.m ├── ex020800.m ├── ex020900.m ├── ex021000.m └── ex021100.m ├── CHAP_03 ├── ex030300.m ├── ex030400.m ├── ex030500.m ├── ex030600.m ├── ex030700.m ├── ex030800.m ├── ex030900.m ├── ex031000.m ├── ex031100.m ├── ex031200.m ├── ex031300.m ├── ex031500.m ├── ex031600.m ├── ex031700.m ├── ex031800.m ├── ex03180a.m ├── ex03180b.m ├── ex031900.m ├── ex032000.m ├── ex032100.m ├── ex032200.m ├── ex032300.m └── ex039900.m ├── CHAP_04 ├── ex040100.m ├── ex040400.m ├── ex040800.m ├── ex040900.m ├── ex041000.m └── ex041100.m ├── CHAP_05 ├── ex050200.m ├── ex050500.m ├── ex050600.m ├── ex050700.m ├── ex050800.m ├── ex050802.m ├── ex050900.m ├── ex051000.m ├── ex051100.m ├── ex051200.m ├── ex051300.m ├── ex051400.m ├── ex051500.m ├── ex051700.m ├── ex051800.m ├── ex052000.m ├── ex052200.m ├── ex05220b.m ├── ex052300.m └── ex05230b.m ├── CHAP_06 ├── ex060100.m ├── ex060200.m ├── ex060300.m ├── ex060600.m └── ex060700.m ├── CHAP_07 ├── ex070300.m ├── ex070400.m ├── ex070500.m ├── ex070600.m ├── ex070700.m ├── ex070800.m ├── ex070900.m ├── ex071000.m ├── ex071100.m ├── ex071200.m ├── ex071300.m ├── ex071400.m ├── ex07150a.m ├── ex07150b.m ├── ex071600.m ├── ex071700.m ├── ex071800.m ├── ex071900.m ├── ex072000.m ├── ex072200.m ├── ex072300.m ├── ex072400.m ├── ex072500.m ├── ex072600.m ├── ex072700.m └── ex072800.m ├── CHAP_08 ├── ex080200.m ├── ex080400.m ├── ex080600.m ├── ex080700.m ├── ex080800.m ├── ex081000.m ├── ex081100.m ├── ex081200.m ├── ex081300.m ├── ex081400.m ├── ex081600.m ├── ex081700.m ├── ex081800.m ├── ex081900.m ├── ex082000.m ├── ex082100.m ├── ex082200.m ├── ex082300.m ├── ex082400.m ├── ex082600.m ├── ex082700.m ├── ex082800.m ├── ex082900.m └── ex083000.m ├── FIGURES ├── ampresbl.m ├── ampresbr.m ├── ampreshm.m ├── ampreshn.m ├── ampreska.m ├── ampresrc.m ├── errorfun.m ├── gen_zero.m ├── gibbs.m ├── pmintro.m ├── type1_ir.m ├── type2_ir.m ├── type3_ir.m └── type4_ir.m ├── PWS_DSP ├── afd_butt.m ├── afd_chb1.m ├── afd_chb2.m ├── afd_elip.m ├── blackman.m ├── cas2dir.m ├── casfiltr.m ├── cheb1hpf.m ├── circevod.m ├── circonvt.m ├── cirshftt.m ├── codegen │ └── mex │ │ └── dft │ │ ├── cfiGuiReport.mat │ │ └── html │ │ └── report.mldatx ├── contents.m ├── conv_m.m ├── conv_tp.m ├── cplxcomp.m ├── db2delta.m ├── delta2db.m ├── dfs.m ├── dft.m ├── dft.prj ├── dir2cas.m ├── dir2fs.m ├── dir2ladr.m ├── dir2latc.m ├── dir2par.m ├── evenodd.m ├── freqs_m.m ├── freqz_m.m ├── hr_type1.m ├── hr_type2.m ├── hr_type3.m ├── hr_type4.m ├── hsolpsav.m ├── ideal_lp.m ├── idfs.m ├── idft.m ├── imp_invr.m ├── impseq.m ├── ladr2dir.m ├── ladrfilt.m ├── latc2dir.m ├── latcfilt.m ├── lms.m ├── mod.m ├── mulaw_c.m ├── mulaw_e.m ├── ovrlpsav.m ├── par2dir.m ├── parfiltr.m ├── pfe2rfz.m ├── quantize.m ├── rf2pfez.m ├── sdir2cas.m ├── sigadd.m ├── sigfold.m ├── sigmult.m ├── sigshift.m ├── stepseq.m ├── u_buttap.m ├── u_chb1ap.m ├── u_chb2ap.m ├── u_elipap.m └── zmapping.m └── readme.txt /CHAP_02/.gitignore: -------------------------------------------------------------------------------- 1 | *.vscode -------------------------------------------------------------------------------- /CHAP_02/ex020100.m: -------------------------------------------------------------------------------- 1 | % Chapter 02: Example 02.01: Signal Synthesis 2 | 3 | % 4 | 5 | figure(1); clf 6 | 7 | % a) x(n) = 2*delta(n+2) - delta(n-4), -5<=n<=5 8 | 9 | n = [-5:5]; 10 | 11 | x = 2*impseq(-2,-5,5)-impseq(4,-5,5); 12 | 13 | subplot(2,2,1); stem(n,x); title('Sequence in Example 2.1a') 14 | 15 | xlabel('n'); ylabel('x(n)'); axis([-5,5,-2,3]) 16 | 17 | % 18 | 19 | % b) x(n) = n[u(n)-u(n-10)]+10*exp(-0.3(n-10))(u(n-10)-u(n-20)); 0<=n<=20 20 | 21 | n = [0:20]; 22 | 23 | x1 = n.*(stepseq(0,0,20)-stepseq(10,0,20)); 24 | 25 | x2 = 10*exp(-0.3*(n-10)).*(stepseq(10,0,20)-stepseq(20,0,20)); 26 | 27 | x = x1+x2; 28 | 29 | subplot(2,2,2);stem(n,x); 30 | 31 | title('Sequence in Example 2.1b') 32 | 33 | xlabel('n');ylabel('x(n)');axis([0,20,-1,11]) 34 | 35 | % 36 | 37 | % c) x(n) = cos(0.04*pi*n) + 0.2*w(n); 0<=n<=50, w(n): Gaussian (0,1) 38 | 39 | n = [0:50]; 40 | 41 | x = cos(0.04*pi*n)+0.2*randn(size(n)); 42 | 43 | subplot(2,2,3);stem(n,x);title('Sequence in Example 2.1c') 44 | 45 | xlabel('n');ylabel('x(n)');axis([0,50,-1.4,1.4]) 46 | 47 | % 48 | 49 | % d) x(n) = {...,5,4,3,2,1,5,4,3,2,1,...}; -10<=n<=9 50 | 51 | n=[-10:9]; 52 | 53 | x=[5,4,3,2,1]; 54 | 55 | xtilde=x' * ones(1,4); 56 | 57 | xtilde=(xtilde(:))'; 58 | 59 | subplot(2,2,4);stem(n,xtilde);title('Sequence in Example 2.1d') 60 | 61 | xlabel('n');ylabel('xtilde(n)');axis([-10,9,-1,6]) -------------------------------------------------------------------------------- /CHAP_02/ex020200.m: -------------------------------------------------------------------------------- 1 | % Chapter 02: Example 02.02: Signal Synthesis 2 | 3 | % 4 | 5 | figure(1); clf 6 | 7 | n = -2:10; x = [1:7,6:-1:1]; 8 | 9 | % a) x1(n) = 2*x(n-5) - 3*x(n+4) 10 | 11 | [x11,n11] = sigshift(x,n,5); [x12,n12] = sigshift(x,n,-4); 12 | 13 | [x1,n1] = sigadd(2*x11,n11,-3*x12,n12); 14 | 15 | subplot(2,1,1); stem(n1,x1); title('Sequence in Example 2.2a') 16 | 17 | xlabel('n'); ylabel('x1(n)'); axis([min(n1)-1,max(n1)+1,min(x1)-1,max(x1)+1]) 18 | 19 | set(gca,'XTickMode','manual','XTick',[min(n1),0,max(n1)]) 20 | 21 | % 22 | 23 | % b) x2(n) = x(3-n) + x(n)*x(n-2) 24 | 25 | [x21,n21] = sigfold(x,n); [x21,n21] = sigshift(x21,n21,3); 26 | 27 | [x22,n22] = sigshift(x,n,2); [x22,n22] = sigmult(x,n,x22,n22); 28 | 29 | [x2,n2] = sigadd(x21,n21,x22,n22); 30 | 31 | subplot(2,1,2); stem(n2,x2); title('Sequence in Example 2.2b') 32 | 33 | xlabel('n'); ylabel('x2(n)'); axis([min(n2)-1,max(n2)+1,0,40]) 34 | 35 | set(gca,'XTickMode','manual','XTick',[min(n2),0,max(n2)]) -------------------------------------------------------------------------------- /CHAP_02/ex020300.m: -------------------------------------------------------------------------------- 1 | % Chapter 02: Example 02.03: Signal Synthesis of complex sequence 2 | 3 | % 4 | 5 | figure(1); clf 6 | 7 | % a) x(n) = exp((-0.1+j0.3)n), -10 <= n <= 10; 8 | 9 | n = [-10:1:10]; alpha = -0.1+0.3j; 10 | 11 | x = exp(alpha*n); 12 | 13 | subplot(2,2,1); stem(n,real(x));title('real part');xlabel('n') 14 | 15 | subplot(2,2,2); stem(n,imag(x));title('imaginary part');xlabel('n') 16 | 17 | subplot(2,2,3); stem(n,abs(x));title('magnitude part');xlabel('n') 18 | 19 | subplot(2,2,4); stem(n,(180/pi)*angle(x));title('phase part');xlabel('n') 20 | 21 | -------------------------------------------------------------------------------- /CHAP_02/ex020400.m: -------------------------------------------------------------------------------- 1 | % Chapter 02: Example 02.04: Even-Odd Synthesis 2 | 3 | % 4 | 5 | % x(n) = u(n)-u(n-10); 6 | 7 | n = [0:10]; 8 | 9 | x = stepseq(0,0,10)-stepseq(10,0,10); 10 | 11 | [xe,xo,m] = evenodd(x,n); 12 | 13 | subplot(1,1,1) 14 | 15 | subplot(2,2,1); stem(n,x); title('Rectangular pulse') 16 | 17 | xlabel('n'); ylabel('x(n)'); axis([-10,10,0,1.2]) 18 | 19 | subplot(2,2,2); stem(m,xe); title('Even Part') 20 | 21 | xlabel('n'); ylabel('xe(n)'); axis([-10,10,0,1.2]) 22 | 23 | subplot(2,2,4); stem(m,xo); title('Odd Part') 24 | 25 | xlabel('n'); ylabel('xe(n)'); axis([-10,10,-0.6,0.6]) -------------------------------------------------------------------------------- /CHAP_02/ex020500.m: -------------------------------------------------------------------------------- 1 | % Example 2.5 2 | 3 | % 4 | 5 | % x(n)=[u(n)=u(n-10]; h(n)=(0.9)^n*u(n) 6 | 7 | % y(n)=10*(1-(0.9)^(n+1))*(u(n)-u(n-10))+ 8 | 9 | % (10*(1-(0.9)^10)*(0.9)^(n-9))*u(n-10) 10 | 11 | n = -5:50; 12 | 13 | u1 = stepseq(0,-5,50); u2=stepseq(10,-5,50); 14 | 15 | % input x(n) 16 | 17 | x = u1-u2; 18 | 19 | % impulse response h(n) 20 | 21 | h = ((0.9).^n).*u1; 22 | 23 | subplot(1,1,1) 24 | 25 | subplot(2,1,1); stem(n,x); axis([-5,50,0,2]) 26 | 27 | title('Input Sequence') 28 | 29 | xlabel('n'), ylabel('x(n)') 30 | 31 | subplot(2,1,2); stem(n,h); axis([-5,50,0,2]) 32 | 33 | title('Impulse Response') 34 | 35 | xlabel('n'), ylabel('h(n)'); pause 36 | 37 | print -deps2 ex0205a.eps 38 | 39 | % output response 40 | 41 | y = (10*(1-(0.9).^(n+1))).*(u1-u2)+(10*(1-(0.9)^10)*(0.9).^(n-9)).*u2; 42 | 43 | subplot(1,1,1) 44 | 45 | subplot(2,1,2); stem(n,y); axis([-5,50,0,8]) 46 | 47 | title('Output Sequence') 48 | 49 | xlabel('n'), ylabel('y(n)') 50 | 51 | print -deps2 ex0205b.eps 52 | 53 | -------------------------------------------------------------------------------- /CHAP_02/ex020600.m: -------------------------------------------------------------------------------- 1 | % Example 2.6 2 | 3 | % 4 | 5 | % x(n)=[3,11,7,0,-1,4,2]; nx = [-3:3] 6 | 7 | % h(n)=[2,3,0,-5,2,1]; nh = [-1:4] 8 | 9 | % y(n)=conv(x,h) 10 | 11 | % input x(n) 12 | 13 | x = [3,11,7,0,-1,4,2]; nx = [-3:3]; 14 | 15 | % impulse response h(n) 16 | 17 | h = [2,3,0,-5,2,1]; nh = [-1:4]; 18 | 19 | subplot(1,1,1) 20 | 21 | % plot x(k) and h(k) 22 | 23 | subplot(2,2,1); stem(nx-0.05,x); axis([-5,5,-6,12]); 24 | 25 | hold on; stem(nh+0.05,h,':') 26 | 27 | title('x(k) and h(k)');xlabel('k'); 28 | 29 | text(-0.5,11,'solid: x dashed: h'); hold off 30 | 31 | % plot x(k) and h(-k) 32 | 33 | subplot(2,2,2); stem(nx-0.05,x); axis([-5,5,-6,12]); 34 | 35 | hold on; stem(-fliplr(nh)+0.05,fliplr(h),':') 36 | 37 | title('x(k) and h(-k)');xlabel('k'); 38 | 39 | text(-0.5,-1,'n=0') 40 | 41 | text(-0.5,11,'solid: x dashed: h'); hold off 42 | 43 | % plot x(k) and h(-1-k) 44 | 45 | subplot(2,2,3); stem(nx-0.05,x); axis([-5,5,-6,12]); 46 | 47 | hold on; stem(-fliplr(nh)+0.05-1,fliplr(h),':') 48 | 49 | title('x(k) and h(-1-k)');xlabel('k'); 50 | 51 | text(-1.5,-1,'n=-1') 52 | 53 | text(-0.5,11,'solid: x dashed: h'); hold off 54 | 55 | % plot x(k) and h(2-k) 56 | 57 | subplot(2,2,4); stem(nx-0.05,x); axis([-5,5,-6,12]); 58 | 59 | hold on; stem(-fliplr(nh)+0.05+2,fliplr(h),':') 60 | 61 | title('x(k) and h(2-k)');xlabel('k'); 62 | 63 | text(2-0.5,-1,'n=2') 64 | 65 | text(-0.5,11,'solid: x dashed: h'); hold off 66 | 67 | %print -deps2 ex020600.eps -------------------------------------------------------------------------------- /CHAP_02/ex020700.m: -------------------------------------------------------------------------------- 1 | 2 | % Example 2.7 3 | 4 | % 5 | 6 | % x(n)=[3,11,7,0,-1,4,2]; nx = [-3:3] 7 | 8 | % h(n)=[2,3,0,-5,2,1]; nh = [-1:4] 9 | 10 | % y(n)=conv(x,h) 11 | 12 | x = [3, 11, 7, 0, -1, 4, 2]; nx = [-3: 3]; 13 | 14 | h = [2, 3, 0, -5, 2, 1]; nh = [-1: 4]; 15 | 16 | [y,ny] = conv_m(x,nx,h,nh) 17 | 18 | -------------------------------------------------------------------------------- /CHAP_02/ex020800.m: -------------------------------------------------------------------------------- 1 | 2 | % Example 2.8 3 | 4 | % 5 | 6 | % x(n)=[3,11,7,0,-1,4,2]; nx = [-3:3] 7 | 8 | % h(n)=[2,3,0,-5,2,1]; nh = [-1:4] 9 | 10 | % y(n)=conv_tp(x,h) 11 | 12 | x = [3, 11, 7, 0, -1, 4, 2]'; 13 | 14 | h = [2, 3, 0, -5, 2, 1]'; 15 | 16 | [y,H] = conv_tp(h,x) -------------------------------------------------------------------------------- /CHAP_02/ex020900.m: -------------------------------------------------------------------------------- 1 | % Example 2.9 2 | 3 | % 4 | 5 | % x(n)=[3,11,7,0,-1,4,2]; nx = [-3:3] 6 | 7 | % y(n)=x(n-2)+w(n) 8 | 9 | % ryx = cross(y,x) 10 | 11 | % 12 | 13 | % noise sequence 1 14 | 15 | x = [3, 11, 7, 0, -1, 4, 2]; nx=[-3:3]; % given signal x(n) 16 | 17 | [y,ny] = sigshift(x,nx,2); % obtain x(n-2) 18 | 19 | w = randn(1,length(y)); nw = ny; % generate w(n) 20 | 21 | [y,ny] = sigadd(y,ny,w,nw); % obtain y(n) = x(n-2) + w(n) 22 | 23 | [x,nx] = sigfold(x,nx); % obtain x(-n) 24 | 25 | [rxy,nrxy] = conv_m(y,ny,x,nx); % cross-corrlation 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,1,1);stem(nrxy,rxy) 30 | 31 | axis([-4,8,-50,250]);xlabel('lag variable l') 32 | 33 | ylabel('rxy');title('Crosscorrelation: noise sequence 1') 34 | 35 | gtext('Maximum') 36 | 37 | % 38 | 39 | % noise sequence 2 40 | 41 | x = [3, 11, 7, 0, -1, 4, 2]; nx=[-3:3]; % given signal x(n) 42 | 43 | [y,ny] = sigshift(x,nx,2); % obtain x(n-2) 44 | 45 | w = randn(1,length(y)); nw = ny; % generate w(n) 46 | 47 | [y,ny] = sigadd(y,ny,w,nw); % obtain y(n) = x(n-2) + w(n) 48 | 49 | [x,nx] = sigfold(x,nx); % obtain x(-n) 50 | 51 | [rxy,nrxy] = conv_m(y,ny,x,nx); % cross-corrlation 52 | 53 | subplot(2,1,2);stem(nrxy,rxy) 54 | 55 | gtext('Maximum') 56 | 57 | axis([-4,8,-50,250]);xlabel('lag variable l') 58 | 59 | ylabel('rxy');title('Crosscorrelation: noise sequence 2') -------------------------------------------------------------------------------- /CHAP_02/ex021000.m: -------------------------------------------------------------------------------- 1 | % Matlab Example 2.10; Chapter 2 2 | 3 | % 4 | 5 | a=[1,-1,0.9];b=1; 6 | 7 | % Part a) 8 | 9 | x=impseq(0,-20,120);n=[-20:120]; 10 | 11 | h=filter(b,a,x); 12 | 13 | subplot(2,1,1);stem(n,h) 14 | 15 | axis([-20,120,-1.1,1.1]) 16 | 17 | title('Impulse Response');xlabel('n');ylabel('h(n)') 18 | 19 | % 20 | 21 | % Part b) 22 | 23 | x=stepseq(0,-20,120); 24 | 25 | s=filter(b,a,x); 26 | 27 | subplot(2,1,2);stem(n,s) 28 | 29 | axis([-20,120,-.5,2.5]) 30 | 31 | title('Step Response');xlabel('n');ylabel('s(n)') 32 | 33 | % 34 | 35 | %print -deps2 ex021000.eps 36 | 37 | % 38 | 39 | % Part c) 40 | 41 | sum(abs(h)) 42 | 43 | z=roots(a); 44 | 45 | magz=abs(z) 46 | 47 | subplot 48 | 49 | -------------------------------------------------------------------------------- /CHAP_02/ex021100.m: -------------------------------------------------------------------------------- 1 | % Example 2.11 2 | 3 | % 4 | 5 | % x(n) = u(n)-u(n-10) 6 | 7 | % h(n) = (0.9)^n * u(n) 8 | 9 | % diff eqn: y(n) - 0.9y(n-1) = x(n) 10 | 11 | % 12 | 13 | b = [1]; a = [1,-0.9]; 14 | 15 | n = -5:50; x = stepseq(0,-5,50) - stepseq(10,-5,50); 16 | 17 | y = filter(b,a,x); 18 | 19 | subplot(1,1,1); 20 | 21 | subplot(2,1,2); stem(n,y); title('Output sequence') 22 | 23 | xlabel('n'); ylabel('y(n)'); axis([-5,50,-0.5,8]) 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CHAP_03/ex030300.m: -------------------------------------------------------------------------------- 1 | w = [0:1:500]*pi/500; % [0, pi] axis divided into 501 points. 2 | 3 | X = exp(j*w) ./ (exp(j*w) - 0.5*ones(1,501)); 4 | 5 | magX = abs(X); angX = angle(X); 6 | 7 | realX = real(X); imagX = imag(X); 8 | 9 | subplot(2,2,1); plot(w/pi,magX); grid 10 | 11 | xlabel('frequency in pi units'); title('Magnitude Part'); ylabel('Magnitude') 12 | 13 | subplot(2,2,3); plot(w/pi,angX); grid 14 | 15 | xlabel('frequency in pi units'); title('Angle Part'); ylabel('Radians') 16 | 17 | subplot(2,2,2); plot(w/pi,realX); grid 18 | 19 | xlabel('frequency in pi units'); title('Real Part'); ylabel('Real') 20 | 21 | subplot(2,2,4); plot(w/pi,imagX); grid 22 | 23 | xlabel('frequency in pi units'); title('Imaginary Part'); ylabel('Imaginary') 24 | 25 | -------------------------------------------------------------------------------- /CHAP_03/ex030400.m: -------------------------------------------------------------------------------- 1 | % Chapter 3: Example 3.4: 2 | 3 | % DTFT of finite duration seq using mat-vec operation 4 | 5 | % 6 | 7 | n = -1:3; x = 1:5; % sequence x(n) 8 | 9 | k = 0:500; w = (pi/500)*k; % [0, pi] axis divided into 501 points. 10 | 11 | X = x * (exp(-j*pi/500)) .^ (n'*k); % DTFT using matrix-vector product 12 | 13 | magX = abs(X); angX = angle(X); 14 | 15 | realX = real(X); imagX = imag(X); 16 | 17 | subplot(2,2,1); plot(w/pi,magX); grid 18 | 19 | xlabel('frequency in pi units'); title('Magnitude Part'); ylabel('Magnitude') 20 | 21 | subplot(2,2,3); plot(w/pi,angX); grid 22 | 23 | xlabel('frequency in pi units'); title('Angle Part'); ylabel('Radians') 24 | 25 | subplot(2,2,2); plot(w/pi,realX); grid 26 | 27 | xlabel('frequency in pi units'); title('Real Part'); ylabel('Real') 28 | 29 | subplot(2,2,4); plot(w/pi,imagX); grid 30 | 31 | xlabel('frequency in pi units'); title('Imaginary Part'); ylabel('Imaginary') 32 | 33 | %print -deps ex030400.eps -------------------------------------------------------------------------------- /CHAP_03/ex030500.m: -------------------------------------------------------------------------------- 1 | subplot(1,1,1) 2 | 3 | n = 0:10; x = (0.9*exp(j*pi/3)).^n; 4 | 5 | k = -200:200; w = (pi/100)*k; 6 | 7 | X = x * (exp(-j*pi/100)) .^ (n'*k); 8 | 9 | magX = abs(X); angX =angle(X); 10 | 11 | subplot(2,1,1); plot(w/pi,magX);grid 12 | 13 | axis([-2,2,0,8]) 14 | 15 | xlabel('frequency in units of pi'); ylabel('|X|') 16 | 17 | title('Magnitude Part') 18 | 19 | subplot(2,1,2); plot(w/pi,angX/pi);grid 20 | 21 | axis([-2,2,-1,1]) 22 | 23 | xlabel('frequency in units of pi'); ylabel('radians/pi') 24 | 25 | title('Angle Part') 26 | 27 | -------------------------------------------------------------------------------- /CHAP_03/ex030600.m: -------------------------------------------------------------------------------- 1 | subplot(1,1,1) 2 | 3 | n = -5:5; x = (-0.9).^n; 4 | 5 | k = -200:200; w = (pi/100)*k; 6 | 7 | X = x * (exp(-j*pi/100)) .^ (n'*k); 8 | 9 | magX = abs(X); angX =angle(X); 10 | 11 | subplot(2,1,1); plot(w/pi,magX);grid 12 | 13 | axis([-2,2,0,15]) 14 | 15 | xlabel('frequency in units of pi'); ylabel('|X|') 16 | 17 | title('Magnitude Part') 18 | 19 | subplot(2,1,2); plot(w/pi,angX)/pi;grid 20 | 21 | axis([-2,2,-1,1]) 22 | 23 | xlabel('frequency in units of pi'); ylabel('radians/pi') 24 | 25 | title('Angle Part') 26 | 27 | -------------------------------------------------------------------------------- /CHAP_03/ex030700.m: -------------------------------------------------------------------------------- 1 | x1 = rand(1,11); x2 = rand(1,11); n = 0:10; 2 | 3 | alpha = 2; beta = 3; 4 | 5 | k = 0:500; w = (pi/500)*k; 6 | 7 | X1 = x1 * (exp(-j*pi/500)).^(n'*k); % DTFT of x1 8 | 9 | X2 = x2 * (exp(-j*pi/500)).^(n'*k); % DTFT of x2 10 | 11 | x = alpha*x1 + beta*x2; % Linear combination of x1 & x2 12 | 13 | X = x * (exp(-j*pi/500)).^(n'*k); % DTFT of x 14 | 15 | % verification 16 | 17 | X_check = alpha*X1 + beta*X2; % Linear Combination of X1 & X2 18 | 19 | error = max(abs(X-X_check)) % Difference 20 | 21 | -------------------------------------------------------------------------------- /CHAP_03/ex030800.m: -------------------------------------------------------------------------------- 1 | x = rand(1,11); n = 0:10; 2 | 3 | k = 0:500; w = (pi/500)*k; 4 | 5 | X = x * (exp(-j*pi/500)).^(n'*k); % DTFT of x 6 | 7 | % signal shifted by two samples 8 | 9 | y = x; m = n+2; 10 | 11 | Y = y * (exp(-j*pi/500)).^(m'*k); % DTFT of y 12 | 13 | % verification 14 | 15 | Y_check = (exp(-j*2).^w).*X; % multiplication by exp(-j2w) 16 | 17 | error = max(abs(Y-Y_check)) % Difference 18 | 19 | -------------------------------------------------------------------------------- /CHAP_03/ex030900.m: -------------------------------------------------------------------------------- 1 | n = 0:100; x = cos(pi*n/2); 2 | 3 | k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi 4 | 5 | X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x 6 | 7 | % 8 | 9 | y = exp(j*pi*n/4).*x; % signal multiplied by exp(j*pi*n/4) 10 | 11 | Y = y * (exp(-j*pi/100)).^(n'*k); % DTFT of y 12 | 13 | % Graphical verification 14 | 15 | subplot(1,1,1) 16 | 17 | subplot(2,2,1); plot(w/pi,abs(X)); grid; axis([-1,1,0,60]) 18 | 19 | xlabel('frequency in pi units'); ylabel('|X|') 20 | 21 | title('Magnitude of X') 22 | 23 | subplot(2,2,2); plot(w/pi,angle(X)/pi); grid; axis([-1,1,-1,1]) 24 | 25 | xlabel('frequency in pi units'); ylabel('radiands/pi') 26 | 27 | title('Angle of X') 28 | 29 | subplot(2,2,3); plot(w/pi,abs(Y)); grid; axis([-1,1,0,60]) 30 | 31 | xlabel('frequency in pi units'); ylabel('|Y|') 32 | 33 | title('Magnitude of Y') 34 | 35 | subplot(2,2,4); plot(w/pi,angle(Y)/pi); grid; axis([-1,1,-1,1]) 36 | 37 | xlabel('frequency in pi units'); ylabel('radians/pi') 38 | 39 | title('Angle of Y') 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /CHAP_03/ex031000.m: -------------------------------------------------------------------------------- 1 | n = -5:10; x = rand(1,length(n)) + j*rand(1,length(n)); 2 | 3 | k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi 4 | 5 | X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x 6 | 7 | % conjugation property 8 | 9 | y = conj(x); % signal conjugation 10 | 11 | Y = y * (exp(-j*pi/100)).^(n'*k); % DTFT of y 12 | 13 | % verification 14 | 15 | Y_check = conj(fliplr(X)); % conj(X(-w)) 16 | 17 | error = max(abs(Y-Y_check)) % Difference 18 | 19 | -------------------------------------------------------------------------------- /CHAP_03/ex031100.m: -------------------------------------------------------------------------------- 1 | n = -5:10; x = rand(1,length(n)); 2 | 3 | k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi 4 | 5 | X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x 6 | 7 | % folding property 8 | 9 | y = fliplr(x); m = -fliplr(n); % signal folding 10 | 11 | Y = y * (exp(-j*pi/100)).^(m'*k); % DTFT of y 12 | 13 | % verification 14 | 15 | Y_check = fliplr(X); % X(-w) 16 | 17 | error = max(abs(Y-Y_check)) % Difference 18 | 19 | -------------------------------------------------------------------------------- /CHAP_03/ex031200.m: -------------------------------------------------------------------------------- 1 | n = -5:10; x = sin(pi*n/2); 2 | 3 | k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi 4 | 5 | X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x 6 | 7 | % signal decomposition 8 | 9 | [xe,xo,m] = evenodd(x,n); % even and odd parts 10 | 11 | XE = xe * (exp(-j*pi/100)).^(m'*k); % DTFT of xe 12 | 13 | XO = xo * (exp(-j*pi/100)).^(m'*k); % DTFT of xo 14 | 15 | % verification 16 | 17 | XR = real(X); % real part of X 18 | 19 | error1 = max(abs(XE-XR)) % Difference 20 | 21 | XI = imag(X); % imag part of X 22 | 23 | error2 = max(abs(XO-j*XI)) % Difference 24 | 25 | % graphical verification 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,2,1); plot(w/pi,XR); grid; axis([-1,1,-2,2]) 30 | 31 | xlabel('frequency in pi units'); ylabel('Re(X)'); 32 | 33 | title('Real part of X') 34 | 35 | subplot(2,2,2); plot(w/pi,XI); grid; axis([-1,1,-10,10]) 36 | 37 | xlabel('frequency in pi units'); ylabel('Im(X)'); 38 | 39 | title('Imaginary part of X') 40 | 41 | subplot(2,2,3); plot(w/pi,real(XE)); grid; axis([-1,1,-2,2]) 42 | 43 | xlabel('frequency in pi units'); ylabel('XE'); 44 | 45 | title('Transform of even part') 46 | 47 | subplot(2,2,4); plot(w/pi,imag(XO)); grid; axis([-1,1,-10,10]) 48 | 49 | xlabel('frequency in pi units'); ylabel('XO'); 50 | 51 | title('Transform of odd part') 52 | 53 | -------------------------------------------------------------------------------- /CHAP_03/ex031300.m: -------------------------------------------------------------------------------- 1 | w = [0:1:500]*pi/500; % [0, pi] axis divided into 501 points. 2 | 3 | X = exp(j*w) ./ (exp(j*w) - 0.9*ones(1,501)); 4 | 5 | magX = abs(X); angX = angle(X); 6 | 7 | subplot(2,1,1); plot(w/pi,magX); grid; axis([0,1,0,10]) 8 | 9 | xlabel('frequency in pi units'); ylabel('|H|'); 10 | 11 | title('Magnitude Response'); 12 | 13 | subplot(2,1,2); plot(w/pi,angX/pi); grid 14 | 15 | xlabel('frequency in pi units'); ylabel('Phase in pi Radians'); 16 | 17 | title('Phase Response'); 18 | 19 | -------------------------------------------------------------------------------- /CHAP_03/ex031500.m: -------------------------------------------------------------------------------- 1 | subplot(1,1,1) 2 | 3 | b = 1; a = [1,-0.8]; 4 | 5 | n=[0:100];x = cos(0.05*pi*n); 6 | 7 | y = filter(b,a,x); 8 | 9 | subplot(2,1,1); stem(n,x); 10 | 11 | xlabel('n'); ylabel('x(n)'); title('Input sequence') 12 | 13 | subplot(2,1,2); stem(n,y); 14 | 15 | xlabel('n'); ylabel('y(n)'); title('Output sequence') 16 | 17 | -------------------------------------------------------------------------------- /CHAP_03/ex031600.m: -------------------------------------------------------------------------------- 1 | b = [0.0181, 0.0543, 0.0543, 0.0181]; 2 | 3 | a = [1.0000, -1.7600, 1.1829, -0.2781]; 4 | 5 | m = 0:length(b)-1; l = 0:length(a)-1; 6 | 7 | K = 500; k = 1:1:K; 8 | 9 | w = pi*k/K; % [0, pi] axis divided into 501 points. 10 | 11 | num = b * exp(-j*m'*w); % Numerator calculations 12 | 13 | den = a * exp(-j*l'*w); % Denominator calculations 14 | 15 | H = num ./ den; 16 | 17 | magH = abs(H); angH = angle(H); 18 | 19 | subplot(1,1,1); 20 | 21 | subplot(2,1,1); plot(w/pi,magH); grid; axis([0,1,0,1]) 22 | 23 | xlabel('frequency in pi units'); ylabel('|H|'); 24 | 25 | title('Magnitude Response'); 26 | 27 | subplot(2,1,2); plot(w/pi,angH/pi); grid 28 | 29 | xlabel('frequency in pi units'); ylabel('Phase in pi Radians'); 30 | 31 | title('Phase Response'); 32 | 33 | -------------------------------------------------------------------------------- /CHAP_03/ex031700.m: -------------------------------------------------------------------------------- 1 | % Analog Signal 2 | 3 | Dt = 0.00005; 4 | 5 | t = -0.005:Dt:0.005; 6 | 7 | xa = exp(-1000*abs(t)); 8 | 9 | % 10 | 11 | % Continuous-time Fourier Transform 12 | 13 | Wmax = 2*pi*2000; 14 | 15 | K = 500; k = 0:1:K; 16 | 17 | W = k*Wmax/K; 18 | 19 | Xa = xa * exp(-j*t'*W) * Dt; 20 | 21 | Xa = real(Xa); 22 | 23 | W = [-fliplr(W), W(2:501)]; % Omega from -Wmax to Wmax 24 | 25 | Xa = [fliplr(Xa), Xa(2:501)]; 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,1,1);plot(t*1000,xa); 30 | 31 | xlabel('t in msec.'); ylabel('xa(t)') 32 | 33 | title('Analog Signal') 34 | 35 | subplot(2,1,2);plot(W/(2*pi*1000),Xa*1000); 36 | 37 | xlabel('Frequency in KHz'); ylabel('Xa(jW)*1000') 38 | 39 | title('Continuous-time Fourier Transform') 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /CHAP_03/ex031800.m: -------------------------------------------------------------------------------- 1 | % Analog Signal 2 | 3 | Dt = 0.00005; 4 | 5 | t = -0.005:Dt:0.005; 6 | 7 | xa = exp(-1000*abs(t)); 8 | 9 | % Discrete-time Signal 10 | 11 | Ts = 0.001; n = -5:1:5; 12 | 13 | x = exp(-1000*abs(n*Ts)); 14 | 15 | % Discrete-time Fourier transform 16 | 17 | K = 500; k = 0:1:K; 18 | 19 | w = pi*k/K; 20 | 21 | X = x * exp(-j*n'*w); 22 | 23 | X = real(X); 24 | 25 | w = [-fliplr(w), w(2:K+1)]; 26 | 27 | X = [fliplr(X), X(2:K+1)]; 28 | 29 | subplot(1,1,1) 30 | 31 | subplot(2,1,1);plot(t*1000,xa); 32 | 33 | xlabel('t in msec.'); ylabel('xa(t)') 34 | 35 | title('Discrete Signal'); hold on 36 | 37 | stem(n*Ts*1000,x); hold off 38 | 39 | subplot(2,1,2);plot(w/pi,X); 40 | 41 | xlabel('Frequency in pi units'); ylabel('X(w)') 42 | 43 | title('Discrete-time Fourier Transform') 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /CHAP_03/ex03180a.m: -------------------------------------------------------------------------------- 1 | % Analog Signal 2 | 3 | Dt = 0.00005; 4 | 5 | t = -0.005:Dt:0.005; 6 | 7 | xa = exp(-1000*abs(t)); 8 | 9 | % Discrete-time Signal 10 | 11 | Ts = 0.0002; n = -25:1:25; 12 | 13 | x = exp(-1000*abs(n*Ts)); 14 | 15 | % Discrete-time Fourier transform 16 | 17 | K = 500; k = 0:1:K; 18 | 19 | w = pi*k/K; 20 | 21 | X = x * exp(-j*n'*w); 22 | 23 | X = real(X); 24 | 25 | w = [-fliplr(w), w(2:K+1)]; 26 | 27 | X = [fliplr(X), X(2:K+1)]; 28 | 29 | subplot(1,1,1) 30 | 31 | subplot(2,1,1);plot(t*1000,xa); 32 | 33 | xlabel('t in msec.'); ylabel('x1(n)') 34 | 35 | title('Discrete Signal'); hold on 36 | 37 | stem(n*Ts*1000,x); gtext('Ts=0.2 msec'); hold off 38 | 39 | subplot(2,1,2);plot(w/pi,X); 40 | 41 | xlabel('Frequency in pi units'); ylabel('X1(w)') 42 | 43 | title('Discrete-time Fourier Transform') 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /CHAP_03/ex03180b.m: -------------------------------------------------------------------------------- 1 | % Analog Signal 2 | 3 | Dt = 0.00005; 4 | 5 | t = -0.005:Dt:0.005; 6 | 7 | xa = exp(-1000*abs(t)); 8 | 9 | % Discrete-time Signal 10 | 11 | Ts = 0.001; n = -5:1:5; 12 | 13 | x = exp(-1000*abs(n*Ts)); 14 | 15 | % Discrete-time Fourier transform 16 | 17 | K = 500; k = 0:1:K; 18 | 19 | w = pi*k/K; 20 | 21 | X = x * exp(-j*n'*w); 22 | 23 | X = real(X); 24 | 25 | w = [-fliplr(w), w(2:K+1)]; 26 | 27 | X = [fliplr(X), X(2:K+1)]; 28 | 29 | subplot(1,1,1) 30 | 31 | subplot(2,1,1);plot(t*1000,xa); 32 | 33 | xlabel('t in msec.'); ylabel('x2(n)') 34 | 35 | title('Discrete Signal'); hold on 36 | 37 | stem(n*Ts*1000,x); gtext('Ts=1 msec'); hold off 38 | 39 | subplot(2,1,2);plot(w/pi,X); 40 | 41 | xlabel('Frequency in pi units'); ylabel('X2(w)') 42 | 43 | title('Discrete-time Fourier Transform') 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /CHAP_03/ex031900.m: -------------------------------------------------------------------------------- 1 | % Chapter 3 : Example 3.19 2 | 3 | % Reconstruction using sinc function 4 | 5 | % 6 | 7 | % Discrete-time Signal x1(n) 8 | 9 | Ts = 0.0002; Fs = 1/Ts; n = -25:1:25; nTs = n*Ts; 10 | 11 | x = exp(-1000*abs(nTs)); 12 | 13 | % Analog Signal reconstruction 14 | 15 | Dt = 0.00005; 16 | 17 | t = -0.005:Dt:0.005; 18 | 19 | xa = x * sinc(Fs*(ones(length(nTs),1)*t-nTs'*ones(1,length(t)))); 20 | 21 | % check 22 | 23 | error = max(abs(xa - exp(-1000*abs(t)))) 24 | 25 | % Plots 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,1,2);plot(t*1000,xa); 30 | 31 | xlabel('t in msec.'); ylabel('xa(t)') 32 | 33 | title('Reconstructed Signal from x1(n) using sinc function'); hold on 34 | 35 | stem(n*Ts*1000,x); hold off 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /CHAP_03/ex032000.m: -------------------------------------------------------------------------------- 1 | % Chapter 3 : Example 3.20 2 | 3 | % Reconstruction and aliasing using sinc function 4 | 5 | % 6 | 7 | % Discrete-time Signal x1(n) 8 | 9 | Ts = 0.001; Fs = 1/Ts; n = -5:1:5; nTs = n*Ts; 10 | 11 | x = exp(-1000*abs(nTs)); 12 | 13 | % Analog Signal reconstruction 14 | 15 | Dt = 0.00005; 16 | 17 | t = -0.005:Dt:0.005; 18 | 19 | xa = x * sinc(Fs*(ones(length(nTs),1)*t-nTs'*ones(1,length(t)))); 20 | 21 | % check 22 | 23 | error = max(abs(xa - exp(-1000*abs(t)))) 24 | 25 | % Plots 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,1,2);plot(t*1000,xa); 30 | 31 | xlabel('t in msec.'); ylabel('xa(t)') 32 | 33 | title('Reconstructed Signal from x2(n) using sinc function'); hold on 34 | 35 | stem(n*Ts*1000,x); hold off 36 | 37 | -------------------------------------------------------------------------------- /CHAP_03/ex032100.m: -------------------------------------------------------------------------------- 1 | % Chapter 3 : Example 3.21 2 | 3 | % Reconstruction using the stairs and plot functions 4 | 5 | % 6 | 7 | figure(1); clf 8 | 9 | % Discrete-time Signal x1(n) : Ts = 0.0002 10 | 11 | Ts = 0.0002; n = -25:1:25; nTs = n*Ts; 12 | 13 | x = exp(-1000*abs(nTs)); 14 | 15 | % Analog Signal reconstruction using stairs 16 | 17 | subplot(2,1,1); stairs(nTs*1000,x); 18 | 19 | xlabel('t in msec.'); ylabel('xa(t)') 20 | 21 | title('Reconstructed Signal from x1(n) using zero-order-hold'); hold on 22 | 23 | stem(n*Ts*1000,x); hold off 24 | 25 | % 26 | 27 | % Analog Signal reconstruction using plot 28 | 29 | subplot(2,1,2); plot(nTs*1000,x); 30 | 31 | xlabel('t in msec.'); ylabel('xa(t)') 32 | 33 | title('Reconstructed Signal from x1(n) using first-order-hold'); hold on 34 | 35 | stem(n*Ts*1000,x); hold off -------------------------------------------------------------------------------- /CHAP_03/ex032200.m: -------------------------------------------------------------------------------- 1 | % Chapter 3 : Example 3.22 2 | 3 | % Reconstruction using cubic splines 4 | 5 | % 6 | 7 | figure(1); clf 8 | 9 | % a) Discrete-time Signal x1(n): Ts = 0.0002 10 | 11 | Ts = 0.0002; n = -25:1:25; nTs = n*Ts; 12 | 13 | x = exp(-1000*abs(nTs)); 14 | 15 | % Analog Signal reconstruction 16 | 17 | Dt = 0.00005; 18 | 19 | t = -0.005:Dt:0.005; 20 | 21 | xa = spline(nTs,x,t); 22 | 23 | % check 24 | 25 | error = max(abs(xa - exp(-1000*abs(t)))) 26 | 27 | % Plots 28 | 29 | subplot(2,1,1);plot(t*1000,xa); 30 | 31 | xlabel('t in msec.'); ylabel('xa(t)') 32 | 33 | title('Reconstructed Signal from x1(n) using cubic spline function'); hold on 34 | 35 | stem(n*Ts*1000,x); hold off 36 | 37 | % 38 | 39 | % Discrete-time Signal x2(n): Ts = 0.001 40 | 41 | Ts = 0.001; n = -5:1:5; nTs = n*Ts; 42 | 43 | x = exp(-1000*abs(nTs)); 44 | 45 | % Analog Signal reconstruction 46 | 47 | Dt = 0.00005; 48 | 49 | t = -0.005:Dt:0.005; 50 | 51 | xa = spline(nTs,x,t); 52 | 53 | % check 54 | 55 | error = max(abs(xa - exp(-1000*abs(t)))) 56 | 57 | % Plots 58 | 59 | subplot(2,1,2);plot(t*1000,xa); 60 | 61 | xlabel('t in msec.'); ylabel('xa(t)') 62 | 63 | title('Reconstructed Signal from x2(n) using cubic spline function'); hold on 64 | 65 | stem(n*Ts*1000,x); hold off -------------------------------------------------------------------------------- /CHAP_03/ex032300.m: -------------------------------------------------------------------------------- 1 | % Chapter 3 : Example 3.21 2 | 3 | % Reconstruction and aliasing using cubic splines 4 | 5 | % 6 | 7 | % Discrete-time Signal x2(n) 8 | 9 | Ts = 0.001; n = -5:1:5; nTs = n*Ts; 10 | 11 | x = exp(-1000*abs(nTs)); 12 | 13 | % Analog Signal reconstruction 14 | 15 | Dt = 0.00005; 16 | 17 | t = -0.005:Dt:0.005; 18 | 19 | xa = spline(nTs,x,t); 20 | 21 | % check 22 | 23 | error = max(abs(xa - exp(-1000*abs(t)))) 24 | 25 | % Plots 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,1,2);plot(t*1000,xa); 30 | 31 | xlabel('t in msec.'); ylabel('xa(t)') 32 | 33 | title('Reconstructed Signal from x2(n)'); hold on 34 | 35 | stem(n*Ts*1000,x); hold off 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /CHAP_03/ex039900.m: -------------------------------------------------------------------------------- 1 | w = [-100:100]*pi/100; % frequency between -pi and +pi 2 | 3 | N = 5; 4 | 5 | X1 = sin((w+eps)*N/2)./sin((w+eps)/2); 6 | 7 | N = 15; 8 | 9 | X2 = sin((w+eps)*N/2)./sin((w+eps)/2); 10 | 11 | N = 25; 12 | 13 | X3 = sin((w+eps)*N/2)./sin((w+eps)/2); 14 | 15 | N = 100; 16 | 17 | X4 = sin((w+eps)*N/2)./sin((w+eps)/2); 18 | 19 | subplot(1,1,1); 20 | 21 | subplot(2,2,1);plot(w/pi,X1);grid 22 | 23 | xlabel('frequency in pi units');title('N=5') 24 | 25 | subplot(2,2,2);plot(w/pi,X2);grid 26 | 27 | xlabel('frequency in pi units');title('N=15') 28 | 29 | subplot(2,2,3);plot(w/pi,X3);grid 30 | 31 | xlabel('frequency in pi units');title('N=25') 32 | 33 | subplot(2,2,4);plot(w/pi,X4);grid 34 | 35 | xlabel('frequency in pi units');title('N=100') 36 | 37 | -------------------------------------------------------------------------------- /CHAP_04/ex040100.m: -------------------------------------------------------------------------------- 1 | % Chapter 4: Example 4.1: 2 | 3 | % X(z) using ztrans 4 | 5 | % x(n) = a^nu(n) 6 | 7 | x = 'a^n'; 8 | 9 | X = ztrans(x) -------------------------------------------------------------------------------- /CHAP_04/ex040400.m: -------------------------------------------------------------------------------- 1 | % Chapter 4: Example 4.4: 2 | 3 | % X(z) using ztrans 4 | 5 | % x(n) = (n-2)(0.5)^(n-2)cos[pi*(n-2)/3]u(n-2) 6 | 7 | x = 'n*((0.5)^n)*cos(pi*n/3)'; 8 | 9 | X = ztrans(x); 10 | 11 | [nX,dX] = numden(X); 12 | 13 | expand(nX), expand(dX); 14 | 15 | dX = symmul(dX,'z^2'); expand(dX) 16 | 17 | -------------------------------------------------------------------------------- /CHAP_04/ex040800.m: -------------------------------------------------------------------------------- 1 | % Chapter 4: Example 4.8: 2 | 3 | % Check of residues in Example 4.7 4 | 5 | % 6 | 7 | b = [0,1]; a = [3,-4,1]; 8 | 9 | [R,p,C] = residuez(b,a) 10 | 11 | % 12 | 13 | [b,a] = residuez(R,p,C) -------------------------------------------------------------------------------- /CHAP_04/ex040900.m: -------------------------------------------------------------------------------- 1 | % Chapter 4: Example 4.8: 2 | 3 | % Check of residue functions rf2pfez and pfe2rfz 4 | 5 | % 6 | 7 | b = 1; a = poly([0.9,0.9,-0.9]) 8 | 9 | [R,p,c] = residuez(b,a) -------------------------------------------------------------------------------- /CHAP_04/ex041000.m: -------------------------------------------------------------------------------- 1 | % Chapter 4: Example 4.10: 2 | 3 | % Check of residue functions rf2pfez and pfe2rfz 4 | 5 | % 6 | 7 | b = [1,0.4*sqrt(2)]; a=[1,-0.8*sqrt(2),0.64]; 8 | 9 | [R,p,C] = residuez(b,a) 10 | 11 | Mp=abs(p') % pole magnitudes 12 | 13 | Ap=angle(p')/pi % pole angles in pi units -------------------------------------------------------------------------------- /CHAP_04/ex041100.m: -------------------------------------------------------------------------------- 1 | % Chapter 4: Example 4.11: 2 | 3 | % zplane function: 4 | 5 | % 6 | 7 | b = [1,0]; a = [1, -0.9]; 8 | 9 | zplane(b,a); title('Pole-Zero Plot'); 10 | 11 | text(0.85,-0.1,'0.9');text(0.01,-0.1,'0'); -------------------------------------------------------------------------------- /CHAP_05/ex050200.m: -------------------------------------------------------------------------------- 1 | % Chapter 5: Example 5.02 2 | 3 | % 4 | 5 | L = 5; N = 20; 6 | 7 | x = [ones(1,L), zeros(1,N-L)]; 8 | 9 | xn = x' * ones(1,3); 10 | 11 | xn = (xn(:))'; 12 | 13 | n = -N:1:2*N-1; 14 | 15 | subplot(1,1,1);subplot(2,1,2); 16 | 17 | stem(n,xn); xlabel('n'); ylabel('xtilde(n)') 18 | 19 | title('Three periods of xtilde(n)') 20 | 21 | axis([-N,2*N-1,-0.5,1.5]) 22 | 23 | %print -deps2 fg0502.eps 24 | 25 | % 26 | 27 | subplot(1,1,1) 28 | 29 | % Part (b)1 30 | 31 | L = 5; N = 20; 32 | 33 | xn = [ones(1,L), zeros(1,N-L)]; 34 | 35 | Xk = dfs(xn,N); 36 | 37 | magXk = abs([Xk(N/2+1:N) Xk(1:N/2+1)]); 38 | 39 | k = [-N/2:N/2]; 40 | 41 | subplot(2,2,1); stem(k,magXk); axis([-N/2,N/2,-0.5,5.5]) 42 | 43 | xlabel('k'); ylabel('Xtilde(k)') 44 | 45 | title('DFS of SQ. wave: L=5, N=20') 46 | 47 | % Part (b)2 48 | 49 | L = 5; N = 40; 50 | 51 | xn = [ones(1,L), zeros(1,N-L)]; 52 | 53 | Xk = dfs(xn,N); 54 | 55 | magXk = abs([Xk(N/2+1:N) Xk(1:N/2+1)]); 56 | 57 | k = [-N/2:N/2]; 58 | 59 | subplot(2,2,2); stem(k,magXk); axis([-N/2,N/2,-0.5,5.5]) 60 | 61 | xlabel('k'); ylabel('Xtilde(k)') 62 | 63 | title('DFS of SQ. wave: L=5, N=40') 64 | 65 | % Part (b)3 66 | 67 | L = 5; N = 60; 68 | 69 | xn = [ones(1,L), zeros(1,N-L)]; 70 | 71 | Xk = dfs(xn,N); 72 | 73 | magXk = abs([Xk(N/2+1:N) Xk(1:N/2+1)]); 74 | 75 | k = [-N/2:N/2]; 76 | 77 | subplot(2,2,3); stem(k,magXk); axis([-N/2,N/2,-0.5,5.5]) 78 | 79 | xlabel('k'); ylabel('Xtilde(k)') 80 | 81 | title('DFS of SQ. wave: L=5, N=60') 82 | 83 | % Part (b)4 84 | 85 | L = 7; N = 60; 86 | 87 | xn = [ones(1,L), zeros(1,N-L)]; 88 | 89 | Xk = dfs(xn,N); 90 | 91 | magXk = abs([Xk(N/2+1:N) Xk(1:N/2+1)]); 92 | 93 | k = [-N/2:N/2]; 94 | 95 | subplot(2,2,4); stem(k,magXk); axis([-N/2,N/2,-0.5,7.5]) 96 | 97 | xlabel('k'); ylabel('Xtilde(k)') 98 | 99 | title('DFS of SQ. wave: L=7, N=60') 100 | 101 | %print -deps2 fg0502b.eps -------------------------------------------------------------------------------- /CHAP_05/ex050500.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.05: Frequency-domain sampling 2 | 3 | % 4 | 5 | % x(n)=(0.7)^n * u(n) 6 | 7 | % X(z)=z/(z-0.7); |z|>0.7 8 | 9 | subplot(1,1,1) 10 | 11 | % 12 | 13 | N = 5; 14 | 15 | k = 0:1:N-1; 16 | 17 | wk = 2*pi*k/N; 18 | 19 | zk = exp(j*wk); 20 | 21 | Xk = (zk)./(zk-0.7); 22 | 23 | xn = real(idfs(Xk,N)); 24 | 25 | xtilde = xn'* ones(1,8); xtilde = (xtilde(:))'; 26 | 27 | subplot(2,2,1); stem(0:39,xtilde);axis([0,40,-0.1,1.5]) 28 | 29 | xlabel('n'); ylabel('xtilde(n)'); title('N=5') 30 | 31 | % 32 | 33 | N = 10; 34 | 35 | k = 0:1:N-1; 36 | 37 | wk = 2*pi*k/N; 38 | 39 | zk = exp(j*wk); 40 | 41 | Xk = (zk)./(zk-0.7); 42 | 43 | xn = real(idfs(Xk,N)); 44 | 45 | xtilde = xn'* ones(1,4); xtilde = (xtilde(:))'; 46 | 47 | subplot(2,2,2); stem(0:39,xtilde);axis([0,40,-0.1,1.5]) 48 | 49 | xlabel('n'); ylabel('xtilde(n)'); title('N=10') 50 | 51 | % 52 | 53 | N = 20; 54 | 55 | k = 0:1:N-1; 56 | 57 | wk = 2*pi*k/N; 58 | 59 | zk = exp(j*wk); 60 | 61 | Xk = (zk)./(zk-0.7); 62 | 63 | xn = real(idfs(Xk,N)); 64 | 65 | xtilde = xn'* ones(1,2); xtilde = (xtilde(:))'; 66 | 67 | subplot(2,2,3); stem(0:39,xtilde);axis([0,40,-0.1,1.5]) 68 | 69 | xlabel('n'); ylabel('xtilde(n)'); title('N=20') 70 | 71 | % 72 | 73 | N = 40; 74 | 75 | k = 0:1:N-1; 76 | 77 | wk = 2*pi*k/N; 78 | 79 | zk = exp(j*wk); 80 | 81 | Xk = (zk)./(zk-0.7); 82 | 83 | xn = real(idfs(Xk,N)); 84 | 85 | subplot(2,2,4); stem(0:39,xn);axis([0,40,-0.1,1.5]) 86 | 87 | xlabel('n'); ylabel('xtilde(n)'); title('N=40') 88 | 89 | -------------------------------------------------------------------------------- /CHAP_05/ex050600.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.06: Simple DFT Example 2 | 3 | % 4 | 5 | x = [1,1,1,1]; 6 | 7 | subplot(1,1,1); 8 | 9 | % 10 | 11 | % a) DTFT 12 | 13 | w = [0:1:500]*2*pi/500; 14 | 15 | [H] = freqz(x,1,w); 16 | 17 | magH = abs(H); phaH = angle(H); phaH(126)=-47.5841*pi/180; 18 | 19 | subplot(2,1,1); plot(w/pi,magH); grid 20 | 21 | xlabel('frequency in pi units'); 22 | 23 | ylabel('|X|'); title('Magnitude of the DTFT') 24 | 25 | subplot(2,1,2); plot(w/pi,phaH/pi*180); grid 26 | 27 | xlabel('frequency in pi units'); 28 | 29 | ylabel('Degrees'); title('Angle of the DTFT') 30 | 31 | %print -deps2 me0506a.eps 32 | 33 | pause;subplot(1,1,1) 34 | 35 | % 36 | 37 | % b) 4-point DFT 38 | 39 | N = 4; w1 = 2*pi/N; k = 0:N-1; 40 | 41 | X = dft(x,N); 42 | 43 | magX = abs(X), phaX = angle(X)*180/pi 44 | 45 | subplot(2,1,1);plot(w*N/(2*pi),magH,'--'); 46 | 47 | axis([-0.1,4.1,-1,5]); hold on 48 | 49 | stem(k,magX); 50 | 51 | xlabel('k'); 52 | 53 | ylabel('|X(k)|'); title('Magnitude of the DFT: N=4') 54 | 55 | hold off 56 | 57 | subplot(2,1,2);plot(w*N/(2*pi),phaH*180/pi,'--'); 58 | 59 | axis([-0.1,4.1,-200,200]); hold on 60 | 61 | stem(k,phaX); 62 | 63 | xlabel('k'); 64 | 65 | ylabel('Degrees'); title('Angle of the DFT: N=4') 66 | 67 | %print -deps2 me0506b.eps 68 | 69 | -------------------------------------------------------------------------------- /CHAP_05/ex050700.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.07: Zero-padding Example 2 | 3 | % 4 | 5 | subplot(1,1,1); 6 | 7 | x = [1,1,1,1]; 8 | 9 | % 10 | 11 | % a) DTFT 12 | 13 | w = [0:1:500]*2*pi/500; 14 | 15 | [H] = freqz(x,1,w); 16 | 17 | magH = abs(H); phaH = angle(H); phaH(126)=-47.5841*pi/180; 18 | 19 | % 20 | 21 | % b) 8-point DFT 22 | 23 | N = 8; w1 = 2*pi/N; k = 0:N-1; 24 | 25 | x = [x, zeros(1,4)]; 26 | 27 | X = dft(x,N); 28 | 29 | magX = abs(X), phaX = angle(X)*180/pi 30 | 31 | subplot(2,1,1);plot(w*N/(2*pi),magH,'--'); 32 | 33 | axis([-0.1,8.1,-1,5]); hold on 34 | 35 | stem(k,magX); 36 | 37 | xlabel('k'); 38 | 39 | ylabel('|X(k)|'); title('Magnitude of the DFT: N=8') 40 | 41 | hold off 42 | 43 | subplot(2,1,2);plot(w*N/(2*pi),phaH*180/pi,'--'); 44 | 45 | axis([-0.1,8.1,-200,200]); hold on 46 | 47 | stem(k,phaX); 48 | 49 | xlabel('k'); 50 | 51 | ylabel('Degrees'); title('Angle of the DFT: N=8');pause 52 | 53 | %print -deps2 me0507a.eps 54 | 55 | % c) 16-point DFT 56 | 57 | subplot(1,1,1) 58 | 59 | N = 16; w1 = 2*pi/N; k = 0:N-1; 60 | 61 | x = [x, zeros(1,8)]; 62 | 63 | X = dft(x,N); 64 | 65 | magX = abs(X), phaX = angle(X)*180/pi 66 | 67 | subplot(2,1,1);plot(w*N/(2*pi),magH,'--'); 68 | 69 | axis([-0.1,16.1,-1,5]); hold on 70 | 71 | stem(k,magX); 72 | 73 | xlabel('k'); 74 | 75 | ylabel('|X(k)|'); title('Magnitude of the DFT: N=16') 76 | 77 | hold off 78 | 79 | subplot(2,1,2);plot(w*N/(2*pi),phaH*180/pi,'--'); 80 | 81 | axis([-0.1,16.1,-200,200]); hold on 82 | 83 | stem(k,phaX); 84 | 85 | xlabel('k'); 86 | 87 | ylabel('Degrees'); title('Angle of the DFT: N=16') 88 | 89 | %print -deps2 me0507b.eps 90 | 91 | -------------------------------------------------------------------------------- /CHAP_05/ex050800.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.08: HiRes Spectrum 2 | 3 | % 4 | 5 | % High resolution spectrum based on 100 samples of the signal x(n) 6 | 7 | subplot(1,1,1) 8 | 9 | n=[0:1:99]; 10 | 11 | x=cos(0.48*pi*n)+cos(0.52*pi*n); 12 | 13 | subplot(2,1,1);stem(n,x);title('signal x(n), 0 <= n <= 99');xlabel('n') 14 | 15 | axis([0,100,-2.5,2.5]) 16 | 17 | X=fft(x);magX=abs(X(1:1:51)); 18 | 19 | k=0:1:50;w=2*pi/100*k; 20 | 21 | subplot(2,1,2);plot(w/pi,magX);title('DTFT Magnitude');xlabel('frequency in pi units') 22 | 23 | axis([0,1,0,60]) 24 | 25 | disp('Press RETURN to continue');pause; 26 | 27 | %print -deps2 me0508c.eps; subplot 28 | 29 | % 30 | 31 | % Spectrum based on the first 10 samples of x(n) 32 | 33 | n1=[0:1:9];y1=x(1:1:10); 34 | 35 | subplot(2,1,1);stem(n1,y1);title('signal x(n), 0 <= n <= 9');xlabel('n') 36 | 37 | axis([0,10,-2.5,2.5]) 38 | 39 | Y1=fft(y1);magY1=abs(Y1(1:1:6)); 40 | 41 | k1=0:1:5;w1=2*pi/10*k1; 42 | 43 | subplot(2,1,2);stem(w1/pi,magY1);title('Samples of DTFT Magnitude'); 44 | 45 | xlabel('frequency in pi units') 46 | 47 | axis([0,1,0,10]) 48 | 49 | disp('Press RETURN to continue');pause; 50 | 51 | print -deps2 me0508a.eps; subplot 52 | 53 | % 54 | 55 | % high density Spectrum (50 samples) based on the first 10 samples of x(n) 56 | 57 | n2=[0:1:49];y2=[x(1:1:10) zeros(1,40)]; 58 | 59 | subplot(2,1,1);stem(n2,y2);title('signal x(n), 0 <= n <= 9 + 40 zeros');xlabel('n') 60 | 61 | axis([0,50,-2.5,2.5]) 62 | 63 | Y2=fft(y2);magY2=abs(Y2(1:1:26)); 64 | 65 | k2=0:1:25;w2=2*pi/50*k2; 66 | 67 | subplot(2,1,2);plot(w2/pi,magY2);title('DTFT Magnitude');xlabel('frequency in pi units') 68 | 69 | axis([0,1,0,10]) 70 | 71 | disp('Press RETURN to continue');pause; subplot 72 | 73 | % 74 | 75 | % High density spectrum (100 samples) based on the first 10 samples of x(n) 76 | 77 | n3=[0:1:99];y3=[x(1:1:10) zeros(1,90)]; 78 | 79 | subplot(2,1,1);stem(n3,y3);title('signal x(n), 0 <= n <= 9 + 90 zeros');xlabel('n') 80 | 81 | axis([0,100,-2.5,2.5]) 82 | 83 | Y3=fft(y3);magY3=abs(Y3(1:1:51)); 84 | 85 | k3=0:1:50;w3=2*pi/100*k3; 86 | 87 | subplot(2,1,2);plot(w3/pi,magY3);title('DTFT Magnitude');xlabel('frequency in pi units') 88 | 89 | axis([0,1,0,10]) 90 | 91 | disp('Press RETURN to continue');pause; 92 | 93 | %print -deps2 me0508b.eps; subplot 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /CHAP_05/ex050802.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.08 2 | 3 | % High density vs HiRes Spectrum 4 | 5 | % 6 | 7 | % signal x(n) 8 | 9 | subplot(1,1,1); 10 | 11 | n = [0:1:99]; x = cos(0.48*pi*n)+cos(0.52*pi*n); 12 | 13 | % 14 | 15 | % Spectrum based on the first 10 samples of x(n) 16 | 17 | n1 = [0:1:9]; y1 = x(1:1:10); 18 | 19 | subplot(2,3,1); stem(n1,y1); 20 | 21 | title('x(n), 0 <= n <= 9');xlabel('n'); 22 | 23 | axis([0,10,-2.5,2.5]); set(gca,'fontsize',10) 24 | 25 | Y1 = fft(y1); magY1 = abs(Y1(1:1:6)); 26 | 27 | k1 = 0:1:5; w1 = 2*pi/10*k1; 28 | 29 | subplot(2,3,4);stem(w1/pi,magY1);title('Samples of DTFT Magnitude'); 30 | 31 | xlabel('frequency in pi units'); axis([0,1,0,10]); set(gca,'fontsize',10) 32 | 33 | % 34 | 35 | % High density spectrum (100 samples) based on the first 10 samples of x(n) 36 | 37 | n2= [0:1:99]; y2 = [x(1:1:10) zeros(1,90)]; 38 | 39 | subplot(2,3,2); stem(n2,y2); title('x(n), 0 <= n <= 9 + 90 zeros'); xlabel('n') 40 | 41 | axis([0,100,-2.5,2.5]); set(gca,'fontsize',10) 42 | 43 | Y2 = fft(y2);magY2=abs(Y2(1:1:51)); 44 | 45 | k2 = 0:1:50; w2 = 2*pi/100*k2; 46 | 47 | subplot(2,3,5); plot(w2/pi,magY2); title('DTFT Magnitude'); xlabel('frequency in pi units') 48 | 49 | axis([0,1,0,10]); set(gca,'fontsize',10) 50 | 51 | % 52 | 53 | % High resolution spectrum based on 100 samples of the signal x(n) 54 | 55 | subplot(2,3,3); stem(n,x); title('x(n), 0 <= n <= 99');xlabel('n') 56 | 57 | axis([0,100,-2.5,2.5]); set(gca,'fontsize',10) 58 | 59 | X = fft(x); magX=abs(X(1:1:51)); 60 | 61 | k = 0:1:50; w = 2*pi/100*k; 62 | 63 | subplot(2,3,6);plot(w/pi,magX);title('DTFT Magnitude');xlabel('frequency in pi units') 64 | 65 | axis([0,1,0,60]); set(gca,'fontsize',10) 66 | 67 | -------------------------------------------------------------------------------- /CHAP_05/ex050900.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.09: Circular symmetry property 2 | 3 | % 4 | 5 | subplot(1,1,1) 6 | 7 | % a) plot x((-n))N 8 | 9 | n = 0:10; x = 10*(0.8) .^ n; 10 | 11 | y = x(mod(-n,11)+1); 12 | 13 | subplot(2,1,1); stem(n,x); title('Original sequence') 14 | 15 | xlabel('n'); ylabel('x(n)'); axis([-0.5,10.5,-1,11]) 16 | 17 | subplot(2,1,2); stem(n,y); title('Circularly folded sequence') 18 | 19 | xlabel('n'); ylabel('x(-n mod 11)'); axis([-0.5,10.5,-1,11]) 20 | 21 | pause; 22 | 23 | %print -deps2 me0509a.eps 24 | 25 | % 26 | 27 | % b) verify property 28 | 29 | X = dft(x,11); Y = dft(y,11); 30 | 31 | subplot(2,2,1); stem(n,real(X)); axis([-0.5,10.5,-5,50]) 32 | 33 | title('Real{DFT[x(n)]}'); xlabel('k'); 34 | 35 | subplot(2,2,2); stem(n,imag(X)); axis([-0.5,10.5,-20,20]) 36 | 37 | title('Imag{DFT[x(n)]}'); xlabel('k'); 38 | 39 | subplot(2,2,3); stem(n,real(Y)); axis([-0.5,10.5,-5,50]) 40 | 41 | title('Real{DFT[x((-n))11]}'); xlabel('k'); 42 | 43 | subplot(2,2,4); stem(n,imag(Y)); axis([-0.5,10.5,-20,20]) 44 | 45 | title('Imag{DFT[x((-n))11]}'); xlabel('k'); 46 | 47 | %print -deps2 me0509b.eps 48 | 49 | -------------------------------------------------------------------------------- /CHAP_05/ex051000.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.10: Circular even/odd property 2 | 3 | % 4 | 5 | subplot(1,1,1) 6 | 7 | % a) plot xec(n) and xoc(n) 8 | 9 | n = 0:10; x = 10*(0.8) .^ n; 10 | 11 | [xec,xoc] = circevod(x); 12 | 13 | subplot(2,1,1); stem(n,xec); title('Circular-even component') 14 | 15 | xlabel('n'); ylabel('xec(n)'); axis([-0.5,10.5,-1,11]) 16 | 17 | subplot(2,1,2); stem(n,xoc); title('Circular-odd component') 18 | 19 | xlabel('n'); ylabel('xoc(n)'); axis([-0.5,10.5,-4,4]) 20 | 21 | pause; 22 | 23 | print -deps2 me0510a.eps 24 | 25 | % 26 | 27 | % b) verify property 28 | 29 | X = dft(x,11); Xec = dft(xec,11); Xoc = dft(xoc,11); 30 | 31 | subplot(2,2,1); stem(n,real(X)); axis([-0.5,10.5,-5,50]) 32 | 33 | title('Real{DFT[x(n)]}'); xlabel('k'); 34 | 35 | subplot(2,2,2); stem(n,imag(X)); axis([-0.5,10.5,-20,20]) 36 | 37 | title('Imag{DFT[x(n)]}'); xlabel('k'); 38 | 39 | subplot(2,2,3); stem(n,real(Xec)); axis([-0.5,10.5,-5,50]) 40 | 41 | title('DFT[xec(n)]'); xlabel('k'); 42 | 43 | subplot(2,2,4); stem(n,imag(Xoc)); axis([-0.5,10.5,-20,20]) 44 | 45 | title('DFT[xoc(n)]'); xlabel('k'); 46 | 47 | print -deps2 me0510b.eps 48 | 49 | -------------------------------------------------------------------------------- /CHAP_05/ex051100.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.11: Circular shift graphical display 2 | 3 | % 4 | 5 | subplot(1,1,1) 6 | 7 | % a) plot x((n+4))11 8 | 9 | n = 0:10; x = 10*(0.8) .^ n; 10 | 11 | n1 = -11:21; x1 = [zeros(1,11), x, zeros(1,11)]; 12 | 13 | subplot(2,2,1); stem(n1,x1); title('Original x(n)') 14 | 15 | xlabel('n'); axis([-6,17,-1,11]) 16 | 17 | x2 = [x, x, x]; 18 | 19 | subplot(2,2,3); stem(n1,x2); title('Periodic extention') 20 | 21 | xlabel('n'); axis([-6,17,-1,11]) 22 | 23 | x3 = [x2(4+1:33), x(1:4)]; 24 | 25 | subplot(2,2,2); stem(n1,x3); title('Periodic shift') 26 | 27 | xlabel('n'); axis([-6,17,-1,11]) 28 | 29 | x4 = x3 .* [zeros(1,11), ones(1,11), zeros(1,11)]; 30 | 31 | subplot(2,2,4); stem(n1,x4); title('Circular shift') 32 | 33 | xlabel('n'); axis([-6,17,-1,11]) 34 | 35 | pause; 36 | 37 | %print -deps2 me0511a.eps 38 | 39 | % 40 | 41 | % b) plot x((n-3))15 42 | 43 | n = 0:10; x = [10*(0.8) .^ n zeros(1,4)]; 44 | 45 | n1 = -15:29; x1 = [zeros(1,15), x, zeros(1,15)]; 46 | 47 | subplot(2,2,1); stem(n1,x1); title('Original x(n)') 48 | 49 | xlabel('n'); axis([-9,25,-1,11]) 50 | 51 | x2 = [x, x, x]; 52 | 53 | subplot(2,2,3); stem(n1,x2); title('Periodic extention') 54 | 55 | xlabel('n'); axis([-9,25,-1,11]) 56 | 57 | x3 = [x2(43:45),x2(1:42)]; 58 | 59 | subplot(2,2,2); stem(n1,x3); title('Periodic shift') 60 | 61 | xlabel('n'); axis([-9,25,-1,11]) 62 | 63 | x4 = x3 .* [zeros(1,15), ones(1,15), zeros(1,15)]; 64 | 65 | subplot(2,2,4); stem(n1,x4); title('Circular shift') 66 | 67 | xlabel('n'); axis([-9,25,-1,11]) 68 | 69 | pause; 70 | 71 | %print -deps2 me0511b.eps 72 | 73 | % 74 | 75 | -------------------------------------------------------------------------------- /CHAP_05/ex051200.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.12: Circular shift example 2 | 3 | % 4 | 5 | subplot(1,1,1) 6 | 7 | % a) plot x((n-6))15 8 | 9 | n = 0:10; x = 10*(0.8) .^ n; 10 | 11 | y = cirshftt(x,6,15); 12 | 13 | n = 0:14; x = [x, zeros(1,4)]; 14 | 15 | subplot(2,1,1); stem(n,x); title('Original sequence') 16 | 17 | xlabel('n'); ylabel('x(n)'); axis([-1,15,-1,11]) 18 | 19 | subplot(2,1,2); stem(n,y); 20 | 21 | title('Circularly shifted sequence, N=15') 22 | 23 | xlabel('n'); ylabel('x((n-6) mod 15)'); 24 | 25 | axis([-1,15,-1,11]) 26 | 27 | pause; print -deps2 me0512.eps -------------------------------------------------------------------------------- /CHAP_05/ex051300.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.12: Circular shift example 2 | 3 | % 4 | 5 | subplot(1,1,1) 6 | 7 | % a) plot x((n-6))15 8 | 9 | n = 0:10; x = 10*(0.8) .^ n; 10 | 11 | y = cirshftt(x,6,15); 12 | 13 | n = 0:14; x = [x, zeros(1,4)]; 14 | 15 | subplot(2,1,1); stem(n,x); title('Original sequence') 16 | 17 | xlabel('n'); ylabel('x(n)'); axis([-1,15,-1,11]) 18 | 19 | subplot(2,1,2); stem(n,y); 20 | 21 | title('Circularly shifted sequence, N=15') 22 | 23 | xlabel('n'); ylabel('x((n-6) mod 15)'); 24 | 25 | axis([-1,15,-1,11]) 26 | 27 | pause; print -deps2 me0512.eps -------------------------------------------------------------------------------- /CHAP_05/ex051400.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.14: Circular convolution example 2 | 3 | % 4 | 5 | x1 = [1,2,2]; x2 = [1,2,3,4]; 6 | 7 | y = circonvt(x1,x2,4) -------------------------------------------------------------------------------- /CHAP_05/ex051500.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.14: Circular convolution example 2 | 3 | % 4 | 5 | % a) 5-point circular convolution 6 | 7 | x1 = [1,2,2]; x2 = [1,2,3,4]; 8 | 9 | y = circonvt(x1,x2,5) 10 | 11 | % b) 6-point circular convolution 12 | 13 | x1 = [1,2,2]; x2 = [1,2,3,4]; 14 | 15 | y = circonvt(x1,x2,6) -------------------------------------------------------------------------------- /CHAP_05/ex051700.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example-5.17: Overlap and save 2 | 3 | % 4 | 5 | n = 0:9; 6 | 7 | x = n+1; Lenx = length(x); 8 | 9 | h = [1,0,-1]; M = 3; M1 = M-1; L = N-M1; 10 | 11 | N = 6; h = [h zeros(1,N-M)]; 12 | 13 | % 14 | 15 | x = [zeros(1,M1), x, zeros(1,N-1)]; 16 | 17 | K = floor((Lenx+M1-1)/(L)); 18 | 19 | Y = zeros(K+1,N); 20 | 21 | for k=0:K 22 | 23 | xk = x(k*L+1:k*L+N); 24 | 25 | Y(k+1,:) = circonvf(xk,h,N); 26 | 27 | end 28 | 29 | Y = Y(:,M:N)'; 30 | 31 | y = (Y(:))'; 32 | 33 | -------------------------------------------------------------------------------- /CHAP_05/ex051800.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example-5.18: olsave function use 2 | 3 | % 4 | 5 | n = 0:9; x = n+1; h = [1,0,-1]; N = 6; 6 | 7 | % 8 | 9 | y = ovrlpsav(x,h,N) 10 | 11 | -------------------------------------------------------------------------------- /CHAP_05/ex052000.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 05.20: Eigenvalues and eigenvectors 2 | 3 | % 4 | 5 | H = [1,4,3,2;2,1,4,3;3,2,1,4;4,3,2,1]; 6 | 7 | [V,D] = eig(H) 8 | 9 | % verification 10 | 11 | h = H(:,1)'; 12 | 13 | Hk = dft(h,4) 14 | 15 | -------------------------------------------------------------------------------- /CHAP_05/ex052200.m: -------------------------------------------------------------------------------- 1 | % Computational Complexity of FFT using MATLAB 2 | 3 | % 4 | 5 | Nmax = 2048; 6 | 7 | fft_time=zeros(1,Nmax); 8 | 9 | for n=1:1:Nmax 10 | 11 | disp(n); 12 | 13 | x=ones(1,n); 14 | 15 | t=clock;fft(x);fft_time(n)=etime(clock,t); 16 | 17 | end 18 | 19 | n=[1:1:Nmax]; 20 | 21 | plot(n,fft_time,'.'); 22 | 23 | save fft_time.mat fft_time n; 24 | 25 | -------------------------------------------------------------------------------- /CHAP_05/ex05220b.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 5.22 Ploting of FFT execution times 2 | 3 | % 4 | 5 | load fft_time.mat; 6 | 7 | top = ceil(max(fft_time)); 8 | 9 | %n = 1:2048; 10 | 11 | subplot 12 | 13 | clg 14 | 15 | plot(n,fft_time,'.');axis([0,2500,0,50]) 16 | 17 | xlabel('N');ylabel('Time in Sec.') 18 | 19 | title('FFT execution times') 20 | 21 | text(2100,top,'o(N*N)') 22 | 23 | text(2100,top/2,'o(N*N/2)') 24 | 25 | text(2100,top/3,'o(N*N/3)') 26 | 27 | text(2100,top/4,'o(N*N/4)') 28 | 29 | text(2100,1,'o(N*logN)') 30 | 31 | -------------------------------------------------------------------------------- /CHAP_05/ex052300.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 5.23 High speed convolution 2 | 3 | % 4 | 5 | conv_time = zeros(1,150); fft_time = zeros(1,150); 6 | 7 | % 8 | 9 | for N = 1:150 10 | 11 | tc = 0; tf=0; 12 | 13 | L = 2*N-1; nu = round((log10(L)/log10(2))+0.45); L = 2^nu; 14 | 15 | for I=1:100 16 | 17 | h = randn(1,N); 18 | 19 | x = rand(1,N); 20 | 21 | t0 = clock; y1 = conv(h,x); t1=etime(clock,t0); 22 | 23 | tc = tc+t1; 24 | 25 | t0 = clock; y2 = ifft(fft(h,L).*fft(x,L)); t2=etime(clock,t0); 26 | 27 | tf = tf+t2; 28 | 29 | end 30 | 31 | % 32 | 33 | conv_time(N)=tc/100; 34 | 35 | fft_time(N)=tf/100; 36 | 37 | end 38 | 39 | % 40 | 41 | n = 1:150; subplot(1,1,1); 42 | 43 | plot(n(25:150),conv_time(25:150),n(25:150),fft_time(25:150)) 44 | 45 | save times.txt conv_time fft_time -ascii -tabs 46 | 47 | -------------------------------------------------------------------------------- /CHAP_05/ex05230b.m: -------------------------------------------------------------------------------- 1 | % Chapter 05: Example 5.23 High speed convolution 2 | 3 | % part b) Plotting of saved data 4 | 5 | % run after part a) 6 | 7 | load times.txt -ascii; 8 | 9 | conv_time=times(1,:); 10 | 11 | hsconv_time=times(2,:); 12 | 13 | n = 1:150; subplot(1,1,1); %set(gca,'LineWidth',10); 14 | 15 | plot(n(25:150),conv_time(25:150),n(25:150),hsconv_time(25:150)) 16 | 17 | axis([0,180,0,0.4]); 18 | 19 | set(gca,'XTickMode','manual','XTick',[25;50;75;100;125;150]); 20 | 21 | set(gca,'YTickMode','manual','YTick',[0.05:0.05:0.35]); %grid 22 | 23 | text(150,0.17,'highspeed') 24 | 25 | text(150,0.155,'convolution') 26 | 27 | text(150,0.34,'convolution') 28 | 29 | xlabel('sequence length N'); ylabel('time in seconds'); 30 | 31 | title('Comparison of convolution times'); -------------------------------------------------------------------------------- /CHAP_06/ex060100.m: -------------------------------------------------------------------------------- 1 | % Chapter 6 : Example 6.1 2 | 3 | % Cascade form conversion 4 | 5 | % 6 | 7 | b = [1,-3,11,-27,18]; a = [16,12,2,-4,-1]; 8 | 9 | [b0,B,A] = dir2cas(b,a) 10 | 11 | format long; delta = impseq(0,0,7); 12 | 13 | hpar = casfiltr(b0,B,A,delta) 14 | 15 | hdir = filter(b,a,delta) -------------------------------------------------------------------------------- /CHAP_06/ex060200.m: -------------------------------------------------------------------------------- 1 | % Chapter 6 : Example 6.2 2 | 3 | % Parallel form conversion 4 | 5 | % 6 | 7 | b = [1,-3,11,-27,18]; a = [16,12,2,-4,-1]; 8 | 9 | [C,B,A] = dir2par(b,a) 10 | 11 | format long; delta = impseq(0,0,7); 12 | 13 | hpar = parfiltr(C,B,A,delta) 14 | 15 | hdir = filter(b,a,delta) 16 | 17 | [b1,a1] = par2dir(C,B,A) -------------------------------------------------------------------------------- /CHAP_06/ex060300.m: -------------------------------------------------------------------------------- 1 | % Chapter 6 : Example 6.3 2 | 3 | % Mixed form conversion 4 | 5 | % 6 | 7 | C = []; B1 = [2,4;3,1]; A1 = [1,1,0.9;1,0.4,-0.4]; 8 | 9 | B2 = [0.5,0.7;1.5,2.5;0.8,1]; A2 = [1,-1,0.8;1,0.5,0.5;1,0,-0.5]; 10 | 11 | [b1,a1] = par2dir(C,B1,A1) 12 | 13 | [b2,a2] = par2dir(C,B2,A2) 14 | 15 | b = conv(b1,b2) 16 | 17 | a = conv(a1,a2) 18 | 19 | [b0,Bc,Ac] = dir2cas(b,a) 20 | 21 | [C,Bp,Ap] = dir2par(b,a) -------------------------------------------------------------------------------- /CHAP_06/ex060600.m: -------------------------------------------------------------------------------- 1 | % Chapter 6 : Example 6.6 Frequency Sampling Form 2 | 3 | % given h(n) 4 | 5 | % 6 | 7 | h = [1,2,3,2,1]/9; 8 | 9 | [C,B,A] = dir2fs(h) 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /CHAP_06/ex060700.m: -------------------------------------------------------------------------------- 1 | % Chapter 6: Example 6.7 2 | 3 | % Freq. Samp. Form: given frequency samples 4 | 5 | % 6 | 7 | M = 32; alpha = (M-1)/2; k = 0:M-1; wk = (2*pi/M)*k; 8 | 9 | magHk = [1,1,1,0.5,zeros(1,25),0.5,1,1]; 10 | 11 | k1 = 0:15; k2 = 16:M-1; 12 | 13 | angHk = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]; 14 | 15 | H = magHk.*exp(j*angHk); 16 | 17 | h = real(ifft(H,M)); 18 | 19 | [C,B,A] = dir2fs(h) -------------------------------------------------------------------------------- /CHAP_07/ex070300.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.3 Amplitude vs Magnitude response 2 | 3 | % 4 | 5 | h = [1,1,1]; 6 | 7 | w = [0:500]*pi/500; 8 | 9 | H = freqz(h,1,w); 10 | 11 | magH = abs(H); phaH = angle(H); 12 | 13 | ampH = ones(1,501)+2*cos(w); angH = -w; 14 | 15 | subplot(1,1,1) 16 | 17 | subplot(2,2,1); plot(w/pi,magH); title('Magnitude Response'); 18 | 19 | xlabel('frequency in pi units'); ylabel('|H|'); grid 20 | 21 | axis([0 1 -1.5 3.5]); 22 | 23 | set(gca,'XTickMode','manual','XTick',[0;0.6667;1]) 24 | 25 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0 ';'2/3';' 1 ']) 26 | 27 | set(gca,'YTickMode','manual','YTick',[0]) 28 | 29 | subplot(2,2,3); plot(w/pi,phaH/pi); title('Piecewise Linear Phase Response'); 30 | 31 | xlabel('frequency in pi units'); ylabel('angle in pi units'); grid 32 | 33 | axis([0 1 -1 1]) 34 | 35 | set(gca,'XTickMode','manual','XTick',[0;0.6667;1]) 36 | 37 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0 ';'2/3';' 1 ']) 38 | 39 | set(gca,'YTickMode','manual','YTick',[-0.6667;0;0.3333]) 40 | 41 | set(gca,'YTickLabelMode','manual','YTickLabels',['-2/3';' 0';' 2/3']) 42 | 43 | subplot(2,2,2); plot(w/pi,ampH); title('Amplitude Response'); 44 | 45 | xlabel('frequency in pi units'); ylabel('Hr'); grid 46 | 47 | axis([0 1 -1.5 3.5]) 48 | 49 | set(gca,'XTickMode','manual','XTick',[0;0.6667;1]) 50 | 51 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0 ';'2/3';' 1 ']) 52 | 53 | set(gca,'YTickMode','manual','YTick',[0]) 54 | 55 | subplot(2,2,4); plot(w/pi,angH/pi); title('Linear Phase Response'); 56 | 57 | xlabel('frequency in pi units'); ylabel('angle in pi units'); grid 58 | 59 | axis([0 1 -1 1]) 60 | 61 | set(gca,'XTickMode','manual','XTick',[0;0.6667;1]) 62 | 63 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0 ';'2/3';' 1 ']) 64 | 65 | set(gca,'YTickMode','manual','YTick',[-0.6667;0]) 66 | 67 | set(gca,'YTickLabelMode','manual','YTickLabels',['-2/3';' 0']) 68 | 69 | -------------------------------------------------------------------------------- /CHAP_07/ex070400.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.4 Type-1 Linear phase FIR filter 2 | 3 | % 4 | 5 | subplot(1,1,1) 6 | 7 | h = [-4,1,-1,-2,5,6,5,-2,-1,1,-4]; 8 | 9 | M = length(h); n = 0:M-1; 10 | 11 | [Hr,w,a,L] = Hr_Type1(h); 12 | 13 | amax = max(a)+1; amin = min(a)-1; 14 | 15 | subplot(2,2,1); stem(n,h); axis([-1 2*L+1 amin amax]) 16 | 17 | xlabel('n'); ylabel('h(n)'); title('Impulse Response') 18 | 19 | subplot(2,2,3); stem(0:L,a); axis([-1 2*L+1 amin amax]) 20 | 21 | xlabel('n'); ylabel('a(n)'); title('a(n) coefficients') 22 | 23 | subplot(2,2,2);plot(w/pi,Hr);grid 24 | 25 | xlabel('frequency in pi units'); ylabel('Hr') 26 | 27 | title('Type-1 Amplitude Response') 28 | 29 | subplot(2,2,4);pzplotz(h,1) 30 | 31 | -------------------------------------------------------------------------------- /CHAP_07/ex070500.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.5 Type-2 Linear phase FIR filter 2 | 3 | % 4 | 5 | subplot(1,1,1) 6 | 7 | h = [-4,1,-1,-2,5,6,6,5,-2,-1,1,-4]; 8 | 9 | M = length(h); n = 0:M-1; 10 | 11 | [Hr,w,b,L] = Hr_Type2(h); 12 | 13 | bmax = max(b)+1; bmin = min(b)-1; 14 | 15 | subplot(2,2,1); stem(n,h); axis([-1 2*L+1 bmin bmax]) 16 | 17 | xlabel('n'); ylabel('h(n)'); title('Impulse Response') 18 | 19 | subplot(2,2,3); stem(1:L,b); axis([-1 2*L+1 bmin bmax]) 20 | 21 | xlabel('n'); ylabel('b(n)'); title('b(n) coefficients') 22 | 23 | subplot(2,2,2);plot(w/pi,Hr);grid 24 | 25 | xlabel('frequency in pi units'); ylabel('Hr') 26 | 27 | title('Type-2 Amplitude Response') 28 | 29 | subplot(2,2,4);pzplotz(h,1) 30 | 31 | -------------------------------------------------------------------------------- /CHAP_07/ex070600.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.6 Type-3 Linear phase FIR filter 2 | 3 | % 4 | 5 | subplot(1,1,1) 6 | 7 | h = [-4,1,-1,-2,5,0,-5,2,1,-1,4]; 8 | 9 | M = length(h); n = 0:M-1; 10 | 11 | [Hr,w,c,L] = Hr_Type3(h); 12 | 13 | cmax = max(c)+1; cmin = min(c)-1; 14 | 15 | subplot(2,2,1); stem(n,h); axis([-1 2*L+1 cmin cmax]) 16 | 17 | xlabel('n'); ylabel('h(n)'); title('Impulse Response') 18 | 19 | subplot(2,2,3); stem(0:L,c); axis([-1 2*L+1 cmin cmax]) 20 | 21 | xlabel('n'); ylabel('c(n)'); title('c(n) coefficients') 22 | 23 | subplot(2,2,2);plot(w/pi,Hr);grid 24 | 25 | xlabel('frequency in pi units'); ylabel('Hr') 26 | 27 | title('Type-3 Amplitude Response') 28 | 29 | subplot(2,2,4);pzplotz(h,1) 30 | 31 | -------------------------------------------------------------------------------- /CHAP_07/ex070700.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.7 Type-4 Linear phase FIR filter 2 | 3 | % 4 | 5 | subplot(1,1,1) 6 | 7 | h = [-4,1,-1,-2,5,6,-6,-5,2,1,-1,4]; 8 | 9 | M = length(h); n = 0:M-1; 10 | 11 | [Hr,w,d,L] = Hr_Type4(h); 12 | 13 | dmax = max(d)+1; dmin = min(d)-1; 14 | 15 | subplot(2,2,1); stem(n,h); axis([-1 2*L+1 dmin dmax]) 16 | 17 | xlabel('n'); ylabel('h(n)'); title('Impulse Response') 18 | 19 | subplot(2,2,3); stem(1:L,d); axis([-1 2*L+1 dmin dmax]) 20 | 21 | xlabel('n'); ylabel('d(n)'); title('d(n) coefficients') 22 | 23 | subplot(2,2,2);plot(w/pi,Hr);grid 24 | 25 | xlabel('frequency in pi units'); ylabel('Hr') 26 | 27 | title('Type-4 Amplitude Response') 28 | 29 | subplot(2,2,4);pzplotz(h,1) 30 | 31 | -------------------------------------------------------------------------------- /CHAP_07/ex070800.m: -------------------------------------------------------------------------------- 1 | % Chapter 07: Example 7.8 Lowpass filter design - Hamming window 2 | 3 | % 4 | 5 | wp = 0.2*pi; ws = 0.3*pi; 6 | 7 | tr_width = ws - wp 8 | 9 | M = ceil(6.6*pi/tr_width) + 1 10 | 11 | n=[0:1:M-1]; 12 | 13 | wc = (ws+wp)/2 14 | 15 | hd = ideal_lp(wc,M); 16 | 17 | w_ham = (hamming(M))'; 18 | 19 | h = hd .* w_ham; 20 | 21 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 22 | 23 | delta_w = 2*pi/1000; 24 | 25 | Rp = -(min(db(1:1:wp/delta_w+1))) % Passband Ripple 26 | 27 | As = -round(max(db(ws/delta_w+1:1:501))) % Min Stopband attenuation 28 | 29 | % plots 30 | 31 | subplot(1,1,1) 32 | 33 | subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response') 34 | 35 | axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('hd(n)') 36 | 37 | subplot(2,2,2); stem(n,w_ham);title('Hamming Window') 38 | 39 | axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)') 40 | 41 | subplot(2,2,3); stem(n,h);title('Actual Impulse Response') 42 | 43 | axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('h(n)') 44 | 45 | subplot(2,2,4); plot(w/pi,db);title('Magnitude Response in dB');grid 46 | 47 | axis([0 1 -100 10]); xlabel('frequency in pi units'); ylabel('Decibels') 48 | 49 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 50 | 51 | set(gca,'YTickMode','manual','YTick',[-50,0]) 52 | 53 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';' 0']) -------------------------------------------------------------------------------- /CHAP_07/ex070900.m: -------------------------------------------------------------------------------- 1 | % Chapter 07: Example 7.9 Lowpass filter design - Kaiser window 2 | 3 | % 4 | 5 | wp = 0.2*pi; ws = 0.3*pi; As = 50; 6 | 7 | tr_width = ws - wp; 8 | 9 | M = ceil((As-7.95)/(14.36*tr_width/(2*pi))+1) + 1 10 | 11 | n=[0:1:M-1]; 12 | 13 | beta = 0.1102*(As-8.7) 14 | 15 | wc = (ws+wp)/2; 16 | 17 | hd = ideal_lp(wc,M); 18 | 19 | w_kai = (kaiser(M,beta))'; 20 | 21 | h = hd .* w_kai; 22 | 23 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 24 | 25 | delta_w = 2*pi/1000; 26 | 27 | As = -round(max(db(ws/delta_w+1:1:501))) % Min Stopband Attenuation 28 | 29 | % Plots 30 | 31 | subplot(1,1,1) 32 | 33 | subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response') 34 | 35 | axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('hd(n)') 36 | 37 | subplot(2,2,2); stem(n,w_kai);title('Kaiser Window') 38 | 39 | axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)') 40 | 41 | subplot(2,2,3); stem(n,h);title('Actual Impulse Response') 42 | 43 | axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('h(n)') 44 | 45 | subplot(2,2,4);plot(w/pi,db);title('Magnitude Response in dB');grid 46 | 47 | axis([0 1 -100 10]); xlabel('frequency in pi units'); ylabel('Decibels') 48 | 49 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 50 | 51 | set(gca,'YTickMode','manual','YTick',[-50,0]) 52 | 53 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';' 0']) -------------------------------------------------------------------------------- /CHAP_07/ex071000.m: -------------------------------------------------------------------------------- 1 | % Chapter 07: Example 7.10 Bandpass filter design - Blackman window 2 | 3 | % 4 | 5 | ws1 = 0.2*pi; wp1 = 0.35*pi; 6 | 7 | wp2 = 0.65*pi; ws2 = 0.8*pi; 8 | 9 | As = 60; 10 | 11 | tr_width = min((wp1-ws1),(ws2-wp2)) 12 | 13 | M = ceil(11*pi/tr_width) + 1 %;M=68 14 | 15 | n=[0:1:M-1]; 16 | 17 | wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2; 18 | 19 | hd = ideal_lp(wc2,M) - ideal_lp(wc1,M); 20 | 21 | w_bla = (blackman(M))'; 22 | 23 | h = hd .* w_bla; 24 | 25 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 26 | 27 | delta_w = 2*pi/1000; 28 | 29 | Rp = -min(db(wp1/delta_w+1:1:wp2/delta_w)) % Actua; Passband Ripple 30 | 31 | As = -round(max(db(ws2/delta_w+1:1:501))) % Min Stopband Attenuation 32 | 33 | % plots 34 | 35 | subplot(1,1,1); 36 | 37 | subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response') 38 | 39 | axis([0 M-1 -0.4 0.5]); xlabel('n'); ylabel('hd(n)') 40 | 41 | subplot(2,2,2); stem(n,w_bla);title('Blackman Window') 42 | 43 | axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)') 44 | 45 | subplot(2,2,3); stem(n,h);title('Actual Impulse Response') 46 | 47 | axis([0 M-1 -0.4 0.5]); xlabel('n'); ylabel('h(n)') 48 | 49 | subplot(2,2,4);plot(w/pi,db);%set(gca,'FontName','cmr12'); 50 | 51 | title('Magnitude Response in dB');grid; 52 | 53 | xlabel('frequency in pi units'); ylabel('Decibels') 54 | 55 | axis([0 1 -150 10]); 56 | 57 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.65,0.8,1]) 58 | 59 | set(gca,'YTickMode','manual','YTick',[-60,0]) 60 | 61 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';' 0']) -------------------------------------------------------------------------------- /CHAP_07/ex071100.m: -------------------------------------------------------------------------------- 1 | % Chapter 07: Example 7.11 Bandstop filter design - Kaiser window 2 | 3 | % 4 | 5 | M = 45; As = 60; n=[0:1:M-1]; 6 | 7 | beta = 0.1102*(As-8.7) 8 | 9 | w_kai = (kaiser(M,beta))'; 10 | 11 | wc1 = pi/3; wc2 = 2*pi/3; 12 | 13 | hd = ideal_lp(wc1,M) + ideal_lp(pi,M) - ideal_lp(wc2,M); 14 | 15 | h = hd .* w_kai; 16 | 17 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 18 | 19 | % 20 | 21 | subplot(1,1,1) 22 | 23 | subplot(2,1,2);plot(w/pi,db); 24 | 25 | title('Magnitude Response in dB');grid; 26 | 27 | xlabel('frequency in pi units'); ylabel('Decibels') 28 | 29 | axis([0 1 -80 10]); 30 | 31 | set(gca,'XTickMode','manual','XTick',[0;0.333;0.667;1]) 32 | 33 | set(gca,'XTickLabelMode','manual',... 34 | 35 | 'XTickLabels',[' 0 ';'1/3';'2/3';' 1 ']) 36 | 37 | set(gca,'YTickMode','manual','YTick',[-60,0]) 38 | 39 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';' 0']) 40 | 41 | %pause; 42 | 43 | print -deps2 ex071101.eps 44 | 45 | % 46 | 47 | M = 45; As = 60; n=[0:1:M-1]; 48 | 49 | beta = 0.1102*(As-8.7)+.3 50 | 51 | w_kai = (kaiser(M,beta))'; 52 | 53 | wc1 = pi/3; wc2 = 2*pi/3; 54 | 55 | hd = ideal_lp(wc1,M) + ideal_lp(pi,M) - ideal_lp(wc2,M); 56 | 57 | h = hd .* w_kai; 58 | 59 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 60 | 61 | % 62 | 63 | % plots 64 | 65 | subplot(1,1,1); 66 | 67 | subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response') 68 | 69 | axis([-1 M -0.2 0.8]); xlabel('n'); ylabel('hd(n)') 70 | 71 | subplot(2,2,2); stem(n,w_kai);title('Kaiser Window') 72 | 73 | axis([-1 M 0 1.1]); xlabel('n'); ylabel('w(n)') 74 | 75 | subplot(2,2,3); stem(n,h);title('Actual Impulse Response') 76 | 77 | axis([-1 M -0.2 0.8]); xlabel('n'); ylabel('h(n)') 78 | 79 | subplot(2,2,4);plot(w/pi,db); 80 | 81 | title('Magnitude Response in dB');grid; 82 | 83 | xlabel('frequency in pi units'); ylabel('Decibels') 84 | 85 | axis([0 1 -80 10]); 86 | 87 | set(gca,'XTickMode','manual','XTick',[0;0.333;0.667;1]) 88 | 89 | set(gca,'XTickLabelMode','manual',... 90 | 91 | 'XTickLabels',[' 0 ';'1/3';'2/3';' 1 ']) 92 | 93 | set(gca,'YTickMode','manual','YTick',[-60,0]) 94 | 95 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';' 0']) 96 | 97 | print -deps2 ex071102.eps -------------------------------------------------------------------------------- /CHAP_07/ex071200.m: -------------------------------------------------------------------------------- 1 | % Chapter 07: Example 7.12 Differentiator design - Hamming window 2 | 3 | % 4 | 5 | M = 21; alpha = (M-1)/2; 6 | 7 | n = 0:M-1; 8 | 9 | hd = (cos(pi*(n-alpha)))./(n-alpha); hd(alpha+1)=0; 10 | 11 | w_ham = (hamming(M))'; 12 | 13 | h = hd .* w_ham; 14 | 15 | [Hr,w,P,L] = Hr_Type3(h); 16 | 17 | % plots 18 | 19 | subplot(1,1,1); 20 | 21 | subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response') 22 | 23 | axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('hd(n)') 24 | 25 | subplot(2,2,2); stem(n,w_ham);title('Hamming Window') 26 | 27 | axis([-1 M 0 1.2]); xlabel('n'); ylabel('w(n)') 28 | 29 | subplot(2,2,3); stem(n,h);title('Actual Impulse Response') 30 | 31 | axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('h(n)') 32 | 33 | subplot(2,2,4);plot(w/pi,Hr/pi); title('Amplitude Response');grid; 34 | 35 | xlabel('frequency in pi units'); ylabel('slope in pi units') 36 | 37 | axis([0 1 0 1]); 38 | 39 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.4,0.6,0.8,1]) 40 | 41 | set(gca,'YTickMode','manual','YTick',[0,0.2,0.4,0.6,0.8,1]) -------------------------------------------------------------------------------- /CHAP_07/ex071300.m: -------------------------------------------------------------------------------- 1 | % Chapter 07: Example 7.13 Hilbert Transformer design - Hanning window 2 | 3 | % 4 | 5 | M = 25; alpha = (M-1)/2; 6 | 7 | n = 0:M-1; 8 | 9 | hd = (2/pi)*((sin((pi/2)*(n-alpha)).^2)./(n-alpha)); hd(alpha+1)=0; 10 | 11 | w_han = (hanning(M))'; 12 | 13 | h = hd .* w_han; 14 | 15 | [Hr,w,P,L] = Hr_Type3(h); 16 | 17 | % plots 18 | 19 | subplot(1,1,1); 20 | 21 | subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response') 22 | 23 | axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('hd(n)') 24 | 25 | subplot(2,2,2); stem(n,w_han);title('Hanning Window') 26 | 27 | axis([-1 M 0 1.2]); xlabel('n'); ylabel('w(n)') 28 | 29 | subplot(2,2,3); stem(n,h);title('Actual Impulse Response') 30 | 31 | axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('h(n)') 32 | 33 | w = w'; Hr = Hr'; 34 | 35 | w = [-fliplr(w), w(2:501)]; Hr = [-fliplr(Hr), Hr(2:501)]; 36 | 37 | subplot(2,2,4);plot(w/pi,Hr); title('Amplitude Response');grid; 38 | 39 | xlabel('frequency in pi units'); ylabel('Hr') 40 | 41 | axis([-1 1 -1.1 1.1]); 42 | 43 | set(gca,'XTickMode','manual','XTick',[-1,0,1]) 44 | 45 | set(gca,'YTickMode','manual','YTick',[-1,0,1]) -------------------------------------------------------------------------------- /CHAP_07/ex071400.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.14 2 | 3 | % Freq. Samp. Tech.: Lowpass,Naive method 4 | 5 | % 6 | 7 | M = 20; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l; 8 | 9 | Hrs = [1,1,1,zeros(1,15),1,1]; 10 | 11 | Hdr = [1,1,0,0]; wdl = [0,0.25,0.25,1]; 12 | 13 | k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; 14 | 15 | angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]; 16 | 17 | H = Hrs.*exp(j*angH); 18 | 19 | h = real(ifft(H,M)); 20 | 21 | [db,mag,pha,grd,w] = freqz_m(h,1); 22 | 23 | [Hr,ww,a,L] = Hr_Type2(h); 24 | 25 | subplot(1,1,1) 26 | 27 | subplot(2,2,1);plot(wl(1:11)/pi,Hrs(1:11),'o',wdl,Hdr); 28 | 29 | axis([0,1,-0.1,1.1]); title('Frequency Samples: M=20') 30 | 31 | xlabel('frequency in pi units'); ylabel('Hr(k)') 32 | 33 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 34 | 35 | set(gca,'YTickMode','manual','YTick',[0,1]); grid 36 | 37 | subplot(2,2,2); stem(l,h); axis([-1,M,-0.1,0.3]) 38 | 39 | title('Impulse Response'); xlabel('n'); ylabel('h(n)'); 40 | 41 | subplot(2,2,3); plot(ww/pi,Hr,wl(1:11)/pi,Hrs(1:11),'o'); 42 | 43 | axis([0,1,-0.2,1.2]); title('Amplitude Response') 44 | 45 | xlabel('frequency in pi units'); ylabel('Hr(w)') 46 | 47 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 48 | 49 | set(gca,'YTickMode','manual','YTick',[0,1]); grid 50 | 51 | subplot(2,2,4);plot(w/pi,db); axis([0,1,-60,10]); grid 52 | 53 | title('Magnitude Response'); xlabel('frequency in pi units'); 54 | 55 | ylabel('Decibels'); 56 | 57 | set(gca,'XTickMode','Manual','XTick',[0;0.2;0.3;1]); 58 | 59 | set(gca,'YTickMode','Manual','YTick',[-16;0]); 60 | 61 | set(gca,'YTickLabelMode','manual','YTickLabels',['16';' 0']) 62 | 63 | % -------------------------------------------------------------------------------- /CHAP_07/ex07150a.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.15 2 | 3 | % Freq. Samp. Tech.: Lowpass,Optimum method 4 | 5 | % 6 | 7 | % (a) T1 = 0.5 8 | 9 | M = 40; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l; 10 | 11 | Hrs = [ones(1,5),0.5,zeros(1,29),0.5,ones(1,4)]; 12 | 13 | Hdr = [1,1,0,0]; wdl = [0,0.25,0.25,1]; 14 | 15 | k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; 16 | 17 | angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]; 18 | 19 | H = Hrs.*exp(j*angH); 20 | 21 | h = real(ifft(H,M)); 22 | 23 | [db,mag,pha,grd,w] = freqz_m(h,1); 24 | 25 | [Hr,ww,a,L] = Hr_Type2(h); 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,2,1);plot(wl(1:21)/pi,Hrs(1:21),'o',wdl,Hdr); 30 | 31 | axis([0,1,-0.1,1.1]); title('Frequency Samples: M=40,T1=0.5') 32 | 33 | xlabel('frequency in pi units'); ylabel('Hr(k)') 34 | 35 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 36 | 37 | set(gca,'YTickMode','manual','YTick',[0,0.5,1]); grid 38 | 39 | subplot(2,2,2); stem(l,h); axis([-1,M,-0.1,0.3]) 40 | 41 | title('Impulse Response'); xlabel('n'); ylabel('h(n)'); 42 | 43 | subplot(2,2,3); plot(ww/pi,Hr,wl(1:21)/pi,Hrs(1:21),'o'); 44 | 45 | axis([0,1,-0.1,1.1]); title('Amplitude Response') 46 | 47 | xlabel('frequency in pi units'); ylabel('Hr(w)') 48 | 49 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 50 | 51 | set(gca,'YTickMode','manual','YTick',[0,0.5,1]); grid 52 | 53 | subplot(2,2,4);plot(w/pi,db); axis([0,1,-100,10]); grid 54 | 55 | title('Magnitude Response'); xlabel('frequency in pi units'); 56 | 57 | ylabel('Decibels'); 58 | 59 | set(gca,'XTickMode','Manual','XTick',[0;0.2;0.3;1]); 60 | 61 | set(gca,'YTickMode','Manual','YTick',[-30;0]); 62 | 63 | set(gca,'YTickLabelMode','manual','YTickLabels',['30';' 0']) 64 | 65 | % 66 | 67 | -------------------------------------------------------------------------------- /CHAP_07/ex07150b.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.15 2 | 3 | % Freq. Samp. Tech.: Lowpass,Optimum method 4 | 5 | % 6 | 7 | % (a) T1 = 0.39 8 | 9 | M = 40; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l; 10 | 11 | Hrs = [ones(1,5),0.3904,zeros(1,29),0.3904,ones(1,4)]; 12 | 13 | Hdr = [1,1,0,0]; wdl = [0,0.25,0.25,1]; 14 | 15 | k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; 16 | 17 | angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]; 18 | 19 | H = Hrs.*exp(j*angH); 20 | 21 | h = real(ifft(H,M)); 22 | 23 | [db,mag,pha,grd,w] = freqz_m(h,1); 24 | 25 | [Hr,ww,a,L] = Hr_Type2(h); 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,2,1);plot(wl(1:21)/pi,Hrs(1:21),'o',wdl,Hdr); 30 | 31 | axis([0,1,-0.1,1.1]); title('Frequency Samples: M=40,T1=0.39') 32 | 33 | xlabel('frequency in pi units'); ylabel('Hr(k)') 34 | 35 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 36 | 37 | set(gca,'YTickMode','manual','YTick',[0,0.39,1]); grid 38 | 39 | subplot(2,2,2); stem(l,h); axis([-1,M,-0.1,0.3]) 40 | 41 | title('Impulse Response'); xlabel('n'); ylabel('h(n)'); 42 | 43 | subplot(2,2,3); plot(ww/pi,Hr,wl(1:21)/pi,Hrs(1:21),'o'); 44 | 45 | axis([0,1,-0.1,1.1]); title('Amplitude Response') 46 | 47 | xlabel('frequency in pi units'); ylabel('Hr(w)') 48 | 49 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 50 | 51 | set(gca,'YTickMode','manual','YTick',[0,0.39,1]); grid 52 | 53 | subplot(2,2,4);plot(w/pi,db); axis([0,1,-100,10]); grid 54 | 55 | title('Magnitude Response'); xlabel('frequency in pi units'); 56 | 57 | ylabel('Decibels'); 58 | 59 | set(gca,'XTickMode','Manual','XTick',[0;0.2;0.3;1]); 60 | 61 | set(gca,'YTickMode','Manual','YTick',[-43;0]); 62 | 63 | set(gca,'YTickLabelMode','manual','YTickLabels',['43';' 0']) 64 | 65 | % -------------------------------------------------------------------------------- /CHAP_07/ex071600.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.16 2 | 3 | % Freq. Samp. Tech.: Lowpass, Optimum method T1 & T2 4 | 5 | % wp = 0.2pi, ws=0.3pi, Rp=0.25dB, As=50dB 6 | 7 | % T1 = 0.5925, T2=0.1099 8 | 9 | M = 60; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l; 10 | 11 | Hrs = [ones(1,7),0.5925,0.11,zeros(1,43),0.11,0.5925,ones(1,6)]; 12 | 13 | Hdr = [1,1,0,0]; wdl = [0,0.2,0.3,1]; 14 | 15 | k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; 16 | 17 | angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]; 18 | 19 | H = Hrs.*exp(j*angH); 20 | 21 | h = real(ifft(H,M)); 22 | 23 | [db,mag,pha,grd,w] = freqz_m(h,1); 24 | 25 | [Hr,ww,a,L] = Hr_Type2(h); 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,2,1);plot(wl(1:31)/pi,Hrs(1:31),'o',wdl,Hdr); 30 | 31 | axis([0,1,-0.1,1.1]); title('Lowpass: M=60,T1=0.59, T2=0.109') 32 | 33 | xlabel('frequency in pi units'); ylabel('Hr(k)') 34 | 35 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 36 | 37 | set(gca,'YTickMode','manual','YTick',[0,0.59,0.109,1]); grid 38 | 39 | subplot(2,2,2); stem(l,h); axis([-1,M,-0.1,0.3]) 40 | 41 | title('Impulse Response'); xlabel('n'); ylabel('h(n)'); 42 | 43 | subplot(2,2,3); plot(ww/pi,Hr,wl(1:31)/pi,Hrs(1:31),'o'); 44 | 45 | axis([0,1,-0.1,1.1]); title('Amplitude Response') 46 | 47 | xlabel('frequency in pi units'); ylabel('Hr(w)') 48 | 49 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 50 | 51 | set(gca,'YTickMode','manual','YTick',[0,0.59,0.109,1]); grid 52 | 53 | subplot(2,2,4);plot(w/pi,db); axis([0,1,-100,10]); grid 54 | 55 | title('Magnitude Response'); xlabel('frequency in pi units'); 56 | 57 | ylabel('Decibels'); 58 | 59 | set(gca,'XTickMode','Manual','XTick',[0;0.2;0.3;1]); 60 | 61 | set(gca,'YTickMode','Manual','YTick',[-63;0]); 62 | 63 | set(gca,'YTickLabelMode','manual','YTickLabels',['63';' 0']) 64 | 65 | % -------------------------------------------------------------------------------- /CHAP_07/ex071700.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.17 2 | 3 | % Freq. Samp. Tech.: Bandpass, Optimum method T1 & T2 4 | 5 | % ws1=0.2pi, wp1=0.35pi, wp2=0.65pi, ws2=0.8pi, Rp=1dB, As=60dB 6 | 7 | % T2 = 0.59417456, T1=0.109021 8 | 9 | M = 40; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l; 10 | 11 | T1 = 0.109021; T2 = 0.59417456; 12 | 13 | Hrs = [zeros(1,5),T1,T2,ones(1,7),T2,T1,zeros(1,9),T1,T2,ones(1,7),T2,T1,zeros(1,4)]; 14 | 15 | Hdr = [0,0,1,1,0,0]; wdl = [0,0.2,0.35,0.65,0.8,1]; 16 | 17 | k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; 18 | 19 | angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]; 20 | 21 | H = Hrs.*exp(j*angH); 22 | 23 | h = real(ifft(H,M)); 24 | 25 | [db,mag,pha,grd,w] = freqz_m(h,1); 26 | 27 | [Hr,ww,a,L] = Hr_Type2(h); 28 | 29 | subplot(1,1,1) 30 | 31 | subplot(2,2,1);plot(wl(1:21)/pi,Hrs(1:21),'o',wdl,Hdr); 32 | 33 | axis([0,1,-0.1,1.1]); title('Bandpass: M=40,T1=0.5941, T2=0.109') 34 | 35 | xlabel('frequency in pi units'); ylabel('Hr(k)') 36 | 37 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.65,0.8,1]) 38 | 39 | set(gca,'YTickMode','manual','YTick',[0,0.59,0.109,1]); grid 40 | 41 | subplot(2,2,2); stem(l,h); axis([-1,M,-0.4,0.4]) 42 | 43 | title('Impulse Response'); xlabel('n'); ylabel('h(n)'); 44 | 45 | subplot(2,2,3); plot(ww/pi,Hr,wl(1:21)/pi,Hrs(1:21),'o'); 46 | 47 | axis([0,1,-0.1,1.1]); title('Amplitude Response') 48 | 49 | xlabel('frequency in pi units'); ylabel('Hr(w)') 50 | 51 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.65,0.8,1]) 52 | 53 | set(gca,'YTickMode','manual','YTick',[0,0.59,0.109,1]); grid 54 | 55 | subplot(2,2,4);plot(w/pi,db); axis([0,1,-100,10]); grid 56 | 57 | title('Magnitude Response'); xlabel('frequency in pi units'); 58 | 59 | ylabel('Decibels'); 60 | 61 | set(gca,'XTickMode','Manual','XTick',[0,0.2,0.35,0.65,0.8,1]); 62 | 63 | set(gca,'YTickMode','Manual','YTick',[-60;0]); 64 | 65 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';' 0']) 66 | 67 | % -------------------------------------------------------------------------------- /CHAP_07/ex071800.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.18 2 | 3 | % Freq. Samp. Tech.: Highpass, Optimum method T1 4 | 5 | % ws=0.6pi, wp=0.8pi, Rp=1dB, As=50dB 6 | 7 | % M=33, T1 = 0.1095; T2 = 0.598; 8 | 9 | M = 33; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l; 10 | 11 | T1 = 0.1095; T2 = 0.598; 12 | 13 | Hrs = [zeros(1,11),T1,T2,ones(1,8),T2,T1,zeros(1,10)]; 14 | 15 | Hdr = [0,0,1,1]; wdl = [0,0.6,0.8,1]; 16 | 17 | k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; 18 | 19 | angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]; 20 | 21 | H = Hrs.*exp(j*angH); 22 | 23 | h = real(ifft(H,M)); 24 | 25 | [db,mag,pha,grd,w] = freqz_m(h,1); 26 | 27 | [Hr,ww,a,L] = Hr_Type1(h); 28 | 29 | subplot(1,1,1) 30 | 31 | subplot(2,2,1);plot(wl(1:17)/pi,Hrs(1:17),'o',wdl,Hdr); 32 | 33 | axis([0,1,-0.1,1.1]); title('Highpass: M=33,T1=0.1095,T2=0.598') 34 | 35 | xlabel('frequency in pi units'); ylabel('Hr(k)') 36 | 37 | set(gca,'XTickMode','manual','XTick',[0;.6;.8;1]) 38 | 39 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0';'.6';'.8';' 1']) 40 | 41 | set(gca,'YTickMode','manual','YTick',[0,0.109,0.59,1]); grid 42 | 43 | subplot(2,2,2); stem(l,h); axis([-1,M,-0.4,0.4]) 44 | 45 | title('Impulse Response'); xlabel('n'); ylabel('h(n)'); 46 | 47 | subplot(2,2,3); plot(ww/pi,Hr,wl(1:17)/pi,Hrs(1:17),'o'); 48 | 49 | axis([0,1,-0.1,1.1]); title('Amplitude Response') 50 | 51 | xlabel('frequency in pi units'); ylabel('Hr(w)') 52 | 53 | set(gca,'XTickMode','manual','XTick',[0;.6;.8;1]) 54 | 55 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0';'.6';'.8';' 1']) 56 | 57 | set(gca,'YTickMode','manual','YTick',[0,0.109,0.59,1]); grid 58 | 59 | subplot(2,2,4);plot(w/pi,db); axis([0,1,-100,10]); grid 60 | 61 | title('Magnitude Response'); xlabel('frequency in pi units'); 62 | 63 | ylabel('Decibels'); 64 | 65 | set(gca,'XTickMode','manual','XTick',[0;.6;.8;1]) 66 | 67 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0';'.6';'.8';' 1']) 68 | 69 | set(gca,'YTickMode','Manual','YTick',[-50;0]); 70 | 71 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';' 0']) 72 | 73 | % -------------------------------------------------------------------------------- /CHAP_07/ex071900.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.19 2 | 3 | % Freq. Samp. Tech.: Differentiator 4 | 5 | % 6 | 7 | M = 33; alpha = (M-1)/2; Dw = 2*pi/M; 8 | 9 | l = 0:M-1; wl = Dw*l; 10 | 11 | k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; 12 | 13 | Hrs = [j*Dw*k1,-j*Dw*(M-k2)]; 14 | 15 | angH = [-alpha*Dw*k1, alpha*Dw*(M-k2)]; 16 | 17 | H = Hrs.*exp(j*angH); 18 | 19 | h = real(ifft(H,M)); 20 | 21 | [Hr,ww,a,P]=Hr_Type3(h); 22 | 23 | % 24 | 25 | % plots 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,1,1); k = 1:(M+1)/2; 30 | 31 | plot(ww/pi,+Hr/pi,wl(k)/pi,abs(Hrs(k))/pi,'o',wl(k)/pi,wl(k)/pi); 32 | 33 | title('Differentiator, frequency sampling design : M = 33'); 34 | 35 | xlabel('frequency in pi units'); ylabel('Hr in pi units'); 36 | 37 | subplot(2,1,2); stem(l,h); axis([-1,M,-1.1,1.1]); 38 | 39 | title('Impulse response'); xlabel('n'); ylabel('h(n)'); 40 | 41 | set(gca,'XTickMode','manual','XTick',[0;alpha;M-1]) 42 | 43 | -------------------------------------------------------------------------------- /CHAP_07/ex072000.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.20 2 | 3 | % Freq. Samp. Tech.: Hilbert Transformer 4 | 5 | % 6 | 7 | M = 51; alpha = (M-1)/2; Dw = 2*pi/M; 8 | 9 | l = 0:M-1; wl = Dw*l; 10 | 11 | k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; 12 | 13 | Hrs = [0,-j*ones(1,(M-3)/2),-0.39j,0.39j,j*ones(1,(M-3)/2)]; 14 | 15 | angH = [-alpha*Dw*k1, alpha*Dw*(M-k2)]; 16 | 17 | H = Hrs.*exp(j*angH); 18 | 19 | h = real(ifft(H,M)); 20 | 21 | [Hr,ww,a,P]=Hr_Type3(h); 22 | 23 | % 24 | 25 | % plots 26 | 27 | subplot(1,1,1) 28 | 29 | subplot(2,1,1); k = 1:(M+1)/2; 30 | 31 | plot(ww/pi,-Hr,wl(k)/pi,abs(H(k)),'o'); 32 | 33 | title('Hilbert Transformer, frequency sampling design : M = 51') 34 | 35 | xlabel('frequency in pi units'); ylabel('Amplitude response') 36 | 37 | set(gca,'XTickMode','manual','XTick',[0:0.2:1]) 38 | 39 | set(gca,'YTickMode','manual','YTick',[0;0.39;1]);grid 40 | 41 | subplot(2,1,2); stem(l,h); axis([-1,M,-1,1]); 42 | 43 | title('Impulse response'); xlabel('n'); ylabel('h(n)'); 44 | 45 | set(gca,'XTickMode','manual','XTick',[0;alpha;M-1]) 46 | 47 | -------------------------------------------------------------------------------- /CHAP_07/ex072200.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Example 7.22 2 | 3 | % Error function plot and counting of extrema 4 | 5 | figure(1);subplot(1,1,1) 6 | 7 | h = [1,2,3,4,3,2,1]/15; 8 | 9 | M = length(h); n = 0:M-1; 10 | 11 | [Hr,w,a,L] = Hr_Type1(h); 12 | 13 | subplot(1,2,1);plot(w/pi,Hr);axis([0,1,-0.05,1.1]) 14 | 15 | xlabel('frequency in pi units'); 16 | 17 | title('Amplitude Response');hold on 18 | 19 | wp = w(1:52); ws = w(197:500); 20 | 21 | upb=Hr(1)*ones(length(wp),1); 22 | 23 | lpb=(2-Hr(1))*ones(length(wp),1); 24 | 25 | ipb=ones(length(wp),1); 26 | 27 | plot(wp/pi,upb,'r',wp/pi,ipb,'g',wp/pi,lpb,'r') 28 | 29 | usb=Hr(197)*ones(length(ws),1); 30 | 31 | lsb=zeros(length(ws),1); 32 | 33 | isb=0.5*usb; 34 | 35 | plot(ws/pi,usb,'r',ws/pi,isb,'g',ws/pi,lsb,'r'); 36 | 37 | set(gca,'XTickMode','manual','XTick',[0,0.1,0.39,1]) 38 | 39 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0 ';'0.1';'0.4';' 1 ']) 40 | 41 | set(gca,'XGrid','on') 42 | 43 | set(gca,'YTickMode','manual','YTick',[0,0.0394,0.0787,0.933,1,1.067]) 44 | 45 | set(gca,'YTickLabelMode','manual',... 46 | 47 | 'YTickLabels',['-0.04';' 0.0 ';' 0.04';' 0.93';' 1.0 ';' 1.07']) 48 | 49 | hold off 50 | 51 | % 52 | 53 | %Error function plots 54 | 55 | subplot(1,2,2); 56 | 57 | erpb=Hr(1:52)-ipb; ersb=Hr(197:500)-isb; 58 | 59 | plot(wp/pi,erpb,ws/pi,ersb); axis([0,1,-.55,.55]); 60 | 61 | xlabel('frequency in pi units'); 62 | 63 | title('Error Function');hold on 64 | 65 | plot(wp/pi,upb-ipb,'r',wp/pi,lpb-ipb,'r') 66 | 67 | plot(ws/pi,usb-isb,'r',ws/pi,lsb-isb,'r'); 68 | 69 | set(gca,'XTickMode','manual','XTick',[0,0.1,0.39,1]) 70 | 71 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0 ';'0.1';'0.4';' 1 ']) 72 | 73 | set(gca,'XGrid','on') 74 | 75 | set(gca,'YTickMode','manual','YTick',[-0.07,0,0.07]) 76 | 77 | hold off 78 | 79 | -------------------------------------------------------------------------------- /CHAP_07/ex072300.m: -------------------------------------------------------------------------------- 1 | % Chapter 7 Example 7.23 2 | 3 | % Lowpass filter design using PM algorithm 4 | 5 | % 6 | 7 | wp = 0.2*pi; ws = 0.3*pi; Rp = 0.25; As = 50; 8 | 9 | delta1 = (10^(Rp/20)-1)/(10^(Rp/20)+1) 10 | 11 | delta2 = (1+delta1)*(10^(-As/20)) 12 | 13 | deltaH = max(delta1,delta2); deltaL = min(delta1,delta2); 14 | 15 | weights = [delta2/delta1 1] 16 | 17 | deltaf = (ws-wp)/(2*pi) 18 | 19 | M = ceil((-20*log10(sqrt(delta1*delta2))-13)/(14.6*deltaf)+1) 20 | 21 | f = [0 wp/pi ws/pi 1] 22 | 23 | m = [1 1 0 0]; 24 | 25 | h = remez(M-1,f,m,weights); 26 | 27 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 28 | 29 | delta_w = 2*pi/1000; wsi=ws/delta_w+1; wpi = wp/delta_w; 30 | 31 | Asd = -max(db(wsi:1:501)) 32 | 33 | M = M+1; 34 | 35 | h = remez(M-1,f,m,weights); 36 | 37 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 38 | 39 | Asd = -max(db(wsi:1:501)) 40 | 41 | M = M+1; 42 | 43 | h = remez(M-1,f,m,weights); 44 | 45 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 46 | 47 | Asd = -max(db(wsi:1:501)) 48 | 49 | M = M+1; 50 | 51 | h = remez(M-1,f,m,weights); 52 | 53 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 54 | 55 | Asd = -max(db(wsi:1:501)) 56 | 57 | M = M+1; 58 | 59 | h = remez(M-1,f,m,weights); 60 | 61 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 62 | 63 | Asd = -max(db(wsi:1:501)) 64 | 65 | M 66 | 67 | [Hr,omega,P,L] = ampl_res(h); 68 | 69 | % 70 | 71 | % Plots 72 | 73 | figure(1); subplot(1,1,1) 74 | 75 | subplot(2,2,1); stem([0:1:M-1],h); title('Actual Impulse Response') 76 | 77 | axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('h(n)') 78 | 79 | set(gca,'XTickMode','manual','XTick',[0,M-1]) 80 | 81 | set(gca,'YTickMode','manual','YTick',[-0.1:0.1:0.3]) 82 | 83 | subplot(2,2,2);plot(w/pi,db);title('Magnitude Response in dB'); 84 | 85 | axis([0,1,-80,10]); xlabel('frequency in pi units'); ylabel('DECIBELS') 86 | 87 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 88 | 89 | set(gca,'YTickMode','manual','YTick',[-50,0]); 90 | 91 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';' 0']);grid 92 | 93 | subplot(2,2,3);plot(omega/pi,Hr);title('Amplitude Response'); 94 | 95 | axis([0 1 -0.1 1.1]); xlabel('frequency in pi units'); ylabel('Hr(w)') 96 | 97 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 98 | 99 | set(gca,'YTickMode','manual','YTick',[0,1]);grid 100 | 101 | subplot(2,2,4); 102 | 103 | pbw = omega(1:1:wpi+1)/pi; pbe = Hr(1:1:wpi+1)-1; 104 | 105 | sbw = omega(wsi+1:501)/pi; sbe = Hr(wsi+1:501); 106 | 107 | plot(pbw,pbe,sbw,sbe); 108 | 109 | axis([0,1,-deltaH,deltaH]);title('Error Response'); 110 | 111 | xlabel('frequency in pi units'); ylabel('Hr(w)') 112 | 113 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]) 114 | 115 | set(gca,'YTickMode','manual','YTick',[-deltaH,-deltaL,0,deltaL,deltaH]); 116 | 117 | set(gca,'XGrid','on') -------------------------------------------------------------------------------- /CHAP_07/ex072500.m: -------------------------------------------------------------------------------- 1 | % Chapter 7 Example 7.25 2 | 3 | % Highpass filter design using PM algorithm 4 | 5 | % 6 | 7 | ws = 0.6*pi; wp = 0.75*pi; Rp = 0.5; As = 50; 8 | 9 | delta1 = (10^(Rp/20)-1)/(10^(Rp/20)+1); 10 | 11 | delta2 = (1+delta1)*(10^(-As/20)); 12 | 13 | deltaH = max(delta1,delta2); deltaL = min(delta1,delta2); 14 | 15 | weights = [1 delta2/delta1]; 16 | 17 | deltaf = (wp-ws)/(2*pi); 18 | 19 | M = ceil((-20*log10(sqrt(delta1*delta2))-13)/(14.6*deltaf)+1); 20 | 21 | % M must be odd 22 | 23 | M = 2*floor(M/2)+1 24 | 25 | f = [0 ws/pi wp/pi 1] 26 | 27 | m = [0 0 1 1]; 28 | 29 | h = remez(M-1,f,m,weights); 30 | 31 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 32 | 33 | delta_w = 2*pi/1000; wsi=ws/delta_w; wpi = wp/delta_w; 34 | 35 | Asd = -max(db(1:1:wsi)) 36 | 37 | M = M+2; 38 | 39 | h = remez(M-1,f,m,weights); 40 | 41 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 42 | 43 | Asd = -max(db(1:1:wsi)) 44 | 45 | M 46 | 47 | [Hr,omega,P,L] = ampl_res(h); 48 | 49 | % 50 | 51 | % Plots 52 | 53 | figure(1); subplot(1,1,1) 54 | 55 | subplot(2,2,1); stem([0:1:M-1],h); title('Actual Impulse Response') 56 | 57 | axis([0 M-1 -0.4 0.4]); xlabel('n'); ylabel('h(n)') 58 | 59 | set(gca,'XTickMode','manual','XTick',[0,M-1]) 60 | 61 | set(gca,'YTickMode','manual','YTick',[-0.4:0.2:0.4]) 62 | 63 | subplot(2,2,2);plot(w/pi,db);title('Magnitude Response in dB'); 64 | 65 | axis([0,1,-80,10]); xlabel('frequency in pi units'); ylabel('DECIBELS') 66 | 67 | set(gca,'XTickMode','manual','XTick',f) 68 | 69 | set(gca,'YTickMode','manual','YTick',[-50,0]);grid 70 | 71 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';' 0']); 72 | 73 | subplot(2,2,3);plot(omega/pi,Hr);title('Amplitude Response'); 74 | 75 | axis([0 1 -0.1 1.1]); xlabel('frequency in pi units'); ylabel('Hr(w)') 76 | 77 | set(gca,'XTickMode','manual','XTick',f) 78 | 79 | set(gca,'YTickMode','manual','YTick',[0,1]);grid 80 | 81 | subplot(2,2,4); 82 | 83 | sbw = omega(1:1:wsi+1)/pi; sbe = Hr(1:1:wsi+1); 84 | 85 | pbw = omega(wpi+1:501)/pi; pbe = Hr(wpi+1:501)-1; 86 | 87 | plot(sbw,sbe,pbw,pbe); 88 | 89 | axis([0,1,-deltaH,deltaH]);title('Error Response'); 90 | 91 | xlabel('frequency in pi units'); ylabel('Hr(w)') 92 | 93 | set(gca,'XTickMode','manual','XTick',f) 94 | 95 | set(gca,'YTickMode','manual','YTick',[-deltaH,-deltaL,0,deltaL,deltaH]); 96 | 97 | set(gca,'XGrid','on') -------------------------------------------------------------------------------- /CHAP_07/ex072600.m: -------------------------------------------------------------------------------- 1 | % Chapter 7 Example 7.26 2 | 3 | % Staircase filter design using PM algorithm 4 | 5 | % 6 | 7 | w1 = 0; w2 = 0.3*pi; delta1 = 0.01; 8 | 9 | w3 = 0.4*pi; w4 = 0.7*pi; delta2 = 0.005; 10 | 11 | w5 = 0.8*pi; w6 = pi; delta3 = 0.001; 12 | 13 | deltaH = max([delta1,delta2,delta3]); deltaL = min([delta1,delta2,delta3]); 14 | 15 | weights = [delta3/delta1 delta3/delta2 1] 16 | 17 | delta_f = min((w3-w2)/(2*pi), (w5-w3)/(2*pi)) 18 | 19 | M = ceil((-20*log10(sqrt(delta1*delta2))-13)/(14.6*delta_f)+1) 20 | 21 | f = [0 w2/pi w3/pi w4/pi w5/pi 1] 22 | 23 | m = [1 1 0.5 0.5 0 0]; 24 | 25 | h = remez(M-1,f,m,weights); 26 | 27 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 28 | 29 | delta_w = 2*pi/1000; 30 | 31 | w1i=floor(w1/delta_w)+1; w2i = floor(w2/delta_w)+1; 32 | 33 | w3i=floor(w3/delta_w)+1; w4i = floor(w4/delta_w)+1; 34 | 35 | w5i=floor(w5/delta_w)+1; w6i = floor(w6/delta_w)+1; 36 | 37 | Asd = -max(db(w5i:w6i)) 38 | 39 | % optimum value was found at M=49 40 | 41 | M = 49; 42 | 43 | h = remez(M-1,f,m,weights); 44 | 45 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 46 | 47 | Asd = -max(db(w5i:w6i)) 48 | 49 | [Hr,omega,P,L] = ampl_res(h); 50 | 51 | % 52 | 53 | % Plots 54 | 55 | figure(1); subplot(1,1,1) 56 | 57 | subplot(2,2,1); stem([0:1:M-1],h); title('Actual Impulse Response') 58 | 59 | axis([0,M-1,-0.1,0.6]); xlabel('n'); ylabel('h(n)') 60 | 61 | set(gca,'XTickMode','manual','XTick',[0,M-1]) 62 | 63 | set(gca,'YTickMode','manual','YTick',[-0.1:0.1:0.6]) 64 | 65 | subplot(2,2,2);plot(w/pi,db);title('Magnitude Response in dB'); 66 | 67 | axis([0,1,-80,10]); xlabel('frequency in pi units'); ylabel('DECIBELS') 68 | 69 | set(gca,'XTickMode','manual','XTick',f) 70 | 71 | set(gca,'YTickMode','manual','YTick',[-60,0]); 72 | 73 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';' 0']);grid 74 | 75 | subplot(2,2,3);plot(omega/pi,Hr);title('Amplitude Response'); 76 | 77 | axis([0 1 -0.1 1.1]); xlabel('frequency in pi units'); ylabel('Hr(w)') 78 | 79 | set(gca,'XTickMode','manual','XTick',f) 80 | 81 | set(gca,'YTickMode','manual','YTick',[0,0.5,1]);grid 82 | 83 | delta_w = 2*pi/1000; sp_edge = w5/delta_w+1; 84 | 85 | subplot(2,2,4); 86 | 87 | b1w = omega(w1i:w2i)/pi; b1e = (Hr(w1i:w2i)-m(1))*weights(1); 88 | 89 | b2w = omega(w3i:w4i)/pi; b2e = (Hr(w3i:w4i)-m(3))*weights(2); 90 | 91 | b3w = omega(w5i:w6i)/pi; b3e = (Hr(w5i:w6i)-m(5))*weights(3); 92 | 93 | plot(b1w,b1e,b2w,b2e,b3w,b3e); 94 | 95 | title('Weighted Error'); 96 | 97 | axis([0,1,-delta3,delta3]); 98 | 99 | xlabel('frequency in pi units'); ylabel('Hr(w)') 100 | 101 | set(gca,'XTickMode','manual','XTick',f) 102 | 103 | set(gca,'YTickMode','manual','YTick',[-delta3,0,delta3]); 104 | 105 | grid 106 | 107 | -------------------------------------------------------------------------------- /CHAP_07/ex072700.m: -------------------------------------------------------------------------------- 1 | % Chapter 7 Example 7.27 2 | 3 | % Differentiator design using PM algorithm 4 | 5 | % 6 | 7 | f = [0 0.2 0.4 0.6 0.8 1]; % in w/pi unis 8 | 9 | %m = [1 1 2 2 3 3]; % in sam/cycle (old version) 10 | 11 | m = [0,0.1,0.4,0.6,1.2,1.5]; % new Student Edition 12 | 13 | h = remez(25,f,m,'differentiator'); 14 | 15 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 16 | 17 | figure(1); subplot(1,1,1) 18 | 19 | subplot(2,1,1); stem([0:25],h); title('Impulse Response'); 20 | 21 | xlabel('n'); ylabel('h(n)'); axis([0,25,-0.6,0.6]) 22 | 23 | set(gca,'XTickMode','manual','XTick',[0,25]) 24 | 25 | set(gca,'YTickMode','manual','YTick',[-0.6:0.2:0.6]); 26 | 27 | subplot(2,1,2); plot(w/(2*pi),mag); title('Magnitude Response') 28 | 29 | xlabel('Normalized frequency f'); ylabel('|H|') 30 | 31 | set(gca,'XTickMode','manual','XTick',f/2) 32 | 33 | set(gca,'YTickMode','manual','YTick',m) 34 | 35 | grid -------------------------------------------------------------------------------- /CHAP_07/ex072800.m: -------------------------------------------------------------------------------- 1 | % Chapter 7 Example 7.28 2 | 3 | % Hilbert transformer design using PM algorithm 4 | 5 | % 6 | 7 | f = [0.05,0.95]; m = [1 1]; M = 51; N = M-1; 8 | 9 | h = remez(N,f,m,'hilbert'); 10 | 11 | [db,mag,pha,grd,w] = freqz_m(h,[1]); 12 | 13 | figure(1); subplot(1,1,1) 14 | 15 | subplot(2,1,1); stem([0:N],h); title('Impulse Response'); 16 | 17 | xlabel('n'); ylabel('h(n)'); axis([0,N,-0.8,0.8]) 18 | 19 | set(gca,'XTickMode','manual','XTick',[0,N]) 20 | 21 | set(gca,'YTickMode','manual','YTick',[-0.8:0.2:0.8]); 22 | 23 | subplot(2,1,2); plot(w/pi,mag); title('Magnitude Response') 24 | 25 | xlabel('frequency in pi units'); ylabel('|H|') 26 | 27 | set(gca,'XTickMode','manual','XTick',[0,f,1]) 28 | 29 | set(gca,'YTickMode','manual','YTick',[0,1]);grid -------------------------------------------------------------------------------- /CHAP_08/ex080200.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.2 2 | 3 | % Calculation of Butterworth Ha(s) given |Ha(jW)| 4 | 5 | % 6 | 7 | N = 3; OmegaC = 0.5; 8 | 9 | [b,a] = u_buttap(N,OmegaC); 10 | 11 | [C,B,A] = sdir2cas(b,a) 12 | 13 | %%C = 0.1250 14 | 15 | %%B = 0 0 1 16 | 17 | %%A = 1.0000 0.5000 0.2500 18 | 19 | %% 0 1.0000 0.5000 -------------------------------------------------------------------------------- /CHAP_08/ex080400.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.4 2 | 3 | % Butterworth Lowpass Analog filter design 4 | 5 | % 6 | 7 | Wp = 0.2*pi; Ws = 0.3*pi; Rp = 7; As = 16; 8 | 9 | Ripple = 10 ^ (-Rp/20); Attn = 10 ^ (-As/20); 10 | 11 | 12 | 13 | % Analog filter design: 14 | 15 | [b,a] = afd_butt(Wp,Ws,Rp,As); 16 | 17 | %%*** Butterworth Filter Order = 3 18 | 19 | 20 | 21 | % Calculation of second-order sections: 22 | 23 | [C,B,A] = sdir2cas(b,a) 24 | 25 | %%C = 0.1238 26 | 27 | %%B = 0 0 1 28 | 29 | %%A = 1.0000 0.4985 0.2485 30 | 31 | %% 0 1.0000 0.4985 32 | 33 | 34 | 35 | % Calculation of Frequency Response: 36 | 37 | [db,mag,pha,w] = freqs_m(b,a,0.5*pi); 38 | 39 | 40 | 41 | % Calculation of Impulse response: 42 | 43 | [ha,x,t] = impulse(b,a); 44 | 45 | 46 | 47 | % Plots 48 | 49 | subplot(2,2,1); plot(w/pi,mag);title('Magnitude Response') 50 | 51 | xlabel('Analog frequency in pi units'); ylabel('|H|'); axis([0,0.5,0,1.1]) 52 | 53 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 54 | 55 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 56 | 57 | subplot(2,2,2); plot(w/pi,db);title('Magnitude in dB') 58 | 59 | xlabel('Analog frequency in pi units'); ylabel('decibels'); axis([0,0.5,-30,5]) 60 | 61 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 62 | 63 | set(gca,'YTickmode','manual','YTick',[-30,-As,-Rp,0]); grid 64 | 65 | set(gca,'YTickLabelMode','manual','YTickLabels',['30';'16';' 7';' 0']) 66 | 67 | subplot(2,2,3); plot(w/pi,pha/pi); title('Phase Response') 68 | 69 | xlabel('Analog frequency in pi units'); ylabel('radians'); axis([0,0.5,-1,1]) 70 | 71 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 72 | 73 | set(gca,'YTickmode','manual','YTick',[-1,-0.5,0,0.5,1]); grid 74 | 75 | subplot(2,2,4); plot(t,ha,[0,max(t)],[0,0]); title('Impulse Response') 76 | 77 | xlabel('time in seconds'); ylabel('ha(t)'); axis([0,max(t),min(ha),max(ha)]) 78 | 79 | -------------------------------------------------------------------------------- /CHAP_08/ex080600.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.6 2 | 3 | % Chebyshev-1 Lowpass Analog filter design 4 | 5 | % 6 | 7 | Wp = 0.2*pi; Ws = 0.3*pi; Rp = 1; As = 16; 8 | 9 | Ripple = 10 ^ (-Rp/20); Attn = 10 ^ (-As/20); 10 | 11 | 12 | 13 | % Analog filter design: 14 | 15 | [b,a] = afd_chb1(Wp,Ws,Rp,As); 16 | 17 | %%*** Chebyshev-1 Filter Order = 4 18 | 19 | 20 | 21 | % Calculation of second-order sections: 22 | 23 | [C,B,A] = sdir2cas(b,a) 24 | 25 | %%C = 0.0383 26 | 27 | %%B = 0 0 1 28 | 29 | %%A = 1.0000 0.4233 0.1103 30 | 31 | %% 1.0000 0.1753 0.3895 32 | 33 | 34 | 35 | % Calculation of Frequency Response: 36 | 37 | [db,mag,pha,w] = freqs_m(b,a,0.5*pi); 38 | 39 | 40 | 41 | % Calculation of Impulse response: 42 | 43 | [ha,x,t] = impulse(b,a); 44 | 45 | 46 | 47 | % Plots 48 | 49 | figure(1); subplot(1,1,1) 50 | 51 | subplot(2,2,1); plot(w/pi,mag);title('Magnitude Response') 52 | 53 | xlabel('Analog frequency in pi units'); ylabel('|H|'); axis([0,0.5,0,1.1]) 54 | 55 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 56 | 57 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 58 | 59 | subplot(2,2,2); plot(w/pi,db);title('Magnitude in dB') 60 | 61 | xlabel('Analog frequency in pi units'); ylabel('decibels'); axis([0,0.5,-30,5]) 62 | 63 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 64 | 65 | set(gca,'YTickmode','manual','YTick',[-30,-As,-Rp,0]); grid 66 | 67 | set(gca,'YTickLabelMode','manual','YTickLabels',['30';'16';' 1';' 0']) 68 | 69 | subplot(2,2,3); plot(w/pi,pha/pi); title('Phase Response') 70 | 71 | xlabel('Analog frequency in pi units'); ylabel('radians'); axis([0,0.5,-1,1]) 72 | 73 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 74 | 75 | set(gca,'YTickmode','manual','YTick',[-1,-0.5,0,0.5,1]); grid 76 | 77 | subplot(2,2,4); plot(t,ha,[0,max(t)],[0,0]); title('Impulse Response') 78 | 79 | xlabel('time in seconds'); ylabel('ha(t)'); axis([0,max(t),min(ha),max(ha)]) -------------------------------------------------------------------------------- /CHAP_08/ex080700.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.7 2 | 3 | % Chebyshev-2 Lowpass Analog filter design 4 | 5 | % 6 | 7 | Wp = 0.2*pi; Ws = 0.3*pi; Rp = 1; As = 16; 8 | 9 | Ripple = 10 ^ (-Rp/20); Attn = 10 ^ (-As/20); 10 | 11 | 12 | 13 | % Analog filter design: 14 | 15 | [b,a] = afd_chb2(Wp,Ws,Rp,As); 16 | 17 | %%*** Chebyshev-2 Filter Order = 4 18 | 19 | 20 | 21 | % Calculation of second-order sections: 22 | 23 | [C,B,A] = sdir2cas(b,a) 24 | 25 | %%C = 0.1585 26 | 27 | %%B = 1.0000 0 6.0654 28 | 29 | %% 1.0000 0 1.0407 30 | 31 | %%A = 1.0000 1.9521 1.4747 32 | 33 | %% 1.0000 0.3719 0.6784 34 | 35 | 36 | 37 | % Calculation of Frequency Response: 38 | 39 | [db,mag,pha,w] = freqs_m(b,a,0.5*pi); 40 | 41 | 42 | 43 | % Calculation of Impulse response: 44 | 45 | [ha,x,t] = impulse(b,a); 46 | 47 | 48 | 49 | % Plots 50 | 51 | figure(1); subplot(1,1,1) 52 | 53 | subplot(2,2,1); plot(w/pi,mag);title('Magnitude Response') 54 | 55 | xlabel('Analog frequency in pi units'); ylabel('|H|'); axis([0,0.5,0,1.1]) 56 | 57 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 58 | 59 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 60 | 61 | subplot(2,2,2); plot(w/pi,db);title('Magnitude in dB') 62 | 63 | xlabel('Analog frequency in pi units'); ylabel('decibels'); axis([0,0.5,-30,5]) 64 | 65 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 66 | 67 | set(gca,'YTickmode','manual','YTick',[-30,-As,-Rp,0]); grid 68 | 69 | set(gca,'YTickLabelMode','manual','YTickLabels',['30';'16';' 1';' 0']) 70 | 71 | subplot(2,2,3); plot(w/pi,pha/pi); title('Phase Response') 72 | 73 | xlabel('Analog frequency in pi units'); ylabel('radians'); axis([0,0.5,-1,1]) 74 | 75 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 76 | 77 | set(gca,'YTickmode','manual','YTick',[-1,-0.5,0,0.5,1]); grid 78 | 79 | subplot(2,2,4); plot(t,ha,[0,max(t)],[0,0]); title('Impulse Response') 80 | 81 | xlabel('time in seconds'); ylabel('ha(t)'); axis([0,max(t),min(ha),max(ha)]) -------------------------------------------------------------------------------- /CHAP_08/ex080800.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.8 2 | 3 | % Elliptic Lowpass Analog filter design 4 | 5 | % 6 | 7 | Wp = 0.2*pi; Ws = 0.3*pi; Rp = 1; As = 16; 8 | 9 | Ripple = 10 ^ (-Rp/20); Attn = 10 ^ (-As/20); 10 | 11 | 12 | 13 | % Analog filter design: 14 | 15 | [b,a] = afd_elip(Wp,Ws,Rp,As); 16 | 17 | %%*** Elliptic Filter Order = 3 18 | 19 | 20 | 21 | % Calculation of second-order sections: 22 | 23 | [C,B,A] = sdir2cas(b,a) 24 | 25 | %%C = 0.2740 26 | 27 | %%B = 1.0000 0 0.6641 28 | 29 | %%A = 1.0000 0.1696 0.4102 30 | 31 | %% 0 1.0000 0.4435 32 | 33 | 34 | 35 | % Calculation of Frequency Response: 36 | 37 | [db,mag,pha,w] = freqs_m(b,a,0.5*pi); 38 | 39 | 40 | 41 | % Calculation of Impulse response: 42 | 43 | [ha,x,t] = impulse(b,a); 44 | 45 | 46 | 47 | % Plots 48 | 49 | figure(1); subplot(1,1,1) 50 | 51 | subplot(2,2,1); plot(w/pi,mag);title('Magnitude Response') 52 | 53 | xlabel('Analog frequency in pi units'); ylabel('|H|'); axis([0,0.5,0,1.1]) 54 | 55 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 56 | 57 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 58 | 59 | subplot(2,2,2); plot(w/pi,db);title('Magnitude in dB') 60 | 61 | xlabel('Analog frequency in pi units'); ylabel('decibels'); axis([0,0.5,-30,1]) 62 | 63 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 64 | 65 | set(gca,'YTickmode','manual','YTick',[-30,-As,-Rp,0]); grid 66 | 67 | set(gca,'YTickLabelMode','manual','YTickLabels',['30';'16';' 1';' 0']) 68 | 69 | subplot(2,2,3); plot(w/pi,pha/pi); title('Phase Response') 70 | 71 | xlabel('Analog frequency in pi units'); ylabel('radians'); axis([0,0.5,-1,1]) 72 | 73 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,0.5]); 74 | 75 | set(gca,'YTickmode','manual','YTick',[-1,-0.5,0,0.5,1]); grid 76 | 77 | subplot(2,2,4); plot(t,ha,[0,max(t)],[0,0]); title('Impulse Response') 78 | 79 | xlabel('time in seconds'); ylabel('ha(t)'); axis([0,max(t),min(ha),max(ha)]) 80 | 81 | -------------------------------------------------------------------------------- /CHAP_08/ex081000.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.10 2 | 3 | % Impulse Invariance Transformation 4 | 5 | % Simple example 6 | 7 | % 8 | 9 | subplot(1,1,1); clg 10 | 11 | c = [1,1]; d = [1,5,6]; T = 0.1; Fs = 1/T; 12 | 13 | [b,a] = imp_invr(c,d,T) 14 | 15 | %%b = 1.0000 -0.8966 16 | 17 | %%a = 1.0000 -1.5595 0.6065 18 | 19 | % Impulse response of the analog filter 20 | 21 | t = [0:0.01:3]; subplot(2,1,1); impulse(c,d,t); 22 | 23 | axis([0,3,-0.1,1]);hold on 24 | 25 | % Impulse response of the digital filter 26 | 27 | n = [0:1:3/T]; hn = filter(b,a,impseq(0,0,3/T)); 28 | 29 | stem(n*T,hn); xlabel('time in sec'); title ('Impulse Responses'); 30 | 31 | hold off 32 | 33 | % Magnitude Response of the digital filter 34 | 35 | [db,magd,pha,grd,wd] = freqz_m(b,a); 36 | 37 | % magnitude response of the analog filter 38 | 39 | [db,mags,pha,ws] = freqs_m(c,d,2*pi*Fs); 40 | 41 | subplot(2,1,2); plot(ws/(2*pi),mags*Fs,wd/(2*pi)*Fs,magd) 42 | 43 | xlabel('frequency in Hz'); title('Magnitude Responses'); 44 | 45 | ylabel('Magnitude'); 46 | 47 | text(1.4,.5,'Analog filter'); text(1.5,1.5,'Digital filter') -------------------------------------------------------------------------------- /CHAP_08/ex081100.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.11 2 | 3 | % Impulse Invariance Transformation 4 | 5 | % Butterworth Lowpass Filter Design 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; % digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; % digital Stopband freq in Hz 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 15; % Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: Inverse mapping for frequencies 22 | 23 | T = 1; % Set T=1 24 | 25 | OmegaP = wp * T; % Prototype Passband freq 26 | 27 | OmegaS = ws * T; % Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Butterworth Prototype Filter Calculation: 38 | 39 | [cs,ds] = afd_butt(OmegaP,OmegaS,Rp,As); 40 | 41 | %%*** Butterworth Filter Order = 6 42 | 43 | 44 | 45 | % Impulse Invariance transformation: 46 | 47 | [b,a] = imp_invr(cs,ds,T); 48 | 49 | [C,B,A] = dir2par(b,a) 50 | 51 | %%C = [] 52 | 53 | %%B = 1.8557 -0.6304 54 | 55 | %% -2.1428 1.1454 56 | 57 | %% 0.2871 -0.4466 58 | 59 | %%A = 1.0000 -0.9973 0.2570 60 | 61 | %% 1.0000 -1.0691 0.3699 62 | 63 | %% 1.0000 -1.2972 0.6949 64 | 65 | 66 | 67 | % Plotting 68 | 69 | figure(1); subplot(1,1,1) 70 | 71 | [db,mag,pha,grd,w] = freqz_m(b,a); 72 | 73 | subplot(2,2,1); plot(w/pi,mag); title('Magnitude Response') 74 | 75 | xlabel('frequency in pi units'); ylabel('|H|'); axis([0,1,0,1.1]) 76 | 77 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 78 | 79 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 80 | 81 | subplot(2,2,3); plot(w/pi,db); title('Magnitude in dB'); 82 | 83 | xlabel('frequency in pi units'); ylabel('decibels'); axis([0,1,-40,5]); 84 | 85 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 86 | 87 | set(gca,'YTickmode','manual','YTick',[-50,-15,-1,0]); grid 88 | 89 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';'15';' 1';' 0']) 90 | 91 | subplot(2,2,2); plot(w/pi,pha/pi); title('Phase Response') 92 | 93 | xlabel('frequency in pi units'); ylabel('pi units'); axis([0,1,-1,1]); 94 | 95 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 96 | 97 | set(gca,'YTickmode','manual','YTick',[-1,0,1]); grid 98 | 99 | subplot(2,2,4); plot(w/pi,grd); title('Group Delay') 100 | 101 | xlabel('frequency in pi units'); ylabel('Samples'); axis([0,1,0,10]) 102 | 103 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 104 | 105 | set(gca,'YTickmode','manual','YTick',[0:2:10]); grid 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /CHAP_08/ex081200.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.12 2 | 3 | % Impulse Invariance Transformation 4 | 5 | % Chebyshev-1 Lowpass Filter Design 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; % digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; % digital Stopband freq in Hz 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 15; % Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: Inverse mapping for frequencies 22 | 23 | T = 1; % Set T=1 24 | 25 | OmegaP = wp * T; % Prototype Passband freq 26 | 27 | OmegaS = ws * T; % Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Chebyshev-1 Prototype Filter Calculation: 38 | 39 | [cs,ds] = afd_chb1(OmegaP,OmegaS,Rp,As); 40 | 41 | %%*** Chebyshev-1 Filter Order = 4 42 | 43 | 44 | 45 | % Impulse Invariance transformation: 46 | 47 | [b,a] = imp_invr(cs,ds,T); 48 | 49 | [C,B,A] = dir2par(b,a) 50 | 51 | %%C = [] 52 | 53 | %%B =-0.0833 -0.0246 54 | 55 | %% 0.0833 0.0239 56 | 57 | %%A = 1.0000 -1.4934 0.8392 58 | 59 | %% 1.0000 -1.5658 0.6549 60 | 61 | 62 | 63 | 64 | 65 | % Plotting 66 | 67 | figure(1); subplot(1,1,1) 68 | 69 | [db,mag,pha,grd,w] = freqz_m(b,a); 70 | 71 | subplot(2,2,1); plot(w/pi,mag); title('Magnitude Response') 72 | 73 | xlabel('frequency in pi units'); ylabel('|H|'); axis([0,1,0,1.1]) 74 | 75 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 76 | 77 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 78 | 79 | subplot(2,2,3); plot(w/pi,db); title('Magnitude in dB'); 80 | 81 | xlabel('frequency in pi units'); ylabel('decibels'); axis([0,1,-40,5]); 82 | 83 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 84 | 85 | set(gca,'YTickmode','manual','YTick',[-50,-15,-1,0]); grid 86 | 87 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';'15';' 1';' 0']) 88 | 89 | subplot(2,2,2); plot(w/pi,pha/pi); title('Phase Response') 90 | 91 | xlabel('frequency in pi units'); ylabel('pi units'); axis([0,1,-1,1]); 92 | 93 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 94 | 95 | set(gca,'YTickmode','manual','YTick',[-1,0,1]); grid 96 | 97 | subplot(2,2,4); plot(w/pi,grd); title('Group Delay') 98 | 99 | xlabel('frequency in pi units'); ylabel('Samples'); axis([0,1,0,15]) 100 | 101 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 102 | 103 | set(gca,'YTickmode','manual','YTick',[0:5:15]); grid 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /CHAP_08/ex081300.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.13 2 | 3 | % Impulse Invariance Transformation 4 | 5 | % Chebyshev-2 Lowpass Filter Design 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; % digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; % digital Stopband freq in Hz 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 15; % Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: Inverse mapping for frequencies 22 | 23 | T = 1; % Set T=1 24 | 25 | OmegaP = wp * T; % Prototype Passband freq 26 | 27 | OmegaS = ws * T; % Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Chebyshev-1 Prototype Filter Calculation: 38 | 39 | [cs,ds] = afd_chb2(OmegaP,OmegaS,Rp,As); 40 | 41 | %%*** Chebyshev-2 Filter Order = 4 42 | 43 | 44 | 45 | % Impulse Invariance transformation: 46 | 47 | [b,a] = imp_invr(cs,ds,T); 48 | 49 | [C,B,A] = dir2par(b,a) 50 | 51 | %%C = 0.1778 52 | 53 | %%B =-0.0313 0.5760 54 | 55 | %% -0.3901 0.1552 56 | 57 | %%A = 1.0000 -0.5273 0.1348 58 | 59 | %% 1.0000 -1.1386 0.6938 60 | 61 | 62 | 63 | % Plotting 64 | 65 | figure(1); subplot(1,1,1) 66 | 67 | [db,mag,pha,grd,w] = freqz_m(b,a); 68 | 69 | subplot(2,2,1); plot(w/pi,mag); title('Magnitude Response') 70 | 71 | xlabel('frequency in pi units'); ylabel('|H|'); axis([0,1,0,1.1]) 72 | 73 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 74 | 75 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 76 | 77 | subplot(2,2,3); plot(w/pi,db); title('Magnitude in dB'); 78 | 79 | xlabel('frequency in pi units'); ylabel('decibels'); axis([0,1,-40,5]); 80 | 81 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 82 | 83 | set(gca,'YTickmode','manual','YTick',[-50,-15,-1,0]); grid 84 | 85 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';'15';' 1';' 0']) 86 | 87 | subplot(2,2,2); plot(w/pi,pha/pi); title('Phase Response') 88 | 89 | xlabel('frequency in pi units'); ylabel('pi units'); axis([0,1,-1,1]); 90 | 91 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 92 | 93 | set(gca,'YTickmode','manual','YTick',[-1,0,1]); grid 94 | 95 | subplot(2,2,4); plot(w/pi,grd); title('Group Delay') 96 | 97 | xlabel('frequency in pi units'); ylabel('Samples'); axis([0,1,0,15]) 98 | 99 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 100 | 101 | set(gca,'YTickmode','manual','YTick',[0:5:15]); grid 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /CHAP_08/ex081400.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.14 2 | 3 | % Impulse Invariance Transformation 4 | 5 | % Elliptic Lowpass Filter Design 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; % digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; % digital Stopband freq in Hz 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 15; % Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: Inverse mapping for frequencies 22 | 23 | T = 1; % Set T=1 24 | 25 | OmegaP = wp * T; % Prototype Passband freq 26 | 27 | OmegaS = ws * T; % Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Elliptic Prototype Filter Calculation: 38 | 39 | [cs,ds] = afd_elip(OmegaP,OmegaS,Rp,As); 40 | 41 | %%*** Elliptic Filter Order = 3 42 | 43 | 44 | 45 | % Impulse Invariance transformation: 46 | 47 | [b,a] = imp_invr(cs,ds,T); 48 | 49 | [C,B,A] = dir2par(b,a) 50 | 51 | %%C = [] 52 | 53 | %%B =-0.1600 0.1299 54 | 55 | %% 0.4560 0 56 | 57 | %%A = 1.0000 -1.4854 0.8521 58 | 59 | %% 1.0000 -0.6338 0 60 | 61 | 62 | 63 | % Plotting 64 | 65 | figure(1); subplot(1,1,1) 66 | 67 | [db,mag,pha,grd,w] = freqz_m(b,a); 68 | 69 | subplot(2,2,1); plot(w/pi,mag); title('Magnitude Response') 70 | 71 | xlabel('frequency in pi units'); ylabel('|H|'); axis([0,1,0,1.1]) 72 | 73 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 74 | 75 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 76 | 77 | subplot(2,2,3); plot(w/pi,db); title('Magnitude in dB'); 78 | 79 | xlabel('frequency in pi units'); ylabel('decibels'); axis([0,1,-40,5]); 80 | 81 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 82 | 83 | set(gca,'YTickmode','manual','YTick',[-50,-15,-1,0]); grid 84 | 85 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';'15';' 1';' 0']) 86 | 87 | subplot(2,2,2); plot(w/pi,pha/pi); title('Phase Response') 88 | 89 | xlabel('frequency in pi units'); ylabel('pi units'); axis([0,1,-1,1]); 90 | 91 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 92 | 93 | set(gca,'YTickmode','manual','YTick',[-1,0,1]); grid 94 | 95 | subplot(2,2,4); plot(w/pi,grd); title('Group Delay') 96 | 97 | xlabel('frequency in pi units'); ylabel('Samples'); axis([0,1,0,15]) 98 | 99 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 100 | 101 | set(gca,'YTickmode','manual','YTick',[0:5:15]); grid 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /CHAP_08/ex081600.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.16 2 | 3 | % Bilinear Transformation 4 | 5 | % Simple example 6 | 7 | % 8 | 9 | c = [1,1]; d = [1,5,6]; T = 1; 10 | 11 | [b,a] = bilinear(c,d,T) 12 | 13 | %%b = 0.1500 0.1000 -0.0500 14 | 15 | %%a = 1.0000 0.2000 0.0000 -------------------------------------------------------------------------------- /CHAP_08/ex081700.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.17 2 | 3 | % BiLinear Transformation: 4 | 5 | % Butterworth Lowpass Filter Design 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; % digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; % digital Stopband freq in Hz 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 15; % Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: Inverse mapping for frequencies 22 | 23 | T = 1; Fs = 1/T; % Set T=1 24 | 25 | OmegaP = (2/T)*tan(wp/2); % Prewarp Prototype Passband freq 26 | 27 | OmegaS = (2/T)*tan(ws/2); % Prewarp Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Butterworth Prototype Filter Calculation: 38 | 39 | [cs,ds] = afd_butt(OmegaP,OmegaS,Rp,As); 40 | 41 | %%*** Butterworth Filter Order = 6 42 | 43 | 44 | 45 | % Bilinear transformation: 46 | 47 | [b,a] = bilinear(cs,ds,T); 48 | 49 | [C,B,A] = dir2cas(b,a) 50 | 51 | %%C = 5.7969e-004 52 | 53 | %%B = 1.0000 2.0183 1.0186 54 | 55 | %% 1.0000 1.9814 0.9817 56 | 57 | %% 1.0000 2.0004 1.0000 58 | 59 | %%A = 1.0000 -0.9459 0.2342 60 | 61 | %% 1.0000 -1.0541 0.3753 62 | 63 | %% 1.0000 -1.3143 0.7149 64 | 65 | 66 | 67 | % Plotting 68 | 69 | figure(1); subplot(1,1,1) 70 | 71 | [db,mag,pha,grd,w] = freqz_m(b,a); 72 | 73 | subplot(2,2,1); plot(w/pi,mag); title('Magnitude Response') 74 | 75 | xlabel('frequency in pi units'); ylabel('|H|'); axis([0,1,0,1.1]) 76 | 77 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 78 | 79 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 80 | 81 | subplot(2,2,3); plot(w/pi,db); title('Magnitude in dB'); 82 | 83 | xlabel('frequency in pi units'); ylabel('decibels'); axis([0,1,-40,5]); 84 | 85 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 86 | 87 | set(gca,'YTickmode','manual','YTick',[-50,-15,-1,0]); grid 88 | 89 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';'15';' 1';' 0']) 90 | 91 | subplot(2,2,2); plot(w/pi,pha/pi); title('Phase Response') 92 | 93 | xlabel('frequency in pi units'); ylabel('pi units'); axis([0,1,-1,1]); 94 | 95 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 96 | 97 | set(gca,'YTickmode','manual','YTick',[-1,0,1]); grid 98 | 99 | subplot(2,2,4); plot(w/pi,grd); title('Group Delay') 100 | 101 | xlabel('frequency in pi units'); ylabel('Samples'); axis([0,1,0,10]) 102 | 103 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 104 | 105 | set(gca,'YTickmode','manual','YTick',[0:2:10]); grid 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /CHAP_08/ex081800.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.18 2 | 3 | % BiLinear Transformation: 4 | 5 | % Chebyshev-1 Lowpass Filter Design 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; % digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; % digital Stopband freq in Hz 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 15; % Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: Inverse mapping for frequencies 22 | 23 | T = 1; Fs = 1/T; % Set T=1 24 | 25 | OmegaP = (2/T)*tan(wp/2); % Prewarp Prototype Passband freq 26 | 27 | OmegaS = (2/T)*tan(ws/2); % Prewarp Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Chebyshev Prototype Filter Calculation: 38 | 39 | [cs,ds] = afd_chb1(OmegaP,OmegaS,Rp,As); 40 | 41 | %%*** Chebyshev-1 Filter Order = 4 42 | 43 | 44 | 45 | % Bilinear transformation: 46 | 47 | [b,a] = bilinear(cs,ds,T); 48 | 49 | [C,B,A] = dir2cas(b,a) 50 | 51 | %%C = 0.0018 52 | 53 | %%B = 1.0000 2.0000 1.0000 54 | 55 | %% 1.0000 2.0000 1.0000 56 | 57 | %%A = 1.0000 -1.4996 0.8482 58 | 59 | %% 1.0000 -1.5548 0.6493 60 | 61 | 62 | 63 | % Plotting 64 | 65 | figure(1); subplot(1,1,1) 66 | 67 | [db,mag,pha,grd,w] = freqz_m(b,a); 68 | 69 | subplot(2,2,1); plot(w/pi,mag); title('Magnitude Response') 70 | 71 | xlabel('frequency in pi units'); ylabel('|H|'); axis([0,1,0,1.1]) 72 | 73 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 74 | 75 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 76 | 77 | subplot(2,2,3); plot(w/pi,db); title('Magnitude in dB'); 78 | 79 | xlabel('frequency in pi units'); ylabel('decibels'); axis([0,1,-40,5]); 80 | 81 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 82 | 83 | set(gca,'YTickmode','manual','YTick',[-50,-15,-1,0]); grid 84 | 85 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';'15';' 1';' 0']) 86 | 87 | subplot(2,2,2); plot(w/pi,pha/pi); title('Phase Response') 88 | 89 | xlabel('frequency in pi units'); ylabel('pi units'); axis([0,1,-1,1]); 90 | 91 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 92 | 93 | set(gca,'YTickmode','manual','YTick',[-1,0,1]); grid 94 | 95 | subplot(2,2,4); plot(w/pi,grd); title('Group Delay') 96 | 97 | xlabel('frequency in pi units'); ylabel('Samples'); axis([0,1,0,15]) 98 | 99 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 100 | 101 | set(gca,'YTickmode','manual','YTick',[0:5:15]); grid 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /CHAP_08/ex081900.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.19 2 | 3 | % BiLinear Transformation: 4 | 5 | % Chebyshev-2 Lowpass Filter Design 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; % digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; % digital Stopband freq in Hz 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 15; % Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: Inverse mapping for frequencies 22 | 23 | T = 1; Fs = 1/T; % Set T=1 24 | 25 | OmegaP = (2/T)*tan(wp/2); % Prewarp Prototype Passband freq 26 | 27 | OmegaS = (2/T)*tan(ws/2); % Prewarp Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Chebyshev-2 Prototype Filter Calculation: 38 | 39 | [cs,ds] = afd_chb2(OmegaP,OmegaS,Rp,As); 40 | 41 | %%*** Chebyshev-2 Filter Order = 4 42 | 43 | 44 | 45 | % Bilinear transformation: 46 | 47 | [b,a] = bilinear(cs,ds,T); 48 | 49 | [C,B,A] = dir2cas(b,a) 50 | 51 | %%C = 0.1797 52 | 53 | %%B = 1.0000 0.5574 1.0000 54 | 55 | %% 1.0000 -1.0671 1.0000 56 | 57 | %%A = 1.0000 -0.4183 0.1503 58 | 59 | %% 1.0000 -1.1325 0.7183 60 | 61 | 62 | 63 | % Plotting 64 | 65 | figure(1); subplot(1,1,1) 66 | 67 | [db,mag,pha,grd,w] = freqz_m(b,a); 68 | 69 | subplot(2,2,1); plot(w/pi,mag); title('Magnitude Response') 70 | 71 | xlabel('frequency in pi units'); ylabel('|H|'); axis([0,1,0,1.1]) 72 | 73 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 74 | 75 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 76 | 77 | subplot(2,2,3); plot(w/pi,db); title('Magnitude in dB'); 78 | 79 | xlabel('frequency in pi units'); ylabel('decibels'); axis([0,1,-40,5]); 80 | 81 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 82 | 83 | set(gca,'YTickmode','manual','YTick',[-50,-15,-1,0]); grid 84 | 85 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';'15';' 1';' 0']) 86 | 87 | subplot(2,2,2); plot(w/pi,pha/pi); title('Phase Response') 88 | 89 | xlabel('frequency in pi units'); ylabel('pi units'); axis([0,1,-1,1]); 90 | 91 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 92 | 93 | set(gca,'YTickmode','manual','YTick',[-1,0,1]); grid 94 | 95 | subplot(2,2,4); plot(w/pi,grd); title('Group Delay') 96 | 97 | xlabel('frequency in pi units'); ylabel('Samples'); axis([0,1,0,15]) 98 | 99 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 100 | 101 | set(gca,'YTickmode','manual','YTick',[0:5:15]); grid 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /CHAP_08/ex082000.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.20 2 | 3 | % BiLinear Transformation: 4 | 5 | % Elliptic Lowpass Filter Design 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; % digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; % digital Stopband freq in Hz 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 15; % Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: Inverse mapping for frequencies 22 | 23 | T = 1; Fs = 1/T; % Set T=1 24 | 25 | OmegaP = (2/T)*tan(wp/2); % Prewarp Prototype Passband freq 26 | 27 | OmegaS = (2/T)*tan(ws/2); % Prewarp Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Elliptic Prototype Filter Calculation: 38 | 39 | [cs,ds] = afd_elip(OmegaP,OmegaS,Rp,As); 40 | 41 | %%*** Elliptic Filter Order = 3 42 | 43 | 44 | 45 | % Bilinear transformation: 46 | 47 | [b,a] = bilinear(cs,ds,T); 48 | 49 | [C,B,A] = dir2cas(b,a) 50 | 51 | %%C = 0.1214 52 | 53 | %%B = 1.0000 -1.4211 1.0000 54 | 55 | %% 1.0000 1.0000 0 56 | 57 | %%A = 1.0000 -1.4928 0.8612 58 | 59 | %% 1.0000 -0.6183 0 60 | 61 | 62 | 63 | % Plotting 64 | 65 | figure(1); subplot(1,1,1) 66 | 67 | [db,mag,pha,grd,w] = freqz_m(b,a); 68 | 69 | subplot(2,2,1); plot(w/pi,mag); title('Magnitude Response') 70 | 71 | xlabel('frequency in pi units'); ylabel('|H|'); axis([0,1,0,1.1]) 72 | 73 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 74 | 75 | set(gca,'YTickmode','manual','YTick',[0,Attn,Ripple,1]); grid 76 | 77 | subplot(2,2,3); plot(w/pi,db); title('Magnitude in dB'); 78 | 79 | xlabel('frequency in pi units'); ylabel('decibels'); axis([0,1,-40,5]); 80 | 81 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 82 | 83 | set(gca,'YTickmode','manual','YTick',[-50,-15,-1,0]); grid 84 | 85 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';'15';' 1';' 0']) 86 | 87 | subplot(2,2,2); plot(w/pi,pha/pi); title('Phase Response') 88 | 89 | xlabel('frequency in pi units'); ylabel('pi units'); axis([0,1,-1,1]); 90 | 91 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 92 | 93 | set(gca,'YTickmode','manual','YTick',[-1,0,1]); grid 94 | 95 | subplot(2,2,4); plot(w/pi,grd); title('Group Delay') 96 | 97 | xlabel('frequency in pi units'); ylabel('Samples'); axis([0,1,0,15]) 98 | 99 | set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]); 100 | 101 | set(gca,'YTickmode','manual','YTick',[0:5:15]); grid 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /CHAP_08/ex082100.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.21 2 | 3 | % Butterworth Lowpass Filter Design: 4 | 5 | % Use of the BUTTER function 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; %digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; %digital Stopband freq in Hz 14 | 15 | Rp = 1; %Passband ripple in dB 16 | 17 | As = 15; %Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: 22 | 23 | T = 1; %Set T=1 24 | 25 | OmegaP = (2/T)*tan(wp/2); %Prewarp Prototype Passband freq 26 | 27 | OmegaS = (2/T)*tan(ws/2); %Prewarp Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Prototype Order Calculation: 38 | 39 | N =ceil((log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(OmegaP/OmegaS))); 40 | 41 | fprintf('\n*** Butterworth Filter Order = %2.0f \n',N) 42 | 43 | %%*** Butterworth Filter Order = 6 44 | 45 | OmegaC = OmegaP/((10^(Rp/10)-1)^(1/(2*N))); %Analog BW prototype cutoff 46 | 47 | wn = 2*atan((OmegaC*T)/2); %Digital BW cutoff freq 48 | 49 | 50 | 51 | % Digital Butterworth Filter Design: 52 | 53 | wn = wn/pi; %Digital Butter cutoff in pi units 54 | 55 | [b,a]=butter(N,wn); 56 | 57 | [b0,B,A] = dir2cas(b,a) 58 | 59 | %%C = 5.7969e-004 60 | 61 | %%B = 1.0000 2.0297 1.0300 62 | 63 | %% 1.0000 1.9997 1.0000 64 | 65 | %% 1.0000 1.9706 0.9709 66 | 67 | %%A = 1.0000 -0.9459 0.2342 68 | 69 | %% 1.0000 -1.0541 0.3753 70 | 71 | %% 1.0000 -1.3143 0.7149 72 | 73 | -------------------------------------------------------------------------------- /CHAP_08/ex082200.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.22 2 | 3 | % Butterworth Lowpass Filter Design: 4 | 5 | % Use of the CHEBY1 function 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; %digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; %digital Stopband freq in Hz 14 | 15 | Rp = 1; %Passband ripple in dB 16 | 17 | As = 15; %Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: 22 | 23 | T = 1; %Set T=1 24 | 25 | OmegaP = (2/T)*tan(wp/2); %Prewarp Prototype Passband freq 26 | 27 | OmegaS = (2/T)*tan(ws/2); %Prewarp Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Prototype Order Calculation: 38 | 39 | ep = sqrt(10^(Rp/10)-1); %Passband Ripple Factor 40 | 41 | A = 10^(As/20); %Stopband Attenuation Factor 42 | 43 | OmegaC = OmegaP; %Analog Prototype Cutoff freq 44 | 45 | OmegaR = OmegaS/OmegaP; %Analog Prototype Transition Ratio 46 | 47 | g = sqrt(A*A-1)/ep; %Analog Prototype Intermediate cal. 48 | 49 | N = ceil(log10(g+sqrt(g*g-1))/log10(OmegaR+sqrt(OmegaR*OmegaR-1))); 50 | 51 | fprintf('\n*** Chebyshev-1 Filter Order = %2.0f \n',N) 52 | 53 | %%*** Chebyshev-1 Filter Order = 4 54 | 55 | 56 | 57 | % Digital Chebyshev-I Filter Design: 58 | 59 | wn = wp/pi; %Digital Passband freq in pi units 60 | 61 | [b,a]=cheby1(N,Rp,wn); 62 | 63 | [b0,B,A] = dir2cas(b,a) 64 | 65 | %%b0 = 0.0018 66 | 67 | %%B = 1.0000 2.0000 1.0000 68 | 69 | %% 1.0000 2.0000 1.0000 70 | 71 | %%A = 1.0000 -1.4996 0.8482 72 | 73 | %% 1.0000 -1.5548 0.6493 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /CHAP_08/ex082300.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.23 2 | 3 | % Butterworth Lowpass Filter Design: 4 | 5 | % Use of the CHEBY2 function 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; %digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; %digital Stopband freq in Hz 14 | 15 | Rp = 1; %Passband ripple in dB 16 | 17 | As = 15; %Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: 22 | 23 | T = 1; %Set T=1 24 | 25 | OmegaP = (2/T)*tan(wp/2); %Prewarp Prototype Passband freq 26 | 27 | OmegaS = (2/T)*tan(ws/2); %Prewarp Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Prototype Order Calculation: 38 | 39 | ep = sqrt(10^(Rp/10)-1); %Passband Ripple Factor 40 | 41 | A = 10^(As/20); %Stopband Attenuation Factor 42 | 43 | OmegaC = OmegaP; %Analog Prototype Cutoff freq 44 | 45 | OmegaR = OmegaS/OmegaP; %Analog Prototype Transition Ratio 46 | 47 | g = sqrt(A*A-1)/ep; %Analog Prototype Intermediate cal. 48 | 49 | N = ceil(log10(g+sqrt(g*g-1))/log10(OmegaR+sqrt(OmegaR*OmegaR-1))); 50 | 51 | fprintf('\n*** Chebyshev-2 Filter Order = %2.0f \n',N) 52 | 53 | %%*** Chebyshev-2 Filter Order = 4 54 | 55 | 56 | 57 | % Digital Chebyshev-II Filter Design: 58 | 59 | wn = ws/pi; %Digital Stopband freq in pi units 60 | 61 | [b,a]=cheby2(N,As,wn); 62 | 63 | [b0,B,A] = dir2cas(b,a) 64 | 65 | %%b0 = 0.1797 66 | 67 | %%B = 1.0000 0.5574 1.0000 68 | 69 | %% 1.0000 -1.0671 1.0000 70 | 71 | %%A = 1.0000 -0.4183 0.1503 72 | 73 | %% 1.0000 -1.1325 0.7183 -------------------------------------------------------------------------------- /CHAP_08/ex082400.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.24 2 | 3 | % Elliptic Lowpass Filter Design: 4 | 5 | % Use of the ELLIP function 6 | 7 | % 8 | 9 | % Digital Filter Specifications: 10 | 11 | wp = 0.2*pi; %digital Passband freq in Hz 12 | 13 | ws = 0.3*pi; %digital Stopband freq in Hz 14 | 15 | Rp = 1; %Passband ripple in dB 16 | 17 | As = 15; %Stopband attenuation in dB 18 | 19 | 20 | 21 | % Analog Prototype Specifications: 22 | 23 | T = 1; %Set T=1 24 | 25 | OmegaP = (2/T)*tan(wp/2); %Prewarp Prototype Passband freq 26 | 27 | OmegaS = (2/T)*tan(ws/2); %Prewarp Prototype Stopband freq 28 | 29 | ep = sqrt(10^(Rp/10)-1); % Passband Ripple parameter 30 | 31 | Ripple = sqrt(1/(1+ep*ep)); % Passband Ripple 32 | 33 | Attn = 1/(10^(As/20)); % Stopband Attenuation 34 | 35 | 36 | 37 | % Analog Elliptic Filter order calculations: 38 | 39 | ep = sqrt(10^(Rp/10)-1); %Passband Ripple Factor 40 | 41 | A = 10^(As/20); %Stopband Attenuation Factor 42 | 43 | OmegaC = OmegaP; %Analog Prototype Cutoff freq 44 | 45 | k = OmegaP/OmegaS; %Analog Prototype Transition Ratio; 46 | 47 | k1 = ep/sqrt(A*A-1); %Analog Prototype Intermediate cal. 48 | 49 | capk = ellipke([k.^2 1-k.^2]); 50 | 51 | capk1 = ellipke([(k1 .^2) 1-(k1 .^2)]); 52 | 53 | N = ceil(capk(1)*capk1(2)/(capk(2)*capk1(1))); 54 | 55 | fprintf('\n*** Elliptic Filter Order = %2.0f \n',N) 56 | 57 | %%*** Elliptic Filter Order = 3 58 | 59 | 60 | 61 | % Digital Elliptic Filter Design: 62 | 63 | wn = wp/pi; %Digital Passband freq in pi units 64 | 65 | [b,a]=ellip(N,Rp,As,wn); 66 | 67 | [b0,B,A] = dir2cas(b,a) 68 | 69 | %%b0 = 0.1214 70 | 71 | %%B = 1.0000 -1.4211 1.0000 72 | 73 | %% 1.0000 1.0000 0 74 | 75 | %%A = 1.0000 -1.4928 0.8612 76 | 77 | %% 1.0000 -0.6183 0 -------------------------------------------------------------------------------- /CHAP_08/ex082700.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.27 2 | 3 | % Chebyshev-1 Highpass Filter Design: 4 | 5 | % Use of the CHEBY1HPF function 6 | 7 | % 8 | 9 | % Digital Highpass Filter Specifications: 10 | 11 | wp = 0.6*pi; % digital Passband freq in Hz 12 | 13 | ws = 0.4586*pi; % digital Stopband freq in Hz 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 15; % Stopband attenuation in dB 18 | 19 | 20 | 21 | [b,a] = cheb1hpf(wp,ws,Rp,As); 22 | 23 | [C,B,A] = dir2cas(b,a) 24 | 25 | %%C = 0.0243 26 | 27 | %%B = 1.0000 -2.0000 1.0000 28 | 29 | %% 1.0000 -2.0000 1.0000 30 | 31 | %%A = 1.0000 1.0416 0.4019 32 | 33 | %% 1.0000 0.5561 0.7647 34 | 35 | -------------------------------------------------------------------------------- /CHAP_08/ex082800.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.28 2 | 3 | % Chebyshev-1 Highpass Filter Design: 4 | 5 | % Use of the CHEBY1 function 6 | 7 | % 8 | 9 | % Digital Filter Specifications: % Type: Chebyshev-I highpass 10 | 11 | ws = 0.4586*pi; % Dig. stopband edge frequency 12 | 13 | wp = 0.6*pi; % Dig. passband edge frequency 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 15; % Stopband attenuation in dB 18 | 19 | Ripple = 10 ^ (-Rp/20); % Passband ripple 20 | 21 | Attn = 10 ^ (-As/20); % Passband attenuation 22 | 23 | 24 | 25 | % Calculations of Chebyshev-I Filter Parameters: 26 | 27 | [N,wn] = cheb1ord(wp/pi,ws/pi,Rp,As); 28 | 29 | 30 | 31 | % Digital Chebyshev-I Highpass Filter Design: 32 | 33 | [b,a] = cheby1(N,Rp,wn,'high'); 34 | 35 | 36 | 37 | % Cascade Form Realization: 38 | 39 | [b0,B,A] = dir2cas(b,a) 40 | 41 | %%b0 = 0.0243 42 | 43 | %%B = 1.0000 -1.9991 0.9991 44 | 45 | %% 1.0000 -2.0009 1.0009 46 | 47 | %%A = 1.0000 1.0416 0.4019 48 | 49 | %% 1.0000 0.5561 0.7647 50 | 51 | 52 | 53 | % Plotting: 54 | 55 | figure(1); subplot(1,1,1) 56 | 57 | [db,mag,pha,grd,w] = freqz_m(b,a); 58 | 59 | subplot(2,2,1);plot(w/pi,mag);grid;title('Magnitude Response') 60 | 61 | xlabel('Digital frequency in pi units'); axis([0,1,0,1]) 62 | 63 | set(gca,'XTickMode','manual','XTick',[0;ws/pi;wp/pi;1]) 64 | 65 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0 ';'0.46';'0.6 ';' 1 ']) 66 | 67 | set(gca,'YTickMode','manual','YTick',[0;Attn;Ripple;1]) 68 | 69 | subplot(2,2,3);plot(w/pi,db);grid;title('Magnitude in dB') 70 | 71 | xlabel('frequency in pi units'); axis([0,1,-30, 0]); 72 | 73 | ylabel('decibels') 74 | 75 | set(gca,'XTickMode','manual','XTick',[0;ws/pi;wp/pi;1]) 76 | 77 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0 ';'0.46';'0.6 ';' 1 ']) 78 | 79 | set(gca,'YTickMode','manual','YTick',[-30;-As;-Rp;0]) 80 | 81 | set(gca,'YTickLabelMode','manual','YTickLabels',['30';'15';' 1';' 0']) 82 | 83 | subplot(2,2,2);plot(w/pi,pha/pi);grid;title('Phase Response') 84 | 85 | xlabel('frequency in pi units');ylabel('phase in pi units'); axis([0,1,-1,1]) 86 | 87 | set(gca,'XTickMode','manual','XTick',[0;ws/pi;wp/pi;1]) 88 | 89 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0 ';'0.46';'0.6 ';' 1 ']) 90 | 91 | subplot(2,2,4);plot(w/pi,grd);grid;title('Group Delay') 92 | 93 | xlabel('frequency in pi units'); 94 | 95 | ylabel('delay in samples') 96 | 97 | set(gca,'XTickMode','manual','XTick',[0;ws/pi;wp/pi;1]) 98 | 99 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0 ';'0.46';'0.6 ';' 1 ']) 100 | 101 | -------------------------------------------------------------------------------- /CHAP_08/ex082900.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.29 2 | 3 | % Elliptic Bandpass Filter Design: 4 | 5 | % Use of the ELLIP function 6 | 7 | % 8 | 9 | % Digital Filter Specifications: % Type: Elliptic Bandpass 10 | 11 | ws = [0.3*pi 0.75*pi]; % Dig. stopband edge frequency 12 | 13 | wp = [0.4*pi 0.6*pi]; % Dig. passband edge frequency 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 40; % Stopband attenuation in dB 18 | 19 | Ripple = 10 ^ (-Rp/20); % Passband ripple 20 | 21 | Attn = 10 ^ (-As/20); % Passband attenuation 22 | 23 | 24 | 25 | % Calculations of Elliptic Filter Parameters: 26 | 27 | [N,wn] = ellipord(wp/pi,ws/pi,Rp,As); 28 | 29 | 30 | 31 | % Digital Elliptic Bandpass Filter Design: 32 | 33 | [b,a] = ellip(N,Rp,As,wn); 34 | 35 | 36 | 37 | % Cascade Form Realization: 38 | 39 | [b0,B,A] = dir2cas(b,a) 40 | 41 | %%b0 = 0.0197 42 | 43 | %%B = 1.0000 1.5066 1.0000 44 | 45 | %% 1.0000 0.9268 1.0000 46 | 47 | %% 1.0000 -0.9268 1.0000 48 | 49 | %% 1.0000 -1.5066 1.0000 50 | 51 | %%A = 1.0000 0.5963 0.9399 52 | 53 | %% 1.0000 0.2774 0.7929 54 | 55 | %% 1.0000 -0.2774 0.7929 56 | 57 | %% 1.0000 -0.5963 0.9399 58 | 59 | 60 | 61 | % Plotting: 62 | 63 | figure(1); subplot(1,1,1) 64 | 65 | [db,mag,pha,grd,w] = freqz_m(b,a); 66 | 67 | subplot(2,2,1);plot(w/pi,mag);grid;title('Magnitude Response') 68 | 69 | xlabel('frequency in pi units'); axis([0, 1, 0, 1]) 70 | 71 | set(gca,'XTickMode','manual','XTick',[0;0.3;0.4;0.6;0.75;1]) 72 | 73 | set(gca,'YTickMode','manual','YTick',[0,Ripple,1]); 74 | 75 | subplot(2,2,3);plot(w/pi,db);grid;title('Magnitude in dB') 76 | 77 | xlabel('frequency in pi units'); axis([0 1 -50 0]); 78 | 79 | set(gca,'XTickMode','manual','XTick',[0;0.3;0.4;0.6;0.75;1]) 80 | 81 | set(gca,'YTickMode','manual','YTick',[-40;0]) 82 | 83 | set(gca,'YTickLabelMode','manual','YTickLabels',['40';' 0']) 84 | 85 | subplot(2,2,2);plot(w/pi,pha/pi);grid;title('Phase Response') 86 | 87 | xlabel('frequency in pi units');ylabel('phase in pi units') 88 | 89 | set(gca,'XTickMode','manual','XTick',[0;0.3;0.4;0.6;0.75;1]) 90 | 91 | subplot(2,2,4);plot(w/pi,grd);grid;title('Group Delay') 92 | 93 | xlabel('frequency in pi units'); ylabel('samples') 94 | 95 | set(gca,'XTickMode','manual','XTick',[0;0.3;0.4;0.6;0.75;1]) 96 | 97 | -------------------------------------------------------------------------------- /CHAP_08/ex083000.m: -------------------------------------------------------------------------------- 1 | % Chapter 8: Example 8.30 2 | 3 | % Chebyshev-2 Bandstop Filter Design: 4 | 5 | % Use of the CHEBY2 function 6 | 7 | % 8 | 9 | % Digital Filter Specifications: % Type: Chebyshev-II Bandstop 10 | 11 | ws = [0.4*pi 0.7*pi]; % Dig. stopband edge frequency 12 | 13 | wp = [0.25*pi 0.8*pi]; % Dig. passband edge frequency 14 | 15 | Rp = 1; % Passband ripple in dB 16 | 17 | As = 40; % Stopband attenuation in dB 18 | 19 | Ripple = 10 ^ (-Rp/20); % Passband ripple 20 | 21 | Attn = 10 ^ (-As/20); % Passband attenuation 22 | 23 | 24 | 25 | % Calculations of Chebyshev-II Filter Parameters: 26 | 27 | [N,wn] = cheb2ord(wp/pi,ws/pi,Rp,As); 28 | 29 | 30 | 31 | % Digital Chebyshev-II Bandstop Filter Design: 32 | 33 | [b,a] = cheby2(N,As,ws/pi,'stop'); 34 | 35 | 36 | 37 | % Cascade Form Realization: 38 | 39 | [b0,B,A] = dir2cas(b,a) 40 | 41 | %%b0 = 0.1558 42 | 43 | %%B = 1.0000 1.1456 1.0000 44 | 45 | %% 1.0000 0.8879 1.0000 46 | 47 | %% 1.0000 0.3511 1.0000 48 | 49 | %% 1.0000 -0.2434 1.0000 50 | 51 | %% 1.0000 -0.5768 1.0000 52 | 53 | %%A = 1.0000 1.3041 0.8031 54 | 55 | %% 1.0000 0.8901 0.4614 56 | 57 | %% 1.0000 0.2132 0.2145 58 | 59 | %% 1.0000 -0.4713 0.3916 60 | 61 | %% 1.0000 -0.8936 0.7602 62 | 63 | 64 | 65 | % Plotting: 66 | 67 | [db,mag,pha,grd,w] = freqz_m(b,a); 68 | 69 | subplot(2,2,1);plot(w/pi,mag);grid;title('Magnitude Response') 70 | 71 | xlabel('Digital frequency in pi units'); axis([0 1 0 1]) 72 | 73 | set(gca,'XTickMode','manual','XTick',[0;0.25;0.4;0.7;0.8;1]) 74 | 75 | set(gca,'YTickMode','manual','YTick',[0;Ripple;1]) 76 | 77 | subplot(2,2,3);plot(w/pi,db);grid;title('Magnitude in dB') 78 | 79 | xlabel('Digital frequency in pi units'); axis([0 1 -50 0]); 80 | 81 | set(gca,'XTickMode','manual','XTick',[0;0.25;0.4;0.7;0.8;1]) 82 | 83 | set(gca,'YTickMode','manual','YTick',[-40;0]) 84 | 85 | subplot(2,2,2);plot(w/pi,pha/pi);grid;title('Phase Response') 86 | 87 | xlabel('Digital frequency in pi units');ylabel('phase in pi units') 88 | 89 | set(gca,'XTickMode','manual','XTick',[0;0.25;0.4;0.7;0.8;1]) 90 | 91 | subplot(2,2,4);plot(w/pi,grd);grid;title('Group Delay') 92 | 93 | xlabel('Digital frequency in pi units'); 94 | 95 | set(gca,'XTickMode','manual','XTick',[0;0.25;0.4;0.7;0.8;1]) 96 | 97 | subplot; -------------------------------------------------------------------------------- /FIGURES/ampresbl.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Blackman Window Amplitude Response 2 | 3 | % 4 | 5 | M = 45; alpha = (M-1)/2; 6 | 7 | n = -alpha:alpha; 8 | 9 | w = (blackman(M))'; sumw = sum(w); 10 | 11 | N = 1000; omega = (2*pi/N)*[-N/2:N/2]; 12 | 13 | Wr = real(w*(exp(-j*n'*omega))); 14 | 15 | db = 20*log10(abs(Wr)/max(Wr)); 16 | 17 | IntWr = cumsum(Wr); 18 | 19 | Intdb = 20*log10(abs(IntWr)/N); 20 | 21 | k = (N/2+1) - min(find(Intdb > -74)); 22 | 23 | tr_width = 2*k*2*M/N, %actual transition width in pi/M units 24 | 25 | omega1 = -(tr_width/2)/M; omega2 = (tr_width/2)/M; 26 | 27 | % 28 | 29 | % plots 30 | 31 | subplot(1,1,1) 32 | 33 | subplot(2,2,1); stem(n,w); 34 | 35 | axis([-(alpha+8),(alpha+8),-0.1,1.1]); 36 | 37 | set(gca,'YTickMode','manual','YTick',[0,1]) 38 | 39 | set(gca,'XTickMode','manual','XTick',[-22,0,22]); 40 | 41 | title('Blackman Window : M=45') 42 | 43 | xlabel('n'); ylabel('w(n)') 44 | 45 | subplot(2,2,3); plot(omega/pi,Wr); 46 | 47 | axis([-1,1,-2,sumw+5]); 48 | 49 | set(gca,'YTickMode','manual','YTick',[0,sumw]) 50 | 51 | set(gca,'XTickMode','manual','XTick',[-1,0,1]); grid 52 | 53 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0';'22';'45']); 54 | 55 | title('Amplitude Response') 56 | 57 | xlabel('frequency in pi units'); ylabel('Wr') 58 | 59 | subplot(2,2,2); plot(omega/pi,db); 60 | 61 | axis([-1,1,-90,10]); 62 | 63 | set(gca,'YTickMode','manual','YTick',[-58,0]) 64 | 65 | set(gca,'YTickLabelMode','manual','YTickLabels',['58';' 0']) 66 | 67 | set(gca,'XTickMode','manual','XTick',[-1,0,1]);grid 68 | 69 | title('Amplitude Response in dB') 70 | 71 | xlabel('frequency in pi units'); ylabel('Decibels') 72 | 73 | subplot(2,2,4); plot(omega/pi,Intdb); 74 | 75 | axis([-1,1,-100,10]); 76 | 77 | set(gca,'YTickMode','manual','YTick',[-75,0]) 78 | 79 | set(gca,'YTickLabelMode','manual','YTickLabels',['74';' 0']) 80 | 81 | set(gca,'XTickMode','manual','XTick',[-1;omega1;omega2;1]);grid 82 | 83 | set(gca,'XTickLabelMode','manual','XTickLabels',['-1';' ';' ';' 1']) 84 | 85 | title('Accumulated Amplitude Response') 86 | 87 | xlabel('frequency in pi units'); ylabel('Decibels') 88 | 89 | text(omega2,5,'Width=(11)*pi/M') 90 | 91 | -------------------------------------------------------------------------------- /FIGURES/ampresbr.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Bartlett (triangular) Window Amplitude Response 2 | 3 | % 4 | 5 | M = 45; alpha = (M-1)/2; 6 | 7 | n = -alpha:alpha; 8 | 9 | w = (bartlett(M))'; sumw = sum(w); 10 | 11 | N = 1000; omega = (2*pi/N)*[-N/2:N/2]; 12 | 13 | Wr = real(w*(exp(-j*n'*omega))); 14 | 15 | db = 20*log10(abs(Wr)/max(Wr)); 16 | 17 | IntWr = cumsum(Wr); 18 | 19 | Intdb = 20*log10(abs(IntWr)/N); 20 | 21 | k = (N/2+1) - min(find(Intdb > -25)); 22 | 23 | tr_width = 2*k*2*M/N, %actual transition width in pi/M units 24 | 25 | omega1 = -(tr_width/2)/M; omega2 = (tr_width/2)/M; 26 | 27 | % 28 | 29 | % plots 30 | 31 | subplot(1,1,1) 32 | 33 | subplot(2,2,1); stem(n,w); 34 | 35 | axis([-(alpha+8),(alpha+8),-0.1,1.1]); 36 | 37 | set(gca,'YTickMode','manual','YTick',[0,1]) 38 | 39 | set(gca,'XTickMode','manual','XTick',[-22,0,22]); 40 | 41 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0';'22';'45']); 42 | 43 | title('Triangular Window : M=45') 44 | 45 | xlabel('n'); ylabel('w(n)') 46 | 47 | subplot(2,2,3); plot(omega/pi,Wr); 48 | 49 | axis([-1,1,-5,30]); 50 | 51 | set(gca,'YTickMode','manual','YTick',[0,sumw]) 52 | 53 | set(gca,'XTickMode','manual','XTick',[-1,0,1]); grid 54 | 55 | title('Amplitude Response') 56 | 57 | xlabel('frequency in pi units'); ylabel('Wr') 58 | 59 | subplot(2,2,2); plot(omega/pi,db); 60 | 61 | axis([-1,1,-60,10]); 62 | 63 | set(gca,'YTickMode','manual','YTick',[-60,-27,0]) 64 | 65 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';'27';' 0']) 66 | 67 | set(gca,'XTickMode','manual','XTick',[-1,0,1]);grid 68 | 69 | title('Amplitude Response in dB') 70 | 71 | xlabel('frequency in pi units'); ylabel('Decibels') 72 | 73 | subplot(2,2,4); plot(omega/pi,Intdb); 74 | 75 | axis([-1,1,-60,10]); 76 | 77 | set(gca,'YTickMode','manual','YTick',[-60,-26,0]) 78 | 79 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';'26';' 0']) 80 | 81 | set(gca,'XTickMode','manual','XTick',[-1;omega1;omega2;1]);grid 82 | 83 | set(gca,'XTickLabelMode','manual','XTickLabels',['-1';' ';' ';' 1']) 84 | 85 | title('Accumulated Amplitude Response') 86 | 87 | xlabel('frequency in pi units'); ylabel('Decibels') 88 | 89 | text(omega2,5,'Width=(6.1)*pi/M') 90 | 91 | -------------------------------------------------------------------------------- /FIGURES/ampreshm.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Hamming Window Amplitude Response 2 | 3 | % 4 | 5 | M = 45; alpha = (M-1)/2; 6 | 7 | n = -alpha:alpha; 8 | 9 | w = (hamming(M))'; sumw = sum(w); 10 | 11 | N = 1000; omega = (2*pi/N)*[-N/2:N/2]; 12 | 13 | Wr = real(w*(exp(-j*n'*omega))); 14 | 15 | db = 20*log10(abs(Wr)/max(Wr)); 16 | 17 | IntWr = cumsum(Wr); 18 | 19 | Intdb = 20*log10(abs(IntWr)/N); 20 | 21 | k = (N/2+1) - min(find(Intdb > -53)); 22 | 23 | tr_width = 2*k*2*M/N, %actual transition width in pi/M units 24 | 25 | omega1 = -(tr_width/2)/M; omega2 = (tr_width/2)/M; 26 | 27 | % 28 | 29 | % plots 30 | 31 | subplot(1,1,1) 32 | 33 | subplot(2,2,1); stem(n,w); 34 | 35 | axis([-(alpha+8),(alpha+8),-0.1,1.1]); 36 | 37 | set(gca,'YTickMode','manual','YTick',[0,1]) 38 | 39 | set(gca,'XTickMode','manual','XTick',[-22,0,22]); 40 | 41 | title('Hamming Window : M=45') 42 | 43 | xlabel('n'); ylabel('w(n)') 44 | 45 | subplot(2,2,3); plot(omega/pi,Wr); 46 | 47 | axis([-1,1,-2,sumw+5]); 48 | 49 | set(gca,'YTickMode','manual','YTick',[0,sumw]) 50 | 51 | set(gca,'XTickMode','manual','XTick',[-1,0,1]); grid 52 | 53 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0';'22';'45']); 54 | 55 | title('Amplitude Response') 56 | 57 | xlabel('frequency in pi units'); ylabel('Wr') 58 | 59 | subplot(2,2,2); plot(omega/pi,db); 60 | 61 | axis([-1,1,-60,10]); 62 | 63 | set(gca,'YTickMode','manual','YTick',[-60,-42,0]) 64 | 65 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';'43';' 0']) 66 | 67 | set(gca,'XTickMode','manual','XTick',[-1,0,1]);grid 68 | 69 | title('Amplitude Response in dB') 70 | 71 | xlabel('frequency in pi units'); ylabel('Decibels') 72 | 73 | subplot(2,2,4); plot(omega/pi,Intdb); 74 | 75 | axis([-1,1,-70,10]); 76 | 77 | set(gca,'YTickMode','manual','YTick',[-70,-54,0]) 78 | 79 | set(gca,'YTickLabelMode','manual','YTickLabels',['70';'54';' 0']) 80 | 81 | set(gca,'XTickMode','manual','XTick',[-1;omega1;omega2;1]);grid 82 | 83 | set(gca,'XTickLabelMode','manual','XTickLabels',['-1';' ';' ';' 1']) 84 | 85 | title('Accumulated Amplitude Response') 86 | 87 | xlabel('frequency in pi units'); ylabel('Decibels') 88 | 89 | text(omega2,5,'Width=(6.6)*pi/M') 90 | 91 | -------------------------------------------------------------------------------- /FIGURES/ampreshn.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Hanning Window Amplitude Response 2 | 3 | % 4 | 5 | M = 45; alpha = (M-1)/2; 6 | 7 | n = -alpha:alpha; 8 | 9 | w = (hanning(M))'; sumw = sum(w); 10 | 11 | N = 1000; omega = (2*pi/N)*[-N/2:N/2]; 12 | 13 | Wr = real(w*(exp(-j*n'*omega))); 14 | 15 | db = 20*log10(abs(Wr)/max(Wr)); 16 | 17 | IntWr = cumsum(Wr); 18 | 19 | Intdb = 20*log10(abs(IntWr)/N); 20 | 21 | l = min(find(Intdb > -44)); % Use this and the next 22 | 23 | k = (N/2+1) - 467; % when logic does not work 24 | 25 | %k = (N/2+1) - (min(find(Intdb > -44))+l-1); % correct 26 | 27 | tr_width = 2*k*2*M/N, %actual transition width in pi/M units 28 | 29 | omega1 = -(tr_width/2)/M; omega2 = (tr_width/2)/M; 30 | 31 | % 32 | 33 | % plots 34 | 35 | subplot(1,1,1) 36 | 37 | subplot(2,2,1); stem(n,w); 38 | 39 | axis([-(alpha+8),(alpha+8),-0.1,1.1]); 40 | 41 | set(gca,'YTickMode','manual','YTick',[0,1]) 42 | 43 | set(gca,'XTickMode','manual','XTick',[-22,0,22]); 44 | 45 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0';'22';'45']); 46 | 47 | title('Hanning Window : M=45') 48 | 49 | xlabel('n'); ylabel('w(n)') 50 | 51 | subplot(2,2,3); plot(omega/pi,Wr); 52 | 53 | axis([-1,1,-2,sumw+5]); 54 | 55 | set(gca,'YTickMode','manual','YTick',[0,sumw]) 56 | 57 | set(gca,'XTickMode','manual','XTick',[-1,0,1]); grid 58 | 59 | title('Amplitude Response') 60 | 61 | xlabel('frequency in pi units'); ylabel('Wr') 62 | 63 | subplot(2,2,2); plot(omega/pi,db); 64 | 65 | axis([-1,1,-60,10]); 66 | 67 | set(gca,'YTickMode','manual','YTick',[-60,-32,0]) 68 | 69 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';'32';' 0']) 70 | 71 | set(gca,'XTickMode','manual','XTick',[-1,0,1]);grid 72 | 73 | title('Amplitude Response in dB') 74 | 75 | xlabel('frequency in pi units'); ylabel('Decibels') 76 | 77 | subplot(2,2,4); plot(omega/pi,Intdb); 78 | 79 | axis([-1,1,-60,10]); 80 | 81 | set(gca,'YTickMode','manual','YTick',[-60,-44,0]) 82 | 83 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';'44';' 0']) 84 | 85 | set(gca,'XTickMode','manual','XTick',[-1;omega1;omega2;1]);grid 86 | 87 | set(gca,'XTickLabelMode','manual','XTickLabels',['-1';' ';' ';' 1']) 88 | 89 | title('Accumulated Amplitude Response') 90 | 91 | xlabel('frequency in pi units'); ylabel('Decibels') 92 | 93 | text(omega2,5,'Width=(6.2)*pi/M') 94 | 95 | -------------------------------------------------------------------------------- /FIGURES/ampreska.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Kaiser Window Amplitude Response 2 | 3 | % 4 | 5 | beta = 5.658; M = 45; N = 1000; 6 | 7 | alpha = (M-1)/2; n = -alpha:alpha; 8 | 9 | w = (kaiser(M,beta))'; sumw = sum(w); 10 | 11 | omega = (2*pi/N)*[-N/2:N/2]; 12 | 13 | Wr = real(w*(exp(-j*n'*omega))); 14 | 15 | db = 20*log10(abs(Wr)/max(Wr)); 16 | 17 | IntWr = cumsum(Wr); 18 | 19 | Intdb = 20*log10(abs(IntWr)/N); 20 | 21 | l = min(find(Intdb > -60)); 22 | 23 | k = (N/2+1) - 460; 24 | 25 | %k = (N/2+1) - min(find(Intdb > -60)); 26 | 27 | tr_width = 2*k*2*M/N, %actual transition width in pi/M units 28 | 29 | omega1 = -(tr_width/2)/M; omega2 = (tr_width/2)/M; 30 | 31 | % 32 | 33 | % plots 34 | 35 | subplot(1,1,1) 36 | 37 | subplot(2,2,1); stem(n,w); 38 | 39 | axis([-(alpha+8),(alpha+8),-0.1,1.1]); 40 | 41 | set(gca,'YTickMode','manual','YTick',[0,1]) 42 | 43 | set(gca,'XTickMode','manual','XTick',[-22,0,22]); 44 | 45 | title('Kaiser Window : M=45') 46 | 47 | xlabel('n'); ylabel('w(n)') 48 | 49 | subplot(2,2,3); plot(omega/pi,Wr); 50 | 51 | axis([-1,1,-2,sumw+5]); 52 | 53 | set(gca,'YTickMode','manual','YTick',[0,sumw]) 54 | 55 | set(gca,'XTickMode','manual','XTick',[-1,0,1]); grid 56 | 57 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0';'22';'45']); 58 | 59 | title('Amplitude Response') 60 | 61 | xlabel('frequency in pi units'); ylabel('Wr') 62 | 63 | subplot(2,2,2); plot(omega/pi,db); 64 | 65 | axis([-1,1,-90,10]); 66 | 67 | set(gca,'YTickMode','manual','YTick',[-42,0]) 68 | 69 | set(gca,'YTickLabelMode','manual','YTickLabels',['42';' 0']) 70 | 71 | set(gca,'XTickMode','manual','XTick',[-1,0,1]);grid 72 | 73 | title('Amplitude Response in dB') 74 | 75 | xlabel('frequency in pi units'); ylabel('Decibels') 76 | 77 | subplot(2,2,4); plot(omega/pi,Intdb); 78 | 79 | axis([-1,1,-80,10]); 80 | 81 | set(gca,'YTickMode','manual','YTick',[-60,0]) 82 | 83 | set(gca,'YTickLabelMode','manual','YTickLabels',['60';' 0']) 84 | 85 | set(gca,'XTickMode','manual','XTick',[-1;omega1;omega2;1]);grid 86 | 87 | set(gca,'XTickLabelMode','manual','XTickLabels',['-1';' ';' ';' 1']) 88 | 89 | title('Accumulated Amplitude Response') 90 | 91 | xlabel('frequency in pi units'); ylabel('Decibels') 92 | 93 | text(omega2,5,'Width=(7.8)*pi/M') 94 | 95 | -------------------------------------------------------------------------------- /FIGURES/ampresrc.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Rectangular Window Amplitude Response 2 | 3 | % 4 | 5 | M = 45; alpha = (M-1)/2; 6 | 7 | n = -alpha:alpha; 8 | 9 | w = ones(1,M); 10 | 11 | N = 1000; omega = (2*pi/N)*[-N/2:N/2]; 12 | 13 | Wr = real(w*(exp(-j*n'*omega))); 14 | 15 | db = 20*log10(abs(Wr)/max(Wr)); 16 | 17 | IntWr = cumsum(Wr); 18 | 19 | Intdb = 20*log10(abs(IntWr)/N); 20 | 21 | %l = find(Intdb(471:N/2) > -21)+470; 22 | 23 | k = (N/2+1) - min(find(Intdb > -21)); 24 | 25 | tr_width = 2*k*2*M/N; %actual transition width in pi/M units 26 | 27 | omega1 = -(tr_width/2)/M; omega2 = (tr_width/2)/M; 28 | 29 | % 30 | 31 | % plots 32 | 33 | subplot(1,1,1) 34 | 35 | subplot(2,2,1); stem(n,w); 36 | 37 | axis([-(alpha+8),(alpha+8),-0.1,1.1]); 38 | 39 | set(gca,'YTickMode','manual','YTick',[0,1]) 40 | 41 | set(gca,'XTickMode','manual','XTick',[-22,0,22]); 42 | 43 | set(gca,'XTickLabelMode','manual','XTickLabels',[' 0';'22';'45']); 44 | 45 | title('Rectangular Window : M=45') 46 | 47 | xlabel('n'); ylabel('w(n)') 48 | 49 | subplot(2,2,3); plot(omega/pi,Wr); 50 | 51 | axis([-1,1,-20,50]); 52 | 53 | set(gca,'YTickMode','manual','YTick',[0,45]) 54 | 55 | set(gca,'XTickMode','manual','XTick',[-1,0,1]); grid 56 | 57 | title('Amplitude Response') 58 | 59 | xlabel('frequency in pi units'); ylabel('Wr') 60 | 61 | subplot(2,2,2); plot(omega/pi,db); 62 | 63 | axis([-1,1,-40,10]); 64 | 65 | set(gca,'YTickMode','manual','YTick',[-40,-13,0]) 66 | 67 | set(gca,'YTickLabelMode','manual','YTickLabels',['40';'13';' 0']) 68 | 69 | set(gca,'XTickMode','manual','XTick',[-1,0,1]);grid 70 | 71 | title('Amplitude Response in dB') 72 | 73 | xlabel('frequency in pi units'); ylabel('Decibels') 74 | 75 | subplot(2,2,4); plot(omega/pi,Intdb); 76 | 77 | axis([-1,1,-50,10]); 78 | 79 | set(gca,'YTickMode','manual','YTick',[-50,-21,0]) 80 | 81 | set(gca,'YTickLabelMode','manual','YTickLabels',['50';'21';' 0']) 82 | 83 | set(gca,'XTickMode','manual','XTick',[-1;omega1;omega2;1]);grid 84 | 85 | set(gca,'XTickLabelMode','manual','XTickLabels',['-1';' ';' ';' 1']) 86 | 87 | title('Accumulated Amplitude Response') 88 | 89 | xlabel('frequency in pi units'); ylabel('Decibels') 90 | 91 | text(omega2,5,' Width=(1.8)*pi/M') 92 | 93 | -------------------------------------------------------------------------------- /FIGURES/gen_zero.m: -------------------------------------------------------------------------------- 1 | % Chapter 7 Matlab Figure on 2 | 3 | % A general Zero Constellation 4 | 5 | % 6 | 7 | subplot(1,1,1) 8 | 9 | r = 0.6; theta = 50*pi/180; 10 | 11 | z1 = r*exp(j*theta); % an arbitrary zero location 12 | 13 | z2 = 1/z1; % a linear-phase zero location 14 | 15 | z3 = conj(z1); % a conjugate zero location 16 | 17 | z4 = 1/z3; % a linear-phase conjugate zero location 18 | 19 | b = poly([z1,z2,z3,z4]); 20 | 21 | pzplotz(b,1) 22 | 23 | text(real(z1)-0.1,imag(z1)+0.15,'z1') 24 | 25 | text(real(z3)-0.2,imag(z3)-0.15,'conj(z1)') 26 | 27 | text(real(z2)-0.1,imag(z2)+0.15,'1/z1') 28 | 29 | text(real(z4)-0.2,imag(z4)-0.15,'1/conj(z1)') -------------------------------------------------------------------------------- /FIGURES/gibbs.m: -------------------------------------------------------------------------------- 1 | % Chapter 7: Rectangular Window Gibbs Phenomenon 2 | 3 | % 4 | 5 | subplot(1,1,1); N = 1000; 6 | 7 | % M = 7 8 | 9 | M = 7; alpha = (M-1)/2; 10 | 11 | n = -alpha:alpha; 12 | 13 | w = ones(1,M); 14 | 15 | omega = (2*pi/N)*[-N/2:N/2]; 16 | 17 | Wr = real(w*(exp(-j*n'*omega))); 18 | 19 | db = 20*log10(abs(Wr)/max(Wr)); 20 | 21 | IntWr = cumsum(Wr)/N; 22 | 23 | % 24 | 25 | % plots 26 | 27 | subplot(2,2,1); plot(omega/pi,IntWr); 28 | 29 | axis([-1,1,-0.15,1.15]); 30 | 31 | title('M = 7') 32 | 33 | xlabel('frequency in pi units'); ylabel('Integrated Amplitude Response') 34 | 35 | set(gca,'YTickMode','manual','YTick',[0,1]) 36 | 37 | set(gca,'XTickMode','manual','XTick',[-1,0,1]); grid 38 | 39 | % 40 | 41 | % M = 21 42 | 43 | M = 21; alpha = (M-1)/2; 44 | 45 | n = -alpha:alpha; 46 | 47 | w = ones(1,M); 48 | 49 | omega = (2*pi/N)*[-N/2:N/2]; 50 | 51 | Wr = real(w*(exp(-j*n'*omega))); 52 | 53 | db = 20*log10(abs(Wr)/max(Wr)); 54 | 55 | IntWr = cumsum(Wr)/N; 56 | 57 | % 58 | 59 | % plots 60 | 61 | subplot(2,2,2); plot(omega/pi,IntWr); 62 | 63 | axis([-1,1,-0.15,1.15]); 64 | 65 | title('M = 21') 66 | 67 | xlabel('frequency in pi units'); ylabel('Integrated Amplitude Response') 68 | 69 | set(gca,'YTickMode','manual','YTick',[0,1]) 70 | 71 | set(gca,'XTickMode','manual','XTick',[-1,0,1]); grid 72 | 73 | % 74 | 75 | % M = 51 76 | 77 | M = 51; alpha = (M-1)/2; 78 | 79 | n = -alpha:alpha; 80 | 81 | w = ones(1,M); 82 | 83 | omega = (2*pi/N)*[-N/2:N/2]; 84 | 85 | Wr = real(w*(exp(-j*n'*omega))); 86 | 87 | db = 20*log10(abs(Wr)/max(Wr)); 88 | 89 | IntWr = cumsum(Wr)/N; 90 | 91 | % 92 | 93 | % plots 94 | 95 | subplot(2,2,3); plot(omega/pi,IntWr); 96 | 97 | axis([-1,1,-0.15,1.15]); 98 | 99 | title('M = 51') 100 | 101 | xlabel('frequency in pi units'); ylabel('Integrated Amplitude Response') 102 | 103 | set(gca,'YTickMode','manual','YTick',[0,1]) 104 | 105 | set(gca,'XTickMode','manual','XTick',[-1,0,1]); grid 106 | 107 | % 108 | 109 | % M = 101 110 | 111 | M = 101; alpha = (M-1)/2; 112 | 113 | n = -alpha:alpha; 114 | 115 | w = ones(1,M); 116 | 117 | omega = (2*pi/N)*[-N/2:N/2]; 118 | 119 | Wr = real(w*(exp(-j*n'*omega))); 120 | 121 | db = 20*log10(abs(Wr)/max(Wr)); 122 | 123 | IntWr = cumsum(Wr)/N; 124 | 125 | % 126 | 127 | % plots 128 | 129 | subplot(2,2,4); plot(omega/pi,IntWr); 130 | 131 | axis([-1,1,-0.15,1.15]); 132 | 133 | title('M = 101') 134 | 135 | xlabel('frequency in pi units'); ylabel('Integrated Amplitude Response') 136 | 137 | set(gca,'YTickMode','manual','YTick',[0,1]) 138 | 139 | set(gca,'XTickMode','manual','XTick',[-1,0,1]); grid 140 | 141 | -------------------------------------------------------------------------------- /FIGURES/type1_ir.m: -------------------------------------------------------------------------------- 1 | % Chapter 7 Matlab Figure on 2 | 3 | % sym impulse response odd M 4 | 5 | % 6 | 7 | subplot(1,1,1) 8 | 9 | % ODD M 10 | 11 | h = [-4,1,-1,-2,5,6,5,-2,-1,1,-4]; 12 | 13 | M = length(h); n = 0:M-1; alpha = (M-1)/2; 14 | 15 | subplot(2,1,2); 16 | 17 | stem(n,h); axis([-1,M,-5,8]); 18 | 19 | title('Symmetric Impulse Response: M odd') 20 | 21 | xlabel('n'); ylabel('h(n)') 22 | 23 | set(gca,'XTickMode','manual','XTick',[0,5,10],'Xgrid','on') 24 | 25 | set(gca,'XTickLabelMode','manual',... 26 | 27 | 'XTickLabels',[' 0 ';'(M-1)/2';' (M-1) ']) 28 | 29 | set(gca,'YTickMode','manual','YTick',[0],'Ygrid','off') 30 | 31 | set(gca,'YTickLabelMode','manual','YTickLabels',['0']) 32 | 33 | -------------------------------------------------------------------------------- /FIGURES/type2_ir.m: -------------------------------------------------------------------------------- 1 | % Chapter 7 Matlab Figure on 2 | 3 | % sym impulse response even M 4 | 5 | % 6 | 7 | subplot(1,1,1) 8 | 9 | % ODD M 10 | 11 | h = [-4,1,-1,-2,5,6,6,5,-2,-1,1,-4]; 12 | 13 | M = length(h); n = 0:M-1; alpha = (M-1)/2; 14 | 15 | subplot(2,1,2); 16 | 17 | stem(n,h); axis([-1,M,-5,8]); 18 | 19 | title('Symmetric Impulse Response: M even') 20 | 21 | xlabel('n'); ylabel('h(n)') 22 | 23 | set(gca,'XTickMode','manual','XTick',[0,5,6,11],'Xgrid','on') 24 | 25 | set(gca,'XTickLabelMode','manual',... 26 | 27 | 'XTickLabels',[' 0 ';'M/2+1';' M/2 ';' M-1 ']) 28 | 29 | set(gca,'YTickMode','manual','YTick',[0],'Ygrid','off') 30 | 31 | set(gca,'YTickLabelMode','manual','YTickLabels',['0']) 32 | 33 | -------------------------------------------------------------------------------- /FIGURES/type3_ir.m: -------------------------------------------------------------------------------- 1 | % Chapter 7 Matlab Figure on 2 | 3 | % Anti-sym impulse response odd M 4 | 5 | % 6 | 7 | subplot(1,1,1) 8 | 9 | % ODD M 10 | 11 | h = [-4,1,-1,-2,5,0,-5,2,1,-1,4]; 12 | 13 | M = length(h); n = 0:M-1; alpha = (M-1)/2; 14 | 15 | subplot(2,1,2); 16 | 17 | stem(n,h); axis([-1,M,-8,8]); 18 | 19 | title('Anti-Symmetric Impulse Response: M odd') 20 | 21 | xlabel('n'); ylabel('h(n)') 22 | 23 | set(gca,'XTickMode','manual','XTick',[0,5,10],'Xgrid','on') 24 | 25 | set(gca,'XTickLabelMode','manual',... 26 | 27 | 'XTickLabels',[' 0 ';'(M-1)/2';' M-1 ']) 28 | 29 | set(gca,'YTickMode','manual','YTick',[0],'Ygrid','off') 30 | 31 | set(gca,'YTickLabelMode','manual','YTickLabels',['0']) 32 | 33 | -------------------------------------------------------------------------------- /FIGURES/type4_ir.m: -------------------------------------------------------------------------------- 1 | % Chapter 7 Matlab Figure on 2 | 3 | % Anti-sym impulse response odd M 4 | 5 | % 6 | 7 | subplot(1,1,1) 8 | 9 | % ODD M 10 | 11 | h = [-4,1,-1,-2,5,6,-6,-5,2,1,-1,4]; 12 | 13 | M = length(h); n = 0:M-1; alpha = (M-1)/2; 14 | 15 | subplot(2,1,2); 16 | 17 | stem(n,h); axis([-1,M,-8,8]); 18 | 19 | title('Anti-Symmetric Impulse Response: M even') 20 | 21 | xlabel('n'); ylabel('h(n)') 22 | 23 | set(gca,'XTickMode','manual','XTick',[0,5,6,11],'Xgrid','on') 24 | 25 | set(gca,'XTickLabelMode','manual',... 26 | 27 | 'XTickLabels',[' 0 ';'M/2+1';' M/2 ';' M-1 ']) 28 | 29 | set(gca,'YTickMode','manual','YTick',[0],'Ygrid','off') 30 | 31 | set(gca,'YTickLabelMode','manual','YTickLabels',['0']) 32 | 33 | -------------------------------------------------------------------------------- /PWS_DSP/afd_butt.m: -------------------------------------------------------------------------------- 1 | function [b,a] = afd_butt(Wp,Ws,Rp,As); 2 | 3 | % Analog Lowpass Filter Design: Butterworth 4 | 5 | % ----------------------------------------- 6 | 7 | % [b,a] = afd_butt(Wp,Ws,Rp,As); 8 | 9 | % b = Numerator coefficients of Ha(s) 10 | 11 | % a = Denominator coefficients of Ha(s) 12 | 13 | % Wp = Passband edge frequency in rad/sec; Wp > 0 14 | 15 | % Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0 16 | 17 | % Rp = Passband ripple in +dB; (Rp > 0) 18 | 19 | % As = Stopband attenuation in +dB; (As > 0) 20 | 21 | % 22 | 23 | if Wp <= 0 24 | 25 | error('Passband edge must be larger than 0') 26 | 27 | end 28 | 29 | if Ws <= Wp 30 | 31 | error('Stopband edge must be larger than Passband edge') 32 | 33 | end 34 | 35 | if (Rp <= 0) | (As < 0) 36 | 37 | error('PB ripple and/or SB attenuation ust be larger than 0') 38 | 39 | end 40 | 41 | 42 | 43 | N = ceil((log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(Wp/Ws))); 44 | 45 | fprintf('\n*** Butterworth Filter Order = %2.0f \n',N) 46 | 47 | OmegaC = Wp/((10^(Rp/10)-1)^(1/(2*N))); 48 | 49 | [b,a]=u_buttap(N,OmegaC); 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /PWS_DSP/afd_chb1.m: -------------------------------------------------------------------------------- 1 | function [b,a] = afd_chb1(Wp,Ws,Rp,As); 2 | 3 | % Analog Lowpass Filter Design: Chebyshev-1 4 | 5 | % ----------------------------------------- 6 | 7 | % [b,a] = afd_chb1(Wp,Ws,Rp,As); 8 | 9 | % b = Numerator coefficients of Ha(s) 10 | 11 | % a = Denominator coefficients of Ha(s) 12 | 13 | % Wp = Passband edge frequency in rad/sec; Wp > 0 14 | 15 | % Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0 16 | 17 | % Rp = Passband ripple in +dB; (Rp > 0) 18 | 19 | % As = Stopband attenuation in +dB; (As > 0) 20 | 21 | % 22 | 23 | if Wp <= 0 24 | 25 | error('Passband edge must be larger than 0') 26 | 27 | end 28 | 29 | if Ws <= Wp 30 | 31 | error('Stopband edge must be larger than Passband edge') 32 | 33 | end 34 | 35 | if (Rp <= 0) | (As < 0) 36 | 37 | error('PB ripple and/or SB attenuation ust be larger than 0') 38 | 39 | end 40 | 41 | 42 | 43 | ep = sqrt(10^(Rp/10)-1); 44 | 45 | A = 10^(As/20); 46 | 47 | OmegaC = Wp; 48 | 49 | OmegaR = Ws/Wp; 50 | 51 | g = sqrt(A*A-1)/ep; 52 | 53 | N = ceil(log10(g+sqrt(g*g-1))/log10(OmegaR+sqrt(OmegaR*OmegaR-1))); 54 | 55 | fprintf('\n*** Chebyshev-1 Filter Order = %2.0f \n',N) 56 | 57 | [b,a]=u_chb1ap(N,Rp,OmegaC); 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /PWS_DSP/afd_chb2.m: -------------------------------------------------------------------------------- 1 | function [b,a] = afd_chb2(Wp,Ws,Rp,As); 2 | 3 | % Analog Lowpass Filter Design: Chebyshev-2 4 | 5 | % ----------------------------------------- 6 | 7 | % [b,a] = afd_chb2(Wp,Ws,Rp,As); 8 | 9 | % b = Numerator coefficients of Ha(s) 10 | 11 | % a = Denominator coefficients of Ha(s) 12 | 13 | % Wp = Passband edge frequency in rad/sec; Wp > 0 14 | 15 | % Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0 16 | 17 | % Rp = Passband ripple in +dB; (Rp > 0) 18 | 19 | % As = Stopband attenuation in +dB; (As > 0) 20 | 21 | % 22 | 23 | if Wp <= 0 24 | 25 | error('Passband edge must be larger than 0') 26 | 27 | end 28 | 29 | if Ws <= Wp 30 | 31 | error('Stopband edge must be larger than Passband edge') 32 | 33 | end 34 | 35 | if (Rp <= 0) | (As < 0) 36 | 37 | error('PB ripple and/or SB attenuation ust be larger than 0') 38 | 39 | end 40 | 41 | 42 | 43 | ep = sqrt(10^(Rp/10)-1); 44 | 45 | A = 10^(As/20); 46 | 47 | OmegaC = Wp; 48 | 49 | OmegaR = Ws/Wp; 50 | 51 | g = sqrt(A*A-1)/ep; 52 | 53 | N = ceil(log10(g+sqrt(g*g-1))/log10(OmegaR+sqrt(OmegaR*OmegaR-1))); 54 | 55 | fprintf('\n*** Chebyshev-2 Filter Order = %2.0f \n',N) 56 | 57 | [b,a]=u_chb2ap(N,As,Ws); 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /PWS_DSP/afd_elip.m: -------------------------------------------------------------------------------- 1 | function [b,a] = afd_elip(Wp,Ws,Rp,As); 2 | 3 | % Analog Lowpass Filter Design: Elliptic 4 | 5 | % -------------------------------------- 6 | 7 | % [b,a] = afd_elip(Wp,Ws,Rp,As); 8 | 9 | % b = Numerator coefficients of Ha(s) 10 | 11 | % a = Denominator coefficients of Ha(s) 12 | 13 | % Wp = Passband edge frequency in rad/sec; Wp > 0 14 | 15 | % Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0 16 | 17 | % Rp = Passband ripple in +dB; (Rp > 0) 18 | 19 | % As = Stopband attenuation in +dB; (As > 0) 20 | 21 | % 22 | 23 | if Wp <= 0 24 | 25 | error('Passband edge must be larger than 0') 26 | 27 | end 28 | 29 | if Ws <= Wp 30 | 31 | error('Stopband edge must be larger than Passband edge') 32 | 33 | end 34 | 35 | if (Rp <= 0) | (As < 0) 36 | 37 | error('PB ripple and/or SB attenuation ust be larger than 0') 38 | 39 | end 40 | 41 | 42 | 43 | ep = sqrt(10^(Rp/10)-1); 44 | 45 | A = 10^(As/20); 46 | 47 | OmegaC = Wp; 48 | 49 | k = Wp/Ws; 50 | 51 | k1 = ep/sqrt(A*A-1); 52 | 53 | capk = ellipke([k.^2 1-k.^2]); % Version 4.0 code 54 | 55 | capk1 = ellipke([(k1 .^2) 1-(k1 .^2)]); % Version 4.0 code 56 | 57 | N = ceil(capk(1)*capk1(2)/(capk(2)*capk1(1))); 58 | 59 | fprintf('\n*** Elliptic Filter Order = %2.0f \n',N) 60 | 61 | [b,a]=u_elipap(N,Rp,As,OmegaC); -------------------------------------------------------------------------------- /PWS_DSP/blackman.m: -------------------------------------------------------------------------------- 1 | function w_black = Blackman(M); 2 | 3 | % M-point Blackman window 4 | 5 | % ----------------------- 6 | 7 | % w_black = Blackman(M); 8 | 9 | % 10 | 11 | M1 = M-1; 12 | 13 | m = [0:1:M1]; 14 | 15 | w_black = abs(0.42 - 0.5*cos(2*pi*m'/(M1)) + 0.08*cos(4*pi*m'/(M1))); 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /PWS_DSP/cas2dir.m: -------------------------------------------------------------------------------- 1 | function [b,a] = cas2dir(b0,B,A); 2 | 3 | % CASCADE-to-DIRECT form conversion 4 | 5 | % --------------------------------- 6 | 7 | % [b,a] = cas2dir(b0,B,A) 8 | 9 | % b = numerator polynomial coefficients of DIRECT form 10 | 11 | % a = denominator polynomial coefficients of DIRECT form 12 | 13 | % b0 = gain coefficient 14 | 15 | % B = K by 3 matrix of real coefficients containing bk's 16 | 17 | % A = K by 3 matrix of real coefficients containing ak's 18 | 19 | % 20 | 21 | [K,L] = size(B); 22 | 23 | b = [1]; 24 | 25 | a = [1]; 26 | 27 | for i=1:1:K 28 | 29 | b=conv(b,B(i,:)); 30 | 31 | a=conv(a,A(i,:)); 32 | 33 | end 34 | 35 | b = b*b0; 36 | 37 | -------------------------------------------------------------------------------- /PWS_DSP/casfiltr.m: -------------------------------------------------------------------------------- 1 | function y = casfiltr(b0,B,A,x); 2 | 3 | % CASCADE form realization of IIR and FIR filters 4 | 5 | % ----------------------------------------------- 6 | 7 | % y = casfiltr(b0,B,A,x); 8 | 9 | % y = output sequence 10 | 11 | % b0 = gain coefficient of CASCADE form 12 | 13 | % B = K by 3 matrix of real coefficients containing bk's 14 | 15 | % A = K by 3 matrix of real coefficients containing ak's 16 | 17 | % x = input sequence 18 | 19 | % 20 | 21 | [K,L] = size(B); 22 | 23 | N = length(x); 24 | 25 | w = zeros(K+1,N); 26 | 27 | w(1,:) = x; 28 | 29 | for i = 1:1:K 30 | 31 | w(i+1,:) = filter(B(i,:),A(i,:),w(i,:)); 32 | 33 | end 34 | 35 | y = b0*w(K+1,:); 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /PWS_DSP/cheb1hpf.m: -------------------------------------------------------------------------------- 1 | function [b,a] = cheb1hpf(wp,ws,Rp,As) 2 | 3 | % IIR Highpass filter design using Chebyshev-1 prototype 4 | 5 | % [b,a] = cheb1hpf(wp,ws,Rp,As) 6 | 7 | % b = Numerator polynomial of the highpass filter 8 | 9 | % a = Denominator polynomial of the highpass filter 10 | 11 | % wp = Passband frequency in radians 12 | 13 | % ws = Stopband frequency in radians 14 | 15 | % Rp = Passband ripple in dB 16 | 17 | % As = Stopband attenuation in dB 18 | 19 | % 20 | 21 | % Determine the digital lowpass cutoff frequecies: 22 | 23 | wplp = 0.2*pi; 24 | 25 | alpha = -(cos((wplp+wp)/2))/(cos((wplp-wp)/2)); 26 | 27 | wslp = angle(-(exp(-j*ws)+alpha)/(1+alpha*exp(-j*ws))); 28 | 29 | % 30 | 31 | % Compute Analog lowpass Prototype Specifications: 32 | 33 | T = 1; Fs = 1/T; 34 | 35 | OmegaP = (2/T)*tan(wplp/2); 36 | 37 | OmegaS = (2/T)*tan(wslp/2); 38 | 39 | 40 | 41 | % Design Analog Chebyshev Prototype Lowpass Filter: 42 | 43 | [cs,ds] = afd_chb1(OmegaP,OmegaS,Rp,As); 44 | 45 | 46 | 47 | % Perform Bilinear transformation to obtain digital lowpass 48 | 49 | [blp,alp] = bilinear(cs,ds,Fs); 50 | 51 | 52 | 53 | % Transform digital lowpass into highpass filter 54 | 55 | Nz = -[alpha,1]; Dz = [1,alpha]; 56 | 57 | [b,a] = zmapping(blp,alp,Nz,Dz); -------------------------------------------------------------------------------- /PWS_DSP/circevod.m: -------------------------------------------------------------------------------- 1 | function [xec, xoc] = circevod(x) 2 | 3 | % signal decomposition into circular-even and circular-odd parts 4 | 5 | % -------------------------------------------------------------- 6 | 7 | % [xec, xoc] = circecod(x) 8 | 9 | % 10 | 11 | if any(imag(x) ~= 0) 12 | 13 | error('x is not a real sequence') 14 | 15 | end 16 | 17 | N = length(x); n = 0:(N-1); 18 | 19 | xec = 0.5*(x + x(mod(-n,N)+1)); 20 | 21 | xoc = 0.5*(x - x(mod(-n,N)+1)); 22 | 23 | -------------------------------------------------------------------------------- /PWS_DSP/circonvt.m: -------------------------------------------------------------------------------- 1 | function y = circonvt(x1,x2,N) 2 | 3 | % N-point circular convolution between x1 and x2: (time-domain) 4 | 5 | % ------------------------------------------------------------- 6 | 7 | % [y] = circonvt(x1,x2,N) 8 | 9 | % y = output sequence containing the circular convolution 10 | 11 | % x1 = input sequence of length N1 <= N 12 | 13 | % x2 = input sequence of length N2 <= N 14 | 15 | % N = size of circular buffer 16 | 17 | % Method: y(n) = sum (x1(m)*x2((n-m) mod N)) 18 | 19 | 20 | 21 | % Check for length of x1 22 | 23 | if length(x1) > N 24 | 25 | error('N must be >= the length of x1') 26 | 27 | end 28 | 29 | 30 | 31 | % Check for length of x2 32 | 33 | if length(x2) > N 34 | 35 | error('N must be >= the length of x2') 36 | 37 | end 38 | 39 | 40 | 41 | x1=[x1 zeros(1,N-length(x1))]; 42 | 43 | x2=[x2 zeros(1,N-length(x2))]; 44 | 45 | 46 | 47 | m = [0:1:N-1]; 48 | 49 | x2 = x2(mod(-m,N)+1); 50 | 51 | H = zeros(N,N); 52 | 53 | 54 | 55 | for n = 1:1:N 56 | 57 | H(n,:) = cirshftt(x2,n-1,N); 58 | 59 | end 60 | 61 | 62 | 63 | y = x1*H'; 64 | 65 | -------------------------------------------------------------------------------- /PWS_DSP/cirshftt.m: -------------------------------------------------------------------------------- 1 | function y = cirshftt(x,m,N) 2 | 3 | % Circular shift of m samples wrt size N in sequence x: (time domain) 4 | 5 | % ------------------------------------------------------------------- 6 | 7 | % [y] = cirshftt(x,m,N) 8 | 9 | % y = output sequence containing the circular shift 10 | 11 | % x = input sequence of length <= N 12 | 13 | % m = sample shift 14 | 15 | % N = size of circular buffer 16 | 17 | % Method: y(n) = x((n-m) mod N) 18 | 19 | 20 | 21 | % Check for length of x 22 | 23 | if length(x) > N 24 | 25 | error('N must be >= the length of x') 26 | 27 | end 28 | 29 | x = [x zeros(1,N-length(x))]; 30 | 31 | n = [0:1:N-1]; 32 | 33 | n = mod(n-m,N); 34 | 35 | y = x(n+1); -------------------------------------------------------------------------------- /PWS_DSP/codegen/mex/dft/cfiGuiReport.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuYingzheng/digital_signal_processing_using_matlab/2af1dc94a639ec081543085e6ca8be937943ac07/PWS_DSP/codegen/mex/dft/cfiGuiReport.mat -------------------------------------------------------------------------------- /PWS_DSP/codegen/mex/dft/html/report.mldatx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuYingzheng/digital_signal_processing_using_matlab/2af1dc94a639ec081543085e6ca8be937943ac07/PWS_DSP/codegen/mex/dft/html/report.mldatx -------------------------------------------------------------------------------- /PWS_DSP/conv_m.m: -------------------------------------------------------------------------------- 1 | function [y,ny] = conv_m(x,nx,h,nh) 2 | 3 | % Modified convolution routine for signal processing 4 | 5 | % -------------------------------------------------- 6 | 7 | % [y,ny] = conv_m(x,nx,h,nh) 8 | 9 | % y = convolution result 10 | 11 | % ny = support of y 12 | 13 | % x = first signal on support nx 14 | 15 | % nx = support of x 16 | 17 | % h = second signal on support nh 18 | 19 | % nh = support of h 20 | 21 | % 22 | 23 | nyb = nx(1)+nh(1); nye = nx(length(x)) + nh(length(h)); 24 | 25 | ny = [nyb:nye]; 26 | 27 | y = conv(x,h); -------------------------------------------------------------------------------- /PWS_DSP/conv_tp.m: -------------------------------------------------------------------------------- 1 | function [y,H]=conv_tp(h,x) 2 | 3 | % Linear Convolution using Toeplitz Matrix 4 | 5 | % ---------------------------------------- 6 | 7 | % [y,H] = conv_tp(h,x) 8 | 9 | % y = output sequence in column vector form 10 | 11 | % H = Toeplitz matrix corresponding to sequence h so that y = Hx 12 | 13 | % h = Impulse response sequence in column vector form 14 | 15 | % x = input sequence in column vector form 16 | 17 | % 18 | 19 | Nx = length(x); Nh = length(h); 20 | 21 | hc=[h; zeros(Nx-1, 1)]; 22 | 23 | hr=[h(1),zeros(1,Nx-1)]; 24 | 25 | H=toeplitz(hc,hr); 26 | 27 | y=H*x; 28 | 29 | -------------------------------------------------------------------------------- /PWS_DSP/cplxcomp.m: -------------------------------------------------------------------------------- 1 | function I = cplxcomp(p1,p2) 2 | 3 | % I = cplxcomp(p1,p2) 4 | 5 | % Compares two complex pairs which contain the same scalar elements 6 | 7 | % but (possibly) at differrent indices. This routine should be 8 | 9 | % used after CPLXPAIR routine for rearranging pole vector and its 10 | 11 | % corresponding residue vector. 12 | 13 | % p2 = cplxpair(p1) 14 | 15 | % 16 | 17 | I=[]; 18 | 19 | for j=1:1:length(p2) 20 | 21 | for i=1:1:length(p1) 22 | 23 | if (abs(p1(i)-p2(j)) < 0.0001) 24 | 25 | I=[I,i]; 26 | 27 | end 28 | 29 | end 30 | 31 | end 32 | 33 | I=I'; 34 | 35 | -------------------------------------------------------------------------------- /PWS_DSP/db2delta.m: -------------------------------------------------------------------------------- 1 | function [d1,d2] = db2delta(Rp,As) 2 | 3 | % Conversion from Relative dB specs to Absolute delta specs. 4 | 5 | % ---------------------------------------------------------- 6 | 7 | % [d1,d2] = db2delta(Rp,As) 8 | 9 | % d1 = Passband tolerance 10 | 11 | % d2 = Stopband tolerance 12 | 13 | % Rp = Passband ripple 14 | 15 | % As = Stopband attenuation 16 | 17 | % 18 | 19 | K = 10^(Rp/20); 20 | 21 | d1 = (K-1)/(K+1); 22 | 23 | d2 = (1+d1)*(10^(-As/20)); 24 | 25 | -------------------------------------------------------------------------------- /PWS_DSP/delta2db.m: -------------------------------------------------------------------------------- 1 | function [Rp,As] = delta2db(delta1,delta2) 2 | 3 | % Conversion from Absolute delta specs to Relative dB specs 4 | 5 | % --------------------------------------------------------- 6 | 7 | % [Rp,As] = delta2db(delta1,delta2) 8 | 9 | % Rp = Passband ripple 10 | 11 | % As = Stopband attenuation 12 | 13 | % d1 = Passband tolerance 14 | 15 | % d2 = Stopband tolerance 16 | 17 | % 18 | 19 | Rp = -20*log10((1-delta1)/(1+delta1)); 20 | 21 | As = -20*log10(delta2/(1+delta1)); 22 | 23 | -------------------------------------------------------------------------------- /PWS_DSP/dfs.m: -------------------------------------------------------------------------------- 1 | function [Xk] = dfs(xn,N) 2 | 3 | % Computes Discrete Fourier Series Coefficients 4 | 5 | % --------------------------------------------- 6 | 7 | % [Xk] = dfs(xn,N) 8 | 9 | % Xk = DFS coeff. array over 0 <= k <= N-1 10 | 11 | % xn = One period of periodic signal over 0 <= n <= N-1 12 | 13 | % N = Fundamental period of xn 14 | 15 | % 16 | 17 | n = [0:1:N-1]; % row vector for n 18 | 19 | k = [0:1:N-1]; % row vecor for k 20 | 21 | WN = exp(-j*2*pi/N); % Wn factor 22 | 23 | nk = n'*k; % creates a N by N matrix of nk values 24 | 25 | WNnk = WN .^ nk; % DFS matrix 26 | 27 | Xk = xn * WNnk; % row vector for DFS coefficients 28 | 29 | -------------------------------------------------------------------------------- /PWS_DSP/dft.m: -------------------------------------------------------------------------------- 1 | function [Xk] = dft(xn,N) 2 | 3 | % Computes Discrete Fourier Transform 4 | 5 | % ----------------------------------- 6 | 7 | % [Xk] = dft(xn,N) 8 | 9 | % Xk = DFT coeff. array over 0 <= k <= N-1 10 | 11 | % xn = N-point finite-duration sequence 12 | 13 | % N = Length of DFT 14 | 15 | % 16 | 17 | n = [0:1:N-1]; % row vector for n 18 | 19 | k = [0:1:N-1]; % row vecor for k 20 | 21 | WN = exp(-j*2*pi/N); % Wn factor 22 | 23 | nk = n'*k; % creates a N by N matrix of nk values 24 | 25 | WNnk = WN .^ nk; % DFT matrix 26 | 27 | Xk = xn * WNnk; % row vector for DFT coefficients 28 | 29 | -------------------------------------------------------------------------------- /PWS_DSP/dir2cas.m: -------------------------------------------------------------------------------- 1 | function [b0,B,A] = dir2cas(b,a); 2 | 3 | % DIRECT-form to CASCADE-form conversion (cplxpair version) 4 | 5 | % --------------------------------------------------------- 6 | 7 | % [b0,B,A] = dir2cas(b,a) 8 | 9 | % b0 = gain coefficient 10 | 11 | % B = K by 3 matrix of real coefficients containing bk's 12 | 13 | % A = K by 3 matrix of real coefficients containing ak's 14 | 15 | % b = numerator polynomial coefficients of DIRECT form 16 | 17 | % a = denominator polynomial coefficients of DIRECT form 18 | 19 | 20 | 21 | % compute gain coefficient b0 22 | 23 | b0 = b(1); b = b/b0; 24 | 25 | a0 = a(1); a = a/a0; 26 | 27 | b0 = b0/a0; 28 | 29 | % 30 | 31 | M = length(b); N = length(a); 32 | 33 | if N > M 34 | 35 | b = [b zeros(1,N-M)]; 36 | 37 | elseif M > N 38 | 39 | a = [a zeros(1,M-N)]; N = M; 40 | 41 | else 42 | 43 | NM = 0; 44 | 45 | end 46 | 47 | % 48 | 49 | K = floor(N/2); B = zeros(K,3); A = zeros(K,3); 50 | 51 | if K*2 == N; 52 | 53 | b = [b 0]; 54 | 55 | a = [a 0]; 56 | 57 | end 58 | 59 | % 60 | 61 | broots = cplxpair(roots(b)); 62 | 63 | aroots = cplxpair(roots(a)); 64 | 65 | for i=1:2:2*K 66 | 67 | Brow = broots(i:1:i+1,:); 68 | 69 | Brow = real(poly(Brow)); 70 | 71 | B(fix((i+1)/2),:) = Brow; 72 | 73 | Arow = aroots(i:1:i+1,:); 74 | 75 | Arow = real(poly(Arow)); 76 | 77 | A(fix((i+1)/2),:) = Arow; 78 | 79 | end 80 | 81 | -------------------------------------------------------------------------------- /PWS_DSP/dir2fs.m: -------------------------------------------------------------------------------- 1 | function [C,B,A] = dir2fs(h) 2 | 3 | % Direct form to Frequency Sampling form conversion 4 | 5 | % ------------------------------------------------- 6 | 7 | % [C,B,A] = dir2fs(h) 8 | 9 | % C = Row vector containing gains for parallel sections 10 | 11 | % B = Matrix containing numerator coefficients arranged in rows 12 | 13 | % A = Matrix containing denominator coefficients arranged in rows 14 | 15 | % h = impulse response vector of an FIR filter 16 | 17 | % 18 | 19 | M = length(h); 20 | 21 | H = fft(h,M); 22 | 23 | magH = abs(H); phaH = angle(H)'; 24 | 25 | % check even or odd M 26 | 27 | if (M == 2*floor(M/2)) 28 | 29 | L = M/2-1; % M is even 30 | 31 | A1 = [1,-1,0;1,1,0]; 32 | 33 | C1 = [real(H(1)),real(H(L+2))]; 34 | 35 | else 36 | 37 | L = (M-1)/2; % M is odd 38 | 39 | A1 = [1,-1,0]; 40 | 41 | C1 = [real(H(1))]; 42 | 43 | end 44 | 45 | k = [1:L]'; 46 | 47 | % initialize B and A arrays 48 | 49 | B = zeros(L,2); A = ones(L,3); 50 | 51 | % compute denominator coefficients 52 | 53 | A(1:L,2) = -2*cos(2*pi*k/M); A = [A;A1]; 54 | 55 | % compute numerator coefficients 56 | 57 | B(1:L,1) = cos(phaH(2:L+1)); 58 | 59 | B(1:L,2) = -cos(phaH(2:L+1)-(2*pi*k/M)); 60 | 61 | % compute gain coefficients 62 | 63 | C = [2*magH(2:L+1),C1]'; 64 | 65 | -------------------------------------------------------------------------------- /PWS_DSP/dir2ladr.m: -------------------------------------------------------------------------------- 1 | function [K,C] = dir2ladr(b,a) 2 | 3 | % IIR Direct form to pole-zero Lattice/Ladder form Conversion 4 | 5 | % ----------------------------------------------------------- 6 | 7 | % [K,C] = dir2ladr(b,a) 8 | 9 | % K = Lattice coefficients (reflection coefficients), [K1,...,KN] 10 | 11 | % C = Ladder Coefficients, [C0,...,CN] 12 | 13 | % b = Numerator polynomial coefficients (deg <= Num deg) 14 | 15 | % a = Denominator polynomial coefficients 16 | 17 | % 18 | 19 | a1 = a(1); a = a/a1; b = b/a1; 20 | 21 | M = length(b); N = length(a); 22 | 23 | if M > N 24 | 25 | error(' *** length of b must be <= length of a ***') 26 | 27 | end 28 | 29 | b = [b, zeros(1,N-M)]; K = zeros(1,N-1); 30 | 31 | A = zeros(N-1,N-1); C = b; 32 | 33 | for m = N-1:-1:1 34 | 35 | A(m,1:m) = -a(2:m+1)*C(m+1); 36 | 37 | K(m) = a(m+1); 38 | 39 | J = fliplr(a); 40 | 41 | a = (a-K(m)*J)/(1-K(m)*K(m)); 42 | 43 | a = a(1:m); 44 | 45 | C(m) = b(m) + sum(diag(A(m:N-1,1:N-m))); 46 | 47 | end 48 | 49 | -------------------------------------------------------------------------------- /PWS_DSP/dir2latc.m: -------------------------------------------------------------------------------- 1 | function [K] = dir2latc(b) 2 | 3 | % FIR Direct form to All-Zero Lattice form Conversion 4 | 5 | % --------------------------------------------------- 6 | 7 | % [K] = dir2latc(b) 8 | 9 | % K = Lattice filter coefficients (reflection coefficients) 10 | 11 | % b = FIR direct form coefficients (impulse response) 12 | 13 | % 14 | 15 | M = length(b); 16 | 17 | K = zeros(1,M); 18 | 19 | b1 = b(1); 20 | 21 | if b1 == 0 22 | 23 | error('b(1) is equal to zero') 24 | 25 | end 26 | 27 | K(1) = b1; A = b/b1; 28 | 29 | for m=M:-1:2 30 | 31 | K(m) = A(m); 32 | 33 | J = fliplr(A); 34 | 35 | A = (A-K(m)*J)/(1-K(m)*K(m)); 36 | 37 | A = A(1:m-1); 38 | 39 | end 40 | 41 | -------------------------------------------------------------------------------- /PWS_DSP/dir2par.m: -------------------------------------------------------------------------------- 1 | function [C,B,A] = dir2par(b,a); 2 | 3 | % DIRECT-form to PARALLEL-form conversion 4 | 5 | % -------------------------------------- 6 | 7 | % [C,B,A] = dir2par(b,a) 8 | 9 | % C = Polynomial part when length(b) >= length(a) 10 | 11 | % B = K by 2 matrix of real coefficients containing bk's 12 | 13 | % A = K by 3 matrix of real coefficients containing ak's 14 | 15 | % b = numerator polynomial coefficients of DIRECT form 16 | 17 | % a = denominator polynomial coefficients of DIRECT form 18 | 19 | % 20 | 21 | M = length(b); N = length(a); 22 | 23 | 24 | 25 | [r1,p1,C] = residuez(b,a); 26 | 27 | p = cplxpair(p1,10000000*eps); 28 | 29 | I = cplxcomp(p1,p); 30 | 31 | r = r1(I); 32 | 33 | 34 | 35 | K = floor(N/2); B = zeros(K,2); A = zeros(K,3); 36 | 37 | if K*2 == N; %N even, order of A(z) odd, one factor is first order 38 | 39 | for i=1:2:N-2 40 | 41 | Brow = r(i:1:i+1,:); 42 | 43 | Arow = p(i:1:i+1,:); 44 | 45 | [Brow,Arow] = residuez(Brow,Arow,[]); 46 | 47 | B(fix((i+1)/2),:) = real(Brow'); 48 | 49 | A(fix((i+1)/2),:) = real(Arow'); 50 | 51 | end 52 | 53 | [Brow,Arow] = residuez(r(N-1),p(N-1),[]); 54 | 55 | B(K,:) = [real(Brow') 0]; A(K,:) = [real(Arow') 0]; 56 | 57 | else 58 | 59 | for i=1:2:N-1 60 | 61 | Brow = r(i:1:i+1,:); 62 | 63 | Arow = p(i:1:i+1,:); 64 | 65 | [Brow,Arow] = residuez(Brow,Arow,[]); 66 | 67 | B(fix((i+1)/2),:) = real(Brow'); 68 | 69 | A(fix((i+1)/2),:) = real(Arow'); 70 | 71 | end 72 | 73 | end 74 | 75 | -------------------------------------------------------------------------------- /PWS_DSP/evenodd.m: -------------------------------------------------------------------------------- 1 | function [xe, xo, m] = evenodd(x,n) 2 | 3 | % Real signal decomposition into even and odd parts 4 | 5 | % ------------------------------------------------- 6 | 7 | % [xe, xo, m] = evenodd(x,n) 8 | 9 | % 10 | 11 | if any(imag(x) ~= 0) 12 | 13 | error('x is not a real sequence') 14 | 15 | end 16 | 17 | m = -fliplr(n); 18 | 19 | m1 = min([m,n]); m2 = max([m,n]); m = m1:m2; 20 | 21 | nm = n(1)-m(1); n1 = 1:length(n); 22 | 23 | x1 = zeros(1,length(m)); 24 | 25 | x1(n1+nm) = x; x = x1; 26 | 27 | xe = 0.5*(x + fliplr(x)); 28 | 29 | xo = 0.5*(x - fliplr(x)); 30 | 31 | -------------------------------------------------------------------------------- /PWS_DSP/freqs_m.m: -------------------------------------------------------------------------------- 1 | function [db,mag,pha,w] = freqs_m(b,a,wmax); 2 | 3 | % Computation of s-domain frequency response: Modified version 4 | 5 | % ------------------------------------------------------------ 6 | 7 | % [db,mag,pha,w] = freqs_m(b,a,wmax); 8 | 9 | % db = Relative magnitude in db over [0 to wmax] 10 | 11 | % mag = Absolute magnitude over [0 to wmax] 12 | 13 | % pha = Phase response in radians over [0 to wmax] 14 | 15 | % w = array of 500 frequency samples between [0 to wmax] 16 | 17 | % b = Numerator polynomial coefficents of Ha(s) 18 | 19 | % a = Denominator polynomial coefficents of Ha(s) 20 | 21 | % wmax = Maximum frequency in rad/sec over which response is desired 22 | 23 | % 24 | 25 | w = [0:1:500]*wmax/500; 26 | 27 | H = freqs(b,a,w); 28 | 29 | mag = abs(H); 30 | 31 | db = 20*log10((mag+eps)/max(mag)); 32 | 33 | pha = angle(H); 34 | 35 | -------------------------------------------------------------------------------- /PWS_DSP/freqz_m.m: -------------------------------------------------------------------------------- 1 | function [db,mag,pha,grd,w] = freqz_m(b,a); 2 | 3 | % Modified version of freqz subroutine 4 | 5 | % ------------------------------------ 6 | 7 | % [db,mag,pha,grd,w] = freqz_m(b,a); 8 | 9 | % db = Relative magnitude in dB computed over 0 to pi radians 10 | 11 | % mag = absolute magnitude computed over 0 to pi radians 12 | 13 | % pha = Phase response in radians over 0 to pi radians 14 | 15 | % grd = Group delay over 0 to pi radians 16 | 17 | % w = 501 frequency samples between 0 to pi radians 18 | 19 | % b = numerator polynomial of H(z) (for FIR: b=h) 20 | 21 | % a = denominator polynomial of H(z) (for FIR: a=[1]) 22 | 23 | % 24 | 25 | [H,w] = freqz(b,a,1000,'whole'); 26 | 27 | H = (H(1:1:501))'; w = (w(1:1:501))'; 28 | 29 | mag = abs(H); 30 | 31 | db = 20*log10((mag+eps)/max(mag)); 32 | 33 | pha = angle(H); 34 | 35 | % pha = unwrap(angle(H)); 36 | 37 | grd = grpdelay(b,a,w); 38 | 39 | % grd = diff(pha); 40 | 41 | % grd = [grd(1) grd]; 42 | 43 | % grd = [0 grd(1:1:500); grd; grd(2:1:501) 0]; 44 | 45 | % grd = median(grd)*500/pi; 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /PWS_DSP/hr_type1.m: -------------------------------------------------------------------------------- 1 | function [Hr,w,a,L] = Hr_Type1(h); 2 | 3 | % Computes Amplitude response Hr(w) of a Type-1 LP FIR filter 4 | 5 | % ----------------------------------------------------------- 6 | 7 | % [Hr,w,a,L] = Hr_Type1(h) 8 | 9 | % Hr = Amplitude Response 10 | 11 | % w = 500 frequencies between [0 pi] over which Hr is computed 12 | 13 | % a = Type-1 LP filter coefficients 14 | 15 | % L = Order of Hr 16 | 17 | % h = Type-1 LP filter impulse response 18 | 19 | % 20 | 21 | M = length(h); 22 | 23 | L = (M-1)/2; 24 | 25 | a = [h(L+1) 2*h(L:-1:1)]; % 1x(L+1) row vector 26 | 27 | n = [0:1:L]; % (L+1)x1 column vector 28 | 29 | w = [0:1:500]'*pi/500; 30 | 31 | Hr = cos(w*n)*a'; -------------------------------------------------------------------------------- /PWS_DSP/hr_type2.m: -------------------------------------------------------------------------------- 1 | function [Hr,w,b,L] = Hr_Type2(h); 2 | 3 | % Computes Amplitude response of Type-2 LP FIR filter 4 | 5 | % --------------------------------------------------- 6 | 7 | % [Hr,w,b,L] = Hr_Type2(h) 8 | 9 | % Hr = Amplitude Response 10 | 11 | % w = frequencies between [0 pi] over which Hr is computed 12 | 13 | % b = Type-2 LP filter coefficients 14 | 15 | % L = Order of Hr 16 | 17 | % h = Type-2 LP impulse response 18 | 19 | % 20 | 21 | M = length(h); 22 | 23 | L = M/2; 24 | 25 | b = 2*[h(L:-1:1)]; 26 | 27 | n = [1:1:L]; n = n-0.5; 28 | 29 | w = [0:1:500]'*pi/500; 30 | 31 | Hr = cos(w*n)*b'; -------------------------------------------------------------------------------- /PWS_DSP/hr_type3.m: -------------------------------------------------------------------------------- 1 | function [Hr,w,c,L] = Hr_Type3(h); 2 | 3 | % Computes Amplitude response Hr(w) of a Type-3 LP FIR filter 4 | 5 | % ----------------------------------------------------------- 6 | 7 | % [Hr,w,c,L] = Hr_Type3(h) 8 | 9 | % Hr = Amplitude Response 10 | 11 | % w = frequencies between [0 pi] over which Hr is computed 12 | 13 | % c = Type-3 LP filter coefficients 14 | 15 | % L = Order of Hr 16 | 17 | % h = Type-3 LP impulse response 18 | 19 | % 20 | 21 | M = length(h); 22 | 23 | L = (M-1)/2; 24 | 25 | c = [2*h(L+1:-1:1)]; 26 | 27 | n = [0:1:L]; 28 | 29 | w = [0:1:500]'*pi/500; 30 | 31 | Hr = sin(w*n)*c'; 32 | 33 | -------------------------------------------------------------------------------- /PWS_DSP/hr_type4.m: -------------------------------------------------------------------------------- 1 | function [Hr,w,d,L] = Hr_Type4(h); 2 | 3 | % Computes Amplitude response of Type-4 LP FIR filter 4 | 5 | % --------------------------------------------------- 6 | 7 | % [Hr,w,d,L] = Hr_Type4(h) 8 | 9 | % Hr = Amplitude Response 10 | 11 | % w = frequencies between [0 pi] over which Hr is computed 12 | 13 | % d = Type-4 LP filter coefficients 14 | 15 | % L = Order of d 16 | 17 | % h = Type-4 LP impulse response 18 | 19 | % 20 | 21 | M = length(h); 22 | 23 | L = M/2; 24 | 25 | d = 2*[h(L:-1:1)]; 26 | 27 | n = [1:1:L]; n = n-0.5; 28 | 29 | w = [0:1:500]'*pi/500; 30 | 31 | Hr = sin(w*n)*d'; 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /PWS_DSP/hsolpsav.m: -------------------------------------------------------------------------------- 1 | function [y] = hsolpsav(x,h,N) 2 | 3 | % High-speed Overlap-Save method of block convolutions using FFT 4 | 5 | % -------------------------------------------------------------- 6 | 7 | % [y] = hsolpsav(x,h,N) 8 | 9 | % y = output sequence 10 | 11 | % x = input sequence 12 | 13 | % h = impulse response 14 | 15 | % N = block length (must be a power of two) 16 | 17 | % 18 | 19 | N = 2^(ceil(log10(N)/log10(2)); 20 | 21 | Lenx = length(x); M = length(h); 22 | 23 | M1 = M-1; L = N-M1; 24 | 25 | h = fft(h,N); 26 | 27 | % 28 | 29 | x = [zeros(1,M1), x, zeros(1,N-1)]; 30 | 31 | K = floor((Lenx+M1-1)/(L)); % # of blocks 32 | 33 | Y = zeros(K+1,N); 34 | 35 | for k=0:K 36 | 37 | xk = fft(x(k*L+1:k*L+N)); 38 | 39 | Y(k+1,:) = real(ifft(xk.*h)); 40 | 41 | end 42 | 43 | Y = Y(:,M:N)'; y = (Y(:))'; -------------------------------------------------------------------------------- /PWS_DSP/ideal_lp.m: -------------------------------------------------------------------------------- 1 | function hd = ideal_lp(wc,M); 2 | 3 | % Ideal LowPass filter computation 4 | 5 | % -------------------------------- 6 | 7 | % [hd] = ideal_lp(wc,M) 8 | 9 | % hd = ideal impulse response between 0 to M-1 10 | 11 | % wc = cutoff frequency in radians 12 | 13 | % M = length of the ideal filter 14 | 15 | % 16 | 17 | alpha = (M-1)/2; 18 | 19 | n = [0:1:(M-1)]; 20 | 21 | m = n - alpha + eps; 22 | 23 | hd = sin(wc*m) ./ (pi*m); 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /PWS_DSP/idfs.m: -------------------------------------------------------------------------------- 1 | function [xn] = idfs(Xk,N) 2 | 3 | % Computes Inverse Discrete Fourier Series 4 | 5 | % ---------------------------------------- 6 | 7 | % [xn] = idfs(Xk,N) 8 | 9 | % xn = One period of periodic signal over 0 <= n <= N-1 10 | 11 | % Xk = DFS coeff. array over 0 <= k <= N-1 12 | 13 | % N = Fundamental period of Xk 14 | 15 | % 16 | 17 | n = [0:1:N-1]; % row vector for n 18 | 19 | k = [0:1:N-1]; % row vecor for k 20 | 21 | WN = exp(-j*2*pi/N); % Wn factor 22 | 23 | nk = n'*k; % creates a N by N matrix of nk values 24 | 25 | WNnk = WN .^ (-nk); % IDFS matrix 26 | 27 | xn = (Xk * WNnk)/N; % row vector for IDFS values 28 | 29 | -------------------------------------------------------------------------------- /PWS_DSP/idft.m: -------------------------------------------------------------------------------- 1 | function [xn] = idft(Xk,N) 2 | 3 | % Computes Inverse Discrete Transform 4 | 5 | % ----------------------------------- 6 | 7 | % [xn] = idft(Xk,N) 8 | 9 | % xn = N-point sequence over 0 <= n <= N-1 10 | 11 | % Xk = DFT coeff. array over 0 <= k <= N-1 12 | 13 | % N = length of DFT 14 | 15 | % 16 | 17 | n = [0:1:N-1]; % row vector for n 18 | 19 | k = [0:1:N-1]; % row vecor for k 20 | 21 | WN = exp(-j*2*pi/N); % Wn factor 22 | 23 | nk = n'*k; % creates a N by N matrix of nk values 24 | 25 | WNnk = WN .^ (-nk); % IDFT matrix 26 | 27 | xn = (Xk * WNnk)/N; % row vector for IDFT values 28 | 29 | -------------------------------------------------------------------------------- /PWS_DSP/imp_invr.m: -------------------------------------------------------------------------------- 1 | function [b,a] = imp_invr(c,d,T) 2 | 3 | % Impulse Invariance Transformation from Analog to Digital Filter 4 | 5 | % --------------------------------------------------------------- 6 | 7 | % [b,a] = imp_invr(c,d,T) 8 | 9 | % b = Numerator polynomial in z^(-1) of the digital filter 10 | 11 | % a = Denominator polynomial in z^(-1) of the digital filter 12 | 13 | % c = Numerator polynomial in s of the analog filter 14 | 15 | % d = Denominator polynomial in s of the analog filter 16 | 17 | % T = Sampling (transformation) parameter 18 | 19 | % 20 | 21 | [R,p,k] = residue(c,d); 22 | 23 | p = exp(p*T); 24 | 25 | [b,a] = residuez(R,p,k); 26 | 27 | b = real(b'); a = real(a'); -------------------------------------------------------------------------------- /PWS_DSP/impseq.m: -------------------------------------------------------------------------------- 1 | function [x,n] = impseq(n0,n1,n2) 2 | 3 | % Generates x(n) = delta(n-n0); n1 <= n0 <= n2 4 | 5 | % ---------------------------------------------- 6 | 7 | % [x,n] = impseq(n0,n1,n2) 8 | 9 | % 10 | 11 | if ((n0 < n1) | (n0 > n2) | (n1 > n2)) 12 | 13 | error('arguments must satisfy n1 <= n0 <= n2') 14 | 15 | end 16 | 17 | n = [n1:n2]; 18 | 19 | %x = [zeros(1,(n0-n1)), 1, zeros(1,(n2-n0))]; 20 | 21 | x = [(n-n0) == 0]; 22 | 23 | -------------------------------------------------------------------------------- /PWS_DSP/ladr2dir.m: -------------------------------------------------------------------------------- 1 | function [b,a] = ladr2dir(K,C) 2 | 3 | % Lattice/Ladder form to IIR Direct form Conversion 4 | 5 | % ------------------------------------------------- 6 | 7 | % [b,a] = ladr2dir(K,C) 8 | 9 | % b = numerator polynomial coefficients 10 | 11 | % a = denominator polymonial coefficients 12 | 13 | % K = Lattice coefficients (reflection coefficients) 14 | 15 | % C = Ladder coefficients 16 | 17 | % 18 | 19 | N = length(K); M = length(C); 20 | 21 | C = [C, zeros(1,N-M+1)]; 22 | 23 | J = 1; a = 1; A = zeros(N,N); 24 | 25 | for m=1:1:N 26 | 27 | a = [a,0]+conv([0,K(m)],J); 28 | 29 | A(m,1:m) = -a(2:m+1); 30 | 31 | J = fliplr(a); 32 | 33 | end 34 | 35 | b(N+1) = C(N+1); 36 | 37 | for m = N:-1:1 38 | 39 | A(m,1:m) = A(m,1:m)*C(m+1); 40 | 41 | b(m) = C(m) - sum(diag(A(m:N,1:N-m+1))); 42 | 43 | end 44 | 45 | -------------------------------------------------------------------------------- /PWS_DSP/ladrfilt.m: -------------------------------------------------------------------------------- 1 | function [y] = ladrfilt(K,C,x) 2 | 3 | % LATTICE/LADDER form realization of IIR filters 4 | 5 | % ---------------------------------------------- 6 | 7 | % [y] = ladrfilt(K,C,x) 8 | 9 | % y = output sequence 10 | 11 | % K = LATTICE (reflection) coefficient array 12 | 13 | % C = LADDER coefficient array 14 | 15 | % x = input sequence 16 | 17 | % 18 | 19 | Nx = length(x); y = zeros(1,Nx); 20 | 21 | N = length(C); f = zeros(N,Nx); g = zeros(N,Nx+1); 22 | 23 | f(N,:) = x; 24 | 25 | for n = 2:1:Nx+1 26 | 27 | for m = N:-1:2 28 | 29 | f(m-1,n-1) = f(m,n-1) - K(m-1)*g(m-1,n-1); 30 | 31 | g(m,n) = K(m-1)*f(m-1,n-1) + g(m-1,n-1); 32 | 33 | end 34 | 35 | g(1,n) = f(1,n-1); 36 | 37 | end 38 | 39 | y = C*g(:,2:Nx+1); 40 | 41 | -------------------------------------------------------------------------------- /PWS_DSP/latc2dir.m: -------------------------------------------------------------------------------- 1 | function [b] = latc2dir(K) 2 | 3 | % All-Zero Lattice form to FIR Direct form Conversion 4 | 5 | % --------------------------------------------------- 6 | 7 | % [b] = latc2dir(K) 8 | 9 | % b = FIR direct form coefficients (impulse response) 10 | 11 | % K = Lattice filter coefficients (reflection coefficients) 12 | 13 | % 14 | 15 | M = length(K); 16 | 17 | J = 1; A = 1; 18 | 19 | for m=2:1:M 20 | 21 | A = [A,0]+conv([0,K(m)],J); 22 | 23 | J = fliplr(A); 24 | 25 | end 26 | 27 | b=A*K(1); 28 | 29 | -------------------------------------------------------------------------------- /PWS_DSP/latcfilt.m: -------------------------------------------------------------------------------- 1 | function [y] = latcfilt(K,x) 2 | 3 | % LATTICE form realization of FIR filters 4 | 5 | % --------------------------------------- 6 | 7 | % y = latcfilt(K,x) 8 | 9 | % y = output sequence 10 | 11 | % K = LATTICE filter (reflection) coefficient array 12 | 13 | % x = input sequence 14 | 15 | % 16 | 17 | Nx = length(x)-1; 18 | 19 | x = K(1)*x; 20 | 21 | M = length(K)-1; K = K(2:M+1); 22 | 23 | fg = [x; [0 x(1:Nx)]]; 24 | 25 | for m = 1:M 26 | 27 | fg = [1,K(m);K(m),1]*fg; 28 | 29 | fg(2,:) = [0 fg(2,1:Nx)]; 30 | 31 | end 32 | 33 | y = fg(1,:); 34 | 35 | -------------------------------------------------------------------------------- /PWS_DSP/lms.m: -------------------------------------------------------------------------------- 1 | function [h,y] = lms(x,d,delta,N) 2 | 3 | % LMS Algorithm for Coefficient Adjustment 4 | 5 | % ---------------------------------------- 6 | 7 | % [h,y] = lms(x,d,delta,N) 8 | 9 | % h = estimated FIR filter 10 | 11 | % y = output array y(n) 12 | 13 | % x = input array x(n) 14 | 15 | % d = desired array d(n), length must be same as x 16 | 17 | % delta = step size 18 | 19 | % N = length of the FIR filter 20 | 21 | % 22 | 23 | M = length(x); y = zeros(1,M); 24 | 25 | h = zeros(1,N); 26 | 27 | for n = N:M 28 | 29 | x1 = x(n:-1:n-N+1); 30 | 31 | y = h * x1'; 32 | 33 | e = d(n) - y; 34 | 35 | h = h + delta*e*x1; 36 | 37 | end 38 | 39 | -------------------------------------------------------------------------------- /PWS_DSP/mod.m: -------------------------------------------------------------------------------- 1 | function m = mod(n,N) 2 | 3 | % Computes m = (n mod N) index 4 | 5 | % ---------------------------- 6 | 7 | % m = mod(n,N) 8 | 9 | m = rem(n,N); 10 | 11 | m = m+N; 12 | 13 | m = rem(m,N); 14 | 15 | -------------------------------------------------------------------------------- /PWS_DSP/mulaw_c.m: -------------------------------------------------------------------------------- 1 | function [y] = mulaw_c(s,mu) 2 | 3 | % mu-law compressor 4 | 5 | % ----------------- 6 | 7 | % [y] = mulaw_c(s,mu) 8 | 9 | % y = compressed output signal 10 | 11 | % s = zero-mean nomalized signal between -1 and 1 12 | 13 | % mu = parameter mu 14 | 15 | % 16 | 17 | if mu == 0 18 | 19 | y = s; 20 | 21 | else 22 | 23 | y = (log(1+mu*abs(s))/(log(1+mu))).*sign(s); 24 | 25 | end -------------------------------------------------------------------------------- /PWS_DSP/mulaw_e.m: -------------------------------------------------------------------------------- 1 | function [sq] = mulaw_e(yq,B,mu) 2 | 3 | % mu-law expander 4 | 5 | % --------------- 6 | 7 | % [sq] = mulaw_e(yq,B,mu) 8 | 9 | % sq = expanded quantized signal 10 | 11 | % yq = quantized input in integers: 0 <=yq <= 2^B-1 12 | 13 | % B = bits/sample 14 | 15 | % mu = compander parameter 16 | 17 | % 18 | 19 | swing = (2^B-1)/2; 20 | 21 | yq = ((yq-swing)/swing); 22 | 23 | if mu == 0 24 | 25 | sq = yq; 26 | 27 | else 28 | 29 | sq = (((1+mu).^(abs(yq))-1)/mu).*sign(yq); 30 | 31 | end 32 | 33 | -------------------------------------------------------------------------------- /PWS_DSP/ovrlpsav.m: -------------------------------------------------------------------------------- 1 | function [y] = ovrlpsav(x,h,N) 2 | 3 | % Overlap-Save method of block convolution 4 | 5 | % ---------------------------------------- 6 | 7 | % [y] = ovrlpsav(x,h,N) 8 | 9 | % y = output sequence 10 | 11 | % x = input sequence 12 | 13 | % h = impulse response 14 | 15 | % N = block length 16 | 17 | % 18 | 19 | Lenx = length(x); M = length(h); 20 | 21 | M1 = M-1; L = N-M1; 22 | 23 | h = [h zeros(1,N-M)]; 24 | 25 | % 26 | 27 | x = [zeros(1,M1), x, zeros(1,N-1)]; % preappend (M-1) zeros 28 | 29 | K = floor((Lenx+M1-1)/(L)); % # of blocks 30 | 31 | Y = zeros(K+1,N); 32 | 33 | % convolution with succesive blocks 34 | 35 | for k=0:K 36 | 37 | xk = x(k*L+1:k*L+N); 38 | 39 | Y(k+1,:) = circonvt(xk,h,N); 40 | 41 | end 42 | 43 | Y = Y(:,M:N)'; % discard the first (M-1) samples 44 | 45 | y = (Y(:))'; % assemble output -------------------------------------------------------------------------------- /PWS_DSP/par2dir.m: -------------------------------------------------------------------------------- 1 | function [b,a] = par2dir(C,B,A); 2 | 3 | % PARALLEL-to-DIRECT form conversion 4 | 5 | % ---------------------------------- 6 | 7 | % [b,a] = par2dir(C,B,A) 8 | 9 | % b = numerator polynomial coefficients of DIRECT form 10 | 11 | % a = denominator polynomial coefficients of DIRECT form 12 | 13 | % C = Polynomial part of PARALLEL form 14 | 15 | % B = K by 2 matrix of real coefficients containing bk's 16 | 17 | % A = K by 3 matrix of real coefficients containing ak's 18 | 19 | % 20 | 21 | [K,L] = size(A); R = []; P = []; 22 | 23 | 24 | 25 | for i=1:1:K 26 | 27 | [r,p,k]=residuez(B(i,:),A(i,:)); 28 | 29 | R = [R;r]; P = [P;p]; 30 | 31 | end 32 | 33 | [b,a] = residuez(R,P,C); 34 | 35 | b = b(:)'; a = a(:)'; -------------------------------------------------------------------------------- /PWS_DSP/parfiltr.m: -------------------------------------------------------------------------------- 1 | function y = parfiltr(C,B,A,x); 2 | 3 | % PARALLEL form realization of IIR filters 4 | 5 | % ---------------------------------------- 6 | 7 | % [y] = parfiltr(C,B,A,x); 8 | 9 | % y = output sequence 10 | 11 | % C = polynomial (FIR) part when M >= N 12 | 13 | % B = K by 2 matrix of real coefficients containing bk's 14 | 15 | % A = K by 3 matrix of real coefficients containing ak's 16 | 17 | % x = input sequence 18 | 19 | % 20 | 21 | [K,L] = size(B); 22 | 23 | N = length(x); 24 | 25 | w = zeros(K+1,N); 26 | 27 | w(1,:) = filter(C,1,x); 28 | 29 | for i = 1:1:K 30 | 31 | w(i+1,:) = filter(B(i,:),A(i,:),x); 32 | 33 | end 34 | 35 | y = sum(w); 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /PWS_DSP/pfe2rfz.m: -------------------------------------------------------------------------------- 1 | function [b,a] = pfe2rfz(R,P,C) 2 | 3 | % Rational function from Partial Fraction Expansions in z-Domain 4 | 5 | % -------------------------------------------------------------- 6 | 7 | % [b,a] = pfe2rfz(R,P,C) 8 | 9 | % b = numerator polynomial coefficients [b0,b1,...,bM] of rational function, 10 | 11 | % a = denominator polynomial coefficients [a0,a1,...,aN] of rational function, 12 | 13 | % R = row vector containing residues evaluated at poles in p vector, 14 | 15 | % p = row vector containing poles of the rational (roots of a), 16 | 17 | % C = (M-N) length (or null) vector containing poly coeffcients. 18 | 19 | % 20 | 21 | R = R'; p = p'; 22 | 23 | [b1,a1]=residue(R,P,[]); 24 | 25 | b1=fliplr(b1); a1=fliplr(a1); 26 | 27 | [r,p,k]=residue(b1,a1); 28 | 29 | [b,a]=residue(r,p,fliplr(C)); 30 | 31 | b=fliplr(b); a=fliplr(a); 32 | 33 | b=real(b); a=real(a); 34 | 35 | b=b/a(1); a=a/a(1); 36 | 37 | -------------------------------------------------------------------------------- /PWS_DSP/quantize.m: -------------------------------------------------------------------------------- 1 | function [yq] = quantize(y,B) 2 | 3 | % Quantize signal to B bits 4 | 5 | % ------------------------- 6 | 7 | % [yq] = quantize(y,B) 8 | 9 | % yq = quantized signal in integers: 0 <= yq <= 2^B-1 10 | 11 | % y = input signal 12 | 13 | % B = bits/sample 14 | 15 | % 16 | 17 | swing = (2^B-1)/2; 18 | 19 | yq = round(y*swing+swing); -------------------------------------------------------------------------------- /PWS_DSP/rf2pfez.m: -------------------------------------------------------------------------------- 1 | function [R,p,C] = rf2pfez(b,a); 2 | 3 | % Partial Fraction Expansion from rational function in z-Domain 4 | 5 | % ------------------------------------------------------------- 6 | 7 | % [R,p,C] = rf2pfez(b,a) 8 | 9 | % R = row vector containing residues evaluated at poles in p vector, 10 | 11 | % p = row vector containing poles of the rational (roots of a), 12 | 13 | % C = (M-N) length (or null) vector containing poly coeffcients, 14 | 15 | % b = numerator polynomial coefficients [b0,b1,...,bM] of rational function, 16 | 17 | % a = denominator polynomial coefficients [a0,a1,...,aN] of rational function. 18 | 19 | % 20 | 21 | b = b/a(1); a = a/a(1); 22 | 23 | b = fliplr(b); a = fliplr(a); 24 | 25 | [R,p,C] = residue(b,a); 26 | 27 | C = fliplr(C); 28 | 29 | [b1,a1] = residue(R,p,[]); 30 | 31 | b1 = fliplr(b1); a1 = fliplr(a1); 32 | 33 | [R,p,k] = residue(b1,a1); 34 | 35 | R = R'; p = p'; -------------------------------------------------------------------------------- /PWS_DSP/sdir2cas.m: -------------------------------------------------------------------------------- 1 | function [C,B,A] = sdir2cas(b,a); 2 | 3 | % DIRECT-form to CASCADE-form conversion in s-plane 4 | 5 | % ------------------------------------------------- 6 | 7 | % [C,B,A] = sdir2cas(b,a) 8 | 9 | % C = gain coefficient 10 | 11 | % B = K by 3 matrix of real coefficients containing bk's 12 | 13 | % A = K by 3 matrix of real coefficients containing ak's 14 | 15 | % b = numerator polynomial coefficients of DIRECT form 16 | 17 | % a = denominator polynomial coefficients of DIRECT form 18 | 19 | % 20 | 21 | Na = length(a)-1; Nb = length(b)-1; 22 | 23 | 24 | 25 | % compute gain coefficient C 26 | 27 | b0 = b(1); b = b/b0; 28 | 29 | a0 = a(1); a = a/a0; 30 | 31 | C = b0/a0; 32 | 33 | % 34 | 35 | % Denominator second-order sections: 36 | 37 | p= cplxpair(roots(a)); K = floor(Na/2); 38 | 39 | if K*2 == Na % Computation when Na is even 40 | 41 | A = zeros(K,3); 42 | 43 | for n=1:2:Na 44 | 45 | Arow = p(n:1:n+1,:); 46 | 47 | Arow = poly(Arow); 48 | 49 | A(fix((n+1)/2),:) = real(Arow); 50 | 51 | end 52 | 53 | 54 | 55 | elseif Na == 1 % Computation when Na = 1 56 | 57 | A = [0 real(poly(p))]; 58 | 59 | 60 | 61 | else % Computation when Na is odd and > 1 62 | 63 | A = zeros(K+1,3); 64 | 65 | for n=1:2:2*K 66 | 67 | Arow = p(n:1:n+1,:); 68 | 69 | Arow = poly(Arow); 70 | 71 | A(fix((n+1)/2),:) = real(Arow); 72 | 73 | end 74 | 75 | A(K+1,:) = [0 real(poly(p(Na)))]; 76 | 77 | end 78 | 79 | 80 | 81 | % Numerator second-order sections: 82 | 83 | z = cplxpair(roots(b)); K = floor(Nb/2); 84 | 85 | if Nb == 0 % Computation when Nb = 0 86 | 87 | B = [0 0 poly(z)]; 88 | 89 | 90 | 91 | elseif K*2 == Nb % Computation when Nb is even 92 | 93 | B = zeros(K,3); 94 | 95 | for n=1:2:Nb 96 | 97 | Brow = z(n:1:n+1,:); 98 | 99 | Brow = poly(Brow); 100 | 101 | B(fix((n+1)/2),:) = real(Brow); 102 | 103 | end 104 | 105 | 106 | 107 | elseif Nb == 1 % Computation when Nb = 1 108 | 109 | B = [0 real(poly(z))]; 110 | 111 | 112 | 113 | else % Computation when Nb is odd and > 1 114 | 115 | B = zeros(K+1,3); 116 | 117 | for n=1:2:2*K 118 | 119 | Brow = z(n:1:n+1,:); 120 | 121 | Brow = poly(Brow); 122 | 123 | B(fix((n+1)/2),:) = real(Brow); 124 | 125 | end 126 | 127 | B(K+1,:) = [0 real(poly(z(Nb)))]; 128 | 129 | end 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /PWS_DSP/sigadd.m: -------------------------------------------------------------------------------- 1 | function [y,n] = sigadd(x1,n1,x2,n2) 2 | 3 | % implements y(n) = x1(n)+x2(n) 4 | 5 | % ----------------------------- 6 | 7 | % [y,n] = sigadd(x1,n1,x2,n2) 8 | 9 | % y = sum sequence over n, which includes n1 and n2 10 | 11 | % x1 = first sequence over n1 12 | 13 | % x2 = second sequence over n2 (n2 can be different from n1) 14 | 15 | % 16 | 17 | n = min(min(n1),min(n2)):max(max(n1),max(n2)); % duration of y(n) 18 | 19 | y1 = zeros(1,length(n)); y2 = y1; % initialization 20 | 21 | y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y 22 | 23 | y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y 24 | 25 | y = y1+y2; % sequence addition 26 | 27 | -------------------------------------------------------------------------------- /PWS_DSP/sigfold.m: -------------------------------------------------------------------------------- 1 | function [y,n] = sigfold(x,n) 2 | 3 | % implements y(n) = x(-n) 4 | 5 | % ----------------------- 6 | 7 | % [y,n] = sigfold(x,n) 8 | 9 | % 10 | 11 | y = fliplr(x); n = -fliplr(n); -------------------------------------------------------------------------------- /PWS_DSP/sigmult.m: -------------------------------------------------------------------------------- 1 | function [y,n] = sigmult(x1,n1,x2,n2) 2 | 3 | % implements y(n) = x1(n)*x2(n) 4 | 5 | % ----------------------------- 6 | 7 | % [y,n] = sigmult(x1,n1,x2,n2) 8 | 9 | % y = product sequence over n, which includes n1 and n2 10 | 11 | % x1 = first sequence over n1 12 | 13 | % x2 = second sequence over n2 (n2 can be different from n1) 14 | 15 | % 16 | 17 | n = min(min(n1),min(n2)):max(max(n1),max(n2)); % duration of y(n) 18 | 19 | y1 = zeros(1,length(n)); y2 = y1; % 20 | 21 | y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y 22 | 23 | y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y 24 | 25 | y = y1 .* y2; % sequence multiplication 26 | 27 | -------------------------------------------------------------------------------- /PWS_DSP/sigshift.m: -------------------------------------------------------------------------------- 1 | function [y,n] = sigshift(x,m,n0) 2 | 3 | % implements y(n) = x(n-n0) 4 | 5 | % ------------------------- 6 | 7 | % [y,n] = sigshift(x,m,n0) 8 | 9 | % 10 | 11 | n = m+n0; y = x; -------------------------------------------------------------------------------- /PWS_DSP/stepseq.m: -------------------------------------------------------------------------------- 1 | function [x,n] = stepseq(n0,n1,n2) 2 | 3 | % Generates x(n) = u(n-n0); n1 <= n,n0 <= n2 4 | 5 | % ------------------------------------------ 6 | 7 | % [x,n] = stepseq(n0,n1,n2) 8 | 9 | % 10 | 11 | if ((n0 < n1) | (n0 > n2) | (n1 > n2)) 12 | 13 | error('arguments must satisfy n1 <= n0 <= n2') 14 | 15 | end 16 | 17 | n = [n1:n2]; 18 | 19 | %x = [zeros(1,(n0-n1)), ones(1,(n2-n0+1))]; 20 | 21 | x = [(n-n0) >= 0]; 22 | 23 | -------------------------------------------------------------------------------- /PWS_DSP/u_buttap.m: -------------------------------------------------------------------------------- 1 | function [b,a] = u_buttap(N,Omegac); 2 | 3 | % Unnormalized Butterworth Analog Lowpass Filter Prototype 4 | 5 | % -------------------------------------------------------- 6 | 7 | % [b,a] = u_buttap(N,Omegac); 8 | 9 | % b = numerator polynomial coefficients of Ha(s) 10 | 11 | % a = denominator polynomial coefficients of Ha(s) 12 | 13 | % N = Order of the Butterworth Filter 14 | 15 | % Omegac = Cutoff frequency in radians/sec 16 | 17 | % 18 | 19 | [z,p,k] = buttap(N); 20 | 21 | p = p*Omegac; 22 | 23 | k = k*Omegac^N; 24 | 25 | B = real(poly(z)); 26 | 27 | b0 = k; 28 | 29 | b = k*B; 30 | 31 | a = real(poly(p)); -------------------------------------------------------------------------------- /PWS_DSP/u_chb1ap.m: -------------------------------------------------------------------------------- 1 | function [b,a] = u_chb1ap(N,Rp,Omegac); 2 | 3 | % Unnormalized Chebyshev-1 Analog Lowpass Filter Prototype 4 | 5 | % -------------------------------------------------------- 6 | 7 | % [b,a] = u_chb1ap(N,Rp,Omegac); 8 | 9 | % b = numerator polynomial coefficients 10 | 11 | % a = denominator polynomial coefficients 12 | 13 | % N = Order of the Elliptic Filter 14 | 15 | % Rp = Passband Ripple in dB; Rp > 0 16 | 17 | % Omegac = Cutoff frequency in radians/sec 18 | 19 | % 20 | 21 | [z,p,k] = cheb1ap(N,Rp); 22 | 23 | a = real(poly(p)); 24 | 25 | aNn = a(N+1); 26 | 27 | p = p*Omegac; 28 | 29 | a = real(poly(p)); 30 | 31 | aNu = a(N+1); 32 | 33 | k = k*aNu/aNn; 34 | 35 | b0 = k; 36 | 37 | B = real(poly(z)); 38 | 39 | b = k*B; -------------------------------------------------------------------------------- /PWS_DSP/u_chb2ap.m: -------------------------------------------------------------------------------- 1 | function [b,a] = u_chb2ap(N,As,Omegac); 2 | 3 | % Unnormalized Chebyshev-2 Analog Lowpass Filter Prototype 4 | 5 | % -------------------------------------------------------- 6 | 7 | % [b,a] = u_chb2ap(N,As,Omegac); 8 | 9 | % b = numerator polynomial coefficients 10 | 11 | % a = denominator polynomial coefficients 12 | 13 | % N = Order of the Elliptic Filter 14 | 15 | % As = Stopband Ripple in dB; As > 0 16 | 17 | % Omegac = Cutoff frequency in radians/sec 18 | 19 | % 20 | 21 | [z,p,k] = cheb2ap(N,As); 22 | 23 | a = real(poly(p)); 24 | 25 | aNn = a(N+1); 26 | 27 | p = p*Omegac; 28 | 29 | a = real(poly(p)); 30 | 31 | aNu = a(N+1); 32 | 33 | b = real(poly(z)); 34 | 35 | M = length(b); 36 | 37 | bNn = b(M); 38 | 39 | z = z*Omegac; 40 | 41 | b = real(poly(z)); 42 | 43 | bNu = b(M); 44 | 45 | k = k*(aNu*bNn)/(aNn*bNu); 46 | 47 | b0 = k; 48 | 49 | b = k*b; -------------------------------------------------------------------------------- /PWS_DSP/u_elipap.m: -------------------------------------------------------------------------------- 1 | function [b,a] = u_elipap(N,Rp,As,Omegac); 2 | 3 | % Unnormalized Elliptic Analog Lowpass Filter Prototype 4 | 5 | % ----------------------------------------------------- 6 | 7 | % [b,a] = u_elipap(N,Rp,As,Omegac); 8 | 9 | % b = numerator polynomial coefficients 10 | 11 | % a = denominator polynomial coefficients 12 | 13 | % N = Order of the Elliptic Filter 14 | 15 | % Rp = Passband Ripple in dB; Rp > 0 16 | 17 | % As = Stopband Attebuation in dB; As > 0 18 | 19 | % Omegac = Cutoff frequency in radians/sec 20 | 21 | % 22 | 23 | [z,p,k] = ellipap(N,Rp,As); 24 | 25 | a = real(poly(p)); 26 | 27 | aNn = a(N+1); 28 | 29 | p = p*Omegac; 30 | 31 | a = real(poly(p)); 32 | 33 | aNu = a(N+1); 34 | 35 | b = real(poly(z)); 36 | 37 | M = length(b); 38 | 39 | bNn = b(M); 40 | 41 | z = z*Omegac; 42 | 43 | b = real(poly(z)); 44 | 45 | bNu = b(M); 46 | 47 | k = k*(aNu*bNn)/(aNn*bNu); 48 | 49 | b0 = k; 50 | 51 | b = k*b; -------------------------------------------------------------------------------- /PWS_DSP/zmapping.m: -------------------------------------------------------------------------------- 1 | function [bz,az] = zmapping(bZ,aZ,Nz,Dz) 2 | 3 | % Frequency band Transformation from Z-domain to z-domain 4 | 5 | % ------------------------------------------------------- 6 | 7 | % [bz,az] = zmapping(bZ,aZ,Nz,Dz) 8 | 9 | % performs: 10 | 11 | % b(z) b(Z)| 12 | 13 | % ---- = ----| N(z) 14 | 15 | % a(z) a(Z)|@Z = ---- 16 | 17 | % D(z) 18 | 19 | % 20 | 21 | bzord = (length(bZ)-1)*(length(Nz)-1); 22 | 23 | azord = (length(aZ)-1)*(length(Dz)-1); 24 | 25 | 26 | 27 | bz = zeros(1,bzord+1); 28 | 29 | for k = 0:bzord 30 | 31 | pln = [1]; 32 | 33 | for l = 0:k-1 34 | 35 | pln = conv(pln,Nz); 36 | 37 | end 38 | 39 | pld = [1]; 40 | 41 | for l = 0:bzord-k-1 42 | 43 | pld = conv(pld,Dz); 44 | 45 | end 46 | 47 | bz = bz+bZ(k+1)*conv(pln,pld); 48 | 49 | end 50 | 51 | 52 | 53 | az = zeros(1,azord+1); 54 | 55 | for k = 0:azord 56 | 57 | pln = [1]; 58 | 59 | for l = 0:k-1 60 | 61 | pln = conv(pln,Nz); 62 | 63 | end 64 | 65 | pld = [1]; 66 | 67 | for l = 0:azord-k-1 68 | 69 | pld = conv(pld,Dz); 70 | 71 | end 72 | 73 | az = az+aZ(k+1)*conv(pln,pld); 74 | 75 | end 76 | 77 | 78 | 79 | az1 = az(1); az = az/az1; bz = bz/az1; -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | DIGITAL SIGNAL PROCESSING USING MATLAB 2 | 3 | -------------------------------------- 4 | 5 | By Proakis and Ingle, 1995 6 | 7 | 8 | 9 | MS-DOS Diskette Contents 10 | 11 | ------ -------- -------- 12 | 13 | The diskette contains all Matlab functions developed in the accompanying 14 | 15 | book. These functions, which can be treated as a new DSP toolbox, are 16 | 17 | available in the subdirectory "pws_dsp". This toolbox can be used either in 18 | 19 | book exercises or for general signal processing operations. Place this toolbox 20 | 21 | as a subdirectory in your Matlab Toolbox directory and place its reference in 22 | 23 | the MATLABPATH environment variable. This can be done by editing your 24 | 25 | matlabrc.m file in the MATLAB directory. 26 | 27 | 28 | 29 | This diskette also contains all Matlab script files used in Chapter 30 | 31 | Examples. These files are available in each chapter subdirectory. It is not 32 | 33 | necessary to reference each subdirectory in the MATLABPATH environment. The 34 | 35 | best approach is to make each subdirectory as a current directory (using the 36 | 37 | "chdir" command) when you want to use or modify scripts. 38 | 39 | 40 | 41 | Finally, some figures generated in the book using Matlab are also provided 42 | 43 | as script files for learning experience. These are available in the "figures" 44 | 45 | directory. 46 | 47 | 48 | 49 | The overall directory structure is as follows: 50 | 51 | 52 | 53 | DIRECTORY COMMENTS 54 | 55 | --------- -------- 56 | 57 | \CHAP_02 : Matlab script files: Chapter 2 Examples 58 | 59 | \CHAP_03 : Matlab script files: Chapter 3 Examples 60 | 61 | \CHAP_04 : Matlab script files: Chapter 4 Examples 62 | 63 | \CHAP_05 : Matlab script files: Chapter 5 Examples 64 | 65 | \CHAP_06 : Matlab script files: Chapter 6 Examples 66 | 67 | \CHAP_07 : Matlab script files: Chapter 7 Examples 68 | 69 | \CHAP_08 : Matlab script files: Chapter 8 Examples 70 | 71 | \FIGURES : Matlab script files for figures 72 | 73 | \PWS_DSP : DSP Toolbox containing Matlab functions 74 | 75 | : developed in the book. 76 | 77 | 78 | 79 | These M-files are User Contributed Routines which are being redistributed by The MathWorks, upon request, on an "as is" basis. A User Contributed Routine is not a product of The MathWorks, Inc. and The MathWorks assumes no responsibility for any errors that may exist in these routines. 80 | 81 | 82 | --------------------------------------------------------------------------------