You are on page 1of 80

SRI RAMAKRISHNA ENGINEERING COLLEGE

[Educational Service: SNR Sons Charitable Trust]


[Autonomous Institution, Accredited by NAAC with ‘A+’ Grade]
[Approved by AICTE and Permanently Affiliated to Anna University, Chennai]
[ISO 9001:2015 Certified and all eligible programmes Accredited by NBA]
VATTAMALAIPALAYAM, N.G.G.O. COLONY POST, COIMBATORE – 641 022.

DEPARTMENT OF ELECTRONICS AND


COMMUNICATION ENGINEERING

LABORATORY RECORD BOOK

20EC273 - SIGNAL PROCESSING LABORATORY

1
SRI RAMAKRISHNA ENGINEERING COLLEGE
[Educational Service: SNR Sons Charitable Trust]
[Autonomous Institution, Accredited by NAAC with ‘A+’ Grade]
[Approved by AICTE and Permanently Affiliated to Anna University, Chennai]
[ISO 9001:2015 Certified and all eligible programmes Accredited by NBA]
VATTAMALAIPALAYAM, N.G.G.O. COLONY POST, COIMBATORE – 641 022.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

This is to certify that the bonafide record of work done by


Mr./Ms._______________________________________ in 20EC273 – Signal Processing Laboratory
for B.E. during II year / IV semester in the Academic year 2022-2023.

Staff in-Charge Head of the Department

Date:

REGISTER NO…………………………….

This record is submitted for the Fourth Semester Autonomous Practical Examination held on
__________________.

Internal Examiner Subject Expert

2
INDEX
S.NO DATE LIST OF EXPERIMENTS PAGE NO. MARK SIGN

3
S.NO DATE LIST OF EXPERIMENTS PAGE NO. MARK SIGN

CONTENT BEYOND SYLLABUS

Average Marks

4
Ex. No: 01
GENERATION AND OPERATION ON SIGNALS
DATE:

AIM:
To write a program using MATLAB Program to generate the following signals and
perform the operations on signals.

1. Unit Impulse Waveform

2. Unit Step Waveform

3. Ramp Waveform

4. Parabolic Waveform

5. Sine and Cosine Waveform

6. Exponential Waveform

7. Operations of Signals

TOOLS REQUIRED:

MATLAB software.

THEORY:

CONTINUOUS SIGNAL:

The signals defined for every instant of time are known as


continuous or continuous- time signals. The continuous signal is also referred to as an analog
signal. They are continuous in both time and amplitude. Most of the signals that are encountered
in real-time are continuous.

DISCRETE SIGNAL:
The signals that are defined at discrete instants of time are known as
discrete-time signals. A time series is a function over a domain of integers. A discrete signal
is continuous in amplitude but discrete in time. A discrete time signal is obtained by sampling
the continuoussignal.
MATHEMATICAL EQUATIONS:

CONTINUOUS TIME SIGNAL

 x ( t ) = δ ( t ) = 1 , for t = 0 
Impulse sequence  
 = 0 , otherwise 
 x ( t ) = u ( t ) = 1 , for t  0 
Step sequence  
 = 0 , otherwise 

Ramp sequence  x ( t ) = r ( t ) = t , for t  0 


 
 = 0, otherwise 

t2
 , t0
Parabolic Signal p(t ) =  2
0 , t  0

eat , a  0 exponenonentially increasing



Exponential Signal x(t ) = 1 , a = 0 constantant magnitude
e− at , a  0 exponenonentially decaying

Sinusoidal signal x ( t ) = Asinωt

DISCRETE-TIME SIGNAL

 x ( n ) = δ ( n ) = 1 , for n = 0 
Impulse sequence  
 = 0, otherwise 

 x ( n ) = u ( n ) = 1, for n > 0 
Step sequence  
 0, otherwise 

Ramp sequence  x ( n ) = r ( n ) = n, for n  0 


 
 = 0, otherwise 

 n2
 , n0
Parabolic Signal p ( n) =  2
0 , n  0

a n , a  1 exponenonentially increasing
Exponential Signal  n
x(n) = a , 0  a  1 exponenonentially decaying
a n , a  0 signal with oppositesign

Sinusoidal Signal: x ( n ) = Asinωn


OPERATIONS ON SIGNALS
Time Shifting:
Continuous time signal : y(t) = x (t - T)
Discrete-time signal : y(n) = y (n - N)
Time Reversal:
Continuous time signal : y(t) = x(-t)
Discrete-time signal : y(n) = x(-n)
Time Scaling:
Continuous time signal : y(t) = x(At)
A > 1, signal is compressed,0 < A < 1, signal is expanded
Discrete-time signal : y(n) = x(Dn)
y(n) = x(Dn), D*n -Down sampling, D/n – Up sampling
Addition:
Continuous time signal : y(t) = x1(t) + x2(t)
Discrete time signal : y(n) = x1(n) + x2(n)
Multiplication:
Continuous time signal : y(t) = x1(t) * x2(t)
Discrete time signal : y(n) = x1(n) * x2(n)
Amplitude Scaling :
Continuous time signal : y(t) = A*x(t)
Discrete time signal : y(n) = A*x(n)

PROGRAM:
MATLAB PROGRAM

A) TO GENERATE UNIT IMPULSE AND UNIT STEP FUNCTION:


clc;
close all;
clear all;
figure(1);
%GENERATION OF UNIT IMPULSE SIGNAL FOR CONTINUOUS TIME
t=-10:10;
z=[zeros(1,10) ones(1,1) zeros(1,10)];
subplot(2,2,1);
plot(t,z);
xlabel('time');
ylabel('amplitude');
title('Unit Impulse signal in CT');

%GENERATION OF UNIT IMPULSE SIGNAL FOR DISCRETE TIME


n=-10:10;
z1=[zeros(1,10) ones(1,1) zeros(1,10)];
subplot(2,2,2);
stem(n,z1);
xlabel('time');
ylabel('amplitude');
title('Unit Impulse signal in DT');

%GENERATION OF UNIT STEP SIGNAL FOR CONTINUOUS TIME


t1=-10:10;
z2=[zeros(1,10) ones(1,11)];
subplot(2,2,3);
plot(t1,z2);
xlabel('time');
ylabel('amplitude');
title('Unit Step signal in CT');

%GENERATION OF UNIT STEP SIGNAL FOR DISCRETE TIME


n1=-10:10;
z3=[zeros(1,10) ones(1,11)];
subplot(2,2,4);
stem(n1,z3);
xlabel('time');
ylabel('amplitude');
title('Unit Step signal in DT');
B) TO GENERATE UNIT RAMP FUNCTION AND PARABOLIC SIGNAL:
figure(2);
%GENERATION OF UNIT RAMP FUNCTION FOR DISCRETE TIME
t3=0:10;
z4=t3;
subplot(2,2,2);
stem(t3,z4);

xlabel('time');
ylabel('amplitude');
title('Unit ramp signal in DT');

%GENERATION OF UNIT RAMP FUNCTION FOR CONTINUOUS TIME


t4=0:10;
z5=t4;
subplot(2,2,1);
plot(t4,z5);
xlabel('time');
ylabel('amplitude');
title('Unit ramp signal in CT');

%GENERATION OF PARABOLIC SIGNAL FOR DISCRETE TIME


t5=1:10;
z6=t5.^2/2;
subplot(2,2,4);
stem(t5,z6);
xlabel('time');
ylabel('amplitude');
title('Parabolic signal in DT');

%GENERATION OF PARABOLIC SIGNAL FOR CONTINUOUS TIME


t6=1:10;
z7=t6.^2/2;
subplot(2,2,3);
plot(t6,z7);
xlabel('time');
ylabel('amplitude');
title('Parabolic signal in CT');

C) TO GENERATE SINE WAVEFORM:


figure(3);
%GENERATION OF SINE WAVE FORM FOR DISCRETE TIME
t7=0:0.1:1;
f=1;
A=5;
x1=A*sin((2*pi*f*t7));
subplot(2,2,2);
stem(t7,x1);
xlabel('time');
ylabel('amplitude');
title('Sinusoidal signal in DT');

%GENERATION OF SINE WAVE FORM FOR CONTINUOUS TIME


t8=0:0.1:1;
f=1;
A=5;
x2=A*sin((2*pi*f*t8));
subplot(2,2,1);
plot(t8,x2);
xlabel('time');
ylabel('amplitude');
title('Sinusoidal signal in CT');

%GENERATION OF SINE WAVE FORM WITH PHASE SHIFT FOR DISCRETE TIME
t9=0:0.1:1;
f=1;
A=5;
x3=A*sin((2*pi*f*t9)+pi);
subplot(2,2,4);
stem(t9,x3);
xlabel('time');
ylabel('amplitude');
title('Sinusoidal signal with phase shift(DT)');

%GENERATION OF SINE WAVE FORM WITH PHASE SHIFT FOR CONTINUOUS


TIME
t10=0:0.1:1;
f=1;
A=5;
x4=A*sin((2*pi*f*t10)+pi);
subplot(2,2,3);
plot(t10,x4);
xlabel('time');
ylabel('amplitude');
title('Sinusoidal signal with phase shift(CT)');

D) TO GENERATE EXPONENTIAL SIGNAL:


figure(4);
%GENERATION OF INCREASING EXPONENTIAL SIGNAL FOR CONTINUOUS
TIME
t11=0:0.1:1;
b=3;
a=10;
x5=b*exp(a*t11);
subplot(2,2,1);
plot(t11,x5);
xlabel('time');
ylabel('amplitude');
title('Increasing Exponential signal in CT');

%GENERATION OF INCREASING EXPONENTIAL SIGNAL FOR DISCRETE TIME


t12=0:0.1:1;
b=3;
a=10;
x6=b*exp(a*t12);
subplot(2,2,2);
stem(t12,x6);
xlabel('time');
ylabel('amplitude');
title('Increasing Exponential signal in DT');

%GENERATION OF DECREASING EXPONENTIAL SIGNAL FOR CONTINUOUS


TIME
t13=0:0.1:1;
b=3;
a=-10;
x7=b*exp(a*t13);
subplot(2,2,3);
plot(t13,x7);
xlabel('time');
ylabel('amplitude');
title('Decreasing Exponential signal in CT');

%GENERATION OF DECREASING EXPONENTIAL SIGNAL FOR DISCRETE TIME


t14=0:0.1:1;
b=3;
a=-10;
x8=b*exp(a*t14);
subplot(2,2,4);
stem(t14,x8);
xlabel('time');
ylabel('amplitude');
title('Decreasing Exponential signal in DT');

E) TO PERFORM TIME SHIFTING, TIME SCALING, TIME REVERSAL &


AMPLITUDE SCALING:
figure(5)
%TIME SHIFTING(DELAY) IN DT
n3=0:4;
p=n3-2;
x11=[0 1 2 3 4];
subplot(2,2,1);
stem(p,x11);
xlabel('time');
ylabel('amplitude');
title('Time Shifting Delay in DT');

%TIME SHIFTING(ADVANCE) IN DT
n4=0:4;
q=n4+2;
x12=[0 1 2 3 4];
subplot(2,2,2);
stem(q,x12);
xlabel('time');
ylabel('amplitude');
title('Time Shifting Advance in DT');

%TIME REVERSAL IN DT
n1=2:7;
x9=[0 1 2 3 4 5];
subplot(2,2,3);
stem(-n1,x9);
xlabel('time');
ylabel('amplitude');
title('Time Reversal in DT');

%AMPLITUDE SCALING
n3=2:7;
x3=[0,1,2,3,4,5];
subplot(2,2,4);
stem(n3,2*x3);
xlabel('time');
ylabel('amplitude')
title( 'Amplitude scaling in DT');
MATLAB OUTPUTS
UNIT IMPULSE SIGNAL & UNIT STEP SIGNAL:

RAMP SIGNAL AND PARABOLIC SIGNAL:


SINUSOIDAL SIGNAL:

EXPONENTIAL SIGNAL:
TIME OPERATIONS AND AMPLITUDE SCALING:

SINE:
RESULT:

Thus, various signals were generated and its various operations were performed in
MATLAB was executed successfully.
Ex. No: 2
VERIFICATION OF SAMPLING THEOREM
DATE:

AIM:
To write a program in MATLAB to verify the sampling theorem.

SOFTWARE REQUIRED:

MATLAB software.
THEORY:

Sampling Theorem is a fundamental connecting bridge between continuous and


discrete signals. Sampling is the process of conversion of a continuous signal to a discrete signal.
A common example is the conversion of a sound wave which is a continuous signal to a sequence
of samples which is a discrete signal. The Nyquist Sampling theorem explains the relationship
between the sample rate and the frequency of the measured signal. It states that the sample rate fs
must be greater than or equal to twice the highest frequency component in the measured signal
i.e., fs ≥ 2fm,

where fs - Sampling frequency, fm – Highest Frequency Component of the signal.

The three important sampling processes are oversampling, under sampling and critical
sampling. Oversampling is the process of sampling a signal with a sampling frequency
significantly higher than the Nyquist rate. Theoretically, a bandwidth-limited signal can be
perfectly reconstructed if sampled above the Nyquist rate, which is twice the highest frequency in
the signal. Oversampling improves resolution, reduces noise, and helps avoid aliasing and phase
distortion. Under-sampling or bandpass, sampling is a technique where a band pass- filtered
signal is sampled at a sampling rate below its Nyquist rate, but still proper reconstruction of the
signal is possible. Critical sampling is the process of sampling exactly at the Nyquist rate.

1. fs = 2fm

2. fs < 2fm

3. fs > 2fm
PROGRAM:

MATLAB PROGRAM

clc;

clear all;

close all;

figure(1);

t=0:0.001:0.1;

a=10;

fm=25;

x=a*sin(2*pi*fm*t);

subplot(2,2,1);

plot(t,x);

xlabel('Time');

ylabel('Amplitude');

title('SINUSOIDAL SIGNAL');

% Case 1 fs<2fm

fs=5;

n=0:(1/fs):0.1;

x=a*sin(2*pi*fm*n);

subplot(2,2,2);

stem(n,x);

xlabel('Time');

ylabel('Amplitude');

title('fs<2fm');

% Case 2 fs=2fm

fs=50;

n=0:(1/fs):0.1;

x=a*sin(2*pi*fm*n);

subplot(2,2,3);

stem(n,x);
title('fs=2fm');

xlabel(‘Time’);

ylabel(‘Amplitude’);

% Case 3 fs>2fm

fs=300;

n=0:(1/fs):0.1;

x=a*sin(2*pi*fm*n);

subplot(2,2,4);

stem(n,x);

xlabel('Time');

ylabel('Amplitude');

MATLAB OUTPUT
RESULT:
Thus, the program to verify the sampling theorem using MATLAB software was
simulated and verified successfully.
Ex. No: 3
STABILITY OF A SYSTEM
Date:

AIM:

To write a program in MATLAB to generate the stability of the System.

SOFTWARE REQUIRED:

MATLAB software.

THEORY:

In signal processing, the impulse response function of a dynamic system is its output
when presented with a brief input signal. If the input x(n) is an impulse response then X(z)=1,
Y(z)=H(z). The transfer function is also defined as the z-transform of the impulse response of the
system. A system is bounded-input, bounded-output stable (BIBO stable) if, for every bounded
input, the output is finite. In the frequency domain, the region of convergence must contain the
imaginary axis s=jω. Stability is an important system property of LTI systems that defines the
input-output characteristics which in turn are used to design applications. Many systems design
applications depend on whether a system is stable or unstable. The necessary and sufficient
condition for stability is given as, 

 h(n)>
N = -
PROGRAM:
clc;
clear all;
close all;
b=input('Enter the Coefficient of numerator');
a=input('Enter the Coefficient of denominator);
[z p k]=tf2zp(b,a);
disp(p); zplane(p);
if(abs(p)<=1);
disp('The system is stable');else
disp('The system is unstable');
end;

22
MATLAB OUTPUT

Enter the Coefficient of numerator : [1 2 -15]


Enter the Coefficient of denominator : [1 1.25 0.375]
H(z) 15𝑍 −2 + 2𝑍 −1 + 1
=
0.375𝑍 −2 + 1.25𝑍 −1 + 1
P1 = -0.7500
P2 = -0.5000
The system is Stable

Enter the Coefficient of numerator : [1 -2 3]


Enter the Coefficient of denominator : [1 1 -2]
H(z) 3 𝑍 −2 + 2𝑍 −1 − 2
=
2 𝑍 −2 + 𝑍 −1 − 1
P1 = -2
P2 = 1
The system is Unstable

23
Enter the Coefficient of numerator : [1 2 4]
Enter the Coefficient of denominator: [0.5 0 0.5]
H(z) 4𝑍 −2 + 2𝑍 −1 + 1 2
=
0.5(𝑍 −2 + 1)
P1 = 0.0000 + 1.0000i
P2 = 0.0000 − 1.0000i

The system is Unstable

RESULT:
Thus, the program to check the stability of a system using MATLAB was simulated
and its output was verified.
24
Ex. No: 4
SYNTHESIS OF FOURIER SERIES
DATE:

AIM:

To write and execute a MATLAB Program for the reconstruction of the signal
represented by the Fourier series.
SOFTWARE REQUIRED:

MATLAB Software.

PROGRAM:

MATLAB PROGRAM

syms t real
N=input("Enter the number of harmonics:");
n_har=input("Enter harmonics as an array:");
t=-1:0.02:1;
for K=1:N
n=[];
n=1:2:n_har(K);
bn=2./(n*pi);
L=length(n);
W=2*pi;
X=0.5+bn*sin(W*n'*t);
subplot(N,1,K);
plot(t,X);
xlabel("t");
ylabel("reconstructed signal");
title("Fourier Series")
axis([-1,1,-0.5,1.5]);
end
MATLAB OUTPUT
Enter the number of harmonics: 2
Enter harmonics as an array: [1 3 2]
RESULT:
Thus, the MATLAB Program to reconstruct the following signal represented by the
Fourier series is executed successfully.
Ex. No: 5
FOURIER TRANSFORM AND INVERSE FOURIER TRANSFORM
DATE:

AIM:
To write a MATLAB program to find the Fourier transform and inverse Fourier
transform of the given signal.

SOFTWARE REQUIRED:
MATLAB Software.

PROGRAM:
MATLAB PROGRAM
%Inverse Fourier Transform:

MATLAB OUTPUT
FOURIER TRANSFORM:
x=
pi*dirac(1,w)*2i
y=
pi*dirac(w) – 1i/ws
=
A/(1+w*1i)t
=
-A*((sign(b)/2 – 1/2)*fourier(t*exp(-b*t), t, w) – 1/(b + w*1i)^2)c
=
pi*A*(dirac(0 + w) + dirac(0 – w))
INVERSE FOURIER TRANSFORM:
x=
(A*(exp(-0*x*1i) + exp(0*x*1i)))/2
y=
(A*(exp(-0*x*1i) – exp(0*x*1i))*1i)/2z
=
(A*exp(-x)*sign(x) + 1))/2
b=
(pi*exp(-x*3i)*sign(x)*5i – pi*exp(-x*4i)*sign(x)*2i)/(2*pi)
RESULT:
Thus, the MATLAB for Fourier transform and inverse Fourier transform was executed
successfully.
Ex. No: 6
SOLUTION TO DIFFERENTIAL EQUATION USING LAPLACE
DATE: TRANSFORM

AIM:
To write a MATLAB program to find the solution to a differential equation using Laplace
transform.
SOFTWARE REQUIRED:
MATLAB Software.

PROGRAM:

%SOLUTION TO DIFFERENTIAL EQUATIONS USING LAPLACE TRANSFORM


clc;
clear all;
close all;
syms s complex;
s=tf('s');
H=1/((s^2)+7*s+12);
t=0:0.01:10;
h=impulse(H,t)
plot(t,h);
xlabel("Time");
ylabel("Amplitude");
title("Solution to Differential Equations");
MATLAB OUTPUT

SOLUTION TO DIFFERENTIAL EQUATION USING LAPLACE EQUATION:

RESULT:
Thus, the MATLAB program to find the solution to the differential equation using
Laplace transform was executed successfully.
Ex. No: 7
SOLUTION TO DIFFERENCE EQUATION USING
DATE: Z-TRANSFORM

AIM:
To write a MATLAB program to find the solution to a difference equation using Z
transform.
SOFTWARE REQUIRED:
MATLAB software.

PROGRAM:
MATLAB PROGRAM:

%SOLUTION TO DIFFERENCE EQUATION USING Z-TRANSFORM

a=input("Enter the co-efficient of Numerator:");

b=input("Enter the co-efficient of Denominator: ");

n=0:10;

h=impulse(a,b,n);

plot(n,h);

xlabel("Time");

ylabel("Amplitude");

title("Solution Difference equation");


MATLAB OUTPUT

SOLUTION TO DIFFERENCE EQUATION USING Z -TRANSFORM

Enter the co-efficient of Numerator: [1 0 0]


Enter the co-efficient of Denominator: [1 10 16]
H(Z) = Z2
Z2 +10 Z + 16

RESULT:
Thus, the MATLAB program to find the solution to difference equation using Z
transform was executed successfully.
Ex. No: 8
CONVOLUTION AND CORRELATION
DATE:

AIM:
To write a MATLAB program to execute Linear Convolution,Circular Convolution, Cross
Correlation, and Auto Correlation.

SOFTWARE USED:
MATLAB software.

PROGRAM:
LINEAR CONVOLUTION:

MATLAB PROGRAM
CIRCULAR CONVOLUTION:

clc;
close all;
clear all;
x=input("Enter the sequence x(n):");
h=input("Enter the sequence h(n):");
N1=length(x);
N2=length(h);
N=N1+N2-1;
n1=input("Starting value for x(n):");
n2=input("Starting value for h(n):");

n=min(n1,n2);

n3=[n:n+N1-1];
Nm=max(N1,N2);
y=cconv(x,h,Nm);
disp(y);
stem(n3,y);

xlabel('n');

ylabel('y(n)');

title('Circular Convolution');

AUTO CORRELATION:

clc;
close all;
clear all;
x=input('Enter input sequence')
subplot(1,2,1);
stem(x); xlabel('n');

ylabel('x(n)');
title('input sequence');
z=xcorr(x,x);
disp(‘The values of z are = ‘);
disp(z);
subplot(1,2,2);
stem(z);
xlabel('n');
ylabel('z(n)');

title('auto correlation of input sequence');

CROSS CORRELATION:

clc;
clear all;
close all;
x = input('Enter the first sequence x(n) =');

y = input('Enter the second sequence y(n) =');

r = xcorr(x,y);

disp('Cross Correlation Output = ');


disp(r);
n1 = length(x)-1;
t1 = 0:n1;
subplot(2,2,1);

stem(t1,x);

xlabel('n');

ylabel('x(n)');

title('plot of x(n)');
n2 = length(y)-1;
t2 = 0:n2;
subplot(2,2,2);

stem(t2,y);

xlabel('n');

ylabel('y(n)');
title('plot of y(n)');
N = max(n1,n2);
k = -N:N;
subplot(2,1,2);
stem(k,r);
xlabel('n');
ylabel('r(n)');
title('cross correlation output');
MATLAB OUTPUT

LINEAR CONVOLUTION:
Enter the sequence x(n) :
[7 1 5 2]
Enter the sequence h(n):
[1 2 7 7]
Starting value for x(n) :
1
Starting value for h(n) :
1
7 15 56 68 46 49 14
CIRCULAR CONVOLUTION:
Enter the sequence x(n) :
[-1 1 2 5]
Enter the sequence h(n) :
[0 1 4 7]
Starting value for x(n) :
-7
Starting value for h(n) :
0
20 33 32 -1
CROSS CORRELATION:
Enter the first sequence x(n) =
[-1 0 1 5]
Enter the second sequence y(n) =
[-1 2 5 8]
Cross Correlation Output =
-8.0000 -5.0000 6.0000 46.0000 27.0000 9.0000 -5.0000
AUTO CORRELATION:
Enter input sequence :
[-1 5 6 7]
x=
-1 5 6 7
The values of z are =
-7 29 67 111 67 29 -7

RESULT:

Thus, the MATLAB program to execute Linear Convolution, Circular Convolution,


Cross Correlation, and Auto Correlation was executed successfully.
Ex. No: 9
DISCRETE FOURIER TRANSFORM AND INVERSE DISCRETE
DATE: FOURIER TRANSFORM

AIM:
To write MATLAB programs to find discrete Fourier transform and inverse discrete
Fourier transform.

SOFTWARE REQUIRED:
MATLAB software.

PROGRAM:
MATLAB PROGRAM
a) DISCRETE FOURIER TRANSFORM
clc;
close all;
clear all;
%Discrete Fourier Transform
figure(1)
x = input("Enter the sequence: ");
N = input("Enter the no. of samples: ");
X = fft(x,N)
n = 0:1:N-1;
subplot(2,1,1)
magx = abs(X)
stem(n,magx)
xlabel('n');
ylabel('magnitude');
title('Magnitude Plot');
subplot(2,1,2)
phasex = angle(X)
stem(n,phasex)
xlabel('n');
ylabel('phase angle');
title('Phase Plot');

b) INVERSE DISCRETE FOURIER TRANSFORM


clc;
close all;
clear all;
figure(1)
%Inverse Discrete Fourier Transform
x = input ("Enter the sequence: ");
N = input("Enter the no. of. Samples: ");
X = ifft(x,N)
n = 0:1:N-1;
subplot(2,1,1)
magx = abs(X)
stem(n,magx)
xlabel('n');
ylabel('magnitude');
title('Magnitude Plot’);
subplot(2,1,2)
phasex = angle(X)
stem(n,phasex)
xlabel('n');
ylabel('phase angle');
title('Phase Plot ');

70
MATLAB OUTPUT
a) DISCRETE FOURIER TRANSFORM
Enter the sequence: [-1 -2 2 3 5 7 1-2]
Enter the no. of samples: 8
X=
13.0000 + 0.0000i -15.8995 + 1.8284i 1.0000 - 4.0000i 3.8995 + 3.8284i 1.0000 +
0.0000i 3.8995 - 3.8284i 1.0000 + 4.0000i -15.8995 - 1.8284i
magx =
13.0000 14.5385 3.6056 7.6572 3.0000 7.6572 3.6056 14.5385
phasex =
0 3.0560 -0.5880 1.2402 3.1416 -1.2402 0.5880 -3.0560

71
b) INVERSE DISCRETE FOURIER TRANSFORM
Enter the sequence: [72.0000+0.0000i -8.0000+19.3137i -8.0000+8.0000i
-8.0000+3.3137i -8.0000+0.0000i -8.0000-3.3137i -8.0000-8.0000i
-8.0000-19.3137i]
Enter the no. of. Samples: 8
X=
2.0000 4.0000 6.0000 8.0000 10.0000 12.0000 14.0000 16.0000
magx =
1.0000 2.0000 2.0000 3.0000 5.0000 7.0000 1.0000 2.0000
phasex =
3.1416 3.1416 0 0 0 0 0 3.1416

72
RESULT:
Thus, the MATLAB to find discrete Fourier transform and Inverse Fourier transform
are executed and output obtained successfully.

73
Ex. No: 10
DESIGN OF DIGITAL FILTERS
DATE:

AIM:
To write MATLAB program to design IIR and FIR digital filters.
SOFTWARE REQUIRED:
MATLAB Software.
PROGRAM:
MATLAB PROGRAM

IIR FILTER PROGRAM


a) BUTTERWORTH LOW PASS FILTER:
clc;
clear all;
close all;
wp=input("Enter the value of pass band frequency:");
ws=input("Enter the value of stop band frequency:");
Ap=input("Enter the value of pass band attenuation:");
As=input("Enter the value of stop band attenuation:");
[N,Wn]=buttord(wp,ws,Ap,As);
[b,a]=butter(N,Wn);
w=0:0.01:pi;
H=freqz(b,a,w);
m=abs(H);
p=angle(H);
subplot(2,1,1);
plot(w/pi,m);
ylabel("|H|");
xlabel("Frequency");
title("magnitude");
subplot(2,1,2);
plot(w/pi,p);
ylabel("|H|");
xlabel("Frequency");
title("phase");
b) BUTTERWORTH HIGH PASS FILTER:
clc;
clear all;
close all;
wp=input("Enter the value of pass band frequency:");
ws=input("Enter the value of stop band frequency:");
Ap=input("Enter the value of pass band attenuation:");
As=input("Enter the value of stop band attenuation:");
[N,Wn]=buttord(wp,ws,Ap,As);
[b,a]=butter(N,Wn,'high');
w=0:0.01:pi;
H=freqz(b,a,w);
m=abs(H);
p=angle(H);
subplot(2,1,1);
plot(w/pi,m);
ylabel("|H|");
xlabel("Frequency");
title("magnitude");
subplot(2,1,2);
plot(w/pi,p);
ylabel("|H|");
xlabel("Frequency");
title("phase");

c) BUTTERWORTH BAND PASS FILTER:


clc;
clear all;
close all;
wp=input("Enter the value of pass band frequency:");
ws=input("Enter the value of stop band frequency:");
Ap=input("Enter the value of pass band attenuation:");
As=input("Enter the value of stop band attenuation:");
[N,Wn]=buttord(wp,ws,Ap,As);
[b,a]=butter(N,Wn);
w=0:0.01:pi;
H=freqz(b,a,w);
m=abs(H);
p=angle(H);
subplot(2,1,1);
plot(w/pi,m);
ylabel("|H|");
xlabel("Frequency");
title("magnitude");
subplot(2,1,2);
plot(w/pi,p);
ylabel("|H|");
xlabel("Frequency");
title("phase");

d) BUTTERWORTH BAND STOP FILTER:


clc;
clear all;
close all;
wp=input("Enter the value of pass band frequency:");
ws=input("Enter the value of stop band frequency:");
Ap=input("Enter the value of pass band attenuation:");
As=input("Enter the value of stop band attenuation:");
[N,Wn]=buttord(wp,ws,Ap,As);
[b,a]=butter(N,Wn,'stop');
w=0:0.01:pi;
H=freqz(b,a,w);
m=abs(H);
p=angle(H);
subplot(2,1,1);
plot(w/pi,m);
ylabel("|H|");
xlabel("Frequency");
title("magnitude");
subplot(2,1,2);
plot(w/pi,p);
ylabel("|H|");
xlabel("Frequency");
title("phase");

e) CHEBYSHEV LOW PASS FILTER:


clc;
clear all;
close all;
r=input("Enter ripple");
wp=input('Enter the value of pass band frequency:');
ws=input('Enter the value of stop band frequency:');
Ap=input('Enter the value of pass band attenuation:');
As=input('Enter the value of stop band attenuation:');
[N,Wn]=cheb1ord(wp,ws,Ap,As)
[b,a]=cheby1(N,r,Wn,'low');
w=0:0.01:pi;
H=freqz(b,a,w);
m=abs(H);
p=angle(H);
subplot(2,1,1);
plot(w/pi,m);
xlabel('Frequency');
ylabel('|H|');
title('Magnitude');
subplot(2,1,2);
plot(w/pi,p);
xlabel('Frequency');
ylabel('|H|');
title('Phase');
f) CHEBYSHEV HIGH PASS FILTER:
clc;
clear all;
close all;
r=input("Enter ripple");
wp=input('Enter the value of pass band frequency:');
ws=input('Enter the value of stop band frequency:');
Ap=input('Enter the value of pass band attenuation:');
As=input('Enter the value of stop band attenuation:');
[N,Wn]=cheb1ord(wp,ws,Ap,As);
[b,a]=cheby1(N,r,Wn,'high');
w=0:0.01:pi;
H=freqz(b,a,w);
m=abs(H);
p=angle(H);
subplot(2,1,1);
plot(w/pi,m);
xlabel('Frequency');
ylabel('|H|');
title('Magnitude');
subplot(2,1,2);
plot(w/pi,p);
xlabel('Frequency');
ylabel('|H|');
title('Phase');

g) CHEBYSHEV BAND PASS FILTER:


clc;
clear all;
close all;
r=input("Enter ripple");
wp=input('Enter the value of pass band frequency:');
ws=input('Enter the value of stop band frequency:');
Ap=input('Enter the value of pass band attenuation:');
As=input('Enter the value of stop band attenuation:');
[N,Wn]=cheb1ord(wp,ws,Ap,As);
[b,a]=cheby1(N,r,Wn);
w=0:0.01:pi;
H=freqz(b,a,w);
m=abs(H);
p=angle(H);
subplot(2,1,1);
plot(w/pi,m);
xlabel('Frequency');
ylabel('|H|');
title('Magnitude');
subplot(2,1,2);
plot(w/pi,p);
xlabel('Frequency');
ylabel('|H|');
title('Phase');

h) CHEBYSHEV BAND STOP FILTER:


clc;
clear all;
close all;
r=input("Enter ripple");
wp=input('Enter the value of pass band frequency:');
ws=input('Enter the value of stop band frequency:');
Ap=input('Enter the value of pass band attenuation:');
As=input('Enter the value of stop band attenuation:');
[N,Wn]=cheb1ord(wp,ws,Ap,As);
[b,a]=cheby1(N,r,Wn,'stop');
w=0:0.01:pi;
H=freqz(b,a,w);
m=abs(H);
p=angle(H);
subplot(2,1,1);
plot(w/pi,m);
xlabel('Frequency');
ylabel('|H|');
title('Magnitude');
subplot(2,1,2);
plot(w/pi,p);
xlabel('Frequency');
ylabel('|H|');
title('Phase');

FIR FILTER PROGRAM


a) LOW PASS FILTER USING RECTANGULAR WINDOW:
clc;
clear all;
close all;
N=input("Enter the order of the filter");
fp=input("Enter the pass band frequency");
fs=input("Enter the stop band frequency");
F=input("Enter the sampling frequency");
fn=2*fp/F;
window=boxcar(N+1);
b=fir1(N,fn,window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));
b=angle(h);
subplot(2,1,1);
plot(w/pi,a);
xlabel("Frequency in rad/sec");
ylabel("Gain in dB");
title("Magnitude plot Rectangular Window");
subplot(2,1,2);
plot(w/pi,b);
xlabel("Frequency in rad/sec");
ylabel("Gain in dB");
title("Phase plot Rectangular Window");

b) HIGH PASS FILTER USING BLACKMAN WINDOW:


clc;
clear all;
close all;
N=input("Enter the order of the filter");
fp=input("Enter the pass band frequency");
fs=input("Enter the stop band frequency");
F=input("Enter the sampling frequency");
fn=2*fp/F;
window=blackman(N+1);
b=fir1(N,fn,'high',window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));
b=angle(h);
figure;
subplot(2,1,1);
plot(w/pi,a);
xlabel("Frequency in rad/sec");
ylabel("Gain in dB");
title("Magnitude plot Blackman Window");
subplot(2,1,2);
plot(w/pi,b);
xlabel("Frequency in rad/sec");
ylabel("Gain in dB");
title("Phase plot Blackman Window");

c) BAND PASS FILTER USING HAMMING WINDOW:


clc;
clear all;
close all;
N=input("Enter the order of the filter");
fp=input("Enter the pass band frequency");
fs=input("Enter the stop band frequency");
F=input("Enter the sampling frequency");
fnp=2*fp/F;
fns=2*fs/F;
wp=[fnp fns]
window=hamming(N+1);
b=fir1(N,wp,window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));
b=angle(h);
subplot(2,1,1);
plot(w/pi,a);
xlabel("Frequency in rad/sec");
ylabel("Gain in dB");
title("Magnitude plot Hamming Window");
subplot(2,1,2);
plot(w/pi,b);
xlabel("Frequency in rad/sec");
ylabel("Gain in dB");
title("Phase plot Hamming Window");

d) BAND STOP FILTER USING HANNING WINDOW:


clc;
clear all;
close all;
N=input("Enter the order of the filter");
fp=input("Enter the pass band frequency");
fs=input("Enter the stop band frequency");
F=input("Enter the sampling frequency");
fnp=2*fp/F;
fns=2*fs/F;
wp=[fnp fns]
window=hanning(N+1);
b=fir1(N,wp,'stop',window);
w=0:0.001:pi;
[h,om]=freqz(b,1,w);
a=20*log10(abs(h));
b=angle(h);
subplot(2,1,1);
plot(w/pi,a);
xlabel("Frequency in rad/sec");
ylabel("Gain in dB");
title("Magnitude plot Hanning Window");
subplot(2,1,2);
plot(w/pi,b);
xlabel("Frequency in rad/sec");
ylabel("Gain in dB");
title("Phase plot Hanning Window");

MATLAB OUTPUT
IIR FILTER
a) BUTTERWORTH LOW PASS FILTER:
Enter the value of pass band frequency:
0.1*pi
Enter the value of stop band frequency:
0.3*pi
Enter the value of pass band attenuation:
2
Enter the value of stop band attenuation:
13
b) BUTTERWORTH HIGH PASS FILTER:
Enter the value of pass band frequency:
0.01*pi
Enter the value of stop band frequency:
0.2*pi
Enter the value of pass band attenuation:
2
Enter the value of stop band attenuation:
13
c) BUTTERWORTH BAND PASS FILTER:
Enter the value of pass band frequency:
[0.1*pi,0.2*pi]
Enter the value of stop band frequency:
[0.05*pi,0.3*pi]
Enter the value of pass band attenuation:
-2
Enter the value of stop band attenuation:
-13

d) BUTTERWORTH BAND STOP FILTER:


Enter the value of pass band frequency:
[0.1*pi,0.2*pi]
Enter the value of stop band frequency:
[0.05*pi,0.3*pi]
Enter the value of pass band attenuation:
-2
Enter the value of stop band attenuation:
-13
e) CHEBYSHEV LOW PASS FILTER:
Enter ripple
2
Enter the value of pass band frequency:
0.05*pi
Enter the value of stop band frequency:
0.25*pi
Enter the value of pass band attenuation:
55
Enter the value of stop band attenuation:
495
f) CHEBYSHEV HIGH PASS FILTER:
Enter ripple
1
Enter the value of pass band frequency:
0.07*pi
Enter the value of stop band frequency:
0.25*pi
Enter the value of pass band attenuation:
25
Enter the value of stop band attenuation:
400
g) CHEBYSHEV BAND PASS FILTER:
Enter ripple
1
Enter the value of pass band frequency:
[0.1*pi,0.27*pi]
Enter the value of stop band frequency:
[0.01*pi,0.3*pi]
Enter the value of pass band attenuation:
-25
Enter the value of stop band attenuation:
-250

h) CHEBYSHEV BAND STOP FILTER:


Enter ripple
1
Enter the value of pass band frequency:
[0.1*pi,0.27*pi]
Enter the value of stop band frequency:
[0.01*pi,0.3*pi]
Enter the value of pass band attenuation:
-25
Enter the value of stop band attenuation:
-250
FIR FILTER
a) LOW PASS FILTER USING RECTANGULAR WINDOW:
Enter the order of the filter
2
Enter the pass band frequency
5
Enter the stop band frequency
6
Enter the sampling frequency
4500
b) HIGH PASS FILTER USING BLACKMAN WINDOW:
Enter the order of the filter
6
Enter the pass band frequency
6
Enter the stop band frequency
0.53
Enter the sampling frequency
4000

c) BAND PASS FILTER USING HAMMING WINDOW:


Enter the order of the filter
12
Enter the pass band frequency
0.032
Enter the stop band frequency
0.063
Enter the sampling frequency
2000
wp =
1.0e-04 *
0.3200 0.6300

d) BAND STOP FILTER USING HANNING WINDOW:


Enter the order of the filter
14
Enter the pass band frequency
0.032
Enter the stop band frequency
0.063
Enter the sampling frequency
0.4
wp =
0.1600 0.3150
RESULT:
Thus, the FIR and IIR digital filters are designed, executed and the output was
verified.
Ex. No: 11
GENERATION OF DTMF SIGNALS
DATE:

AIM:
To generate DTMF signals using MATLAB Software.

SOFTWARE REQUIRED:
MATLAB Software.

THEORY:
The DTMF stands for "Dual Tone Multi Frequency", and is a method of
representing digits with tone frequencies, in order to transmit them over an analog
communications network, for example a telephone line. In telephone networks, DTMF
signals are used to encode dial trains and other information. Dual-tone Multi-Frequency
(DTMF) signaling is the basis for voice communications control and is widely used
worldwide in modern telephony to dial numbers and configure switchboards. It is also used in
systems such as in voice mail, electronic mail and telephone banking. A DTMF signal
consists of the sum of two sinusoids - or tones - with frequencies taken from two mutually
exclusive groups. These frequencies were chosen to prevent any harmonics from being
incorrectly detected by the receiver as some other DTMF frequency. Each pair of tones
contains one frequency of the low group (697 Hz, 770 Hz, 852 Hz, 941 Hz) and one
frequency of the high group (1209 Hz, 1336 Hz, 1477Hz) and represents a unique symbol.
1209Hz 1336Hz 1477Hz

697Hz 1 2 3

770Hz 4 5 6

852Hz 7 8 9

941Hz * 0 #
PROGRAM:
clc;
close all;
clear all;
t=-2:0.05:2;
x=input("enter the input number:");
fr1=697;
fr2=770;
fr3=852;
fr4=941;
fc1=1209;
fc2=1336;
fc3=1477;
fc4=1633;
y0=sin(2*pi*fr4*t)+sin(2*pi*fc2*t);%0
y1=sin(2*pi*fr1*t)+sin(2*pi*fc1*t);%1
y2=sin(2*pi*fr1*t)+sin(2*pi*fc2*t);%2
y3=sin(2*pi*fr1*t)+sin(2*pi*fc3*t);%3
y4=sin(2*pi*fr2*t)+sin(2*pi*fc1*t);%4
y5=sin(2*pi*fr2*t)+sin(2*pi*fc2*t);%5
y6=sin(2*pi*fr2*t)+sin(2*pi*fc3*t);%6
y7=sin(2*pi*fr3*t)+sin(2*pi*fc1*t);%7
y8=sin(2*pi*fr3*t)+sin(2*pi*fc2*t);%8
y9=sin(2*pi*fr3*t)+sin(2*pi*fc3*t);%9
y_start=sin(2*pi*fr4*t)+sin(2*pi*fc1*t);%*
y_canc=sin(2*pi*fr4*t)+sin(2*pi*fc3*t);%#
if(x==1)
plot(t,y1)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x==2)
plot(t,y2)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x==3)
plot(t,y3)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x==4)
plot(t,y4)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x==5)
plot(t,y5)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x==6)
plot(t,y6)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x==7)
plot(t,y7)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x==8)
plot(t,y8)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x==9)
plot(t,y9)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x==0)
plot(t,y0)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x=='*')
plot(t,y_start)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
elseif(x=='#')
plot(t,y_canc)
xlabel('time(t)')
ylabel('amplitude')
title('Dual Tone Multi Frequency')
else
disp('Enter the correct input')
end
MATLAB OUTPUT
enter the input number:
7

RESULT:
Thus, the DTMF Signals for various frequencies were generated using MATLAB
Software.
EX:NO: 12
NOISE REMOVAL IN A SIGNAL
DATE:

AIM:

To write a MATLAB program to perform filtering of signal.

SOFTWARE REQURIED:

MATLAB Software.

ALGORITHM:

1. Start the program


2. Get the sample interval
3. Find cosine signal1 and signal2
4. Add the 2 signals
5. Filtering using function
6. Plot the waveform
7. Stop the program

PROGRAM:

clc;
clear all;
close all;
n=0:299;
x1=cos(2*pi*10*n/256);
x2=cos(2*pi*100*n/256);
x=x1+x2;
num1=[0.5 0.27 0.77];
y1=filter(num1,1,x);
num2=[0.45 0.5 0.45];
den2=[1 -0.53 0.46];
y2=filter(num2,den2,x);
subplot(3,1,1);
plot(n,x);
title ('Input of system');
xlabel('Time');
ylabel('Amplitude in volt');
subplot(3,1,2);
plot(n,y1);
axis([0 300 -2 2]);
title ('Output of system');
xlabel('Time');
ylabel('Amplitude in volt');
subplot(3,1,3);
plot(n,y2);
axis([0 300 -2 2]);
title('Output of system');
xlabel('Time');
ylabel('Amplitude');
OUTPUT:

RESULT:

Thus, the MATLAB program to perform filtering of a signal was executed


successfully and output was verified.
CONTENT BEYOND SYLLABUS
EX:NO:
IMPLEMENTATION OF DECIMATION AND

DATE: INTERPOLATION PROCESS

AIM:
To write a program to verify the decimation and interpolation of given sequence.

SOFTWARE REQUIRED:
MATLAB Software.

THEORY:
“Decimation” is the process of reducing the sampling rate. “Down sampling” is a more
specific term which refers to just the process of throwing away samples, without the lowpass
filtering operation. The most immediate reason to decimate is simply to reduce the sampling rate
at the output of one system so a system operating at a lower sampling rate can input the signal.
But a much more common motivation for decimation is to reduce the cost of processing: the
calculation and/or memory required to implement a DSP system generally is proportional to the
sampling rate, so the use of a lower sampling rate usually results in a cheaper implementation.

ALGORITHM:
Step I: Define down sampling factor and input frequencies f1 and f2
Step II: Represent input sequence with frequencies f1 and f2
Step III: Perform the decimation on input signal using MATLAB command decimate
Step IV: Plot the input and output sequence

PROGRAM:
Clc;
Clear all;
Close all;
D=input('enter the down sampling factor');
L=input('enter the length of the input signal');
f1=input('enter the frequency of first sinusoidal');
f2=input('enter the frequency of second sinusoidal');
n=0:L-1;
x=sin(2*pi*f1*n)+sin(2*pi*f2*n);
y=decimate(x,D,'fir');
subplot(2,1,1);
stem(n,x(1:L));
title('input sequence');
xlabel('time(n)');
ylabel('amplitude');
subplot(2,1,2) m=0:(L/D)-1;
stem(m,y(1:L/D));
title('Decimated sequence');
xlabel('time(n)');
ylabel('amplitude');

INPUT:
enter the down sampling factor = 5
enter the length of the input signal = 100
enter the frequency of first sinusoidal = 0.01
enter the frequency of second sinusoidal = 0.03
INTERPOLATION PROCESS:

THEORY:

“Up sampling” is the process of inserting zero-valued samples between original


samples to increase the sampling rate. (This is called “zero-stuffing”.) “Interpolation”, is the
process of up sampling followed by filtering. The filtering removes the undesired spectral
images. The primary reason to interpolate is simply to increase the sampling rate at the output of
one system so that another system operating at a higher sampling rate can input the signal.

ALGORITHM:
Step I: Define down sampling factor and input frequencies f1 and f2
Step II: Represent input sequence with frequencies f1 and f2
Step III: Perform the decimation on input signal using MATLAB command decimate
Step IV: Plot the input and output sequence

PROGRAM:
Clc;
Clear all;
Close all;
L=input('enter the upsampling factor');
N=input('enter the length of the input signal'); % Length should be greater than 8
f1=input('enter the frequency of first sinusodal');
f2=input('enter the frequency of second sinusodal');
n=0:N-1;
x=sin(2*pi*f1*n)+sin(2*pi*f2*n);
y=interp(x,L);
subplot(2,1,1)
stem(n,x(1:N)) title('input sequence');
xlabel('time(n)');
ylabel('amplitude');
subplot(2,1,2)
m=0:N*L-1;
stem(m,y(1:N*L))
title('output sequence ');
xlabel('time(n)');
ylabel('amplitude');

INPUT:
enter the up sampling factor = 5
enter the length of the input signal = 9
enter the frequency of first sinusoidal = 0.1
enter the frequency of second sinusoidal = 0.3

RESULT:

Thus, the MATLAB program for Decimation and Interpolation is performed and executed
successfully.

You might also like