MATLAB Fair Record (Model)
MATLAB Fair Record (Model)
Experiment: 1
AIM
To implement a program in MATLAB to generate Amplitude Modulated (AM),
Frequency Modulated (FM) & Pulse Width Modulated (PWM) waveforms.
PROGRAM
Amplitude Modulated Wave
OUTPUT
Modulation Index:0.5
Signal frequency:100
Carrier frequency:1000
OUTPUT
Amplitude:1
Carrier frequency:100
Signal frequency:10
Modulation index:5
OUTPUT
RESULT
The programs for AM, FM & PWM signals are implemented in MATLAB and the output
waveforms are generated.
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');
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.
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);
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');
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.
Experiment: 4
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
[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
OUTPUT
Enter passband ripple:0.4
Enter stopband ripple:50
Enter passband frequency:[800 1200]
Enter stopband frequency:[500 1500]
Enter passband frequency:4000
OUTPUT
Enter passband ripple:0.4
Enter stopband ripple:50
Enter passband frequency:[800 1500]
Enter stopband frequency:[1000 1200]
Enter passband frequency:4000
RESULT
The IIR Butterworth filters are designed using MATLAB and the output waveforms are
obtained.
Experiment: 5
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:');
OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:1000
Enter stopband frequency:1500
Enter passband frequency:4000
OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:1500
Enter stopband frequency:1000
Enter passband frequency:5000
OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:[1000 1200]
Enter stopband frequency:[800 1500]
Enter passband frequency:4500
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
RESULT
The Chebyshev Type 1 filters are implemented using MATLAB p waveforms are
obtained.
Experiment: 6
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
OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:1000
Enter stopband frequency:800
Enter passband frequency:4500
OUTPUT
Enter passband ripple:0.5
Enter stopband ripple:50
Enter passband frequency:[800 1500]
Enter stopband frequency:[1000 1200]
Enter passband frequency:4500
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
RESULT
The Chebyshev Type 2 filters are implemented using MATLAB & the output waveforms
are obtained.
Experiment: 7
AIM
To design & simulate FIR filters using various windows such as rectangular, Hamming,
Kaiser, Hanning, Blackman & Bartlett windows in MATLAB.
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);
[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
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:');
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
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
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
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:');
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
PROGRAM-BLACKMAN WINDOW
clc;clear all;close all;
rp=input('Enter passband ripple:');
rs=input('Enter stopband ripple:');
fp=input('Enter passband frequency:');
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
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
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
RESULT
FIR filters using Rectangular, Hamming, Kaiser, Hanning, Blackman & Bartlett windows
are implemented in MATLAB & output waveforms are obtained.
Experiment: 8
Circular Convolution
AIM
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]
RESULT
The circular convolution of 2 sequences is implemented using MATLAB & resulting
sequence is graphically obtained.
Experiment: 9
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]
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
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');
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
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
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
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');
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
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';
[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;
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
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
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
RESULT
The given sequence is up-sampled and the resulting waveforms are obtained.
Experiment: 17
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
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
Columns 8 through 12
RESULT
The required random sequence is obtained using MATLAB.