forked from macs-lab/macs-arb-adaptive-regulation-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_attenuation_additional_output.m
executable file
·79 lines (68 loc) · 2.38 KB
/
global_attenuation_additional_output.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function [G_A, norm_square_ol_in_dB, norm_square_cl_in_dB] =...
global_attenuation_additional_output (y_ol,y_cl,Fs,ED,Td)
%--------------------------------------------------------------------------
% Benchmark on Adaptive Regulation:
%
% Rejection of unknown/time-varying multiple narrow band disturbances
%
%--------------------------------------------------------------------------
%
% This function computes the global attenuation for narrow band disturbance
% rejection (Application to a Benchmark problem) in closed loop with
% respect to the open loop.
%
%
%
% G_A = global_attenuation (y_ol,y_cl,Fs,ED,Td)
%
% G_A : Global attenuation (in dB)
%
% y_ol : is vector of "open loop" data
%
% y_cl : is vector of "closed loop" data
%
% Fs : is the sampling frequency ( Fs = 800 Hz by default)
%
% Ed : is the experiment duration ( ED = 15 sec by default)
% The experiment duration should be at least equal to 10 sec.
%
% Td : Start disturbance time (Td = 5 sec by default)
%
% To compute the global attenuation, the function uses the last three
% seconds of the records of data in open and in closed loop.
%
% The global attenuation is computed with the formula :
%
% G_A = 20*log10(norm_ol^2/norm_cl^2);
%
% where :
% norm_ol^2 is the square of the norm of the output in open loop (last
% three seconds)
%
% norm_cl^2 is the square of the norm of the output in closed loop (last
% three seconds)
%
% Important Remark :
% If you use the default values : Fs=800; ED=15; Td=5; you can
% run the function with the syntax :
%
% G_A = global_attenuation (y_ol,y_cl)
%
% Written by M. Alma and I.D. Landau (GIPSA-LAB)
% Version 1, September 22, 2010
if nargin<2, error('Missed open or closed loop data');end
if nargin<3, Fs = 800; ED = 32; Td = 5;end
if nargin<4, Td = 5;ED = 15;end
if nargin<5, Td=5;end
if ED-Td<3, error('Disturbance duration must be at least equal to 3 sec'),end
if Td>=ED, error('Disturbance must be injected before the end of the experiment'),end
y_ol2=y_ol-mean(y_ol);
y_cl2=y_cl-mean(y_cl);
norm_ol = norm(y_ol2(Fs*(ED-3)+1:Fs*ED))^2;
norm_cl = norm(y_cl2(Fs*(ED-3)+1:Fs*ED))^2;
norm_square_ol_in_dB = 20*log10(norm_ol);
norm_square_cl_in_dB = 20*log10(norm_cl);
% norm_ol = var(y_ol2(Fs*(ED-3)+1:Fs*ED));
% norm_cl = var(y_cl2(Fs*(ED-3)+1:Fs*ED));
fprintf ('Global attenuation expressed in "dB" is :')
G_A = 20*log10(norm_ol/norm_cl);