0% found this document useful (0 votes)
68 views12 pages

DSP - Manual Part

This document provides instructions for an experiment in MATLAB to generate various discrete-time signals including the unit impulse, unit step, sine, cosine, ramp, and exponential signals. It explains that discrete-time signals are represented as sequences of samples denoted by x[n]. The experiment teaches how to generate both finite-length and infinite-length sequences representing these basic signals in the time domain using MATLAB.

Uploaded by

Shivani Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views12 pages

DSP - Manual Part

This document provides instructions for an experiment in MATLAB to generate various discrete-time signals including the unit impulse, unit step, sine, cosine, ramp, and exponential signals. It explains that discrete-time signals are represented as sequences of samples denoted by x[n]. The experiment teaches how to generate both finite-length and infinite-length sequences representing these basic signals in the time domain using MATLAB.

Uploaded by

Shivani Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

JSS Academy of Technical Education – NOIDA

Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

program’ is a vector containing the ASCII codes of the characters inside the quotation marks.
Any text following a percent symbol % denotes a comment and is not treated as a program
statement.

The colon symbol: has many different applications in MATLAB. It is used to generate vectors,
subscript matrices, and perform iterations of a block of commands. For example,

x = M:N generates the vector


x = [M M+1 M+2 . . . N],
if M < N. However x = M:N is an empty matrix, denoted by [], if M > N. The command x =
M:k:N generates the vector
x = [M M+k M+2k . . . N],
where k can be a positive or a negative integer. Note that x = M:k:N generates the empty matrix
[] if k > 0and M > Nor if k < 0and M < N. The colon can also be employed to select specific
rows, columns, and elements of a matrix
or a vector. For example, Y(:,N) represents the Nth column of Y. Likewise, the Mth row of Y is
represented by Y(M,:). Y(:,M:N) is equivalent to Y(:,M), Y(:,M+1), . . ., Y(:,N). Finally, Y(:) is
equivalent to a column vector formed by concatenating the columns of Y.

Output Data Format

All arithmetic operations in MATLAB are performed in double precision. However, different
formats can be used to display the result of such operations in the Command window. If all
results are exact integers, they are displayed as such without any decimal points. If one or more
data elements are not integers, the results can be displayed with various precision. Format short
displays five significant decimal digits and is the default format. Format short e displays five
significant decimal digits with two positive or negative decimal exponents. Format long shows
results in 15 significant decimal digits, while format long e adds two positive or negative decimal
exponents to 15 significant decimal digits. There are three other formats for displaying results.
However, these are not that useful in signal processing applications.

Graphics
MATLAB includes high-level graphics capability for displaying the results of a computation. In
most situations, we shall be concerned with two-dimensional (2-D) graphics and will use three-
dimensional (3-D) graphics in some special cases. For 2-D graphics, plotting can be done in
various forms with either linear or logarithmic scales for one or both axes of the plots. Grid lines
can be added to the plots along with labels for the two axes and a title on
top of the plot. Text can be placed anywhere on the graph using a mouse or specifying the
starting position through commands in the program. Moreover, by including appropriate symbols
in the argument of the plotting command, specific line styles, plot symbols, and colors can be
displayed in the graph. For 3-D data, plotting can also be done in various forms with either linear
or logarithmic scales for one or two or all three axes of the plots. For example, lines and points
can be plotted in three dimensions. Contour plots, 3-D perspective plots, surface plots,
pseudocolor

Department of Electronic Engineering Page 17 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

plots, and so forth can also be generated.


The M-file in the following section illustrates the use of several graphics commands.

M-Files: Scripts and Functions

An M-file is a sequence of MATLAB statements developed using a word processor or a text


editor and saved with a name that must be in the form filename.m. The names of M-files must
begin with a letter followed by at most 18 letters and/or digits (or underscores). However certain
characters, such as hyphen - and decimal point ., are not allowed in the names. Also, do not use
the names of existing M-files. An M-file can include references to
other existing M-files. Each statement of a new program is typed in the Editor window line by
line as ASCII text
files and can be edited using the text editor or the word processor of your computer. The
complete program can then be saved as an M-file.
There are two types of M-files: scripts and functions. A function file must contain the word
function in the first line of all program statements. Arguments in a function file may be passed
from another M-file, and all variables used inside the function file are local. The script file makes
use of workspace data globally. The first line of a function file contains the word function and
does not make use of workspace data globally. The variables defined inside a function file are
manipulated locally, and the arguments of the file may be passed. When a function is completed,
all local variables are lost. Only values specifically passed out are retained.
A simple example of a function file runsum is given below.
function y = runsum(x)
% Computes the mean of a vector x
L = length(x);
y = sum(x)/L;
A simple example of a script file lowpass.m follows.
% Script M-file lowpass.m
% Program to Perform Lowpass Filtering
% Using Three-Point Averaging of a Random Signal
% Program uses the function file runsum
z = zeros(1,11);data = randn(size(z));
u = [zeros(1,3) data];
N = 3; % N is the filter length
for k = 1:10;
w = u(k:k+N);
z(k) = runsum(w);
end
n = 0:10;
% Plot the noise in solid line and
% the smoothed version in dashed line
plot(n,data,’r-’,n,z,’b--’);grid
xlabel(’Time index n’);
ylabel(’Amplitude’);

Department of Electronic Engineering Page 18 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

gtext(’Noisy data’);gtext(’Smoothed data’);


The plot generated by executing the M-file lowpass.m is shown in Figure A.1.
Note that the function file runsum uses the built-in function sum. Likewise, the script file
lowpass.m uses the function file runsum.

MAT-Files
Data generated by a MATLAB program can be saved as a binary file, called a MAT-file, for
later use. For example, the noisy data generated by executing the program lowpass.m of the
previous section can be saved using the command save noise.mat data Later it can be retrieved
using the command load noise for use in another MATLAB session. The data can also be saved
in ASCII form. For example, after execution of the program
lowpass.m, we can generate a 2×11 matrix containing the noisy data and the smoothed data
using the command
result = [noise; z];
and then save the matrix result in ASCII form using the command save tempo.dat result –ascii.
The stored data can later be retrieved using the command load tempo

Printing

Department of Electronic Engineering Page 19 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

To develop a hardcopy version of the current Figure window, the command print can be used.
There are many versions of this command. See the MathWorks Online Documentation [Mat05]
for details. In a PC or a Mac environment, a figure can also be copied to the clipboard and then
inserted into a word processing document. This approach permits generating a smaller size figure
and also pasting the figure on to a text.

Department of Electronic Engineering Page 20 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

A Summary of MATLAB Commands Used

Department of Electronic Engineering Page 21 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

Department of Electronic Engineering Page 22 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

Department of Electronic Engineering Page 23 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

Department of Electronic Engineering Page 24 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

Department of Electronic Engineering Page 25 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

Experiment No. 1

Aim: Program to generate discrete time signals: unit impulse, unit step, sine, cosine, ramp
and exponential

Theory: In this experiment we learn how to generate in the time domain some basic discrete-
time signals in MATLAB.
A discrete-time signal is represented as a sequence of numbers, called samples. A sample value
of a typical discrete-time signal or sequence {x[n]} is denoted as x[n] with the argument n being
an integer in the range −∞ and ∞.
The discrete-time signal may be a finite length or an infinite length sequence. A finite length
(also called finite duration or finite extent) sequence is defined only for a finite time interval: N1
≤ n ≤ N2, where −∞ < N1 and N2 < ∞ with N2 ≥ N1. The length or duration N of the finite
length sequence is N = N2 − N1 + 1.
The unit sample sequence, often called the discrete-time impulse or the unit impulse, denoted by
δ[n], is defined by
δ[n] = 1, for n = 0,
0, for n ≠ 0.

The unit step sequence , denoted by μ[n], is defined by


μ[n] = 1, for n ≥ 0,
0, for n < 0.
The exponential sequence is given by
x[n] = Aαn, where A and α are real or complex numbers.
The real sinusoidal sequence with constant amplitude is of the form
x[n] = Acos(ωon + φ),
where A, ωo, and φ are real numbers. The parameters A, ωo, and φ are called, respectively, the
amplitude , the angular frequency , and the initial phase of the sinusoidal sequence x[n]. fo =
ωo/2π is the frequency.

Continuous time unit ramp function is defined by


r(n)= 0 ,n<0
n, n≥0
A ramp signal starts at n=0 and increases linearly with time‘n’.

Code:

Figures obtained:

Discussion of Results obtained:

Department of Electronic Engineering Page 26 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

Experiment Related Questions

(a) What is the difference between continuous time, discrete time and digital signals
(b) How are step and plot functions different
(c) Give relation between signum function and step function
(d) Give relationship between unit step and impulse function
(e) How will you justify that area under the curve for an impulse function is one.
(f) Differentiate between * and .* operator in MATLAB.

Department of Electronic Engineering Page 27 of 36


JSS Academy of Technical Education – NOIDA
Digital Signal Processing Laboratory (EEC-652) Manual (EC VIth Semester)

Experiment No.: 2

Aim: Write a program to perform basic operations on sequences


(a) Time shifting (b) Time reversal (c) Amplitude scaling (d) signal addition (e)
multiplication
Make use of function operator to form the discrete time signal and perform
signal operations in main program.

Theory:

Time Shifting: Time shifting of a signal results in time delay or time advance. y(n) =x(n-k)
implies that y(n) is obtained by time shifting the signal x(n) by k units. If k is positive, it is a
delay and the shift is to right and if it is negative, it is advance and shift is to left.

Time Reversal: Obtained by folding the sequence about n=0.

Time Scaling: It is expansion or compression and is obtained by replacing n with an


y(n) = x(an)
When a>1, it compression and a<1, it is expansion.
e.g.: x(n) ={ 4,3,2,1,2,3,4}

x(2n)= {3,1,3}
`
x(n/2) = { 0.4,0,3,2,0,1,0,2,0,3,0,4,0}

Signal Multiplication/Addition: Multiplication/ Addition is performed by multiplying /adding


values at the sampling instant.

Amplitude Scaling: y(n)= a x(n)

Use of Functions in MATLAB is explained in introduction part above.

Code:

Figures obtained :

Discussion of Results obtained:

Department of Electronic Engineering Page 28 of 36

You might also like