Sie sind auf Seite 1von 71

DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 1

AM, FM and PWM using MATLAB

AIM
To implement a program in MATLAB to generate Amplitude Modulated (AM),
Frequency Modulated (FM) & Pulse Width Modulated (PWM) waveforms.

PROGRAM
Amplitude Modulated Wave

clc;clear all;close all;


t=0:0.0001:0.015;
m=input('Modulation Index:');
fm=input('Signal frequency:');
fc=input('Carrier frequency:');
x=sin(2*pi*fm*t);
y=sin(2*pi*fc*t);
e=(1+(m.*x)).*y;
plot(e);
title('Amplitude Modulation');
xlabel('Time');
ylabel('Amplitude');

OUTPUT
Modulation Index:0.5
Signal frequency:100
Carrier frequency:1000

Dept. of Electronics & Communication Engg. Page No: 1


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Frequency Modulated Wave


clc;clear all;close all;
a=input('Amplitude:');
fc=input('Carrier frequency:');
fm=input('Signal frequency:');
m=input('Modulation index:');
n=0:0.001:0.2;
y=a*sin(2*pi*fc*n-(m*cos(2*pi*fm*n)));
plot(n,y);
title('Frequency Modulation');
xlabel('Time');
ylabel('Amplitude');

OUTPUT
Amplitude:1
Carrier frequency:100
Signal frequency:10
Modulation index:5

Dept. of Electronics & Communication Engg. Page No: 2


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Pulse Width Modulated Wave


clc;clear all;close all;
fs=100;
t=0:1/(5*fs):2;
x=sawtooth(2*pi*20*t);
m=0.75*sin(2*pi*t);
k=length(x);
for i=1:k
if (m(i)>=x(i))
pwm(i)=1;
else if (m(i)<x(i))
pwm(i)=0;
end;
end;
end;
plot(t,pwm,t,m);
axis([0,-1,-2,2]);
title('Pulse Width Modulation');
xlabel('Time');
ylabel('Amplitude');
Dept. of Electronics & Communication Engg. Page No: 3
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

OUTPUT

RESULT
The programs for AM, FM & PWM signals are implemented in MATLAB and the output
waveforms are generated.

Dept. of Electronics & Communication Engg. Page No: 4


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 2

Linear Convolution

AIM
To write a program in MATLAB for the linear convolution of 2 sequences.

PROGRAM
clc;clear all;close all;
a=input('First sequence:');
b=input('Second sequence:');
c=fliplr(b);
d=length(a);
e=length(b);
f=[zeros(1,e-1),a,zeros(1,e)];
g=0;
i=d+e-1;
for h=0:(d+e-1)
j=[zeros(1,g),c,zeros(1,i)];
k=sum(f.*j);
con(g+1)=k;
g=g+1;
i=i-1;
end;
m=0:d+e-1;
stem(m,con);
title('Convlouted sequence');
xlabel('Time');
ylabel('Amplitude');

Dept. of Electronics & Communication Engg. Page No: 5


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

OUTPUT
First sequence:[1 2 3 4]
Second sequence:[4 3 2 1]

RESULT
The program for convolution of 2 sequences is implemented using MATLAB and the
resulting sequence is graphically generated.

Dept. of Electronics & Communication Engg. Page No: 6


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 3

FIR Filters

AIM
To write a program in MATLAB for implementing FIR filters.

PROGRAM
clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
fp=input('Enter passband frequency:');
fs=input('Enter stopband frequency:');
f=input('Enter 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);
%LOW PASS FILTER
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);

Dept. of Electronics & Communication Engg. Page No: 7


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

plot(o/pi,m);
title('Low Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('High Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%BAND PASS 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);
title('Band Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('Band Stop Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');

Dept. of Electronics & Communication Engg. Page No: 8


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

OUTPUT
Enter passband ripple:0.05
Enter stopband ripple:0.04
Enter passband frequency:1500
Enter stopband frequency:2000
Enter sampling frequency:9000

RESULT
The program for FIR filters are implemented using MATLAB and the corresponding
frequency responses are obtained.

Dept. of Electronics & Communication Engg. Page No: 9


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 4

Butterworth IIR Filters

AIM
To design & simulate Butterworth IIR filters using MATLAB.

PROGRAM
Low Pass Filter
clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
wp=input('Enter passband frequency:');
ws=input('Enter stopband frequency:');
fs=input('Enter passband frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,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);
title('IIR Low Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
Dept. of Electronics & Communication Engg. Page No: 10
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:200
Enter stopband frequency:400
Enter passband frequency:1000

High Pass Filter


clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
wp=input('Enter passband frequency:');
ws=input('Enter stopband frequency:');
fs=input('Enter passband frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);

Dept. of Electronics & Communication Engg. Page No: 11


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

[b,a]=butter(n,wn,'high');
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);
title('IIR High Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:1200
Enter stopband frequency:1000
Enter passband frequency:4000

Dept. of Electronics & Communication Engg. Page No: 12


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Band Pass Filter


clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
wp=input('Enter passband frequency:');
ws=input('Enter stopband frequency:');
fs=input('Enter passband frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,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);
title('IIR Band Pass Filter');
Dept. of Electronics & Communication Engg. Page No: 13
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

ylabel('Gain (in dB)');


xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.4
Enter stopband ripple:50
Enter passband frequency:[800 1200]
Enter stopband frequency:[500 1500]
Enter passband frequency:4000

Band Stop Filter


clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
wp=input('Enter passband frequency:');

Dept. of Electronics & Communication Engg. Page No: 14


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

ws=input('Enter stopband frequency:');


fs=input('Enter passband frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'stop');
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);
title('IIR Band Stop Filter');
ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.4
Enter stopband ripple:50
Enter passband frequency:[800 1500]
Enter stopband frequency:[1000 1200]
Enter passband frequency:4000

Dept. of Electronics & Communication Engg. Page No: 15


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT
The IIR Butterworth filters are designed using MATLAB and the output waveforms are
obtained.
Experiment: 5

Chebyshev Type 1 Filters

AIM
To design & simulate Chebyshev Type 1 filters using MATLAB.

PROGRAM
Low Pass Filter
clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
wp=input('Enter passband frequency:');

Dept. of Electronics & Communication Engg. Page No: 16


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

ws=input('Enter stopband frequency:');


fs=input('Enter passband frequency:');
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);
title('Chebyshev Type 1 Low Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:1000
Enter stopband frequency:1500
Enter passband frequency:4000

Dept. of Electronics & Communication Engg. Page No: 17


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

High Pass Filter


clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
wp=input('Enter passband frequency:');
ws=input('Enter stopband frequency:');
fs=input('Enter passband frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high');
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);

Dept. of Electronics & Communication Engg. Page No: 18


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

title('Chebyshev Type 1 High Pass Filter');


ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:1500
Enter stopband frequency:1000
Enter passband frequency:5000

Band Pass Filter


clc;clear all;close all;
rp=input('Enter passband ripple:');
Dept. of Electronics & Communication Engg. Page No: 19
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

rs=input('Enter stopband ripple:');


wp=input('Enter passband frequency:');
ws=input('Enter stopband frequency:');
fs=input('Enter passband frequency:');
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);
title('Chebyshev Type 1 Band Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:[1000 1200]
Enter stopband frequency:[800 1500]
Enter passband frequency:4500

Dept. of Electronics & Communication Engg. Page No: 20


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Band Stop Filter


clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
wp=input('Enter passband frequency:');
ws=input('Enter stopband frequency:');
fs=input('Enter passband frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'stop');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));

Dept. of Electronics & Communication Engg. Page No: 21


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('Chebyshev Type 1 Band Stop Filter');
ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:[1000 1200]
Enter stopband frequency:[800 1500]
Enter passband frequency:4500

Dept. of Electronics & Communication Engg. Page No: 22


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT
The Chebyshev Type 1 filters are implemented using MATLAB p waveforms are
obtained.

Experiment: 6

Chebyshev type 2 Filters

AIM
To design & simulate Chebyshev Type 2 filters using MATLAB.

PROGRAM
Low Pass Filter
clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
wp=input('Enter passband frequency:');
ws=input('Enter stopband frequency:');
fs=input('Enter passband frequency:');
w1=2*wp/fs;
Dept. of Electronics & Communication Engg. Page No: 23
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

w2=2*ws/fs;
[n,wn]=cheb2ord(w1,w2,rp,rs);
[b,a]=cheby2(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);
title('Chebyshev Type 2 Low Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:1000
Enter stopband frequency:1500
Enter passband frequency:4000

Dept. of Electronics & Communication Engg. Page No: 24


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

High Pass Filter


clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
wp=input('Enter passband frequency:');
ws=input('Enter stopband frequency:');
fs=input('Enter passband frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb2ord(w1,w2,rp,rs);
[b,a]=cheby2(n,rp,wn,'high');
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);

Dept. of Electronics & Communication Engg. Page No: 25


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

title('Chebyshev Type 2 High Pass Filter');


ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:1000
Enter stopband frequency:800
Enter passband frequency:4500

Band Pass Filter


clc;clear all;close all;
rp=input('Enter passband ripple:');

Dept. of Electronics & Communication Engg. Page No: 26


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

rs=input('Enter stopband ripple:');


wp=input('Enter passband frequency:');
ws=input('Enter stopband frequency:');
fs=input('Enter passband frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb2ord(w1,w2,rp,rs);
[b,a]=cheby2(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);
title('Chebyshev Type 2 Band Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:[800 1500]
Enter stopband frequency:[1000 1200]
Enter passband frequency:4500

Dept. of Electronics & Communication Engg. Page No: 27


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Band Stop Filter


clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
wp=input('Enter passband frequency:');
ws=input('Enter stopband frequency:');
fs=input('Enter passband frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb2ord(w1,w2,rp,rs);
[b,a]=cheby2(n,rp,wn,'stop');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);

Dept. of Electronics & Communication Engg. Page No: 28


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('Chebyshev Type 2 Band Stop Filter');
ylabel('Gain (in dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase (radians)');
xlabel('Normalised frequency');

OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:[800 1500]
Enter stopband frequency:[1000 1200]
Enter passband frequency:4500

Dept. of Electronics & Communication Engg. Page No: 29


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT
The Chebyshev Type 2 filters are implemented using MATLAB & the output waveforms
are obtained.

Experiment: 7

FIR Filters Using Window Methods

AIM
To design & simulate FIR filters using various windows such as rectangular, Hamming,
Kaiser, Hanning, Blackman & Bartlett windows in MATLAB.

PROGRAM- RECTANGULAR WINDOW


clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
fp=input('Enter passband frequency:');
fs=input('Enter stopband frequency:');
f=input('Enter sampling frequency:');

Dept. of Electronics & Communication Engg. Page No: 30


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

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=rectwin(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);
title('Low Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('High Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%BAND PASS FILTER
wn=[wp,ws];
b=fir1(n,wn,y);

Dept. of Electronics & Communication Engg. Page No: 31


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
title('Band Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('Band Stop Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');

OUTPUT
Enter passband ripple:0.05
Enter stopband ripple:0.04
Enter passband frequency:1500
Enter stopband frequency:2000
Enter sampling frequency:9000

Dept. of Electronics & Communication Engg. Page No: 32


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

PROGRAM-HAMMING WINDOW
clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
fp=input('Enter passband frequency:');
fs=input('Enter stopband frequency:');

Dept. of Electronics & Communication Engg. Page No: 33


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

f=input('Enter 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=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);
title('Low Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('High Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%BAND PASS FILTER
wn=[wp,ws];

Dept. of Electronics & Communication Engg. Page No: 34


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
title('Band Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('Band Stop Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');

OUTPUT
Enter passband ripple:0.02
Enter stopband ripple:0.01
Enter passband frequency:1200
Enter stopband frequency:1700
Enter sampling frequency:9000

Dept. of Electronics & Communication Engg. Page No: 35


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

PROGRAM-KAISER WINDOW
clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
fp=input('Enter passband frequency:');
fs=input('Enter stopband frequency:');
Dept. of Electronics & Communication Engg. Page No: 36
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

f=input('Enter sampling frequency:');


beta=input('Enter beta value:');
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=kaiser(n1,beta);
%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);
title('Low Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('High Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%BAND PASS FILTER

Dept. of Electronics & Communication Engg. Page No: 37


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

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);
title('Band Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('Band Stop Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');

OUTPUT
Enter passband ripple:0.02
Enter stopband ripple:0.01
Enter passband frequency:1000
Enter stopband frequency:1500
Enter sampling frequency:10000

Dept. of Electronics & Communication Engg. Page No: 38


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Enter beta value:5.8

PROGRAM-HANNING WINDOW
clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
fp=input('Enter passband frequency:');
fs=input('Enter stopband frequency:');

Dept. of Electronics & Communication Engg. Page No: 39


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

f=input('Enter 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);
%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);
title('Low Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('High Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%BAND PASS FILTER
wn=[wp,ws];

Dept. of Electronics & Communication Engg. Page No: 40


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
title('Band Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('Band Stop Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');

OUTPUT
Enter passband ripple:0.03
Enter stopband ripple:0.01
Enter passband frequency:1400
Enter stopband frequency:2000
Enter sampling frequency:8000

Dept. of Electronics & Communication Engg. Page No: 41


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

PROGRAM-BLACKMAN WINDOW
clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
fp=input('Enter passband frequency:');

Dept. of Electronics & Communication Engg. Page No: 42


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

fs=input('Enter stopband frequency:');


f=input('Enter 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=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);
title('Low Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('High Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%BAND PASS FILTER

Dept. of Electronics & Communication Engg. Page No: 43


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

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);
title('Band Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('Band Stop Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');

OUTPUT
Enter passband ripple:0.03
Enter stopband ripple:0.01
Enter passband frequency:2000
Enter stopband frequency:2500

Dept. of Electronics & Communication Engg. Page No: 44


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Enter sampling frequency:7000

PROGRAM-BARTLETT WINDOW
clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
fp=input('Enter passband frequency:');
Dept. of Electronics & Communication Engg. Page No: 45
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

fs=input('Enter stopband frequency:');


f=input('Enter 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=bartlett(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);
title('Low Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('High Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%BAND PASS FILTER

Dept. of Electronics & Communication Engg. Page No: 46


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

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);
title('Band Pass Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');
%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);
title('Band Stop Filter');
ylabel('Gain (in dB)');
xlabel('Normalised Frequency');

OUTPUT
Enter passband ripple:0.04
Enter stopband ripple:0.02
Enter passband frequency:1500
Enter stopband frequency:2000

Dept. of Electronics & Communication Engg. Page No: 47


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Enter sampling frequency:8000

RESULT
FIR filters using Rectangular, Hamming, Kaiser, Hanning, Blackman & Bartlett windows
are implemented in MATLAB & output waveforms are obtained.

Experiment: 8

Circular Convolution

AIM

Dept. of Electronics & Communication Engg. Page No: 48


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

To write a program in MATLAB for the circular convolution of 2 sequences.

PROGRAM
clc;clear all;close all;
a=input('First sequence:');
b=input('Second sequence:');
d=length(a);
e=length(b);
if(d>e)
f=a;
g=[b,zeros(1,d-e)];
end;
if(d<e)
f=[a,zeros(1,e-d)];
g=b;
end;
n=0;
i=length(f)-1;
for h=0:i
k=sum(f.*g);
con(n+1)=k;
n=n+1;
g=circshift(g,[0 -1]);
end;
stem(con);
title('Circular convoluted sequence:');
xlabel('Time');
ylabel('Amplitude');
OUTPUT
First sequence:[1 2 3]
Second sequence:[5 4 3 2]

Dept. of Electronics & Communication Engg. Page No: 49


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT
The circular convolution of 2 sequences is implemented using MATLAB & resulting
sequence is graphically obtained.

Experiment: 9

Linear Convolution Using Circular Convolution


Dept. of Electronics & Communication Engg. Page No: 50
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

AIM
To write a program in MATLAB for the linear convolution of 2 sequences using circular
convolution.

PROGRAM
clc;clear all;close all;
x=input('Enter first sequence:');
h=input('Enter second sequence:');
n1=length(x);
n2=length(h);
N=n1+n2-1;
x=[x zeros(1,n2-1)];
h=[h zeros(1,n1-1)];
for n=0:N-1
y(n+1)=0;
for i=0:N-1
j=mod(n-i,N);
y(n+1)=y(n+1)+x(i+1)*h(j+1);
end;
end;
disp(y);
stem(y);
title('Linear convolution using circular convolution');
ylabel('Amplitude');
xlabel('Time');

OUTPUT
Enter first sequence:[1 2 3 4]
Enter second sequence:[4 1 4]

Dept. of Electronics & Communication Engg. Page No: 51


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

4 9 18 27 16 16

RESULT
The linear convolution of 2 sequences using circular convolution is implemented using
MATLAB & resulting sequence is graphically obtained.

Experiment: 10

Discrete Time Sequence


Dept. of Electronics & Communication Engg. Page No: 52
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

AIM
To generate discrete time unit step, sinusoidal, exponential & addition sequences.

PROGRAM
clc;clear all;close all;
N=input('Enter length:');
%UNIT STEP SEQUENCE
x=ones(1,N);
n=0:1:N-1;
subplot(2,2,1);
stem(n,x);
title('Unit step sequence');
xlabel('Time');
ylabel('Amplitude');
%SINUSOIDAL SEQUENCE
x1=cos(.2*pi*n);
subplot(2,2,2);
stem(n,x1);
title('Sinusoidal sequence');
xlabel('Time');
ylabel('Amplitude');
%EXPONENTIAL SEQUENCE
x2=exp(n);
subplot(2,2,3);
stem(n,x2);
title('Exponential sequence');
xlabel('Time');
ylabel('Amplitude');

%ADDITION OF 2 SINUSOIDAL SEQUENCES


x3=sin(.1*pi*n)+sin(.2*pi*n);

Dept. of Electronics & Communication Engg. Page No: 53


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

subplot(2,2,4);
stem(n,x3);
title('Added sequence');
xlabel('Time');
ylabel('Amplitude');

OUTPUT
Enter length:21

RESULT
The discrete time unit step, sinusoidal, exponential & addition of 2 sinusoidal sequences
are obtained in MATLAB.

Experiment: 11

Dept. of Electronics & Communication Engg. Page No: 54


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

DFT & IDFT

AIM
To find Discrete Fourier Transform (DFT) & Inverse Discrete Fourier Transform (IDFT)
of a sequence.

PROGRAM
clc;clear all;close all;
x1=input('Enter sequence:');
N=input('Enter samples:');
xk=fft(x1)/N;
n=0:1:length(xk)-1;
subplot(2,2,2);
stem(n,abs(xk));
title('Magnitude Spectrum');
subplot(2,2,3);
stem(x1,angle(xk));
title('Angle of Fourier Transform');
xk1=ifft(xk)*N;
subplot(2,2,4);
stem(n,abs(xk1));
title('Inverse of Fourier Transform');
subplot(2,2,1);
stem(n,x1);
title('Input Signal');

OUTPUT

Dept. of Electronics & Communication Engg. Page No: 55


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Enter sequence:[1 2 3 4]
Enter samples:3

RESULT
The DFT & IDFT of a sequence is obtained in MATLAB & output waveforms are
obtained.

Experiment: 12

Dept. of Electronics & Communication Engg. Page No: 56


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Linear Convolution Using Overlap-Save Method

AIM
To compute the linear convolution of 2 sequences using overlap-save method.

PROGRAM
clc; close all; clear all;
x=input('Enter input sequence:');
h=input('Enter impulse sequence:');
N=4;
if(N<length(h))
error('N must be >= length of h');
end;
Nx=length(x);
m=length(h);
m1=m-1;
l=N-m1;
x=[zeros(1,m-1),x,zeros(1,N-1)];
h=[h,zeros(1,N-m)];
k=floor((Nx+m1-1)/l);
Y=zeros(k+1,N);
for k=0:k
xk=x(k*l+1:k*l+N);
Y(k+1,:)=circonv(xk,h,N);
end;
Y=Y(:,m:N);
y=(Y(:));
stem(y);
title('Overlap-Save Method');
ylabel('Amplitude');

Dept. of Electronics & Communication Engg. Page No: 57


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

xlabel('Time');

OUTPUT
Enter input sequence:[1 2 3 4 5]
Enter impulse sequence:[3 2 1]

RESULT
The linear convolution of 2 sequences is obtained using overlap-save method and output
waveforms are obtained.

Experiment: 13
Dept. of Electronics & Communication Engg. Page No: 58
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Linear Convolution Using Overlap-Add Method

AIM
To compute the linear convolution of 2 sequences using overlap-add method.

PROGRAM
clc; close all; clear all;
x=[1,2,-1,2,3,-2,-3,-1,1,1,2,-1];
h=[1,2,1,1];
N=4;
y=ovrladd(x,h,N);
disp(y);

‘ovrladd’ function
function y= ovrladd(x,h,L);
nx=length(x);
m=length(h);
m1=m-1;
r=rem(nx,L);
n=L+m1;
x=[x,zeros(1,L-r)];
h=[h,zeros(1,n-m)];
K=floor(nx/L);
Y=zeros(K+1,n);
z=zeros(1,m1);
for k=0:K
xp=x(k*L+1:k*L+L);
xk=[xp z];
y(k+1,:)=circonv(xk,h,n);
end;
yp=y';

Dept. of Electronics & Communication Engg. Page No: 59


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

[x,y]=size(yp);
for i=L+1:x
for j=1:y-1
temp1=i-L;
temp2=j+1;
temp3=yp(temp1,temp2)+yp(i,j);
yp(temp1,temp2)=yp(i,j);
yp(temp1,temp2)=temp3;
end;
end;
z=1;
for j=1:y
for i=1:x
if ((i<=L&j<=y-1)|(j==y));
ypnew(z)=yp(i,j);
z=z+1;
end;
end;
end;
y=ypnew;

‘circonv’ function
function[y]=circonv(x,h,N);
n2=length(x);
n3=length(h);
x=[x,zeros(1,N-n2)];
h=[h,zeros(1,N-n3)];
m=[0:1:N-1];
M=mod(-m,N);
h=h(M+1);
for n=1:1:N
m=n-1;

Dept. of Electronics & Communication Engg. Page No: 60


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

p=0:1:N-1;
q=mod(p-m,N);
hm=h(q+1);
H(n,:)=hm;
end;
y=x*H';

OUTPUT
Columns 1 through 13

1 4 4 3 8 5 -2 -6 -6 -1 4 5 1

Columns 14 through 19

1 -1 0 0 0 0

RESULT
The linear convolution of 2 sequences is obtained using overlap-add method and output
sequence is obtained.

Experiment: 14
Dept. of Electronics & Communication Engg. Page No: 61
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Distributions

AIM
To generate Gaussian, Poisson & random distributions using MATLAB.

PROGRAM
clc;clear all;close all;
%GAUSSIAN SIGNAL
x1=gauspuls('cutoff',50e3,.6,-40);
x=-x1:1e-7:x1;
y=gauspuls(x,50e3,.6);
%POISSON SIGNAL
lambda=input('Enter value of lambda:');
m=input('Size of first array:');
n=input('Size of second array:');
R=poissrnd(lambda,m,n);
%RANDOM SIGNAL
p=input('Enter value:');
d=rand(1,p);
subplot(3,1,1);
plot(x,y);
xlabel('Time');
ylabel('Amplitude');
title('Gaussian distribution');
subplot(3,1,2);
plot(R);
xlabel('Time');
ylabel('Amplitude');
title('Poisson distribution');
subplot(3,1,3);
plot(d);
xlabel('Time');
Dept. of Electronics & Communication Engg. Page No: 62
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

ylabel('Amplitude');
title('Random distribution');

OUTPUT
Enter value of lambda:0.05
Size of first array:10
Size of second array:20
Enter value:21

RESULT
The Gaussian, Poisson & random distributions are implemented using MATLAB anf
output waveforms are obtained.

Experiment: 15

Dept. of Electronics & Communication Engg. Page No: 63


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Frequency Sampling

AIM
To obtain a filter using frequency sampling method.

PROGRAM
clc;clear all;close all;
N=33;
alpha=(N-1)/2;
Hrk=[ones(1,9),zeros(1,16),ones(1,8)];
k1=0:(N-1)/2;k2=(N+1)/2:N-1;
theetak=[(-alpha*(2*pi)/N)*k1,(alpha*(2*pi)/N)*(N-k2)];
Hk=Hrk.*(exp(i*theetak));
hn=real(ifft(Hk,N));
w=0:0.01:pi;
H=freqz(hn,1,w);
plot(w/pi,20*log10(abs(H)));
hold on;
Hrk=[ones(1,9),0.5,zeros(1,14),0.5,ones(1,8)];
k1=0:(N-1)/2;k2=(N+1)/2:N-1;
theetak=[(-alpha*(2*pi)/N)*k1,(alpha*(2*pi)/N)*(N-k2)];
Hk=Hrk.*(exp(i*theetak));
hn=real(ifft(Hk,N));
w=0:0.01:pi;
H=freqz(hn,1,w);
plot(w/pi,20*log10(abs(H)),'.');
ylabel('Magnitude in dB');
xlabel('Normalised frequency \omega/\pi');
hold off;

OUTPUT

Dept. of Electronics & Communication Engg. Page No: 64


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT
The filter is obtained using frequency sampling method in MATLAB.

Experiment: 16
Dept. of Electronics & Communication Engg. Page No: 65
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Up-sampling

AIM
To up-sample a given finite length sequence.

PROGRAM
N=input('Enter length of sinusoidal signal:');
L=input('Upsampling factor:');
fi=input('Input signal frequency:');
n=0:N-1;
x=sin(2*pi*fi*n);
y=zeros(1,L*length(x));
y([1:L:length(y)])=x;
subplot(2,1,1);
stem(n,x);
title('Input sequence:');
xlabel('Time n');
ylabel('Amplitude');
subplot(2,1,2);
stem(n,y(1:length(x)));
title(['Output sequence, upsampling factor=',num2str(L)]);
xlabel('Time n');
ylabel('Amplitude');

OUTPUT
Dept. of Electronics & Communication Engg. Page No: 66
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Enter length of sinusoidal signal:25


Upsampling factor:2
Input signal frequency:100

RESULT
The given sequence is up-sampled and the resulting waveforms are obtained.

Experiment: 17

Dept. of Electronics & Communication Engg. Page No: 67


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Down-sampling

AIM
To down-sample a given finite length sequence.

PROGRAM
clc;clear all;close all;
N=input('Enter length of sinusoidal signal:');
M=input('Downsampling factor:');
fi=input('Input signal frequency:');
n=0:N-1;
m=0:N*M-1;
x=sin(2*pi*fi*m);
y=x([1:M:length(x)]);
subplot(2,1,1);
stem(n,x(1:N));
title('Input sequence');
ylabel('Amplitude');
xlabel('Time');
subplot(2,1,2);
stem(n,y);
title(['Output sequence with downsampling factor ',num2str(M)]);
ylabel('Amplitude');
xlabel('Time');

OUTPUT
Enter length of sinusoidal signal:25
Dept. of Electronics & Communication Engg. Page No: 68
SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Downsampling factor:3
Input signal frequency:100

RESULT
The given sequence is down-sampled and the resulting waveforms are obtained.

Experiment: 18

Dept. of Electronics & Communication Engg. Page No: 69


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

Random Sequence

AIM
To generate a random sequence in MATLAB.

PROGRAM
clc;clear all;close all;
N=input('Enter length of random sequence:');
y=linspace(1,N,N);
x = 0+sqrt(1)*randn(1,N);
disp(x);
plot(y,x);
title('Random Sequence');

OUTPUT
Enter length of random sequence:12
Columns 1 through 7

0.1139 1.0668 0.0593 -0.0956 -0.8323 0.2944 -1.3362

Columns 8 through 12

0.7143 1.6236 -0.6918 0.8580 1.2540

Dept. of Electronics & Communication Engg. Page No: 70


SCT College of Engineering
Pappanamcode-18
DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT
The required random sequence is obtained using MATLAB.

Dept. of Electronics & Communication Engg. Page No: 71


SCT College of Engineering
Pappanamcode-18

Das könnte Ihnen auch gefallen