Fixed-Point Toolbox Tutorial (Japanese) demo files

by

 

"Fixed-Point Toolbox Tutorial (Japanese)" demo files. 「Fixed-Point Toolbox チュートリアル」の例題ファイルです。

myfilter_fi.m
function [y, acc] = myfilter_fi(b, a, u, Ty, Tacc, resetStates)
% 2̒ڌ^T\IIRfBW^tB^iŒ菬_j

% ԕϐ̍쐬
persistent xu xy

% f[^̏
y   = fi(zeros(size(u)), Ty, fimath(u));
acc = fi(0, Tacc, fimath(u));
if isempty(xu) || isempty(xy) || resetStates
	% Ԃ̏
	xu = fi(zeros(2, 1), numerictype(u), fimath(u));
	xy = fi(zeros(2, 1), numerictype(y), fimath(y));
end

% fBW^tB^vZ
% y(n) = b(1) * u(n) + b(2) * u(n-1) + b(3) * u(n-2) 
%                    - a(2) * y(n-1) - a(3) * y(n-2)
for n = 1:length(u)
    acc(1) =       b(1) * u(n);
    acc(1) = acc + b(2) * xu(1);
    acc(1) = acc + b(3) * xu(2);
    acc(1) = acc - a(2) * xy(1);
    acc(1) = acc - a(3) * xy(2);
    y(n)   = acc;
    % Ԃ̍XV
    xu(2)  = xu(1);
	xu(1)  = u(n);
    xy(2)  = xy(1);
	xy(1)  = y(n);
end

Contact us