matlab 生成离散序列,【 MATLAB 】常用的离散时间序列的 Matlab 产生

单位样本序列

cdfdb35bc3db6b97f6d1364bbd0cde4b.gif

clc

clear

close all

n1 = 0;

n2 = 5;

n0 = 3;

n = [n1:n2];

x = [(n - n0) == 0];

stem(n,x,'filled');

ylim([-1,2]);

c3a0d25b74ed409e8100a17b254bc536.png

改成一个函数:

function [x,n]=delta(n0,n1,n2);

% generate x(n) = delta(n - n0); n1 <= n <= n2

%_____________________________________________

%[x,n] = delta(n0, n1, n2);

%

n = [n1:n2];

x = [(n-n0) == 0];

命名为delta.m

新建一个脚本:

n0 = 3;

n1 = -3;

n2 = 6;

[x,n] = delta(n0,n1,n2);

stem(n,x,'filled');

ylim([-1,2]);

运行得到:

ab5efd80f0f92c26b93070e0b034086a.png

单位阶跃序列

2133583e98ff8822b00f24e9d785d4c3.gif

直接写成函数形式吧:

function [x,n]=stepseq(n0,n1,n2);

% generate x(n) = u(n - n0); n1 <= n <= n2

%_____________________________________________

%[x,n] = stepseq(n0, n1, n2);

%

n = [n1:n2];

x = [(n-n0) >= 0];

新建一个脚本,测试:

clc

clear

close all

n0 = 3;

n1 = -3;

n2 = 6;

[x,n] = stepseq(n0,n1,n2);

stem(n,x,'filled');

ylim([-1,2]);

结果:

18dca3c243a6670066bd212a9efdfda9.png

实值指数序列

cb7c33d988b8ab8b07f5b1ed00a77131.gif 为一般形式。

下面产生一个序列:

66826e1af560700431e5cfc8fefc7b93.gif

脚本代码:

clc

clear

close all

n = -3:10;

x = 0.9.^n;

stem(n,x,'filled');

xlabel('n');

ylabel('0.9^n');

xlim([-5,13]);

ylim([0,2]);

34b4f830dcb7087722ed6814c91d040d.png

复指数序列

b64e2724c90ee22951252aa051097508.gif

clc

clear

close all

n = 0:10;

x = exp( (2+3j)*n );

stem(n,x);

xlabel('n');

593369fbe67e9444253ee2f967d03f17.png

周期序列

clc

clear

close all

n = 0:10;

x = exp( (2+3j)*n );

subplot(2,1,1)

stem(n,x);

xlabel('n');

title('Not Period Sequence');

% the number of period

P = 5;

xtilde = x' * ones(1,P);

xtilde = xtilde(:)';

subplot(2,1,2);

stem(xtilde);

title('Period Sequence');

f0ff053ed7d5e5e72aa8bfe43ff2e0e2.png

本文同步分享在 博客“李锐博恩”(CSDN)。

如有侵权,请联系 support@oschina.cn 删除。

本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。