first running observer with new data

This commit is contained in:
2019-02-08 13:38:45 +01:00
parent 6b5b8750d1
commit cc582d1bf8
10 changed files with 560 additions and 43 deletions

32
matlab/bodeSamples.m Normal file
View File

@@ -0,0 +1,32 @@
function [fig]=bodeSamples(simData)
%f=figure(); h=plot(simData.Time,simData.Data,'g');
%set(h(1),'color','b'); set(h(2),'color',[0 0.5 0]);
Ts=1/5000; % sampling period
t=0:Ts:simData.Time(end);
posI=interp1(simData.Time,simData.Data(:,1),t);
posO=interp1(simData.Time,simData.Data(:,2),t);
ftI=fft(posI);
ftO=fft(posO);
tf=ftO./ftI;
L=length(t);
k=(L-1)*Ts; % fmax =1/Ts at sample (L-1)/2 (index0-base)
N=[10 220]*k; % number of relevant indexes (index0-base)
frq=(N(1):N(2))/k;
N=N+1;%index0-base -> index1-base
tfn=tf(N(1):N(2));
%fig=figure(); h=plot(abs(ftI));
%fig=figure(); h=plot(abs(ftO));
%fig=figure(); h=plot(abs(ftI(N(1):N(2))));
fig=figure();
ax1=subplot(2,1,1);
ax2=subplot(2,1,2);
h=plot(ax1,frq,abs(tfn));
p=unwrap(phase(tfn))/(2*pi)*360;
h=plot(ax2,frq,p);
grid(ax1,'on');grid(ax2,'on');
set(ax1, 'XScale', 'log');
set(ax2, 'XScale', 'log');
end

View File

@@ -1,39 +1,68 @@
baseDir='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/MXTuningDoc/';
%plots bode of desPos_actPos
[mot1,mot2]=identifyFxFyStage();
close all;
[pb]=simFxFyStage(mot2);sim('stage_closed_loop');
t=desPos_actPos.Time;
u=desPos_actPos.Data(:,1);
y=desPos_actPos.Data(:,2);
figure(1);
clf;
plot(t,u,'b');hold on;
plot(t,y,'color',[0 .5 0]);
grid on;ylim([-4 4]);
grid on;ylim([-2 2]);
saveas(gca, baseDir+"m2_sim_pb.eps",'epsc');
saveas(gca, baseDir+"m1_sim_ss.eps",'epsc');
saveas(gca, baseDir+"m2_sim_ss.eps",'epsc');
saveas(gca, baseDir+"m1_sim_ss_pref.eps",'epsc');
saveas(gca, baseDir+"m2_sim_ss_pref.eps",'epsc');
baseDir='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/matlab/figures';
clear;clear global;
close all;disp('löoad identification data...');
mot=identifyFxFyStage(7);
close all;disp('simulate stage closed loop...');
for k =1:2
[pb]=simFxFyStage(mot{k});sim('stage_closed_loop');
f=figure(); h=plot(desPos_actPos.Time,desPos_actPos.Data,'g');
set(h(1),'color','b'); set(h(2),'color',[0 0.5 0]);
print(f,sprintf('figures/sim_cl_DTGz_%d',mot{k}.id),'-depsc');
f=bodeSamples(desPos_actPos);
print(f,sprintf('figures/sim_cl_DTGz_bode%d',mot{k}.id),'-depsc');
end
close all;disp('simulate observer...');
for k =1:2
[ssc]=StateSpaceControlDesign(mot{k});sim('observer');
f=figure(); h=plot(desPos_actPos.Time,desPos_actPos.Data,'g');
set(h(1),'color','b'); set(h(2),'color',[0 0.5 0]);
print(f,sprintf('figures/sim_cl_observer_%d',mot{k}.id),'-depsc');
f=bodeSamples(desPos_actPos);
print(f,sprintf('figures/sim_cl_observer_bode%d',mot{k}.id),'-depsc');
end
disp('document figure generation done');close all;
function SCRATCH()
%plots bode of desPos_actPos
[mot1,mot2]=identifyFxFyStage();
close all;
[pb]=simFxFyStage(mot2);sim('stage_closed_loop');
saveas(gca, baseDir+"m2_mdl_bode.eps",'epsc');
t=desPos_actPos.Time;
u=desPos_actPos.Data(:,1);
y=desPos_actPos.Data(:,2);
figure(1);
clf;
plot(t,u,'b');hold on;
plot(t,y,'color',[0 .5 0]);
grid on;ylim([-4 4]);
grid on;ylim([-2 2]);
saveas(gca, baseDir+"m2_sim_pb.eps",'epsc');
saveas(gca, baseDir+"m1_sim_ss.eps",'epsc');
saveas(gca, baseDir+"m2_sim_ss.eps",'epsc');
saveas(gca, baseDir+"m1_sim_ss_pref.eps",'epsc');
saveas(gca, baseDir+"m2_sim_ss_pref.eps",'epsc');
minFrq=1;maxFrq=1000;
tSec=t(length(t));
f=(1:length(t))/tSec;
fu=fft(u);
fy=fft(y);
ph=phase(fy./fu)
mag=abs(fy)./abs(fu);
magDb=20*log10(mag);
figure(2);
subplot(2,1,1);
semilogx(f,magDb);
subplot(2,1,2);
semilogx(f,ph);
grid on;
saveas(gca, baseDir+"m2_mdl_bode.eps",'epsc');
minFrq=1;maxFrq=1000;
tSec=t(length(t));
f=(1:length(t))/tSec;
fu=fft(u);
fy=fft(y);
ph=phase(fy./fu)
mag=abs(fy)./abs(fu);
magDb=20*log10(mag);
figure(2);
subplot(2,1,1);
semilogx(f,magDb);
subplot(2,1,2);
semilogx(f,ph);
grid on;
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Binary file not shown.