SP FINAL

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 68

CMS COLLEGE OF ENGINEERING

ERNAPURAM, NAMAKKAL – 637003

DEPARTMENT OF BIOMEDICAL ENGINEERING

BM3401 SIGNAL PROCESSING

Name : …....................................................

Reg. No. : ……………………………………

Branch : ……………………………………

Year & Semester : ……………………………………


CMS COLLEGE OF ENGINEERING
ERNAPURAM, NAMAKKAL – 637003

BONAFIDE CERTIFICATE

Certified that this is the bonafide record of work done in BM3401 SIGNAL PROCESSING by

Mr./Ms...................................................... of FOURTH SEMESTER of BIOMEDICAL

ENGINEERING during the academic year 2023-2024.

STAFF-IN-CHARGE HEAD OF DEPARTMENT

Submitted for the University Practical Examination held on ............................ his/her

University number is.........................................

INTERNAL EXAMINER EXTERNAL EXAMINER


INDEX
Page
Exp. No. Date Name of the Experiment No. Mark Sign.
Ex. No: 1
Date :
GENERATION OF DISCRETE TIME SIGNALS

AIM:

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

APPARATUS REQUIRED:

HARDWARE : Personal Computer

SOFTWARE : MATLAB

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.
PROGRAMS: (GENERATION OF BASIC SIGNALS)

%Program for generation of unit impulse signal


t=-3:1:3;
y=[zeros(1,3),ones(1,1),zeros(1,3)];
Subplot (2, 2,1);
stem (t,y);
ylabel('amplitude');
xlabel('time period');
title('unit impulse')

%Program for generation of unit step signal


n=input('enter the sample length of unit step sequence');
t=0:1:n-1;
y=ones(1,n);
subplot(2,2,2);
stem(t,y);
ylabel('amplitude');
xlabel('sequence');
title('unit step')

%Program for generation of unit ramp signal


n1=input('enter the sample length of unit ramp sequence');
t=0:n1;
subplot(2,2,3);
stem(t,t);
ylabel('amplitude');
xlabel('sequence');
title('unit ramp')

%Program for generation of discrete exponential signal:


n2=input('enter the length of the exponential sequence');
t=0:n2;
a=input('enter the a value');
y2=exp(a*t);
subplot(2,2,4);
stem(t,y2);
ylabel('amplitude');
xlabel('time period');
title('exponential sequence')

%Program for generation of continuous exponential signal:


n3=input('enter the length of the exponential sequence');
t=0:2:n3-1;
a=input('enter the a value');
y3=exp(a*t);
subplot(3,1,1);
stem(t,y3);
ylabel('amplitude');
xlabel('time period');
title('continuous exponential sequence')
%Program for generation of sine wave
t=0:0.01: pi;
y=sin(2*pi*t);
subplot(3,1,2);
stem(t,y);
ylabel('amplitude');
xlabel('time period');
title('sine wave')

%Program for generation of cosine wave


t=0:0.01: pi;
y=cos(2*pi*t);
subplot(3,1,3);
stem(t,y);
ylabel('amplitude');
xlabel('time period');
title('cosine wave')
OUTPUT: (DISCRETE SIGNALS)
Enter the sample length of unit step sequence 8
Enter the length of ramp sequence 6
Enter the length of the exponential sequence 8
Enter the a value 5

unit impulse unit step


1 1
amplitude

amplitude
0.5 0.5

0 0
-4 -2 0 2 4 0 2 4 6 8
time period sequence
17
unit ramp x 10 exponential sequence
6 3
amplitude

amplitude

4 2

2 1

0 0
0 2 4 6 0 2 4 6 8
sequence time period
OUTPUT: (CONTINUOUS SIGNALS)

Enter the length of continuous exponential sequence 10


Enter the a value 5

17
x 10 continuous exponential sequence
3
amplitude

0
0 1 2 3 4 5 6 7 8
tisminee pwearivoed
1
amplitude

-1
0 0.5 1 1.5 2 2.5 3 3.5
time period
cosine wave
1
amplitude

-1
0 0.5 1 1.5 2 2.5 3 3.5
time period

RESULT:
Thus the MATLAB programs for discrete time signal sequence (Unit step,
Unit ramp, Sine, Cosine, Exponential, Unit impulse) using MATLAB function written
and the results were plotted.
Ex. No: 2 ANALYSE THE STABILITY OF A CT SYSTEM
Date: WITH VARIOUS INPUTS

AIM:

To write MATLAB programs for analyse the stability of a CT system with various
inputs.

APPARATUS REQUIRED:

HARDWARE : Personal Computer

SOFTWARE : MATLAB R2014a

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;
% Define the transfer function of
the systemnum = [1 2];
den = [1 3 2];
sys = tf(num, den);

% Define the time vector and


step inputt = 0:0.01:10;
u_step = ones(size(t));

% Simulate the step response of


the system[y_step, t_step] =
lsim(sys, u_step, t);

% Plot the step


responsefigure;
plot(t_step,
y_step);
title('Step
Response');
xlabel('Time
(s)');
ylabel('Amplitud
e');

% Define the impulse input


u_impulse = [1 zeros(1, length(t)-1)];
% Simulate the impulse response of the
system [y_impulse, t_impulse] =
lsim(sys, u_impulse, t);

% Plot the impulse


responsefigure;
plot(t_impulse,
y_impulse);
title('Impulse
Response');
xlabel('Time (s)');
ylabel('Amplitude');

% Define the
sinusoidal input
u_sine =
sin(2*pi*0.5*t);

% Simulate the response of the system to the


sinusoidal input[y_sine, t_sine] = lsim(sys,
u_sine, t);

% Plot the response to the


sinusoidal inputfigure;
plot(t_sine, y_sine);
title('Response to Sinusoidal

Input');xlabel('Time (s)');
ylabel('Amplitude');

% Check the stability of


the systempoles =
pole(sys);
if max(real(poles)) < 0
disp('The system is
stable.');else
disp('The system is unstable.');
end
Output:

RESULT:
Thus, the MATLAB program of analysis of the stability of a CT system with various
input results was obtained.
EXP. NO: 3 ANALYSE THE STABILITY OF A DT SYSTEM WITH VARIOUS INPUTS.

Date :

AIM:
To write a MATLAB program for the analyses the stability of a system with various inputs.

APPARATUS REQUIRED:

HARDWARE : Personal Computer

SOFTWARE : MATLAB R2014a

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:
clear
clc
close all

%%%%%%INPUT COEFFICIENTS OF CHARACTERISTIC POLYNOMIAL HERE%%%%%


%coeff = [1,-6,-7,-52];
%coeff = [1,2,1];
%coeff = [1,6,11,7,200];
%coeff = [1,10,31,1030]
syms K % - hey if you have the symbolic toolbox try this
%coeff = [1,18,77,K];
%or this
%coeff = [1,9,(K-10),2]
coeff = [1,9,8,10]

%%%%Create the First Row of the Routh Table


routh_table = [];
first_row = [];
for idx = 1:2:length(coeff)
first_row = [first_row,coeff(idx)];
end
while length(first_row) <= 2
first_row = [first_row,0];
end
disp('First Row')
routh_table = [routh_table;first_row]
%%%%Create the second row of the Routh
Tablesecond_row = [];
for idx = 2:2:length(coeff)
second_row = [second_row,coeff(idx)];
end
while length(second_row) < length(first_row)
second_row = [second_row,0];
end
disp('Second Row')
routh_table = [routh_table;second_row]
routh_table_width = length(first_row);

%%%Now create the next rows


required_rows_to_compute = length(coeff)-2;

%%%Check and see if this is first order or smaller


if required_rows_to_compute < 0
disp('Trivial Solution')
return
end

for loop_row = 1:required_rows_to_compute


row = [];
%disp(['Computing Row ',num2str(loop_row+2)])
disp('Divide All Determinants by this var = ')
divisor = routh_table(loop_row+1,1)
%%THe left part of the determinant for a given row is constant
%Thanks Sumit Godara for pointing that out
%disp('Left Half Determinat')
left_half_det = routh_table(loop_row:loop_row+1,1);
for col = 1:routh_table_width
%disp(['Computing Column ',num2str(col)])
if col == routh_table_width
right_half_det = [0;0];
else
right_half_det = routh_table(loop_row:loop_row+1,col+1);
end
disp('Determinant to be computed')
both_det = [left_half_det,right_half_det]
value = -det(both_det)/divisor;
row = [row,value];
end
disp('Next Row of Routh Table')
routh_table = [routh_table;row]
end

%%%Check for stability


%%%Grab the first column
routh_table
first_column = routh_table(:,1)
s = sign(first_column(1));
unstable = 0;
for idx = 2:length(first_column)
value = first_column(idx);
if s ~= sign(value)
disp('Unstable ')
unstable = 1;
break
end
end
if ~unstable
disp('System is Stable')
end

%%%%%%Check%%%%%
roots(coeff) %%%%Create the second row of
the Routh Tablesecond_row = [];
for idx = 2:2:length(coeff)
second_row = [second_row,coeff(idx)];
end
while length(second_row) < length(first_row)
second_row = [second_row,0];
end
disp('Second Row')
routh_table = [routh_table;second_row]
routh_table_width = length(first_row);

%%%Now create the next rows


required_rows_to_compute = length(coeff)-2;

%%%Check and see if this is first order or smaller


if required_rows_to_compute < 0
disp('Trivial Solution')
return
end

for loop_row = 1:required_rows_to_compute


row = [];
%disp(['Computing Row ',num2str(loop_row+2)])
disp('Divide All Determinants by this var = ')
divisor = routh_table(loop_row+1,1)
%%THe left part of the determinant for a given row is constant
%Thanks Sumit Godara for pointing that out
%disp('Left Half Determinat')
left_half_det = routh_table(loop_row:loop_row+1,1);
for col = 1:routh_table_width
%disp(['Computing Column ',num2str(col)])
if col == routh_table_width
right_half_det = [0;0];
else
right_half_det = routh_table(loop_row:loop_row+1,col+1);
end
disp('Determinant to be computed')
both_det = [left_half_det,right_half_det]
value = -det(both_det)/divisor;
row = [row,value];
end
disp('Next Row of Routh Table')
routh_table = [routh_table;row]
end

%%%Check for stability


%%%Grab the first
column routh_table
first_column = routh_table(:,1)
s = sign(first_column(1));
unstable = 0;
for idx = 2:length(first_column)
value = first_column(idx);
if s ~= sign(value)
disp('Unstable ')
unstable = 1;
break

end
end
if ~unstable
disp('System is Stable')
end

%%%%%%Check%%%%%
roots(coeff)
OUTPUT:
coeff =

1 9 8 10
First row=

route table=

1 8 0

Second row=

route table=

1 8 0

9 10 0

Divide All Determinants by this var =divisor =

9
Determinant to be computedboth_det =

1 8
9 10

Determinant to be computedboth_det =

1 0
9 0

Determinant to be computedboth_det =

1 0
9 0

Next Row of Routh Tablerouth_table =

1.0000 8.0000 0
9.0000 10.0000 0
6.8889 0 0

Divide All Determinants by this var =

divisor =

6.8889
Determinant to be computed

both_det =

9.0000 10.0000
6.8889 0

Determinant to be computed

both_det =

9.0000 0
6.8889 0

Determinant to be computed

both_det =

9.0000 0
6.8889 0

Next Row of Routh Table

routh_table =

1.0000 8.0000 0
9.0000 10.0000 0
6.8889 0 0
10.0000 0 0

routh_table =

1.0000 8.0000 0
9.0000 10.0000 0
6.8889 0 0
10.0000 0 0

first_column =
1.0000
9.0000
6.8889
10.0000

Syatem is stable

ans=
-8.1707 + 0.0000i
-0.4147 + 1.0256i
-0.4147 - 1.0256i

Result:
Thus, the MATLAB program of analysis of the stability of a DT system with various input results was
obtained.
EXP. NO: 4
Date :

RECONSTRUCT A SIGNAL FROM SAMPLES AND STUDY THE EFFECT OF


ALIASING
AIM:
To write a MATLAB program for the reconstruct a signal from samples andstudy the effect of
aliasing.
APPRATUS REQUIRED:
HARDWARE : Personal Computer

SOFTWARE : MATLAB

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;
%% Parameters
F = 30; % frequency of signal [Hz]Fs
= 2*F; % sampling rate [Hz]
Ts = 1/Fs; % sampling period [sec]

%% Generate "continuous time" signal and discrete time signaltc


= 0:1e-4:5/F; % CT axis
xc = cos(2*pi*F*tc); % CT signaltd
= 0:Ts:5/F; % DT axis xd
= cos(2*pi*F*td); % DT signal
N = length(td); % number of samples

%% Reconstruction by using the formula:


% xr(t) = sum over n=0,...,N-1: x(nT)*sin(pi*(t-nT)/T)/(pi*(t-nT)/T)
% Note that sin(pi*(t-nT)/T)/(pi*(t-nT)/T) = sinc((t-nT)/T)
% sinc(x) = sin(pi*x)/(pi*x) according to MATLABxr
= zeros(size(tc)); %initialization
sinc_train = zeros(N,length(tc)); %initialization
for n = 0:N-1
%unless we define our sinc with a value in zero it will introduce NaN which
%lead to a small error
%sinc_train(n+1,:) = sin(pi*(tc-n*Ts)/Ts)./(pi*(tc-n*Ts)/Ts); %sinc train
sinc_train(n+1,:) = sinc((tc-n*Ts)/Ts); %sinc train
current_sinc=xd(n+1)*sinc_train(n+1,:); %a sinc scaled by the sample value
xr = xr + current_sinc; %generation of the reconstructed signal summing the sinc scaled
end
plot the result
figue
hold on
grid on
plot(tc,xc,'b','linewidth',2)
stem(td,xd,'k','linewidth',2)
plot(tc,xr,'r','linewidth',2)
legend('Continuos Signal','Sampled Signal','Reconstructed Signal')
xlabel('Time [sec]')
ylabel('Amplitude')
OUTPUT:

Result:
Thus, the MATLAB program of reconstruct a signal from samples andstudy the effect of aliasing results was
obtained.
EXP. NO: 5
Date :
SPECTRUM ANALYSIS USING FFT
AIM:
To write a MATLAB program for the spectrum analysis using FFT.
APPRATUS REQUIRED:
HARDWARE : Personal Computer

SOFTWARE : MATLAB

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;
% Define the input signal
fs = 100; % Sampling frequency t
= 0:1/fs:1-1/fs; % Time vector
x = sin(2*pi*50*t) + sin(2*pi*120*t); % Signal with two frequencies

% Compute the FFT of the signal


N = length(x); % Length of the signal
X = fft(x)/N; % Normalize the FFT by the length of the signal

% Compute the frequency vector


f = (0:N-1)*(fs/N); % Frequency vector

% Plot the spectrum


figure;
plot(f,abs(X));
title('Single-Sided Amplitude Spectrum of x(t)');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
OUTPUT:

Result:
Thus, the MATLAB program of spectrum analysis using FFT results was obtained.
EXP. NO: 6A
Date:
DESIGN OF FIR FILTERS
(RECTANGULAR WINDOW DESIGN)

AIM:
To write a program to design the FIR low pass, High pass, Band pass and Band stop filters
using RECTANGULAR window and find out the response of the filter by using MATLAB.

APPARATUS REQUIRED:

HARDWARE : Personal Computer

SOFTWARE : MATLAB R2014a

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: (Rectangular Window)
%program for the design of FIR low pass, high pass, band pass and band stop
filter using rectangular window
clc;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
f=input('enter the sampling frequency');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end;
y=boxcar(n1);
%lowpass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
ylabel('gain in db ... >');
xlabel('(a)normalized frequency .... >');

%highpass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
ylabel('gain in db ..... >');
xlabel('(b)normalized frequency..... >');
%bandpass filter
wn=[wp ws];0
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
ylabel('gain in db ... >');
xlabel('(c)normalized frequency ... >');
%bandstop filter
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);
ylabel('gain in db ... >');
xlabel('(d)normalized frequency.... >');
OUTPUT: (Rectangular Window)
Enter the pass band ripple 0.03
Enter the stop band ripple 0.01
Enter the pass band frequency 1400
Enter the stop band frequency 2000
Enter the sampling frequency 8000

MAGNITUDE RESPONSE OF LPF MAGNITUDE RESPONSE OF HPF


50 50
Gain in db ------ --.

Gain in db ------ --.


0 0

-50 -50

-100 -100
0 0.5 1 0 0.5 1
Normalized freqency------> Normalized freqency ----- >
MAGNITUDE RESPONSE OF BPF MAGNITUDE RESPONSE OF BSF
50 20
Gain in db ------ --.

Gain in db ------ --.

0
0
-20
-50
-40

-100 -60
0 0.5 1 0 0.5 1
Normalized freqency -----> Normalized freqency------>
RESULT:
Thus,the program to design FIR low pass, high pass, band pass and band stop Filters using
RECTANGULAR Window was written and response of the filter using MATLAB was executed.
EXP. NO: 6B
Date:
DESIGN OF FIR FILTERS
(HANNING WINDOW DESIGN)
AIM:
To write a program to design the FIR low pass, High pass, Band pass and Band stop
filters using RECTANGULAR window and find out the response of the filter by using
MATLAB.

APPARATUS REQUIRED:

HARDWARE : Personal Computer

SOFTWARE : MATLAB R2014a

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 (HANNING WINDOW);
%program for the design of FIR lowpass, high pass, band pass, band stop filter
using hanning window
clc;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
f=input('enter the sampling frequency');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end;
Y=hanning(n1);

%lowpass filter
b=fir1(n,wp,Y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
ylabel('gain in db ... >');
xlabel('(a)normalized frequency');

%highpass filter
b=fir1(n,wp,'high',Y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
ylabel('gain in db .. >');
xlabel('(b)normalized frequency .. >');

%bandpass filter
wn=[wp ws];
b=fir1(n,wn,Y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
ylabel('gain in db .... >');
xlabel('(c)normalized frequency ...>');

%bandstop filter
b=fir1(n,wn,'stop',Y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);
ylabel('gain in db...>');
xlabel('(d)normalized frequency >')
OUTPUT:

Pass band ripple=0.03

Stop band ripple=0.01

Stop band frequency in rad/sec=2000

Pass band frequency in rad/sec=1400

Sampling frequency in rad/sec=8000

n = 21

LOW PASS FILTER HIGH PASS FILTER


50 50

0
Gain in db --- >

Gain in db --- >

0
-50
-50
-100

-150 -100
0 0.5 1 0 0.5 1
Normalized frequency --- > Normalized frequency --- >
BAND PASS FILTER BAND STOP FILTER
50 5

0
Gain in db--- >

Gain in db--- >

0
-5
-50
-10

-100 -15
0 0.5 1 0 0.5 1
Normalized frequency --- > Normalized frequency --- >

RESULT:

Thus the program to design FIR low pass, high pass, band pass and band stop Filters using
HANNING Window was written and response of the filter using MATLAB was executed.
EXP. NO: 6C
DESIGN OF FIR FILTERS
Date: (HAMMING WINDOW DESIGN)

AIM:
To design a FIR filter using Hamming window with MATLAB 7.0.
APPARATUS REQUIRED:
Hard ware: IBM PC or compatible
Soft ware :Matlab 7.0 or higher
PROCEDURE:
1. Get the pass band and stop band ripple and frequency.
2. Get the sampling frequency.
3. Find the order of filter N.
4. Design the lowpass, High pass, Band pass and Band stop filter.
5. Plot the magnitude response of all the filters.
PROGRAM:

clc;
clear all;
close all;
rp=input('Pass band ripple=');
rs=input('Stop band ripple=');
fs=input('Stop band frequency in rad/sec=');
fp=input('Pass band frequency in rad/sec=');
f=input('Sampling frequency in rad/sec=');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem)
n1=n+1;
if(rem(n,2)~=0);
n1=n;
n=n-1;
end
y=hamming(n1);
%LOW PASS FILTER
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m,'k');
ylabel('Gain in db --->');
xlabel('Normalized frequency --->');
title('LOW PASS FILTER')
%HIGH PASS FILTER
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m,'k');
ylabel('Gain in db --->');
xlabel('Normalized frequency --->');
title('HIGH PASS FILTER')
%BAND PASS FILTER
wn=[wp,ws];
x=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
subplot(2,2,3);
plot(o/pi,m,'k');
ylabel('Gain in db --->');
xlabel('Normalized frequency --->');
title('BAND PASS FILTER')
%BAND STOP FILTER
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m,'k');
ylabel('Gain in db --->');
xlabel('Normalized frequency --->');
title('BAND STOP FILTER')
OUTPUT:

Pass band ripple=0.02

Stop band ripple=0.01

Stop band frequency in rad/sec=1700

Pass band frequency in rad/sec=1200

Sampling frequency in rad/sec=9000

n = 30

LOW PASS FILTER HIGH PASS FILTER


50 50

0
Gain in db -- >

Gain in db -- >

0
-50
-50
-100

-150 -100
0 0.5 1 0 0.5 1
Normalized frequency --- > Normalized frequency --- >
BAND PASS FILTER BAND STOP FILTER
50 5
Gain in db -- >

Gain in db -- >

0
0
-5
-50
-10

-100 -15
0 0.5 1 0 0.5 1
Normalized frequency --- > Normalized frequency --- >

RESULT:
Thus, the program to design FIR low pass, high pass, band pass and band stop Filters
using HAMMING Window was written and response of the filter using MATLAB was
executed.
EXP. NO: 6D
Date:
DESIGN OF FIR FILTERS
(BLACKMAN WINDOW DESIGN)

AIM:
To design a FIR filter using Blackmann window with MATLAB 7.0.
APPARATUS REQUIRED:
Hard ware: IBM PC or compatible
Soft ware :Matlab 7.0 or higher
PROCEDURE:

1. Get the pass band and stop band ripple and frequency.
2. Get the sampling frequency.
3. Find the order of filter N.
4. Design the lowpass,Highpass,Band pass and Band stop filter.
5. Plot the magnitude response of all the filters.
PROGRAM OF FIR FILTER USING BLACKMANN WINDOW:

clc;
clear all;
close all;
rp=input('Pass band ripple=');
rs=input('Stop band ripple=');
fs=input('Stop band frequency in rad/sec=');
fp=input('Pass band frequency in rad/sec=');
f=input('Sampling frequency in rad/sec=');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem)
n1=n+1;
if(rem(n,2)~=0);
n1=n;
n=n-1;
end
y=blackman(n1);
%LOW PASS FILTER
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m,'k');
ylabel('Gain in db --- >');
xlabel('Normalized frequency --->');
title('LOW PASS FILTER')
%HIGH PASS FILTER
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m,'k');
ylabel('Gain in db --- >');
xlabel('Normalized frequency --->');
title('HIGH PASS FILTER')
%BAND PASS FILTER
wn=[wp,ws];
x=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
subplot(2,2,3);
plot(o/pi,m,'k');
ylabel('Gain in db --- >');
xlabel('Normalized frequency --->');
title('BAND PASS FILTER')
%BAND STOP FILTER
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m,'k');
ylabel('Gain in db --- >');
xlabel('Normalized frequency --->');
title('BAND STOP FILTER')
OUTPUT:
Pass band ripple=0.03
Stop band ripple=0.01

Stop band frequency in rad/sec=2500

Pass band frequency in rad/sec=2000

Sampling frequency in rad/sec=7000

n = 22

LOW PASS FILTER HIGH PASS FILTER


50 50

0 0
Gain in db --->

Gain in db --->

-50 -50

-100 -100

-150 -150
0 0.5 1 0 0.5 1
Normalized frequency --- > Normalized frequency --- >
BAND PASS FILTER BAND STOP FILTER
50 5

0
Gain in db --- >

Gain in db --- >

0
-50
-5
-100

-150 -10
0 0.5 1 0 0.5 1
Normalized frequency --- > Normalized frequency --- >

RESULT:
Thus, FIR Filter using Blackman window is designed by using Matlab and result was obtained.
EXP. NO: 6E
Date:
DESIGN OF IIR FILTERS

AIM:
To design a Butterworth and chebychev digital IIR filter using MATLAB 7.0.
APPARATUS REQUIRED:
Hard ware: IBM PC or compatible
Soft ware :Matlab 7.0 or higher

PROCEDURE:
1. Start the program and specify the input datas for each type of filters.
2.Find the order of the filter using built function.
3. Find the number and denominator polynomials for calculation of transfer function.
4. Plot the frequency response and gain for low pass,high pass, band pass and band stop IIR butterworth
filter.
5. Stop the program
PROGRAM:
(BUTTERWORTH FILTER)
clc;
clear all;
close all;
N=8;
wn=0.4;
[num,den]=butter(N,wn,'s');
w=(0:0.01:2);
h=freqs(num,den,w);
subplot(2,2,1);
plot(w/2*pi,(abs(h)),'linewidth',2.5);
title('butterworth low pass filter');
grid on;
xlabel('frequency in hz');
ylabel('gain in db');
[num,den]=butter(N,wn,'high','s');
h=freqs(num,den,w);
subplot(2,2,2);
plot(w/2*pi,(abs(h)),'linewidth',2.5);
title('butterworth high pass filter');
grid on;
xlabel('frequency in hz');
ylabel('gain in db');
N=8;
wp=0.4;
ws=0.6;
wn=[wp ws];
[num,den]=butter(N,wn,'s');
h=freqs(num,den,w);
subplot(2,2,3);
plot(w/2*pi,(abs(h)),'linewidth',2.5);
title('butterworth band pass filter');
grid on;
xlabel('frequency in hz');
ylabel('gain in db');
N=8;
wp=0.4;
ws=0.6;
wn=[wp ws];
[num,den]=butter(N,wn,'stop','s');
h=freqs(num,den,w);
subplot(2,2,4);
plot(w/2*pi,(abs(h)),'linewidth',2.5);
title('butterworth band stop filter');
grid on;
ylabel('gain in db');
xlabel('frequency in hz');
OUTPUT:

butterworth low pass filter butterworth high pass filter


1 1
gain in db

gain in db
0.5 0.5

0 0
0 1 2 3 4 0 1 2 3 4
frequency in hz frequency in hz
butterworth band pass filter butterworth band stop filter
1.5 1.5

1 1
gain in db

gain in db

0.5 0.5

0 0
0 1 2 3 4 0 1 2 3 4
frequency in hz frequency in hz
PROGRAMS: IIR (CHEBYSHEW FILTER)
% chebyshew filter
% get the input values
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband frequency');
ws=input('enter the stopband frequency');
fs=input('enter the sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
%filter order
[n,wn]=cheb1ord(w1,w2,rp,rs);
%lowpass filter
%either coefficient
[b,a]=cheby1(n,rp,wn);
%frequency response
[H,w]=freqz(b,a,512);
subplot(2,2,1);
plot(w,abs(H));
xlabel('normalised frequency');
ylabel('abs(H)');
title('LPF')
%high pass filter
%filter coefficient
[b,a]=cheby1(n,rp,wn,'High');
%frequency response
[H,w]=freqz(b,a,512);
subplot(2,2,2);
plot(w,abs(H));
xlabel('normalised frequency');
ylabel('abs(H)');
title('HPF')
%band pass filter
%filter coefficient
wn1=[w1,w2];
[b,a]=cheby1(n,rp,wn1);
%frequency response
[H,w]=freqz(b,a,512);
subplot(2,2,3);
plot(w,abs(H));
xlabel('normalised frequency');
ylabel('abs(H)');
title('BPF')
%band stop filter
%filter coefficient
wn2= [w1, w2];
%frequency response
[b,a]=cheby1(n,rp,wn2,'stop');
[H,w]=freqz(b,a,512);
subplot(2,2,4);
plot(w,abs(H));
xlabel('normalised frequency');
ylabel('abs(H)');
title('BSF')
OUTPUT:

IIR : (CHEBYSHEW FILTER)


Enter the pass band ripple 6
Enter the stop band ripple 25
Enter the pass band frequency 1300
Enter the stop band frequency 3000
Enter the sampling frequency 8000

LPF HPF
1 1
abs(H)

abs(H)
0.5 0.5

0 0
0 1 2 3 4 0 1 2 3 4
normalised frequency normalised frequency
BPF BSF
1 1
abs(H)

abs(H)

0.5 0.5

0 0
0 1 2 3 4 0 1 2 3 4
normalised frequency normalised frequency

RESULT:
Thus, the digital butterworth and
chebychev IIR Filter are designed by using
Matlab program.
EXP. NO:7
Date: FINITE WORD LENGTH EFFECT
AIM:
To write a MATLAB program for the finite word length.
SOFTWARE REQUIRED:
PC with MATLAB

PROCEDURE:
1. Open the MATLAB
2. Open New file
3. Typethe program
4. Save in current directory
5. Compileand run the program
PROGRAM
clc;
clearall
close all;
fs = 1000; % Sampling
frequency t = 0:1/fs:1-
1/fs; % Time vector
x = sin(2*pi*50*t) + sin(2*pi*120*t); % Signal with two frequencies

% Define the number of bits for the


quantizernbits = 8;

% Quantize the signal using a uniform quantizer


xmax = max(abs(x)); % Maximum amplitude of the
signalq = 2*xmax/(2^nbits-1); % Quantization
step size
xq = round(x/q)*q; % Quantized signal

% Calculate the quantization


errore = x - xq;

% Plot the original and quantized


signalsfigure;
subplot(2,1,1);
plot(t, x);
title('Original
Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2,1,2);
plot(t, xq);
title('Quantized
Signal');xlabel('Time
(s)');
ylabel('Amplitude');
% Plot the quantization error
figure;
plot(t, e);
title('Quantization
Error');xlabel('Time
(s)');
ylabel('Amplitude');
OUTPUT:

Result:
Thus the MATLAB program for the finite word length result was obtained.
EXP. NO:8 MULTIRATE SIGNAL PROCESSING
Date:

AIM:
To write a MATLAB program for the multirate signal processing
SOFTWARE REQUIRED:
PC with MATLAB
PROCEDURE:
1. Open the MATLAB
2. Open New file
3. Typethe program
4. Save in current directory
5. Compile and run the program
PROGRAM:
clc;
clos
e
all;
clea
r
all;
% Define the input signal
fs =700; % Sampling frequency
t = 0:1/fs:1-1/fs; % Time vector
x = sin(2*pi*50*t) + sin(2*pi*120*t); % Signal with two frequencies

% Decimate the signal by a


factor of 2x_dec = decimate(x,
2);

% Interpolate the decimated signal by a


factor of 2x_interp = interp(x_dec, 2);

% Plot the original and interpolated


signalsfigure;
subplot(2,1,1);
plot(t, x);
title('Original
Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2,1,2);
plot(t, x_interp);
title('Interpolated
Signal');xlabel('Time
(s)');
ylabel('Amplitude');
OUTPUT:

RESULT:
Thus, the MATLAB program of multirate signal processing results was obtained.
EXP. NO:9A DSP PROCESSOR IMPLEMENTATION (LINEAR

Date: AND CIRCULAR CONVOLUTION)

AIM:
To design and implement the circular and linear convolution using TMS320C5410 processor
APPARATUS REQUIRED:

TMS320C5410 processor
Personal computer
PROCEDURE:
1. Open New file
2. Typethe program
3. Save in current directory
4. Compile and run the program
PROGRAM:

Output:
PROGRAM:
OUTPUT:

RESULT:
Thus, the circular and linear convolution and circular convolution was implemented using TMS 320C5416.
EXP. NO:9(B)
Date:
DSP PROCESSOR IMPLEMENTATION
(IIR &FIR FILTER)
AIM:
To design and implement IIR(LPF/HPF) filter using TMS320C5416 processor.
APPRATUS REQUIRED:
TMS320C5416 processor
Personal Computer
PROCEDURE:
1. Open New file
2. Typethe program
3. Save in current directory
4. Compile and run the program
PROGRAM (IIR):
OUTPUT:
PROGRAM (FIR);
OUTPUT:
RESULT:
Thus, the IIR filter and FIRfilter was implemented using TMS320C5416 processor.
EXP. NO:9(C)
Date:
DSP PROCESSOR IMPLEMENTATION
(FFT IMPLEMENTATION)
AIM:
To design and implement FFT filter using TMS320C5416 processor.
APPRATUS REQUIRED:
TMS320C5416 processor.
Personal Computer
PROCEDURE:
1. Open New file
2. Typethe program
3. Save in current directory
4. Compile and run the program
PROGRAM:
RESULT:
Thus, the FFT filter was implemented using TMS 320C5416.

You might also like