📄 clt.m
字号:
function [y1,y2] = clt(ty,n)
%CLT Gaussian approximation for repeated convolution.
%
% [YA,YG] = CLT(TY,N) Gaussian approximation for N repeated convolutions
% TY = 't' for conv of tri signals, 'r' for rect, 'e' for exp(-t)
% DEFAULTS: N = 10
%
% YA returns the actual convolution at 0.02s intervals.
% YG returns the Gaussian approximation at 0.02s intervals.
% Both results are overplotted
%
% CLT (with no input arguments) invokes the following example:
%
% % Plot of the actual and Gaussian approximation to
% % 15 repeated convolutions of exp(-t)
% >>clt('exp',15);
% 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 clt,disp('Strike a key to see results of the example')
pause,clt('exp',15);return,end
if nargin<2,n=10;end,ty=ty(1);
if n<1,error('Number of convolutions must be > 0'),return,end
pl='Gaussian (--) & conv(-) for ';
if ty=='t'
pl=[pl 'tri functions: n='];
dt=.02;y=bartlett(101).';y1=y;
for j=1:n,y1=dt*conv(y,y1);end,t=-(n+1):.02:n+1;%m=2*n+1;
ss=(n+1)/6;s=sqrt(ss);
y2=exp(-(t.^2)/2/ss)/sqrt(2*pi*ss);
plot(t,y1,t,y2,'--'),title([pl num2str(n)])
elseif ty=='r'
pl=[pl 'rect functions: n='];
dt=.02;r=rem(n,2);n0=fix((n-1)/2);
y0=[.5 ones(1,49) .5];y=bartlett(101).';y1=y;
for j=1:n0,y1=dt*conv(y,y1);end,if r==0,y1=dt*conv(y1,y0);end
t=-(n+1)/2:.02:(n+1)/2;ss=(n+1)/12;y2=exp(-(t.^2)/2/ss)/sqrt(2*pi*ss);
plot(t,y1,t,y2,'--'),title([pl num2str(n)])
elseif ty=='e'
pl=[pl 'exp(-t): n='];
s=4*sqrt(n);
if n>16,t=n-s:n/200:n+s;else,t=(n+s)/400:(n+s)/400:n+s;end
y1=exp(n*log(t)-t-gmln(n+1));y2=exp(-((t-n).^2)/2/n)/sqrt(2*pi*n);
plot(t,y1,t,y2,'--'),title([pl num2str(n)])
else,error('Unindentified signal type. Use t(ri), r(ect) or e(xp)'),end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -