You are on page 1of 83

DIGITAL SIGNAL PROCESSING LAB EX.

NO:01

GENERATION OF SIGNALS
OBJECTIVE: To know about how to generate various basic signals using MATLAB AIM:

To write a MATLAB program for the generation of various basic signals.

THEORY:
A Signal is defined as any physical quantity that varies with time, space, or any other independent variable, For example, the functions x1(t)=2t and x2(t)=t2 describe two signals, one that varies linearly with independent variable t and a second that varies quadratically with t. A System is defined as a physical device that performs an operation on a signal, For example, a filter used to reduce the noise corrupting a desired information bearing signal is called a system. Signal processing is any operation that changes the characteristics of a signal. These characteristics include the amplitude, shape, phase and frequency content of the signal. Classification of signals: Signal in general can be of two types. 1. Continuous-time signal: A signal that varies continuously with time. It can be represented as x(t), where time t represents the independent variable. Example: sinusoidal signal.

Fig. 1.1 Continuous Time Signal 1

DIGITAL SIGNAL PROCESSING LAB 2. Discrete-time signal: A signal that has values only at discrete instants of time. One way of obtaining discrete-time signal is, sampling a continuous-time signal at regular intervals. It can be represented as x(nT) where n=0,1,2n, and T is the time interval between two consecutive signal values. A discrete-time signal is discrete in time but continuous in amplitude. Another form of discrete-time signal is a digital signal which is discrete in both time and amplitude. These signals are called digital because their samples are represented by numbers or digits.

Fig.1.2 Discrete Time Signal Standard Discrete-time signals: 1. Unit sample sequence: The unit sample sequence (unit impulse) is defined as (n) = 1 for n = 0 = 0 for n 0 The graphical representation of (n) is as shown in Fig.

Fig. 1.3 Unit Sample Sequence 2. Unit step sequence: The unit step sequence is defined as u(n) = 1 for n 0 = 0 for n < 0 The graphical representation of u(n) is shown in Fig. 2

DIGITAL SIGNAL PROCESSING LAB

Fig. 1.4

Unit Step Sequence

3. Unit ramp sequence : The unit ramp sequence is denoted as ur (n) and is defined as ur (n) = n for n 0 = 0 for n < 0 The graphical representation of ur (n) is shown in Fig.

Fig. 1.5 Unit Ramp Sequence 4. Exponential sequence The exponential signal is a sequence of the form x(n) = an for all n shows exponential sequences for different values of a.

DIGITAL SIGNAL PROCESSING LAB

Fig. 1.6 Exponential Sequences

UNIT STEP
ALGORITHM:

1.Clear Command Window [an alternative to the clc function, use Clear Command Window in the MATLAB desktop Edit menu.] 2.Get the minimum value of time 3.Get the maximum value time 4.Iterate the for loop with colon operator. 5.Plot amplitude against time

PROGRAM:

clc; clear all; close all; a=input('enter minimum value'); b=input('enter maximum value'); u=[a:1:b]; x=1; for s=[a:1:b] if(s<0) 4

DIGITAL SIGNAL PROCESSING LAB t(x)=0; else t(x)=1; end x=x+1; end plot(u,t);

INPUT: Enter the minimum value: 0 Enter the maximum value: 5 OUTPUT:

2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0

0.5

1.5

2.5

3.5

4.5

UNIT IMPULSE

DIGITAL SIGNAL PROCESSING LAB


ALGORITHM:

1. Clear Command Window [an alternative to the clc function, use Clear Command Window in the MATLAB desktop Edit menu.] 2.Get the minimum value of time 3. Get the maximum value of time 4.Zeros([m n]) returns an m-by-n matrix of zeros. 5. Ones([m n]) returns an m-by-n matrix of ones 6. Plot amplitude against time
[stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of the same size.]

PROGRAM:

clc; clear all; close all; t=-2:1:2; y=[zeros(1,2),ones(1,1),zeros(1,2)]; subplot(2,2,1); stem(t,y); ylabel('amplitude'); xlabel('n');

OUTPUT:

a pt d ml u e i

0 . 5

0 2

0 n

UNIT RAMP 6

DIGITAL SIGNAL PROCESSING LAB


ALGORITHM:

1. Clear Command Window [an alternative to the clc function, use Clear Command Window in the MATLAB desktop Edit menu.] 2. Get the minimum value of time 3. Get the maximum value of time 4. Plot amplitude against time
PROGRAM:

clc; clear all; close all; a=input('enter minimum value'); b=input('enter maximum value'); w=[a:1:b]; x=1; for d=[a:1:b] f(x)=d; x=x+1; end plot(w,f);
INPUT: Enter minimum value Enter maximum value OUTPUT:
1 0 9 8 7 6 5 4 3 2 1 0 0

0 10

1 0

DIGITAL SIGNAL PROCESSING LAB

EXPONENTIAL
ALGORITM:

1.Get the amplitude of the signal 2.Get the time period 3.The exp function is an elementary function that operates element-wise on arrays. Its domain includes complex numbers. Y = exp(X) returns the exponential for each element of X. 4.Plot amplitude against time period PROGRAM: clc; clear all; close all; a=input('enter amplitude'); b=input('enter time'); y=exp(a:.01:b); x=[a:.01:b]; plot(x,y);
INPUT: Enter amplitude Enter time period OUTPUT:
7 .5 7 6 .5 6 5 .5 5 4 .5 4 3 .5 3 2 .5

1 2

1 .1

1 .2

1 .3

1 .4

1 .5

1 .6

1 .7

1 .8

1 .9

DIGITAL SIGNAL PROCESSING LAB

SINE
ALGORITHM:

1.Get the amplitude of the signal 2.Get the constant value 3.Get the minimum range of time 4.Get the maximum range of time 5.The sin function operates element-wise on arrays. The function's domains and ranges include complex values. All angles are in radians. Y = sin(X) returns the circular sine of the elements of X. 6.Plot the amplitude against time
PROGRAM:

clc; clear all; close all; a=input('enter amplitude'); b=input('enter constant value'); t1=input('enter minimum value'); t2=input('enter maximum value'); t=[t1:.01:t2]; plot(b*sin(b*3.14*t));
INPUT:

enter amplitude enter constant value enter minimum value enter maximum value
OUTPUT:
1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1

: : : :

1 1 1 5

50

100

150

200

250

300

350

400

450

DIGITAL SIGNAL PROCESSING LAB

COSINE
ALGORITHM:

1.Get the amplitude of the signal 2.Get the constant value 3.Get the minimum range of time 4.Get the maximum range of time 5.The cos function operates element-wise on arrays. The function's domains and ranges include complex values. All angles are in radians. Y = cos(X) returns the circular cosine for each element of X. 6.Plot the amplitude against time
PROGRAM:

clc; clear all; close all; a=input('enter amplitude'); b=input('enter constant value'); t1=input('enter minimum value'); t2=input('enter maximum value'); t=[t1:.01:t2]; plot(a*cos(b*3.14*t));
INPUT:

enter amplitude enter constant value enter minimum value enter maximum value
OUTPUT:
1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1

: : : :

1 1 0 5

100

200

300

400

500

600

10

DIGITAL SIGNAL PROCESSING LAB

RESULT:

Thus MATLAB programs to generate various signals are written and executed successfully

11

DIGITAL SIGNAL PROCESSING LAB

VIVA QUESTIONS
1. The

impulse response exits at t\n=0 or t\n=t0\n0

2. The ramp signal can be expressed as n=an for a as amplitude and n as the discrete time 3. The command used to clear the command window is clc 4. The each and every statement of the MATLAB statement ends with operator ;(semi colon) 5. The MATLAB command used to add the zero matrix \array having the number of rows as r and columns as c is zeros. 6. The MATLAB command that used to accept the used defined input data is INPUT. 7. The MATLAB command used to plot the discrete signal is STEM. 8. The MATLAB command used to plot the continuous signal is PLOT 9. The MATLAB command that used to perform the exponent function is EXP 10. The MATLAB command that is pi represents 3.14 pi 3.1415926535897.... pi = 4*atan(1) = imag(log(-1)) = 3.1415926535897.... 11. The MATLAB command that creates axes in the titled position is SUBPLOT 12A power signal is a periodic signal. 13. The integral of unit step is function is RAMP function of unit slope 14. What is meant by signal processing? Any operation that changes the characteristics of a signal is called signal processing. 15. Define a signal. Any physical quantity that varies with time, space or any other independent variable is called a signal. 16. What do you mean by a system? A physical device that performs an operation on a signal is defied as a system. 17. Mention some of the applications of DSP. Speech processing Image processing Telecom

12

DIGITAL SIGNAL PROCESSING LAB Define DFT of a discrete time sequence. The DFT is used to convert a finite discrete time sequence x(n) to and N-point frequency domain sequence denoted by X(k). The N-point DFT of a finite duration sequence x (n) of length L, where L<=N is defined as

2. Define IDFT. The IDFT is used to convert the N-point frequency domain sequence X(k) to an N-point time domain sequence. The IDFT of the sequence X(k) of length N is defined as

3. What is the relation between DTFT and DFT? Let x (n) be a discrete time sequence. Now DTFT{x(n)}=X(w) or FT{x(n)}=X(w) which can be obtained by sampling one period of X(w) at N equal intervals. 4. What is the drawback in Fourier Transform and how it is overcome? The drawback in Fourier transform is that it is a continuous function of w and so it cannot be processed by digital system. This drawback is overcome by using Discrete Fourier transform. The DFT converts the continuous function of w to a discrete function of w.

13

DIGITAL SIGNAL PROCESSING LAB EX NO:02

CONVOLUTION
OBJECTIVE: To implement the circular & linear convolution using MATLAB AIM:

To convolute both linear and circular for the two given sequences using MATLAB program. LINEAR CONVOLUTION:
ALGORITHM:

1.Get two signals x(n) and h(n) in matrix form. 2.The convolute signal is denoted as y(n). 3.y(n) is given by the formula y(n)= x(k)h(n-k) 4. n = length(X) returns the size of the longest dimension of X. If X is a vector, this is the same as its length. 5. 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. [subplot divides the current figure into rectangular panes that are numbered rowwise] 6.Stop the program
PROGRAM:

clc; clear all; x=[1,0,1,2,-1,3,2]; N1=length(x); n=0:1:N1-1; subplot(2,2,1),stem(n,x); xlabel('n'),ylabel('x(n)'); h=[1,1,2,2,1,1]; N2=length(h); n1=0:1:N2-1; subplot(2,2,2),stem(n1,h); xlabel('n'),ylabel('h(n)'); y=conv(x,h) n2=0:1:N1+N2-2; subplot(2,1,2),stem(n2,y); xlabel('n'),ylabel('y(n)'); title('Convolution of two sequences');

14

DIGITAL SIGNAL PROCESSING LAB


OUTPUT:
3 2 x(n) 1 0 -1 h(n) 0 2 n Convolution of two sequences 15 4 6 2 1.5 1 0.5 0

2 n

10 y(n) 5 0 0

6 n

10

12

CIRCULAR CONVOLUTION ALGORITHM: 1. 2. 3. 4. 5. 6. 7. 8. Program: % Program for Circular Convolution clc; clear all; close all; g=input('enter the sequence'); h=input('enter the sequence'); N1=length(g); N2=length(h); 15 Start the program. Get the two input sequence x(n) and h(n). Calculate the length of two input sequence and find for the output sequence. Append zeros. Compute the circular convolution of the two input sequences. Execute the program, display the result and verify it theoretically. Plot the output graph for each sequence. Stop the process.

DIGITAL SIGNAL PROCESSING LAB subplot(2,2,1); n1=0:1:N1-1 stem(n1,g); title('g(n)'); ylabel('amplitude --->'); xlabel('n --->'); subplot(2,2,2); n2=0:1:N2-1 stem(n2,h); title('h(n)'); ylabel('amplitude --->'); xlabel('n --->'); N=max(N1,N2); if(N1<=N); g1=[g,zeros(1,N-N1)]; end if(N2<=N); h1=[h,zeros(1,N-N2)]; end for n=1:N y(n)=0; for i=1:N j=n-i+1; if(j<=0) j=N+j; end y(n)=y(n)+g1(i)*h1(j); end end disp(y); subplot(2,2,3); n=0:1:N-1; stem(n,y); title('output'); ylabel('amplitude --->'); xlabel('n --->')
INPUT: ENTER THE SEQUENCE:[1,1,1,1,1] ENTER THE SEQUENCE;[1,1,1,1]

16

DIGITAL SIGNAL PROCESSING LAB


OUTPUT:

g(n) 1 amplitude ---> amplitude ---> 1

h(n)

0.5

0.5

2 n ---> output

1 n --->

4 amplitude ---> 3 2 1 0

2 time --->

RESULT:

Thus MATLAB program to perform convolution was written and executed successfully

17

DIGITAL SIGNAL PROCESSING LAB


VIVA QUESTIONS

1. What is meant by linear convolution? The linear convolution of two sequences x(n) of L no.of samples and h(n) of M no.of samples produce a result y(n) which contains N=L+M-1 samples. 2. What is meant by circular convolution? The circular convolution of two sequences x(n) of L no.of samples and h(n) with M samples, after convolution y(n) will contain N=Max (L,M) samples. 3. Why linear convolution is important in DSP? The response or output of LTI discrete time system for any input x(n) is Given by linear convolution of the input x(n) and the impulse response h(n) of the system. 4. Why circular convolution is important in DSP? The DFT supports only circular convolution. Hence, when DFT techniques are employed, the result of linear convolution are obtained only via circular convolution. 5. What are the properties of linear convolution? i) ii) iii) Commutative property. Associative property. Distributive property

6. What is the advantage of linear convolution? It can be used to find the response of a linear or a linear filter. 7. Mention the method of circular convolution? i) ii) Concentric circle method. Matrix Multiplication method.

8. What are the uses of zero padding? a) b) c) We can get better display of the frequency spectrum. With zero padding, the DFT can be used in linear filtering. In circular convolution, when the two input sequences are of different size, then they are converted to equal size by zero padding.

18

DIGITAL SIGNAL PROCESSING LAB

9. How will you perform linear convolution via circular convolution? To perform linear convolution via circular convolution, convert the input sequence to N1+N2-1 point sequences by padding with zeros. 10. Where the circular convolution uses in DSP? The DFT is used for the analysis and design of discrete time systems Using Digital Computers. 11. The MATLAB command used to convolute the two sequence is CONV 12. The MATLAB command used to display the processed sequence is DISP. 13. The ROUND command rounds the element to the nearest integers 14. The LENGTH command returns the length of vector 15. When we implement the linear convolution via circular convolution we have to use ZERO PADDING concept.

19

DIGITAL SIGNAL PROCESSING LAB

EX.NO:03

DESIGN OF IIR FILTERS


OBJECTIVE: To implement IIR (Butterworth Lowpass, Highpass, Bandpass, Band stop) filter using MATLAB

AIM: To write a MATLAB program to design a Butterworth low pass, high pass. band pass & band reject filter and also convert a analog filter into digital filter. THEORY: A filter is one, which rejects unwanted frequencies from the input signal and allow the desired frequencies to obtain the required shape of output signal. The range of frequencies of signal that are passed through the filter is called pass band and those frequencies that are blocked is called stop band. The filters are of different types. 1. Low pass filter 2. High pass filter 3. Band pass filter 4. Band reject filter Design of Digital filters from Analog filters: The most common technique used for designing IIR digital filters known as indirect method, involves first designing an analog prototype filter and then transforming the prototype to a digital filter. For the given specification of a digital filter, the derivation of the digital filter transfer function requires three steps. 1. 2. 3. Map the desired digital filter specification into those for an equivalent analog filter. Derive the analog transfer function for the analog prototype. Transform the transfer function of the analog prototype into an equivalent digital filter transfer function.

Fig 5.1 Shows the magnitude response of a digital low pass filter. The various parameters in the figure are, p = Pass band frequency in radians s = Stop band frequency in radians c = 3-db cutoff frequency in radians = Parameter specifying allowable pass band 20

DIGITAL SIGNAL PROCESSING LAB = Parameter specifying allowable stop band

Fig 5.1 Magnitude response of a Low pass filter Design of IIR filters from analog filters: There are several methods that can be used to design digital filters having an infinite duration unit sample response. The techniques described are all based on converting an analog filter into digital filter. If the conversion technique is to be effective, it should posses the following desirable properties. 1. 2. The j -axis in the s-plane should map into the unit circle in the z-plane. Thus there will be a direct relationship between the two frequency variables in the two domains. The left-half plane of the s-plane should map into inside of the unit circle in the zplane. Thus a stable analog filter will be converted to a stable digital filter.

The four most widely used methods for digitizing the analog filter into a digital filter include, 1. 2. 3. 4. Approximation of derivatives. The impulse invariant transformation. The bilinear transformation. The matched z-transformation.

Impulse invariant transformation: 21

DIGITAL SIGNAL PROCESSING LAB In this method of digitizing an analog filter, the impulse response of resulting digital filter is a sampled version of the impulse response of the analog filter. First we express the transfer function of analog filter in partial fraction form,

Then the transfer function of digital filter can be obtained using the transformation. (i.e),

Bilinear transformation: The bilinear transformation is a mapping that transforms the left half of s-plane into the unit circle in the z-plane only once, thus avoiding aliasing of frequency components. The mapping from the s-plane to the z-plane is in bilinear transformation is

22

DIGITAL SIGNAL PROCESSING LAB ALGORITHM:

BUTTERWORTH LOW PASS FILTER


1.Get the pass band and stop band ripples. 2.Get the pass band and stop band edge frequencies. 3.Get the sampling frequency. 4.Calculate the order the filter 5. buttord calculates the minimum order of a digital or analog Butterworth filter required to meet a set of filter design specifications. 6. butter(d,'matchexactly',match) returns a Butterworth IIR filter where the filter response matches the specified response exactly for one filter band. 7.Find the filter coefficients. 8.Draw the magnitude and phase response.

BUTTERWORTH HIGHPASS FILTER


1.Get the pass band and stop band ripples. 2.Get the pass band and stop band edge frequencies. 3.Get the sampling frequency. 4.Calculate the order the filter 5. Buttord calculates the minimum order of a digital or analog Butterworth filter required to meet a set of filter design specifications. 6. Butter(d,'matchexactly',match) returns a Butterworth IIR filter where the filter response matches the specified response exactly for one filter band. 7.Find the filter coefficients. 8.Draw the magnitude and phase response.

BUTTERWORTH BANDPASS FILTER


1.Get the pass band and stop band ripples. 2.Get the pass band and stop band edge frequencies. 3.Get the sampling frequency. 4.Calculate the order the filter 5. Buttord calculates the minimum order of a digital or analog Butterworth filter required to meet a set of filter design specifications. 6. Butter(d,'matchexactly',match) returns a Butterworth IIR filter where the filter response matches the specified response exactly for one filter band. 7.Find the filter coefficients. 8.Draw the magnitude and phase response.

BUTTERWORTH BANDSTOP FILTER


23

DIGITAL SIGNAL PROCESSING LAB

1.Get the passband and stopband ripples 2.Get the passband and stopband edge frequencies 3.Get the sampling frequencies 4.Calculate the order of the filter 5. Buttord calculates the minimum order of a digital or analog Butterworth filter required to meet a set of filter design specifications. 6. Butter(d,'matchexactly',match) returns a Butterworth IIR filter where the filter response matches the specified response exactly for one filter band. 7.Find the filter co-efficients 8.Draw the magnitude and phase response
PROGRAM:

clc; close all; clear all; format long rp=input('enter the passband ripple'); rs=input('enter the stop band ripple'); wp=input('enter the pass band frequency'); ws=input('enter the stop band frequency'); fs=input('enter the sampling frequency'); w1=2*wp/fs;w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs,'s'); [z,p,k]=butter(n,wn); [b,a]=zp2tf(z,p,k); [b,a]=butter(n,wn,'s'); w=0:.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1);plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); subplot(2,1,2); plot(om/pi,an); xlabel('(b) normalised frequency-->'); ylabel('phase in radians-->'); pause; format long rp=input('enter the passband ripple'); rs=input('enter the stop band ripple'); wp=input('enter the pass band frequency'); ws=input('enter the stop band frequency'); fs=input('enter the sampling frequency'); w1=2*wp/fs;w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs,'s'); 24

DIGITAL SIGNAL PROCESSING LAB [b,a]=butter(n,wn,'high','s'); w=0:.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1);plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); subplot(2,1,2); plot(om/pi,an); xlabel('(b) normalised frequency-->'); ylabel('phase in radians-->'); pause; format long rp=input('enter the passband ripple'); rs=input('enter the stop band ripple'); wp=input('enter the pass band frequency'); ws=input('enter the stop band frequency'); fs=input('enter the sampling frequency'); w1=2*wp/fs;w2=2*ws/fs; [n]=buttord(w1,w2,rp,rs,'s'); wn=[w1,w2]; [b,a]=butter(n,wn,'bandpass','s'); w=0:.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1);plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); subplot(2,1,2); plot(om/pi,an); xlabel('(b) normalised frequency-->'); ylabel('phase in radians-->'); pause; format long rp=input('enter the passband ripple'); rs=input('enter the stop band ripple'); wp=input('enter the pass band frequency'); ws=input('enter the stop band frequency'); fs=input('enter the sampling frequency'); w1=2*wp/fs;w2=2*ws/fs; [n]=buttord(w1,w2,rp,rs,'s'); wn=[w1,w2]; [b,a]=butter(n,wn,'stop','s'); w=0:.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); 25

DIGITAL SIGNAL PROCESSING LAB an=angle(h); subplot(2,1,1);plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); subplot(2,1,2); plot(om/pi,an); xlabel('(b) normalised frequency-->'); ylabel('phase in radians-->');

BUTTERWORTH LOW PASS FILTER


INPUT:

enter the passband ripple 0.15 enter the stop band ripple 60 enter the pass band frequency 1500 enter the stop band frequency 3000 enter the sampling frequency 7000
OUTPUT:
100 gain in db--> 0 -100 -200 -300

0.1

0.2

0.3 0.4 0.5 0.6 0.7 (a)normalised frequency-->

0.8

0.9

4 phase in radians--> 2 0 -2 -4

0.1

0.2

0.3 0.4 0.5 0.6 0.7 (b) normalised frequency-->

0.8

0.9

26

DIGITAL SIGNAL PROCESSING LAB

BUTTERWORTH HIGH PASS FILTER


INPUT:

enter the stop band ripple 40 enter the pass band frequency 2000 enter the stop band frequency 3500 enter the sampling frequency 8000
OUTPUT:
200 gain in db-->

-200

-400

0.1

0.2

0.3 0.4 0.5 0.6 0.7 (a)normalised frequency-->

0.8

0.9

4 phase in radians--> 2 0 -2 -4

0.1

0.2

0.3 0.4 0.5 0.6 0.7 (b) normalised frequency-->

0.8

0.9

27

DIGITAL SIGNAL PROCESSING LAB

BUTTERWORTH BAND PASS FILTER


INPUT: enter the stop band ripple 36 enter the pass band frequency 1500 enter the stop band frequency 2000 enter the sampling frequency 6000 OUTPUT:

500 gain in db-->

-500

-1000

0.1

0.2

0.3 0.4 0.5 0.6 0.7 (a)normalised frequency-->

0.8

0.9

4 phase in radians--> 2 0 -2 -4

0.1

0.2

0.3 0.4 0.5 0.6 0.7 (b) normalised frequency-->

0.8

0.9

28

DIGITAL SIGNAL PROCESSING LAB

BUTTERWORTH BAND REJECT FILTER

INPUT:

enter the passband ripple 0.28 enter the stop band ripple28 enter the pass band frequency1000 enter the stop band frequency1400 enter the sampling frequency5000
OUTPUT:

5 0 gain in db--> 0 -5 0 -1 0 0 -1 0 5

0 .1

0 .2

0 .3

0 .4 0 .5 0 .6 (a o a d fre u n )n rm lise q e cy-->

0 .7

0 .8

0 .9

phase in radians-->

4 2 0 -2 -4

0 .1

0 .2

0 .3 0 .4 0 .5 0 .6 (b n rm lise fre u n ) o a d q e cy-->

0 .7

0 .8

0 .9

29

DIGITAL SIGNAL PROCESSING LAB

RESULT:

Thus MATLAB program to design Butterworth low pass, high pass, band pass & band reject filters was written and executed successfully.

VIVA QUESTIONS 30

DIGITAL SIGNAL PROCESSING LAB 1.IIR filters has INFINITE memory 2.IF the impulse response sequence is of finite direction, then the system is called on FIR system 3. IF the impulse response sequence is of infinite direction, then the system is called on IIR system 4.When an MATLAB program is executed, if the error occurs then the errors proper code can be viewed with the help of HELP ON SELECTION. 5. When an MATLAB program is executed, if the error occurs then the error can be evaluated with the help of EVALUATE SELECTION 6. When an MATLAB program is executed, if the error occurs then the missing thing can be found with the help of open selection. 7.More memory is required in the realization of IIR system using DIRECT FORM I structure. 8.If the o/p of a system depends on the past output values, then the is called RECURSIVE system. 9.If the o/p of a system does not depends on the past output values, then the is called NON RECURSIVE system. 10.The MATLAB commands FREQZ returns the N-point complex frequency response vector H and the Npoint frequency vector W in radians/sample of the filter 11.The MATLAB commands FREQS returns the complex frequency response vector H of the filter B/A 12.The MATLAB command ABS returns the absolute value. 13..The ANGLE command computes the phase angle.

EX.NO:04 31

DIGITAL SIGNAL PROCESSING LAB

DESIGN OF FIR FILTERS


OBJECTIVE: To implement FIR (Lowpass, Highpass, Bandpass, Band stop) filter using various windowing techniques in MATLAB

AIM: To design a FIR low pass, high pass, band pass &band reject filter in MATLAB using Rectangular, Hamming, Hanning, Blackman &Kaiser windowing technique. ALGORITHM:

LOW PASS FILTER USING RECTANGULAR WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function boxcar(N) 5. Draw the magnitude and phase response.

HIGH PASS FILTER USING RECTANGULAR WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function boxcar(N) 5. Draw the magnitude and phase response.

BAND PASS FILTER USING RECTANGULAR WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function boxcar(N) 5. Draw the magnitude and phase response.

BAND STOP FILTER USING RECTANGULAR WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function boxcar(N) 5. Draw the magnitude and phase response. 32

DIGITAL SIGNAL PROCESSING LAB

PROGRAM:

clc; close all; clear all; format long; %FIR Low pass filter using Rectangular window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=boxcar(n); b=fir1(n-1,w1,'low',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,1); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR high pass filter using Rectangular window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=boxcar(n); b=fir1(n-1,w1,'high',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,2); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR BandPass filter using Rectangular window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=boxcar(n); wn=[w1,w2]; b=fir1(n-1,wn,'bandpass',w); 33

DIGITAL SIGNAL PROCESSING LAB [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,3); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR BandStop filter using Rectangular window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=boxcar(n); wn=[w1,w2]; b=fir1(n-1,wn,'stop',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,4); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->');
INPUT:

Enter the pass band frequency1000 Enter the stop band frequency2000 Enter the sampling frequency5000 Enter the order of the filter 8 Enter the pass band frequency1000 Enter the stop band frequency2000 Enter the sampling frequency5000 Enter the order of the filter 9 Enter the pass band frequency2000 Enter the stop band frequency4000 Enter the sampling frequency9000 Enter the order of the filter 12 Enter the pass band frequency1000 Enter the stop band frequency2000 Enter the sampling frequency5000 Enter the order of the filter 11

34

DIGITAL SIGNAL PROCESSING LAB


OUTPUT:

50 gain in db--> gain in db--> 0 0.5 (a)normalised frequency--> 1

20 0 -20 -40 -60

-50

-100

0.5 (a)normalised frequency-->

50

20 0 -20 -40 -60

gain in db-->

-50

-100

0.5 (a)normalised frequency-->

gain in db-->

0.5 (a)normalised frequency-->

ALGORITHM:

LOW PASS FILTER USING HAMMING WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function hamming (N) 5. Draw the magnitude and phase response.

HIGH PASS FILTER USING HAMMING WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function hamming (N) 5. Draw the magnitude and phase response.

BAND PASS FILTER USING HAMMING WINDOW


35

DIGITAL SIGNAL PROCESSING LAB

1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function hamming (N) 5. Draw the magnitude and phase response.

BAND STOP FILTER USING HAMMING WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function hamming (N) 5. Draw the magnitude and phase response.
PROGRAM:

clc; close all; clear all; format long; %FIR Low pass filter using Hamming window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=hamming(n); b=fir1(n-1,w1,'low',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,1); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR high pass filter using Hamming window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=hamming(n); b=fir1(n-1,w1,'high',w); 36

DIGITAL SIGNAL PROCESSING LAB [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,2); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR BandPass filter using Hamming window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=hamming(n); wn=[w1,w2]; b=fir1(n-1,wn,'bandpass',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,3); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR BandStop filter using Hamming window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=hamming(n); wn=[w1,w2]; b=fir1(n-1,wn,'stop',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,4); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->');

37

DIGITAL SIGNAL PROCESSING LAB INPUT: enter the pass band frequency1000 enter the stop band frequency2000 enter the sampling frequency5000 enter the order of the filter 8 enter the pass band frequency1000 enter the stop band frequency2000 enter the sampling frequency8000 enter the order of the filter 9 enter the pass band frequency2000 enter the stop band frequency4000 enter the sampling frequency9000 enter the order of the filter 12 enter the pass band frequency1000 enter the stop band frequency2000 enter the sampling frequency5000 enter the order of the filter 11 OUTPUT:
0 gain in db--> gain in db--> 0 0.5 (a)normalised frequency--> 1 -20 -40 -60 -80 10

-10

-20

0.5 (a)normalised frequency-->

0 -20 gain in db--> -40 -60 -80 -100 0 0.5 (a)normalised frequency--> 1 gain in db-->

0 -5 -10 -15 -20

0.5 (a)normalised frequency-->

ALGORITHM: 38

DIGITAL SIGNAL PROCESSING LAB

LOW PASS FILTER USING HANNING WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function hanning (N) 5. Draw the magnitude and phase response.

HIGH PASS FILTER USING HANNING WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function hanning (N) 5. Draw the magnitude and phase response.

BAND PASS FILTER USING HANNING WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function hanning (N) 5. Draw the magnitude and phase response.

BAND STOP FILTER USING HANNING WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3.Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function hanning (N) 5. Draw the magnitude and phase response.

PROGRAM:

39

DIGITAL SIGNAL PROCESSING LAB clc; close all; clear all; format long; %FIR Low pass filter using Hanning window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=hanning(n); b=fir1(n-1,w1,'low',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,1); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR high pass filter using Hanning window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=hanning(n); b=fir1(n-1,w1,'high',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,2); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR BandPass filter using Hanning window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=hanning(n); wn=[w1,w2]; b=fir1(n-1,wn,'bandpass',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); 40

DIGITAL SIGNAL PROCESSING LAB subplot(2,2,3); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR BandStop filter using Hanning window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=hanning(n); wn=[w1,w2]; b=fir1(n-1,wn,'stop',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,4); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); INPUT: enter the pass band frequency1000 enter the stop band frequency2000 enter the sampling frequency5000 enter the order of the filter 8 enter the pass band frequency1000 enter the stop band frequency2000 enter the sampling frequency5000 enter the order of the filter 9 enter the pass band frequency2000 enter the stop band frequency4000 enter the sampling frequency9000 enter the order of the filter 12 enter the pass band frequency1000 enter the stop band frequency2000 enter the sampling frequency5000 enter the order of the filter 11

41

DIGITAL SIGNAL PROCESSING LAB OUTPUT:

0 gain in db--> gain in db--> 0 0.5 (a)normalised frequency--> 1

50

-50

-50

-100

-100

0.5 (a)normalised frequency-->

50

10 0 -10 -20 -30

gain in db-->

-50

-100

0.5 (a)normalised frequency-->

gain in db-->

0.5 (a)normalised frequency-->

ALGORITHM:

LOW PASS FILTER USING BLACKMAN WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3. Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function blackman (N) 5. Draw the magnitude and phase response.

HIGH PASS FILTER USING BLACKMAN WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3. Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function blackman (N) 42

DIGITAL SIGNAL PROCESSING LAB 5. Draw the magnitude and phase response.

BAND PASS FILTER USING BLACKMAN WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3. Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function blackman (N) 5. Draw the magnitude and phase response.

BAND STOP FILTER USING BLACKMAN WINDOW


1. Get the pass band and stop band edge frequencies. 2. Get the sampling frequency 3. Get the order of the filter(N) 4. Find the window co-efficients using the MATLAB function blackman (N) 5. Draw the magnitude and phase response.
PROGRAM:

clc; close all; clear all; format long; %FIR Low pass filter using Blackman window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=blackman(n); b=fir1(n-1,w1,'low',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,1); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR high pass filter using Blackman window fp=input('enter the pass band frequency'); 43

DIGITAL SIGNAL PROCESSING LAB fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=blackman(n); b=fir1(n-1,w1,'high',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,2); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR BandPass filter using Blackman window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=blackman(n); wn=[w1,w2]; b=fir1(n-1,wn,'bandpass',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,3); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); pause; %FIR BandStop filter using Blackman window fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); f=input('enter the sampling frequency'); n=input('enter the order of the filter '); w1=2*fp/f;w2=2*fs/f; w=blackman(n); wn=[w1,w2]; b=fir1(n-1,wn,'stop',w); [h,om]=freqz(b,1,256); m=20*log10(abs(h)); p=angle(h); subplot(2,2,4); plot(om/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->');

44

DIGITAL SIGNAL PROCESSING LAB INPUT: enter the pass band frequency1000 enter the stop band frequency2000 enter the sampling frequency5000 enter the order of the filter 8 enter the pass band frequency1000 enter the stop band frequency2000 enter the sampling frequency5000 enter the order of the filter 9 enter the pass band frequency2000 enter the stop band frequency4000 enter the sampling frequency9000 enter the order of the filter 12 enter the pass band frequency1000 enter the stop band frequency2000 enter the sampling frequency5000 enter the order of the filter 11 OUTPUT:

0 gain in db--> gain in db--> 0 0.5 (a)normalised frequency--> 1 -20 -40 -60 -80

-10

-20

-30

0.5 (a)normalised frequency-->

20 0 -20 -40 -60

gain in db-->

gain in db--> 0 0.5 (a)normalised frequency--> 1

-5

-10

-15

0.5 (a)normalised frequency-->

45

DIGITAL SIGNAL PROCESSING LAB

RESULT:

Thus MATLAB program for design FIR low pass, high pass, band pass & band reject filters using Rectangular, Hamming, Hanning & Blackman windowing technique was written and executed successfully.

46

DIGITAL SIGNAL PROCESSING LAB VIVS QUESTION 1. What are the different types of arithmetic in digital systems? There are three types of arithmetic used in digital systems. 1. Fixed point arithmetic 2. Floating point arithmetic 3. Block Floating arithmetic. 2. What do you understand by a fixed-point number? In fixed-point arithmetic the position of the binary point is fixed. The bits to the right represent the fractional part of the number and those to the left represent the integer part. For example, the binary number 01.1100 has the value 1.75 in decimal. 3. What are the different types in fixed-point number representation? Depending on the way negative numbers are represented, there are three different forms of fixedpoint arithmetic. They are 1) sign-magnitude 2) 1s complement 3) 2s complement. 4. What do you understand by sign-magnitude representation? Write a short note on 1s complement For sign-magnitude representation the leading binary digit is used to represent the sign. If it is equal to 1 the number is negative, otherwise the number is positive. For example, the decimal number -1.75 is represented as 11.11000 and 1.75 is represented as 01.110000. in sign-magnitude form the number 0 has two representations, i.e., 00.000000 or 10.000000. With b bits only 2b 1 numbers can be represented. 5. representation? In ones complement form the positive number is represented as in the sign-magnitude system. To obtain the negative of a positive number, one simply complements all the bits of the positive number. For example, the negative of 01.110000 would be represented as (01.11000)2 = (10.001111)2 The number 0 has two representations i.e., 00.00000 and 11.11111 in a 1s complement representation.

47

DIGITAL SIGNAL PROCESSING LAB EX.NO:05

FAST FOURIER TRANSFORM


OBJECTIVE: To know about how to perform Fast Fourier transform of given sequences using MATLAB AIM:

To write a MATLAB program to compute the fast fourier transform


ALGORITHM:

1. Clear Command Window [an alternative to the clc function, use Clear Command Window in the MATLAB desktop Edit menu.] 2.Get the input sequence (x) 3. Get the length of the sequence (y) 4. Compute the fast fourier transform using fft (x,y). 5. Plot and display the output
PROGRAM: %FAST FOURIER TRANSFORM clc; clear all; close all; x=input('ENTER THE SEQUENCE:'); y=input('ENTER THE LENGTH OF THE SEQUENCE:'); z=fft(x,y); stem(z); ylabel('Imaginary axis'); xlabel('Real axis'); disp(z);

48

DIGITAL SIGNAL PROCESSING LAB

INPUT: ENTER THE SEQUENCE:[3,2,1,4] ENTER THE LENGTH OF THE SEQUENCE:6 OUTPUT:

1 Imaginary axis

-1

-2

-3

1.5

2.5

3.5 Real axis

4.5

5.5

49

DIGITAL SIGNAL PROCESSING LAB

RESULT:

Thus MATLAB programs to compute fast fourier transform are written and executed successfully

50

DIGITAL SIGNAL PROCESSING LAB VIVA QUESTION 1. Explain deterministic &random signals with examples. Deterministic: A signal that can be uniquely determined by well defined mathematical expression is called deterministic signal. Example: (a).a sinusoidal signal can represented as v (t)=vmsinwt ,for t0 (b).an exponential signal DT signal =ean, for n0 CT signal= e-at, for n<0 Random signals: a signal that can be generated in a random fashion &cannot be predicted ahead of a time is called as random signal. In other words it can be defined as signal about which there is uncertainty before its actual occurrence. Examples: (a).speech signal (b)EEG signals&EEG signals 2. Define auto correlation function of x (n) which is random sequence. Let x (n) be an N point sequence obtained by sampling the signal x (t).the time average auto correlation for the sequence x (n) is, N-|m|-1 Rxx (m) =1/ (N-|m|) x*(n) x (n+m) n=0 3. State power density spectrum of a random signal. Let x (t) be a stationary random process .the statistical auto correlation function for this signal is, xx() =E [x*(t) x (t + )] The Fourier transform of an auto correlation function of a stationary random process gives the power density spectrum. xx () =F [xx()] = xx() e-j2f d -

51

DIGITAL SIGNAL PROCESSING LAB

4. What is known as periodogram? The estimate for the power density spectrum is, (N-1) Pxx (f) = rxx(m) e-j2fm m=-(N-1) rxx (m), then N-1 Pxx (f) = 1/N | x (n) e-j2fm |2 n=0 This estimate for power density spectrum is called periodogram. 5. Differentiate between auto&cross correlation of random signals. Correlation is the process of measuring the degree of similarity between two signals. There are two types of correlation. 1. Auto correlation 2. Cross correlation Auto correlation: It is the process in which we are measuring degree of similarity between two unique character signals. xx(n, m) =E [xnxm*] Cross correlation: It is the process in which we are measuring degree of similarity between two different signals. xx(n, m) =E [xnym*] 6. What is random process said to be mean ergodic. A stationary random process xn is said to be ergodic if all the stationary averages can be determined from a single realization x(n) of process Subs the value of

52

DIGITAL SIGNAL PROCESSING LAB

EX.NO:06 SAMPLING & EFFECT OF ALIASING


OBJECTIVE: To implement the Sampling & effect of Aliasing technique using MATLAB AIM:

To write a MATLAB program to perform a sampling & effect of aliasing of given signal.
ALGORITHM:

1. Get the time of the signal 2. Using this time to find the frequency of signal 3. Generate the signal for using cosine function 4. Plot the signal 5. Sampled the generating signal, the condition is fs<2fm. 6. Sampled the generating signal, the condition is fs=2fm. 7. Sampled the generating signal, the condition is fs>2fm. 8. Plot the sampled signal (fs<2fm) 9. Plot the sampled signal (fs=2fm) 10. Plot the sampled signal (fs>2fm)
PROGRAM: clc; clear all; close all; t=-10:.01:10; T=4;fm=1/T; x=cos(2*pi*fm*t); fs1=1.6*fm; fs2=2*fm; fs3=8*fm; n1=-4:1:4; xn1=cos(2*pi*n1*fm/fs1); subplot(2,2,1),plot(t,x); xlabel('time in sec'),ylabel('x(t)'); title('continuous-time signal'); subplot(2,2,2),stem(n1,xn1); hold on; subplot(2,2,2),plot(n1,xn1); xlabel('n'),ylabel('x(n)'); title('discrete-time signal with fs<fm'); n2=-5:1:5; xn2=cos(2*pi*n2*fm/fs2); subplot(2,2,3),stem(n2,xn2); hold on;

53

DIGITAL SIGNAL PROCESSING LAB


subplot(2,2,3),plot(n2,xn2); xlabel('n'),ylabel('x(n)'); title('discrete-time signal with fs=fm'); n3=-20:1:20; xn3=cos(2*pi*n3*fm/fs3); subplot(2,2,4),stem(n3,xn3); hold on; subplot(2,2,4),plot(n3,xn3); xlabel('n'),ylabel('x(n)'); title('discrete-time signal with fs>fm');

OUTPUT:

continuous-time signal 1 0.5 0 -0.5 -1 -10 1 0.5 x(n) 0 -0.5 -1 -5 x(n) x(n) x(t) 1 0.5 0 -0.5

discrete-time signal with fs<fm

0 5 10 time in sec discrete-time signal with fs=fm

-5

-1 -4 1 0.5 0 -0.5

0 2 4 n discrete-time signal with fs>fm

-2

0 n

-1 -20

-10

0 n

10

20

54

DIGITAL SIGNAL PROCESSING LAB

RESULT:

Thus MATLAB program to perform sampling & effect of aliasing of given signal are written and executed successfully

55

DIGITAL SIGNAL PROCESSING LAB

VIVA QUESTIONS
5. What are the properties that are maintained same in the transformation of analog to digital filter? (Or Mention the two properties that an analog filter should have for effective transformation). The analog filters should be stable and causal for effective transformation to digital filters. While transforming the analog filter to digital filters these two properties(i.e., stability & causality) are maintained same, which means that the transformed digital filter should also be stable and causal. 6. What are the requirements for an analog filter to be stable and causal? 1. The analog filter transfer function Ha(s) should be a rational function of s and the coefficients of s should be real. 2. The poles should lie on the left half of s-plane. 3. The number of zeros should be less than or equal to number of poles. 7. What are the requirements for a digital filter to be stable and causal? 1. The digital filter transfer function H (z) should be a rational function of z and the coefficients of z should be real. 2. The poles should lie inside the unit circle in z-plane. 3. The number of zeros should be less than or equal to number of poles. 9. Define ripples in a filter? The limits of the tolerance in the magnitude of pass band and stop band are called ripples. The tolerance in pass band is denoted as p and that in stop band is denoted as s 10. Write a brief note on the design of IIR filter(or How a digital IIR filter is designed?)? For designing a digital IIR filter, first an equivalent analog filter is designed using any one of the approximation technique and the given specifications. The result of the analog filter design will be an analog filter transfer function Ha(s). The analog filter transfer function is transformed to digital filter transfer function H (z) using either Bilinear or Impulse invariant transformation. 11. Mention any two techniques for digitizing the transfer function of an analog filter. The bilinear transformation and the impulse invariant transformation are the two techniques available for digitizing the analog filter transfer function.

56

DIGITAL SIGNAL PROCESSING LAB

EX NO:07

CORRELATION
OBJECTIVE: To know about how to perform Correlation of given sequences using MATLAB AIM:

To correlate the given two sequences using MATLAB program.


ALGORITHM:

1.Get two signals x(n) and h(n) in matrix form. 2. corr(X,Y,...) returns a p1-by-p2 matrix containing the pairwise correlation coefficient between each pair of columns in the n-by-p1 and n-by-p2 matrices X and Y. 3.The correlated signal is denoted as y(n). [subplot divides the current figure into rectangular panes that are numbered rowwise] 4. y(n) is given by the formula 5.stop the program.
PROGRAM:

clc; close all; clear all; x=input('Enter first sequence'); h=input('Enter second sequence'); y=xcorr(x,h); figure;subplot(3,1,1); stem(x);ylabel('Amplitude-->'); xlabel('(a)n-->'); subplot(3,1,2); stem(h);ylabel('Amplitude-->'); xlabel('(b)n-->'); subplot(3,1,3); stem(y);ylabel('Amplitude-->'); xlabel('(c)n-->'); disp('The resultant signal is');fliplr(y) 57

DIGITAL SIGNAL PROCESSING LAB

INPUT:

Enter first sequence [1, 2, 3, 4] Enter second sequence [4, 3, 2, 1] The resultant signal is OUTPUT:
Amplitude--> 4 2 0

1.5

2.5 (a)n-->

3.5

Amplitude-->

4 2 0

1.5

2.5 (b)n-->

3.5

30 Amplitude--> 20 10 0 1 2 3 4 (c)n--> 5 6 7

58

DIGITAL SIGNAL PROCESSING LAB

RESULT:

Thus MATLAB program to perform correlation was written and executed successfully.

59

DIGITAL SIGNAL PROCESSING LAB

VIVA QUESTIONS What are the classification digital signal processors? The digital signal processors are classified as (i)General purpose digital signal processors. (ii)Special purpose digital signal processors. Give some examples for fixed point DSPs. TM320C50, TMS320C54, TMS320C55, ADSP-219x, ADSP-219xx. 1. Give some example for floating point DSPs. TMS320C3x, TMS320C67x, ADSP-21xxx. 2. What are the factors that influence selection of DSPs? Architectural features Execution speed Type of arithmetic Word length 3. What are applications of PDSPs? Digital cell phones, automated inspection, voicemail, motor control, video conferencing, Noise cancellation, Medical imaging, speech synthesis, satellite communication etc. 4. What are the advantages and disadvantages of VLIW architecture? Advantages of VLIW architecture 1. Increased performance 2. Better compiler targets 3. Potentially easier to program 4. Potentially scalable 5. Can add more execution units; allow more instructions to be packed into the VLIW instruction. Disadvantages of VLIW architecture 1. New kind of programmer/ compiler complexity 2. Program must keep track of instruction scheduling 3. Increased memory use 4. High power consumption 5. Misleading MIPS ratings The program bus carries the instruction code and immediate operands from program memory to the CPU. 7. What is pipelining? Pipelining a processor mean breaking down its instruction into a serious of discrete pipeline stages which can be completed in sequence by specialized hardware. 8. What is pipeline depth? 60

DIGITAL SIGNAL PROCESSING LAB The number of pipeline stages is referred to as the pipeline depth. 9. What is the pipeline depth of TMS320C50 and TMS320C54x? TMS 320C50 4 TMSS320C54x 6. 10. What are the different stages in pipelining? (i) The fetch phase (ii) The decode phase (iii) Memory read phase (iv) The execute phase

61

DIGITAL SIGNAL PROCESSING LAB

TMS320C50 DIGITAL SIGNAL PROCESSOR

62

DIGITAL SIGNAL PROCESSING LAB

EX.NO:08 CALCULATION OF FFT USING TMS320C50


OBJECTIVE:

To implement the processing technique for calculation of FFT using the instructions of TMS320c50. AIM: To write a assembly language program to calculate the Fast Fourier transform for the given sequence.

THEORY:
The fast fourier transform (FFT) is an algorithm used to compute the DFT with minimum number of calculations. It makes use of the symmetry and periodicity properties of twiddle factor WkN to effectively reduce the DFT computation time. It is based on the fundamental principal of decomposing the computation of DFT of a sequence of length N into successively smaller discrete Fourier transforms. The FFT algorithm provides speed-increase factors, when compared with direct computation of the DFT. The direct evaluation of DFT using the formula

requires N2 complex multiplications and N (N-1) complex additions. Thus for reasonably large values of N (in the order of 1000) direct evaluation of the DFT requires an inordinate amount of computation. By using FFT algorithms the number of computations can be reduced. For example, for an N-point DFT, the number of complex multiplications required using FFT is N 2 log2 N. If N=16, the number of complex multiplications required for direct evaluation of DFT is 256, whereas using FFT only 32 multiplications are required.

Two Types of FFT :


1. Decimation in time ( DIT ) Algorithm :

63

DIGITAL SIGNAL PROCESSING LAB Decimation in-time algorithm is used to calculate the DFT of a N-point sequence. The idea is to break the N-point sequence into two sequences, the DFTs of which can be combined to give the DFT of the original N-point sequence. Initially the N-point sequence is divided into two N 2 point sequences xe(n) and xo(n), which have the even and odd members of x(n) respectively. The N 2 point DFTs of these two sequences are evaluated and combined to give the N-point DFT. Similarly the N 2 point DFTs can be expressed as a combination of N 4 point DFTs. This process is continued until we left with 2-point DFT. This algorithm is called decimation-in-time because the sequence x(n) is often splited into smaller subsequences. 2. Decimation-in-frequency algorithm : It is a popular form of the FFT algorithm. In this the output sequence x(k) is divided into smaller and smaller subsequences, that is why the name decimation in frequency. Initially the input sequence x(n) is divided into two sequences x1(n) and x2(n) consisting of the first N 2 samples of x(n) and the last N 2 samples of x(n) respectively. Then we find the N 2 point sequences f(n) and g(n) as f(n) = x1(n) + x2(n) and g(n) = [x1(n) - x2(n)]WnN The N 2 point DFTs of the above two sequences give even numbered and odd numbered output samples respectively. The above procedure can now be iterated to express each N 2 point DFT as a combination of two N 4 point DFTs. This process is continued until we left with 2-point DFT. PROGRAM: IN .set 8010H BITREV .set 8020H REAL .set 8040H IMG .set 8050H .MMREGS .TEXT LDP #100H LAR AR1,#IN LAR AR2,#BITREV SPLK #2H,05H LMMR INDX,#8005H MAR *,AR2 RPT #3H BLDD #IN,*BR0+ LAR AR2,#BITREV LAR AR3,#8030H LAR AR0,#1H FFT1: MAR *,AR2 LACC *+ SACB 64

DIGITAL SIGNAL PROCESSING LAB LT *+ MPY #1H APAC MAR *,AR3 SACL *+ LACB SPAC SACL *+,AR0 BANZ FFT1,*LAR AR3,#8030H LAR AR4,#REAL LAR AR5,#IMG MAR *,AR3 LACC * SACB ADRK #2H LT *MPY #1H APAC MAR *,AR4 SACL * ADRK #2H LACC #0H MAR *,AR5 SACL * ADRK #2H LACB SPAC MAR *,AR4 SACL *LACC #0H MAR *,AR5 SACL *-,AR3 LACC *,AR4 SACL * ADRK #2H SACL *,AR3 ADRK #2H LT * MPY #0FFFFH MAR *,AR5 SPL *,AR3 LT * MPY #1H MAR *,AR5 ADRK #2H SPL * 65

DIGITAL SIGNAL PROCESSING LAB H: B H

INPUT: 8010-0001 8011-0001 8012-0000 8013-0000 BIT_REV: 8020-0001 8021-0000 8022-0001 8023-0000 FFT1: 8030-0001 8031-0001 8032-0001 8033-0001 REAL: 8040-0002 8041-0001 8042-0000 8043-0001 IMG: 8050-0000 8051-FFFF 8052-0000 8053-0001

RESULT:

Thus assembly language program to perform FFT was written and executed successfully EX.NO:09 66

DIGITAL SIGNAL PROCESSING LAB

STUDY OF ADDRESSING MODES


OBJECTIVE:

To know about the addressing modes of DSP using TMS320C50 AIM: To study the various addressing modes of DSP using simple programs. THOERY: The addressing modes in TMS320C50 are 1. Immediate addressing 2. Indirect addressing 3. Register addressing 4. Memory mapped register addressing 5. Direct addressing 6. Circular addressing modes. IMMEDIATE ADDRESSING MODES: The immediate addressing mode is used to handle constant data. It allows the program to operate an actual value the data can be either a 16 bit constant or constant length T, 9 or 13 depending on the length of data the addressing. In long addressing mode the data contained in a portion of a bit in a single word instruction. At the assembly code level the developer uses a prefix to specify immediate addressing as en: LD #80HA; The instruction load an immediate value 80H into the acculmator. ADD #K, Store immediate ADD #LK, Long immediate Long immediate may # k for multiplication 1 add # LK [for shift] 2 OR #LK [for shift] 3 XOR #LK [for shift] INDIRECT ADDRESSING MODE: The addressing modes uses the auxillary register to hold the address of operand in memory. In indirect addressing any location in the 64-k word data memory space can be accessed using a 16-bit address contained in accumulator. There are 7 types of indirect addressing modes. 1. Auto increment 2. auto decrement port inducting by adding the content AR0 3. port inducing by subtracting the content AR0 4. single indirect addressing with no increment 5. Single indirect addressing with no decrements 6. Bit reversed addressing EX: ADD {find} {shift} [ARM] SUB {shift} [ARM]. REGISTER ADDRESSING: The register addressing mode uses operands in CPU registered eitheir explicitly such as with a direct reference to a specific register or simplicity with instruction that reference contain register that if it is an BLPD- block move from the program to data memory with source address in BMAR. 67

DIGITAL SIGNAL PROCESSING LAB MEMORY MAPPED REGISTER ADDRESSING: Memory mapped register addressing is used to access efficiently the cpu on chip peripheral register. It operates like the direct addressing except that the upper bit of the address that is accessed are assumed to be 0.05. This allows the addressing and operand can be represented using a single 16-bit word. LAMM load accumulator with memory mapped register. SAMM store accumulator in memory mapped register. DIRECT ADDRESSING MODE: Direct addressing mode allowed the CPU to operate as an operand by specifying an offer from a base address defined in data pointer. In their mode the address of the operand is obtained by concatenating the 7 bit data memory address with the bit of the data page pointer 16- bit data memory address is placed or an internal direct data memory address. CIRCULAR ADDRESSING MODE: Circular addressing is the CSX addressing mode many algorithm. Such as convolution and the FIR filtering can use circular. Buffer in memory to event data to be processed. CBSR-1 circular buffer 1 start register CBSR-2 circular buffer 2 start register CBER-1 - circular buffer 1 end register. CBER-2 - circular buffer 2 end register. The 8 bit CBER enables A disables circular buffer operation to define circular first use load the start A and addressing into the corresponding buffer register. PROGRAM: IMMEDIATE ADDRESSING MODE: .mmregs .ps 0a00h .entry LACC #1000h LACC #1111h, 3 LAR AR0,#1000h LAR AR1,#1100h ADD #00FFh ADD #0011h,2 SPLK #10h,TREG0 MPY #0010h SUB #0022h SUB #0011h,3 .end DIRECT ADDRESSING MODES .mmregs .ps 0a00h 68

DIGITAL SIGNAL PROCESSING LAB .entry LDP #20h LACC 10h LACC 5h,2 LDP #22h LAR AR0,15h SACL 15h SACL 20h,3 SAMM AR7 LDP #12h ADD 25h ADD 7h,2 SUB 10h SUB 12h,2 SPLK #10h,TREG0 MPY 15h .end INDIRECT ADDRESSING MODE .mmregs .ps 0a00h .entry LAR AR0,#1000h LACC * LACC *,4,AR1 LAR AR1,#1010h SACL * SACL *+,2,AR0 LACC *-,2,AR1 LACC *0+ LACC *BR0+ ADD *+,0,AR0 SUB *-,2 SPLK #10h,TREG0 MPY * .end CIRCULAR ADDRESSING MODE .mmregs .ps 0a00h .entry SPLK #1000h,CBSR1 SPLK #1003h,CBER1 SPLK #08h,CBSR LACC AR0,#1000h LACC*# LACC *# 69

DIGITAL SIGNAL PROCESSING LAB LACC*# LACC *# .end

RESULT: Thus the various addressing modes of DSP using simple programs were studied.

EX.NO:10
70

DIGITAL SIGNAL PROCESSING LAB

SAMPLING OF INPUT SIGNAL AND DISPLAY


OBJECTIVE:

To implement the Sampling of input signal using the instructions of TMS320C50.


AIM:

To write a assembly language program to sample the given input signal and display it. PROGRAM:
.mmregs .text START: LDP #100H LAR AR1,#2FFFH REP: IN 0,06 RPT #0FH NOP IN 0,04 RPT #5FFFH NOP LACC 0 AND #0FFFH SACL 0 OUT 0,4 MAR *,AR1 BANZ REP,*B START .end

71

DIGITAL SIGNAL PROCESSING LAB

RESULT:

Thus assembly language program to perform sampling the input signal was written and executed successfully

EX.NO:11
72

DIGITAL SIGNAL PROCESSING LAB

IMPLEMENTATION OF FIR FILTER


OBJECTIVE: To know about the coding of TMS320C50 Processor for implementing the FIR filter of various windowing techniques
AIM:

To write an assembly language program to implement FIR filter.


PROGRAM:

Approximation type: Window design - Blackmann Window * Filter type: highpass filter * Filter Order: 52

* Cutoff frequency in KHz = 3.000000 .mmregs .text B CTABLE: .word 0FCD3H .word 05H .word 0FCB9H .word 087H .word 0FD3FH .word 01ADH 73 START

DIGITAL SIGNAL PROCESSING LAB

.word 0FE3DH .word 0333H .word 0FF52H .word 04ABH .word 0FFF8H .word 0595H .word 0FFACH .word 0590H .word 0FE11H .word 047CH .word 0FB0BH .word 029DH .word 0F6BAH .word 0AEH .word 0F147H .word 01CH 74

DIGITAL SIGNAL PROCESSING LAB .word 0E9FDH .word 04C5H .word 0D882H .word 044BCH .word 044BCH .word 0D882H .word 04C5H .word 0E9FDH .word 01CH .word 0F147H .word 0AEH .word 0F6BAH .word 029DH .word 0FB0BH .word 047CH .word 0FE11H .word 0590H 75

DIGITAL SIGNAL PROCESSING LAB

.word 0FFACH .word 0595H .word 0FFF8H .word 04ABH .word 0FF52H .word 0333H .word 0FE3DH .word 01ADH .word 0FD3FH .word 087H .word 0FCB9H .word 05H .word 0FCD3H * * * * 76 Move the Filter coefficients from program memory to data memory

DIGITAL SIGNAL PROCESSING LAB START: MAR *,AR0 LAR RPT AR0,#0200H #33H

BLKP CTABLE,*+ SETC CNF * * Input data and perform convolution * ISR: LDP #0AH

LACC #0 SACL 0 OUT 0,05 IN LAR 0,06H AR7,#0 ;change value to modify sampling freq. ;pulse to find sampling frequency

MAR *,AR7 BACK: IN NOP NOP NOP NOP MAR *,AR1 LAR AR1,#0300H 77 BANZ BACK,*0,4

DIGITAL SIGNAL PROCESSING LAB LACC 0 AND #0FFFH SUB #800H

SACL * LAR AR1,#333H

MPY #0 ZAC RPT MACD APAC LAR AR1,#0300H ;give as sach *,1 incase of overflow #33H 0FF00H,*-

SACH * LACC * ADD #800H SACL * OUT *,4 LACC #0FFH SACL 0 OUT 0,05 NOP B .end ISR

78

DIGITAL SIGNAL PROCESSING LAB

RESULT:

Thus assembly language program to perform implementation of FIR was written and executed successfully.

EX.NO:12
79

DIGITAL SIGNAL PROCESSING LAB

CIRCULAR CONVOLUTION OF TWO SEQUENCES


OBJECTIVE: To know about the coding of TMS320C50 Processor for circular convolution of two sequences.
AIM:

To write an assembly language program to convolute the given two sequences.


PROGRAM:

.MMREGS .TEXT START: LDP #100H LACC 0H SUB #1H LAR AR0,1H LAR AR1,#8060H; LAR AR2,#8100H COPYX2: MAR *,AR1 LACC *+ MAR *,AR2 SACL *+ MAR *,AR0 BANZ COPYX2,*_ LAR AR0,1H LAR AR2,#8010H LAR AR2,#8060H ; LAR AR3,#8050H LOOP3: LAR AR4,1H ZAP LOOP: MAR *,AR3 ; LT *+ MAR *,AR1 ; output MPY *+ SPL 5H ADD 5H MAR *,AR4 BANZ LOOP,*_, MAR *,AR2 SACL *+ CALL ROTATE 80

DIGITAL SIGNAL PROCESSING LAB LOOP2: MAR *,AR0 BANZ LOOP3,*_ H: B H ROTATE: LDP #100H ; LACC 1H SUB #1H SACL 2H LACC 0050H SACB ; ACCUMULATOR BUFFER LAR AR3,#8051H LAR AR5,#8070H LAR AR6,2H LOOP1: MAR *,AR3 LACC *+ MAR *,AR5 SACL *+ MAR *,AR6 BANZ LOOP1,*_ LACB ;

ACCUMULATOR AS LAST DATA MAR *,AR5 SACL *+ LACC #8070H SAMM BMAR LAR AR3,#8050H MAR *,AR3 RPT #3H ; BLDD BMAR,*+ ; RET INPUT: 8000-0004 x1(n) = 8050-0002 8051-0001 8052-0002 8053-0001 81

DIGITAL SIGNAL PROCESSING LAB h2(n) = 8060-0001 8061-0002 8062-0003 8063-0004 OUTPUT: 8010-000E 8011-0010 8012-000E 8013-0010

RESULT:

Thus assembly language program to circular convolution for two sequences was written and executed successfully. VIVA QUESTIONS 82

DIGITAL SIGNAL PROCESSING LAB 1. TMS320C5X accepts the source code from c1x,c2x, and c2xx. 2. PIPELINING is process of breaking down its instruction 3. TMS320C5X has the pipeline F-D-R-X(4 levels) 4. TMS320c50 has 16 bit processor running at 4MHz 5. TMS320c50 has programmable memory map 6. TMS320c50 address range is 224K x 16 bit words 7. TMS320c50 has onchip memory include 10K words of the RAM 8. TMS320c50 has 2K words of the ROM 9. TMS320c50 is 16 bit processor 10. TMS320c50 has the signal instruction execution time is 50nsec 11. TMS320c54x has 16 bit fixed point digital signal processor 12. TMS320c54x was introduced in JAPAN IN 1994 13. TMS320c54x has 3 data memory buses

83

You might also like