diff options
Diffstat (limited to 'compareBJ.sci')
-rwxr-xr-x | compareBJ.sci | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/compareBJ.sci b/compareBJ.sci new file mode 100755 index 0000000..06d2fb8 --- /dev/null +++ b/compareBJ.sci @@ -0,0 +1,56 @@ +function varargout = compareBJ(varargin)
+ //varargin(1) -> idpoly data about oe
+ //varargin(2) -> [y u] matrix of "nx2" dimension
+ //disp('compareBj')
+ bjData = varargin(1)
+ //disp(typeof(bjData))
+ plantData = varargin(2)
+ //disp(typeof(plantData))
+ yData = plantData(:,1)
+ uData = plantData(:,2)
+ uData = [0;uData]
+ //storing the data in A,B,C,D,F matrix
+ // B(z) C(z)
+ // y(n)=---------- u(n)+ ----------- e(n)
+ // A(z)F(z) A(z)D(z)
+ polyA = poly(bjData.a,'x','coeff')
+ polyB = poly(bjData.b,'x','coeff')
+ polyC = poly(bjData.c,'x','coeff')
+ polyD = poly(bjData.d,'x','coeff')
+ polyF = poly(bjData.f,'x','coeff')
+ adf = polyA*polyD*polyF
+ bd = polyB*polyD
+ cf = polyC*polyF
+ delay = max(size(coeff(adf),'*'),size(coeff(bd),'*'),size(coeff(cf),'*'))
+ yHat = [0]
+ bdCoeff = coeff(bd)
+ adfCoeff = coeff(adf)
+ adfCoeff = -adfCoeff(2:length(adfCoeff))
+ for ii = 1:length(uData)
+ uSum = 0;ySum = 0;
+ for jj = 1:length(bdCoeff)
+ if ii-jj <= 0 then
+ uSum = uSum + 0
+ else
+ uSum = uSum + uData(ii-jj+1)*bdCoeff(jj)
+ end
+ end
+ for jj = 1:length(adfCoeff)
+ if ii-jj <= 0 then
+ ySum = ySum + 0
+ else
+ ySum = ySum + yHat(ii-jj+1)*adfCoeff(jj)
+ end
+ end
+ yHat = [yHat; uSum+ySum]
+ end
+ tempStart = 1
+ if size(yHat,'r')- size(yData,'r') > 0 then
+ tempStart = size(yHat,'r')-size(yData,'r')+1
+ end
+ varargout(1) = yHat(tempStart:length(yHat))
+// plot(yHat(tempStart:length(yHat)),'m')
+// plot(yData)
+// xgrid()
+// pause
+endfunction
|