Home > ALS > Booster > matchramp.m

matchramp

PURPOSE ^

To do:

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 To do:
 Get repeatibility of bend ramp AM
 Remove ILC linearity
 Try waveform correction
 Time range of correction?
 Is there a better BEND waveform to start with?
 Store the set waveforms to disk since you cann't get them.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % To do:
0002 % Get repeatibility of bend ramp AM
0003 % Remove ILC linearity
0004 % Try waveform correction
0005 % Time range of correction?
0006 % Is there a better BEND waveform to start with?
0007 % Store the set waveforms to disk since you cann't get them.
0008 
0009 
0010 
0011 clear
0012 
0013 % High frequency poles for the compensation
0014 Fc = 1000;
0015 
0016 
0017 %FileName = uigetfile('*.mat', 'Pick a ramp file', '/home/als/physdata/matlab/srdata/powersupplies/BQFQD_ramping_20070109/');
0018 
0019 if ispc
0020     %i = 69;
0021     %FileName = sprintf('C:\\greg\\Matlab\\machine\\ALS\\BoosterData\\123INJ\\PowerSupplies\\BQFQD_ramping_20070109\\coordinated_ramp_B_QF_QD_20070109_4kHz_%d.txt', i);
0022 
0023     i = 2;
0024     FileName = sprintf('C:\\greg\\Matlab\\machine\\ALS\\BoosterData\\123INJ\\PowerSupplies\\BQFQD_ramping_20070111\\coordinated_ramp_B_QF_QD_20070111_4kHz_%d.txt', i);
0025     %\\Als-filer\physdata\matlab\srdata\powersupplies\BQFQD_ramping_20070109
0026 else
0027     %i = 69;
0028     %FileName = sprintf('/home/als/physdata/matlab/srdata/powersupplies/BQFQD_ramping_20070109/coordinated_ramp_B_QF_QD_20070109_4kHz_%d.txt', i);
0029 
0030 %    i = 1;
0031 %    FileName = sprintf('/home/als/physdata/matlab/srdata/powersupplies/BQFQD_ramping_20070119/coordinated_ramp_B_QF_QD_20070119_4kHz_%d.txt', i);
0032 
0033 %    i = 8;
0034 %    FileName = sprintf('/home/als/physdata/matlab/srdata/powersupplies/BQFQD_ramping_current/test%d.txt', i)
0035 %    Directory = '/home/als/physdata/matlab/srdata/powersupplies/BQFQD_ramping_current/';
0036  
0037 Directory = '/home/als/physdata/matlab/srdata/powersupplies/BQFQD_ramping_20070124/';
0038 d = dir(Directory);
0039 FileName = [Directory d(end).name]
0040 end
0041 
0042 LineType = 'g';
0043 
0044 fid = fopen(FileName,'r');
0045 if fid == -1
0046     fprintf('   File open error.\n');
0047     return;
0048 end
0049 f = fscanf(fid, '%f\n', 1);
0050 N = fscanf(fid, '%f\n', 1);
0051 Data = fscanf(fid, '%f %f %f', [3 inf]);
0052 fclose(fid);
0053 
0054 Data = Data';
0055 Data(:,1) =  60 * Data(:,1);  %  60->New Quad, 48->Old Quad
0056 Data(:,2) =  60 * Data(:,2);  %  60->New Quad, 48->Old Quad
0057 Data(:,3) = 125 * Data(:,3);  % 125->New BEND, 80->Old BEND
0058 
0059 %80*newbqfqd12.data(end/2:end,3),
0060 %60*newbqfqd12.data(end/2:end,2)./(80*newbqfqd12.data(end/2:end,3))
0061 %60*newbqfqd12.data(end/2:end,1)./(80*newbqfqd12.data(end/2:end,3))
0062 
0063 
0064 % Cut the Data
0065 %Data = Data(2000:end,:);
0066 
0067 
0068 
0069 fs = 4000;
0070 t = (0:(size(Data,1)-1)) / fs;
0071 
0072 
0073 % Goal
0074 QFratio = Data(:,1)./Data(:,3); 
0075 QDratio = Data(:,2)./Data(:,3);
0076 
0077 
0078 if 1
0079     TimeFlag = 1;
0080     x = t;
0081     xLabelString = 'Time [Seconds]';
0082 else
0083     TimeFlag = 0;
0084     x = Data(:,3);
0085     xLabelString = 'BEND Current [Amps]';
0086 end
0087 
0088 
0089 figure(1);
0090 %clf reset
0091 subplot(4,1,1);
0092 plot(x, Data);
0093 legend('QF', 'QD', 'BEND', 'Location', 'NorthWest');
0094 axis tight;
0095 grid on;
0096 ylabel('[Amps]');
0097 title('New Bend, QF Compensation');
0098 
0099 subplot(4,1,2);
0100 plot(x, QFratio, LineType);
0101 hold on;
0102 plot([min(x) max(x)],[.520 .520],'r');
0103 hold off;
0104 ylabel('QF/BEND (Goal .520)');
0105 axis tight;
0106 yaxis([.45 .6]);
0107 grid on;
0108 
0109 orient tall
0110 
0111 
0112 figure(2);
0113 %clf reset
0114 subplot(4,1,1);
0115 plot(x, Data);
0116 legend('QF', 'QD', 'BEND', 'Location', 'NorthWest');
0117 axis tight;
0118 grid on;
0119 title('New Bend, QD Compensation');
0120 
0121 subplot(4,1,2);
0122 plot(x, QDratio, LineType);
0123 hold on;
0124 plot([min(x) max(x)],[.535 .535],'r');
0125 hold off;
0126 ylabel('QD/BEND (Goal .535)');
0127 axis tight;
0128 yaxis([.45 .6]);
0129 grid on;
0130 
0131 orient tall
0132 
0133 
0134 % Power supply TF
0135 w = 2 * pi * 10;
0136 sys = tf(1,[1/w 1]);
0137 %bode(H)
0138 
0139 
0140 %t = (0:0.00001:.25)';
0141 
0142 
0143 % Track the following system
0144 %QFratio = sin(2*pi*5*t);
0145 %QFratio = sin(2*pi*5*t) + .25*square(2*pi*5*t) - .25;
0146 %QFratio = step(sys, t);
0147 %randn('state',0);
0148 %QFratio = randn(length(t));
0149 %QFratio = QFratio(:);
0150 
0151 
0152 % The inverse system
0153 sysinv = tf([1/w 1],conv([1/Fc 1],[1/Fc 1]));
0154 
0155 
0156 % Put the error waveform through the inverse system
0157 QFErr = QFratio - .520;
0158 QDErr = QDratio - .535;
0159 
0160 % Zero the error until the system can be controlled (old bend)
0161 i = find(t < .01);
0162 QFErr(i) = 0;
0163 QDErr(i) = 0;
0164 
0165 % Slowly zero the error after the top of the ramp
0166 i = find(t > .85);
0167 QFErr(i) = linspace(QFErr(i(1)),0,length(i));
0168 QDErr(i) = linspace(QDErr(i(1)),0,length(i));
0169 
0170 [QFcommand, tinv, xinv] = lsim(sysinv, -QFErr, t);
0171 [QDcommand, tinv, xinv] = lsim(sysinv, -QDErr, t);
0172 
0173 
0174 % Simulate the result
0175 [QFsim, t1, x1] = lsim(sys, QFcommand, t);
0176 [QDsim, t1, x1] = lsim(sys, QDcommand, t);
0177 
0178 
0179 % % Put the offset back on
0180 % QFcommand = QFcommand + .520;
0181 % QDcommand = QDcommand + .520;
0182 % QFsim = QFsim + .535;
0183 % QDsim = QDsim + .535;
0184 
0185 
0186 figure(1);
0187 subplot(4,1,3);
0188 plot(x,[QFratio-.520 QFcommand QFsim QFratio-.535+QFsim]);
0189 ylabel('QF/BEND Error');
0190 legend('QF/BEND-.520', '\DeltaQFcommand', '\DeltaQFsim', 'QF/BEND-.535+\DeltaQFsim', 'Location', 'SouthWest');
0191 axis tight;
0192 %yaxis([-.1 .1]);
0193 grid on;
0194 
0195 subplot(4,1,4);
0196 plot(x, Data(:,3) .* QFcommand);
0197 ylabel('\DeltaQF [Amps]');
0198 xlabel(xLabelString);
0199 axis tight;
0200 %yaxis([-20 20]);
0201 grid on;
0202 
0203 
0204 figure(2);
0205 subplot(4,1,3);
0206 %plot(x, [QDratio QDcommand QDsim QDratio+QDsim]);
0207 plot(x, [QDratio-.535 QDcommand QDsim QDratio-.535+QDsim]);
0208 ylabel('QD/BEND Error');
0209 legend('QD/BEND-.535', '\DeltaQDcommand', '\DeltaQDsim', 'QD/BEND-.535+\DeltaQDsim', 'Location', 'SouthWest');
0210 axis tight;
0211 %yaxis([-.1 .1]);
0212 grid on;
0213 
0214 subplot(4,1,4);
0215 plot(x, Data(:,3) .* QDcommand);
0216 ylabel('\DeltaQD [Amps]');
0217 xlabel(xLabelString);
0218 axis tight;
0219 %yaxis([-20 20]);
0220 grid on;
0221 
0222 % ysim = 0;
0223 % clf
0224 % for i = 1:10
0225 %     Err = QFratio - ysim;
0226 %     [yr, tr, xr] = lsim(sysr, Err, t);
0227 %
0228 %     unew = unew + yr;
0229 %     [ysim, t1, x] = lsim(sys,unew,t);
0230 %
0231 %     plot(t,[unew(:) yr(:) ysim(:) QFratio(:)]);
0232 %
0233 %     legend('unew','yr','ysim','QFratio');
0234 %
0235 %     %[ysim, t1, x] = lsim(sys,unew,t);
0236 %     %plot(t,[unew(:) ysim(:) QFratio(:)]);
0237 %     %unew = unew + (QFratio-ysim(:)');
0238 %
0239 %     i; %pause;
0240 % end
0241 
0242 
0243

Generated on Thu 02-Aug-2007 13:16:07 by m2html © 2003