0% found this document useful (0 votes)
83 views30 pages

Digital Signal Processing

This document describes 7 experiments related to signal processing and digital filter design using MATLAB. Experiment 1 involves representing basic signals like unit step, impulse, ramp, exponential, sine and cosine functions using MATLAB programs. Experiment 2 develops a program for discrete convolution. Experiment 3 develops a program for discrete correlation. Experiment 4 explains stability testing of systems. Experiment 5 explains the sampling theorem. Experiment 6 designs analog filters including low-pass, high-pass, band-pass and band-stop filters. Experiment 7 designs digital filters including low-pass, high-pass, band-pass and band-stop filters using Chebyshev and Butterworth approaches.
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)
83 views30 pages

Digital Signal Processing

This document describes 7 experiments related to signal processing and digital filter design using MATLAB. Experiment 1 involves representing basic signals like unit step, impulse, ramp, exponential, sine and cosine functions using MATLAB programs. Experiment 2 develops a program for discrete convolution. Experiment 3 develops a program for discrete correlation. Experiment 4 explains stability testing of systems. Experiment 5 explains the sampling theorem. Experiment 6 designs analog filters including low-pass, high-pass, band-pass and band-stop filters. Experiment 7 designs digital filters including low-pass, high-pass, band-pass and band-stop filters using Chebyshev and Butterworth approaches.
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/ 30

EXPERIMENT:-1

AIM :- To represent basic signals (Unit step,Unit


impulse,Ramp,Exponential, Sine and Cosine).

APPARATUS :- MATLAB software,Microsoft Word.


PROGRAMS :-
(1).Unit step Sequence :-

% Unit step sequence


N = 21;
x = ones (1,N);
n = 0:1:N-1;-
subplot (2,2,1),stem (n,x);
xlabel ('n'),ylabel ('x(n)');
title ('Unit step sequence');

Output :-

(2).Exponential Function :-

% Exponential sequence
x2 = .8.^(n);
subplot (2,2,3),stem (n,x2);
xlabel('n');
ylabel('x2(n)');

1
title('Exponential sequence');
Output :-

(3). Unit Impulse function :-

% Program for unit impulse


n=-3:1:3;
y=[zeros(1,3),ones(1,1),zeros(1,3)];
subplot(3,2,6);
stem(n,y,'k');
xlabel('Time');
ylabel('Amplitude');
title('Unit impulse');

Output:-

2
(4).Sine Function :-
% 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');

Output:-

(5).Cosine Function :-

% Program for cosine wave


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

EXPERIMENT:-2

AIM :- To develop program for discrete convolution.

APPARATUS :- MATLAB software,Microsoft Word.


PROGRAMS:-
% Convolution of two sequences
clear all;
x = [1,0,-1,1,2,1]; % input sequence
N1 = length (x);
h = [1,1,1,1,1]; % input sequence
N2 = length(h);
y = conv (x,h) % output sequence
n = 0:1:N1+N2-2;
stem (n,y);
title ('Convolution of two sequences x(n)and h(n)');
xlabel ('n'), ylabel('y(n)');

Output:-

y=1 1 0 1 3 3 3 4 3 1

4
EXPERIMENT:-3

AIM :- To develop program for discrete correlation.

APPARATUS :- MATLAB software,Microsoft Word.


PROGRAMS:-
% Program for computing Cross-Correlation of the Sequences.
clc;
clear all;
close all;
x=input('Enter the sequence 1: ');
h=input('Enter the sequence 2: ');
y=xcorr(x,h);
figure;
subplot(3,1,1);
stem(x);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 1');
subplot(3,1,2);
stem(fliplr(y));
stem(h);

5
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 2');
subplot(3,1,3);
stem(fliplr(y));
xlabel('n->');
ylabel('Amplitude->');
title('Output sequence');
disp('The resultant is');
fliplr(y);

Output:-
Enter the sequence 1: 3
Enter the sequence 2: 6
The resultant is = 9

6
EXPERIMENT:-4

AIM :- To understand stability test.

7
APPARATUS :- MATLAB software,Microsoft Word.
PROGRAMS:-
%Program for stability test
clc;
clear all;
close all;
b=input('enter numerator coefficients ');
c=input('enter denominator coefficients ');
sys=tf(b/c);
z=isstable(sys);
if(z==1)
disp('''Stable system''');
else
disp('''Non-stable System''');
end

Output:-
Enter numerator coefficients: 54
Enter denominator coefficients: 79
'Stable system'

EXPERIMENT:-5

AIM :- To understand sampling therom.

8
APPARATUS :- MATLAB software,Microsoft Word.
PROGRAMS:-
%Program to understand sampling theorem
clc;
clear all;
close all;
f1=1/128;
f2=5/128;
n=0:127;
fc=50/128;
x=cos(2*pi*f1*n)+cos(2*pi*f2*n);
xa=cos(2*pi*fc*n);
xamp=x.*xa;
subplot(4,1,1);
stem(n,x);
title('modulating wave');
xlabel('n');
ylabel('x');
subplot(4,1,2);
stem(n,xa);
title('carrier wave');
xlabel('n');
ylabel('xa');
subplot(4,1,3);
stem(n,xamp);
title('amplitude modulated wave');
xlabel('n');
ylabel('xamp');
n1=128;
xam=fft(xamp,n1);
subplot(4,1,4);
stem(n,xam);
xlabel('time');
ylabel('amplitude')

Output:-

9
10
EXPERIMENT:-6

AIM :- To design analog filter (low –pass,high-pass,band-pass,band-stop).

APPARATUS :- MATLAB software,Microsoft Word.


PROGRAMS:-
LPF:-
%program for the design of butterworth low pass filter
clc;
close all;
clear all;
format long;
rs=input('Enter the stopband ripple=');
rp=input('Enter the passband ropple=');
ws=input('Enter the stopband freq.=');
wp=input('Enter the passband freq.=');
fs=input('Enter the sampling freq.=');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[z,p,k]=butter(n,wn);
[b,a]=zp2tf(z,p,k);
[b,a]=butter(n,wn);
w=0: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('GainindB.......>');
xlabel('(a)Normalised frequency.......>');
subplot(2,1,2);
plot(om/pi,an)
xlabel('(b)Normalised frequency........>');
ylabel('Phase in radians.........>');

11
Output:-
Enter the stopband ripple=60
Enter the passband ropple=0.15
Enter the stopband freq.=3000
Enter the passband freq.=1500
Enter the sampling freq.=7000

12
HPF:-

%program for the design of butterworth high pass filter


clc;
close all;
clear all;
rp = input('Enter passband ripple freq.=');
rs = input('Enter stopband ripple freq.=');
wp = input('Enter passband freq.=');
ws = input('Enter stopband freq.=');
f= input('Sample freq.=');
w1= 2*wp/f;
w2= 2*ws/f;
[n,wn]= buttord(w1 ,w2,rp,rs);
[b,a]= butter(n,wn,'high');
w=0:0.1 :pi;
[h,p]= freqz(b,a,w);
g= 20*log10(abs(h));
A=angle(h);
subplot (2,2,1); plot(p/pi,g);
ylabel('Amp.......>');
xlabel('Freq......>');
title('Amp.Freq......>');
subplot (2,2,2); plot(p/pi,A);
xlabel('Normal.freq.......>');
ylabel('Phase......>');

13
Output:-
Enter passband ripple freq.=0.2
Enter stopband ripple freq.=40
Enter passband freq.=2000
Enter stopband freq.=3500
Sample freq.=8000

14
BPF:-
%program for the design of butterworth bandpass filter
clc;
close all;
clear all;
format long;
rp = input('Enter pass ripple freq:');
rs = input('Enter stop ripple freq:');
wp = input('Enter pass band freq:');
ws = input('Enter stop band freq:');
fs = input('Enter sample freq:');
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: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('amp…………>');
xlabel('ferq………>');
title('amp,freq…………>');
subplot (2,1,2);
plot(om/pi,an);
xlabel('Normalised freq…………>');
ylabel('phase…………');
title('Normalised Freq,phase……….>');

15
Output:-

Enter pass ripple freq:0.36


Enter stop ripple freq:36
Enter pass band freq:1500
Enter stop band freq:2000
Enter sample freq:6000

16
BSF:-
%program for the design of butterworth bandstop filter
clc;
close all;
clear all;
format long;
rp = input('Enter pass ripple freq:');
rs = input('Enter stop ripple freq:');
wp = input('Enter pass band freq:');
ws = input('Enter stop band freq:');
fs = input('Enter sample freq:');
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: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('amp');
xlabel('ferq');
title('amp,freq');
subplot (2,1,2);
plot(om/pi,an);
xlabel('Normalised freq');
ylabel('phase');
title('Normalised Freq,phase');

17
Output:-
Enter pass ripple freq:0.28
Enter stop ripple freq:28
Enter pass band freq:1000
Enter stop band freq:14000
Enter sample freq:5000

18
EXPERIMENT:-7

AIM :- To design digital filter (low –pass,high-pass,band-pass,band-stop).

APPARATUS :- MATLAB software,Microsoft Word.


PROGRAMS:-

LPF:-

%program for the design of chebyshev lowpass filter


clc;
close all;
clear all;
format long;
rp = input('Enter passband ripple freq:');
rs = input('Enter stopband ripple freq:');
wp = input('Enter passband freq:');
ws = input('Enter stopband freq:');
fs= input('Sample freq');
w1= 2*wp/fs;
w2= 2*ws/fs;
[n,wn]= cheb1ord(w1,w2,rp,rs);
[b,a]= cheby1(n,rp,wn);
w=0:0.01:pi;
[h,om]= freqz(b,a,w);
m= 20*log10(abs(h));
an=angle(h);
subplot (2,1,1);
plot(om/pi,m);
ylabel('Gain in db........>');
xlabel('Freq..........>');
title('Amp.Freq');
subplot (2,1,2);
plot(om/pi,an);
xlabel('Normal. freq.........>');
ylabel('Phase radians......>');

19
title('Normal.Freq,phase');

Output:-

Enter passband ripple freq:45


Enter stopband ripple freq:0.2
Enter passband freq:1500
Enter stopband freq:1300
Sample freq10000

20
HPF:-

%program for the design of chebyshev highpass filter


clc;
close all;
clear all;
format long;
rp = input('Enter passband ripple freq:');
rs = input('Enter stopband ripple freq:');
wp = input('Enter passband freq:');
ws = input('Enter stopband freq:');
fs= input('Sample freq');
w1= 2*wp/fs;
w2= 2*ws/fs;
[n,wn]= cheb1ord(w1,w2,rp,rs);
[b,a]= cheby1(n,rp,wn,'high','s');
w=0:0.01:pi;
[h,om]= freqz(b,a,w);
m= 20*log10(abs(h));
an=angle(h);
subplot (2,1,1);
plot(om/pi,m);
ylabel('Gain in db........>');
xlabel('Freq..........>');
title('Amp.Freq');
subplot (2,1,2);

21
plot(om/pi,an);
xlabel('Normal. freq.........>');
ylabel('Phase in radians........>');
title('Normal.Freq,phase');

Output:-

Enter passband ripple freq:0.3


Enter stopband ripple freq:70
Enter passband freq:1600
Enter stopband freq:2500
Sample freq:9000

22
BPF:-

%program for the design of chebyshev bandpass filter


clc;
close all;
clear all;
format long;
rp = input('Enter passband ripple freq:');
23
rs = input('Enter stopband ripple freq:');
wp = input('Enter passband freq:');
ws = input('Enter stopband freq:');
fs= input('Sample freq');
w1= 2*wp/fs;
w2= 2*ws/fs;
[n]= cheb1ord(w1,w2,rp,rs,'s');
wn=[w1 w2];
[b,a]= cheby1(n,rp,wn,'bandpass','s');
w=0:0.01:pi;
[h,om]= freqz(b,a,w);
m= 20*log10(abs(h));
an=angle(h);
subplot (2,1,1);
plot(om/pi,m);
ylabel('Gain in db........>');
xlabel('Freq..........>');
title('Amp.Freq');
subplot (2,1,2);
plot(om/pi,an);
xlabel('Normal. freq.........>');
ylabel('Phase in radians........>');
title('Normal.Freq,phase');

ssOutput:-
Enter passband ripple freq:0.4
Enter stopband ripple freq:35
Enter passband freq:2000
Enter stopband freq:2500
Sample freq:10000

24
BSF:-

%program for the design of chebyshev bandstop filter


clc;
close all;
clear all;
format long;
25
rp = input('Enter passband ripple freq:');
rs = input('Enter stopband ripple freq:');
wp = input('Enter passband freq:');
ws = input('Enter stopband freq:');
fs= input('Sample freq');
w1= 2*wp/fs;
w2= 2*ws/fs;
[n]= cheb1ord(w1,w2,rp,rs);
wn=[w1 w2];
[b,a]= cheby1(n,rp,wn,'stop');
w=0:0.01/pi:pi;
[h,om]= freqz(b,a,w);
m= 20*log10(abs(h));
an=angle(h);
subplot (2,1,1);
plot(om/pi,m);
ylabel('Gain in db........>');
xlabel('Freq..........>');
title('Amp.Freq');
subplot (2,1,2);
plot(om/pi,an);
xlabel('Normal. freq.........>');
ylabel('Phase in radians........>');
title('Normal.Freq,phase');

Output:-

Enter passband ripple freq:40


Enter stopband ripple freq:0.25
Enter passband freq:2750

26
Enter stopband freq:2500
Sample freq:7000

EXPERIMENT:-8

AIM :- To design FIR filter using windows technique.

APPARATUS :- MATLAB software,Microsoft Word.


27
PROGRAMS:-
%Program for the design if FIR low pass,high pass,band pass,band stop
using rectangular window.

clear all;
rp=input('Enter the PB ripple rp =');
rs=input('Enter the SB ripple rs =');
fp=input('Enter the PB ripple fp =');
fs=input('Enter the SB ripple fs =');
f=input('Enter the sampling frequency f =');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
n=n1;
n=n-1;
end;
y=boxcar(n1);

%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db-------->.');
title('MAGNITUDE RESPONSE OF LPF');

%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);

28
plot(o/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db-------->');
title('MAGNITUDE RESPONSE OF HPF');

%BPF
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);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BPF');

%BSF
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);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BSF');

Output:-

Enter the PB ripple rp =0.04


29
Enter the SB ripple rs =0.03
Enter the PB ripple fp =1500
Enter the SB ripple fs =2000
Enter the sampling frequency f =9000

30

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy