DSP LAB File 20bec095
DSP LAB File 20bec095
DSP LAB File 20bec095
(EC-317)
B. Tech 5th Semester: Academic Year 2022-23
Submitted by : GOURAV
To
Index
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
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
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:
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.