DSP Using Matlab® - 1
DSP Using Matlab® - 1
Variable lists
/Current
Directory Main
typing/command
window
Command
history
MATLAB Environment
MATLAB can function as normal calculator:
A 1x1 8 double
array
a 1x1 8 double
array
b 1x1 8 double
array
c 1x1 8 double
array
MATLAB Environment
To clear variables: CLEAR
>> clear a b c >> clear
>> who >> who
Your variables are: >>
A x
>>me(1)
ans =
I
>>me(5)
ans =
n
>>me(8)
ans =
r
MATLAB Environment
Other string funtions:
length - Return the number of character
strings
strcmp - Compares two strings
str2num - Converts a string to a numerical
value, i.e. converts ‘123’ to 123.
strrep - Replaces characters in a string with
different characters (very useful in editing
programs and debugging)
upper - Converts a string to uppercase
lower - Converts a string to lowercase
MATLAB Environment
Input and Output statement:
Use semicolon at the end of your line to
suppress the display- matlab will carry out the
calculation without displaying the result. Try
this
fprintf – Use this command to generate a text
>> fprintf('This is a test. \n')
line:
This is a test.
Thefprintf('
>> “\n” isThis
included
\n is \n ato\nprompt
test. \n ')the display to start a
This
new line, e.g.:
is
a
test.
MATLAB
Environment
fprintf – to display the value of variables, we
can include a “%g” format character:
>> A = 3.45
A=
3.4500
• The abs
function returns
the absolute
values of x.
•This is the
generated plot:
MATLAB
Environment
Plotting in MATLAB Intro:
We can also plot multiple traces on a single
plot:
>>
x=linspace(0,2*pi,100)
;
>> y1=sin(x);
>> y2=cos(x);
>> y3=sin(x).*sin(x);
>> plot(x,y1,x,y2,x,y3)
MATLAB
Environment
Plotting in MATLAB Intro:
We use xlable, ylable, title and legend
tocomplete the plot:
>> xlabel('x');
>> ylabel('y');
>> title('Various
trigonometric
Function');
>> legend('sin(x)',
'cos(x)',
'sin(x)*sin(x)');
• This example is
just a tiny fraction
of MATLAB’s full
range plotting
capabilities. We
shall see that later.
MATLAB
Environment
Predefined Functions in this chapter: