DSP Exp 1-2-3 - Antrikshpdf - Removed

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

Digital Signal Processing

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 :

MATLAB (MATRIX LABORATORY):


MATLAB is a software package for high-performance language for technical computing. It
integrates computation, visualization, and programming in an easy-to-use environment where
problems and solutions are expressed in familiar mathematical notation. Typical uses include
the following
 Math and computation
 Algorithm development
 Data acquisition
 Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization
 Scientific and engineering graphics
 Application development, including graphical user interface building

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.

MATLAB features a family of add-on application-specific solutions called toolboxes. Very


important to most users of MATLAB, toolboxes allow learning and applying specialized
technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend
the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are
available include Image processing, signal processing, control systems, neural networks, fuzzy
logic, wavelets, simulation, and many others.
Features of MATLAB
1. Advance algorithm for high performance numerical computation ,especially in the
Field matrix algebra

2. A large collection of predefined mathematical functions and the ability to define one’s own
functions.

3. Two-and three dimensional graphics for plotting and displaying data


4. A complete online help system
5. Powerful, matrix or vector oriented high level programming language for individual
applications.
6. Toolboxes available for solving advanced problems in several application areas

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.

MATLAB [1] is a high-performance language for technical computing. It integrates


computation, visualization and programming environment. Furthermore, MATLAB is a modern
programming language environment: it has sophisticated data structures contains built-in
editing and debugging tools , and supports object-oriented programming These factors make
MATLAB an excellent tool for teaching and research. MATLAB has many advantages compared
to conventional computer languages (e.g., C, FORTRAN) for solving technical problems. MATLAB
is an interactive system whose basic data element is an array that does not require
dimensioning. The software package has been commercially available since 1984 and is now
considered as a standard tool at most universities and industries worldwide.

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:

• The Command Window


• The Command History
• The Workspace
• The Current Directory
• The Help Browser
• The Start button

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

>> look for inverse


Note - At this particular time of our study, it is important to emphasize one main point. Because
MATLAB is a huge program; it is impossible to cover al l the details of each function one by one.
However, we will give you information how to get help. Here are some examples

• Use on-line help to request info on a specific function


>> help sqrt
• In the current version (MATLAB version 7), the doc function opens the on-line version of the
help manual. This is very helpful for more complex commands
>> doc plot
• Use look for to find functions by keywords. The general form is
>> look for Function Name

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.

A unit step function is defined mathematically as

The Laplace transform of the unit step function is


MATLAB Code :
clc;
clear all;
close all;

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.

The Laplace transform of the unit impulse function is

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");

d) Exponential function: An exponential function is a mathematical


function, which is used in many real-world situations. It is mainly used to
find the exponential decay or exponential growth or to compute
investments, model populations and so on.

The following figure represents the graph of exponents of x. It can be


seen that as the exponent increases, the curves get steeper and the
rate of growth increases respectively. Thus, for x > 1, the value of y = f n(x)
increases for increasing values of (n).
From the above, it can be seen that the nature of polynomial functions
is dependent on their degree. The higher the degree of any polynomial
function, the higher its growth. A function which grows faster than a
polynomial function is y = f(x) = ax, where a>1. Thus, for any of the
positive integers n the function f (x) is said to grow faster than that of
fn(x).

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.

It must be noted that the exponential function is increasing and the


point (0, 1) always lies on the graph of an exponential function. Also, it is
very close to zero if the value of x is mostly negative.

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.

The basic mathematical definition of convolution is the integral over all


space of one function at x multiplied another function at u-x, taken with
respect to x. It should be noted that x can represent anything including
time, frequency, or even three dimensional space, depending on the
application. It should also be noted that the convolution results in a
function of a new variable u, which will represent the same domain as
the original variable. Convolution is typically represented as a circle
with a cross in the center, as follows:
  f (x) g(x) = f (x) g(u −x) = g(x)f (u −x)
MATLAB Code :
clc;
close all;
clear all;

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');

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy