注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Mr.Right

不顾一切的去想,于是我们有了梦想。脚踏实地的去做,于是梦想成了现实。

 
 
 

日志

 
 
关于我

人生一年又一年,只要每年都有所积累,有所成长,都有那么一次自己认为满意的花开时刻就好。即使一时不顺,也要敞开胸怀。生命的荣枯并不是简单的重复,一时的得失不是成败的尺度。花开不是荣耀,而是一个美丽的结束,花谢也不是耻辱,而是一个低调的开始。

网易考拉推荐

matlab信号处理符号symbolic工具箱demo  

2012-12-11 21:36:46|  分类: 学习 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
%  Solutions to linear dynamical equations.
%  Find impulse and step responses.
%  This is an example with (distinct) Complex Eigenvalue
%  and the use of time domain polynomial evaluation
%  of e^{At}to solve.
%  This needs the Symbolic Toolbox to run.
%
%   Written by Kevin D. Donohue (donohue@engr.uky.edu) Sept. 2008

A = [0 1; -109 -6];  %  Systems Matrix
b = [0 2]';  %  Input Matrix
c = [1 0];   %  Ouput Matrix
d = [0];     %  Transmission matrix
x0 = [1 -1]';  %   Initial Conditions on States
[rw, cl] = size(A);  %  Get dimension of systems matrix (should be square)

syms tau t  %   Define symbolic variables
%  Evaluate e^(At) with Matlab's Function
eat = expm(A*tau);
% Find eigenvalues to evaluate polynomical on spectrum of A 
%  Define inputs as they would appear in convolution integral from 0 to t
tstep = 1;  %   weight of step for t > 0
%  For impulse, intergral will be evaluated directly using the sifting
%  propery of the impulse
timpulse = 1;  %  weight of impulse for t=0
% Apply step to input to solution formula
xt = subs(eat,tau,t)*x0 + subs(eat,tau,t)*int(subs(eat,tau,-tau)*b*tstep,tau,0,t);
ytstep = c*xt + d*tstep*heaviside(t);
%  display result to workspace screen
disp('Unit Step Response y(t) =')
pretty(ytstep)

% Apply impulse to input to solution formula (use sifting property on
% integral)
xt = subs(eat,tau,t)*x0 + subs(eat,tau,t)*subs(eat,tau,0)*b*timpulse;
ytimpulse = c*xt + d*tstep*dirac(t);
%  display result to workspace screen
disp('Unit Impulse Response y(t) =')
pretty(ytimpulse)


%  Solutions to linear dynamical equations.
%  Find impulse and step responses.
%  This is an example with (distinct) Complex Eigenvalue
%  and the use of time domain polynomial evaluation
%  of e^{At}to solve.
%  This needs the Symbolic Toolbox to run.
%
%   Written by Kevin D. Donohue (donohue@engr.uky.edu) Sept. 2008

A = [0 1; -109 -6];  %  Systems Matrix
b = [0 2]';  %  Input Matrix
c = [1 0];   %  Ouput Matrix
d = [0];     %  Transmission matrix
x0 = [1 -1]';  %   Initial Conditions on States
[rw, cl] = size(A);  %  Get dimension of systems matrix (should be square)

syms tau t  %   Define symbolic variables
%  Evaluate e^(At) with Matlab's Function
eat = expm(A*tau);
% Find eigenvalues to evaluate polynomical on spectrum of A 
%  Define inputs as they would appear in convolution integral from 0 to t
tstep = 1;  %   weight of step for t > 0
%  For impulse, intergral will be evaluated directly using the sifting
%  propery of the impulse
timpulse = 1;  %  weight of impulse for t=0
% Apply step to input to solution formula
xt = subs(eat,tau,t)*x0 + subs(eat,tau,t)*int(subs(eat,tau,-tau)*b*tstep,tau,0,t);
ytstep = c*xt + d*tstep*heaviside(t);
%  display result to workspace screen
disp('Unit Step Response y(t) =')
pretty(ytstep)

% Apply impulse to input to solution formula (use sifting property on
% integral)
xt = subs(eat,tau,t)*x0 + subs(eat,tau,t)*subs(eat,tau,0)*b*timpulse;
ytimpulse = c*xt + d*tstep*dirac(t);
%  display result to workspace screen
disp('Unit Impulse Response y(t) =')
pretty(ytimpulse)



%  Conversion to Discrete linear dynamical equations.
%  Find system to generate squence of samples for impulse and
%  step responses.
%  This is an example with (distinct) Complex Eigenvalue
%  and the use of Laplace evaluation to solve for e^{At}
%  in computing the discrete-time systems matrix. This part
%  needs the Symbolic Toolbox to run, however the actual
%  output for plotting is done numerically.
%
%   Written by Kevin D. Donohue (donohue@engr.uky.edu) Sept. 2008

% discrete-time sampling frequency
fs = 100;  %  Samples per second
T = 1/fs;   %   Sampling period
evallim = 300;    %  Time sample for stopping simulation
ut = ones(1,evallim);   %  Create unit step samples
impt = zeros(1,evallim);   %  Create unit impulse samples
impt(1) = 1;   %  Initialize first sample to 1


%  Continuous-time system
A = [0 1; -109 -6];  %  Systems Matrix
b = [0 2]';  %  Input Matrix
c = [1 0];   %  Ouput Matrix
d = [0];     %  Transmission matrix
x0 = [0 0]';  %   Initial Conditions on States

[rw, cl] = size(A);  %  Get dimension of systems matrix (should be square)

% Find e^(At) via Laplace
syms s t tau%  Define s, t, and tau as symbolic variables

As = inv(eye(rw)*s - A);  %  Directly compute LT of e^(At)
eat = ilaplace(As,s,t);   %  Take inverse

%  Get discrete systems matrices
Ad = subs(eat,t,T);
bdum = int(eat,t,0,tau);
bd = subs(bdum,tau,T)*b;

% unit step response
xn = x0;  % Initalize state variable
ystep = zeros(1,evallim);   %  Initalize output matrix
%  loop to update state and compute current output sample
for n=1:evallim
    xnp1 = Ad*xn+bd*ut(n);   %  Update state
    ystep(n) = c*xnp1 + d*ut(n);  %  Ouput sample
    xn = xnp1;  %  Assign future state to current state
end

%  
figure(1)
plot(T*[0:length(ystep)-1], ystep)
xlabel('Seconds')
ylabel('Amplitude')
title('Unit Step Response')

% unit impulse response
xn = x0;  % Initalize state variable
yimp = zeros(1,evallim);   %  Initalize output matrix
for n=1:evallim
    xnp1 = Ad*xn+bd*impt(n);   %  Update state
    yimp(n) = c*xnp1 + d*impt(n);  %  Output sample
    xn = xnp1;   %  Assign future state to current state
end

%  Plot impulse response
figure(2)
plot(T*[0:length(yimp)-1], yimp)
xlabel('Seconds')
ylabel('Amplitude')
title('Unit Impulse Response')
  评论这张
 
阅读(855)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016