0% found this document useful (0 votes)
116 views54 pages

Svu Dsp-Lab - Manual-2

The document describes the objectives, outcomes and list of experiments for a Digital Signal Processing laboratory course. The course aims to analyze and implement digital signal processing systems using MATLAB. The key topics covered include DFT, FFT, digital filter design and multirate signal processing. The list of 12 experiments involves topics like signal generation, convolution, spectrum analysis, filter design and decimation/interpolation using MATLAB.

Uploaded by

Gurusreenu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views54 pages

Svu Dsp-Lab - Manual-2

The document describes the objectives, outcomes and list of experiments for a Digital Signal Processing laboratory course. The course aims to analyze and implement digital signal processing systems using MATLAB. The key topics covered include DFT, FFT, digital filter design and multirate signal processing. The list of 12 experiments involves topics like signal generation, convolution, spectrum analysis, filter design and decimation/interpolation using MATLAB.

Uploaded by

Gurusreenu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

LAB MANUAL

DIGITAL SIGNAL PROCESSING LABORATORY

Department of ECE, SVUCE 1


Course Objectives

⮚ Analyze and implement digital signal processing systems in time domain.

⮚ Design frequency-selective digital filters.

⮚ Design digital filters using windows.

⮚ Sample and reconstruct analog signals.

⮚ Compute circular convolution, linear convolution and the discrete Fourier transform

(DFT) of discrete-time signals.

⮚ Analyze and implement digital systems using the DFT and the Fast Fourier Transform (FFT).

⮚ Use MATLAB for DSP system analysis and design.

Course Outcomes:

Upon successful completion of the course, the student will be able to

CO1 Interpret discrete – time signals using DFT


CO2 Apply FFT algorithms for various signsl processing operations
CO3 Design the Multirate Filters
CO4 Design IIR and FIR digital filters for real time DSP applications

Department of ECE, SVUCE2


DIGITAL SIGNAL PROCESSING LABORATORY

LIST OF EXPERIMENTS:

1. Introduction to Basics of MATLAB

2. a) Generation of continuous - time signals

b) Generation of discrete – time sequences


2. DFT and IDFT of a sequence
3. Perform the following operations on the given sequences using DFT
a) Linear Convolution
b) Circular Convolution
4. Implement the following operations using radix-2 FFT
a) Decimation in Time – Fast Fourier Transform (DIT - FFT)
b) Decimation in Frequency – Fast Fourier Transform (DIT - FFT)
5. Spectrum Analysis using DFT

6. IIR filter design

7. FIR filter design

8. FIR filter design using various window techniques

9. Chebshev Type – I & Type – II filters design

10. Perform the conversion of analog filter into digital filter using the following methods
a) Impulse Invariant method
b) Bilinear Transformation method

11. Decimation and Interpolation of a sequence

Department of ECE, SVUCE3


MATLAB
MATLAB is a software package for high performance numerical computation and visualization
provides an interactive environment with hundreds of built in functions for technical
computation, graphics and animation. The MATLAB name stands for MATrix LABoratory The
diagram shows the main features and capabilities of MATLAB.

MATLAB

GRAPHICS COMPUTATIONS EXTERNAL INTERFACE


2-D
Linear
Graphics
Algebra3 Signal
–D Graphics
Processing
Animations
Polynomial and interpolation
Interface
Quadrature
with Csolution
and FORTAN
of ODE’S
language

TOOL BOX
Signal Processing Image Processing
Statistics Neural Network Control Systems Communication

At its core ,MATLAB is essentially a set (a “toolbox”) of routines (called “m files” or


“mex files”) that sit on your computer and a window that allows you to create new variables with
names (e.g. voltage and time) and process those variables with any of those routines (e.g. plot
voltage against time, find the largest voltage, etc).

Department of ECE, SVUCE4


It also allows you to put a list of your processing requests together in a file and save that
combined list with a name so that you can run all of those commands in the same order at some
later time. Furthermore, it allows you to run such lists of commands such that you pass in data
and/or get data back out (i.e. the list of commands is like a function in most programming
languages). Once you save a function, it becomes part of your toolbox (i.e. it now looks to you as
if it were part of the basic toolbox that you started with).
For those with computer programming backgrounds: Note that MATLAB runs as an
interpretive language (like the old BASIC). That is, it does not need to be compiled. It simply
reads through each line of the function, executes it, and then goes on to the next line. (In practice,
a form of compilation occurs when you first run a function, so that it can run faster the next time
you run it.

MATLAB Windows:
MATLAB works with through three basic windows

Command Window : This is the main window .it is characterized by MATLAB command
prompt >> when you launch the application program MATLAB puts you in this window all
commands including those for user-written programs ,are typed in this window at the MATLAB
prompt

Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background color
the user can create as many windows as the system memory will allow

Edit window: This is where you write edit, create and save your own programs in files called M
files.

INPUT-OUTPUT:
MATLAB supports interactive computation taking the input from the screen and flushing,
the output to the screen. In addition it can read input files and write output files.

Data Type: the fundamental data –type in MATLAB is the array. It encompasses several distinct
data objects- integers, real numbers, matrices, character strings, structures and cells. There is no
need to declare variables as real or complex, MATLAB automatically sets the variable to be
real.

Dimensioning: Dimensioning is automatic in MATLAB. No dimension statements are required


Department of ECE, SVUCE5
for vectors or arrays .we can find the dimensions of an existing matrix or a vector with the size
and length commands.
BASIC INSTRUCTIONS IN MAT LAB

1. T = 0: 1:10
This instruction indicates a vector T which as initial value 0 and final value 10 with an
increment of 1
Therefore T = [0 1 2 3 4 5 6 7 8 9 10]

2. F= 20: 1: 100
Therefore F = [20 21 22 23 24 ……… 100]

3. T= 0:1/pi: 1
Therefore T= [0, 0.3183, 0.6366, 0.9549]

4. zeros (1, 3)

The above instruction creates a vector of one row and three columns whose values are zero Output=
[0 0 0]

5. ones (5,2)
The above instruction creates a vector of five rows and two columns
Output= 11

11

11

11

11

6. zeros (2, 4)
Output= 0 0 00
0 0 00

7. a = [ 1 2 3] , b = [4 5 6]

Then a.*b = [4 10 18]

i.e. [4*1 5*2 6*3]

Department of ECE, SVUCE6


8. If C= [2 2 2] and b = [4 5 6]
b.*C results in [8 10 12]

9. plot (t,x)

If x = [6 7 8 9] and t = [1 2 3 4]; This instruction will display a figure window which


indicates the plot of x versus t

10. stem(t,x)
If x(n) = [0 1 2 3];This instruction will display a figure window as shown

11. Subplot: This function divides the figure window into rows and columns Subplot (2 2 1) divides
the figure window into 2 rows and 2 columns 1 represent number of the figure

Department of ECE, SVUCE7


12. Filter:
Syntax: y =filter(b,a,X)
Description :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.

13. Fliplr:
Syntax: B =fliplr(A)

Description :B=fliplr(A) returns A with columns flipped in the left-right direction, that is,
about a vertical axis. If A is a row vector, then fliplr(A) returns a vector of the same length with
the order of its elements reversed. If A is a column vector, then fliplr(A) simply returns A.

14. Conv:
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.

15. Impz:
Syntax: [h,t] =impz(b,a,n)

Description:[h,t] = impz(b,a,n) computes the impulse response of the filter with numerator
coefficients b and denominator coefficients a and computes n samples of the impulse response
when n is an integer (t = [0:n-1]'). If n is a vector of integers,impz computes the impulse response
at those integer locations, starting the response computation from 0 (and t = n or t = [0 n]).If,
instead of n, you include the empty vector for the second argument, the number of samples is
Department of ECE, SVUCE8
computed automatically by default.

16. Disp:
Syntax: disp(X)
Description: disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed. Another way to display an array on the screen is to type its name,
but this prints a leading "X=," which is not always desirable. Note that disp does not display
empty arrays.

17. xlabel:
Syntax : xlabel('string')
Description : xlabel('string') labels the x-axis of the current axes.

18. Ylabel :
Syntax : ylabel('string')
Description :ylabel ('string') labels the y-axis of the current axes.

19. Title :
Syntax :title('string')
Description :title('string') outputs the string at the top and in the center of the current axes.

20. grid on:


Syntax : grid on
Description : grid on adds major grid lines to the current axes.

Department of ECE, SVUCE9


Exp. No: 1a
GENERATION OF CONTINUOUS TIME SIGNALS

AIM:

To generate a functional sequence of a signal (Sine, Cosine, triangular, Square,


Saw tooth and sinc ) using MATLAB function.
TOOLS REQUIRED:

Mat lab software


Personal computer
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.

Department of ECE, SVUCE10


PROGRAM: (Generation of Continuous Time Signals)

%Program for sine wave


t=0:0.1:10;
y=sin(2*pi*t);
subplot(3,3,1);
plot(t,y,'k');
xlabel('Time');
ylabel('Amplitude');
title('Sine wave');

%Program for cosine wave


t=0:0.1:10;
y=cos(2*pi*t);
subplot(3,3,2);
plot(t,y,'k');
xlabel('Time');
ylabel('Amplitude');
title('Cosine wave');

%Program for square wave


t=0:0.001:10;
y=square(t);
subplot(3,3,3);
plot(t,y,'k');
xlabel('Time');
ylabel('Amplitude');
title('Square wave');

%Program for sawtooth wave


t=0:0.1:10;
y=sawtooth(t);
subplot(3,3,4);
plot(t,y,'k');
xlabel('Time'); ylabel('Amplitude');
title('Sawtooth wave');

%Program for Triangular wave


t=0:.0001:20;
y=sawtooth(t,.5); % sawtooth with 50% duty cycle (triangular)
subplot(3,3,5);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
title('Triangular waveform');

%Program for Sinc Pulse


t=-10:.01:10;
y=sinc(t);
axis([-10 10 -2 2]);
Department of ECE, SVUCE11
subplot(3,3,6) plot(t,y)
ylabel ('Amplitude'); xlabel
('Time Index'); title('Sinc
Pulse');

% Program for Exponential Growing signal


t=0:.1:8;
a=2;
y=exp(a*t);
subplot(3,3,7);
plot(t,y);
ylabel ('Amplitude'); xlabel
('Time Index');
title('Exponential growing Signal');

% Program for Exponential Growing signal t=0:.1:8;


a=2;
y=exp(-a*t);
subplot(3,3,8);
plot(t,y);
ylabel ('Amplitude'); xlabel
('Time Index');
title('Exponential decaying Signal');

% Program for Unit step signal


t=-5:0.01:5;
step=[zeros(1,500),ones(1,501)];
subplot(4,4,9);
plot(t,step);
xlabel(‘t--->’);
ylabel(‘amp--->’);
title(‘unit step signal’);
axis([-5 5 0 1.5]);
% Program for Unit impulse signal
t=-1:0.001:1;
impulse=[zeros(1,1000),ones(1,1),zeros(1,1000)];
subplot(4,4,10);
plot(t,impulse);
xlabel(‘t--->’);
ylabel(‘amp--->’);
title(‘impulse signal’);
axis([-2 2 0 2]);

Department of ECE, SVUCE12


OUTPUT: (Generation of Continuous Time Signals)

RESULT:
Thus the programs for discrete time signals/sequences were executed
successfully using MATLAB and the results were plotted.
Ex. No: 1b

AIM:
GENERATION OF DISCRETE TIME
SIGNALS

To generate a discrete time signal sequence (Unit step, Unit ramp, Sine, Cosine,
Exponential, Unit impulse) using MATLAB function.
TOOLS REQUIRED:

Mat lab software


Personal computer
PROCEDURE:
1. Start the MATLAB program.

2. Open new M-file

3. Type the program

4. Save in current directory

5. Compile and Run the program

6. If any error occurs in the program correct the error and run it again

7. For the output see command window\ Figure window

8. Stop the program.


PROGRAM: (Generation of Discrete Time Signals)

%Program for sinusoidal (sine & Cosine) sequences


clc;
clear all;
close all;
n=0:pi/10:2*pi;
y=sin(n);
subplot(4,4,1);
stem(n,y);
xlabel(‘n--->’);
ylabel(‘amp--->’);
title(‘sinusoidal signal’);
z=cos(n);
subplot(4,4,2);
stem(n,z);
xlabel(‘n--->’);
ylabel(‘amp--->’);
title(‘cosine signal’);

%Program for Square signal


n=0:pi/10:2*pi;
p=square(n);
subplot(4,4,3);
stem(n,p);
xlabel(‘n--->’);
ylabel(‘amp--->’);
title(‘square signal’);

%Program for Sawtooth signal


n=0:pi/10:2*pi;
q=sawtooth(n);
subplot(4,4,4);
stem(n,q);
xlabel(‘n--->’);
ylabel(‘amp--->’);
title(‘sawtooth signal’);

%Program for Sawtooth signal


n=-pi:0.2:pi;
r=sinc(n);
subplot(4,4,5);
stem(n,r);
xlabel(‘n--->’);
ylabel(‘amp--->’);
title(‘sinc signal’);

%Program for exponential signal


n=0:0.2:2;
s=exp(n);
subplot(4,4,6);
stem(n,s);
xlabel(‘n--->’);
ylabel(‘amp--->’);
title(‘exponential signal’);

%Program for Triangular signal


n=-5:0.5:5;
width=5;
T=tripuls(n,width);
subplot(4,4,7);
stem(n,T);
xlabel(‘n--->’);
ylabel(‘amp--->’);
title(‘triangular signal’);

%Program for unit ramp signal


n=0:0.5:5;
ramp=n;
subplot(4,4,8);
stem(n,ramp);
xlabel(‘n--->’);
ylabel(‘amp--->’);
title(‘ramp signal’);

%Program for unit step sequence


n=-5:0.5:5;
step=[zeros(1,10),ones(1,11)];
subplot(4,4,9);
stem(n,step);
xlabel(‘n--->’);
ylabel(‘amp--->’);
title(‘unit step signal’);
axis([-5 5 0 1.5]);

%Program for unit impulse sequence


n=-1:0.1:1;
impulse=[zeros(1,10),ones(1,1),zeros(1,10)];
subplot(4,4,10);
stem(t,impulse);
xlabel(‘n--->’);
ylabel(‘amp--->’);
title(‘impulse signal’);
axis([-2 2 0 2]);

OUTPUT: (Generation of Discrete Time Signals)


RESULT:
Thus the programs for discrete time signals/sequences were executed
successfully using MATLAB and the results were plotted.
Exp. No: 2
DFT AND IDFT OF A SEQUENCE

AIM :

To compute DFT and IDFT of a sequence without using the inbuilt functions and to plot
magnitude and phase spectrum.

TOOLS REQUIRED:

Mat lab software


Personal computer
PROGRAM :
clc;
close all;
clear all;
xn=input(‘enter the sequence x(n)=’);
N=length(xn);
xk=zeros(1,N);
ixk=zeros(1,N);
for k=0:N-1
for n=0:N-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/N))
end;
end;
t=0:N-1;
subplot(2,2,1);
stem(t,xn);
grid;
ylabel (‘amplitude’);
xlabel (‘time index’);
title(‘input sequence’);
magnitude=abs(xk);
t=0:N-1;
subplot(2,2,2);
stem(t,magnitude);
grid;
ylabel(‘amplitude’);
xlabel(‘k’);
title(‘magnitude response’);
phase=angle(xk);
t=0:N-1;
subplot(2,2,3);
stem(t,phase);
grid;
ylabel(‘phase’);
xlabel(‘k’);
title(‘phase response’);
for n=0:N-1
for k=0:N-;
ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/N));
end
end
ixk=ixk./N;
t=0:N-1;
subplot(2,2,4);
stem(t,xn);
grid;
ylabel (‘amplitude’);
xlabel (‘time index’);
title(‘IDFT sequence’);

OUTPUT:
Enter the sequence x(n)=[ 1 1 0 0 ]
DFT sequence is x(k) =[2,1-j,0,1+j]
Magnitude of x(k) =[2,√2,0,√2]
Phase of DFT=[0 , -0.7854 , -1.571 , 0.7854]
Magnitude of IDFT=[4 , 4 , 0 , 0]
Phase of IDFT=[0 , 0 , 1.938 , 0.9273]
RESULT:

Thus, the program for the DFT and IDFT of a sequence without using the inbuilt functions was
executed successfully using MATLAB and the results were plotted.
Exp. No. 3a

IMPLEMENTATION OF DECIMATION-IN-TIME RADIX-2 FFT ALGORITHM

AIM:
To implement the Decimation –in Time FFT of a sequence using DIT-FFT method

TOOLS REQUIRED:

Mat lab software


Personal computer

% Direct computation of FFT


x=[1 1 0
0]; N=4;
y=fft(x,N);
stem(abs(y));
ylabel ('Amplitude');
xlabel ('N');
title('Magnitude Response');

%Matlab Program for FFT using DIT algorithm


clc;

clear all;

close all;

x=input('enter x[n]:');
N=length(x);
levels=nextpow2(N);
xn=[x,zeros(1,(2^levels)-
N)]; x=bitrevorder(xn)
N=length(xn);
tw=cos(2*pi*(1/N)*(0:N/2-1))-j*sin(2*pi*(1/N)*(0:N/2-1));
for level=1:levels;
L=2^level;
twlvl=tw(1:N/L:N/2);
for k=0:L:N-L;
for n=0:L/2-1;
A=x(n+k+1);
B=x(n+k+(L/2)+1)*twlvl(n+1);
x(n+k+1)=A+B;
x(n+k+(L/2)+1)=A-B;
end
end
x
end
XK=x
n=0:N-1;
subplot(2,2,1);
stem(n,xn);
title('x(n)');
xlabel('n');
ylabel('Amplitude');
subplot(2,2,2);
stem(n,real(XK));
title('Real part of X(K)');
xlabel('n');
ylabel('Amplitude');
subplot(2,2,3);
stem(n,imag(XK));
title('Imag part of X(K)');
xlabel('n');
ylabel('Amplitude');

OUTPUT:

enter x[n]:[1 2 3 4 4 3 2 1]

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

0 -5.8284 +2.4142i
RESULT:

Thus, the program for the DFT and IDFT of a sequence without using the inbuilt functions
was executed successfully using MATLAB and the results were plotted.
Exp. No. 3b

IMPLEMENTATION OF DECIMATION-IN-TIME RADIX-2 FFT ALGORITHM

AIM:
To implement the Decimation –in Frequency FFT of a sequence using DIT-FFT method

TOOLS REQUIRED:

Mat lab software


Personal computer

PROGRAM:
Clc;
Clear
all;
Close
all;
DECIMATION IN FREQUENCY [DIF] ALGORITHM

function q=dif(x)

t=nextpow2(length(x)); %Calculate the ndearest exponent of 2

j=[x zeros(1,(2^t)-length(x))] ;% zeropadding

N=length(j); % Length of paddedstructure

S=log2(N); %stages

for stage=S:-

1:1 a=1;

b=1+2^(stage-1); %Initialise a and b for each

stage n=0;

while(n<=2^(stage-1)-1 && a<=N

&&b<=N) l=(n).*(2^(S+1-stage))./2;

e=exp((-1i)*2*pi*l/(16)); %Twiddle

factor y=j(a)+j(b);

z=(j(a)-j(b)).*e; % Butterfly
structure j(a)=y;
j(b)=z;
a=a+1; % Increment a,b and n

b=b+1;

n=n+1;

if (stage==1) % Discontinuity in the butterfly


structure

if(rem(1,a)==1) % in a particular stage

a=a+2^(stage-1);

b=b+2^(stage-1);

n=0;

end

end

if(stage~=1)

if(rem(a,2^(stage-1))==1)

a=a+2^(stage-1);

b=b+2^(stage-1);

n=0;

end

end

end

end

j=bitrevorder(j); % Bit reverse the output sequence

disp(j);

q=j;

end

RESULT:

Thus, the program for the DFT and IDFT of a sequence without using the inbuilt functions was
executed successfully using MATLAB and the results were plotted.
Exp. No. 4a

LINEAR CONVOLUTION USING DFT AND IDFT

AIM:
To compute linear convolution of two given sequences using inbuilt MATLAB functions FFT and
IFFT for DFT and IDFT.

TOOLS REQUIRED:

Mat lab software


Personal computer

PROGRAM:
clc;
clear all;
close all;
xn=input(‘enter the first sequence x(n)=’);
hn=input(‘enter the second sequence h(n)=’);
N=length(xn)+length(hn)-1;
Xk=fft(xn,N);
Hk=fft(hn,N);
Yk=Xk*Hk;
yn=ifft(Yk,N);
disp(‘linear convolution of x(n) and h(n)=’);
disp(yn);
subplot(2,2,1);
stem(xn);
xlabel(‘n’);
ylabel(‘x(n)’);
title(‘plot of x(n)’);
subplot(2,2,2);
stem(hn);
xlabel(‘n’);
ylabel(‘h(n)’);
title(‘plot of h(n)’);
subplot(2,2,3);
xlabel(‘n’);
ylabel(‘y(n)’);
title(‘convolution output’);
yv=conv(xn,hn);
disp(‘convolution in time domain=’);
disp(yv);
subplot(2,2,4);
stem(yv);
xlabel(‘n’);
ylabel(‘yv(n)’);
title(‘verified convolution output’);
OUTPUT:

Enter the first sequence x(n)= [ 1 2 3]


Enter the second sequence h(n)= [4 5 6]
Linear convolution of x(n) and h(n)= 4.0000 13.0000 28.0000 27.0000 18.0000
Convolution in time domain= 4 13 28 27 18

RESULT:
Linear convolution of two given sequences was found using DFT and
IDFT in MATLAB and the result was verified.
Exp. No. 4b

CIRCULAR CONVOLUTION USING DFT AND IDFT

AIM:
To compute circularr convolution of two given sequences using inbuilt MATLAB functions FFT
and IFFT for DFT and IDFT.

TOOLS REQUIRED:

Mat lab software


Personal computer

PROGRAM:
clc;
clear all;
close all;
xn=input(‘enter the first sequence x(n)=’);
hn=input(‘enter the second sequence h(n)=’);
N=max(length(xn),length(hn));
Xk=fft(xn,N);
Hk=fft(hn,N);
Yk=Xk.*Hk;
yn=ifft(Yk,N);
disp(‘circular convolution of x(n) and h(n)=’);
disp(yn);
subplot(2,2,1);
stem(xn);
xlabel(‘n’);
ylabel(‘x(n)’);
title(‘plot of x(n)’);
subplot(2,2,2);
stem(hn);
xlabel(‘n’);
ylabel(‘h(n)’);
title(‘plot of h(n)’);
subplot(2,2,3);
stem(yn);
xlabel(‘n’);
ylabel(‘y(n)’);
title(‘circular convolution output’);

OUTPUT:
enter the first sequence x(n)= [5 6 7]
Enter the second sequence h(n)= [4 3 2]
Circular convolution of x(n) and h(n)= [53 53 56]
RESULT:
Thus, the Circular convolution of two given sequences was found using DFT and IDFT in
MATLAB.

Ex. No: 5

SPECTRUM ANALYSIS USING DFT


AIM:
To write MATLAB program for spectrum analyzing signal using DFT.

TOOLS REQUIRED:

Mat lab software


Personal computer
PROCEDURE:
1. Start the MATLAB program.

2. Open new M-file

3. Type the program

4. Save in current directory

5. Compile and Run the program

6. If any error occurs in the program correct the error and run it again

7. For the output see command window\ Figure window

8. Stop the program.


PROGRAM: (Spectrum Analysis Using DFT)
N=input('type length of DFT= ');
T=input('type sampling period= '); freq=input('type
the sinusoidal freq= '); k=0:N-1;
f=sin(2*pi*freq*1/T*k);
F=fft(f); stem(k,abs(F));
grid on; xlabel('k');
ylabel('X(k)');

INPUT:
type length of DFT=32 type
sampling period=64
type the sinusoidal freq=11

OUTPUT: (Spectrum Analysis Using DFT)

RESULT:
Thus the Spectrum Analysis of the signal using DFT was obtained using MATLAB.
Ex. No: 6
DESIGN OF BUTTERWORTH IIR FILTER (LOW PASS, HIGH PASS)

AIM :
To write a MATLAB program for designing butterworth IIR Filter for low pass and high pass
circuits.
TOOLS REQUIRED:

Mat lab software Personal


computer
PROCEDURE:
1. Start the MATLAB program.

2. Open new M-file

3. Type the program

4. Save in current directory

5. Compile and Run the program

6. If any error occurs in the program correct the error and run it again

7. For the output see command window\ Figure window

8. Stop the program.

PROGRAM :
clc
clear all;
close all;
rp=input('Enter pass band ripple:');
rs=input('Enter stop band ripple:');
fp=input('Enter pass band freq:');
fs=input('Enter stop band freq:');
f=input('Enter range of freq:');
wp=2*(fp/f);
ws=2*(fs/f);
[n,wn]=buttord (wp,ws,rp,rs);
[b,a]=butter(n,wn,'high'); [b,a]=butter(n,wn, 'low');
[h,w]=freqz(b,a);
subplot(2,1,1); plot(w/pi,20* log(abs(h)));
grid;
xlabel('nf');
ylabel('mag');
title('mag response');
subplot(2,1,2);
plot(w/pi,angle(h));
grid;
xlabel('nf');
ylabel('angle');
title('phase response');

INPUT :
Enter pass band ripple : 05
Enter stop band ripple : 30
Enter pass band freq : 340
Enter stop band freq : 725
Enter range of freq : 4530

RESULT :

Thus, the design of butterworth LPF and HPF using MATLAB was observed for the above
parameters.
Ex. No: 8
DESIGN OF FIR FILTERS

AIM :
To write and simulate a MATLAB program for designing FIR filters i.e., low pass, high pass and
band pass Filters.
TOOLS REQUIRED:

Mat lab software Personal


computer
PROCEDURE:
1. Start the MATLAB program.

2. Open new M-file

3. Type the program

4. Save in current directory

5. Compile and Run the program

6. If any error occurs in the program correct the error and run it again

7. For the output see command window\ Figure window

8. Stop the program.

PROGRAM :
clc;
close all;
clear all;
f=input('Enter frequency range:');
fs=input('Enter sampling range:');
n=input('Enter order of filter:');
w=f/(fs/2);
b=fir1(n,w, 'low');
freqz(b,1,128,fs);
figure;
w=f/(fs/2);
b=fir1(n,w,'high');
freqz(b,1,128,fs);
figure;
b=fir1(n, [f/(fs/2) (f+600)/(fs/2)], 'bandpass');
freqz(b,1,128,fs);

INPUT:
Enter frequency range: 1500
Enter sampling range: 9300
Enter order of filter: 63
RESULT :

Thus, a MATLAB program for designing FIR filters i.e., low pass, high pass and band pass Filters
was simulated and results were observed for the above parameters.
Ex. No: 9
DESIGN FIR LPF USING DIFFERENT WINDOW TECHNIQUES
AIM :
To write and simulate a MATLAB program for designing FIR filters i.e., low pass Filter using
various window techniques.

TOOLS REQUIRED:

Mat lab software Personal computer

PROCEDURE:
1. Start the MATLAB program.

2. Open new M-file

3. Type the program

4. Save in current directory

5. Compile and Run the program

6. If any error occurs in the program correct the error and run it again

7. For the output see command window Figure window

8. Stop the program.

PROGRAM :
clc;
close all;
clear all;
n=input("Enter order of filter:");
fp=input("Enter pass band freq:" );
fa=input("Enter stop band freq:");
f=input("Enter range of freq:");
wp=2*(fp/f);
wa=2*(fa/f);
wn=[wp,wa];
window=boxcar(n+1);
window=bartlett(n+1);
window=hamming(n+1);
window=hanning(n+1);
window=kaiser(n+1);
b=fir1(n,wn,window);
[H,w]=freqz(b,1);
subplot(2,1,1);
plot(w/pi,20*log(abs(H)));
xlabel('nf');
ylabel('mag in db');
title('mag response');
subplot(2,1,2);
plot(w/pi,angle(H));
xlabel('nf');
ylabel('angle');
title("phase response")

INPUT:

Enter order of filter: 19


Enter pass band freq: 259
Enter stop band freq:559
Enter range of freq: 1667
RESULT:

Thus, a MATLAB program for designing FIR low pass filter using various window techniques was
simulated and results were observed.
Ex. No: 10
DESIGN OF CHEBYSHEV’S TYPE I AND TYPE II FILTERS

AIM :
To write and simulate a MATLAB program for designing Chebyshev’s type I and type II filters
i.e., low pass, high Filters.
TOOLS REQUIRED:

Mat lab software Personal


computer
PROCEDURE:
1. Start the MATLAB program.

2. Open new M-file

3. Type the program

4. Save in current directory

5. Compile and Run the program

6. If any error occurs in the program correct the error and run it again

7. For the output see command window\ Figure window

8. Stop the program.

PROGRAM :
clc;
clear all;
close all;
format long;
rp=input(“Enter pass band ripple:”);
rs = input (“Enter stop band ripple:”);
wp = input (“Enter pass band freq:”);
ws = input (“Enter stop band freq:”);
fs = input (“Enter sampling freq:”);
w1 = 2*(wp/fs);
w2 = 2*(ws/fs);
c = input (‘Select any type’);
switch c
case 1
[n,wn] = cheb1ord (w1,w2,rp,rs,’s’);
[b,a] = cheby1(n,wn,rp,’low’,’s’);
case 2
[n,wn] = cheb1ord (w1,w2,rp,rs,’s’);
[b,a] = cheby1(n,wn,rp,’high’,’s’);
case 3
[n,wn] = cheb2ord (w1,w2,rp,rs,’s’);
[b,a] = cheby2(n,wn,rp,’s’);
case 4
[n,wn] = cheb2ord (w1,w2,rp,rs,’s’);
[b,a] = cheby2(n,wn,rp,’high’,’s’);
end
w = 0: 0.01: pi;
[h,om] = freqs(b,a,w);
m = 20*log 10(abs(h));
an = angle(h);
subplot (2,1,1);
plot (om/pi, m);
grid;
xlabel (‘nf’);
ylabel (‘mag’);
title (‘Magnitude Response’);
subplot (2,1,2);
plot (om/pi, an);
grid;
xlabel (‘nf’);
ylabel (‘angle’);
title (‘phase response’);

INPUT:
Enter pass band ripple: 8
Enter stop band ripple: 30
Enter pass band freq: 389
Enter stop band freq: 732
Enter sampling freq: 4656
Select any type: 1,2,3,4
RESULT:

Thus, a MATLAB program for designing of Chebyshev type-I and type-II filters (low pass, high)
was simulated and results were observed.

Ex. No: 10a

CONVERSION OF ANALOG FILTERS INTO DIGITAL FILTERS USING IMPULSE INVARIANT METHOD

AIM :
To write and simulate a matlab program for conversion of analog filters into digital filters using
impulse invariant method
.
TOOLS REQUIRED:

Mat lab software Personal


computer
PROCEDURE:
1. Start the MATLAB program.

2. Open new M-file

3. Type the program

4. Save in current directory

5. Compile and Run the program


6. If any error occurs in the program correct the error and run it again

7. For the output see command window\ Figure window

8. Stop the program.

PROGRAM :
clc;
clear all;
close all;
b=[-1,6];
a=[1,-2, -8];
f=5;
[bz,az]=impinvar(b,a,f)
freqz(bz,az,f)

OUTPUT :
bz = -0.2000 0.5488
az = 1.0000 -2.8959 1.4918
RESULT:
Thus, a MATLAB program for conversion of analog filters into digital filters using impulse
invariant method was simulated and results were observed for above parameters.

Ex. No: 10b

CONVERSION OF ANALOG FILTERS INTO DIGITAL FILTERS USING BILINEAR


TRANSFORMATION METHOD

AIM :
To write and simulate a matlab program for conversion of analog filters into digital filters using
bilinear transformation method.
.
TOOLS REQUIRED:

Mat lab software Personal


computer
PROCEDURE:
1. Start the MATLAB program.

2. Open new M-file

3. Type the program


4. Save in current directory

5. Compile and Run the program

6. If any error occurs in the program correct the error and run it again

7. For the output see command window\ Figure window

8. Stop the program.

PROGRAM :
clc;
clear all;
close all;
b=[-1 ,5];
a=[2,-4, -7];
f=6;
[bz,az]=bilinear(b,a,f)
freqz(bz,az,f)

OUTPUT :
bz = -0.0300 0.0429 0.0730

az = 1.0000 -2.5322 1.4120


RESULT:
Thus, a MATLAB program for conversion of analog filters into digital filters using bilinear
transformation method was simulated and results were observed for above parameters.
Ex. No: 11
COMPUTE INTERPOLATION AND DECIMATION OF A SEQUENCE

AIM :

To write and simulate a matlab program for computation of interpolation and decimation of a sequence
.
.
TOOLS REQUIRED: m
p
M
u
a
t
t
e
r
l
a PROCEDURE:

b 1. Start the MATLAB


program.
2. Open new M-file
s
o 3. Type the program

f 4. Save in current
directory
t
w 5. Compile and Run the
program
a
6. If any error occurs in
r the program correct
e the error and run it
again

P 7. For the output see


command window\
e Figure window
r 8. Stop the program.
s
o PROGRAM :
n clc;
a close all;
clear all;
l x=input('Enter the sequence:');
l=input('Enter the sampling factor:');
y=upsample(x,l);
c subplot(4,1,1);
o stem(x);
xlabel(‘time’);
ylabel(‘amplitude’);
title(‘input’); xlabel(‘time’);
subplot(4,1,2); ylabel(‘amplitude’);
stem(y); title(‘downsample’);
xlabel(‘time’);
ylabel(‘amplitude’); INPUT:
title(‘upsample’);
c=downsample(y,l); Enter the sequence:[1 4 6 7 8]
subplot(4,1,3); Enter the sampling frequency: 4
stem(c);

RESULT:
Thus, a MATLAB program for computation
of interpolation and decimation of a sequence
was simulated and results were observed for
above parameters.

You might also like