Digital Signal Processing
Digital Signal Processing
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 :-
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 :-
EXPERIMENT:-2
Output:-
y=1 1 0 1 3 3 3 4 3 1
4
EXPERIMENT:-3
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
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
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
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:-
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:-
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
LPF:-
19
title('Normal.Freq,phase');
Output:-
20
HPF:-
21
plot(om/pi,an);
xlabel('Normal. freq.........>');
ylabel('Phase in radians........>');
title('Normal.Freq,phase');
Output:-
22
BPF:-
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:-
Output:-
26
Enter stopband freq:2500
Sample freq:7000
EXPERIMENT:-8
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:-
30