System Identification Tips

download System Identification Tips

of 44

Transcript of System Identification Tips

  • 7/29/2019 System Identification Tips

    1/44

    ECE 621, Project # 2 Question 1

    Qn:1 Driving System with Sinusiods

    a)Input Signal DefinitionA general function for the input chosen is shown below:

    For the three cases analyzed, the parameters were varied.

    b)Results with one sinusoidParameter Value

    0.01

    1.00

    0.00

    0.00

    5.00

    NA

    NA

    0.00

    NA

    NA

    For this analysis, the Batch LS algorithm was chosen, as directed. A 1000 sample sinusoidal signal was

    chosen for this analysis. Figure 1 below shows the response of the system. Note that the first 200

    samples have been discarded for the system identification analysis, as directed.

  • 7/29/2019 System Identification Tips

    2/44

    ECE 621, Project # 2 Question 1

    Figure 1 1-Sine Response

    Results

    True value Estimate with

    1 Sinusoid

    Condition Number

    Of Data Matrix

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    0.7867

    -4.0551

    1.5249

    -76.0945

    504.1890

    -336.1260

    4.2589e+21

    With one sinusoid, the system was not identified.

    0 100 200 300 400 500 600 700 800 900-1

    -0.5

    0

    0.5

    1

    Input

    0 100 200 300 400 500 600 700 800 900-200

    -100

    0

    100

    200

    Output

    0 100 200 300 400 500 600 700 800 900-1

    -0.5

    0

    0.5

    1

    InputconsideredforI/D

    Samples

    0 100 200 300 400 500 600 700 800 900-200

    -100

    0

    100

    200

    OutputconsideredforI/D

  • 7/29/2019 System Identification Tips

    3/44

    ECE 621, Project # 2 Question 1

    c) Results with two sinusoidsParameter Value

    0.01

    1.00 1.00

    0.00

    5.00

    2.00

    NA

    0.00

    NA

    For this analysis, the Batch LS algorithm was chosen, as directed. A 1000 sample sinusoidal signal waschosen for this analysis. Figure 1 below shows the response of the system. Note that the first 200

    samples have been discarded for the system identification analysis, as directed.

  • 7/29/2019 System Identification Tips

    4/44

    ECE 621, Project # 2 Question 1

    Figure 2 2-Sine Response

    Results

    True value Estimate with

    2 Sinusoids

    Condition Number

    Of Data Matrix

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    -3.1668

    3.7274

    -1.5170

    140.4014

    -307.9648

    185.5163

    6.5278e+20

    Even with 2 sinusoids, the system was not identified.

    0 100 200 300 400 500 600 700 800 900-2

    -1

    0

    1

    2

    Input

    0 100 200 300 400 500 600 700 800 900-400

    -200

    0

    200

    400

    Output

    0 100 200 300 400 500 600 700 800 900-2

    -1

    0

    1

    2

    InputconsideredforI/D

    Samples

    0 100 200 300 400 500 600 700 800 900-400

    -200

    0

    200

    400

    OutputconsideredforI/D

  • 7/29/2019 System Identification Tips

    5/44

    ECE 621, Project # 2 Question 1

    d)Results with three sinusoidsParameter Value

    0.01

    1.00 1.00

    1.00

    5.00

    2.00

    1.00

    0.00

    For this analysis, the Batch LS algorithm was chosen, as directed. A 1000 sample sinusoidal signal waschosen for this analysis. Figure 1 below shows the response of the system. Note that the first 200

    samples have been discarded for the system identification analysis, as directed.

  • 7/29/2019 System Identification Tips

    6/44

    ECE 621, Project # 2 Question 1

    Figure 3 3-Sine Response

    Results

    True value Estimate with

    3 Sinusoids

    Condition Number

    Of Data Matrix

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    2.7145e+12

    With a combination of three sinusoids, the system was identified.

    0 100 200 300 400 500 600 700 800 900-4

    -3

    -2

    -1

    0

    1

    2

    3

    4

    Input

    0 100 200 300 400 500 600 700 800 900-1000

    -800

    -600

    -400

    -200

    0

    200

    400

    600

    Output

    0 100 200 300 400 500 600 700 800 900

    0

    InputconsideredforI/D

    Samples

    0 100 200 300 400 500 600 700 800 900-1000

    0

    OutputconsideredforI/D

  • 7/29/2019 System Identification Tips

    7/44

    ECE 621, Project # 2 Question 1

    e)ConclusionThe persistency of the input signal used is clearly seen to affect the ability of the algorithm to identify

    the system. The weak/strong persistency order (PE) of a sinusoidal signal is shown to be 2. In order that

    the Data Matrix has full rank, (in this case 6, since there are 6 parameters to be identified), it means thatthe input sequence must have a PSE of at least 6.

    Input TypeOrder

    of P.E.Identifiability

    Condition

    Number of QComment

    1 Sinusoid 2 < 6, Not Identifiable 4.2589e+21

    Does not meet the Identifiability

    requirement. This is seen from the large

    condition number.

    2 Sinusoids 4 < 6, Not Identifiable 6.5278e+20

    Does not meet the Identifiability

    requirement. This is seen from the large

    condition number.

    3 Sinusoids 6 >= 6, Identifiable 2.7145e+12

    Meets the Identifiability requirement.The condition number is still large due to

    the sinusoidal input, however the matrix

    is invertible

  • 7/29/2019 System Identification Tips

    8/44

    ECE 621, Project # 2 Question 1

    g)Code% ECE 621, Systems Identification% Project # 2, Qn 01%% Author:%

    % Date: 2012.10.30%

    clear all; clc;close allhidden;

    % Display true system parameters for comparisonp1 = 0.80;p2 = 0.68;p3 = 0.50;b0 = 5.00;b1 = 2.00;b2 = 3.00;

    a1 = - (p1 + p2 + p3);a2 = p1*p2 + p2*p3 + p1*p3;a3 = - p1*p2*p3;disp ('Theta matrix from System');disp([a1;a2;a3;b0;b1;b2]);

    clear all;

    % Batch estimation% Drive system with random input and get output vector.t = (0:1:999);u = 0 + 1*sin(2*pi*5*0.01*t);u = u + 0*sin(2*pi*2*0.01*t + pi/6);

    u = u + 0*sin(2*pi*1*0.01*t - pi/12);y = g_proj_1(u);

    % Length of input/output vectornum = length(u);

    % Samples to discarddiscard = 200;

    % Length of theta_hat vector = m + nm = 3;n = 3;

    % Initialize Phi Matrixphi = zeros(num-discard+1, m+n);

    % Define regressor phi'% phi_t = [-y(t-1) -y(t-2) -y(t-3) u(t-1) u(t-2) u(t-3)]

    for i = discard : num

    i1 = i-1;

  • 7/29/2019 System Identification Tips

    9/44

    ECE 621, Project # 2 Question 1

    i2 = i-2;i3 = i-3;

    if i10)y1 = y(i1); y2 = y(i2); y3 = y(i3);u1 = u(i1); u2 = u(i2); u3 = u(i3);

    end

    phi(i,:) = [-y1 -y2 -y3 u1 u2 u3];

    end

    % Form Q Matrixq = phi'*phi;disp(['Condition Number of Data Matrix = ', num2str(cond(q))]);

    % Batch compute theta_hat with PHI matrixtheta_hat = q\(phi'*y);disp ('Theta hat matrix from System Identification');disp(theta_hat);

    figure;

    subplot(211);[AX,H1,H2] = plotyy(t,u,t,y); grid on;set(AX(1), 'xlim', [0 t(num)]); set(AX(2), 'xlim', [0 t(num)]);ax1y = get(AX(1), 'ylim'); ax2y = get(AX(2), 'ylim');set(get(AX(1),'ylabel'), 'string', 'Input');set(get(AX(2),'ylabel'), 'string', 'Output');

    clear AX;

    subplot(212);[AX,H1,H2] = plotyy(t(discard:num), u(discard:num),t(discard:num),y(discard:num)); grid on;set(AX(1), 'xlim', [0 t(num)]); set(AX(2), 'xlim', [0 t(num)]);

    set(AX(1), 'ylim', ax1y); set(AX(2), 'ylim', ax2y);set(get(AX(1),'ylabel'), 'string', 'Input considered for I/D');set(get(AX(2),'ylabel'), 'string', 'Output considered for I/D');xlabel('Samples');

  • 7/29/2019 System Identification Tips

    10/44

    ECE 621, Project # 2 Question 2

    Qn:2 Driving System with Symmetric

    Square waveforms

    h)Results with Period = 6 samples

    Figure 4 Response with 6 sample symmetric square wave

    The first 200 samples (208s) of the input and output signals were discarded and only the rest was fed

    into the identifier.

    0 5 10 15 20 25 30 35-1

    -0.5

    0

    0.5

    1

    Input

    0 5 10 15 20 25 30 35-20

    0

    20

    40

    60

    Output

    Samples

    180 190 200 210 220 230 240 250

    -1

    -0.5

    0

    0.5

    1

    InputconsideredforI/D

    Time (s)

    180 190 200 210 220 230 240 250-20

    -10

    0

    10

    20

    OutputconsideredforI/D

  • 7/29/2019 System Identification Tips

    11/44

    ECE 621, Project # 2 Question 2

    Results

    True value Estimate with

    6 sample sym. Sqr. wave

    Condition Number

    Of Data Matrix

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    4.6946

    -9.1376

    -11.7038

    -106.7417

    -7.0509

    98.1983

    4.0311e+17

    With a 6 sample symmetric square waveform, the system was not identified.

    0 50 100 150 200 250 300 350 400 450 500

    -1

    -0.5

    0

    0.5

    1

    Input

    0 50 100 150 200 250 300 350 400 450 500-20

    0

    20

    40

    60

    Output

    0 50 100 150 200 250 300 350 400 450 500

    -1

    -0.5

    0

    0.5

    1

    InputconsideredforI/D

    Time (s)

    0 50 100 150 200 250 300 350 400 450 500-20

    -10

    0

    10

    20

    Outputconsidered

    forI/D

  • 7/29/2019 System Identification Tips

    12/44

    ECE 621, Project # 2 Question 2

    i) Results with Period = 12 samples

    Figure 5 Response with 12 sample symmetric square wave

    The first 200 samples (104s) of the input and output signals were discarded and only the rest was fed

    into the identifier.

    0 2 4 6 8 10 12 14 16 18 20-1

    -0.5

    0

    0.5

    1

    Input

    0 2 4 6 8 10 12 14 16 18 20-100

    -50

    0

    50

    100

    150

    Output

    Samples

    70 80 90 100 110 120 130 140

    -1

    -0.5

    0

    0.5

    1

    InputconsideredforI/D

    Time (s)

    70 80 90 100 110 120 130 140-100

    -50

    0

    50

    100

    OutputconsideredforI/D

  • 7/29/2019 System Identification Tips

    13/44

    ECE 621, Project # 2 Question 2

    Results

    True value Estimate with12 sample sym. Sqr. wave Condition NumberOf Data Matrix

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    374614.1391

    With a 12 sample symmetric square waveform, the system was identified correctly.

    0 50 100 150 200 250 300 350 400 450 500

    -1

    0

    1

    I

    nput

    0 50 100 150 200 250 300 350 400 450 500-200

    0

    200

    Output

    0 50 100 150 200 250 300 350 400 450 500

    -1

    -0.5

    0

    0.5

    1

    InputconsideredforI/

    D

    Time (s)

    0 50 100 150 200 250 300 350 400 450 500-100

    -50

    0

    50

    100

    OutputconsideredforI

    /D

  • 7/29/2019 System Identification Tips

    14/44

    ECE 621, Project # 2 Question 2

    j) Results with Period = 20 samples

    Figure 6 Response with 20 sample symmetric square wave

    The first 200 samples (63s) of the input and output signals were discarded and only the rest was fed intothe identifier.

    0 2 4 6 8 10 12 14 16 18 20-1

    -0.5

    0

    0.5

    1

    Input

    0 2 4 6 8 10 12 14 16 18 20-200

    -100

    0

    100

    200

    300

    Output

    Sam les

    45 50 55 60 65 70 75 80 85 90

    -1

    -0.5

    0

    0.5

    1

    InputconsideredforI/D

    Time (s)

    45 50 55 60 65 70 75 80 85 90-200

    -100

    0

    100

    200

    OutputconsideredforI/D

  • 7/29/2019 System Identification Tips

    15/44

    ECE 621, Project # 2 Question 2

    Results

    True value Estimate with20 sample sym. Sqr. wave

    Condition NumberOf Data Matrix

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    800462.8466

    With a 20 sample symmetric square waveform as well, the system was identified correctly.

    0 50 100 150 200 250 300 350 400 450 500

    -1

    -0.8

    -0.6

    -0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    Input

    0 50 100 150 200 250 300 350 400 450 500-200

    -150

    -100

    -50

    0

    50

    100

    150

    200

    250

    300

    Output

    0 50 100 150 200 250 300 350 400 450 500

    -1

    -0.5

    0

    0.5

    1

    InputconsideredforI/D

    Time (s)

    0 50 100 150 200 250 300 350 400 450 500-200

    -100

    0

    100

    200

    OutputconsideredforI/D

  • 7/29/2019 System Identification Tips

    16/44

    ECE 621, Project # 2 Question 2

    k)ConclusionThe persistency of the input signal used is clearly seen to affect the ability of the algorithm to identify

    the system. The weak/strong persistency order (PE) of a symmetric square wave is known to be function

    of the number of samples per period. For a symmetric square wave with M samples per period, theorder of persistency is M/2.

    In order that the Data Matrix has full rank, (in this case 6, since there are 6 parameters to be identified),

    it means that the input sequence must have a PSE of at least 6. Hence the input symmetric square wave

    shall have at least 12 samples per period.

    Input TypeOrder

    of P.E.Identifiability

    Condition

    Number of QComment

    6 sample

    symmetric

    sq. wave

    3< 6, Not

    Identifiable4.0311e+17

    Does not meet the Identifiability

    requirement. This is seen from the large

    condition number.12 sample

    symmetric

    sq. wave

    6 >= 6, Identifiable 374614.1 Meets the Identifiability requirement.

    20 sample

    symmetric

    sq. wave

    10 >= 6, Identifiable 800462.8 Meets the Identifiability requirement.

  • 7/29/2019 System Identification Tips

    17/44

    ECE 621, Project # 2 Question 2

    m) Code.% ECE 621, Systems Identification% Project # 2, Qn 02%% Author:

    %% Date: 2012.10.30%

    clear all; clc;close allhidden;

    % Display true system parameters for comparisonp1 = 0.80;p2 = 0.68;p3 = 0.50;b0 = 5.00;b1 = 2.00;

    b2 = 3.00;a1 = - (p1 + p2 + p3);a2 = p1*p2 + p2*p3 + p1*p3;a3 = - p1*p2*p3;disp ('Theta matrix from System');disp([a1;a2;a3;b0;b1;b2]);

    clear all;

    % Batch estimation% Drive system with random input and get output vector.

    nmp = 11; % Number of periodssmp = 20; % Samples per periodt = linspace(1e-10,nmp*2*pi,smp*nmp);% Symmetric Square Waveu = (2*(sin(t)>0)-1);

    y = g_proj_1(u);

    figure;subplot(211);stem(t(1:3*smp),u(1:3*smp)); grid on; ylabel('Input');subplot(212);stem(t(1:3*smp),y(1:3*smp)); grid on; ylabel('Output');xlabel('Samples');

    % Length of input/output vector

    num = length(u);

    % Samples to discarddiscard = 200;

    % Length of theta_hat vector = m + nm = 3;n = 3;

  • 7/29/2019 System Identification Tips

    18/44

    ECE 621, Project # 2 Question 2

    % Initialize Phi Matrixphi = zeros(num-discard+1, m+n);

    for i = discard : num

    i1 = i-1;

    i2 = i-2;i3 = i-3;

    if i10)y1 = y(i1); y2 = y(i2); y3 = y(i3);u1 = u(i1); u2 = u(i2); u3 = u(i3);

    end

    phi(i,:) = [-y1 -y2 -y3 u1 u2 u3];

    end

    % Form Q Matrixq = phi'*phi;disp(['Condition Number of Data Matrix = ', num2str(cond(q))]);

    % Batch compute theta_hat with PHI matrixtheta_hat = q\(phi'*y);disp ('Theta hat matrix from System Identification');disp(theta_hat);figure;subplot(211);[AX,H1,H2] = plotyy(t,u,t,y); grid on;set(AX(1), 'xlim', [0 t(num)]); set(AX(2), 'xlim', [0 t(num)]);set(AX(1), 'ylim', [-1.1 1.1]);set(get(AX(1),'ylabel'), 'string', 'Input');set(get(AX(2),'ylabel'), 'string', 'Output');

    subplot(212);

    [AX,H1,H2] = plotyy(t(discard:num), u(discard:num),t(discard:num),y(discard:num)); grid on;set(AX(1), 'xlim', [0 t(num)]); set(AX(2), 'xlim', [0 t(num)]);set(AX(1), 'ylim', [-1.1 1.1]);set(get(AX(1),'ylabel'), 'string', 'Input considered for I/D');set(get(AX(2),'ylabel'), 'string', 'Output considered for I/D');xlabel('Time (s)');

  • 7/29/2019 System Identification Tips

    19/44

    ECE 621, Project # 2 Question 3

    Qn:3 Over Parametrization

    n)True ModelThe true model for the system can be defined as follows:

    An expression for y(t) in discrete time domain can then be defined as follows:

    where:

    and with the following parameters:

    p1 = 0.80;p2 = 0.68;p3 = 0.50;b0 = 5.00;b1 = 2.00;b2 = 3.00;

    Parameter True value

    a0a1a2b0b1b2

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

  • 7/29/2019 System Identification Tips

    20/44

    ECE 621, Project # 2 Question 3

    o)Input Used for IdentificationA symmetric square wave with 20 samples per period was chosen for system identification, for all cases

    discussed here. This should be sufficient, since such a signal has an order of persistence of 10, and can

    be used to estimate up to 10 parameters. Even if an extra parameter is added to both the numerator

    and the denominator, the total number of parameters to be estimated would only be 8 in this case.

    Hence the chosen signal has sufficient order of P.E..

    0 5 10 15 20 25 30 35-1

    -0.5

    0

    0.5

    1

    Input

    0 5 10 15 20 25 30 35-200

    -100

    0

    100

    200

    300

    Output

    Samples

    0 10 20 30 40 50 60 70

    -1

    -0.8

    -0.6

    -0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    Input

    0 10 20 30 40 50 60 70-200

    -150

    -100

    -50

    0

    50

    100

    150

    200

    250

    300

    Output

    0 10 20 30 40 50 60 70

    -1

    -0.5

    0

    0.5

    1

    InputconsideredforI/D

    Time (s)

    0 10 20 30 40 50 60 70-200

    -100

    0

    100

    200

    OutputconsideredforI/D

  • 7/29/2019 System Identification Tips

    21/44

    ECE 621, Project # 2 Question 3

    p)Extra Input TermIf the System ID model were modeled with an extra input term, the regressor can be expressed as:

    [ ]

    Results

    True value Estimate with

    extra i/p parameter

    Condition Number

    Of Data Matrix

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    0.0000

    1.4112e+07

    It can be seen that in this case, the least squares identifier was able to correctly identify the system and

    the excess parameter. The excess parameter b3 was identified as 0, as expected.

    q)Extra Output TermIf the System ID model were modeled with an extra output term, the regressor can be expressed as:

    [ ]

    Results

    True value Estimate with

    extra o/p parameter

    Condition Number

    Of Data Matrix

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    -1.9800

    1.2840

    -0.2720

    -0.0000

    5.0000

    2.0000

    3.0000

    2711800.233

    It can be seen that in this case, the least squares identifier was able to correctly identify the system and

    the excess parameter. The excess parameter a3 was identified as 0, as expected.

  • 7/29/2019 System Identification Tips

    22/44

    ECE 621, Project # 2 Question 3

    r) Extra Term in Numerator and DenominatorIf the System ID model were modeled with an extra term in the numerator and the denominator,, the

    regressor can be expressed as:

    [ ]

    Results

    True value Estimate with

    extra i/p parameter

    Condition Number

    Of Data Matrix

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    7.2433

    -16.9782

    11.5708

    -2.5087

    5.0000

    48.1167

    21.4467

    27.6700

    8.4400e+17

    It can be seen that in this case, the least squares identifier was not able to identify the system. Several

    attempts were made to evaluate the possibility of complete system identification with the

    overparametrization:

    Increased Samples per period to upto 50 sampleso No effect: System was not identified

    Increased total number of samples considered for identificationo No effect: System was not identified

    Changed input to a pseudorandom signalo No effect: System was not identified. But estimates slightly better

    True value Estimate Cond(Q)

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    -2.7020

    2.7135

    -1.1990

    0.1964

    5.0000

    -1.6100

    1.5560

    -2.1660

    5.2243e+16

    s) ConclusionOverparametrization introduces limitation to estimation of an ARMA system only if excess parameters

    are introduced both at the input and at the autoregressive terms. This is because it creates linear

    dependencies in the regressor, if extra input terms and output terms are present together.

  • 7/29/2019 System Identification Tips

    23/44

    ECE 621, Project # 2 Question 3

    t) Code: (+1 param in numerator)% ECE 621, Systems Identification% Project # 2, Qn 03 a (+1 param in numerator)%% Author:%

    % Date: 2012.10.30%

    clear all; clc;close allhidden;

    % Display true system parameters for comparisonp1 = 0.80;p2 = 0.68;p3 = 0.50;b0 = 5.00;b1 = 2.00;b2 = 3.00;

    a1 = - (p1 + p2 + p3);a2 = p1*p2 + p2*p3 + p1*p3;a3 = - p1*p2*p3;disp ('Theta matrix from System');disp([a1;a2;a3;b0;b1;b2]);

    clear all;

    % Batch estimation% Drive system with random input and get output vector.

    nmp = 12; % Number of periodssmp = 20; % Samples per periodt = linspace(1e-10,nmp*2*pi,smp*nmp);% Symmetric Square Waveu = (2*(sin(t)>0)-1);

    y = g_proj_1(u);

    % This will assume that the system is an ARMA model with a form as defined% as below:% y(t) = bo u(t-1) + b1 u(t-2) + b2 u(t-3) - a1 y(t-1) - a2 y(t-2) - a3 y(t-3)% Goal of the batch estimator will be to find b0, b1, b2, a1, a2, & a3

    % Length of input/output vectornum = length(u);

    % Samples to discarddiscard = 200;

    % Length of theta_hat vector = m + nm = 4;n = 3;

  • 7/29/2019 System Identification Tips

    24/44

    ECE 621, Project # 2 Question 3

    % Initialize Phi Matrixphi = zeros(num-discard+1, m+n);

    % Define regressor phi'% Add param in numerator (b4)

    % phi_t = [-y(t-1) -y(t-2) -y(t-3) u(t-1) u(t-2) u(t-3) u(t-4)]

    for i = discard : num

    % indices will be +ve as long as discard >=4% here discard = 200 samples

    i1 = i-1;i2 = i-2;i3 = i-3;i4 = i-4;

    y1 = y(i1); y2 = y(i2); y3 = y(i3);u1 = u(i1); u2 = u(i2); u3 = u(i3); u4 = u(i4);

    phi(i,:) = [-y1 -y2 -y3 u1 u2 u3 u4];

    end

    % Form Q Matrixq = phi'*phi;disp(['Condition Number of Data Matrix = ', num2str(cond(q))]);

    % Batch compute theta_hat with PHI matrixtheta_hat = q\(phi'*y);disp ('Theta hat matrix from System Identification');disp(theta_hat);

  • 7/29/2019 System Identification Tips

    25/44

    ECE 621, Project # 2 Question 3

    u)Code: (+1 param in denominator)% ECE 621, Systems Identification% Project # 2, Qn 03 b (+1 param in denominator)%% Author:%

    % Date: 2012.10.30%

    clear all; clc;close allhidden;

    % Display true system parameters for comparisonp1 = 0.80;p2 = 0.68;p3 = 0.50;b0 = 5.00;b1 = 2.00;b2 = 3.00;

    a1 = - (p1 + p2 + p3);a2 = p1*p2 + p2*p3 + p1*p3;a3 = - p1*p2*p3;disp ('Theta matrix from System');disp([a1;a2;a3;b0;b1;b2]);

    clear all;

    % Batch estimation% Drive system with random input and get output vector.

    nmp = 12; % Number of periodssmp = 20; % Samples per periodt = linspace(1e-10,nmp*2*pi,smp*nmp);% Symmetric Square Waveu = (2*(sin(t)>0)-1);

    y = g_proj_1(u);

    % This will assume that the system is an ARMA model with a form as defined% as below:% y(t) = bo u(t-1) + b1 u(t-2) + b2 u(t-3) - a1 y(t-1) - a2 y(t-2) - a3 y(t-3)% Goal of the batch estimator will be to find b0, b1, b2, a1, a2, & a3

    % Length of input/output vectornum = length(u);

    % Samples to discarddiscard = 200;

    % Length of theta_hat vector = m + nm = 3;n = 4;

  • 7/29/2019 System Identification Tips

    26/44

    ECE 621, Project # 2 Question 3

    % Initialize Phi Matrixphi = zeros(num-discard+1, m+n);

    % Define regressor phi'% Add param in numerator (b4)

    % phi_t = [-y(t-1) -y(t-2) -y(t-3) u(t-1) u(t-2) u(t-3) u(t-4)]

    for i = discard : num

    % indices will be +ve as long as discard >=4% here discard = 200 samples

    i1 = i-1;i2 = i-2;i3 = i-3;i4 = i-4;

    y1 = y(i1); y2 = y(i2); y3 = y(i3); y4 = y(i4);u1 = u(i1); u2 = u(i2); u3 = u(i3);

    phi(i,:) = [-y1 -y2 -y3 -y4 u1 u2 u3];

    end

    % Form Q Matrixq = phi'*phi;disp(['Condition Number of Data Matrix = ', num2str(cond(q))]);

    % Batch compute theta_hat with PHI matrixtheta_hat = q\(phi'*y);disp ('Theta hat matrix from System Identification');disp(theta_hat);

  • 7/29/2019 System Identification Tips

    27/44

    ECE 621, Project # 2 Question 3

    v)Code: (+1 param in numerator & denominator)% ECE 621, Systems Identification% Project # 2, Qn 03 c (+1 param in num and den)%% Author:%

    % Date: 2012.10.30%

    clear all; clc;close allhidden;

    % Display true system parameters for comparisonp1 = 0.80;p2 = 0.68;p3 = 0.50;b0 = 5.00;b1 = 2.00;b2 = 3.00;

    a1 = - (p1 + p2 + p3);a2 = p1*p2 + p2*p3 + p1*p3;a3 = - p1*p2*p3;disp ('Theta matrix from System');disp([a1;a2;a3;b0;b1;b2]);

    clear all;

    % Batch estimation% Drive system with random input and get output vector.

    nmp = 50; % Number of periodssmp = 50; % Samples per periodt = linspace(1e-10,nmp*2*pi,smp*nmp);% Symmetric Square Waveu = (2*(sin(t)>0)-1);clear u; load rand_uy = g_proj_1(u);

    % This will assume that the system is an ARMA model with a form as defined% as below:% y(t) = bo u(t-1) + b1 u(t-2) + b2 u(t-3) - a1 y(t-1) - a2 y(t-2) - a3 y(t-3)% Goal of the batch estimator will be to find b0, b1, b2, a1, a2, & a3

    % Length of input/output vectornum = length(u);

    % Samples to discarddiscard = 200;

    % Length of theta_hat vector = m + nm = 4;n = 4;

  • 7/29/2019 System Identification Tips

    28/44

    ECE 621, Project # 2 Question 3

    % Initialize Phi Matrixphi = zeros(num-discard+1, m+n);

    % Define regressor phi'% Add param in numerator (b4)

    % phi_t = [-y(t-1) -y(t-2) -y(t-3) u(t-1) u(t-2) u(t-3) u(t-4)]

    for i = discard : num

    % indices will be +ve as long as discard >=4% here discard = 200 samples

    i1 = i-1;i2 = i-2;i3 = i-3;i4 = i-4;

    y1 = y(i1); y2 = y(i2); y3 = y(i3); y4 = y(i4);u1 = u(i1); u2 = u(i2); u3 = u(i3); u4 = u(i4);

    phi(i,:) = [-y1 -y2 -y3 -y4 u1 u2 u3 u4];

    end

    % Form Q Matrixq = phi'*phi;disp(['Condition Number of Data Matrix = ', num2str(cond(q))]);

    % Batch compute theta_hat with PHI matrixtheta_hat = q\(phi'*y);disp ('Theta hat matrix from System Identification');disp(theta_hat);

  • 7/29/2019 System Identification Tips

    29/44

    ECE 621, Project # 2 Question 4

    Qn:4 Effect of Feedback

    The system is modeled as the following per the problem description:

    This can be simplified to:

    For the analysis, a pseudorandom sequence was used for measurement noise v(t). For the sake of

    comparison, the same measurement noise sequence was used for all the cases analyzed. The following

    table shows the list of cases that have been analysed.

    Controller

    Type

    Controller

    Reference r(t)

    Measurement

    Noise

    P 0 random

    P random random

    PI 0 random

    PI random random

    v(t)

    r(t)

    y(t)

    d(t)

    y0(t)

    Plant

    Controller

    v(t)

    r(t)

    y(t)

    u(t)

    d(t)

    y0(t)

  • 7/29/2019 System Identification Tips

    30/44

    ECE 621, Project # 2 Question 4

    w)Case 1: P Controller, r(t) = random

    Results

    True value Estimate with

    P Controller, r(t) = random

    Condition Number

    Of Data Matrix-1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0001

    42903.3689

    With a measurement noise magnitude of 0.000001 (Noise Power Level of 7.083e-6 compared to Output

    Power), the system was identified to adequate precision, in the presence of a pseudorandom reference

    signal. The following table shows the effect of measurement noise on the estimates with a P controller.

    100 200 300 400 500 600 700 800-2

    -1

    0

    1

    2x 10

    -3

    PlantInput(u)

    Time (s)

    100 200 300 400 500 600 700 800-0.2

    -0.1

    0

    0.1

    0.2

    PlantMeasu

    redOutput(y)

    100 200 300 400 500 600 700 800-2

    -1

    0

    1

    2x 10

    -3

    PlantInput(u)

    Time (s)

    100 200 300 400 500 600 700 800-1

    -0.5

    0

    0.5

    1

    ControllerRefernce(r)

    750 755 760 765 770 775 780 785 790 795 800-0.1

    -0.05

    0

    0.05

    0.1

    PlantTrueOutput(y0

    )Zoom In on Plant Output (True vs Measured), Noise Level :7.0833e-006

    Time (s)

    750 755 760 765 770 775 780 785 790 795 800-0.1

    -0.05

    0

    0.05

    0.1

    PlantMeasuredOutput

    (y)

  • 7/29/2019 System Identification Tips

    31/44

    ECE 621, Project # 2 Question 4

    Table 1 Comparison of Results with a P Controller for various Measurement Noise Levels

    Noise Amplitude Estimate RMS Estimate Error Cond(Q) Noise to Output Ratio

    1.00E-10

    -1.9800

    2.40E-09 47020.04436 6.88853E-10

    1.2840

    -0.2720

    5.0000

    2.00003.0000

    1.00E-09

    -1.9800

    2.40E-08 47020.04436 6.88853E-09

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    1.00E-08

    -1.9800

    0.0000002 47020.04431 6.88853E-08

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    1.00E-07

    -1.9800

    0.0000024 47020.0438 6.88853E-07

    1.2840-0.2720

    5.0000

    2.0000

    3.0000

    1.00E-06

    -1.9800

    0.0000245 47020.03626 6.88853E-06

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    1.00E-05

    -1.9800

    0.0002843 47019.70911 6.88852E-05

    1.2839

    -0.2720

    5.0000

    2.00023.0001

    0.0001

    -1.9790

    0.0068166 46991.29833 0.000688852

    1.2821

    -0.2711

    4.9997

    2.0056

    3.0032

    0.001

    -1.9096

    0.4328803 44408.34346 0.006888419

    1.1566

    -0.2115

    4.9958

    2.3511

    3.1981

    0.01

    -1.1454

    5.2706347 17059.58527 0.068871096

    -0.17140.3887

    5.0249

    6.1491

    5.7042

    0.1

    -0.4081

    14.7885249 14540.0083 0.684050624

    -0.2804

    -0.1290

    5.2693

    10.3454

    15.0018

  • 7/29/2019 System Identification Tips

    32/44

    ECE 621, Project # 2 Question 4

    x)Case 2: P Controller, r(t) = 0

    Results

    True value Estimate with

    P Controller, r(t) = 0

    Condition Number

    Of Data Matrix-1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    -0.0407

    -0.0886

    -0.3442

    33.2457

    140.6121

    -8.3892

    1.4493e+021

    With r(t) = 0, the system was not identified. This is because of the following:

    Controller input d(t) is:

    Hence Plant Input u(t):

    Since the regressor is the following:

    there is linear dependence between u and y. Hence the data matrix is not invertible.

    100 200 300 400 500 600 700 800-2

    -1

    0

    1

    2x 10

    -9

    PlantInput(u)

    Time (s)

    100 200 300 400 500 600 700 800-1

    -0.5

    0

    0.5

    1x 10

    -6

    PlantMeasu

    redOutput(y)

    100 200 300 400 500 600 700 800-2

    -1

    0

    1

    2x 10

    -9

    PlantInput(u)

    Time (s)

    100 200 300 400 500 600 700 800-1

    -0.5

    0

    0.5

    1

    ControllerRefernce(r)

    750 755 760 765 770 775 780 785 790 795 800-1

    -0.5

    0

    0.5

    1

    x 10-7

    PlantTrueOutput(y0

    )Zoom In on Plant Output (True vs Measured), Noise Level :6.308

    Time (s)

    750 755 760 765 770 775 780 785 790 795 800-1

    -0.5

    0

    0.5

    1

    x 10-6

    PlantMeasuredOutput

    (y)

  • 7/29/2019 System Identification Tips

    33/44

    ECE 621, Project # 2 Question 4

    y)Case 3: PI Controller, r(t) = randomFor a PI controller, the block diagram is represented as before, but the coeffients A(z) and B(z) will be

    different:

    where:

    An expression for y(t) can hence be obtained as follows:

    With a measurement noise magnitude of 0.000001 (Noise Power Level of 7.083e-6 compared to Output

    Power), the system was identified to adequate precision, in the presence of a pseudorandom reference

    signal.

    Results

    True value Estimate with

    PI Controller, r(t) = random

    Condition Number

    Of Data Matrix

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    -1.9800

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0001

    92529.8786

    v(t)

    r(t)

    y(t)

    d(t)

    y0(t)

  • 7/29/2019 System Identification Tips

    34/44

    ECE 621, Project # 2 Question 4

    The following table shows the effect of measurement noise on the estimates with a PI controller.

    100 200 300 400 500 600 700 800-2

    -1

    0

    1

    2x 10

    -3

    PlantInput(u)

    Time (s)

    100 200 300 400 500 600 700 800-0.2

    -0.1

    0

    0.1

    0.2

    PlantMeasuredOutput(y)

    100 200 300 400 500 600 700 800-2

    -1

    0

    1

    2x 10

    -3

    PlantInput(u)

    Time (s)

    100 200 300 400 500 600 700 800-1

    -0.5

    0

    0.5

    1

    ControllerRefernce(r)

    750 755 760 765 770 775 780 785 790 795 800-0.2

    -0.1

    0

    0.1

    0.2

    PlantTrueOutput(y0

    )Zoom In on Plant Output (True vs Measured), Noise Level :4.5487e-006

    Time (s)

    750 755 760 765 770 775 780 785 790 795 800-0.2

    -0.1

    0

    0.1

    0.2

    PlantMeasuredO

    utput(y)

  • 7/29/2019 System Identification Tips

    35/44

    ECE 621, Project # 2 Question 4

    Table 2 Comparison of Results with a PI Controller for various Measurement Noise Levels

    Noise Amplitude Estimate RMS Estimate Error Cond(Q) Noise to Output Ratio

    1.00E-10

    -1.9800

    2.22E-09 97123.60802 4.51E-10

    1.2840

    -0.2720

    5.0000

    2.00003.0000

    1.00E-09

    -1.9800

    2.20E-08 97123.60803 4.51E-09

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    1.00E-08

    -1.9800

    0.0000002 97123.60809 4.51E-08

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    1.00E-07

    -1.9800

    0.0000022 97123.60867 4.51E-07

    1.2840-0.2720

    5.0000

    2.0000

    3.0000

    1.00E-06

    -1.9800

    0.0000224 97123.61018 4.51E-06

    1.2840

    -0.2720

    5.0000

    2.0000

    3.0000

    1.00E-05

    -1.9800

    0.0002580 97123.19356 4.51E-05

    1.2839

    -0.2720

    5.0000

    2.00023.0001

    0.0001

    -1.9791

    0.0059687 97075.89533 0.000451

    1.2824

    -0.2713

    4.9998

    2.0049

    3.0029

    0.001

    -1.9208

    0.3759261 92591.31712 0.004508

    1.1775

    -0.2223

    5.0038

    2.3037

    3.1782

    0.01

    -1.1632

    5.3322007 35372.40991 0.045086

    -0.14550.3732

    5.1671

    6.2032

    5.7588

    0.1

    -0.4577

    17.1558106 27309.19736 0.449590

    -0.3035

    -0.1117

    7.3639

    12.0901

    16.4930

  • 7/29/2019 System Identification Tips

    36/44

    ECE 621, Project # 2 Question 4

    z)Case 4: P Controller, r(t) = 0With r(t) = 0 , the LS identifier will not be able to identify the parameters due to the linear dependency

    introduced in the regressor by the PI controller. Since r(t) = 0, the plant input u(t) is:

    or

    Since the regressor is the following:

    there is linear dependence between u and y. Hence the data matrix is not invertible.

    Results

    True value Estimate with

    PI Controller, r(t) = 0

    Condition Number

    Of Data Matrix

    -1.9800

    1.2840-0.2720

    5.0000

    2.0000

    3.0000

    -0.0133

    0.4766-1.6467

    -183.7949

    669.0858

    -41.7854

    8.7032e+022

    100 200 300 400 500 600 700 800-2

    -1

    0

    1

    2x 10

    -9

    PlantInput

    (u)

    Time (s)

    100 200 300 400 500 600 700 800-1

    -0.5

    0

    0.5

    1x 10

    -6

    PlantMeasuredO

    utput(y)

    100 200 300 400 500 600 700 800-2

    -1

    0

    1

    2x 10

    -9

    PlantInput(u)

    Time (s)

    100 200 300 400 500 600 700 800-1

    -0.5

    0

    0.5

    1

    ControllerRefernce(r)

    750 755 760 765 770 775 780 785 790 795 800-2

    -1

    0

    1

    2x 10

    -7

    PlantTrueOutput(y0

    )Zoom In on Plant Output (True vs Measured), Noise Level :4.1584

    Time (s)

    750 755 760 765 770 775 780 785 790 795 800-1

    -0.5

    0

    0.5

    1x 10

    -6

    PlantMeasuredOutput(y)

  • 7/29/2019 System Identification Tips

    37/44

    ECE 621, Project # 2 Question 4

    aa) ConclusionIt was seen that feedback introduces linear dependencies in the regressor, and hence led to singularities

    in the data matrix inversion calculations, if the controller reference signal was set to 0. If the controller

    reference signal was non-zero, and independent of u(t) and y(t), the system identifier did not have any

    issues estimating the parameters.

    Furthermore, the introduction of measurement noise was shown to significantly impact the parameter

    estimates. As shown in Table 1 and Table 2, the noise levels had to be significantly reduced to yield

    parameter estimates close to truth.

    Table 3 Comparison of Results

    Controller

    Type

    Controller

    Reference r(t)

    Measurement

    Noise

    Condition Number

    Of Data MatrixEstimate

    P 0 random 1.4493e+021 Not IdentifiedP random random 42903.3689 Identified

    PI 0 random 8.7032e+022 Not Identified

    PI random random 92529.8786 Identified

  • 7/29/2019 System Identification Tips

    38/44

    ECE 621, Project # 2 Question 4

    bb) Code: (P Controller)% ECE 621, Systems Identification% Project # 2, Qn 04%% Author:%

    % Date: 2012.11.02%

    clear all; clc;close allhidden;

    % Display true system parameters for comparisonp1 = 0.80;p2 = 0.68;p3 = 0.50;b0 = 5.00;b1 = 2.00;b2 = 3.00;

    a1 = - (p1 + p2 + p3);a2 = p1*p2 + p2*p3 + p1*p3;a3 = - p1*p2*p3;disp ('Theta matrix from System');disp([a1;a2;a3;b0;b1;b2]);

    clear all;

    % Batch estimation

    load rand_rload rand_v

    % Length of input/output vectornum = 800;

    r(num+1:end)=[];v(num+1:end)=[];

    rmax = 0.0;vmax = 0.000001;

    rmean = -mean(r);vmean = -mean(v);

    t = (1:num);

    r = rmean*rmax + rmax*r;v = vmean*vmax + vmax*v;

    for i = 1:length(r)

  • 7/29/2019 System Identification Tips

    39/44

    ECE 621, Project # 2 Question 4

    i1 = i-1;i2 = i-2;i3 = i-3;

    if i10)y01 = y0(i1); y02 = y0(i2); y03 = y0(i3);u1 = u(i1); u2 = u(i2); u3 = u(i3);r1 = r(i1);

    d1 = d(i1);y1 = y(i1);end

    d(i) = r(i) - y1;

    kp =0.0023;u(i) = kp*d(i);

    y0curr = [y03 y02 y01];ucurr = [u3 u2 u1];

    % Compute current outputy0(i) = g_proj_1_current(ucurr, y0curr);

    y(i) = y0(i) + v(i);

    end

    y = y';

    % This will assume that the system is an ARMA model with a form as defined% as below:% y(t) = bo u(t-1) + b1 u(t-2) + b2 u(t-3) - a1 y(t-1) - a2 y(t-2) - a3 y(t-3)% Goal of the batch estimator will be to find b0, b1, b2, a1, a2, & a3

    % Samples to discarddiscard = 20;

    % Length of theta_hat vector = m + nm = 3;n = 3;

  • 7/29/2019 System Identification Tips

    40/44

    ECE 621, Project # 2 Question 4

    % Initialize Phi Matrixphi = zeros(num-discard+1, m+n);

    % Define regressor phi'% phi_t = [-y(t-1) -y(t-2) -y(t-3) u(t-1) u(t-2) u(t-3)]

    for i = discard : num

    phi(i,:) = [-y(i-1) -y(i-2) -y(i-3) u(i-1) u(i-2) u(i-3)];

    end

    % Form Q Matrixq = phi'*phi;disp(['Condition Number of Data Matrix = ', num2str(cond(q))]);

    % Batch compute theta_hat with PHI matrixtheta_hat = q\(phi'*y);disp ('Theta hat matrix from System Identification');disp(theta_hat);

    pnum = [t(1) t(end)];

    figure;

    subplot(311);[AX,H1,H2] = plotyy(t,u,t,y); grid on;set(H2,'LineStyle','-.', 'Linewidth',1.2)set(AX(1), 'xlim', pnum); set(AX(2), 'xlim', pnum);set(get(AX(1),'ylabel'), 'string', 'Plant Input (u)');set(get(AX(2),'ylabel'), 'string', 'Plant Measured Output (y)');xlabel('Time (s)');

    subplot(312);[AX,H1,H2] = plotyy(t,u,t,r); grid on;set(H2,'LineStyle','-.', 'Linewidth',1.2)set(AX(1), 'xlim', pnum); set(AX(2), 'xlim', pnum);set(get(AX(1),'ylabel'), 'string', 'Plant Input (u)');set(get(AX(2),'ylabel'), 'string', 'Controller Refernce (r)');xlabel('Time (s)');

    subplot(313);[AX,H1,H2] = plotyy(t(num-50:num),y0(num-50:num),t(num-50:num),y(num-50:num)); grid on;set(H2,'LineStyle','.')set(get(AX(1),'ylabel'), 'string', 'Plant True Output (y_0)');set(get(AX(2),'ylabel'), 'string', 'Plant Measured Output (y)');ttt = ['Zoom In on Plant Output (True vs Measured), Noise Level :',num2str(std(v)/std(y0))];title(ttt)xlabel('Time (s)');size_figs_4PPT

  • 7/29/2019 System Identification Tips

    41/44

    ECE 621, Project # 2 Question 4

    cc) Code: (PI Controller)% ECE 621, Systems Identification% Project # 2, Qn 04%% Author:%

    % Date: 2012.11.02%

    clear all; clc;close allhidden;

    % Display true system parameters for comparisonp1 = 0.80;p2 = 0.68;p3 = 0.50;b0 = 5.00;b1 = 2.00;b2 = 3.00;

    a1 = - (p1 + p2 + p3);a2 = p1*p2 + p2*p3 + p1*p3;a3 = - p1*p2*p3;disp ('Theta matrix from System');disp([a1;a2;a3;b0;b1;b2]);

    clear all;

    % Batch estimation

    load rand_rload rand_v

    % Length of input/output vectornum = 800;

    r(num+1:end)=[];v(num+1:end)=[];

    rmax = 0.0;vmax = 0.000001;

    rmean = -mean(r);vmean = -mean(v);

    t = (1:num);

    r = rmean*rmax + rmax*r;v = vmean*vmax + vmax*v;

    for i = 1:length(r)

    i1 = i-1;i2 = i-2;i3 = i-3;

  • 7/29/2019 System Identification Tips

    42/44

    ECE 621, Project # 2 Question 4

    if i10)y01 = y0(i1); y02 = y0(i2); y03 = y0(i3);u1 = u(i1); u2 = u(i2); u3 = u(i3);r1 = r(i1);d1 = d(i1);y1 = y(i1);

    end

    d(i) = r(i) - y1;

    dcurr = [d1 d(i)];

    u(i) = pi_control_current(dcurr, u1);

    y0curr = [y03 y02 y01];ucurr = [u3 u2 u1];

    % Compute current outputy0(i) = g_proj_1_current(ucurr, y0curr);

    y(i) = y0(i) + v(i);

    end

    y = y';

    % This will assume that the system is an ARMA model with a form as defined% as below:% y(t) = bo u(t-1) + b1 u(t-2) + b2 u(t-3) - a1 y(t-1) - a2 y(t-2) - a3 y(t-3)% Goal of the batch estimator will be to find b0, b1, b2, a1, a2, & a3

    % Samples to discarddiscard = 20;

    % Length of theta_hat vector = m + nm = 3;n = 3;

  • 7/29/2019 System Identification Tips

    43/44

    ECE 621, Project # 2 Question 4

    % Initialize Phi Matrixphi = zeros(num-discard+1, m+n);

    % Define regressor phi'% phi_t = [-y(t-1) -y(t-2) -y(t-3) u(t-1) u(t-2) u(t-3)]

    for i = discard : num

    phi(i,:) = [-y(i-1) -y(i-2) -y(i-3) u(i-1) u(i-2) u(i-3)];

    end

    % Form Q Matrixq = phi'*phi;disp(['Condition Number of Data Matrix = ', num2str(cond(q))]);

    % Batch compute theta_hat with PHI matrixtheta_hat = q\(phi'*y);disp ('Theta hat matrix from System Identification');disp(theta_hat);

    pnum = [t(1) t(end)];

    figure;

    subplot(311);[AX,H1,H2] = plotyy(t,u,t,y); grid on;set(H2,'LineStyle','-.', 'Linewidth',1.2)set(AX(1), 'xlim', pnum); set(AX(2), 'xlim', pnum);set(get(AX(1),'ylabel'), 'string', 'Plant Input (u)');set(get(AX(2),'ylabel'), 'string', 'Plant Measured Output (y)');xlabel('Time (s)');

    subplot(312);[AX,H1,H2] = plotyy(t,u,t,r); grid on;set(H2,'LineStyle','-.', 'Linewidth',1.2)set(AX(1), 'xlim', pnum); set(AX(2), 'xlim', pnum);set(get(AX(1),'ylabel'), 'string', 'Plant Input (u)');set(get(AX(2),'ylabel'), 'string', 'Controller Refernce (r)');xlabel('Time (s)');

    subplot(313);[AX,H1,H2] = plotyy(t(num-50:num),y0(num-50:num),t(num-50:num),y(num-50:num)); grid on;set(H2,'LineStyle','.')set(get(AX(1),'ylabel'), 'string', 'Plant True Output (y_0)');set(get(AX(2),'ylabel'), 'string', 'Plant Measured Output (y)');ttt = ['Zoom In on Plant Output (True vs Measured), Noise Level :',num2str(std(v)/std(y0))];title(ttt)xlabel('Time (s)');size_figs_4PPT

  • 7/29/2019 System Identification Tips

    44/44

    ECE 621, Project # 2 Question 4

    dd) Code: (Functions)function y = g_proj_1_current(u, yold)

    p1 = 0.80;p2 = 0.68;

    p3 = 0.50;b0 = 5.00;b1 = 2.00;b2 = 3.00;

    a1 = - (p1 + p2 + p3);a2 = p1*p2 + p2*p3 + p1*p3;a3 = - p1*p2*p3;

    il = length(u);ol = length(yold);

    y = b0*u(il) + b1*u(il-1) + b2*u(il-2) - a1*yold(ol) - a2*yold(ol-1) -a3*yold(ol-2);

    function u = pi_control_current(d, uold)

    il = length(d);ol = length(uold);

    kp =0.0023;ki =0.00023;

    if (il ~=2 || ol ~=1 )disp(['i/p vector has length ', int2str(il)]);disp(['o/p vector has length ', int2str(ol)]);error ('i/p vector should have length of 2, & prev o/p vector should have

    length of 1');end

    u = uold + (kp + ki)*d(il) - kp*d(il-1);