Matlab calculates the convolution of discrete signals

1. The default sequence starts from 0

1.matlab code

%# 复制下面的代码,粘贴在命令行中运行;或者复制到m文件中,按F5运行。
x = [1];       %# 序列x,可理解为代表离散的输入信号
h = [1 2 3];   %# 序列h,可理解为系统的冲激信号
y = conv(x,h)    %# 对x,h进行卷积
stem(y,'fill')   %# 绘制离散序列数据
axis([0 5 -4 8]) %# 设置图像的横坐标区间为[0,5],纵坐标区间为[-4,8]

%# 输出如下`在这里插入代码片`
>> y =
     1     2     3

2. Running results

Cao Qinghua

2. When the starting position of the convolution sequence is not 0

Convolution calculation as shown in the figure belowx(n) starts from -2, h(n) starts from 0

Insert picture description here
Insert picture description here

1.matlab code

n  = -2;                   %起始位置为-2
x = [-1,0,0,1,0,2,0];       
nx = [n:n+length(x)-1];       %x的起始位置
h = [0,0,2,1,0.5,0,0];        %h(n)从0开始有定义,这里需要补全-2,-1处的值为0
nh = [n:n+length(h)-1];       %h的起始位置
y  = conv(x,h);  
ny = [(nx(1)+nh(1)):(nx(length(nx))+nh(length(nh)))];           %卷积和的起始位置,这里数学推导不再赘述
stem(ny,y,'fill');

2. Running results

Insert picture description here

Guess you like

Origin blog.csdn.net/ca___0/article/details/108965033