Digital Signal Processing Reference
In-Depth Information
»
x ¼ 2:(1/4):4
% Create x ¼ [2 2.25 2.5 2.75 3 3.25 3.5 3.75 4]
x Columns 1 through 7
2.0000 2.2500 2.5000 2.7500 3.0000 3.2500 3.5000
Columns 8 through 9
3.7500 4.0000
»
y
2:-0.5:-1
% Create y
[2 1.5 1 0.5 0 -0.5 -1]
¼
¼
y
2.0000 1.5000 1.0000 0.5000 0 -0.5000 -1.0000
Next, we examine creating a vector and extracting numbers in a vetcor:
»
xx
[ 1 2 3 4 5 [5:-1:1] ]
% Create xx
[1234554321]
¼
¼
xx 1234554321
»
xx(3:7)
% Show elements to 7, that is, [3 4 5 5 4]
ans ¼
34554
»
length(xx)
% Return of the number of elements in vetcor xx
ans ¼
10
»
yy ¼ xx(2:2:length(xx))
% Display even indexed numbers in array xx
yy 24531
A.3 PLOT UTILITIES: SUBPLOT, PLOT, STEM, AND STAIR
The following are common MATLAB plot
functions
for digital
signal processing (DSP)
simulation:
subplot opens subplot windows for plotting.
plot produces an x-y plot. It can also create multiple plots.
stem produces discrete-time signals.
stair produces staircase (sample-and-hold) signals.
The following program contains different MATLAB plot functions:
t ¼ 0:0.01:0.4; % Create time vector for time instants from 0 to 0.4 second
xx ¼ 4.5*sin(2*pi*10*t+pi/4); % Calculate a sine function with a frequency of 10 Hz
yy ¼ 4.5*cos(2*pi*5*t-pi/3); % Calculate cos function with a frequency of 5 Hz
subplot(4,1,1), plot(t,xx);grid % Plot a sine function in window 1
subplot(4,1,2), plot(t,xx, t,yy, ' -. ' ) ;grid; % Plot sine and cos functions in window 2
subplot(4,1,3), stem(t,xx);grid
% Plot a sine function in the discrete-time form
subplot(4,1,4), stairs(t,yy);grid
% Plot a cos function in the sample-and-hold form
xlabel(
);
Each plot is shown in Figure A.1 . Notice that dropping the semicolon at the end of the MATLAB
syntax will display values on the MATLAB prompt.
Time (sec.)
'
'
Search WWH ::




Custom Search