% very clear stiction pattern but with moving setpoint
clear all,close all,clc
load ..\Yamashita\stiction_model\TIPdata.mat
x = data{1}.OP{4};
y = data{1}.MV{4};
e = data{1}.SP{4} - data{1}.MV{4};
e = e - mean(e);
x = x - mean(x);
y = y - mean(y);
x = detrend(x(1:2048)); y = detrend(y(1:2048));
bicoherence(e)
xlabel('f_1')
ylabel('f_2')
zlabel('bic^2')
% f = [min([0.004 0.0625-0.05]) 0.0781 + 1*0.05]
f = [0.0125 0.0781+0.05]
span = 3000;
figure
xf = wfilter(x,f); yf = wfilter(y,f);
subplot(2,2,1),plot(x(1:2*128),y(1:2*128)/span*100,'o-')
title('Unfiltered')
xlabel('OP - mean(OP) [% span]')
ylabel('PV - mean(PV) [% span]')
subplot(2,2,2),plot(xf(1:2*128),yf(1:2*128)/span*100,'o-')
title(['filter = ' num2str(f)])
xlabel('OP - mean(OP) [% span]')
ylabel('PV - mean(PV) [% span]')
subplot(2,2,[3 4])
plot((e(1:256) + y(1:256))/span*100), ylabel('SP - mean(SP)\newline [% span]')
