0% found this document useful (0 votes)
15 views

DSP Codes

Uploaded by

Abhinay Challa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
15 views

DSP Codes

Uploaded by

Abhinay Challa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
Ce o~ 10 a 12 13 a4 15 16 17 18 19 20 21 22 23 24 25 26 m7 28 29 30 32 33 34 3A Low Pass filter FIR filter type %X%X% clear all cle b-([21]; a= 2; [h, w] = freqz(b,a); figure(1) subplot (2,1,1); plot(w/pi, abs(h),'b’, LineWidth',2); grid on title(' Frequency + of Elementary Low pass filter’); axis([@ 1 @ 1]) xdabel(‘Normalized frequency’); ylabel (‘Magnitude in ab te value!); subplot(2,1,2) plot(w/pi,rad2deg(angle(h)), ‘b’, ‘Linewidth » 2)3 grid on xlabel(*Normalized frequency’); ylabel('Phase angle (deg)'); BERK Discrete time sequence Ts 21 n = @:1:100; x = sin(0.1*pitn*Ts) + sin(@.9*pi=n*Ts); x1 = Sin(@.1*pitn*Ts); x2 = sin(@.9*pi*n*Ts); zi = 0; y = filter(b,a,x,2i); Figure(2) stem(n,x,'b', “filled BBO ONG Cf eameies 135) lyiabel( ‘amplitude dy titlec t 0 ence’); Pegend(*Tnput OF sequence’) figure(3) stem(n,x,'b', ys hold Stem(nyy "m1 Hed!); hold xlabel( ‘No of samplen). Ylabel(' input dnd’ iit ey are title(! Input dae Gnd eae ie WKXK High Pass filter FIR filter type XXXK% clear all ele b= [2-1]; (als 2; (h, w] = freqz(b,a); figure(1) subplot (2,1,1); plot(w/pi, abs(h),"b',‘Linewidth',2); grid on title(| Frequency response of Elementary High pass filter’); axis([@ 1 @ 1) xlabel('Normalized frequency’); ylabel( ‘Magnitude in absolute value’); subplot (2,1, 2) plot(w/pi,radzdeg(angle(h)), ‘b’, ‘Linewidth', 2); grid on xlabel(‘Normalized frequency’); ylabel(‘Phase angle (deg)"); BKK Discrete time sequence ts |= 25 100; sin(@.1*pitn*Ts) + sin(@.9*pitn*Ts); x1 = sin(@.1*pi*n*Ts); x2 = sin(@.9*pitn*Ts); zi = a; y = filter(b,a,x,zi); figure(2) stem(n,x,'b',"filled’); xlabel('No of samples‘); ylabel(‘Amplitude’); title('Input DT sequence’); legend(*Input DT sequence’) figure(3) stem(n,x,'b','filled’); hold on stem(n,y,'m-",'filled’); hold on xlabel('No of samples’); ylabel(’Input and filtered DT title(‘Input (blue color) and Filtered DT sequ ARK Band pass filter FIR filter type X¥XXX clear all. cle b = [eonv([1 1],[2 -1])]; a = 25 [h, w] = freqz(b,a); figure(1) subplot(2,1,1); plot(w/pi, abs(h),"b","Linewidth’,2); grid on title(*Frequency response of Elementary band pass filter’); axis([@ 1 @ 1]) xlabel( ‘Normalized frequency"); ylabel( ‘Magnitude in absolute value’)} subplot(2,1,2) plot(w/pi,rad2deg(angle(h)), "b*, ‘Linewidth’, 2)$ grid on xlabel(‘Normalized frequency’); ylabel('Phase angle (deg)'); XKXX Discrete time sequence 1 @:1:100; cos(0.01*pitn*Ts) + cos(0.4*pitn*Ts) + cos(0.5*pitn*Ts) + cos(@.95*pitntTs); zeros(1 , max(length(a),length(b))-1) y = filter(b,a,x,zi); Figure(2) stem(n,x, "b’," filled") xlabel(‘No of samples’); ylabel("Amplitude'); title(/tnput oT) sequen legend(‘Input OT sequence") figure(3) stem(n,x,'b','filled"); hold stem(n,y,'m-',‘filled'); hold xlabel(‘No amples"); ylabel(‘Input and filtered title(‘Input (blue color) and Filtere deneetRLael le 31 32 XEKK Band stop filter FIR filter type %XXRX clear all cle b=[1@4]; a= 2; [h, w] = freqz(b,a); figure(1) subplot (2,1,1); plot(w/pi, abs(h),'b*,’LineWidth",2); grid on title(‘Frequency response of Elementary band stop filter’); axis([@ 1 @ 1]) xlabel(‘Normalized frequency’); subplot (2,1,2) plot(w/pi,rad2deg(angle(h)), “b’, ‘Linewidth’, 2)} grid on xlabel( ‘Normalized frequency"); ylabel('Phase angle (deg)'); %EK% Discrete time sequence Ts = 15 00; zi = zeros(1 , max(length(a),length(b))-1); = filter(b,a,x,zi); figure(2) ylabel( ‘Magnitude in absolute value’) cos(@.01*pi*n*Ts) + cos(@.4*pitn*Ts) + cos(0.5*pi* ee co2(0. 95¢pi stem(n,x,°b *filled'); xlabel(‘No of samples’); ylabel( Amplitude’); legend( ‘Input oT equence') figure(3) stem(n,x,'b stem(n,y,'m-", . filled’); *filled’); hold on) hold on xlabel(‘No of samples’); ylabel(‘Input and fil title(’Input oy sequence’ )3) ed DT sequence’); | ||| title('Input (blue color) and Filtered DT sequence(Pink cole yy i freqz(bl,al); freqz(b2,a2 freqz(b3,a3); freqz(b4,a4) 5 subplot (4,2, 1); Plot(wi/pi, abs(h1),"b', "Li: (914 1]) xlabel(‘Hormelized freaiiency'), ‘subplot (4,2,2) i | Plat (wi/pi, radzdeg(angle(n)) | Mabel (/ Normalized) frequel subplot(4,2, 3) i ate an |absctutel value"); 4, 2)5 @rid on ip fapgte| Klee) 1)3 KKK Discrete time sequence 1 | fis i= dy i n= @:1:100; i X1 = cos(@.1*pitn*Ts) + cos(@.45*pitn*Ts) + cos(@.8*pitn*Ts) ; ) : zil = zeros(1 , max(length(al),length(b1))-1); | yi = filter(b1,al,x1,zi1); figure(2) stem(n,x1,'b',"filled'); : | xlabel('No of samples’); ylabel(*Amplitude'); title(*Input OT sequence 4") legend('Input DT sequence 1°) | figure(3) | stem(n,x1,'b','Filled’); hold on ; stem(n,y1,'m-','filled'); hold on i xlabel(‘No of samples’); ylabel('Input and filtered DT’ sequence 1"); title(' Input (blue color) and Filtered OT! sequence 1¢Pink color) *)+ %HRG Discrete time sequence 2 Tei n= @:1:100; x2 = Cos(@.1*pi*n#Ts) + cos(@.35*pitn*Ts) + cos(@.45*pi*n*Ts); zi2 = zeros(1 , max(length(a2) ,length(b2))-1); y2 = filter(b2,a2,x2,212); figure(4) stem(n,x2,'b','filled'); mlabel( Hoof samples’); | ylabeh( Amplitude’); title( Inout, DT sequence 2"); Jegend(' Inout: OT) sequence!) Figure(5) | im stem(n,x2,°b''Filled")}\ hold dq stem(n,y2,'m-", 'fillea’ hold) en, Mabel (‘No gf samples"), ylabel(’ tnaut and filtered DY sequence 2°), title(* input (blue 'olgin)) and Faitedred, Dp pequence 2(Pink colon) ") 5

You might also like