DSP Exp 1-2-3 - Antrikshpdf - Removed
DSP Exp 1-2-3 - Antrikshpdf - Removed
DSP Exp 1-2-3 - Antrikshpdf - Removed
Lab File
Submitted By:
Name: Antriksh
Roll No: 21BEC023
Submitted To:
Dr. Aman Kumar
Department :
Electronics and Communication
Engineering
INDEX :
S. No. Experiment Date Remarks
INDEX :
S. No. Experiment Date Remarks
INTRODUCTION TO MATLAB :
The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide
easy access to matrix software developed by the LINPACK and EISPACK projects. Today, MATLAB
engines incorporate the LAPACK and BLAS libraries, embedding the state of the art in software
for matrix computation.
MATLAB has evolved over a period of years with input from many users. In university
environments, it is the standard instructional tool for introductory and advanced courses in
mathematics, engineering, and science. In industry, MATLAB is the tool of choice for high-
productivity research, development, and analysis.
2. A large collection of predefined mathematical functions and the ability to define one’s own
functions.
The name MATLAB stands for MATrix LABoratory. MATLAB was written originally to
provide easy access to matrix software developed by the LINPACK (linear system package) and
EISPACK (Eigen system package) projects.
It has powerful built-in routines that enable a very wide variety of computations. It also has
easy to use graphics commands that make the visualization of results immediately available.
Specific applications are collected in packages referred to as toolbox. There are toolboxes for
signal processing, symbolic computation, control theory, simulation, optimization, and several
other fields of applied science and engineering.
Figure 1.1: The graphical interface to the MATLAB workspace
Starting MATLAB
After logging into your account, you can enter MATLAB by double-clicking on the MATLAB
shortcut icon (MATLAB 7.0.4) on your Windows desktop. When you start MATLAB, a special
window called the MATLAB desktop appears. The desktop is a window that contains other
windows. The major tools within or accessible from the desktop are:
When MATLAB is started for the first time, the screen looks like the one that shown in
the Figure 1.1. This illustration also shows the default configuration of the MATLAB desktop. You
can customize the arrangement of tools and documents to suit your needs.
Now, we are interested in doing some simple calculations. We will assume that you have
sufficient understanding of your computer under which MATLAB is being run. You are now faced
with the MATLAB desktop on your computer, which contains the prompt (>>) in the Command
Window. Usually, there are 2 types of prompt:
Getting started
MATLAB variables are created with an assignment statement. The syntax of variable assignment
is variable name = a value (or an expression)
For example,
>> x = expression
Where expression is a combination of numerical values, mathematical operators, variables,
and function calls. On other words, expression can involve:
• manual entry
• built-in functions
• user-defined functions
Managing the workspace
The contents of the workspace persist between the executions of separate commands.
There- fore, it is possible for the results of one problem to have anent on the next one. To avoid
this possibility, it is a good idea to issue a clear command at the start of each new independent
calculation
>> clear
The command clear or clear all removes all variables from the workspace. This frees up system
memory. In order to display a list of the variables currently in the memory type >> who
While, whos will give more details which include size, space allocation, and class of the
variables
Getting help
To view the online documentation, select MATLAB Help from Help menu or MATLAB
Help directly in the Command Window. The preferred method is to use the Help
Browser. The Help Browser can be started by selecting the? icon from the desktop toolbar.
On the other hand, information about any command is available by typing
>> help Command
Another way to get help is to use the look for command. The help command searches for an
exact function name match, while the look for command searches the quick summary
information in each function for a match. For example, suppose that we were looking for a
function to take the inverse of a matrix. Since MATLAB does not have a function named inverse,
the command help inverse will produce nothing. On the other hand, the command look for
inverse will produce detailed information, which includes the function of interest, inv
PROCEDURE :
• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
• For the output see command window\ Figure window
EXPERIMENT - 1:
AIM :
Generation of basic continuous and discrete signal
EQUIPMENT:
• PC with operating system
• MATLAB Software
THEORY :
a) Unit step function: This function has already been discussed in the
preceding It is defined as one that has magnitude of one for time greater
than zero, and has zero magnitude for time less than zero.
n=-1:0.05:1;
an=zeros(1,length(n));
for i=1:length(n)
if n(i)<0
an(i)=0;
else
an(i)=1;
end
end
stem(n,an);
title("unit step");
(b) Unit ramp function: If the unit step function is integrated with
respect to time t, then the unit ramp function results. It is symbolized by
r(t). A unit ramp function increases linearly with time. A unit ramp
functions may be defined mathematically
as
The Laplace transform of the unit ramp function is
MATLAB Code :
clc;
clear all;
close all;
n=-1:0.05:1;
bn=zeros(1,length(n));
for i=1:length(n)
if n(i)<0
bn(i)=0;
else
bn(i)=n(i);
end
end
stem(n,bn);
title("ramp signal");
c) Unit impulse function: If a unit step function u(t) is differentiated with
respect to t, the derivative is zero for time t greater than zero, and is
infinite for time t equal to zero. Mathematically, the function is defined as
and
where the symbol δ(t) (delta) is used to represent the unit impulse. An
impulse of unity amplitude occurring at it t = 0 gives that it has an area
‘δ’ equal to unity.
Therefore,
MATLAB Code :
clc;
clear all;
close all;
n=-1:0.05:1;
xn=zeros(1,length(n));
for i=1:length(n)
if n(i)==0
xn(i)=1;
end
end
stem (n,xn);
title("unit impulse");
Thus, the exponential function having base greater than 1, i.e., a > 1 is
defined as y = f(x) = ax. The domain of exponential function will be the
set of entire real numbers R and the range are said to be the set of all
the positive real numbers.
MATLAB Code :
clc;
clear all;
close all;
n=-1:0.05:1;
x_n=(2).^(2*n);
stem(n,x_n);
title('Exponential Signal');
e) Sinusoidal function: A sine wave or sinusoidal wave is the most
natural representation of how many things in nature change state. A
sine wave shows how the amplitude of a variable changes with time.
The variable could be audible sound for example. A single pure note is a
sine wave, although it would sound a very plain and flat note indeed
with none of the harmonics we normally hear in nature.
A straightforward oscillating or alternating current or voltage within
a wire can also be represented by a sine wave. The number of times the
sine wave goes through a complete cycle in the space of 1 second is
called the frequency. Indeed the unit used to be cycles per second, but
now the unit of measurement is hertz (Hz).
A frequency of 1000Hz, or 1 kHz, means that the sine wave goes
through 1000 complete cycles in 1 s. If we are considering audible sound
waves then the human ear has a frequency range of about 20Hz-20kHz.
The electrical mains frequency in Europe is 50Hz and 60Hz in
MATLAB Code :
clc;
clear all;
close all;
n =0:0.01:5;
fi=2;
X=sin(2*pi*fi*n);
stem(n,X);
title('Sine function');
f) Cosinusoidal function: The cosine graph or the cos graph is an up-
down graph just like the sine graph. The only difference between the
sine graph and the cos graph is that the sine graph starts from 0 while
the cos graph starts from 90 (or π/2). The cos graph given below starts
from 1 and falls till -1 and then starts rising again.
MATLAB Code :
clc;
clear all;
close all;
n =0:0.01:5;
fi=2;
X=cos(2*pi*fi*n);
stem(n,X);
title('Cosine function');
EXPERIMENT - 2:
AIM :
To write a MATLAB program to find the linear convolution of
two discrete signals
EQUIPMENT:
• PC with operating system
• MATLAB Software
THEORY :
When dealing with dynamic measurements and digital signals, one of
the most important mathematical theorems next to the Fourier
transformation is the convolution integral. The convolution integral is, in
fact, directly related to the Fourier transform, and relies on a
mathematical property of it. It is because of this property that makes
the convolution integral often very convenient to use and has a wide
variety of uses in many different fields and applications.
x = [1, 2, 3];
h = [4, 5, 6];
M = length(x);
N = length(h);
y = zeros(1, M + N - 1);
for n = 1:M + N - 1
y(n) = 0;
for k = max(1, n - N + 1):min(M, n)
y(n) = y(n) + x(k) * h(n - k + 1);
end
end
subplot(3,1,1);
stem(x);
display('Input Signal x = [1, 2, 3]')
disp(x);
title('Signal: x = [1, 2, 3]');
subplot(3,1,2);
stem(h);
display('Input Signal y = [4, 5, 6]')
disp(h);
title('Signal y = [4, 5, 6]');
subplot(3,1,3);
stem(y);
display('Convoluted Signal:');
disp(y);
title('Convoluted Signal');