Introduction
Introduction
1 MATLAB fundamentals:
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.
performs vector/matrix multiplication. The number of columns in the first vector/matrix must
equal to the number of rows in the second. Example:
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.
Exercise 1:
Task # 1: Try all help methods to get help of any function.
Task # 2: (a) Assign 10 samples, from 0 to 9, of time to the vector t.
(b) Assign a vector of samples without assigning it to a variable.
(c) Assign 10 samples, from 0 to 9, of time to any vector without printing it to screen.
Task # 3: Investigate the difference between multiplication and element-wise multiplication of
vectors/matrices.
Task # 4: Generate a complex-valued matrix
and calculate the absolute square of all elements of all elements of this matrix.
Task # 5: Implement a function
[x]=sinewave(t)
which produces a sine wave of 1001 samples with spacing of .
Task # 6: Use MATLAB help to get familiar with the syntax of FOR, WHILE and IF-ELSE statement.
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.