|||
MATLAB代码如下:(参考书:Digital Signal Processing Using MATLAB, 3rd Edition 2011.下同)
连续时间信号:
t = 0:0.01:2; % sample points from 0 to 2 in steps of 0.01
x = sin(2*pi*t); % Evaluate sin(2 pi t)
plot(t,x,'b'); % Create plot with blue line
xlabel('t in sec'); ylabel('x(t)'); % Label axis
title('Plot of sin(2\pi t)'); % Title plot
离散时间信号(火柴梗图):
n = 0:1:40; % sample index from 0 to 20
x = sin(0.1*pi*n); % Evaluate sin(0.2 pi n)
Hs = stem(n,x,'b','filled'); % Stem-plot with handle Hs
set(Hs,'markersize',4); % Change circle size
xlabel('n'); ylabel('x(n)'); % Label axis
title('Stem Plot of sin(0.2 pi n)'); % Title plot
将两者画在同一个图上:
t = 0:0.01:2; % sample points from 0 to 2 in steps of 0.01
tx = sin(2*pi*t); % Evaluate sin(2 pi t)
plot(t,tx,'b'); % Create plot with blue line
hold on
n = 0:1:40; % sample index from 0 to 20
nx = sin(0.1*pi*n); % Evaluate sin(0.2 pi n)
Hs = stem(n*0.05,nx,'b','filled'); % Stem-plot with handle Hs
set(Hs,'markersize',4); % Change circle size
hold off
画在两个图上同时显示:
t = 0:0.01:2; % sample points from 0 to 2 in steps of 0.01
tx = sin(2*pi*t); % Evaluate sin(2 pi t)
subplot(2,1,1);
plot(t,tx,'b'); % Create plot with blue line
n = 0:1:40; % sample index from 0 to 20
nx = sin(0.1*pi*n); % Evaluate sin(0.2 pi n)
subplot(2,1,2);
Hs = stem(n*0.05,nx,'b','filled'); % Stem-plot with handle Hs
set(Hs,'markersize',4); % Change circle size
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-27 06:11
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社