Sie sind auf Seite 1von 22

SANSKRITHI SCHOOL OF ENGINEERING

Department of ECE

( 15A04608 )
DIGITAL SIGNAL PROCESSING
LABORATORY MANUAL

NAME:
REGISTER NO:
YEAR & SEMESTER:

Prepared Approved
By By

K.ANITHA
AP/ ECE
Mr. HARI KRISHNAN.S
HOD-ECE
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR

B. Tech III-IISem. (ECE)

DIGITAL SIGNAL PROCESSING LABORATORY


COURSE OUTCOMES:
Able to design real time DSP systems and real world applications.
Able to implement DSP algorithms using both fixed and floating point processors.
List of Experiments:
(Minimum of 5 experiments are to be conducted from each part)
Software Experiments (PART – A)
1. Generation of random signal and plot the same as a waveform showing all the
specifications.
2. Finding Power and (or) Energy of a given signal
3. Convolution and Correlation (auto and cross correlation) of discrete sequences without
using built in functions for convolution and correlation operations.
4. DTFT of a given signal
5. N – point FFT algorithm
6. Design of FIR filter using windowing technique and verify the frequency response of the
filter.
7. Design of IIR filter using any of the available methods and verify the frequency response
of the filter.
8. Design of analog filters.
Using DSP Processor kits (Floating point) and Code Composure Studio (CCS) (PART – B)
1.Generation of random signal and plot the same as a waveform showing all the specifications.
2. Finding Power and (or) Energy of a given signal.
3. Convolution and Correlation (auto and cross correlation) of discrete sequences without
using built in functions for convolution and correlation operations.
4. DTFT of a given signal
5. N – point FFT algorithm
6. Design of FIR filter using windowing technique and verify the frequency response of the
filter.
7. Design of IIR filter using any of the available methods and verify the frequency response of the filter.
8. Design of analog filters.
INDEX
Faculty
EX.NO NAME OF THE EXPERIMENTS Page No Signature

1.

2.

3.

4.

5.

6.

7.

8.

9.

10

11

12
1.Generation of random signal and plot the same as a waveform showing
all the specifications

AIM:
To generate the following discrete time signals using MATLAB:

 Unit step
 Unit Ramp
 Impulse
 Sine
 Cosine
Software required: MATLAB
ALGORITHM:

Step-1: Clear the command window and workspace.


Step-2: Declare the time scale and amplitude of the signal.
Step-3: Using pre-defined functions generate the corresponding waveforms and plot them.
Step-4: Label the axes and title.
Step-5: Execute the program and view the output waveforms.

CODING:

GENERATION OF ELEMENTARY SIGNALS:

clc;
t=0:1:10;
f=0.1;
a=t;
%RAMP SIGNAL
subplot(3,2,1);
plot(t,a);
title('continuous ramp');
xlabel('time');
ylabel('x(t)');

subplot(3,2,2);
stem(t,a);
title('discrete ramp');
xlabel('n');
ylabel('x(n)');
%STEP SIGNAL
y1=ones(1,11);
subplot(3,2,3);
plot(t,y1);
title('continuous step');
xlabel('time');
ylabel('x(t)');
subplot(3,2,4);
stem(t,y1);
title('discrete step');
xlabel('n');
ylabel('x(n)');
%IMPULSE SIGNAL
p=-10:1:10;
y=[zeros(10,1);1;zeros(10,1)];
subplot(3,2,5);
stem(p,y);
title('discrete impulse');
xlabel('n');
ylabel('x(n)');
GENERATION OF SINE AND COSINE WAVEFORMS
clc;
t=0:0.2:10;
f=0.5;
a=10;

%SINE SIGNAL
s=a*sin(2*pi*f*t);
subplot(2,2,1);
plot(t,s);
title('continuous sine wave');
xlabel('time');
ylabel('x(t)');
subplot(2,2,2);
stem(t,s);
title('discrete sine wave');
xlabel('n');
ylabel('x(n)');
%COSINE SIGNAL
c=a*cos(2*pi*f*t);
subplot(2,2,3);
plot(t,c);
title('continuous cos wave');
xlabel('time');
ylabel('x(t)');
subplot(2,2,4);
stem(t,c);
title('discrete cos wave');
xlabel('n');
ylabel('x(n)');

SINE AND COSINE WAVEFORMS:

continuous s ine wave dis c rete sine wave

10 10

5 5

x(n)
0 0
x(t)

-5 -5

-10 -10
0 2 4 6 8 10 0 2 4 6 8 10

tim e n

c ontinuous c os wave dis c rete cos wave

10 10

5 5
x(n)

0 0
x(t)

-5 -5

-10 -10
0 2 4 6 8 10 0 2 4 6 8 10

tim e n
ELEMENTARY SIGN

continuousramp discreteramp
10 10

5 5

x (n)
x (t)

0 0
0 2 4 6 8 10 0 2 4 6 8 10
time n

2 continuousstep 1 discretestep

1.5

1 0.5

0.5

0 0
0 2 4 6 8 10 0 2 4 6 8 10
time n

1 discreteimpulse

0.5

0
-10 -5 0 5 10

RESULT:
Thus the various discrete time signals are generated using MATLAB
2. CONVOLUTION and CORRELATION

AIM:
To generate the following convolution and correlation signals using MATLAB

Software required: MATLAB

CODING:

Linear convolution:

%program for finding linear convolution between two sequences

clc; close all; clear all;

x=input('Supply the input signal: ');

h=input('Supply the System response: ');

L=length(x);

M=length(h);

x1=[zeros(1,M-1),x,zeros(1,M-1)];

conv_matrix=[];

for i=1: L+M-1

seq=x1(1,i:i+M-1);

seq1=fliplr(seq);

conv_matrix=[conv_matrix;seq1];

end

y=conv_matrix*h'

y1=conv(x,h)

subplot(221)

stem(x)

xlabel('n'); ylabel('x(n)');

grid on

title('INPUT SIGNAL');
subplot(223)

stem(y)

xlabel('n'); ylabel('y(n)');

grid on

title('OUTPUT SIGNAL');

subplot(222)

stem(h)

xlabel('n'); ylabel('h(n)');

grid on

title('SYSTEM RESPONSE');

subplot(224)

stem(y1)

xlabel('n'); ylabel('y1(n)');

grid on

title('OUTPUT SIGNAL USING MATLAB FUNCTION');

output:

Enter first sequence; [1 2 3]


Enter Second sequence; [1 2 3 4]
r = [ 1 4 10 16 17 12]

CIRCULAR CONVOLTION

clc;
g=input('Enter the sequence 1:');
h=input('Enter the sequence 2:');
N1=length(g);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
if(N3>0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
for n=1:N;
y(n)=0;
for i=1:N;
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=[y(n)+(g(i)*h(j))];
end
end
disp('The resultant is');y
subplot(2,1,1);
stem(y);
xlabel('N->');
ylabel('Amplititude->');
OUTPUT:
Enter 1st sequence: [1 2 2 2]
Enter 2nd sequence: [1 2 3]
c =[ 11 10 9 12]

AUTO-CORRELATION

clc;
close all;
clear all;
x=input('Enter the sequence 1: ');
y=xcorr(x,x);
figure;
subplot(2,1,1);
stem(x);
ylabel('Amplitude->');
xlabel('n->');
title('Input sequence');
subplot(2,1,2);
stem(fliplr(y));
ylabel('amplitude');
xlabel('n->');
title('Output sequence');
disp('the resultant is ');
fliplr(y);
OUTPUT:

Enter first sequence: [1 2 3 4]


Ans = [4 11 20 30 20 11 4]
CROSS-CORRELATION

clc;
clear all;
close all;
x=input('Enter the sequence 1: ');
h=input('Enter the sequence 2: ');
y=xcorr(x,h);
figure;
subplot(3,1,1);
stem(x);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 1');
subplot(3,1,2);
stem(fliplr(y));
stem(h);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 2');
subplot(3,1,3);
stem(fliplr(y));
xlabel('n->');
ylabel('Amplitude->');
title('Output sequence');
disp('The resultant is');
fliplr(y);

OUTPUT:

Enter first sequence:[1 2 2 2]


Enter Second sequence:[2 2 3]
ans: r =[ 3 8 12 14 8 4]

RESULT:

Hence we findout the convolution and correlation of a given sequence.


3. DFT / IDFT OF GIVEN DT SIGNAL

AIM: To find the DFT / IDFT of given signal.

Software required: MATLAB


MATLAB CODE:
x=input('enter sequence');
N=length(x);
s=zeros(1,N);
for k=1:N
for n=1:N
s(k)=s(k)+x(n)*exp(-j*2*pi*(k-1)*(n-
1)/N);
end
end
disp(s);
% INVERSE DISCRETE FOURIER TRANSFORM.
m=input('enter sequence'); %m=s;
N=length(m);
G=zeros(1,N);
for n=1:N
for k=1:N
G(n)=G(n)+m(k)*exp(j*2*pi*(k-1)*(n-1)/N);
end;
end;
disp(G/N);

Output:
enter sequence[1 2 3 4 5]
Columns 1 through 4
15.0000 -2.5000 + 3.4410i -2.5000
+ 0.8123i -2.5000 - 0.8123i
Column 5
-2.5000 - 3.4410i
enter sequence s
Columns 1 through 4
1.0000 - 0.0000i 2.0000 - 0.0000i 3.0000
4.0000 + 0.0000i
Column 5
5.0000 + 0.0000i

RESULT:
Hence we executed the DFT & IDFT of a given signal.
Computation of N point DFT of a given sequence and to plot magnitude and
phase spectrum.

AIM: To generate and compute n point DFT sequence.

SOURCE CODE:

N = input('Enter the the value of N(Value of N in N-Point DFT)');


x = input('Enter the sequence for which DFT is to be calculated');
n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(-1j*2*pi/N); % twiddle factor
nk=n'*k;

WNnk=WN.^nk;
Xk=x*WNnk;
MagX=abs(Xk) % Magnitude of calculated DFT
PhaseX=angle(Xk)*180/pi % Phase of the calculated DFT figure(1);
subplot(2,1,1);
plot(k,MagX);
subplot(2,1,2);
plot(k,PhaseX);

OUTPUT
Enter the the value of N(Value of N in N-Point DFT)4 Enter the sequence for which DFT is to be
calculated [1 2 3 4]
MagX = 10.0000 2.8284 2.0000 2.8284
PhaseX = 0 135.0000 -180.0000 -135.0000
DFT of the given sequence is
10.0000-2.0000 + 2.0000i -2.0000 - 0.0000i -2.0000 -
2.0000i
4. N-point FFT / IFFT OF GIVEN DT SIGNAL

Aim: findout the N-POINT FFT WITHOUT USING INBUILT FUNCTION

Software required: MATLAB


PROGRAM:
clear all;
close all;
clc;
x=input('Enter the sequence x[n]= ');
N=input('Enter the value N point= ');
L=length(x);
x_n=[x,zeros(1,N-L)];
for i=1:N
for j=1:N
temp=-2*pi*(i-1)*(j-1)/N;
DFT_mat(i,j)=exp(complex(0,temp));
end
end
X_k=DFT_mat*x_n';
disp('N point DFT is X[k] = ');
disp(X_k);
mag=abs(X_k);
phase=angle(X_k)*180/pi;
subplot(2,1,1);
stem(mag);
xlabel('frequency index k');
ylabel('Magnitude of X[k]');
axis([0 N+1 -2 max(mag)+2]);
subplot(2,1,2);
stem(phase);
xlabel('frequency index k');
ylabel('Phase of X[k]');
axis([0 N+1 -180 180]);

PROGRAM: for user defined sequence


%fast fourier transform
clc;
clear all;
close all;
tic;
x=input('enter the sequence');
n=input('enter the length of fft'); %compute fft
disp('fourier transformed signal');
X=fft(x,n)
subplot(1,2,1);stem(x); title('i/p signal');
xlabel('n --->');
ylabel('x(n) -->');grid;
subplot(1,2,2);stem(X);
title('fft of i/p x(n) is:');
xlabel('Real axis --->');
ylabel('Imaginary axis -->');grid;

OUTPUT:-
enter the sequence[1 .25 .3 4]
enter the length of fft4
fourier transformed signal
X=
5.5500 0.7000 + 3.7500i -2.9500 0.7000 - 3.7500i

RESULT: The Fast Fourier Transform of given sequence is obtained. Hence the theory and practical
value are proved.
5. DESIGN OF FIR FILTER USING WINDOWING TECHNIQUE

AIM:
To design the following FIR filters using windowing techniques
 LPF using Hamming window
 HPF using Blackman window

Software required: MATLAB

LOW PASS FILTER:


CODING:
clc;
wc=0.5*pi;
N=25;
alpha=(N-1)/2;eps=0.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=boxcar(N);
hn=hd.*wr';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
wh=hamming(N);
hn=hd.*wh';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-.');grid;
title('FIR-Low pass filter');
ylabel('magnitude');
xlabel('Normalised frequency');
hold off
HIGH PASS FILTER:
CODING:
clc;
wc=0.5*pi;
N=25;
alpha=(N-1)/2;eps=0.001;
n=0:1:N-1;
hd=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));
wr=boxcar(N);
hn=hd.*wr';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
wb=blackman(N);

hn=hd.*wb';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-.');grid;
title('FIR-High pass filter');
ylabel('magnitude');
xlabel('Normalised frequency');
hold off
BAND STOP FILTER:
CODING:
clc;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
alpha=(N-1)/2;eps=0.001;
n=0:1:N-1;
hd=(sin(wc1*(n-alpha+eps))-sin(wc2*(n-alpha+eps))+sin(pi*(n-alpha+eps)))./
(pi*(n-alpha+eps));
wr=boxcar(N);
hn=hd.*wr';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
wh=hamming(N);
hn=hd.*wh';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-.');
hold on
wb=blackman(N);
hn=hd.*wb';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));grid;
title('FIR-Bandstop filter');
ylabel('magnitude');
xlabel('Normalised frequency');
hold off
BAND PASS FILTER:
CODING:
clc;
wc1=0.25*pi;

wc2=0.75*pi;
N=25;
alpha=(N-1)/2;eps=0.001;
n=0:1:N-1;
hd=(sin(wc2*(n-alpha+eps))-sin(wc1*(n-alpha+eps)))./(pi*(n-alpha+eps));
wr=boxcar(N);
hn=hd.*wr';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
wh=hamming(N);
hn=hd.*wh';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-.');grid;
title('FIR-Bandpass filter');
ylabel('magnitude');
xlabel('Normalised frequency');
hold off
OUTPUT|:
RESULT:
Thus FIR filters have been designed using window technique.
6. DESIGN OF IIT FILTER USING BUTTERWORTH & CHEBYCHEV FILTER

AIM:
To design the following IIR filters :
 Butterworth type
 Chebychev type

Software required: MATLAB


BUTTERWORTH FILTER
CODING:
clc;
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
Rp=input('Enter the passband attenuation:');
Rs=input('Enter the stopband attenuation:');
[n,wn]=buttord(wp,ws,Rp,Rs);
disp('order');
disp(n);
disp('cutoff frequency');
disp(wn);
if wp<ws
type='low';
elseif wp>ws
type='high';
elseif ws(1)<wp(1)<wp(2)<ws(2)
type='bandpass';
elseif wp(1)<ws(1)<ws(2)<wp(2)
type='stop';
end
[b,a]=butter(n,wn,type);
freqz(b,a)
CHEBYSHEV FILTER
CODING:
clc;
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
Rp=input('Enter the passband attenuation:');
Rs=input('Enter the stopband attenuation:');
[n,wn]=cheb1ord(wp,ws,Rp,Rs);
disp('order');
disp(n);
disp('cutoff frequency');
disp(wn);
if wp<ws
type='low';
elseif wp>ws
type='high';
elseif ws(1)<wp(1)<wp(2)<ws(2)
type='bandpass';
elseif wp(1)<ws(1)<ws(2)<wp(2)
type='stop';
end
[b,a]=cheby1(n,Rp,wn,type);
freqz(b,a)

Das könnte Ihnen auch gefallen