Code covered by the BSD License

# kappa - Frequency-wise nu-gap metric

### Daniel Auger (view profile)

This function calculates the frequency-wise version of the nu-gap between two systems.

testkappa.m
%testkappa Test script for the kappa function.

%% Basic Test

clear
clc

%% Test Case 1: Two different systems

% Define two systems, and measure the difference between them.
% Setup a (non-square) plant transfer function.  This helps us catch bugs
% with the dimensionality.
P1 = tf(1, [1 2 1]);
P2 = tf(1, [10 1 1]);
P3 = tf(1, [100 -0.5 1]);
P11 = [P1 P2 0; 0 0 P3];

P1 = tf([1 -1], [1 2 1]);
P2 = tf(1, [12 1.2 1]);
P3 = tf(1, [80 -0.1 1]);
P22 = [P1 P2 0; 0 0 P3];

clear P1 P2 P3

h = figure();
clf
kappa(P11, P22)
pause(2)
close(h)

%% Test Case 2: Winding Number Condition
% The following plant pair should violate the winding number condition part
% of the nu-gap.
P1 = tf(1,[1 0.1 1]);
P2 = tf(1, [1 -1 0 0 0]);

[~,ksup,~] = kappa(P1,P2);
assert(isequal(ksup, 1));

%% Test Case 3: Identical systems
%
P1 = tf(1,[1 0.1 1]);
P2 = P1;

[k, kinf] = kappa(P1, P2);
assert(all(k < 1e-4));
assert(kinf < 1e-4);

%% Test Case 4: Discrete-time systems

% Define two systems, and measure the difference between them.
P1 = c2d(tf(1,[1 0.1 1]), 0.01);
P2 = c2d(tf(1, [1 -0.5 0.2]), 0.01);

h = figure();
clf
kappa(P1, P2)
pause(2)
close(h)