image thumbnail
from Recursive Least Square Identification without Noise by Otniel Adrian
RLS algorithm to identified parameter of transfer function

RLS_Pure : Recursive Least Square Identification without Noise

RLS_Pure : Recursive Least Square Identification without Noise

This program objective is to identified parameters of third order transfer function. In real-life application usually there's some noise add in recorded signal. But to get beter understanding we didn't include noise. Author : Otniel Adrian Rachmat Contact information : Department of Electrical Engineering, Atma Jaya Catholic University Jendral Sudirman 51, Jakarta 12930 , Indonesia . email :adrian7@mhs.atmajaya.ac.id email : otniel.adrian@gmail.com Date : 09-06-2009 Version : 1.0 Reference : (1) System Modeling and Identification, Prentice Hall, Rolf Johansson,1993 (2) Neuro-Fuzzy and Soft Computing, J.-S.R.Jang, C.-T.Sun, E.Mizutani,1997 (3) FIR_RLS.m-file, Tamer Abdelazim Mellik, version 1.1.0, Note : The author doesn't take any responsibility for any harm caused by the use of this file

Contents

Generate Transfer Function

In this example we try to identified some parameters in third order transfer function. First we generate some transfer function, using an identified parameters manually. Hence we use butter to generate third order lowpass digital Butterworth filter with determine cutoff frequency.

[num,den] = butter(3,0.1)
r_param = [num,den(2:end)];
Gz = tf(num,den,0.01)
ltiview('step',Gz);
num =

    0.0029    0.0087    0.0087    0.0029


den =

    1.0000   -2.3741    1.9294   -0.5321

 
Transfer function:
0.002898 z^3 + 0.008695 z^2 + 0.008695 z + 0.002898
---------------------------------------------------
        z^3 - 2.374 z^2 + 1.929 z - 0.5321
 
Sampling time: 0.01

Simulate Input-Output Data

Now that we got the transfer function, we must specified some input data to simulate identification process. Normally in identification we record a sequence of input-output data, in this term of case we use step input.

n_input = 10;       % Number of input data each step
n_step = 10;        % Number of step signal
sample = 4*n_step*n_input;
zero = zeros(n_input,1);
one = ones(n_input,1);
onen = one.*-1;
data = [zero;one;zero;onen];
in_data = [];
for n=1:n_step
    in_data = [in_data;data];
end
out_data = lsim(Gz,in_data);

figure
hold on;
plot(in_data,'b');
plot(out_data,'r');
title('Input-Output Data Identification') ;
xlabel('Samples')
ylabel('Input-Output Signal')

RLS Algorithm

After we obtain input-output data pairs, we try to identified parameters of the original transfer function. This can be done by applied Recursive Least-Square with input-output data pairs. Vk as Input data at k-times. Wk as Output data at k-times. W(z) b0*Z^3 + b1*Z^2 + b2*Z + b3 ---- = ------------------------------ V(z) a0*Z^3 + a1*Z^2 + a2*Z + a3 Base on the function above, we must identified the parameters such as b0, b1, b2, b3, a1, a2, a3.

in_order = 4;
out_order = 3;
sys_order = in_order + out_order;

delta = 1e2;
Po = delta*eye(sys_order);
Qo = zeros(sys_order,1);
lamda = 0.97;

for n=4:sample
    for i=1:3
        W(i) = out_data(n-i);
    end
    for i=1:4
        V(i) = in_data(n-i+1);
    end
    reg = [V';W'];
    sample_out = out_data(n);
    est_out(n)= reg' * Qo;
    error(n) = out_data(n) - est_out(n);
    Po = (Po - ( (Po*reg*reg'*Po)/( lamda+(reg'*Po*reg) ) ))/lamda;
    Qo = Qo + (Po*reg* (sample_out - (reg'*Qo) ) );
    Recordedw(1:sys_order,n) = Qo;
end
f_param = [Qo(1:4);-Qo(5:7)];
numz = [Qo(1:4,1)];
denz = [1;-Qo(5:7,1)];
Fz = tf(numz',denz',0.01);

figure
hold on
plot(r_param,'b*');
plot(f_param,'R+');
title('Parameters system') ;
xlabel('Order')
ylabel('True and estimated output')

figure
plot(Recordedw(1:sys_order,sys_order:sample)');
title('Estimated parameters convergence') ;
xlabel('Samples');
ylabel('Parameter value');
axis([1 (sample)-sys_order min(min(Recordedw(1:sys_order,sys_order:(sample))')) max(max(Recordedw(1:sys_order,sys_order:(sample))')) ]);

figure
semilogy((abs(error))) ;
title('Error curve') ;
xlabel('Samples');
ylabel('Error value');

figure
hold on
plot(out_data);
plot(est_out,'r');
title('System output') ;
xlabel('Samples')
ylabel('True and estimated output')

Comparison between real and identified transfer function

In this comparison we found the identified parameters has a close value to the real one.

Gz
Fz
ltiview('step',Gz,Fz);
 
Transfer function:
0.002898 z^3 + 0.008695 z^2 + 0.008695 z + 0.002898
---------------------------------------------------
        z^3 - 2.374 z^2 + 1.929 z - 0.5321
 
Sampling time: 0.01
 
Transfer function:
0.002896 z^3 + 0.008695 z^2 + 0.008699 z + 0.002908
---------------------------------------------------
        z^3 - 2.374 z^2 + 1.929 z - 0.5317
 
Sampling time: 0.01

Conclusion

Using RLS we may identified parameters of transfer function by means of its input-output data. For the Pure Signal with no Noise we can easily found the parameters close to the real one. But what will happen if there some noise include? We can found the answer in RLS_Noise.

Contact us at files@mathworks.com