DSP LAB File 20bec095

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

DIGITAL SIGNAL PROCESSING LAB

(EC-317)
B. Tech 5th Semester: Academic Year 2022-23

Submitted by : GOURAV

Roll No. : 20BEC095


Electronics & Communication and engineering
Semester: 5TH

To

Dr. Abhijit Bhattacharyya


Assistant Professor
E&CE Department

Index

S. No. Experiment Date Page Remarks

1. Introduction to MATLAB

Experiment -1
2.
Plotting Elementary functions

Experiment-2
3.
Sine and Cosine Wave Generation

Experiment-3
4
Sine wave with two harmonics and noise
Experiment-4
5
Sampling of sine wave

Experiment-5
6
Linear Convolution of two sequences
using built-in function

Experiment-6
7
Convolution of two sequences without
using built-in function

INTRODUCTION TO MATLAB

MATLAB is a software for a high-performance


language for technical computation. In a simple-to-
use interface, it mixes computation, modeling, and
programming while expressing issues and solutions
using well-known mathematical notation. Some typical
applications are:

 Mathematical operation and computation


 Creating Algorithm
 Data acquisition
 Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization
 Scientific and engineering graphics
 Application development, including graphical user
interface building

Needless to say, MATLAB is highly useful


for engineers and scientists in almost any field.
MATLAB stands for Matrix Laboratory. The original
purpose of MATLAB was to make it simple to access
the matrix software. The LAPACK and BLAS libraries
are now incorporated into MATLAB engines, making
matrix computation software state-of-the-art.

Toolboxes are a group of MATLAB's add-on,


application-specific solutions. They are crucial for
the majority of MATLAB users since they enable
learning and using special technologies. Toolboxes
are extensive MATLAB function collections (M-files)
that expand the MATLAB environment to address
certain problem types. Image processing, signal
processing, control systems, neural networks, fuzzy
logic, wavelets, simulation, and many other fields
are among the fields where toolboxes are offered.

The main features of MATLAB


1.A new high-performance numerical calculation
algorithm, particularly for matrix algebra
2.A substantial library of mathematical functions
that have already been defined as well as the
capability of creating one's own functions.
3.Plotting and displaying data using two- and
three-dimensional graphics
4.A high-level programming language for specific
applications that is matrix- or vector-oriented.
5.A substantial library of mathematical functions
that have already been defined as well as the
capability of creating one's own functions.

Common Procedure to all Programs in MATLAB

1. Click on the MATLAB Icon on the desktop.

2. MATLAB window open.

3. Click on the ‘FILE’ Menu on the menu bar.

4. Click on NEW M-File from the File Menu.

5. An editor window opens and starts typing


commands.

6. Now SAVE the file in the directory.

7. Then Click on DEBUG from the Menu bar and Click


Run.
Experiment: 1
Plotting Elementary Functions
Aim: To generate commonly used functions – Unit step, Ramp, Unit
Impulse, Exponential, Sine and Cosine function.
EQUIPMENT:
 PC with Windows/MacOS
 MATLAB Software

Theory:
Unit Step, Unit Impulse, Ramp, Exponential, Sine and Cosine signals are
often used signals in signal processing to accomplish various operations.
Generating Basic Discrete-Time Signals for Discrete-Time Signal
Processing.
Unit step signal: A signal with magnitude one for time greater than
zero We can assume it as a dc signal which got switched on at time
equal to zero.
u[n−a]= {0 ,∧otherwise
1 , n>a

Unit impulse signal: A signal which has unit magnitude at time equal to
zero only. We can assume it as a lightning pulse which acts for a short
duration with unit magnitude of voltage.
ð ( a )=
{0 ,∧otherwise
1 ,∧n=a

Ramp signal: A signal whose magnitude increases same as time It can


be obtained by integrating unit step.
r ( n) = {0 ,∧otherwise
n ,∧n=0

Exponential signal: The 'exponential" signal literally represents an


exponentially increasing or falling series:
x (n)=ean u(n)
Sine signal: The sine signal is the sinusoidal sine signal but in discrete
time.
x ( t )=sin (t)
Cosine signal: The cosine signal is also like the sine signal the discrete
time equivalent of the continuous cosine signal.
x ( t )=cos(t)

Program:
%1. BASIC SIGNALS

clc;
close all;
n=-50:0.1:50;
l1=length(n);
t=0:0.1:2*pi;

%Unit Impulse
for i=1:l1
if(n(i)==0)
x(i)=1;
else
x(i)=0;
end
end
subplot(2,3,1);
plot(n,x);
xlabel("n");
ylabel("x(n)");
title("Unit Impulse");

%Unit Step
for i=1:l1
if(n(i)<0)
x(i)=0;
else
x(i)=1;
end
end
subplot(2,3,2);
plot(n,x,'g');
xlabel("n");
ylabel("x(n)");
title("Unit Step");

%Unit Ramp
for i=1:l1
if(n(i)>=0)
x(i)=n(i);
else
x(i)=0;
end
end
subplot(2,3,3);
plot(n,x,'r');
xlabel("n");
ylabel("x(n)");
title("Ramp function");

%Exponential
subplot(2,3,4);
a=0:0.1:5;
plot(a,exp(a),'b');
xlabel("t");
ylabel("x(t)");
title("Exponential Signal");

%Sine Function
subplot(2,3,5);
plot(t,sin(t),'c');
xlabel("t");
ylabel("x(t)");
title("Sine Signal");

%Cosine Function
subplot(2,3,6);
plot(t,cos(t),'m');
xlabel("t");
ylabel("x(t)");
title("Cosine Signal");
Result:

Conclusion:
In this experiment, elementary discrete functions have been plotted using
MATLAB software.

Experiment: 2
Sine and Cosine Wave Generation
Aim: To generate sine and cosine waves.
EQUIPMENT:
 MATLAB Software
Theory: Sine and cosine waves are signal waveforms which are identical to
each other. The main difference between the two is that cosine wave leads
the sine wave by an amount of 90 degrees.
A sine wave depicts a reoccurring change or motion. It is known as sine wave
as it has the similar shape as the sine function, when it is plotted on a graph.
The graph shows the repetition of one wave segment in a repeated manner.

Program:
%Sine and cos wave generation
clc;
x=-2*pi:pi/20:2*pi;
y=sin(x);
subplot(2,1,1);
plot(x,y);
grid;
axis([-pi,pi,-1,1]);
xlabel('time');
ylabel('amplitude');
title('sine wave generation');
y1=cos(x);
subplot(2,1,2);
plot(x,y1);
grid;
axis([-pi,pi,-1,1]);
xlabel('time');
ylabel('amplitude');
title('cos wave generation');
Result:

Conclusion:
In this experiment, sine and cosine wave have been generated.

Experiment: 3
Sine wave with two harmonics and noise
Aim: To generate sine wave with two harmonics and noise
EQUIPMENT:
 PC with Windows/MacOS
 MATLAB Software
Program:
%sine wave with 2 harmonics and noise
clc;
fs=1000;
ts=1/fs;
t=0:ts:1;
x=10*sin(2*pi*10*t)+10*sin(2*pi*2*10*t);
plot(t,x);
grid;
xlabel('time');
ylabel('amplitude');
title('sine wave with 2 harmonics');
grid;
x1=x+randn(size(t));
figure;
plot(t,x1);
grid;
xlabel('time');
ylabel('amplitude');
title('sine wave with noise');
figure;
plot(t,x,t,x1);
grid;
xlabel('time');
ylabel('amplitude');
legend('sin wave with harmonics','sine wave with noise');

Result:
Figure 1:
Figure 2:

Figure 3:
Conclusion:
In this experiment sine wave has been produced with two harmonics and
noise.
Experiment: 4
Sampling of Sine wave
Aim: To generate sine wave with two harmonics and noise
EQUIPMENT:
 PC with Windows/MacOS
 MATLAB Software
Theory:

A harmonic is one of an ascending series of sonic components that


sound above the audible fundamental frequency. Harmonics are integer
multiples of the fundamental frequency. For example, if the fundamental
frequency is 50 Hz (also known as the first harmonic) then the second
harmonic will be 100 Hz (50 * 2 = 100 Hz), the third harmonic will be 150
Hz (50 * 3 = 150 Hz), and so on.

Program:
%sine wave with sampling frequency
clc;
fs=1000;
ts=1/fs;
t=0:ts:1;
y=10*sin(2*pi*10*t);
plot(t,y);
figure;
stem(t,y);
grid;
xlabel('time');
ylabel('amplitude');
title('sine wave with sampling frequency');
axis([0 0.1 10 -10]);

Result:
Figure 1:
Figure 2:
Conclusion:
In this experiment, sine wave has been generated with two harmonics
and noise.

Experiment: 5
Linear Convolution of two sequences using built-in function
Aim: To display Linear convolution sequences using built-in function.
EQUIPMENT:
 PC with Windows/MacOS
 MATLAB Software
Theory:
Linear Convolution: Linear Convolution is an operation by which one may
relate the output and input of an LTI system given the system’s impulse
response. Clearly, it is required to convolve the input signal with the
impulse response of the system. 
y(t)= h(t)*x(t)
For convolution, we use conv() function.

Program:

clc;
close all;
clear all;
x1=input('enter the 1st sequence');
x2=input('enter the 2nd sequence');
l1=length(x1);
l2=length(x2);
if(l1<l2)
X1=[x1,zeros(1,l2-l1)];
X2=x2;
else
X2=[x2,zeros(1,l1-l2)];
X1=x1;
end
c=conv(X1,X2);
stem(c);
title('convolution of two sequences');
xlabel('n');
ylabel('y(n)');
Result:

Conclusion:
In this experiment convolution of two sequences has been performed
using MATLAB software.
Experiment: 6
Convolution of two sequences without using function
Aim: To display convolution of two sequence without using function.
EQUIPMENT:
 PC with Windows/MacOS
 MATLAB Software
Theory:
Once again, convolution has been performed. However, this time we don’t
use the function provided by MATLAB. Rather a function of own has been
developed for performing linear convolution.

Program:
%Convolution of two sequences (w/o using direct function)
clc;
close all;
X1=input('Enter the 1st sequence');
X2=input('Enter the 2nd sequence');
l1=length(x1);
l2=length(x2);
if(l1<l2)
X1=[x1,zeros(1,l2-l1)];
X2=x2;
m=l2;
end
if(l1>=l2)
X2=[x2,zeros(1,l2-l1)];
X1=x1;
m=l1;
end
l=l1+l2;
y=zeros(1,1);
for (n=1:l)
for (k=1:l1)
if((n-k+1)>0&&(n-k+1)<=m)
y(n)=X1(k).*X2(n-k+1);
end
end
end
stem(y,'r');
title('Convolution of two sequence');
xlabel('n');
ylabel('y(n)');

Result:

Conclusion:
In this experiment convolution of two sequences has been performed
without using function.

You might also like