Académique Documents
Professionnel Documents
Culture Documents
Signal
Processing
Aim: To study MATLAB and various commands and file types associated with it and hence
appreciate the use of MATLAB in signal processing.
THEORY
MATLAB (short for Matrix Laboratory) is a special purpose computer program organized to
perform engineering and scientific calculations.
MATLAB has many advantages compared to conventional computer languages for technical
problem solving .Among them are:
1) Ease of use:->Programs may be easily written and modified with the built in integrated
development environment and debugged with the MATLAB debugger. Because the language is
so easy to use, it is ideal for the rapid prototyping of new programs.
4) Device independent plotting:->The plots and images can be displaced on any graphical output
device supported by the computer on which MATLAB is running. This capability makes
MATLAB an outstanding tool for visualizing technical data.
Aim: Write a program to develop elementary signal function modules (m-files) for unit sample,
unit step, exponential and unit ramp sequences.
THEORY
Exponential Function:
Unit impulse is a signal that is 0 everywhere except at n=0 where it is 1. In discrete time domain
the unit impulse signal is defined as:
∂(n) = 1; n=0
= 0; elsewhere
The integral of the impulse function is a unit step signal. In discrete time unit step signal is
defined as:
U(n) = 1; n>=0
= 0; n<0
Ramp signal:
R(n) = n; n>=0
= 0; n<0
DESCRIPTION OF MATLAB FUNCTION USED:
Exp:
The exp function is an elementary function that operates element-wise on arrays. Its domain
includes complex numbers.
Subplot:
subplot divides the current figure into rectangular panes that are numbered rowwise. Each pane
contains an axes. Subsequent plots are output to the current pane.
subplot(m,n,p) creates an axes in the pth pane of a figure divided into an m-by-n matrix of
rectangular panes.
The new axes becomes the current axes. If p is a vector, it specifies an axes having a position
that covers all the subplot positions listed in p.
Stem:
A two-dimensional stem plot displays data as lines extending from a baseline along the x-axis. A
circle (the default) or other marker whose y-position represents the data value terminates each
stem.
stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of the same
size. Additionally, X can be a row or a column vector and Y a matrix with length(X) rows.
Xlabel:
Ylabel:
t=0:7;
a=1;
y2=exp(a*t);
subplot(2,2,1);
stem(t,y2);
ylabel('amplitude-->');
xlabel('n-->')
clc;
clear all;
clear all;
t=-2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot(2,2,2);
stem(t,y);
ylabel('amplitude-->');
xlabel('n-->');
%TO PLOT RAMP SIGNAL
n1=7;
t=0:n1;
subplot(2,2,3);
stem(t,t);
ylabel('amplitude-->');
xlabel('(c)n-->');
n=7;
t=0:1:n-1;
y1=ones(1,n);
subplot(2,2,4);
stem(t,y1);
ylabel('amplitude-->');
xlabel('n-->');
OUTPUT:
Experiment No. 3
Aim:Write a program to develop program modules based on operation on sequences like signal
shifting,signal folding,signal addition and signal multiplication.
THEORY
Signal processing is group of basic operations applied to an input signal resulting in another
signal as the output. There are various operations which can be performed on a signal.
Signal addition:
{x1(n)}+{x2(n)}={x1(n)+x2(n)}
Summation: Sum all the values of the sequence to obtain the value of the output at a given
time.
Signal multiplication:
{x1(n)}*{x2(n)}={x1(n)*x2(n)}
Multiplication: Multiply x1(n) by x2(n) to obtain the value of the output sequence.
Scaling of signal:
S*{x(n)}={s*x(n)}
Shifting of signal:
The shift signal takes the input sequence and shifts the values by an increment of the independent
variable. The shifting may delay or advance the sequences in time.
Y(n)={x(n-k)}
Shifting: Shift x(-k) by n to the right(left) if n is positive(negative) to obtain x(n-k).
Folding of signal:
Y(n)=x(-n)
Here x(n) is the input and y(n) is the output.
Exp:
The exp function is an elementary function that operates element-wise on arrays. Its domain
includes complex numbers.
Subplot:
subplot divides the current figure into rectangular panes that are numbered rowwise. Each pane
contains an axes. Subsequent plots are output to the current pane.
subplot(m,n,p) creates an axes in the pth pane of a figure divided into an m-by-n matrix of
rectangular panes.
The new axes becomes the current axes. If p is a vector, it specifies an axes having a position
that covers all the subplot positions listed in p.
Stem:
A two-dimensional stem plot displays data as lines extending from a baseline along the x-axis. A
circle (the default) or other marker whose y-position represents the data value terminates each
stem.
stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of the same
size. Additionally, X can be a row or a column vector and Y a matrix with length(X) rows.
Xlabel:
Ylabel:
Sin:
The sin function operates element-wise on arrays. The function's domains and ranges include
complex values. All angles are in radians.
Cos:
The cos function operates element-wise on arrays. The function's domains and ranges include
complex values. All angles are in radians.
Max:
Min:
Fliplr:
B = fliplr(A) returns A with columns flipped in the left-right direction, that is, about a vertical
axis.
Disp:
disp(X) displays an array, without printing the array name. If X contains a text string, the string
is displayed.
PROGRAM:
%% Signal addition
n1=[-5:10];
n2=[-2:11];
x1=sin(n1);
x2=cos(n2);
subplot(2,2,1);stem(x1,n1);
subplot(2,2,2);stem(x2,n2);
n=min(min(n1),min(n2)): max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y=y1+y2;
subplot(2,2,3);
stem(y,n);
OUTPUT:
%% Signal multiplication
n1=[-5:10];
n2=[-2:11];
x1=sin(n1);
x2=cos(n2);
n=min(min(n1),min(n2)): max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y=y1.*y2;
stem(n,y);
OUTPUT:
%% Signal Shifting
a=8;
n1=[3:18];
x1=n1;
subplot(1,2,1);stem(n1,x1);
n=a+n1;
y=x1;
subplot(1,2,2);stem(n,y);
OUTPUT:
%% Signal Folding
x=[-2:3];
n1=-2;
n2=3;
n=[n1:n2];
m=-fliplr(n);
z=fliplr(x);
disp(n);
disp(x);
disp(m);
disp(z);
subplot(2,1,1);
stem(n,x);
title('given signal');
subplot(2,1,2);
stem(m,z);
title('folded signal');
OUTPUT:
Experiment No. 4
Aim:Write a program to generate the given sequences and decompose them into their even and
odd parts.
THEORY
Even and odd signals bear some important symmetry properties. Under reversal of independent
variable, these signals either remain the same (even signal) or get reflected or flipped (odd
signal) about the horizontal axis.
Equations or definitions (5.1) and (5.2) mathematically express these properties for both
continuous and discrete time cases.
It is possible to decompose any signal into its even and odd parts,
xe(t)=1/2(x(t)+x(-t))
xo(t) =1/2(x(t)-x(-t))
x(t)=xe(t)+xo(t)
Exp:
The exp function is an elementary function that operates element-wise on arrays. Its domain
includes complex numbers.
subplot divides the current figure into rectangular panes that are numbered rowwise. Each pane
contains an axes. Subsequent plots are output to the current pane.
subplot(m,n,p) creates an axes in the pth pane of a figure divided into an m-by-n matrix of
rectangular panes.
The new axes becomes the current axes. If p is a vector, it specifies an axes having a position
that covers all the subplot positions listed in p.
Stem:
A two-dimensional stem plot displays data as lines extending from a baseline along the x-axis. A
circle (the default) or other marker whose y-position represents the data value terminates each
stem.
stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of the same
size. Additionally, X can be a row or a column vector and Y a matrix with length(X) rows.
Xlabel:
Ylabel:
Clf:
clf deletes from the current figure all graphics objects whose handles are not hidden (i.e., their
HandleVisibility property is set to on).
Figure:
figure(h) does one of two things, depending on whether or not a figure with handle h exists. If h
is the handle to an existing figure, figure(h) makes the figure identified by h the current figure,
makes it visible, and raises it above all other figures on the screen. The current figure is the target
for graphics output. If h is not the handle to an existing figure, but is an integer, figure(h) creates
a figure and assigns it the handle h. figure(h) where h is not the handle to a figure, and is not an
integer, is an error.
Cos:
The cos function operates element-wise on arrays. The function's domains and ranges include
complex values. All angles are in radians.
Fliplr:
B = fliplr(A) returns A with columns flipped in the left-right direction, that is, about a vertical
axis.
a)
PROGRAM:
n=[0:20];
x=(0.9.^n).*cos((0.2.*n.*pi)+(pi/3));
[xe,xo,m]=evenodd(x,n);
figure(1),clf;
subplot(2,2,1);stem(n,x);
title('Main');
subplot(2,2,2);stem(m,xo);
title('ODD');
subplot(2,2,3);stem(m,xe);
title('EVEN');
FUNCTION:
function[xo,xe,m]=evenodd(x,n)
if any(imag(x)~=0)
end
m=-fliplr(n);
m1=min([m,n]); m2=max([m,n]);
m=m1:m2;
nm=n(1)-m(1); n1=1:length(n);
x1=zeros(1,length(m));
x1(n1+nm)=x; x=x1;
xe=0.5*(x+fliplr(x));
xo=0.5*(x-fliplr(x));
OUTPUT:
b)
PROGRAM:
n=[0:100];
x=10.*sin(0.008.*pi.*(n.^2)+randn(1,101));
[xe,xo,m]=evenodd(x,n);
figure(1),clf;
subplot(2,2,1);stem(n,x);
title('Main');
subplot(2,2,2);stem(m,xo);
title('ODD');
subplot(2,2,3);stem(m,xe);
title('EVEN');
function:
function[xo,xe,m]=evenodd(x,n)
if any(imag(x)~=0)
end
m=-fliplr(n);
m1=min([m,n]); m2=max([m,n]);
m=m1:m2;
nm=n(1)-m(1); n1=1:length(n);
x1=zeros(1,length(m));
x1(n1+nm)=x; x=x1;
xe=0.5*(x+fliplr(x));xo=0.5*(x-fliplr(x));
OUTPUT:
Experiment No. 6
Aim: Write a program to show the application of cross correlation in comparing the signals.
THEORY
In signal processing, cross-correlation is a measure of similarity of two waveforms as a function
of a time-lag applied to one of them. This is also known as a sliding dot product or inner-
product. It is commonly used to search a long duration signal for a shorter, known feature. It also
has applications in pattern recognition, single particle analysis, electron tomographic
averaging, cryptanalysis, and neurophysiology.
The exp function is an elementary function that operates element-wise on arrays. Its domain
includes complex numbers.
Subplot:
subplot divides the current figure into rectangular panes that are numbered rowwise. Each pane
contains an axes. Subsequent plots are output to the current pane.
subplot(m,n,p) creates an axes in the pth pane of a figure divided into an m-by-n matrix of
rectangular panes.
The new axes becomes the current axes. If p is a vector, it specifies an axes having a position
that covers all the subplot positions listed in p.
Stem:
A two-dimensional stem plot displays data as lines extending from a baseline along the x-axis. A
circle (the default) or other marker whose y-position represents the data value terminates each
stem.
stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of the same
size. Additionally, X can be a row or a column vector and Y a matrix with length(X) rows.
Xlabel:
Ylabel:
Xcorr:
c = xcorr(x,y) returns the cross-correlation sequence in a length 2*N-1 vector, where x and y are
length N vectors (N>1).
If x and y are not the same length, the shorter vector is zero-padded to the length of the longer
vector. By default, xcorr computes raw correlations with no normalization.
PROGRAM:
x=[1,2,3,4];
y=[4,3,2,1];
nx=[0:8];
[c,lags]=xcorr(x,y);
subplot(1,1,1);
stem(lags,c);
xlabel('n');
ylabel('a');
OUTPUT:
Experiment No. 8
Aim: Write a program to compute the partial expansion of a given transfer function in z-domain
and compute its poles and zeros. Also plot poles and zeros , and determine the ROC of z-
transform.
THEORY
In this technique the desired impulse response of the digital filter is obtained by uniformly
sampling the impulse response of the analog filter.
H(s) = (s+1)/(s2+5s+6)
Bilinear Transformation
In this technique the desired impulse response of the digital filter is obtained uniformly sampling
the impulse response of the analog filter.
Taking T=1sec.
H(z)=(0.15-0.1z-1-0.05z-2)/(1+0.2z-1)
Region of convergence
The region of convergence (ROC) is the set of points in the complex plane for which the Z-
transform summation converges.
DESCRIPTION OF MATLAB FUNCTION USED:
Zplane:
This function displays the poles and zeros of quantized filters, as well as the poles and zeros of
the associated unquantized reference filter.
Residue:
[r,p,k] = residue(b,a) finds the residues, poles, and direct terms of a partial fraction expansion of
the ratio of two polynomials, b(z) and a(z). Vectors b and a specify the coefficients of the
polynomials of the discrete-time system b(z)/a(z) in descending powers of z
PROGRAM:
>> n=[2 16 44 56 32]
n=
2 16 44 56 32
d=
3 3 -15 18 -12
>> [r,p,k]=residue(n,d)
r=
-0.0177
9.4914
-3.0702 + 2.3398i
-3.0702 - 2.3398i
p=
-3.2361
1.2361
0.5000 + 0.8660i
0.5000 - 0.8660i
k=
-2.6667
>> zplane(n,d)
OUTPUT:
Experiment No. 7
Aim: To compute the circular convolution of two sequences using MATLAB functions and
using the fold, shift and multiply procedure, then compare the result with that obtained using
DFT & IDFT.
THEORY
Let x1(n) and x2(n) are finite duration sequences both of length N with DFTs X1(k) and
X2(k).Now we find a sequence x3(n) for which the DFT is X3(k), where
X3(K)=X1(K)*X2(K)
This equation represents circular convolution of x1(n) and x2(n) which is represented as
DFT[x1(n) N x2(n)]=X1(K)*X2(K)
PROGRAM:
%% circular convolution
clc;
clear all;
close all;
n=50;
x1=1:n;
figure,stem(x1);
title('first seq');
x2=n:-1:1;
figure,stem(x2);
title('second seq');
x3=cconv(x1,x2,n);
figure,stem(x3);
x4=fliplr(x1);
x4=circshift(x4,[0,1]);
for i=1:n
x5(i)=sum(x2.*circshift(x4,[0,i-1]));
end
figure,stem(x5);
x6=fft(x1).*fft(x2);
x6==ifft(x6);
figure,stem(x6);
title('fourier transform');
OUTPUT:
first seq
50
45
40
35
30
25
20
15
10
0
0 5 10 15 20 25 30 35 40 45 50
second seq
50
45
40
35
30
25
20
15
10
0
0 5 10 15 20 25 30 35 40 45 50