Sunteți pe pagina 1din 26

LIST OF EXPERIMENTS S.No.

1 2 NAME OF EXPERIMENTS Study of basic commands used in MATLAB Write a program for elementary signals in digital signals processing 3 Write a program for fast Fourier transform and inverse discrete Fourier transform. 4 Write a program to a BUTTERWORTH low pass filter for given specification. 5 6 Write a program to a CHEBYSHEV 1 low pass filter. Write a program to a CHEBYSHEV 2 low pass filter. Date Sig.

Write a program to covert an analog filter to a digital filter using impulse invariant transformation and bilinear transformation.

Write a program to design a low pass filter with cut off frequency using rectangular, hamming and blackman and plot their frequency response.

Write a program to find convolution, cross correlation and auto correlation of a sequence using inbuilt functions.

EXP-1 %Study of basic commands used in MATLAB% 1. abs :Absolute value and complex magnitude Syntax Y = abs(X) Description abs(X) returns an array Y such that each element of Y is the absolute value of the corresponding element of X. If X is complex, abs(X) returns the complex modulus (magnitude), which is the same as sqrt(real(X).^2 + imag(X).^2) Examples abs(-5) ans = 5 abs(3+4i) ans =5 2. angle : Phase angle Syntax P = angle(Z) Description P = angle(Z) returns the phase angles, in radians, for each element of complex array Z. The angles lie between . For complex Z, the magnitude R and phase angle theta are given by R = abs(Z) theta = angle(Z) and the statement Z = R.*exp(i*theta) converts back to the original complex Z. Examples Z = [ 1 - 1i 2 + 1i 3 - 1i 4 + 1i 1 + 2i 2 - 2i 3 + 2i 4 - 2i 1 - 3i 2 + 3i 3 - 3i 4 + 3i 1 + 4i 2 - 4i 3 + 4i 4 - 4i ] P = angle(Z) P= -0.7854 0.4636 -0.3218 0.2450

1.1071 -0.7854 0.5880 -0.4636 -1.2490 0.9828 -0.7854 0.6435 1.3258 -1.1071 0.9273 -0.7854

3. rem Remainder after division Syntax R = rem(X,Y) Description R = rem(X,Y) if Y ~= 0, returns X - n.*Y where n = fix(X./Y). If Y is not an integer and the quotient X./Y is within roundoff error of an integer, then n is that integer. The inputs X and Y must be real arrays of the same size, or real scalars. The following are true by convention: rem(X,0) is NaN rem(X,X) for X~=0 is 0 rem(X,Y) for X~=Y and Y~=0 has the same sign as X. Remarks mod(X,Y) for X~=Y and Y~=0 has the same sign as Y. rem(X,Y) and mod(X,Y) are equal if X and Y have the same sign, but differ by Y if X and Y have different signs. The rem function returns a result that is between 0 and sign(X)*abs(Y). If Y is zero, rem returns NaN. (FIX Round towards zero. FIX(X) rounds the elements of X to the nearest integers Towards zero.)

4. log10 Common (base 10) logarithm Syntax Y = log10(X) Description The log10 function operates element-by-element on arrays. Its domain includes complex numbers, which may lead to unexpected results if used unintentionally. Y = log10(X) returns the base 10 logarithm of the elements of X. Examples log10(realmax) is 308.2547 and log10(eps) is -15.6536 (eps returns the distance from 1.0 to the next largest double-precision number, that is eps = 2^(-52).)

5.log Natural logarithm Syntax Y = log(X) Description The log function operates element-wise on arrays. Its domain includes complex and negative numbers, which may lead to unexpected results if used unintentionally. Y = log(X) returns the natural logarithm of the elements of X. For complex or negative z, where z=x+i*y, the complex logarithm is returned. log(z) = log(abs(z)) + i*atan2(y,x) Examples The statement abs(log(-1)) is a clever way to generate . ans = 3.1416 6. mod Modulus after division Syntax M = mod(X,Y) Description M = mod(X,Y) if Y ~= 0, returns X - n.*Y where n = floor(X./Y). If Y is not an integer and the quotient X./Y is within roundoff error of an integer, then n is that integer. The inputs X and Y must be real arrays of the same size, or real scalars. The following are true by convention: mod(X,0) is X mod(X,X) is 0 mod(X,Y) for X~=Y and Y~=0 has the same sign as Y. Remarks rem(X,Y) for X~=Y and Y~=0 has the same sign as X. mod(X,Y) and rem(X,Y) are equal if X and Y have the same sign, but differ by Y if X and Y have different signs. The mod function is useful for congruence relationships: x and y are congruent (mod m) if and only if mod(x,m) == mod(y,m). Examples mod(13,5) ans =3 mod([1:5],3) ans = 1 2 0 1 2 mod(magic(3),3) ans = 2 1 0 0 2 1 1 0 2

(FLOOR Round towards minus infinity. FLOOR(X) rounds the elements of X to the nearest integer towards minus infinity. MAGIC Magic square. MAGIC(N) is an N-by-N matrix constructed from the integers 1 through N^2 with equal row, column, and diagonal sums. Produces valid magic squares for all N > 0 except N = 2.) 7. conv Convolution and polynomial multiplication Syntax w = conv(u,v) Description w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same operation as multiplying the polynomials whose coefficients are the elements of u and v. Definition Let m = length(u) and n = length(v). Then w is the vector of length m+n-1 whose kth element is w(k)= u(j)v(k+1-j) The sum is over all the values of j which lead to legal subscripts for u(j) and v(k+1-j), specifically j = max(1,k+1-n): min(k,m). When m = n, this gives w(1) = u(1)*v(1) w(2) = u(1)*v(2)+u(2)*v(1) w(3) = u(1)*v(3)+u(2)*v(2)+u(3)*v(1) ... w(n) = u(1)*v(n)+u(2)*v(n-1)+ ... +u(n)*v(1) ... w(2*n-1) = u(n)*v(n) 8.filter Filter data with an infinite impulse response (IIR) or finite impulse response (FIR) filter Syntax y = filter(b,a,X) [y,zf] = filter(b,a,X) [y,zf] = filter(b,a,X,zi) y = filter(b,a,X,zi,dim) [...] = filter(b,a,X,[],dim)

Description The filter function filters a data sequence using a digital filter which works for both real and complex inputs. The filter is a direct form II transposed implementation of the standard difference equation (see "Algorithm"). y = filter(b,a,X) filters the data in vector X with the filter described by numerator coefficient vector b and denominator coefficient vector a. If a(1) is not equal to 1, filter normalizes the filter coefficients by a(1). If a(1) equals 0, filter returns an error. If X is a matrix, filter operates on the columns of X. If X is a multidimensional array, filter operates on the first nonsingleton dimension. [y,zf] = filter(b,a,X) returns the final conditions, zf, of the filter delays. If X is a row or column vector, output zf is a column vector of max(length(a),length(b))-1. If X is a matrix, zf is an array of such vectors, one for each column of X, and similarly for multidimensional arrays. [y,zf] = filter(b,a,X,zi) accepts initial conditions, zi, and returns the final conditions, zf, of the filter delays. Input zi is a vector of length max(length(a),length(b))-1, or an array with the leading dimension of size max(length(a),length(b))-1 and with remaining dimensions matching those of X. y = filter(b,a,X,zi,dim) and [...] = filter(b,a,X,[],dim) operate across the dimension dim. Example You can use filter to find a running average without using a for loop. This example finds the running average of a 16-element vector, using a window size of 5. data = [1:0.2:4]'; windowSize = 5; filter(ones(1,windowSize)/windowSize,1,data) ans = 0.2000 0.4400 0.7200 1.0400 1.4000 1.6000 1.8000 2.0000 2.2000 2.4000 2.6000 2.8000 3.0000 3.2000 3.4000 3.6000

9.FFT Discrete Fourier transform. FFT(X) is the discrete Fourier transform (DFT) of vector X. For matrices, the FFT operation is applied to each column. For N-D arrays, the FFT operation operates on the first non-singleton dimension. FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated if it has more. FFT(X,[],DIM) or FFT(X,N,DIM) applies the FFT operation across the dimension DIM. For length N input vector x, the DFT is a length N vector X, with elements

EXP-2 % Write a program for elementary signals in digital signals processing% % unit step signal % a=0:1:6; b=2*ones(1,7); subplot(2,3,1); 1stposition stem(a,b); xlabel('time'); ylabel('amplitude'); title('unit step signal'); % unit impulse signal% a=-1:1:1; b=[0 1 0]; subplot(2,3,2); stem(a,b); xlabel('time'); ylabel('amplitude'); title('unit impulse signal'); % unit ramp signal% a=0:1:5; b=[0 1 2 3 4 5]; subplot(2,3,3); stem(a,b); xlabel('time'); ylabel('amplitude'); title('unit ramp signal'); % assign the value at x axis 0 to 6 with increment 1 % assign the value at y axis % plot the subgraph with 2 rows,3columns & at % show the graph in discrete form % to show title on x axis % to show title on y axis % to show the title of graph % assign the value at x axis -1 to 1 with increment 1 % assign the value at y axis % plot the subgraph with 2 rows,3columns & at 2nd %position % show the graph in discrete form % to show title on x axis % to show title on y axis % to show the title of graph % assign the value at x axis 0 to 5 with increment 1 % assign the value at y axis % plot the subgraph with 2 rows,3columns & at 3rd % position % show the graph in discrete form % to show title on x axis % to show title on y axis % to show the title of graph

% sinusoidal signal % a=0:1:10; b=sin(a); subplot(2,3,4); position stem(a,b); xlabel('time'); ylabel('amplitude'); title('sinusoidal signal'); % cosine signal % a=0:1:10; 1 b=cos(a); subplot(2,3,5); position stem(a,b); xlabel('time'); ylabel('amplitude'); title('cosine signal'); % assign value at x axis 0 to 10 with increment 1 % assign the value at y axis % plot the subgraph with 2 rows,3columns & at 4th % show the graph in discrete form % to show title on x axis % to show title on y axis % to show the title of graph

% assign the value at x axis 0 to 10 with increment % assign the value at y axis % plot the subgraph with 2 rows,3columns & at 5th % show the graph in discrete form % to show title on x axis % to show title on y axis % to show the title of graph

% exponential signal % a=0:1:10; 1 % assign the value at x axis 0 to 10 with increment


9

b=exp(a); subplot(2,3,6); position stem(a,b); xlabel('time'); ylabel('amplitude'); title('exponential signal');

% assign the value at y axis % plot the subgraph with 2 rows,3columns & at 6th % show the graph in discrete form % to show title on x axis % to show title on y axis % to show the title of graph

OUTPUT:
10

u n it s t e p 2

s ig n a l 1

u n it im p u ls e

s ig n a l 5

u n it ra m p

s ig n a l

1 .5

0 .8 0 .6

3 a m p litu d e -0 .5 0 0 .5 t im e 1

a m p litu d e

a m p litu d e

0 .4

0 .5

0 .2

2 t im e

0 -1

3 tim e

s in u s o id a l s ig n a l 1

c o s in e

s ig n a l

4 x 1 0 e x p o n e n tia l s ig n a l 2 .5

0 .5

0 .5

1 .5 a m p litu d e a m p litu d e a m p litu d e 2 4 6 t im e 8 1 0 0 0

-0 .5

-0 .5 0 .5

-1 0

6 t im e

1 0

-1 0

6 tim e

1 0

EXP-3
11

%Write a program for fast Fourier transform and inverse discrete Fourier transform.% x=input('enter the sequence'); N=input('enter the points of fft'); n=length(x); if(n<N) comment then disp('n should be greater than N'); end; X=fft(x,N); na=0:N-1; %Program for x signal% subplot(2,2,1) graph1 stem(x) xlabel('X(n)'); ylabel('amp'); title('x signal'); %Program for magnitude signal% subplot(2,2,2) graph 2 stem(na,abs(X)) use abs xlabel('time'); ylabel('amplitude'); title('plot magnitude signal'); % show 2*2 no.of rows & colums, %disceret value, for finding magnitude %title at x label %title at y label %title for graph %show 2*2no. of rows & columns, %disceret value to find phase % title at x label %title at y label %title for graph %enter the input sequences %enter the points of fft % enter the length of n % if loop, whn n<N thn display

% use fft command % series upto 0 to N-1

12

%Program for phase signal% subplot(2,2,3) graph stem(angle(X)) xlabel('X(n)'); ylabel('amplitude'); title('phase signal'); %Program for ifft signal% xn=ifft(X); subplot(2,2,4) graph3 stem(xn) xlabel('X(n)'); ylabel('amplitude'); title('ifft signal'); %use ifft command %show 2*2no. of rows & columns, %disceret value to find phase % title at x label %title at y label %title for graph %show 2*2no. of rows & columns, %disceret value to find phase % title at x label %title at y label %title for graph

13

OUTPUT:

p 2 1 am p 1 5 0 0 5

l o

n 4 2

i t u p d h e a

ie g

ns

ai g l n

am p 2 x 4 t i m s 6 e i g n a 8

0 - 2 - 4 0 l 4 3

2 X

4 ( n s i f f t

6 ) i g

8 n a l

4 3 am p am p 0 2 X 4 ( n 6 )
14

2 1 0

2 1 0

2 X

4 ( n

6 )

EXP-4 %Write a program to a BUTTERWORTH low pass filter for given specification. % Pa1=0.4; Sa1=30; Fp1=400; Sp1=800; fs=2000; Fp=2*Fp1/fs Sp=2*Sp1/fs [n,Wn]=buttord(Fp,Sp,Pa1,Sa1); [b,a]=butter(n,Wn); w=0:0.1:pi; upto pi [h,Wc]=freqz(b,a,w); mag=abs(h); phase=angle(h); %Program for magnitude subplot(2,1,1); plot(Wc/pi,20*log(mag)); grid; xlabel('normalized frequency'); ylabel('gain in db'); title('magnitude'); %magnitude %for continous signal plot used % title at x label % title at y label % title at graph label % passband attenuations in dB % stopband attenuations in dB % passband frequency in Hz % stopband frequency in Hz %sample frequency % passband frequency in radian/sample % stopband frequency in radian/sample %order & normalized frequencies % cofficient of butterworth % value of w start frm 0 with increment 0.1 % z domain frequencies % abs command used for magnitude % angle command used for phase

15

% Program for phase

i t u

subplot(2,1,2); plot(Wc/pi,phase); grid; 0 xlabel(''normalized frequency''); ylabel(''phase in radians'); title('phase');

% plot phase % for continous signal plot used % % title at x label % title at y label % title at graph label

- 1 g a in in d b - 2 - 3 0

0 0 0

0 0 0

. 0 1

. 0 2

. 0 3 n

. 0 4 . 0 5 o r m p h a

. 0 6 a s

. 0 7 . 0 8 . 19 l i z e d e

f r

4 2 0 p h a s e in r a d ia n s - 2 - 4 0

OUTPUT:

. 0 1

. 0 2

. 0 3 n

16

. 0 4 . 0 5 o r m

. 0 6 a

. 0 7 . 0 8 . 19 l i z e d

f r

EXP 5 %Write a program to design a Chebyshev-1 low pass filter% clear all; alphap=1; %passband attenuation in db alphas=16; %stopband attenuation in db wp=.2*pi; %passband frequency in radians ws=.3*pi; %stopband frequency in radians [n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas) [b,a]=cheby1(n,alphap,wn) w=0:.01:pi; [h,ph]=freqz(b,a,w); m=20*log(abs(h)); an=angle(h); subplot(2,1,1); plot(ph/pi,m); grid; ylabel('gain in db'); xlabel('normalised frequency'); subplot(2,1,2); plot(ph/pi,an); grid; ylabel('phase in radians'); xlabel('narmalised frequency'); Output n= wn = 4 0.2000 0.0073 0.0110 0.0073 0.0018

b = 0.0018 a=

1.0000 -3.0543

3.8290 -2.2925

17

OUTPUT:

0 - 2 g a in in d b - 4 - 6 - 8 0 0 0 0 0 0 0 0 0

. 10

. 20

. 30 . 40 . 50 . 60 . 70 . 80 . 9 1 n o r m a l i s e d f r e q

4 2 p h a s e in r a d ia n s 0 - 2 - 4 0

. 10

. 20

. 30 . 40 . 50 . 60 . 70 . 80 . 9 1 n o r m a l i s e d f r e q

18

EXP-6 %Write a program to design a Chebyshev-2 low pass filter% clear all; alphap=1; %passband attenuation in db% alphas=16; %stopband attenuation in db% wp=.2*pi; %passband frequency in hz% ws=.3*pi %stopband frequency in hz% [n,wn]=cheb2ord(wp/pi,ws/pi,alphap,alphas) [b,a]=cheby2(n,alphas,wn) w=0:.01:pi; [h,ph]=freqz(b,a,w); m=abs(h); an=angle(h); subplot(2,1,1); plot(ph/pi,20*log(m)); grid; ylabel('gain in db'); xlabel('Normalised frequency'); subplot(2,1,2); plot(ph/pi,an); grid; ylabel('phase in radian'); xlabel('normalised frequency'); Output: n= 4 ws = 0.9425

wn = 0.3000 b= a= 0.1647 -0.0840 1.0000 -1.6035 0.2315 -0.0840 1.3881 -0.4993 0.1647 0.1077
19

OUTPUT:

- 5 g a in in d b

- 1

- 1 0

0 . 1 0. 2 0 . 3 0. 4 0. 5 0 . 6 0. 7 0. 8 . 1 9 N o r m a l i s

f r e

4 2 0 p h a s e in r a d ia n - 2 - 4 0 0

0 . 1 0. 2 0 . 3 0. 4 0. 5 0 . 6 0. 7 0. 8 . 1 9 n o r m a l i s

f r e

20

EXP-7 %Write a program to Convert Analog Filter into Digital Using Impulse Invariant Transformation & Bilinear Transformation % Using impulse invariant clear all; b=[1 1]; a=[1 5 6 ]; f=10; [bz,az]=impinvar(b,a,f) Output:bz = az = 0.1000 -0.0897 1.0000 -1.5595 0.6065

%numerator coefficient of analog filter %denominator coefficient of analog filter %sampling frequency

Using Bilinear Transformation b=[1 1]; %numerator cofficients of analog filter a=[1 5 6]; %denominator coefficient of analog filter f=1; %sampling frequency [bz,az]=bilinear(b,a,f)

Output:bz = az = 0.1500 1.0000 0.1000 -0.0500 0.2000 -0.0000

21

EXP- 8 %Write a program to design a 25-tap low pass filter with cutoff frequency .5pi radian using rectangular, hamming and blackman windows and plot their frequency response % clear all; wc=.5*pi; N=25;alpha=(N-1)/2;eps=.001; n=0:1:N-1; hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps)); wr=boxcar(N); %rectangular window sequence hn=hd.*wr'; %filter coefficients w=0:.01:pi; h=freqz(hn,1,w); plot(w/pi,abs(h));grid; hold on wh=hamming(N); %hamming window sequence hn=hd.*wh'; %filter coefficients w=0:.01:pi; h=freqz(hn,1,w); plot(w/pi,abs(h),'--');grid; xlabel('normalised frequency/omega/pi'); ylabel('magnitude'); hold on wb=blackman(N); %blackman window sequence hb=hd.*wb'; %filter coefficients w=0:.01:pi; h=freqz(hb,1,w); plot(w/pi,abs(h),':');grid; xlabel('normalised frequency/omega/pi'); ylabel('magnitude'); hold off

22

OUTPUT:

. 4 r e c a l a m c k t a m m n g i n a u g n l a w w r

. 2 h b 1

0 m a g n it u d e

. 8

. 6

. 4

. 2

. 10

. 20

. 30 . 40 n o r m

. 50 a

. 60 . 70 l i s e d

. 80 . 9 1 f r e q u

23

EXP- 9 %Write a program to find convolution, cross-correlation and auto-correlation of sequences using in-built convolution and correlation functions. x=[1 2 3 4];%% input sequence h=[2 3 4 5];%% impulse response l1=length(x); l2=length(h); n=0:1:l1+l2-2; n1=0:1:l1-1; n2=0:1:l2-1; subplot(2,3,1); stem(n1,x); grid; xlabel('n');ylabel('x(n)'); title('input sequence');%%to plot input sequence subplot(2,3,2); stem(n2,h); grid; xlabel('n');ylabel('h(n)'); title('impulse response sequence');%% to plot impulse response % convolution y=conv(x,h); subplot(2,3,3); stem(n,y);grid; xlabel('n');ylabel('x(n)'); title('output sequence'); %% to plot convolution of two sequences %auto-correlation n3= -(l1-1):(l1-1) y1=xcorr(x,x); subplot(2,3,4); stem(n3,y1);grid; xlabel('n');ylabel('x(n)'); title('output sequence'); %% to plot auto-correlation of a sequence

24

%cross-correlation n4= -(l1-1):(l2-1) y2=xcorr2(x,h); subplot(2,3,5); stem(n4,y2);grid; xlabel('n');ylabel('x(n)'); title('output sequence'); %% to plot cross-correlation of two sequences

25

OUTPUT:

in p u t s e q u e n c e 4 5 4 3 x (n ) h (n ) 2 1 0

i m p u l s e r e s p o n s e s e q u o e u n t cp e t s e q u e n c e u 4 0

3 0

x (n ) 0 1 n 2 3

2 0 1 0

1 n

2 n

3 0 2 5

o u tp u t s e q u e n c e 4 0

o u tp u t s e q u e n c e

3 0 2 0 x (n ) x (n ) -2 0 n 2 4 1 5 1 0 1 0 5 0 -4 0 -4 -2 0 n 2 4 2 0

26

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