Lab#1
Lab#1
In this course we will use software MATLAB to implement and simulate digital signal processing
algorithms.
The name MATLAB stands for MATrix LABoratory. Originally MATLAB was developed to deal
with only one single but universal data type: the matrix.
A matrix is defined by [1]
Its associated name
The number of rows
The number of column
The value of all matrix elements
The matrix data type includes vectors, for the case when either of the number of rows or the
number of column equals to 1; and it includes scalars when both the number of rows and
columns equal 1. Furthermore, matrices can be either real-valued or complex valued, which is
the most general case.
There is a small tutorial in this exercise for newcomer to become familiar with the MATLAB
fundamentals. It is recommended to try out introduced methods while solving the described
tasks.
1.3 Workspace:
The contents of all the variables are stored in the MATLAB workspace. This is the memory region
allocated for variable.
The command WHO lists all variable which currently exist in the workspace.
WHOS additionally lists the size and amount of allocated memory.
The entire workspace or single variable can be cleared by using the CLEAR command.
In general, any matrix within the MATLAB can be complex-valued. However, for efficient
storage, MATLAB distinguishes between real-valued and complex-valued matrices. Real valued
matrices are matrices where the imaginary parts of all matrix elements are zero. The following
essentials must be known to deal with complex-valued matrices:
The variables i and j are assigned, by default, the value . This is used to define
the complex values. For example,
1.6 M-files:
MATLAB can execute a sequence of statements stored in a file. Such files are called M-files
because they have “.m” extension as the last part of their file name.
There are two types of M-types:
Script files
Function files
1.6.1 Script file:
In a script file, script is a sequence of commands as they could be entered at the prompt. The
script allows to execute the entire sequence multiple times in a comfortable way, or to test
modified versions.
1.6.2 Function file:
In a function file, function has the additional feature of passing parameters. On calling a
function, it may read input arguments and after execution it may return output values. The
“FUNCTION” command specifies the input and output parameters of a function. It must be very
first command in a function file. Only comment may be written before the FUNCTION command.
Any text after a % sign inside an m-file is comment.
of the two. Systems can also be multirate, i.e., have different parts that are sampled or updated
at different rates.
For modeling, Simulink provides a graphical user interface (GUI) for building models as block
diagrams, using click-and-drag mouse operations. With this interface, you can draw the models
just as you would with pencil and paper (or as most textbooks depict them). This is a far cry from
previous simulation packages that require you to formulate differential equations and difference
equations in a language or program. Simulink includes a comprehensive block library of sinks,
sources, linear and nonlinear components, and connectors. To customize and create own blocks
S-Functions can be used, which is another skill.
MATLAB and Simulink are integrated; you can simulate, analyze, and revise your models in
either environment at any point.
Task # 7: Use FOR loop to generate a single vector y, which is a digitized unit sine wave with ten
samples per cycles, with 100 elements.
Task#8:
(a): Using Simulink, plot a sine wave between t=0s and t=10s.
(b): Using Simulink, plot a sine wave between t=0s and t=100s and also plot its Spectral
Density by setting Max step size to 0.02.
Task#9: Using Simulink, plot a Unit step Signal between t=0s and t=10s.
Task#10: Implement figure 6 in Simulink to understand the concept of synthesizing square wave.
Task#12: Make a Simulink Model to record and write wave file from a wave device for
the duration of 10 sec at 8 kHz sampling rate and also show its time plot.