TP1: MATLAB Coding: Bjective

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

TP1: MATLAB Coding

OBJECTIVE
In this TP, basic knowledge in MATLAB will be reviewed such as using MATLAB Command line, MATLAB
Syntax, and MATLAB Script and Functions. From this TP, student able to

- Understand MATLAB
- Represent discrete-time signal
- Generate script and function using MATLAB IDE

BASIC KNOWLEDGE OF MATLAB


Two important categories of DSP

Signal analysis: Frequency-domain processing


 Spectrum (frequency and/or phase) analysis
 Speech recognition
 Speaker verification
 Target detection
Signal filtering: Time-domain operation
 Removal of unwanted background noise
 Removal of interference
 Separation of frequency bands
 Shaping of the signal spectrum

MATLAB (MATrix LABoratory)


Definition: An interactive, matrix-based system for scientific and engineering numeric computation and
visualization.
There are three basic elements in MATLAB

 Number
 Variables
 Operators
Also, punctuation marks (, , ;, :, etc.) have special meanings.
Number: MATLAB can handle all types of numbers, that is, integers, real numbers, complex numbers.
Variable: Basic variable is a matrix, or an array
 Matrix
 Scalar
 Vector (column vector or row vector)
Operators:

Control flow
 If-elseif-else-end (condition)
 For…end loop
Example

Function and Script


 Scripts: The first construct can be accomplished by using the so-called block mode of operation.
 Functions: The second construct of creating a block of code is through subroutines.
Example:
1. Implement the following equation in script file

K
x ( t )=∑ c k sin ( 100 πkt )
k=1
1
K=5; c k =
k

2. Plot x (t) and sin(100 πt ) during 1 second with sampling time of twice of the maximum
frequency
3. Implement function of the following basic functions
δ ( n )= {10 ,n=0
,n≠0
u ( n )= {10 ,, nn ≥≤ 00
4. Implement general form of impulse sequence and step sequence considering delay, n 0

x ( n )=δ ( n−n0 )

x ( n )=u( n−n 0)
5. Plot the following function of discrete-time signal using the definition in 3

x 1 ( n )=2 δ ( n−5 )−4 δ ( n+ 4 ): add multiple function of delta Kronecker delta function

x 2 ( n )=u ( n ) +u ( n−5 ): add multiple function of unit step

6. Create function that perform shifting operation and folding on sequence


 y ( n )={ x ( n−k ¿ }, shifting function: shifting by the amount of k samples
 y ( n )= { x (−n ) } : time reversal or folding
7. Let x ( n )= {1,2,3,4,5,6,76,5,4,3,2,1 } ,−2 ≤n ≤ 10. Determine and plot the following sequence

x 1 ( n )=2 x ( n−5 )−3 x ( n+ 4 )

x 2 ( n )=x ( 3−n ) + x ( n ) x ( n−2 )

You might also like