0% found this document useful (0 votes)
152 views

Digital Signal Processing

The document describes experiments related to digital signal processing using MATLAB. It includes experiments to generate basic signals like unit step, ramp, exponential and sinusoidal signals. It also covers impulse response calculation, DFT, DTFT, linear convolution, autocorrelation and circular convolution of sequences. The experiments provide hands-on experience with digital signal processing concepts and MATLAB commands.

Uploaded by

Sanjay Pal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Digital Signal Processing

The document describes experiments related to digital signal processing using MATLAB. It includes experiments to generate basic signals like unit step, ramp, exponential and sinusoidal signals. It also covers impulse response calculation, DFT, DTFT, linear convolution, autocorrelation and circular convolution of sequences. The experiments provide hands-on experience with digital signal processing concepts and MATLAB commands.

Uploaded by

Sanjay Pal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Digital signal processing

INDEX :
1. MATLAB program to generate basic signals.
2. MATLAB program to generate Impulse signal.
3. MATLAB program to evaluate the impulse response
of the system .
4. To study the computation of N point DFT of a given
sequence.
5. Write a program to compute N point DTFT of a
sequence.
6. To study the linear convolution of two given
sequences.
7. To study autocorrelation of a given sequence and
verification.
8. Study Circular convolution of two given sequences.
9. To Design of FIR filters using MATLAB commands
10. To design a Butterworth digital IIR filter using
MATLAB 7.0.

EXPERIMENT NO:- 1

AIM: Write MATLAB program for generation of signals.


To generate the following signals using MATLAB 7.0
1. Unit step signal
2. Unit ramp signal
3. Exponential growing signal
4. Exponential decaying signal
5. Sine signal
6. Cosine signal
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM:
1. Get the number of samples.
2. Generate the unit impulse, unit step using ‘ones’, ‘zeros’ matrix command.
3. Generate ramp, sine, cosine and exponential signals using corresponding general
formula.
4. Plot the graph.

PROGRAM:
1. UNIT STEP SIGNAL
SIGNAL clc; clearall;
closeall;
N=input('Numberof Samples
= '); n=-N:1:N
x=[zeros(1,N) 1 ones(1,N)]
stem(n,x); xlabel('Time');
ylabel('Amplitude'); title('Unit
Step Response');
% 3. UNIT RAMP SIGNAL
clc; clear
all;
close all;
disp('UNIT RAMP SIGNAL');
N=input('Number of Samples = ');
a=input('Amplitude = ') n=-N:1:N
x=a*n stem(n,x); xlabel('Time'
);
ylabel('Amplitude'); title('Unit Ramp
Response');

3.EXPONENTIAL DECAYING

SIGNAL
clc; clear
all;
close
all;
disp('EXPONENTIAL DECAYING
SIGNAL'); N=input('Number of
Samples = '); a=0.5 n=0:.1:N x=a.^n
stem(n,x); xlabel('Time'
);
ylabel('Amplitude');
title('Exponential Decaying Signal Response');

4. EXPONENTIAL GROWING
SIGNAL clc; clear all;
close
all;
disp('EXPONENTIAL GROWING SIGNAL');
N=input('Number of Samples = '); a=0.5
n=0:.1:N

x=a.^n stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Growing Signal Response');

5.COSINE SIGNAL
clc; Clear
all;
close
all;
disp('COSINE SIGNAL');
N=input('Number of Samples = ');
n=0:.1:N x=cos(n) stem(n,x);
xlabel('Time'); ylabel('Amplitude
');
title('Cosine Signal');

6. SINE SIGNAL
clc; clear all;
close all;
disp('SINE
SIGNAL');

N=input('Number of
Samples = '); n=0:.1:N
x=sin(n) stem(n,x);
xlabel('Time'
);
ylabel('Amplitude
'); title('sine
Signal');
EXPERIMENT NO. 2

AIM : Write a MATLAB program to generate Impulse function


APPARATUS REQUIRED:
System with MATLAB 7.0.
PROGRAM :
UNIT IMPULSE
SIGNAL clc; Clearall;
closeall;
N=input('Number of
Samples'); n=-N:1:N
x=[zeros(1,N) 1 zeros(1,N)]
stem(n,x); xlabel('Time');
ylabel('Amplitude');
title('Impulse Response');

                                   EXPERIMENT NO. 3

AIM:- To write a MATLAB program to evaluate the impulse response of the system .

EQUIPMENTS:

Operating System - Windows XP


Constructor - Simulator

Software - CCStudio 3 & MATLAB 7.5 PROGRAM:-

clc; clear all;

close all;

% Difference equation of a second order system % y(n) = x(n)

+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2) b=input('enter the

coefficients of x(n),x(n-1)-----'); a=input('enter the coefficients

of y(n),y(n-1)----');

N=input('enter the number of samples of imp response ');

[h,t]=impz(b,a,N); subplot(2,1,1);

% figure(1); plot(t,h); title('plot of

impulse response'); ylabel('amplitude');

xlabel('time index----->N');

subplot(2,1,2); % figure(2); stem(t,h);

title('plot of impulse response');

ylabel('amplitude'); xlabel('time

index----->N'); disp(h); grid on;

Output :

Enter the coefficients of x(n),x(n-1)-----[1 0.5 0.85] enter the coefficients of y(n),y(n-1)-----[1 -1
-1]

Enter the number of samples of imp respons 4

1.1000

2.5000
3.3500
4.8500

GRAPH:

RESULT: The impulse response of given Differential equation is obtained. Hence the theory
and practical value are proved.

                                              EXPERIMENT NO: 4

AIM: To study the computation of N point DFT of a given sequence and to plot
magnitude and phase spectrum.
APPARATUS REQUIRED:
System with MATLAB 7.0.
PROGRAM:
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); 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
RESULT: We have study the computation of N point DFT of a given sequence and
also plot magnitude and phase. 

                                             

                                     EXPERIMENT NO. 5

Aim : Write a program to compute N point DTFT of a sequence.

Apparatus :
System with MATLAB 7.0.
Program :

clc;

% Compute the frequency samples of the DTFT w =

-4*pi:8*pi/511:4*pi; num = [2 1]; den = [1 -0.6]; h =

freqz(num, den, w); % Plot the DTFT subplot(2,2,1)

plot(w/pi,real(h)); grid on; title('Real part of

H(e^{j\omega})') xlabel('\omega /\pi');

ylabel('Amplitude'); subplot(2,2,2) plot(w/pi,imag(h));

grid on; title('Imaginary part of H(e^{j\omega})')

xlabel('\omega /\pi'); subplot(2,2,3) plot(w/pi,abs(h));

grid on; title('Magnitude Spectrum |H(e^{j\omega})|')

xlabel('\omega /\pi'); ylabel('Amplitude'); subplot(2,2,4)


plot(w/pi,angle(h)); grid on; title('Phase Spectrum

arg[H(e^{j\omega})]') xlabel('\omega /\pi');

ylabel('Phase, radians');

Output :

EXPERIMENT NO. 6

AIM : To study the linear convolution of two given sequences.


APPARATUS REQUIRED:
System with MATLAB 7.0.
PROGRAM :
% Linear convolution using conv command (A) Using
CONV command.
clc;
x1=input('enter the first sequence');
subplot(3,1,1); stem(x1);
ylabel('amplitude'); title('plot of the first
sequence'); x2=input('enter 2nd sequence');
subplot(3,1,2); stem(x2);
ylabel('amplitude'); title('plot of 2nd
sequence'); f=conv(x1,x2);
disp('output of linear conv is'); disp(f);
xlabel('time index n');
ylabel('amplitude f'); subplot(3,1,3);
stem(f);
title('linear conv of sequence'); Output
enter the first sequence[1 2 3] enter 2nd
sequence[1 2 3 4] output of linear conv is
1 4 10 16 17 12
(B) Linear convolution Using DFT and IDFT / Linear convolution using circular
convolution
clc; clear all;
x1=input(‘enter the first sequence’); x2=input(‘enter
the second sequence’); n=input(‘enter the no of
points of the dft’); subplot(3,1,1); stem(x1,’filled’);
title(‘plot of first sequence’);
subplot(3,1,2); stem(x2,’filled’);
title(‘plot the second sequnce’); n1
=length(x1); n2 = length(x2);
m = n1+n2-1; % Length of linear convolution x = [x1 zeros(1,n2-
1)]; % Padding of zeros to make it of
% length m y = [x2
zeros(1,n1-1)]; x_fft =
fft(x,m); y_fft = fft(y,m);
dft_xy = x_fft.*y_fft;
y=ifft(dft_xy,m);
disp(‘the circular convolution result is ......’); disp(y);
subplot(3,1,3); stem(y,’filled’);
title(‘plot of circularly convoluted sequence’); Output
enter the first sequence[1 2 1 2 1 2] enter the
second sequence[1 2 3 4] the circular convolution
result is ......
1.0000 4.0000 8.0000 14.0000 16.0000 14.0000
15.0000 10.0000 8.0000

Output :

RESULT:- Linear convolution has been


EXPERIMENT NO: 7

AIM :To study autocorrelation of a given sequence and verification of its properties.

APPARATUS REQUIRED :
System with MATLAB 7.0.
PROGRAM :
% Read the signal
x=[1,2,3,6,5,4] %
define the axis
n=0:1:length(x)-1 %
plot the signal
stem(n,x); xlabel('n');
% auto correlate the signal
Rxx=xcorr(x,x);
% the axis for auto correlation results nRxx=-
length(x)+1:length(x)-1 % display the result
stem(nRxx,Rxx)
% properties of Rxx(0) gives the energy of the signal
% find energy of the signal energy=sum(x.^2)
%set index of the centre value
centre_index=ceil(length(Rxx)/2) % Acces
the centre value Rxx(0)
Rxx_0==Rxx(centre_index)
Rxx_0==Rxx(centre_index) % Check if the
Rxx(0)=energy if Rxx_0==energy
disp('Rxx(0) gives energy proved'); else
disp('Rxx(0) gives energy not proved'); end
Rxx_right=Rxx(centre_index:1:length(Rxx))
Rxx_left=Rxx(centre_index:-1:1) if
Rxx_right==Rxx_left disp('Rxx is even'); else
disp('Rxx is not even'); end OUTPUT:-
x = 1 2 3 6 5 4 n = 0 1 2 3 4 5 nRxx
= -5 -4 -3 -2 -1 0 1 2 3 4
5 energy= 91
centre_index = 6
Rxx(0) gives energy not proved
Rxx_right =
91.0000 76.0000 54.0000 28.0000 13.0000 4.0000
Rxx_left =
91.0000 76.0000 54.0000 28.0000 13.0000 4.0000
Rxx is even
RESULT : Autocorrelation of a given sequence and its properties has been proved.

EXPERIMENT NO: 8

AIM : To study Circular convolution of two given sequences.


APPARATUS REQUIRED:
System with MATLAB 7.0.
PROGRAM :
clc; clear all;
x1=input('enter the first sequence');
x2=input('enter the second sequence'); n1 =
length(x1); n2 = length(x2); subplot(3,1,1);
stem(x1,'filled'); title('plot of first sequence');
subplot(3,1,2); stem(x2,'filled'); title('plot the
second sequnce'); y1=fft(x1,n); y2=fft(x2,n);
y3=y1.*y2; y=ifft(y3,n);
disp('the circular convolution result is ......'); disp(y);
subplot(3,1,3); stem(y,'filled');
title('plot of circularly convoluted sequence');
Output
enter the first sequence[1 2 3 4] enter the second
sequence[4 3 2 1] the circular convolution result
is ......
24 22 24 30
RESULT:- Circular convolution has been proved.  

                                                    EXPERIMENT NO. 9

AIM : Design of FIR filters using MATLAB commands 


EQUIPMENTS: 
Operating System - Windows XP
Constructor - Simulator
Software - CCStudio 3 & MATLAB 7.5

. DESCRIPTION: Digital filters refers to the hard ware and software


implementation of the
mathematical algorithm which accepts a digital signal as input and produces another digital
signal
as output whose wave shape, amplitude and phase response has been modified in a specified
manner. Digital filter play very important role in DSP. Compare with analog filters they are
preferred in number of application due to following advantages.
Truly linear phase response
Better frequency response
Filtered and unfiltered data remains saved for further use.
There are two type of digital filters.

1. Finite impulse response


2. Infinite impulse response

PROGRAM :
App. 1 Window function method
f1=100;f2=200;%the frequencies of sines signal that needs filtered
fs=2000;%sampling frequency

m=(0.3*f1)/(fs/2);%define tansition bandwidth


M=round(8/m);%define the window length N=M-1;%define the order of
filter
b=fir1(N,0.5*f2/(fs/2));%use the firl function to design a filter
%Input parameters are respectively the order number and the cutoff
%frequency of filter figure(1)
[h,f]=freqz(b,1,512);%amplitude-frequency characteristic graph
plot(f*fs/(2*pi),20*log10(abs(h)))%parameters are respectively frequency and
amplitude
xlabel('frequency/Hz');ylabel('gain/dB');title('The gain response of lowpass
filter'); figure(2) subplot(211)
t=0:1/fs:0.2;%define the time domain and the steplength s=sin(2*pi*f1*t)
+sin(2*pi*f2*t);%signal before filtering plot(t,s);%plot the signal graph before
filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram before filtering');
axis([0 0.1 -2 2]); subplot(212)
Fs=fft(s,512);%transform the signal to frequency domain AFs=abs(Fs);%take
the amplitude f=(0:255)*fs/512;%frequency sampling
plot(f,AFs(1:256));%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain diagram before filtering');
figure(3)
sf=filter(b,1,s);%use filter function to filter subplot(211)
plot(t,sf)%plot the signal graph after filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram after filtering');
axis([0.1 0.2 -2 2]); subplot(212)
Fsf=fft(sf,512);%frequency-domain diagram after filtering AFsf=abs(Fsf);
%the amplitude f=(0:255)*fs/512;%frequency sampling
plot(f,AFsf(1:256))%plot the frequency domain diagram after filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain diagram after
filtering');

                                EXPERIMENT NO. 10

AIM : To design a Butterworth digital IIR filter using MATLAB 7.0.


APPARATUS REQUIRED :
System with MATLAB 7.0.
ALGORITHM :
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter using log √ [10 kp – 1 / 10 kp – 1] N =
------------------------------------- log s / p
5.Find the filter co-efficient.
6.Draw the magnitude and phase response.
PROGRAM:
clear all; clc;
close all;
format long
rp=input(‘enter the pass band ripple’); rs=input(‘enter the
stop band ripple’); wp=input(‘enter the pass band
frequency
‘); ws=input(‘enter the stop band frequency
‘); fs=input(‘enter the sampling frequency
‘); w1=2*wp/fs; w2=2*ws/fs;
%LOW PASS FILTER
[n,wn]=buttord(w1,w2,rp,rs];
[b,a]=butter(n,wn);
%[b,a]=zp2tf(z,p,k);
[b,a]= butter(n,wn);
W=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h)); an=angle(h);
%figure(1); Subplot(2,1,1);
Plot(om/pi,m); Ylabel(‘gain in db…
>’);
Xlabel(‘(a)normalized frequency…>’);
%figure(1);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel(‘(b)normalized frequency…>’);
Ylabel(‘phase in radians…>’);
%HIGH PASS FILTER
[n,wn]=buttord(w1,w2,rp,rs];
[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); figure(2);
Subplot(2,1,1); Plot(om/pi,m);
Ylabel(‘gain in db…>’);
Xlabel(‘(a)normalized frequency…>’); figure(2);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel(‘(b)normalized frequency…>’); Ylabel(‘phase in
radians…>’);
%BAND PASS FILTER
[n]=buttord(w1,w2,rp,rs];
Wn=[w1,w2];
[b,a]=butter(n,wn,’band pass’);
W=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h); figure(3);
Subplot(2,1,1); Plot(om/pi,m);
Ylabel(‘gain in db…>’);
Xlabel(‘(a)normalized frequency…>’); figure(3);
Subplot(2,1,2);
Plot(om/pi,an);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy