Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 85

Digital Signal Processing Lab

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Ex.No:01 Generation of Signals Using Matlab Function.

Aim:
To Study the following Mat lab Function of Standard Commands and Write the
simple program of signal.

Apparatus Required:
Hardware: PC.
Software: MATLAB 2011a Version.

Algorithm:
1. Start the program.
2. Get the value of length of the sequence N.
3. Give the steps to generate Unit Step, Unit Impulse, Unit Ramp, Sine Signal, Cosine
Signal and Exponential Signal.
4. Output is generated in discrete format.
5. Terminate the Process.

Program:
clc;
clear all;
close all;
N=input('Enter the length of the sequence:');

% Generation of Unit Step Sequence


t=-N :1 :N;
x=[zeros(1,N), ones(1,N+1)];
subplot(2,3,1);
stem(t,x);
xlabel('n samples');
ylabel('Amplitude');
title('Generation of Unit Step Sequence');

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

% Generation of Unit Impulse Signal


x1=[zeros(1,N),ones(1,1),zeros(1,N)];
subplot(2,3,2);
stem(t,x1);
xlabel('n samples');
ylabel('Amplitude');
title('Generation of Unit Impulse Signal’);

% Generation of Unit Ramp Signal


r=[zeros(1,N), 0 :N]
subplot(2,3,3);
stem(t,r);
xlabel('n samples');
ylabel('amplitude');
title('Generation of Unit Ramp Signal');

% Generation of Sine Signal


t=0:0.1:2*pi;
x3=sin(t);
subplot(2,3,4);
stem(t,x3);
xlabel('Time');
ylabel('Amplitude');
title('Generation of Sine Signal');

% Generation of CoSine Signal'


x4=cos(t);
subplot(2,3,5);
stem(t,x4);
xlabel('Time---');
ylabel('Amplitude---’);
Title('Generation of Cosine signal');

% Generation of Exponential Signal'

x5=exp(t);
subplot(2,3,6);

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Electronics and Communication Engineering Department


Digital Signal Processing Lab

stem(t,x5);
xlabel('Exponential');
ylabel('Amplitude');
Title('Generation of Exponential sequence');

Continuous Assessment

Max Allotted
S.No Components
mark Marks

1. Preparation and Conduct


50
of experiments

2. Observation & Result 30

3. Record 10

4. Viva Voce 10

Total 100

Result:
Thus the MATLAB program for generation of basic signals is executed and waveforms are
plotted successfully.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

EX.No:02 Implementation of DIT and DIF Algorithms.


Electronics and Communication Engineering Department
Digital Signal Processing Lab

Aim:
To write a MATLAB Program to obtain discrete Fourier transform for the
system given in any form of the sequence using FFT algorithm and verify manual and
practical value.

Apparatus Required:
Hardware: PC.

Software: MATLAB 2011a Version.

Algorithm:
1. Start the program.
2. Get the finite duration sequence x(n).
3. Calculate the value of N.
4. DFT is calculated using DIT and DIF algorithm.
a. Calculate the magnitude response.
b. Plot the magnitude response.
5. Verify manual and built in function values.
6. Terminate the process.

Program:

% DIT Algorithm
clc;
clear all
close all
xn=input('enter the sequence: ');
N=input('enter the length: ');
p=length(xn);
if N>p
xn=[xn,zeros(1,N-p)];
else
xn=xn;
end
lev=log2(N);

Input:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Output:

x=bitrevorder(xn);
tw=exp(-i*2*pi*(0:N/2-1)/N);
for levn=1:lev;

Electronics and Communication Engineering Department


Digital Signal Processing Lab

L=2^levn;
twl=tw(1:N/L:N/2);
for k=0:L:N-L;
for n=0:L/2-1;
A=x(n+k+1);
B=x(n+k+(L/2)+1)*twl(n+1);
x(n+k+1)=A+B;
x(n+k+(L/2)+1)=A-B;
end
end
end
x
l=0:N-1;
subplot(3,2,1),stem(l,xn);
title('input');
xlabel('n');
ylabel('x[n]');
subplot(3,2,2),stem(l,abs(x));
title('FFT using DIT algorithm');
xlabel('k');
ylabel('X[k]');
subplot(3,2,3),stem(l,abs(fft(xn)));
title('FFT using function');
xlabel('k');
ylabel('X[k]');
ansft=fft(xn)

%ifft

N=length(x);
xn1=conj(x);
lev=log2(N);
x1=bitrevorder(xn1);
tw=exp(-2i*pi*(0:N/2-1)/N);
for levn=1:lev;
L=2^levn;
twl=tw(1:N/L:N/2);

Input:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Output:

for k=0:L:N-L
for n=0:L/2-1

Electronics and Communication Engineering Department


Digital Signal Processing Lab

A=x1(n+k+1);
B=x1(n+k+(L/2)+1)*twl(n+1);
x1(n+k+1)=A+B;
x1(n+k+(L/2)+1)=A-B;
end
end
end
X=conj(x1)/N
subplot(3,2,4);stem(l,abs(X));
title('IFFT using DIT algorithm');
xlabel('n');
ylabel('x[n]');
subplot(3,2,5);stem(l,abs(ifft(x)));
title('IFFT using function’);
xlabel('n');
ylabel('x[n]');
ansift=ifft(x)

% DIF ALGORITHM
clc;
clear all;
close all;
xn=input('enter a sequence:');
p=length(xn);
N=input('Enter the value of N ');
if N>p
xn=[xn,zeros(1,N-p)];
else
xn=xn;
end
x=xn;
lev=log2(N);
tw=exp(-2i*pi*(0:N/2-1)/N);
for level=lev:-1:1;
L=2^level;
twlvl=tw(1:N/L:N/2);
for k=0:L:N-L;

Input:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Output:

for n=0:L/2-1;
A=x(n+k+1);
B=x(n+k+(L/2)+1);

Electronics and Communication Engineering Department


Digital Signal Processing Lab

x(n+k+1)=A+B;
x(n+k+(L/2)+1)=(A-B)*twlvl(n+1);
end
end
end
XK=bitrevorder(x);
l=0:N-1;
subplot(3,2,1),stem(l,abs(xn));
title('input’);
xlabel('n');
ylabel('x[n]');
subplot(3,2,2),stem(l,abs(XK));
title('FFT using DIF algorithm');
xlabel('k');ylabel('X[k]');
ansft=fft(xn)
subplot(3,2,3),stem(l,abs(fft(xn)));
title('FFT using function');
xlabel('k');ylabel('X[k]');
%ifft
x1=conj(XK);
levels=log2(N);
tw=exp(-2i*pi*(0:N/2-1)/N);
for level=levels:-1:1;
L=2^level;
twlvl=tw(1:N/L:N/2);
for k=0:L:N-L;
for n=0:L/2-1;
A=x1(n+k+1);
B=x1(n+k+(L/2)+1);
x1(n+k+1)=A+B;
x1(n+k+(L/2)+1)=(A-B)*twlvl(n+1);
end
end
end
x=bitrevorder(x1);

Input:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Output:

xk=conj(x)/N
ansift=ifft(XK)
subplot(3,2,4),stem(l,abs(xk));
title('IFFT using DIF algorithm-');

Electronics and Communication Engineering Department


Digital Signal Processing Lab

xlabel('n');
ylabel('x[n]');
subplot(3,2,5),stem(l,abs(ansift));
title('IFFT using function');
xlabel('n');ylabel('x[n]');

Continuous Assessment

Max Allotted
S.No Components
mark Marks

1. Preparation and Conduct


50
of experiments

2. Observation & Result 30

3. Record 10

4. Viva Voce 10

Total 100

Result:
Thus the MATLAB Programs for FFT using DIF and DIT Algorithm for the given finite
duration were generated using program and inbuilt function and is plotted successfully.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

EX.NO:03 Implementation of Linear and Circular Convolution

Aim:
Electronics and Communication Engineering Department
Digital Signal Processing Lab

To write a MATLAB Program to obtain the linear and circular convolution between
two finite duration sequence h(n) and x(n) and calculate FFT sequence.

Apparatus Required:
Hardware: PC.

Software: MATLAB 2011a Version.

Algorithm:
1. Start the program.
2. Get the input sequence.
3. Get the impulse sequence.
4. Write coding to find out the linear convolution and circular convolution.
5. Plot the convolution sequence.
6. Terminate the process.

Program:
clc;
clear all;
close all;
x=input('enter the input sequence');
h=input('enter the impulse sequence');
m=length(x);
n=length(h);
X=[x, zeros(1,n-1)];
H=[h, zeros(1,m-1)];
for i=1:n+m-1
y(i)=0;
for j=1:m
if(i-j+1>0)
y(i)=y(i)+X(j)*H(i-j+1);

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

else
end
end
end
y
Y=conv(x,h)
subplot(2,2,1);
stem(x);
xlabel('n samples--->');
ylabel('amplitude--->');
title('input signal');

Electronics and Communication Engineering Department


Digital Signal Processing Lab

subplot(2,2,2);
stem(h);
xlabel('n samples--->');
ylabel('amplitude--->');
title('impulse signal');
subplot(2,2,3);
stem(y);
xlabel('n samples-->');
ylabel('amplitude-->');
title('Linear Convolution using program');
stem(Y);
xlabel('n samples-->');
ylabel('amplitude-->');
title('Linear Convolution using function’);

Circular Convolution
clc;
clear all;
close all;
x=input('Enter the input sequences x(n):');
m=length(x);
h=input('Enter the impulse response h(n)');
n=length(h);
subplot(2,2,1);
stem(x);
title('Input sequencce x(n)');
xlabel('n ---->');
ylabel('x(n) ---->');
grid; subplot(2,2,2);
stem(h);
title('Impulse response h(n)');
xlabel('n ---->');
ylabel('h(n) ---->');
if(m-n~=0)
if(m>n)
h=[h,zeros(1,m-n)];

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

n=m;
end
if(n>m)
x=[x,zeros(1,n-m)];
disp('circular convolution of x(n) & h(n) is y(n):');
if(m-n~=0)
if(m>n)
h=[h,zeros(1,m-n)];
n=m;
end
if(n>m)

Electronics and Communication Engineering Department


Digital Signal Processing Lab

x=[x,zeros(1,n-m)];
m=n;
end
end
a=zeros(m,m)
a(:,1)=x
for i=1:n-1
a(:,i+1)=[a(n,i);a(1:n-1,i);
end
h1(:,1)=h;
y1=a*h1;
y(1,:)=y1;
y
subplot(2,2,3),stem(y);
title('convolution of x(n) & h(n)');
xlabel('n ---->');
ylabel('y(n) ---->');
Y=circonv(x,h,m)
subplot(2,2,3),stem(y);
title('convolution of x(n) & h(n) using inbuilt function');
xlabel('n ---->');
ylabel('y(n) ---->');

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Continuous Assessment

Max Allotted
S.No Components
mark Marks

1. Preparation and Conduct


50
of experiments

2. Observation & Result 30

3. Record 10

4. Viva Voce 10

Total 100

Result:
Thus the MATLAB Program for linear and Circular convolution through program and inbuilt
function was generated and plotted successfully.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

E.NO:04 Implementation of FIR Filter Design.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Aim:
To write a MATLAB Program to generate and plot the window technique.

1. Rectangular
2. Hanning
3. Hamming
4. Blackman

Apparatus Required:
Hardware: PC.

Software: MATLAB 2011a Version

Algorithm:
1. Start the program.
2. Get the pass band and stop band ripples.
3. Get the stop and pass band frequency.
4. Get the sampling frequency.
5. Calculate the order of the filter (N=-20log10 (sqrt (rp*rs)) 13), dem=14.6*(fs-fp)/f.
6. Find the windows co-efficient using particular windows formula.
7. Draw the magnitude and phase response.
8. Terminate the program.

Program:
clc;
clear all;
close all;
rp=input('Enter the Pass Band Ripple:');
rs=input('Enter the Stop Band Ripple :');
fp=input('Enter the Pass Band Frequency :');
fs=input('Enter the Stop Band Frequency :');
f=input('Enter the Sampling Frequency :');

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Input:

Enter the pass band ripple: 0.05

Enter the stop band ripple: 0.04

Enter the pass band freq: 1500

Enter the stop band freq: 2000

Enter the sampling freq: 9000

Output:

Rectangular window filter response

Electronics and Communication Engineering Department


Digital Signal Processing Lab

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);
Disp ('rectangular window filter response');
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);[h,o]=freqz(b,1,256);
plot(o/pi,m);
Title('LPF');
ylabel('Gain in dB');
xlabel('(a) Normalized Frequency');
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
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('BSF');
ylabel('Gain in dB');
xlabel('(d) Normalized Frequency');

Input:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Enter the pass band ripple: 0.03

Enter the stop band ripple: 0.01

Enter the pass band freq: 1400

Enter the stop band freq: 2000

Enter the sampling freq: 8000

Output:

Hamming window filter response

clc;
clear all;
close all;

Electronics and Communication Engineering Department


Digital Signal Processing Lab

rp=input('Enter the Pass Band Ripple:');


rs=input('Enter the Stop Band Ripple :');
fp=input('Enter the Pass Band Frequency :');
fs=input('Enter the Stop Band 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=hamming(n1);
Disp('hamming window filter response');
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);[h,o]=freqz(b,1,256);
plot(o/pi,m);
Title('LPF');
ylabel('Gain in dB');
xlabel('(a) Normalized Frequency');
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
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('BSF');
ylabel('Gain in dB');
xlabel('(d) Normalized Frequency');

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Input:

Enter the pass band ripple: .03

Enter the stop band ripple: .01

Enter the pass band freq: 1400

Enter the stop band freq: 2000

Enter the sampling freq: 8000

Output:

Hanning window filter response

clc;
clear all;

Electronics and Communication Engineering Department


Digital Signal Processing Lab

close all;
rp=input('Enter the Pass Band Ripple:');
rs=input('Enter the Stop Band Ripple :');
fp=input('Enter the Pass Band Frequency :');
fs=input('Enter the Stop Band 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);
Disp ('hanning window filter response');
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);[h,o]=freqz(b,1,256);
plot(o/pi,m);
Title('LPF');
ylabel('Gain in dB');
xlabel('(a) Normalized Frequency');
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
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('BSF');
ylabel('Gain in dB');
xlabel('(d) Normalized Frequency');

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Input:

Enter the pass band ripple: .02

Enter the stop band ripple: .01

Enter the pass band freq: 1000

Enter the stop band freq: 1500

Enter the sampling freq: 10000

Enter the beta value: 5.8

Output:

Blackmann window filter response

Electronics and Communication Engineering Department


Digital Signal Processing Lab

clear all;
close all;
rp=input('Enter the Pass Band Ripple:');
rs=input('Enter the Stop Band Ripple :');
fp=input('Enter the Pass Band Frequency :');
fs=input('Enter the Stop Band 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=blackman(n1);
Disp('Blackman Window Filter Response');
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);[h,o]=freqz(b,1,256);
plot(o/pi,m);
Title('LPF');
ylabel('Gain in dB');
xlabel('(a) Normalized Frequency');
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
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('BSF');
ylabel('Gain in dB');
xlabel('(d) Normalized Frequency');

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Continuous Assessment

Max Allotted
S.No Components
mark Marks

1. Preparation and Conduct


50
of experiments

2. Observation & Result 30

3. Record 10

4. Viva Voce 10

Total 100

Result:
Thus the MATLAB Program for windows function rectangular, hamming, hanning and
blackmann were generated and plotted successfully

Electronics and Communication Engineering Department


Digital Signal Processing Lab

EX.NO:05 Implementation of IIR Filter Design.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Aim:
To write a MATLAB Program to generate and plot the magnitude and phase
Response of IIR filter Digital filter.

Apparatus Required:
Hardware: PC.

Software: MATLAB 2011a Version

Algorithm:
1. Start the program.
2. Use the given specification value and find the required coefficients.
3. Plot the magnitude and phase response.
4. Terminate the program.

Program:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

1.Write a mat lab program to design a Butterworth Digital IIR Low Pass filter using bilinear
transformation by taking T=0.1 seconds, to satisfy the following Specifications.
0.6≤|H(ejω)| ≤1.0;for 0≤ω≤0.35π

Electronics and Communication Engineering Department


Digital Signal Processing Lab

|H(ejω)| ≤0.1;for 0.7π≤ω≤π

clc;
clear all;
close all;
AP=0.6;
AS=0.1;
PEF=0.35*pi;
SEF=0.7*pi;
T=0.1;
alphap=-20*log10(AP)
alphas=-20*log10(AS)
PEFA=(2/T)*tan((PEF/2))
SEFA=(2/T)*tan((SEF/2))
[N,CF]=buttord(PEFA,SEFA,alphap,alphas,'s')
[Bn,An]=butter(N,1,'s');
display('Normalised Transfer Function is,')
Hsn=tf(Bn,An)
[B,A]=butter(N,CF,'s');
display('Un Normalised Transfer Function is,')
Hs=tf(B,A)
[num,den]=bilinear(B,A,1/T);
display('Digital Transfer Function is,')
Hz=tf(num,den,T)
w=0:pi/16:pi;
display('Frequency Response is,')
Hw=freqz(num,den,w)
display('Magnitude Response is,')
Hw_mag=abs(Hw)
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response of Second order Low pass Filter');
xlabel('Normalised Frequency');
ylabel('Magnitude');

Input:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Output:

2.Write a mat lab program to design a Butterworth Digital IIR High Pass filter using bilinear
transformation by taking T=0.1 seconds, to satisfy the following Specifications.
0.6≤|H(ejω)| ≤1.0;for 0.7π ≤ω≤π
|H(ejω)| ≤0.1;for 0≤ω≤0.35π

Electronics and Communication Engineering Department


Digital Signal Processing Lab

clc;
clear all;
close all;
AP=0.6;
AS=0.1;
PEF=0.35*pi;
SEF=0.7*pi;
T=0.1;
alphap=-20*log10(AP)
alphas=-20*log10(AS)
PEFA=(2/T)*tan((PEF/2))
SEFA=(2/T)*tan((SEF/2))
[N,CF]=buttord(PEFA,SEFA,alphap,alphas,'s')
[Bn,An]=butter(N,1,'s');
display('Normalised Transfer Function is,')
Hsn=tf(Bn,An)
[B,A]=butter(N,CF,'high','s');
display('Un Normalised Transfer Function is,')
Hs=tf(B,A)
[num,den]=bilinear(B,A,1/T);
display('Digital Transfer Function is,')
Hz=tf(num,den,T)
w=0:pi/16:pi;
display('Frequency Response is,')
Hw=freqz(num,den,w)
display('Magnitude Response is,')
Hw_mag=abs(Hw)
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response of Second order Low pass Filter');
xlabel('Normalised Frequency');
ylabel('Magnitude');

Input:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Output:

3.Write a mat lab program to design a Butterworth Digital IIR Low Pass filter using bilinear
transformation by taking T=0.5 seconds, to satisfy the following Specifications.
0.707≤|H(ejω)| ≤1.0;for 0≤ω≤0.45π
|H(ejω)| ≤0.2;for 0.65π≤ω≤π

Electronics and Communication Engineering Department


Digital Signal Processing Lab

clc;
clear all;
close all;
AP=0.707;
AS=0.2;
PEF=0.45*pi;
SEF=0.65*pi;
T=0.5;
alphap=-20*log10(AP)
alphas=-20*log10(AS)
PEFA=(2/T)*tan((PEF/2))
SEFA=(2/T)*tan((SEF/2))
[N,CF]=buttord(PEFA,SEFA,alphap,alphas,'s')
[Bn,An]=butter(N,1,'s');
display('Normalised Transfer Function is,')
Hsn=tf(Bn,An)
[B,A]=butter(N,CF,'s');
display('Un Normalised Transfer Function is,')
Hs=tf(B,A)
[num,den]=bilinear(B,A,1/T);
display('Digital Transfer Function is,')
Hz=tf(num,den,T)
w=0:pi/16:pi;
display('Frequency Response is,')
Hw=freqz(num,den,w)
display('Magnitude Response is,')
Hw_mag=abs(Hw)
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response of Third order Low pass Filter');
xlabel('Normalised Frequency');
ylabel('Magnitude');

Input:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Output:

4.Write a mat lab program to design a Butterworth Digital IIR High Pass filter using bilinear
transformation by taking T=0.5 seconds, to satisfy the following Specifications.
0.707≤|H(ejω)| ≤1.0;for 0.65π ≤ω≤π
|H(ejω)| ≤0.2;for 0≤ω≤0.45π

clc;
clear all;
Electronics and Communication Engineering Department
Digital Signal Processing Lab

close all;
AP=0.707;
AS=0.2;
PEF=0.45*pi;
SEF=0.65*pi;
T=0.5;
alphap=-20*log10(AP)
alphas=-20*log10(AS)
PEFA=(2/T)*tan((PEF/2))
SEFA=(2/T)*tan((SEF/2))
[N,CF]=buttord(PEFA,SEFA,alphap,alphas,'s')
[Bn,An]=butter(N,1,'s');
display('Normalised Transfer Function is,')
Hsn=tf(Bn,An)
[B,A]=butter(N,CF,'high','s');
display('Un Normalised Transfer Function is,')
Hs=tf(B,A)
[num,den]=bilinear(B,A,1/T);
display('Digital Transfer Function is,')
Hz=tf(num,den,T)
w=0:pi/16:pi;
display('Frequency Response is,')
Hw=freqz(num,den,w)
display('Magnitude Response is,')
Hw_mag=abs(Hw)
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response of Third order High pass Filter');
xlabel('Normalised Frequency');
ylabel('Magnitude');

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

5.Write a mat lab program to design a Butterworth Digital IIR Low Pass filter using impulse
invariance transformation by taking T=1 seconds, to satisfy the following Specifications.
0.707≤|H(ejω)| ≤1.0;for 0≤ω≤0.3π
|H(ejω)| ≤0.2;for 0.75π≤ω≤π

clc;
clear all;
close all;
AP=0.707;
AS=0.2;
Electronics and Communication Engineering Department
Digital Signal Processing Lab

PEF=0.3*pi;
SEF=0.75*pi;
T=1;
alphap=-20*log10(AP)
alphas=-20*log10(AS)
PEFA=PEF/T
SEFA=SEF/T
[N,CF]=buttord(PEFA,SEFA,alphap,alphas,'s')
[Bn,An]=butter(N,1,'s');
display('Normalised Transfer Function is,')
Hsn=tf(Bn,An)
[B,A]=butter(N,CF,'s');
display('Un Normalised Transfer Function is,')
Hs=tf(B,A)
[num,den]=impinvar(B,A,1/T);
display('Digital Transfer Function is,')
Hz=tf(num,den,T)
w=0:pi/16:pi;
display('Frequency Response is,')
Hw=freqz(num,den,w)
display('Magnitude Response is,')
Hw_mag=abs(Hw)
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response of Second order Low pass Filter');
xlabel('Normalised Frequency');
ylabel('Magnitude');

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

6.Write a mat lab program to design a Butterworth Digital IIR Low Pass filter using impulse
invariance transformation by taking T=1 seconds, to satisfy the following Specifications.
0.9≤|H(ejω)| ≤1.0;for 0≤ω≤0.35π
|H(ejω)| ≤0.275;for 0.7π≤ω≤π

clc;
clear all;
close all;
AP=0.9;
AS=0.275;
PEF=0.35*pi;
SEF=0.7*pi;
Electronics and Communication Engineering Department
Digital Signal Processing Lab

T=1;
alphap=-20*log10(AP)
alphas=-20*log10(AS)
PEFA=PEF/T
SEFA=SEF/T
[N,CF]=buttord(PEFA,SEFA,alphap,alphas,'s')
[Bn,An]=butter(N,1,'s');
display('Normalised Transfer Function is,')
Hsn=tf(Bn,An)
[B,A]=butter(N,CF,'s');
display('Un Normalised Transfer Function is,')
Hs=tf(B,A)
[num,den]=impinvar(B,A,1/T);
display('Digital Transfer Function is,')
Hz=tf(num,den,T)
w=0:pi/16:pi;
display('Frequency Response is,')
Hw=freqz(num,den,w)
display('Magnitude Response is,')
Hw_mag=abs(Hw)
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response of Third order Low pass Filter');
xlabel('Normalised Frequency');
ylabel('Magnitude');

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

7.Write a mat lab program to design a Butterworth Digital IIR Low Pass filter using impulse
invariance transformation by taking T=1 seconds, to satisfy the following Specifications.
0.8≤|H(ejω)| ≤1.0;for 0≤ω≤0.2π
|H(ejω)| ≤0.2;for 0.32π≤ω≤π

clc;
clear all;
close all;
AP=0.8;
AS=0.2;
PEF=0.2*pi;
SEF=0.32*pi;
T=1;
alphap=-20*log10(AP)
alphas=-20*log10(AS)
Electronics and Communication Engineering Department
Digital Signal Processing Lab

PEFA=PEF/T
SEFA=SEF/T
[N,CF]=buttord(PEFA,SEFA,alphap,alphas,'s')
[Bn,An]=butter(N,1,'s');
display('Normalised Transfer Function is,')
Hsn=tf(Bn,An)
[B,A]=butter(N,CF,'s');
display('Un Normalised Transfer Function is,')
Hs=tf(B,A)
[num,den]=impinvar(B,A,1/T);
display('Digital Transfer Function is,')
Hz=tf(num,den,T)
w=0:pi/16:pi;
display('Frequency Response is,')
Hw=freqz(num,den,w)
display('Magnitude Response is,')
Hw_mag=abs(Hw)
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response of Fourth order Low pass Filter');
xlabel('Normalised Frequency');
ylabel('Magnitude');

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

8.Write a mat lab program to design a Butterworth Digital IIR Low Pass filter using Bilinear
transformation by taking T=1 seconds, to satisfy the following Specifications.
0.707≤|H(ejω)| ≤1.0;for 0≤ω≤0.2π
|H(ejω)| ≤0.08;for 0.4π≤ω≤π

clc;
clear all;
close all;
AP=0.707;
AS=0.08;
PEF=0.2*pi;
SEF=0.4*pi;
T=1;
alphap=-20*log10(AP)
alphas=-20*log10(AS)
PEFA=PEF/T
SEFA=SEF/T
[N,CF]=buttord(PEFA,SEFA,alphap,alphas,'s')
Electronics and Communication Engineering Department
Digital Signal Processing Lab

[Bn,An]=butter(N,1,'s');
display('Normalised Transfer Function is,')
Hsn=tf(Bn,An)
[B,A]=butter(N,CF,'s');
display('Un Normalised Transfer Function is,')
Hs=tf(B,A)
[num,den]=bilinear(B,A,1/T);
display('Digital Transfer Function is,')
Hz=tf(num,den,T)
w=0:pi/16:pi;
display('Frequency Response is,')
Hw=freqz(num,den,w)
display('Magnitude Response is,')
Hw_mag=abs(Hw)
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response of Fourth order Low pass Filter');
xlabel('Normalised Frequency');
ylabel('Magnitude');

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

9.Write a mat lab program to design a Chebyshev Digital IIR Low Pass filter using impulse
invariance transformation by taking T=1 seconds, to satisfy the following Specifications.
0.9≤|H(ejω)| ≤1.0;for 0≤ω≤0.25π
|H(ejω)| ≤0.24;for 0.5π≤ω≤π

clc;
clear all;
close all;
AP=0.9;
AS=0.24;
PEF=0.25*pi;
SEF=0.5*pi;
T=1;
alphap=-20*log10(AP)
alphas=-20*log10(AS)
PEFA=PEF/T
SEFA=SEF/T
[N,CF]=cheb1ord(PEFA,SEFA,alphap,alphas,'s')
[Bn,An]=cheby1(N,alphap,1,'s');
display('Normalised Transfer Function is,')
Electronics and Communication Engineering Department
Digital Signal Processing Lab

Hsn=tf(Bn,An)
[B,A]=cheby1(N,alphap,CF,'s');
display('Un Normalised Transfer Function is,')
Hs=tf(B,A)
[num,den]=impinvar(B,A,1/T);
display('Digital Transfer Function is,')
Hz=tf(num,den,T)
w=0:pi/16:pi;
display('Frequency Response is,')
Hw=freqz(num,den,w)
display('Magnitude Response is,')
Hw_mag=abs(Hw)
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response of Third order Low pass Filter');
xlabel('Normalised Frequency');
ylabel('Magnitude');

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

10.Write a mat lab program to design a Chebyshev Digital IIR Low Pass filter using Bilinear
transformation by taking T=1 seconds, to satisfy the following Specifications.
0.8≤|H(ejω)| ≤1.0;for 0≤ω≤0.2π
|H(ejω)| ≤0.2;for 0.32π≤ω≤π

clc;
clear all;
close all;
AP=0.8;
AS=0.2;
PEF=0.2*pi;
SEF=0.32*pi;
T=1;
alphap=-20*log10(AP)
alphas=-20*log10(AS)
PEFA=(2/T)*tan(PEF/2)
SEFA=(2/T)*tan(SEF/2)
[N,CF]=cheb1ord(PEFA,SEFA,alphap,alphas,'s')
[Bn,An]=cheby1(N,alphap,1,'s');
display('Normalised Transfer Function is,')
Hsn=tf(Bn,An)
[B,A]=cheby1(N,alphap,CF,'s');
display('Un Normalised Transfer Function is,')
Electronics and Communication Engineering Department
Digital Signal Processing Lab

Hs=tf(B,A)
[num,den]=bilinear(B,A,1/T);
display('Digital Transfer Function is,')
Hz=tf(num,den,T)
w=0:pi/16:pi;
display('Frequency Response is,')
Hw=freqz(num,den,w)
display('Magnitude Response is,')
Hw_mag=abs(Hw)
plot(w/pi,Hw_mag,'k');
grid;
title('Magnitude Response of Third order Low pass Filter');
xlabel('Normalised Frequency');
ylabel('Magnitude');

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Continuous Assessment

Max Allotted
S.No Components
mark Marks

1. Preparation and Conduct


50
of experiments

2. Observation & Result 30

3. Record 10
Electronics and Communication Engineering Department
4. Viva Voce 10

Total 100
Digital Signal Processing Lab

Result:
Thus the MATLAB Program for design of IIR Filter was generated and plotted successfully.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Ex. No: Implementation of Power Spectrum Estimation

Aim:
To write a MATLAB Program to generate spectrum of various FFT length.

Apparatus Required:
Hardware: PC.

Software: 7.0.4.version.

Algorithm:
1. Start the program.
2. Get input signal for which power spectrum is to be drawn.
3. Plot the power spectrum for different N values.
4. Terminate the program.

Program:
clc;
clear all;
close all;
x=input('enter the input sequence');
l=length(x);

Electronics and Communication Engineering Department


Digital Signal Processing Lab

N=8;
psd=abs(fft(x,N)).^2/(l);
stem((0:N-1)/N,psd);
xlim([0 1]);
xlabel(‘Discrete Frequency f, f=k/N, k=0,1....N-
1’,’fontsize’,12,’fontweight’,’b’);
ylabel (‘power’,’fontsize’,12,’fontweight’,’b’);
title(‘Power spectrum, FFT length N=8’,’fontsize’,12,’fontweight’,’b’);

N=16;
psd=abs(fft(x,N)).^2/(l);figure;
stem((0:N-1)/N,psd);
xlim([0 1]);
xlabel(‘Discrete Frequency f, f=k/N, k=0,1....N-1’);
ylabel (‘power’,’fontsize’,12,’fontweight’,’b’);
title(‘Power spectrum, FFT length N=16’);

Electronics and Communication Engineering Department


Digital Signal Processing Lab

N=32;
psd=abs(fft(x,N)).^2/(l); figure;
stem((0:N-1)/N,psd);
xlim([0 1]);
xlabel(‘Discrete Frequency f, f=k/N, k=0,1....N-
1’,’fontsize’,12,’fontweight’,’b’);
ylabel (‘power’,’fontsize’,12,’fontweight’,’b’);
title(‘Power spectrum, FFT length N=32’);

N=64;
psd=abs(fft(x,N)).^2/(l); figure;
stem((0:N-1)/N,psd);
xlim([0 1]);
xlabel(‘Discrete Frequency’);
ylabel (‘power’);
title(‘Power spectrum, FFT length N=64’);

Continuous Assessment

Max Allotted
S.No Components
mark Marks

1. Preparation and Conduct


50
of experiments

2. Observation & Result 30

3. Record 10
Electronics and Communication Engineering Department
4. Viva Voce 10

Total 100
Digital Signal Processing Lab

Result:
Thus the MATLAB Program for power spectrum is plotted successfully.

PROCEDURE FOR 6713 CCS:


1. Open the CCS setup and select Family-c67xx, platform-Simulator, Endiannes-little.

2. Select C67xx simulator board and add then save & quit.

3. Start a new project using Project New pull down menu, save it in a separate directory (D:\
My projects) with file name project name.pjt.

4. Create a new source file using FileNewSource file menu and save it in the project folder
(project name.c).

5. Add the source file (project name.c) to the project ProjectAdd files to ProjectSelect
project name.c

6. Add the linker command file hello.cmd ProjectAdd files to Project(path: C:\CCstudio\
tutorial\dsk6713\hello\hello.cmd)

7. Add the run time support library file rts6700.libProjectAdd files to Project(path: C\
CCStudio\cgtools\lib\rts6700.lib)

8. Compile the program using „projectCompile menu or by Ctrl+F7

Electronics and Communication Engineering Department


Digital Signal Processing Lab

9. Build the program using projectBuild menu or by F7

10. Load the project name.out file (from project folder project name\Debug) using FileLoad
Program

11. Run the program using DebugRun or F5

12. To view the output graphically Select ViewGraphTime and Frequency

Ex.No:07 Simulation of Waveform Generator.

Aim:
To Write a DSP Processor Program to Generate a following standard signal.

1. Sinusoidal wave.
2. Cosine wave.
3. Square wave

Apparatus Required:
Hardware: PC.
Software: CCS 6713, 6713 Debugger

Theory:
The SPLK instruction allows a full 16-bit pattern to be written in to any memory location.
The parallel logic unit supports this bit manipulation independently of the ALU so that the ACC is un
affected.
ALGORITHM:
Step 1: Start the program.
Step 2: Define a float variable a.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Step 3: Find the sequence for sine signal.


Step 4: Find the sequence for cosine signal.
Step 5: Find the sequence for square signal.
Step 7: Plot the sine, cosine and square signal a.
Step 8: Terminate the process.

OUTPUT:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Program:
Sinusoidal signal
#include<stdio.h>
#include<math.h>
float a[100];
main ( )
{ int i;
for(i=0;i<99;i++)
{a[i]=sin(2*3.14*5*i/100);
printf(“%f,a[i]);
}}

Cosine signal
#include<stdio.h>
#include<math.h>
float a[100];
main ( )
{ int i;
for(i=0;i<99;i++)
{
a[i]=cos(2*3.14*5*i/100);
printf(“%f”,a[i]);
}
}

Electronics and Communication Engineering Department


Digital Signal Processing Lab

OUTPUT:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Square wave signal


#include <stdio.h>
#include <math.h>
int a[1000];
void main()
{
int i,j=0;
int b=5;
for(i=0;i<10;i++)
{
for (j=0;j<=50;j++)
{
a[(50*i)+j]=b;
}
b=b*(-1);
}
}

Continuous Assessment

Max Allotted
S.No Components
mark Marks

1. Preparation and Conduct


50
of experiments

2. Observation & Result 30

3. Record 10

4. Viva Voce 10

Total 100

Result:
Thus the C program for generation of different wave form is executed and plotted through
processor successfully.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Ex.No:08 Simulation of Convolution Using C Coding.

AIM:
To write a C program to obtain the linear convolution between two finite duration sequences
x(n) and h(n).
ALGORITHM:
Step 1: Start the program.
Step 2: Get the sequence x(n).
Step 3: Get the range of the sequence x(n).
Step 4: Get the sequence h(n).
Step 5: Get the range of the sequence h(n)..
Step 6: Find the convolution between the sequences x(n) and h(n)
Step 7: Plot the convoluted sequence y(n).
Step 8: Terminate the process.
PROGRAM:
Linear convolution:
#include<stdio.h>
#include<math.h>
int y[20];
void main()
{
int m=4;
int n=4;
int i=0;j;
int x[15]={1,2,3,4};
int h[15]={1,2,2,1};
int y(20);

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Input:

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

for(i=0;i<m+n-1;i++)
}
y[i=0];
for(j=0;j<=i;j++)
y[i]=x[j]*h[i-j];
for(i=0;m+n-1;i++)
printf(“%d\n”,y[i]);
}
Circular convolution:
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf("Enter the length of 1st sequence\n");
scanf("%d",&m);
printf("Enter the length of 2nd sequence\n");
scanf("%d",&n);
printf("Enter the 1st sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter the 2nd sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);if(m-n!=0){if(m>n)
{
for(i=n;i<m;i++)
h(i)=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
a[j]=h[n-j];

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Input:

Output:

for(i=0;i<n;i++)

Electronics and Communication Engineering Department


Digital Signal Processing Lab

y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf("The circular convolution is \n");
for(i=0;i<n;i++)
printf("%d\t",y[i]);
}

Continuous Assessment

Max Allotted
S.No Components
mark Marks

1. Preparation and Conduct


50
of experiments

2. Observation & Result 30

3. Record 10

4. Viva Voce 10

Total 100

Result:
Thus the C program for calculation of linear convolution and circular convolution was
successfully completed.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Ex.No:9 DESIGN OF FIR FILTER

AIM:
To write a C program to obtain FIR filter design.
ALGORITHM:
Step 1: Start the program.
Step 2: Define pi value
Step 3: Get the number of samples.
Step 4: Get the choice of windows.
Step 5: Calculate the output.
Step 6: Terminate the process.
PROGRAM:
#include<stdio.h>

#include<math.h>

#define pi 3.1415

int n,N,c;

float wr[64],wt[64];

void main()

printf("\n enter no. of samples,N= :");

scanf("%d",&N);

printf("\n enter choice of window function: 1.rect 2. triang \n c= :");

scanf("%d",&c);

printf("\n elements of window function are:");

switch(c)

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

case 1:

for(n=0;n<=N-1;n++)

Electronics and Communication Engineering Department


Digital Signal Processing Lab

wr[n]=1;

printf(" \n wr[%d]=%f",n,wr[n]);

break;

case 2:

for(n=0;n<=N-1;n++)

wt[n]=1-(2*(float)n/(N-1));

printf("\n wt[%d]=%f",n,wt[n]);

break;

}
Continuous Assessment

Max Allotted
S.No Components
mark Marks

1. Preparation and Conduct


50
of experiments

2. Observation & Result 30

3. Record 10

4. Viva Voce 10

Total 100

Result:
Thus the C program for Loaded and design of FIR was successfully calculated and plotted.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Ex.No:10 DESIGN OF IIR FILTER

Electronics and Communication Engineering Department


Digital Signal Processing Lab

AIM:
To write a C program to obtain IIR filter design.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the value for order, cut of frequency, and choice of filter.
Step 3: Calculate the output.
Step 4: Terminate the process.
PROGRAM:
#include<stdio.h>

#include<math.h>

nt i,w,wc,c,N;

float H[100];

float mul(float, int);

void main()

printf("\n enter order of filter ");

scanf("%d",&N);

printf("\n enter the cutoff freq ");

scanf("%d",&wc);

printf("\n enter the choice for IIR filter 1. LPF 2.HPF ");

scanf("%d",&c);

switch(c)

Output:

Electronics and Communication Engineering Department


Digital Signal Processing Lab

case 1:

for(w=0;w<100;w++)

Electronics and Communication Engineering Department


Digital Signal Processing Lab

H[w]=1/sqrt(1+mul((w/(float)wc),2*N));

printf("H[%d]=%f\n",w,H[w]);

break;

case 2:

for(w=0;w<=100;w++){H[w]=1/sqrt(1+mul((float)wc/w,2*N));

printf("H[%d]=%f\n",w,H[w]);

break;

float mul(float a,int x)

for(i=0;i<x-1;i++)

a*=a;

return(a);

}.

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Electronics and Communication Engineering Department


Digital Signal Processing Lab

Continuous Assessment

Max Allotted
S.No Components
mark Marks

1. Preparation and Conduct


50
of experiments

2. Observation & Result 30

3. Record 10

4. Viva Voce 10

Total 100

Result:
Thus the C program is Loaded for design of IIR filter was successfully completed and plotted.

Electronics and Communication Engineering Department

You might also like