Sunteți pe pagina 1din 73

SIES College of Arts, Commerce & Science, Nerul GENERAL TERMS USED IN PROGRAMS OF MATLAB:1) WINDOW :SYNTAX :WINDOW

FUNCTION GATEWAY: WINDOW(@WNAME,N) returns an N-point window of type specified by the function handle @WNAME in a column vector. WINDOW(@WNAME,N,OPT) designs the window with the optional input argument specified in OPT. To see what the optional input arguments are, see the help for the individual windows, for example, KAISER or CHEBWIN. 2) FREQZ :SYNTAX :Digital filter frequency response :[H,W] = FREQZ(B,A,N) returns the N-point complex frequency response vector H and the N-point frequency vector W in radians/sample of the filter: jw -jw -jmw jw B(e) b(1) + b(2)e + .... + b(m+1)e H(e) = ---- = -----------------------------------jw -jw -jnw A(e) a(1) + a(2)e + .... + a(n+1)e given numerator and denominator coefficients in vectors B and A. The frequency response is evaluated at N points equally spaced around the upper half of the unit circle. If N isn't specified, it defaults to 512. [H,W] = FREQZ(B,A,N,'whole') uses N points around the whole unit circle. 3) STEM :SYNTAX :Discrete sequence or "stem" plot :STEM(Y) plots the data sequence Y as stems from the x axis terminated with circles for the data value. STEM(X,Y) plots the data sequence Y at the values specified in X.

Digital Signal Processing

SIES College of Arts, Commerce & Science, Nerul


4) FIGURE :SYNTAX :Create figure window :FIGURE, by itself, creates a new figure window, and returns its handle. FIGURE(H) makes H the current figure, forces it to become visible, and raises it above all other figures on the screen. If Figure H does not exist, and H is an integer, a new figure is created with handle H. 5) ABS :SYNTAX :Absolute value :ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is the complex modulus (magnitude) of the elements of X. 6) ANGLE :SYNTAX :Phase angle :ANGLE(H) returns the phase angles, in radians, of a matrix with complex elements. 7) SIN :SYNTAX :Sine :SIN(X) is the sine of the elements of X. 8) COS :SYNTAX :Cosine :COS(X) is the cosine of the elements of X. 9) HOLD :SYNTAX :Hold current graph. HOLD ON holds the current plot and all axis properties so that subsequent graphing commands add to the existing graph.

Digital Signal Processing

SIES College of Arts, Commerce & Science, Nerul


10) XLABEL :SYNTAX :X-axis label :XLABEL('text') adds text beside the X-axis on the current axis. 11) YLABEL :SYNTAX: Y-axis label: YLABEL('text') adds text beside the Y-axis on the current axis. 12) INPUT :SYNTAX :Prompt for user input :R = INPUT('How many apples') gives the user the prompt in the text string and then waits for input from the keyboard.The input can be any MATLAB expression, which is evaluated, using the variables in the current workspace, and the result returned in R. If the user presses the return key without entering anything, INPUT returns an empty matrix. 13) AXIS :SYNTAX :Control axis scaling and appearance :AXIS([XMIN XMAX YMIN YMAX]) sets scaling for the x- and y-axes on the current plot. AXIS([XMIN XMAX YMIN YMAX ZMIN ZMAX]) sets the scaling for the x-, y- and z-axes on the current 3-D plot. AXIS([XMIN XMAX YMIN YMAX ZMIN ZMAX CMIN CMAX]) sets the scaling for the x-, y-, z-axes and color scaling limits on the current axis . 14) CONV :SYNTAX :Convolution and polynomial multiplication :C = CONV(A, B) convolves vectors A and B. The resulting vector is length LENGTH(A)+LENGTH(B)-1. If A and B are vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials. 15) SUBPLOT:-

Digital Signal Processing

SIES College of Arts, Commerce & Science, Nerul


SYNTAX :Create axes in tiled positions :. H = SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window into an m-by-n matrix of small axes, selects the p-th axes for the current plot, and returns the axis handle. The axes are counted along the top row of the Figure window, then the second row, etc. For example, SUBPLOT(2,1,1), PLOT(income) SUBPLOT(2,1,2), PLOT(outgo) 16) FIR1 :SYNTAX :FIR filter design using the window method :B = FIR1(N,Wn) designs an N'th order lowpass FIR digital filter and returns the filter coefficients in length N+1 vector B.The cut-off frequency Wn must be between 0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. The filter B is real and has linear phase.The normalized gain of the filter at Wn is -6 dB. B = FIR1(N,Wn,'high') designs an N'th order highpass filter. You can also use B = FIR1(N,Wn,'low') to design a lowpass filter. If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an order N bandpass filter with passband W1 < W < W2. You can also specify B = FIR1(N,Wn,'bandpass'). If Wn = [W1 W2], B = FIR1(N,Wn,'stop') will design a bandstop filter. If Wn is a multi-element vector, Wn = [W1 W2 W3 W4 W5 ... WN], FIR1 returns an order N multiband filter with bands 0 < W < W1, W1 < W < W2, ..., WN < W < 1. B = FIR1(N,Wn,'DC-1') makes the first band a passband. B = FIR1(N,Wn,'DC-0') makes the first band a stopband. 17) FILTER :SYNTAX :One-dimensional digital filte :Y = FILTER(B,A,X) filters the data in vector X with the filter described by vectors A and B to create the filtered data Y. The filter is a "Direct Form II Transposed" implementation of the standard difference equation: a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) - a(2)*y(n-1) - ... - a(na+1)*y(n-na) If a(1) is not equal to 1, FILTER normalizes the filter coefficients by a(1).

Digital Signal Processing

SIES College of Arts, Commerce & Science, Nerul


18) PLOT :SYNTAX :Linear plot :PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, length(Y) disconnected points are plotted. PLOT(Y) plots the columns of Y versus their index.If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)).In all other uses of PLOT, the maginary part is ignored. 19) BUTTORD :SYNTAX :Butterworth filter order selection :[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Butterworth filter that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the stopband. Wp and Ws are the passband and stopband edge frequencies, normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For example, Lowpass: Wp = .1, Ws = .2 Highpass: Wp = .2, Ws = .1 Bandpass: Wp = [.2 .7], Ws = [.1 .8] Bandstop: Wp = [.1 .8], Ws = [.2 .7] BUTTORD also returns Wn, the Butterworth natural frequency (or, the "3 dB frequency") to use with BUTTER to achieve the specifications. 20) BUTTER :SYNTAX :Butterworth digital and analog filter design :[B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator). The coefficients are listed in descending powers of z. The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. If Wn is a two-element vector, Wn = [W1 W2], BUTTER returns an order 2N bandpass filter with passband W1 < W < W2. [B,A] = BUTTER(N,Wn,'high') designs a highpass filter.

Digital Signal Processing

SIES College of Arts, Commerce & Science, Nerul


[B,A] = BUTTER(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2]. 21) RANDN:SYNTAX :Normally distributed random numbers :RANDN(N) is an N-by-N matrix with random entries, chosen from a normal distribution with mean zero, variance one and standard deviation one. RANDN(M,N) and RANDN([M,N]) are M-by-N matrices with random entries. RANDN(M,N,P,...) or RANDN([M,N,P...]) generate random arrays. RANDN with no arguments is a scalar whose value changes each time it is referenced. RANDN(SIZE(A)) is the same size as A. RANDN produces pseudo-random numbers. The sequence of numbers generated is determined by the state of the generator. Since MATLAB resets the state at start-up, the sequence of numbers generated will be the same unless the state is changed. 22) SPECTRUM :SYNTAX :Power spectrum estimate of one or two data sequences :[P,F] = SPECTRUM(X,NFFT,NOVERLAP,WINDOW,Fs) given a sampling frequency Fs returns a vector of frequencies the same length as Pxx at which the PSD is estimated. PLOT(F,P(:,1)) plots the power spectrum estimate versus true frequency. [P, F] = SPECTRUM(X,NFFT,NOVERLAP,WINDOW,Fs,Pr) where Pr is a scalar between 0 and 1, overrides the default 95% confidence interval and returns the Pr*100% confidence interval for Pxx instead. SPECTRUM(X) with no output arguments plots the PSD in the current figure window, with confidence intervals. 23) REMEZ :SYNTAX :Parks-McClellan optimal equiripple FIR filter design :B=REMEZ(N,F,A) returns a length N+1 linear phase (real, symmetric coefficients) FIR filter which has the best approximation to the desired frequency response described by F and A in the minimax sense. F is a vector of frequency band edges in pairs, in ascending order between 0 and 1. 1 corresponds to the Nyquist frequency or half the sampling frequency. A is a real vector the same size as F which specifies the desired amplitude of the frequency response of the resultant filter B. The desired response is the line connecting the points (F(k),A(k)) and (F(k+1),A(k+1)) for odd k.

Digital Signal Processing

SIES College of Arts, Commerce & Science, Nerul


24) CONV2 :SYNTAX :Two dimensional convolution :C = CONV2(A, B) performs the 2-D convolution of matrices A and B.If [ma,na] = size(A) and [mb,nb]=size(B), then size(C)=[ma+mb-1,na+nb1]. CORR2 Compute 2-D correlation coefficient :R = CORR2(A,B) computes the correlation coefficient between A and B, where A and B are matrices or vectors of the same size. 25) SUM :SYNTAX :Sum of elements:For vectors, SUM(X) is the sum of the elements of X. For matrices, SUM(X) is a row vector with the sum over each column. For N-D arrays, SUM(X) operates along the first non-singleton dimension. 26) DISP:SYNTAX:Display array :DISP(X) displays the array, without printing the array name. In all other ways it's the same as leaving the semicolon off an expression except that empty arrays don't display. 27) LENGTH :SYNTAX :Length of vecto :-

LENGTH(X) returns the length of vector X. It is equivalent to MAX(SIZE(X)) for non-empty arrays and 0 for empty ones. 28) BITREVORDER :SYNTAX :Permute input into bit-reversed orde :-

Digital Signal Processing

SIES College of Arts, Commerce & Science, Nerul


Y = BITREVORDER(X) returns an array Y of the same size as X, with its first non-singleton dimension permuted to be in bit-reversed order. [Y,I] = BITREVORDER(X) returns the bit-reversed index vector I, such that, for a vector Y, Y=X(I). 29) DEC2BIN :SYNTAX :Convert decimal integer to a binary string :DEC2BIN(D) returns the binary representation of D as a string.D must be a non-negative integer smaller than 2^52. DEC2BIN(D,N) produces a binary representation with at least N bits. 30) SPRINTF :SYNTAX :Write formatted data to string :[S,ERRMSG] = SPRINTF(FORMAT,A,...) formats the data in the real part of atrix A (and in any additional matrix arguments), under control of the secified FORMAT string, and returns it in the MATLAB string variable S. ERRMSG is an optional output argument that returns an error message string if an error occurred or an empty matrix if an error did not occur. SPRINTF is the same as FPRINTF except that it returns the data in a MATLAB string variable rather than writing it to a file. The special formats \n,\r,\t,\b,\f can be used to produce linefeed,carriage return, tab, backspace, and formfeed characters respectively.Use to produce a backslash character and %% to produce the percent character.

Digital Signal Processing

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL NO.1 %SIGNAL FOR COSINE clc; close all; clear all; w=input('enter the frequency'); for n=0:0.1:6.28 b=cos(w*n); stem(n,b); hold on; end xlabel('samle position'); ylabel('amplitude'); title('cosine');

Digital Signal Processing

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

10

SIES College of Arts, Commerce & Science, Nerul


%Signal for exponential clc; close all; clear all; N=input('enter the no of samples'); a=input('enter the base'); for n=0:1:N-1 b=exp(-n); subplot(2,3,1); stem(n,b); hold on; end axis([0,10,0,3]); xlabel('sample position'); ylabel('amplitude'); title('Exponential');

Digital Signal Processing

11

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

12

SIES College of Arts, Commerce & Science, Nerul


%Signal for sine clc; close all; clear all; w=input('enter the frequency'); for n=0:0.1:6.28 b=sin(w*n); stem(n,b); hold on; end xlabel('samle position'); ylabel('amplitude'); title('sinusoidal');

Digital Signal Processing

13

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

14

SIES College of Arts, Commerce & Science, Nerul


%Signal for unit impulse clc; close all; clear all; N=input('enter the no of samples'); for n=0:1:N-1 if n==0 a=1; else a=0; end stem(n,a); hold on; end axis([-2,2,0,1]); xlabel('sample position'); ylabel('amplitude'); title('Unit impulse response');

Digital Signal Processing

15

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

16

SIES College of Arts, Commerce & Science, Nerul


%Signal for unit ramp clc; close all; clear all; N=input('enter the no of samples'); a=input('enter the base'); for n=0:1:N-1 b=power(a,n); stem(n,b); hold on; end % axis([0,10,0,10]); xlabel('sample position'); ylabel('amplitude'); title('Unit ramp input'); figure(2); stem(b,n);

Digital Signal Processing

17

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

18

SIES College of Arts, Commerce & Science, Nerul


%Signal for unit step clc; close all; clear all; N=input('enter the no of samples'); for n=0:1:N-1 a=1; stem(n,a); hold on; end axis([0,1,0,6]); xlabel('sample position'); ylabel('amplitude'); title('Unit step input');

Digital Signal Processing

19

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

20

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL-2

%Magnitude and phase response clc; close all; clear all; M=input('enter the no of samples'); n=0:1:M; xn=3.5*sin(2*pi*(0.15)*n)+sin(2*pi*(0.4)*n); [xnr,M]=freqz(xn,1,M+1) xrm=abs(xnr);%to clalculate magnitude xra=angle(xnr);%to claculate phase subplot(2,1,1) plot(n,xrm,'r'); subplot(2,1,2) plot(n,xra,'m');

Digital Signal Processing

21

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

22

SIES College of Arts, Commerce & Science, Nerul


%Magntiude and phase response clc; close all; clear all; M=input('enter the no of samples'); n=0:1:M; xn=3+5.657*cos(2*pi*(0.1)*n); [xnr,M]=freqz(xn,1,M+1); xrm=abs(xnr) xra=angle(xnr); subplot(2,1,1) plot(n,xrm,'r'); subplot(2,1,2) plot(n,xra,'m');

Digital Signal Processing

23

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

24

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL-3 %PLOT OF POLE-ZERO clc; close all; clear all; num=[1 -1]; den=[1 -2*0.7071 0.7071*0.7071]; [r,p,k]=residuez(num,den); zplane(r,p); title('zero plot of x(z)=z-1/pow((z-0.7071),2')

Digital Signal Processing

25

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

26

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL-4 %TO calculate N point DFT clc; close all; clear all; N=input('Enter no.of samples'); n=0:1:N-1 xn=2*exp(-0.1*n); dx=fft(xn,N); MAGNITUDE=20*log10(abs(dx)) PHASE=angle(dx)*180/pi subplot(2,1,1) stem(n,MAGNITUDE,'filled'); title('MAGNITUDE') subplot(2,1,2) stem(n,PHASE,'filled'); title('PHASE') xn=2*exp(0.1*n);

Digital Signal Processing

27

SIES College of Arts, Commerce & Science, Nerul


Output :N=8

N=16

Digital Signal Processing

28

SIES College of Arts, Commerce & Science, Nerul


N=64

N=128

Digital Signal Processing

29

SIES College of Arts, Commerce & Science, Nerul


N=256

Digital Signal Processing

30

SIES College of Arts, Commerce & Science, Nerul


%TO calculate N point DFT clc; close all; clear all; N=input('Enter no.of samples'); n=0:1:N-1 sn=4*sin(4*pi*(0.4)*n)+sin(2*pi*(0.2)*n); dx=fft(sn,N); MAGNITUDE=20*log10(abs(dx)) PHASE=angle(dx)*180/pi subplot(2,1,1) stem(n,MAGNITUDE,'filled') title('MAGNITUDE') subplot(2,1,2) stem(n,PHASE,'filled') title('PHASE') sn=4*sin(4*pi*(0.4)*n)+sin(2*pi*(0.2)*n);

Digital Signal Processing

31

SIES College of Arts, Commerce & Science, Nerul


Output :N=256

N=64

Digital Signal Processing

32

SIES College of Arts, Commerce & Science, Nerul


N=24

Digital Signal Processing

33

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL NO.5 %N point DFT using Twiddle Matrix clc; close all; clear all; xn=input('Enter the sequence'); tw=[1 1 1 1; 1 -j -1 j; 1 -1 1 -1; 1 j -1 -j]; n=0:1:length(xn)-1; yn=tw*xn' N=input('Enter no.of samples'); n=0:1:N-1; yn1=fft(xn,N)

Digital Signal Processing

34

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

35

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL NO.6 %Linear Convolution clc; close all; clear all; xn=input('Enter 1st sequence'); hn=input('Enter 2nd sequence'); y1=conv(xn,hn); a=length(xn); b=length(hn); c=a+b-1; n1=0:1:a-1; subplot(3,1,1); stem(n1,xn); title('INPUT SEQUENCE') n2=0:1:b-1; subplot(3,1,2); stem(n2,hn); title('INPUT RESPONSE') n=0:1:c-1; subplot(3,1,3); stem(n,y1); title('OUTPUT SEQUENCE')

Digital Signal Processing

36

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

37

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL NO.7 %Circular Convolution clc; close all; clear all; xn=input('Enter 1st sequence'); hn=input('Enter 2nd sequence'); x=[xn(1:1) xn(4:4) xn(3:3) xn(2:2); xn(2:2) xn(1:1) xn(4:4) xn(3:3); xn(3:3) xn(2:2) xn(1:1) xn(4:4); xn(4:4) xn(3:3) xn(2:2) xn(1:1)] h=hn'; y=x*h n=0:1:length(xn)-1; subplot(3,1,1); stem(n,xn); title('INPUT SEQUENCE') subplot(3,1,2); stem(n,hn); title('INPUT RESPONSE') subplot(3,1,3); stem(n,y); title('OUTPUT SEQUENCE')

Digital Signal Processing

38

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

39

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL-8 %Lowpass Filter clc; close all; clear all; f=input('enter the freq.'); M=input('enter the no of samples'); wc=input('enter the cutoff freq.'); n=0:1:M; xn=4*sin(2*pi*f*M)+(4/3)*sin(2*pi*3*f*M)+(4/7)*sin(2*pi*7*f*M); win=window(@rectwin, M+1); hnr=fir1(M,wc,win); ynr=conv(xn,hnr); [Hr,w]=freqz(hnr,1,M+1) hrm=abs(Hr); hra=angle(Hr); figure(1) subplot(2,1,1) stem(n,hrm); title('magnitude of filter using rectangular window') subplot(2,1,2) stem(n,hra); title('phase of filter using rectangular windiow') [Yr,w]=freqz(ynr,1,M+1) yrm=abs(Yr); yra=angle(Yr); figure(2) subplot(2,1,1) stem(n,yrm); title('magnitude of output') subplot(2,1,2) stem(n,yra); title('phase of output')

Digital Signal Processing

40

SIES College of Arts, Commerce & Science, Nerul


Output:-

Digital Signal Processing

41

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL-9 %Highpass Filter clc; close all; clear all; f=input('enter the freq.'); M=input('enter the no of samples'); wc=input('enter the cutoff freq.'); n=0:1:M; xn=4*sin(2*pi*f*M)+(4/3)*sin(2*pi*3*f*M)+(4/7)*sin(2*pi*7*f*M); win=window(@hann,M+1); hnr=fir1(M,wc,'high',win); ynr=conv(xn,hnr); [Hr,w]=freqz(hnr,1,M+1) hrm=abs(Hr); hra=angle(Hr); figure(1) subplot(2,1,1) stem(n,hrm); title('magnitude of filter of hanning window') subplot(2,1,2) stem(n,hra); title('phase of filter of hanning window') [Yr,w]=freqz(ynr,1,M+1) yrm=abs(Yr); yra=angle(Yr); figure(2) subplot(2,1,1) stem(n,yrm); title('magnitude of output') su stem(n,yra); title('phase of output')

Digital Signal Processing

42

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

43

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL-10 %LOWPASS FILTER clc; close all; clear all; M=input('enter the no. of samples'); wc=input('cut off frequency'); n=0:1:M; xn=3*exp(-0.1*n); hn=fir1(M,wc); ynr=conv(xn,hn); [yr,wc]=freqz(ynr,1,M+1); yrm=abs(yr); yra=angle(yr); figure(1) subplot(2,1,1) stem(n,yrm); title('Magnitude of Output') subplot(2,1,2) stem(n,yra); title('Phase of Output') [xnr,m]=freqz(xn,1,M+1); xrm=abs(xnr); xra=angle(xnr); figure(2) subplot(2,1,1) stem(n,xrm); title('Magnitude of Input') subplot(2,1,2) stem(n,xra); title('Phase of Input')

Digital Signal Processing

44

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

45

SIES College of Arts, Commerce & Science, Nerul


%HIGHPASS FILTER clc; close all; clear all; M=input('enter the no. of samples'); wc=input('cut off frequency'); n=0:1:M; xn=3*exp(-0.1*n); hn=fir1(M,wc,high); ynr=conv(xn,hn); [yr,wc]=freqz(ynr,1,M+1); yrm=abs(yr); yra=angle(yr); figure(1) subplot(2,1,1) stem(n,yrm); title('Magnitude of Output') subplot(2,1,2) stem(n,yra); title('Phase of Output') [xnr,m]=freqz(xn,1,M+1); xrm=abs(xnr); xra=angle(xnr); figure(2) subplot(2,1,1) stem(n,xrm); title('Magnitude of Input') subplot(2,1,2) stem(n,xra); title('Phase of Input')

Digital Signal Processing

46

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

47

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL-11 %BAND STOP FILTER clc; close all; clear all; f=input('Enter the frequency of input signal'); M=input('Enter the number of samples'); fp1=input('Enter the low pass band frequency'); fp2=input('Enter the high pass band frequency'); fs1=input('Enter the low stop band frequency'); fs2=input('Enter the high stop band frequency'); fa=input('Enter the sampling frequency'); wp1=2*fp1/fa; wp2=2*fp2/fa; ws1=2*fs1/fa; ws2=2*fs2/fa; wc1=(wp1+ws1)/2; wc2=(wp2+ws2)/2; wc=[wc1 wc2]; n=0:1:M; win=window(@chebwin,M+1,60); hnr=fir1(M,wc,'stop',win); [Hr,w]=freqz(hnr,1,M+1); hrm=abs(Hr); hra=angle(Hr); subplot(2,1,1) stem(n,hrm); title('Magnitude of filter'); subplot(2,1,2) stem(n,hra); title('Phase of filter');

Digital Signal Processing

48

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

49

SIES College of Arts, Commerce & Science, Nerul


%Band pass filter clc; close all; clear all; f=input('Enter the frequency of input signal'); M=input('Enter the number of samples'); fp1=input('Enter the low pass band frequency'); fp2=input('Enter the high pass band frequency'); fs1=input('Enter the low stop band frequency'); fs2=input('Enter the high stop band frequency'); fa=input('Enter the sampling frequency'); wp1=2*fp1/fa; wp2=2*fp2/fa; ws1=2*fs1/fa; ws2=2*fs2/fa; wc1=(wp1+ws1)/2; wc2=(wp2+ws2)/2; wc=[wc1 wc2]; n=0:1:M; win=window(@chebwin,M+1,60); hnr=fir1(M,wc,'bandpass',win); [Hr,w]=freqz(hnr,1,M+1); hrm=abs(Hr); hra=angle(Hr); subplot(2,1,1) stem(n,hrm); title('Magnitude of filter'); subplot(2,1,2) stem(n,hra); title('Phase of filter');

Digital Signal Processing

50

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

51

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL-12 clc; opt=input('Select 1.Lowpass,2.Highpass,3.Bandstop,4.Bandpass:'); switch(opt) case{1} A1=input('Enter the pass band ripple/gain'); A2=input('Enter stop band ripple/gain'); fp=input('Enter the passband frequency'); fs=input('Enter the stop band frequency'); fa=input('Enter sampling frequency'); %CONVERT FREQUENCY IN HTZ TO RADIAN/SAMPLE wp=2*fp/fa; ws=2*fs/fa; [N,wc]=buttord(wp,ws,A1,A2); [z,p,k]=butter(N,wc,'low','z'); [n,d]=butter(N,wc,'low','z'); case{2} A1=input('Enter the pass band ripple/gain'); A2=input('Enter stop band ripple/gain'); fp=input('Enter the passband frequency'); fs=input('Enter the stop band frequency'); fa=input('Enter sampling frequency'); %CONVERT FREQUENCY IN HTZ TO RADIAN/SAMPLE wp=2*fp/fa; ws=2*fs/fa; [N,wc]=buttord(wp,ws,A1,A2); [z,p,k]=butter(N,wc,'high','z'); [n,d]=butter(N,wc,'high','z');

case{3} A1=input('Enter the pass band ripple/gain'); A2=input('Enter stop band ripple/gain'); fp1=input('Enter the low passband frequency'); fs1=input('Enter the low stop band frequency'); fa=input('Enter sampling frequency'); fp2=input('Enter the high passband frequency'); fs2=input('Enter the high stop band frequency'); %CONVERT FREQUENCY IN HTZ TO RADIAN/SAMPLE wp1=2*fp1/fa; ws1=2*fs1/fa; wp2=2*fp2/fa; ws2=2*fs2/fa; wp=[wp1 wp2]; ws=[ws1 ws2]; wc1=(wp1+ws1)/2; wc2=(wp2+ws2)/2; wc=[wc1 wc2];

Digital Signal Processing

52

SIES College of Arts, Commerce & Science, Nerul


[N,wc]=buttord(wp,ws,A1,A2); [z,p,k]=butter(N,wc,'stop','z'); [n,d]=butter(N,wc,'stop','z'); case{4} A1=input('Enter the pass band ripple/gain'); A2=input('Enter stop band ripple/gain'); fp1=input('Enter the low passband frequency'); fs1=input('Enter the low stop band frequency'); fa=input('Enter sampling frequency'); fp2=input('Enter the high passband frequency'); fs2=input('Enter the high stop band frequency');

%CONVERT FREQUENCY IN HTZ TO RADIAN/SAMPLE wp1=2*fp1/fa; ws1=2*fs1/fa; wp2=2*fp2/fa; ws2=2*fs2/fa; wp=[wp1 wp2]; ws=[ws1 ws2]; wc1=(wp1+ws1)/2; wc2=(wp2+ws2)/2; wc=[wc1 wc2]; [N,wc]=buttord(wp,ws,A1,A2); [z,p,k]=butter(N,wc,'bandpass','z'); [n,d]=butter(N,wc,'bandpass','z'); otherwise disp('Inavlid option'); end w=0:0.01*pi:pi; H=freqz(n,d,w); hm=abs(H); ha=angle(H); subplot(2,1,1) stem(w,hm); title('Magnitude response of a filter'); subplot(2,1,2) stem(w,ha); title('Phase response of a filter ');

Digital Signal Processing

53

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

54

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL 13 Radix 2 DIF FFT Algorithm Problem Statement :Write a program in MATLAB to implement Radix2 Decimation In Frequency (DIF) FFT Algorithm. (MATLAB) Functions used: Y = fft(X)-: Returns the Discrete Fourier Transform (DFT) of vector X computed with a Fast Fourier Transform (FFT) algorithm. Source Code: % RADIX-2 DIF FFT ALGORITHM

clc ; clear all ; close all ; format short ; N = input('Please enter the length of the DFT : ') ; for i = 1:N+1 if N == 2^i x = input('Please enter the input sequence : ') ; Z = fft(x,N) ; disp('FFT Sequence') ; disp(Z) ; subplot(2,1,1) ; stem(x) ; xlabel('N') ; ylabel('Amplitude') ; title('Input Sequence') ; subplot(2,1,2) ; stem(Z) ; xlabel('N') ; ylabel('Amplitude') ; title('FFT of the Input Sequence') ; break ; elseif N > 2^i else disp('Not a proper number') ; break ; end ; end ;

Digital Signal Processing

55

SIES College of Arts, Commerce & Science, Nerul


Output :Enter Length Of FFT : - 8 Input The Sequence [1 2 3 4 5 6 7 8] FFT Sequence Columns 1 through 6 36.0000 -4.0000 + 9.6569i -4.0000 + 4.0000i -4.0000 + 1.6569i -4.0000 -4.0000 - 1.6569i Columns 7 through 8 -4.0000 - 4.0000i -4.0000 - 9.6569i

Original Signal 8 6 4 2 0

Amplitude---->

4 n----> FFT Signal

10 5 0 -5 -10 -5

Amplitude---->

10

15 n---->

20

25

30

35

40

Digital Signal Processing

56

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL 14 Radix 2 DIT FFT Algorithm Problem Statement :Write a program in MATLAB to implement Radix2 Decimation In Time (DIT) FFT Algorithm. (MATLAB) Functions used: Y = fft(X) Returns the Discrete Fourier Transform (DFT) of vector X computed with a Fast Fourier Transform (FFT) algorithm. Source Code: % RADIX-2 DIT FFT ALGORITHM

clc ; clear all ; close all ; format short ; N = input('Please enter the length of the input sequence : ') ; for i = 1:N+1 if N == 2^i x = input('Please enter the input sequence : ') ; y = bitrevorder(x) ; Z = fft(y,N) ; disp('Input Sequence After Reversal') ; disp(y) ; disp('FFT Sequence') ; disp(Z) ; subplot(2,1,1) ; stem(x) ; xlabel('N') ; ylabel('Amplitude') ; title('Input Sequence') ; subplot(2,1,2) ; stem(Z) ; xlabel('N') ; ylabel('Amplitude') ; title('FFT of the Input Sequence') ; break ; elseif N > 2^i else disp('Not a proper number') ; break ; end ; end;

Digital Signal Processing

57

SIES College of Arts, Commerce & Science, Nerul


Output :Enter Length Of FFT : - 8 Input The Sequence [1 2 3 4 5 6 7 8] 1 5 3 7 2 6 4 8 FFT Sequence Columns 1 through 6 36.0000 -4.0000 + 9.6569i -4.0000 + 4.0000i -4.0000 + 1.6569i -4.0000 -4.0000 - 1.6569i Columns 7 through 8 -4.0000 - 4.0000i -4.0000 - 9.6569i
O inl Snl r a iga ig 8 A p d ----> m litu e 6 4 2 0 1

4 n-> -FT i nl FS a g

1 0 A p d ----> m litu e 5 0 5 -0 1 5

1 0

1 5 n-> --

2 0

2 5

3 0

3 5

4 0

Digital Signal Processing

58

SIES College of Arts, Commerce & Science, Nerul


PRACTICAL-15 %POWER SPECTRUM clc; clear all; close all; t=0:0.01:0.5; d=randn(size(t)); f=input('enter the freq.'); x1=cos(2*pi*f*t)+randn(size(t)); x=x1+d(1,:); subplot(3,1,1) spectrum(x1) subplot(3,1,2) spectrum(x) subplot(3,1,3) spectrum(d(1,:))

Digital Signal Processing

59

SIES College of Arts, Commerce & Science, Nerul


Output :-

Digital Signal Processing

60

SIES College of Arts, Commerce & Science, Nerul

PRACTICAL-16 %REMEZ ALGORITHM

clc; clear all; close all; F=input('enter the freq edges'); A=input('amplitude'); N=input('order of filter'); B=remez(N,F,A); [H,w]=freqz(B,1,N+1);

Digital Signal Processing

61

SIES College of Arts, Commerce & Science, Nerul


hm=abs(H); n=0:1:N; stem(n,hm);

Output :-

Digital Signal Processing

62

SIES College of Arts, Commerce & Science, Nerul

PRACTICAL -17 %TWO DIMENSIONAL LINEAR CONVOLUTION

Digital Signal Processing

63

SIES College of Arts, Commerce & Science, Nerul


clc; close all; clear all; xn=input('Enter 1st sequence'); hn=input('Enter 2nd sequence'); yn=conv2(xn,hn) subplot(3,1,1) stem(xn); title('Input Sequence') subplot(3,1,2) stem(hn); title('Input Response') subplot(3,1,3) stem(yn); title('Output Sequence')

Output :-

Digital Signal Processing

64

SIES College of Arts, Commerce & Science, Nerul

PRACTICAL-18

Digital Signal Processing

65

SIES College of Arts, Commerce & Science, Nerul


%Program for 1-Dimensional clc; close all; clear all; xn=input('Enter the 1st sequence'); hn=input('Enter the 2nd sequence'); a=length(xn); n=-a+1:1:a-1; b=length(hn); c=max(a,b); n1=-c+1:1:c-1; ra=xcorr(xn) rc=xcorr(xn,hn) subplot(2,1,1) plot(n,ra,'g'); title('Auto correlation of xn'); subplot(2,1,2) plot(n,rc,'m'); title('Cross correlation of xn and hn'); %Program for 2-Dimensional clc; close all; clear all; xn=input('Enter 1st sequence'); hn=input('Enter 2nd sequence'); ra=xcorr2(xn) rc=xcorr2(xn,hn)

Output :-

Digital Signal Processing

66

SIES College of Arts, Commerce & Science, Nerul

Digital Signal Processing

67

SIES College of Arts, Commerce & Science, Nerul

PRACTICAL-19 %STABILITY

Digital Signal Processing

68

SIES College of Arts, Commerce & Science, Nerul


clc; clear all; close all; xn=input('enter input seq.'); hn=input('enter impulse response'); yn=conv(xn,hn) d=sum(yn) if d<inf disp('System is stable'); else disp('System is unstable'); end a=length(xn) n=0:1:a-1; stem(n,xn);

Output :-

Digital Signal Processing

69

SIES College of Arts, Commerce & Science, Nerul

Digital Signal Processing

70

SIES College of Arts, Commerce & Science, Nerul

PRACTICAL-20

Digital Signal Processing

71

SIES College of Arts, Commerce & Science, Nerul


%Bit Reversal Algorithm clc; close all; clear all x=input('enter the seq'); x0=x(1,1); x1=x(1,2); x2=x(1,3); x3=x(1,4); X0=x0+x1+x2+x3; X1=x0-x1*j-x2+x3*j; X2=x0-x1+x2-x3; X3=x0+x1*j-x2-x3*j; Xk=[X0 X1 X2 X3]; x=[0:3] [y,I]=bitrevorder(x) a=dec2bin(x) b=dec2bin(y) p=sprintf('%s%s%s%s\n','[linear index]','[bits]','[bitreve]','[index]'); disp(p); s=sprintf('%d\t%d%d\t%d%d\t%d',x(1:1),a(1,:),b(1,:),I(1:1)); disp(s);

Output :-

Digital Signal Processing

72

SIES College of Arts, Commerce & Science, Nerul

Digital Signal Processing

73

S-ar putea să vă placă și