digital signal processing and control system under matlab environment

25
A Practical Report on DIGITAL SIGNAL PROCESSING & CONTROL SYSTEM Under MATLAB Environment Submitted To: Submitted By: Mr. Asim Ali Khan Paramjeet Singh Jamwal Associate Professor PG/ICE/136321 Mr. Manpreet Singh Manna M.Tech Associate Professor First Semester 1 | Page info4eee | MATLAB

Upload: paramjeet-singh-jamwal

Post on 06-May-2015

1.189 views

Category:

Technology


7 download

DESCRIPTION

A practical report on Digital Signal Processing and Control System under MATLAB Environment present in M.Tech 1st Semester during session 2013-14.

TRANSCRIPT

Page 1: Digital Signal Processing and Control System under MATLAB Environment

APractical Report

on

DIGITAL SIGNAL PROCESSING&

CONTROL SYSTEMUnder MATLAB Environment

Submitted To: Submitted By:Mr. Asim Ali Khan Paramjeet Singh JamwalAssociate Professor PG/ICE/136321

Mr. Manpreet Singh Manna M.TechAssociate Professor First Semester

DEPARTMENT OF ELECTRICAL AND INSTRUMENTATION ENGINEERINGSANT LONGOWAL INSTITUTE OF ENGINEERING & TECHNOLOGY

LONGOWAL - 148106JAN 2014

1 | P a g e

info4eee | MATLAB

Page 2: Digital Signal Processing and Control System under MATLAB Environment

S.No. Command Function1. Clc Clear command window and homes the cursors2. clear all Removes all variables, globals, functions and MEX links.3. close all Closes all the open figure windows.4. zeros(N) An N-by-N matrix of zeros.5. zeros(M,N) An M-by-N matrix of zeros.6. ones(N) An N-by-N matrix of ones.7. ones(M,N) An M-by-N matrix of ones.

8. subplot(m,n,p)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.

9. stem(y)Plots the data sequence y as stems from the x axis terminated

with circles for the data value. If y is a matrix then each column is plotted as a separate series.

10. stem(x,y) Plots the data sequence y at the values specified in x.11. xlabel(‘text’) Adds text beside the x-axis on the current axis.12. ylabel(‘text’) Adds text beside the y-axis on the current axis.

13.Input(‘How many assignments’)

To get user defined value

14. sum(A) To find sum of matrix ‘A’ column wise.15. prod(A) To find product of ‘A’(column wise).16. mean(A) Find mean of ‘A’.17. length(A) To find length of matrix ‘A’.18. inv(A) To find inverse of matrix ‘A’ if possible.19. A’ It gives transpose of matrix ‘A’.20. rand(N) It generates N-N random matrix.21. rand(N,M) It generates N-M random matrix.

22.magic(N) It generates N-N matrix whose sum of all rows and columns

are equal.23. max(A) It shows largest element present in each column.24. min(A) It shows smallest element present in each column.

2 | P a g e

info4eee | MATLAB

Page 3: Digital Signal Processing and Control System under MATLAB Environment

1. Write a program to generate unit step signal.

Program:

n=input('enter lowest index= ');m=input('enter highest index= ');t=n:m;x=ones(1,m-n+1);stem(t,x);axis([n m 0 1.5]);title('Unit Step Signal')xlabel('Value of n')ylabel('Amplitude')

Command Window:

>> psj_unitstepenter lowest index= 7enter highest index= 17

Figure Window:

3 | P a g e

info4eee | MATLAB

Page 4: Digital Signal Processing and Control System under MATLAB Environment

2. Write a program to generate ramp signal.

Program:

n=input('enter lowest index= ');m=input('enter highest index= ');t=n:m;x=0:m-n;stem(t,x);axis([n m 0 m-n+1]);title('Unit Ramp Signal')xlabel('Value of n')ylabel('Amplitude')

Command Window:

>> psj_unitrampenter lowest index= 7enter highest index= 17

Figure Window:

4 | P a g e

info4eee | MATLAB

Page 5: Digital Signal Processing and Control System under MATLAB Environment

3. Write a program to generate unit impulse signal.

Program:

n=input('enter the value of impluse point= ');t=n-2:n+2;x=[zeros(1,2) ones(1,1) zeros(1,2)];stem(t,x);axis([n-2 n+2 0 1.5]);title('Unit Impulse Signal')xlabel('Value of n')ylabel('Amplitude')

Command Window:

>> psj_unitimpulseenter the value of impluse point= 7

Figure Window:

5 | P a g e

info4eee | MATLAB

Page 6: Digital Signal Processing and Control System under MATLAB Environment

4. Write a program to find the convolution of two numbers.

Program:

x=input('Enter the value of x= ');h=input('Enter the value of h= ');lx=length(x);lh=length(h);z(1,1:lx+lh-1)=zeros;l=max(lx,lh);for i=1:l y(1,2*i-1)=x(1,i)*h(1,i); z(1,2*i-1)=z(1,2*i-1)+y(1,2*i-1);end for j=2:lfor i=j:l y(1,2*i-j)=x(1,i)*h(1,i-j+1)+x(1,i-j+1)*h(1,i); z(1,2*i-j)=z(1,2*i-j)+y(1,2*i-j);endenddisp('The Convolution of x & h is');z

Command Window:

6 | P a g e

info4eee | MATLAB

>> psj_convolutionEnter the value of x= [2,-1,0,0,1,0,-1]Enter the value of h= [1,2,2,1,0,-1,0]The Convolution of x & h is

z =

2 3 2 0 0 0 2 -1 -2 -2 0 1 0

Page 7: Digital Signal Processing and Control System under MATLAB Environment

5. Write a program to generate cosine wave of different amplitude.

Program:

t=0:0.01:10;c1=0.5*cos(2*pi*t);c2=cos(4*pi*t);c3=(2/3)*cos(6*pi*t);c=1+c1+c2+c3;subplot(4,1,1),plot(t,c1);xlabel('time axis----->'),ylabel('Amplitude----->');axis([0 10 -0.7 0.7]);title('0.5*cos(2*pi*t)')subplot(4,1,2),plot(t,c2);xlabel('time axis----->'),ylabel('Amplitude----->');title('cos(4*pi*t)')axis([0 10 -1.2 1.2]);subplot(4,1,3),plot(t,c3);xlabel('time axis----->'),ylabel('Amplitude----->');title('(2/3)*cos(6*pi*t)')subplot(4,1,4),plot(t,c);xlabel('time axis----->'),ylabel('Amplitude of c----->');title('1+0.5*cos(2*pi*t)+cos(4*pi*t)+(2/3)*cos(6*pi*t)')

Command Window:

>> psj_cosine

7 | P a g e

info4eee | MATLAB

Page 8: Digital Signal Processing and Control System under MATLAB Environment

Figure Window:

8 | P a g e

info4eee | MATLAB

Page 9: Digital Signal Processing and Control System under MATLAB Environment

6. Inbuilt function for Fourier transform in MATLAB.

S.No. Command Function

1.

FFT(X)

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)N-point FFT padded with zeros if X has less than N points and truncated if it has more.

FFT(X,N,DIM) FFT operation across the dimension DIMs.

2.FFT2(X)

Two-dimensional Fourier transform of matrix X. If X is a vector, the result will have the same orientation.

FFT2(X,MROWS,NCOLS)Pads matrix X with zeros to size MROWS-by-NCOLS before transforming.

3.

FFTN(X)N-dimensional discrete Fourier transform of the N-D array X. If X is a vector, the output will have the same orientation.

FFTN(X,SIZ)

Pads X so that its size vector is SIZ before performing the transform. If any element of SIZ is smaller than the corresponding dimension of X, then X will be cropped in that dimension.

4.

IFFT(X) Inverse discrete Fourier transform of X.IFFT(X,N) N-point inverse transform.

IFFT(X,N,DIM)Inverse discrete Fourier transform of X across the dimension DIM.

IFFT(..., 'symmetric')

IFFT to treat X as conjugate symmetric along the active dimension. This option is useful when X is not exactly conjugate symmetric merely because of round-off error.

IFFT(..., 'nonsymmetric')IFFT to make no assumptions about the symmetry of X.

5.

IFFT2(F)Two-dimensional inverse Fourier transform of matrix F. If F is a vector, the result will have the same orientation.

IFFT2(F,MROWS,NCOLS)Pads matrix F with zeros to size MROWS-by-NCOLS before transforming.

IFFT2(..., 'symmetric')

IFFT2 to treat F as conjugate symmetric in two dimensions so that the output is purely real. This option is useful when F is not exactly conjugate symmetric merely because of round-off error.

IFFT2(..., 'nonsymmetric')IFFT2 to make no assumptions about the symmetry of F.

6.IFFTN(F)

N-dimensional inverse discrete Fourier transform of the N-D array F. If F is a vector, the result will have the same orientation.

IFFTN(F,SIZ) Pads F so that its size vector is SIZ before performing the transform. If any element of SIZ is

9 | P a g e

info4eee | MATLAB

Page 10: Digital Signal Processing and Control System under MATLAB Environment

smaller than the corresponding dimension of F, then F will be cropped in that dimension.

IFFTN(..., 'symmetric')

IFFTN to treat F as multidimensionally conjugate symmetric so that the output is purely real. This option is useful when F is not exactly conjugate symmetric merely because of round-off error.

IFFTN(..., 'nonsymmetric')IFFTN to make no assumptions about the symmetry of F.

7.DFTMTX(N)

N-by-N complex matrix of values around the unit-circle whose inner product with a column vector of length N yields the discrete Fourier transform of the vector. If X is a column vector of length N, then DFTMTX(N)*X yields the same result as FFT(X); however, FFT(X) is more efficient.

CONJ(DFTMTX(N))/N The inverse discrete Fourier transform matrix.8.

S = SPECTROGRAM(X)

Spectrogram of the signal specified by vector X in the matrix S. By default, X is divided into eight segment with 50% overlap, each segment is windowed with a Hamming window. The number of frequency points used to calculate the discrete Fourier transforms is equal to the maximum of 256 or the next power of two greater than the length of each segment of X. If X cannot be divided exactly into eight segments, X will be truncated accordingly.

S = SPECTROGRAM(X,WINDOW)

when WINDOW is a vector, divides X into segments of length equal to the length of WINDOW, and then windows each segment with the vector specified in WINDOW. If WINDOW is an integer, X is divided into segments of length equal to that integer value, and a Hamming window of equal length is used. If WINDOW is not specified, the default is used.

S = SPECTROGRAM(X,WINDOW,NOV

ERLAP)

the number of samples each segment of X overlaps. NOVERLAP must be an integer smaller than WINDOW if WINDOW is an integer. NOVERLAP must be an integer smaller than the length of WINDOW if WINDOW is a vector. If NOVERLAP is not specified, the default value is used to obtain a 50% overlap.

S = SPECTROGRAM(X,WINDOW,NOV

ERLAP,NFFT)

specifies the number of frequency points used to calculate the discrete Fourier transforms. If NFFT is not specified, the default NFFT is used.

S = SPECTROGRAM(X,WINDOW,NOV

ERLAP,NFFT,Fs)

Fs is the sampling frequency specified in Hz. If Fs is specified as empty, it defaults to 1 Hz. If it is not specified, normalized frequency is used.

[S,F,T] = SPECTROGRAM(...)

a vector of frequencies F and a vector of times T at which the spectrogram is computed. F has length equal to the number of rows of S. T has length k and its value corresponds to the center of each segment.

[S,F,T] = where F is a vector of frequencies in Hz computes

10 | P a g e

info4eee | MATLAB

Page 11: Digital Signal Processing and Control System under MATLAB Environment

SPECTROGRAM(X,WINDOW,NOVERLAP,F,Fs)

the spectrogram at those frequencies using the Goertzel algorithm. The specified frequencies in F are rounded to the nearest DFT bin commensurate with the signal's resolution.

[S,F,T,P] = SPECTROGRAM(...)

P is a matrix representing the Power Spectral Density (PSD) of each segment. For real signals, SPECTROGRAM returns the one-sided modified periodogram estimate of the PSD of each segment; for complex signals and in the case when a vector of frequencies is specified, it returns the two-sided PSD.

SPECTROGRAM(...)

The PSD estimate for each segment on a surface in the current figure with no output arguments. It uses SURF(f,t,10*log10(abs(P)) where P is the fourth output argument. A trailing input string, FREQLOCATION, controls where MATLAB displays the frequency axis. This string can be either 'xaxis' or 'yaxis'. Setting this FREQLOCATION to 'yaxis' displays frequency on the y-axis and time on the x-axis. The default is 'xaxis' which displays the frequency on the x-axis. If FREQLOCATION is specified when output arguments are requested, it is ignored.

9. [X,T] = INSTDFFT(XHAT,LOWB,UPPB)

the inverse nonstandard FFT of XHAT, on a power-of-2 regular grid (non necessarily integers) on the interval [LOWB,UPPB]. Output arguments are X the recovered signal computed on the time interval T given by T = LOWB + [0:n-1]*(UPPB-LOWB)/n, where n is the length of XHAT. Outputs are vectors of length n. The length of XHAT must be a power of 2.

10 [XHAT,OMEGA] = NSTDFFT(X,LOWB,UPPB)

a nonstandard FFT of signal X sampled on a power-of-2 regular grid (non necessarily integers) on the interval [LOWB,UPPB]. Output arguments are XHAT the shifted FFT of computed on the interval OMEGA given by OMEGA = [-n:2:n-2]/(2*(UPPB-LOWB)) where n is the length of X. Outputs are vectors of length n. Length of X must be a power of 2.

11 | P a g e

info4eee | MATLAB

Page 12: Digital Signal Processing and Control System under MATLAB Environment

7. Write a program to find the Fourier transform of cosine function.

Program:

t=0:0.01:10;x=cos(2*pi*t);y=fft(x);z=ifft(y);subplot(3,1,1);plot(x);title('Cosine Wave')subplot(3,1,2);plot(y);title('FFT of Cosine Wave')subplot(3,1,3);plot(z);title('IFFT')

Command Window:

>> psj_fourier

Figure Window:

12 | P a g e

info4eee | MATLAB

Page 13: Digital Signal Processing and Control System under MATLAB Environment

8. Write a program to find the DFT of given sequence.

Program:

h=input('enter sequence= ');N=input('enter N=');n=length(h);x=[h,zeros(1,N-n)];y=zeros(N,1);for k=1:N,for n=1:N, y(k)=y(k)+x(n)*exp(-i*2*pi*(k-1)*(n-1)/N);endenddisp('DFT of x=');y

Command Window:

>> psj_dftenter sequence= [1 2 4 8 16 32 64 128]enter N=8DFT of x=

y =

1.0e+002 *

2.5500 0.4864 + 1.6607i -0.5100 + 1.0200i -0.7864 + 0.4607i -0.8500 - 0.0000i -0.7864 - 0.4607i -0.5100 - 1.0200i 0.4864 - 1.6607i

13 | P a g e

info4eee | MATLAB

Page 14: Digital Signal Processing and Control System under MATLAB Environment

9. Write a program to find the IDFT of given sequence.

Program:

h=input('enter sequence = ');N=input('enter N = ');n=length(x);x=[h,zeros(1,N-n)];y=zeros(N,1);for n=1:N,for k=1:N, y(k)=y(k)+(1/N)*x(n)*exp(i*2*pi*(k-1)*(n-1)/N);endenddisp('IDFT of Sequence = ');y

Command Window:

>> psj_idftenter sequence = [36 -4+9.656i -4+4i -4+1.656i -4 -4-1.656i -4-4i -4-9.656i]enter N = 8IDFT of Sequence =

y =

1.0000 2.0003 + 0.0000i 3.0000 + 0.0000i 4.0003 5.0000 - 0.0000i 5.9997 - 0.0000i 7.0000 + 0.0000i 7.9997 - 0.0000i

14 | P a g e

info4eee | MATLAB

Page 15: Digital Signal Processing and Control System under MATLAB Environment

10. Write a program to find the DFT of given sequence using matrix.

Program:

x=input('Enter the sequence = ');n=length(x);w=dftmtx(n);y=[w*x'];w;disp('DFT of Sequence');y

Command Window:

>> psj_dftumtxEnter the sequence = [1 2 3 4 4 3 2 1]DFT of Sequence

y =

20.0000 -5.8284 - 2.4142i 0 -0.1716 - 0.4142i 0 -0.1716 + 0.4142i 0 -5.8284 + 2.4142

15 | P a g e

info4eee | MATLAB

Page 16: Digital Signal Processing and Control System under MATLAB Environment

11. Write a program to find the IDFT using matrix.

Program:

x=input('enter the sequence = ');n=length(x);w=conj(dftmtx(n))/n;y=[inv(w)*x']/n;w;disp('IDFT of Sequence');y

Command Window:

>> psj_idftumtxenter the sequence = [36 -4+9.656i -4+4i -4+1.656i -4 -4-1.656i -4-4i -4-9.656i]IDFT of Sequence

y =

1.0000 + 0.0000i 2.0003 + 0.0000i 3.0000 - 0.0000i 4.0003 - 0.0000i 5.0000 + 0.0000i 5.9997 + 0.0000i 7.0000 - 0.0000i 7.9997 + 0.0000i

16 | P a g e

info4eee | MATLAB

Page 17: Digital Signal Processing and Control System under MATLAB Environment

12. Write a program to generate DFT Matrix without using direct command.

Program:

N=input('Enter the value of N = ');x=zeros(N,N);for j=1:N, n=N*(j-1);for k=1:N, x(k+n)=exp(-i*2*pi*(j-1)*(k-1)/N); endenddisp('Resultant matrix ');x

Command Window:

>> psj_dftmtxEnter the value of N = 4Resultant matrix

x =

1.0000 1.0000 1.0000 1.0000 1.0000 0.0000 - 1.0000i -1.0000 - 0.0000i -0.0000 + 1.0000i 1.0000 -1.0000 - 0.0000i 1.0000 + 0.0000i -1.0000 - 0.0000i 1.0000 -0.0000 + 1.0000i -1.0000 - 0.0000i 0.0000 - 1.0000i

17 | P a g e

info4eee | MATLAB

Page 18: Digital Signal Processing and Control System under MATLAB Environment

13. Write a program to find the step response and impulse response of transfer function.

Program:

sys=tf([8 18 31],[1 6 14 24])subplot(2,1,1)step(sys)subplot(2,1,2)impulse(sys)

Command Window:

>> psj_sni Transfer function: 8 s^2 + 18 s + 31-----------------------s^3 + 6 s^2 + 14 s + 24

Figure Window:

18 | P a g e

info4eee | MATLAB

Page 19: Digital Signal Processing and Control System under MATLAB Environment

14. Design a system to convert Fahrenheit to degree Celsius.

Setup:

19 | P a g e

info4eee | MATLAB

Page 20: Digital Signal Processing and Control System under MATLAB Environment

15. Design a system for torque converter.

Setup:

--------------------------------------A

Group--------------------------------------

20 | P a g e

info4eee | MATLAB