📄 convnum.m
字号:
function Y =convnum(x,y,dt,ty)
% CONVNUM Numerical convolution.
%
% Z = CONVNUM(X,Y,DT,TY) numerically convolves vectors X and Y
% DT = sampling interval (DEFAULT: DT = 1)
% TY = Numerical Integration Algorithm:
% TY = 's' for Step or TY = 't' for Trapezoidal.
%
% NOTE: If both X and Y are the same size, Z has the same size also.
% If X is a row vector and Y a column vector, Z is a column vector.
%
% CONVNUM (with no input arguments) invokes the following example:
%
% % Compare numerical convolution using Step and Trapezoidal rules
% >>x1=[1 2 3 4],x2=[4 3 2 1]
% >>Y1=convnum(x1,x2)
% >>Y2=convnum(x1,x2,'t')
%
% See Also: PAIRSUM, CONVPLOT
% ADSP Toolbox: Version 2.0
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998
if nargin==0,help convnum,disp('Strike a key to see results of the example')
pause,x1=[1 2 3 4],x2=[4 3 2 1],
Y1=convnum(x1,x2),Y2=convnum(x1,x2,'t'),return,end
if nargin==3,if isstr(dt),ty=dt;dt=1;else,ty='s';end,end
if nargin==2,ty='s';dt=1;end
[m1 n1]=size(x);[m2 n2]=size(y);
x=x(:);y=y(:);
nx=length(x);ny=length(y);
Y=conv(x,y);
if ty=='t',
m=ny-1;a=y(1)*[x;zeros(m,1)]+y(ny)*[zeros(m,1);x];
b=x(1)*[0;y(2:ny-1,1);zeros(nx,1)]+x(nx)*[zeros(nx,1);y(2:ny-1,1);0];
Y=Y-0.5*(a+b);end
if dt~=1,Y=Y*dt;end,
if m1==1 & m2==1,Y=Y.';end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -