簡體   English   中英

相當於MATLAB ltitr.m函數的八度

[英]Octave equivalent of MATLAB ltitr.m function

我試圖讓一些MATLAB腳本在Octave中運行,但是以下代碼行有問題:

x = ltitr( a, b, u, x0 ) ;

這會在八度音階中引發錯誤。

在線研究表明,ltitr函數是內部MATLAB函數,可為給定的輸入返回線性時不變時間響應內核。 這聽起來好像應該是一個常見的DSP要求,所以我覺得這必須直接在Octave或Source Forge的最新Control軟件包中實現。 但是,我似乎找不到等效的八度音階。 我已經閱讀了最新的Octave Control軟件包的文檔,也許我應該使用lsim.m或ss.m或dss.m或impulse.m函數,但我不確定。

誰能啟發我? 如果未在Octave中實現,也許可以在線參考一些代碼,以編寫自己的ltitr函數?

如果您實際上是在MATLAB命令提示符下鍵入help ltitr ,那么您將獲得以下文檔:

%LTITR  Linear time-invariant time response kernel.
%
%   X = LTITR(A,B,U) calculates the time response of the
%   system:
%           x[n+1] = Ax[n] + Bu[n]
%
%   to input sequence U.  The matrix U must have as many columns as
%   there are inputs u.  Each row of U corresponds to a new time 
%   point.  LTITR returns a matrix X with as many columns as the
%   number of states x, and with as many rows as in U.
%
%   LTITR(A,B,U,X0) can be used if initial conditions exist.
%   Here is what it implements, in high speed:
%
%   for i=1:n
%          x(:,i) = x0;
%          x0 = a * x0 + b * u(i,:).';
%   end
%   x = x.';

%   Copyright 1984-2007 The MathWorks, Inc.
%   $Revision: 1.1.6.4 $  $Date: 2007/05/23 18:54:41 $

% built-in function

這樣,他們幾乎已經為您提供了代碼。 但是,我假設這是用MEX編寫的,所以這就是它內置且超快速的原因。 因此,如果要將其移植到Octave,只需使用它們上面引用的代碼即可。 雖然它不會像MATLAB版本那樣快,但是for循環本質上是實現它的基本方法。

但是,為了完整起見,讓我們為其編寫自己的Octave函數:

function x = ltitr(A, B, U, x0)

%// Number of rows in U is the number of time points
num_points = size(U, 1);

%// Number of columns in U is how many inputs we have
num_inputs = size(U, 2);

x = zeros(num_inputs, num_points); %// Pre-allocate output

%// For each time point we have ...
for idx = 1 : num_points
    x(:,idx) = x0; %// Output the corresponding time point
    x0 = A*x0 + B*U(idx,:).'; %// Compute next time point
end
x = x.';

上面的函數幾乎與您在MATLAB中看到的代碼相似,但是我做了一些額外的步驟,例如預先分配矩陣以提高效率,以及獲取一些相關變量以幫助計算。 另外,請注意,輸出矩陣x的尺寸已翻轉 之所以這樣,是因為在此狀態下,每個時間點的輸出計算都更容易計算。 如果不這樣做,則必須對x0 = ...語句中定義的其他變量進行不必要的轉置。 這樣,更容易在轉置矩陣中進行計算。 完成后,對結果矩陣進行轉置,以得到最終的輸出矩陣x

我假設x0的默認狀態將全為零,因此如果要將其用作默認狀態,請指定x0 = zeros(n,1); 其中n是LTI系統的輸入總數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM