Skip to content

Instantly share code, notes, and snippets.

@tobin
Created May 23, 2012 09:49
Show Gist options
  • Select an option

  • Save tobin/2774325 to your computer and use it in GitHub Desktop.

Select an option

Save tobin/2774325 to your computer and use it in GitHub Desktop.
Measuring the PZT actuation matrix
function phi = findSystematicPhase(X)
% This function finds the angle (in radians) that minimizes the sum of the
% squared imaginary components of a list (or matrix) of numbers. Note that
% there is an ambiguity of pi radians in the result; resolving that is up
% to you.
%
% Tobin Fricke - 2009-01-05
% Possible future enhancement: consider the matrix of errors on the
% real and imaginary components of X, and weight the corresponding
% components appropriately.
% Reshape the input into a one-dimensional vector
X = reshape(X, numel(X), 1);
% Find the angle that minimizes the sum of the squared imaginary parts:
phi = fminbnd(@(phi) sum(imag(X * exp(1i*phi)).^2), -pi/2, pi/2);
% Here's an alternate procedure, if you don't have "fminbnd":
% phi = linspace(-pi/2, pi/2, 1000);
% mag = sum(imag(X * exp(i*phi)).^2); % Note matrix trickery
% [y,ii] = min(mag);
% phi = phi(ii(1));
#!/bin/csh
set IFO=G1
set SYS=ACO
setenv LIGONDSIP geo-fb1
set freq=31
set amp=1000
set ncyc=20
set navg=100
set ACTUATOR=PZT2
#set SENSOR=NEAR
set really_do_it=1
set tdsresp=./tdsresp.pl
set readbacks=$IFO\:ACO-SQZ_{FAR}_{LONG,ROT,TILT}_IN1
echo \#Readbacks are ${readbacks}
foreach EXC_DOF (A B C)
set exc=$IFO\:ACO-SQZ_${ACTUATOR}_${EXC_DOF}_EXC
echo \#Exciting $exc
set cmd="$tdsresp $freq $amp $ncyc $navg $exc $readbacks"
if ($really_do_it) then
$cmd
else
echo $cmd
endif
end
%
%
% Script to diagonalize the degrees of freedom of a MIMO system
% In particular, the OMC dither ASC.
%
% to-do:
% Compensate for gain changes
% Check stability
filename = 'results-near_PZT1.txt';
N = 3; % number of excitations
M = 3; % number of readbacks
fid = fopen(filename, 'r');
if (fid == -1)
error('Couldn''t open input file ("%s")', filename);
end
%% Read in the new coupling measurements
data = textscan(fid, '%f', 7*N*(M+1), 'CollectOutput', 1, 'CommentStyle', '#');
data = reshape(data{1}, 7, N*(M+1))';
% Columns are [coh mag angle re im err_re err_im]
% delete the columns other than coherence, amplitude, and phase
coh = data(:,1);
data(:,[1,4:7]) = [];
% Turn each amplitude, phase pair into a complex number
data = data(:,1) .* exp(1i*data(:,2));
%% Reshape the matrix
coh = reshape(coh, N+1, M);
data = reshape(data, N+1, M);
% Now each column of the matrix is a measurement group, with the excitation
% in the first row.
% Divide out the excitation
data = data ./ repmat(data(1,:), N+1, 1);
% We no longer need the excitation amplitude; we can remove it
data(1,:) = [];
coh(1,:) = [];
% Now we have to determine the correct demodulation phase
% There is a sign ambiguity here
phi = findSystematicPhase(data);
fprintf('Demodulation phase is %0.2f degrees\n', -phi*180/pi);
data = data * exp(1i*phi);
plot(real(data),imag(data),'x')
axis equal % use 1:1 aspect ratio
grid on
% make sure that worked
if (sum(imag(data).^2) > 0.10*sum(real(data).^2))
error('Demodulation phase adjustment seems to have failed.');
end
% discard the imaginary part of the matrix
measured_matrix = real(data);
fprintf('\nmeasured matrix:\n');
disp(measured_matrix);
fprintf('coherences:\n');
disp(coh);
fprintf('Each column corresponds to a particular excitation. \n\n');
% if any(coh(:) < 0.5)
% error('Coherence is terrible.');
% end
%
% if any(coh(:) < 0.7)
% warning('Coherence is not so good.');
% end
%%
matrix = measured_matrix;
% Force the first row to unity
matrix(1,:) = cross(matrix(2,:), matrix(3,:));
% Normalize the matrix columns
% so that each ROW vector has length 1
matrix = matrix ./ repmat(sqrt(sum(matrix.^2,2)), 1, 3);
fprintf('normalized, hand-patched matrix:\n');
disp(matrix);
inv_matrix = inv(matrix);
fprintf('inverted matrix:\n');
disp(inv_matrix);
%% install the matrix
new_matrix = inv_matrix;
really_install = 0;
channel_base = 'G1:ACO-SQZ_PZT1_OUTMATRIX_';
cmd = 'tdswrite ';
for row=1:N,
for col=1:M
cmd = [cmd channel_base num2str(row) '_' num2str(col) ' ' sprintf('%0.2f', new_matrix(row,col)) ' '];
end
end
fprintf('command is:\n%s\n', cmd);
if really_install
[status, result] = system(cmd)
end

Excitation channels:

G1:ACO-SQZ_PZT1_{A,B,C}_EXC

Two wavefront sensors: near and far. Only NEAR has a longitudinal signal, but FAR has better SNR.

G1:ACO-SQZ_FAR_{ROT,TILT,LONG}_IN1

Kate suggests an excitation amplitude of 300 counts at 31 Hz.

FAR, PZT1:
Demodulation phase is -77.63 degrees
measured matrix:
-0.0000 0.0000 -0.0001
-0.0054 -0.0365 0.0415
0.0135 0.0063 -0.0200
coherences:
0.0447 0.0017 0.1273
0.9810 0.9998 0.9999
0.9964 0.9552 0.9996
Each column corresponds to a particular excitation.
normalized, hand-patched matrix:
0.5864 0.5692 0.5763
-0.0965 -0.6573 0.7474
0.5417 0.2535 -0.8015
inverted matrix:
0.5864 1.0469 1.3980
0.5692 -1.3595 -0.8585
0.5763 0.2776 -0.5744
NEAR, PZT1:
Demodulation phase is -71.79 degrees
measured matrix:
0.0052 0.0001 -0.0045
0.0137 -0.0164 0.0037
-0.0019 0.0293 -0.0252
coherences:
0.7153 0.1921 0.7196
0.9916 0.9974 0.7001
0.7934 0.9994 0.9998
Each column corresponds to a particular excitation.
normalized, hand-patched matrix:
0.5179 0.5770 0.6316
0.6322 -0.7555 0.1718
-0.0503 0.7575 -0.6509
inverted matrix:
0.5179 1.2231 0.8254
0.5770 -0.4373 0.4445
0.6316 -0.6034 -1.0829
#Readbacks are G1:ACO-SQZ_FAR_LONG_IN1 G1:ACO-SQZ_FAR_ROT_IN1 G1:ACO-SQZ_FAR_TILT_IN1
#Exciting G1:ACO-SQZ_PZT1_A_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.0447061 0.0221114 1.38464 0.00409244 0.0217294 0.0105965 0.0603498
0.980981 5.48747 1.46237 0.593843 5.45525 0.0667376 0.29522
0.996378 13.7841 -1.72751 -2.15133 -13.6151 0.122954 0.316515
#Exciting G1:ACO-SQZ_PZT1_B_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.00172751 0.000888403 -0.443009 0.000802642 -0.000380823 0.0119025 0.0658686
0.999834 37.2885 1.40146 6.28431 36.7551 0.0929685 0.441688
0.955238 6.48284 -1.6436 -0.471535 -6.46567 0.182409 0.279358
#Exciting G1:ACO-SQZ_PZT1_C_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.127255 0.0759038 1.40492 0.0125331 0.0748619 0.0136508 0.0777008
0.999938 42.4024 -1.75297 -7.68206 -41.7007 0.0830394 0.41012
0.999563 20.3929 1.38833 3.7005 20.0543 0.0838487 0.271012
#Readbacks are G1:ACO-SQZ_FAR_LONG_IN1 G1:ACO-SQZ_FAR_ROT_IN1 G1:ACO-SQZ_FAR_TILT_IN1
#Exciting G1:ACO-SQZ_PZT2_A_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.0568784 0.0276512 1.43005 0.00387897 0.0273778 0.0115558 0.0647852
0.999775 29.0849 1.30697 7.58475 28.0785 0.0744628 0.301756
0.999051 21.2253 -1.7851 -4.51398 -20.7397 0.0898434 0.296053
#Exciting G1:ACO-SQZ_PZT2_B_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.0147902 0.00694902 -1.81486 -0.00167919 -0.00674308 0.0110297 0.0619699
0.999313 16.602 1.30307 4.39194 16.0105 0.0759837 0.345526
0.92274 3.65281 1.41299 0.57406 3.60742 0.0934213 0.245217
#Exciting G1:ACO-SQZ_PZT2_C_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.111814 0.052678 -1.77623 -0.010746 -0.0515703 0.0108433 0.060777
0.999959 45.3669 -1.76612 -8.80508 -44.5042 0.087693 0.379071
0.999647 16.5839 1.36938 3.3178 16.2486 0.0662212 0.269949
#Readbacks are G1:ACO-SQZ_NEAR_LONG_IN1 G1:ACO-SQZ_NEAR_ROT_IN1 G1:ACO-SQZ_NEAR_TILT_IN1
#Exciting G1:ACO-SQZ_PZT1_A_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.715279 5.42392 -1.85532 -1.52247 -5.20586 0.158805 0.813551
0.991565 14.669 -1.94528 -5.36576 -13.6524 0.0921265 0.515024
0.793415 4.72483 0.361293 4.4198 1.67015 0.0836167 0.41241
#Exciting G1:ACO-SQZ_PZT1_B_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.192083 0.990327 -3.11612 -0.990005 -0.0252233 0.122881 0.608081
0.997392 16.8454 1.61136 -0.683172 16.8315 0.0977331 0.487244
0.999425 30.0297 -1.56667 0.123933 -30.0294 0.0991105 0.465738
#Exciting G1:ACO-SQZ_PZT1_C_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.71961 4.72532 1.31027 1.21721 4.56585 0.132118 0.618566
0.70008 3.89402 -1.43107 0.542326 -3.85607 0.103487 0.511356
0.999754 25.7424 1.46135 2.81169 25.5884 0.0955571 0.467714
#Readbacks are G1:ACO-SQZ_NEAR_LONG_IN1 G1:ACO-SQZ_NEAR_ROT_IN1 G1:ACO-SQZ_NEAR_TILT_IN1
#Exciting G1:ACO-SQZ_PZT2_A_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.558503 4.15862 1.63113 -0.250751 4.15106 0.146808 0.763598
0.995459 12.6024 -1.92582 -4.38078 -11.8165 0.0929758 0.482889
0.873619 5.62799 -1.0451 2.82422 -4.86807 0.0897601 0.421024
#Exciting G1:ACO-SQZ_PZT2_B_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.639083 4.80032 1.48833 0.395426 4.78401 0.160152 0.759758
0.964263 7.66084 1.52645 0.339633 7.65331 0.0867127 0.465158
0.990807 10.3672 -1.55751 0.137782 -10.3663 0.10542 0.399544
#Exciting G1:ACO-SQZ_PZT2_C_EXC
1 1021.98 -0.390535 945.03 -389.05 4.30269 1.76577
0.908724 9.44992 -1.80416 -2.18528 -9.19378 0.137177 0.719538
0.843375 4.49605 1.51812 0.236722 4.48981 0.0951535 0.464607
0.998282 13.2523 1.27301 3.8883 12.6691 0.0883987 0.37966
PZT1 --> FAR
geo@geo-ws1 ~/tfricke/pzt-diag $ ./geo-pzt-check-matrix.csh
#Readbacks are G1:ACO-SQZ_FAR_LONG_IN1 G1:ACO-SQZ_FAR_ROT_IN1 G1:ACO-SQZ_FAR_TILT_IN1
#Exciting G1:ACO-SQZ_PZT1_ANALOG_ROT_EXC
1 1000.1 1.57282 -2.02476 1000.09 4.95325e-05 0.000361416
0.0569292 0.0106104 -1.72408 -0.00162007 -0.010486 0.00449158 0.0237199
0.990071 15.8945 -0.245151 15.4192 -3.85764 0.205525 0.220334
0.944824 4.54228 0.0890198 4.5243 0.403819 0.147695 0.147347
#Exciting G1:ACO-SQZ_PZT1_ANALOG_TILT_EXC
1 1000.1 1.57282 -2.02476 1000.09 4.95301e-05 0.000361401
0.034546 0.00551803 1.31027 0.00142139 0.00533181 0.00353371 0.0194948
0.926845 5.63038 2.63305 -4.91787 2.74148 0.231286 0.219409
0.991695 12.0972 -0.0888148 12.0495 -1.073 0.169927 0.14887
PZT1 --> NEAR
geo@geo-ws1 ~/tfricke/pzt-diag $ ./geo-pzt-check-matrix.csh
#Readbacks are G1:ACO-SQZ_NEAR_LONG_IN1 G1:ACO-SQZ_NEAR_ROT_IN1 G1:ACO-SQZ_NEAR_TILT_IN1
#Exciting G1:ACO-SQZ_PZT1_ANALOG_ROT_EXC
1 1000.1 1.57282 -2.02476 1000.09 4.95295e-05 0.000361429
0.950082 7.07809 0.116948 7.02974 0.825886 0.120856 0.237919
0.884069 2.71161 0.749573 1.98484 1.84749 0.11915 0.161293
0.947255 8.37327 -2.68921 -7.53101 -3.66001 0.28278 0.264932
#Exciting G1:ACO-SQZ_PZT1_ANALOG_TILT_EXC
1 1000.1 1.57282 -2.02476 1000.09 4.95331e-05 0.000361432
0.411134 1.04985 -0.586425 0.874449 -0.580975 0.11028 0.24066
0.982308 8.84789 -0.0450546 8.83891 -0.398503 0.132748 0.169499
0.647141 2.7542 1.38061 0.520655 2.70454 0.281432 0.265164
PZT2 --> FAR
geo@geo-ws1 ~/tfricke/pzt-diag $ ./geo-pzt-check-matrix.csh
#Readbacks are G1:ACO-SQZ_FAR_LONG_IN1 G1:ACO-SQZ_FAR_ROT_IN1 G1:ACO-SQZ_FAR_TILT_IN1
#Exciting G1:ACO-SQZ_PZT2_ANALOG_ROT_EXC
1 1000.1 1.57282 -2.02477 1000.09 4.95345e-05 0.000361379
0.029156 0.00509543 -1.15075 0.00207793 -0.00465248 0.00414506 0.0222266
0.991843 14.7239 -0.111244 14.6329 -1.63458 0.205899 0.18628
0.0872316 0.13032 2.66678 -0.115904 0.0595782 0.111794 0.132216
#Exciting G1:ACO-SQZ_PZT2_ANALOG_TILT_EXC
1 1000.1 1.57282 -2.02476 1000.09 4.95325e-05 0.000361414
0.0321904 0.00500004 -1.64974 -0.000394328 -0.00498446 0.00383255 0.0194094
0.173095 0.449465 2.7434 -0.4143 0.174282 0.244469 0.182396
0.982375 7.19157 -0.140928 7.12027 -1.01014 0.156051 0.128851
geo@geo-ws1 ~/tfricke/pzt-diag $ ./geo-pzt-check-matrix.csh
PZT2 --> NEAR
#Readbacks are G1:ACO-SQZ_NEAR_LONG_IN1 G1:ACO-SQZ_NEAR_ROT_IN1 G1:ACO-SQZ_NEAR_TILT_IN1
#Exciting G1:ACO-SQZ_PZT2_ANALOG_ROT_EXC
1 1000.1 1.57282 -2.02477 1000.09 4.95352e-05 0.000361434
0.934324 7.08682 0.0215302 7.08518 0.152569 0.128575 0.271934
0.591529 1.34535 0.366481 1.25601 0.482083 0.144026 0.163626
0.905033 6.44354 3.0526 -6.41805 0.572671 0.262809 0.286947
#Exciting G1:ACO-SQZ_PZT2_ANALOG_TILT_EXC
1 1000.1 1.57282 -2.02477 1000.09 4.95345e-05 0.000361424
0.580535 1.80713 -0.578366 1.51321 -0.987878 0.109079 0.275673
0.966847 6.49209 -0.0321863 6.48872 -0.20892 0.125678 0.171979
0.729716 3.52118 2.31905 -2.39567 2.58059 0.303829 0.254624
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment