-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCouplig_AO_Simulation.m
290 lines (246 loc) · 8.14 KB
/
Couplig_AO_Simulation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
%% Fiber Coupling Efficiency OOMAO
clear all;
% General Params
% npx - number of pixel per lenslet
% D - telescope diameter in meter
% Robs - Obscurecimiento central
% atm realisations
% nLenslet - numero de lentillas del detector SH (una más que el DM)
% r0 - Parameter Fried
% Sampling_time - Freq AO
% Lambda_comms - Data Wavelength in meters
% Tambien puede coger el valor de photometry.XXX
% Lambda_beacon - Beacon Wavelength in meters
% Link Distance - in meters
% iterations -
% ω0 represents the mode field radius of the fiber core
iterations = 1;
nPx = 360;
D = 0.5;
Robs = 0.34;
nLenslet = 12; % DM 11x11
r0 = 0.008; % ITEFI r0 = 1cm @ 850 nm -> 0.8cm @ 550nm
sampling_time = 1/2000; % AO freq
lambda_comms = photometry.FSOC; % Wavelengths data
lambda_beacon = photometry.R; % Wavelengths beacon
link_distance = 2e3;
% Fibre coupling params
w0=10e-6;
D_f = 0.195; % D/f optimum from coupling_Ruilier
% Closed loop params don't need to be defined each time
loopGain = 0.5;
loopIter = 2000;
loopIter_noCOrrection = 1000;
% DM doesn't need to be defined each iteration
comm_signal = source('wavelength',lambda_comms,'height',link_distance); %GEO 35876000
% Satellite beacon to measure
beacon = source('wavelength',lambda_beacon,'height',link_distance); %Beacon at 850nm
tel = telescope(D,...
'resolution',nPx,...
'obstructionRatio', Robs,...
'samplingTime',sampling_time);
wfs = shackHartmann(nLenslet,nPx,0.8);
beacon = beacon.*tel*wfs;
wfs.INIT
bif = influenceFunction('monotonic',50/100);
nActuator = nLenslet + 1;
dm = deformableMirror(nActuator,...
'modes',bif,...
'resolution',nPx,...
'validActuator',wfs.validActuator);
beacon=beacon.*tel;
dmCalib = calibration(dm,wfs,beacon,beacon.wavelength/40); %we can use a calibration source at 1550nm?
dmCalib.nThresholded = 10;
commandMatrix = dmCalib.M;
% Params for fiber coupling computation
lambda = comm_signal.wavelength;
% focal optima D/f = 0.22
f= tel.D/D_f;
% Crear mesh conveniente con el tamaño tel.D para las
% variables X e Y para el back propagated mode (fórmula Chen).
comm_signal = comm_signal.*tel;
EA = comm_signal.amplitude.*exp(1i.*comm_signal.phase);
sizeEA = size(EA,1);
X = (1:1:sizeEA) - 0.5*sizeEA;
X = tel.D*X/sizeEA;
Y = X';
FCE_atm = zeros(iterations,loopIter);
for i=1:iterations
clear ngs atm tel wfs
% Random seed
s = randi([1 1000],1);
s = RandStream('mt19937ar', 'seed', s);
% Satellite downlink to correct
comm_signal = source('wavelength',lambda_comms,'height',link_distance); %GEO 35876000
% Satellite beacon to measure
beacon = source('wavelength',lambda_beacon,'height',link_distance); %Beacon at 850nm
% ATMOSPHERE
atm = atmosphere(photometry.V,r0,30,...
'altitude',[0,0.5,1,2]*1e3,...
'fractionnalR0',[0.25,0.25,0.25,0.25],...
'windSpeed',[5,10,20,5],...
'windDirection',[0,pi/4,pi,pi],...
'randStream',s);
% atm = atmosphere(photometry.V,r0,30,...
% 'altitude',[0,4,10]*1e3,...
% 'fractionnalR0',[0.7,0.25,0.05],...
% 'windSpeed',[5,10,20],...
% 'windDirection',[0,pi/4,pi]);
% atm = ogsAtmosphere(10,1,'semilla',s);
% TELESCOPE
tel = telescope(D,...
'resolution',nPx,...
'obstructionRatio', Robs,...
'samplingTime',sampling_time);
% WFS
wfs = shackHartmann(nLenslet,nPx,0.8);
%
beacon = beacon.*tel*wfs;
wfs.INIT
%
tel = tel+atm;
% Resetting the DM command
dm.coefs = 0;
figure(11)
% subplot(1,2,1); imagesc(comm_signal.meanRmPhase);
% subplot(1,2,2); imagesc(beacon.meanRmPhase);
% drawnow;
for k=1:loopIter
sprintf('ATM iter: %d; AO loop iter: %d', i, k)
if k<=loopIter_noCOrrection
+tel;
comm_signal=comm_signal.*tel;
beacon = beacon.*tel;
dm.coefs = 0;
comm_signal=comm_signal*dm;
beacon = beacon*dm*wfs;
else
% Propagation throught the atmosphere to the telescope, +tel means that
% all the layers move of one step based on the sampling time and the
% wind vectors of the layers
+tel;
beacon = beacon.*tel*dm*wfs;
comm_signal=comm_signal.*tel*dm;
% % Saving the turbulence aberrated phase
% turbPhase = beacon.meanRmPhase;
% % % Variance of the atmospheric wavefront
% % total(k) = var(ngs);
% % Propagation to the WFS
% comm_signal=comm_signal*dm;
% beacon = beacon*dm*wfs;
% % Variance of the residual wavefront
% residue(k) = var(ngs);
% Computing the DM residual coefficients
residualDmCoefs = commandMatrix*wfs.slopes;
% Integrating the DM coefficients
dm.coefs = dm.coefs - loopGain*residualDmCoefs;
% Display of turbulence and residual phase
% gcf;
% subplot(1,2,1); imagesc(comm_signal.meanRmPhase);
% subplot(1,2,2); imagesc(beacon.meanRmPhase);
% % % set(h,'Cdata',[comm_signal.meanRmPhase,beacon.meanRmPhase])
% drawnow;
end
%% Chen
% % Aplicación de la fórmula encontrada en el artículo de Chen.
% % http://dx.doi.org/10.1364/AO.54.008722
% %
% % Sin atmósfera
% tel = tel - atm;
% ngs = ngs.*tel*wfs;
%
% % Onda propagada
% % amplitude = ngs.amplitude;
% % phase = ngs.phase;
% EA = ngs.amplitude.*exp(1i.*ngs.phase); % Dimensiones 250 x 250
% % % EA está "sampleado" en las dimensiones de la apertura del telescopio de
% % % tel.D de tamaño.
EA_atm = comm_signal.amplitude.*exp(1i.*comm_signal.meanRmPhase);
% [FCE(i),~] = eta_Chen(EA,w0,lambda,f,tel.D);
FCE_atm(i,k) = eta_Chen(EA_atm,w0,lambda,f,tel.D);
end
end
save('May23_ITEFI_FCE_WFS633_DM1550_1atm_100AOoff_2900AOon_12x12_sampling1_2000_D25_4cm', 'FCE_atm')
figure()
% plot([1:iterations],FCE);
% hold on;
plot([1:loopIter],FCE_atm);
% hold off;
% legend('w/o atmosphere', 'w/ atmosphere');
ylabel('Coupling Efficiency \eta');
xlabel('AO Loop Iterations');
%%
%
% figure()
% plot(tel.D./f,FCE_atm./max(FCE_atm));
% hold on;
% plot(tel.D./f,etaF_atm_check./max(etaF_atm_check),'+');
% hold off;
% % %% focal fija, diferentes atmósferas
% % focal_opt = tel.D/ra_max_atm;
% % iterations = 10;
% % etaF_EA1 = zeros(1,iterations);
% % for i = 1:iterations
% % ngs = ngs.*+tel*camH;
% % EA1 = ngs.amplitude.*exp(1i.*ngs.phase);
% % [etaF_EA1(i),~] = eta_Chen(EA1,w0,lambda,focal_opt,tel.D);
% % end
% % plot(1:iterations,etaF_EA1);
% %
% % k=2*pi/lambda;
%
% %% Diferentes "pasos de atmósfera" con diferentes focales
% Natm = 10;
% etaF_EA1 = zeros(Natm,size(f,2));
% for j = 1:Natm
% for k = 1:Natm
% ngs = ngs.*+tel*wfs;
% end
% EA_atm = ngs.amplitude.*exp(1i.*ngs.phase);
% for i = 1:size(f,2)
%
% [etaF_EA1(j,i),~] = eta_Chen(EA_atm,w0,lambda,f(i),tel.D);
% end
% end
% %%
% figure()
% hold on;
%
% for i =1:Natm
% txt = num2str(i);
% plot(tel.D./f,etaF_EA1(i,:),'DisplayName',txt);
% end
% hold off;
% legend show
%
%
% % check if wave changes
% before.amplitude = ngs.amplitude;
% before.phase = ngs.phase;
% ngs = ngs.*+tel*wfs;
% after.amplitude = ngs.amplitude;
% after.phase = ngs.phase;
% substraction = after.phase - before.phase;
%
% %% cambio manual de fase para propagar beam en otra direccion - CHECK
% beam0.phase = zeros(size(ngs.phase));
% beam0.amplitude = ngs.amplitude;
% fopt = tel.D/ra_max;
% wk = 2*pi/lambda/1e6;
% ivector = 0:wk/100:wk;
% eta_EA_beam0 = zeros(size(ivector));
% k=1;
% for index=ivector
% ph.max = index;
% ph.min = -ph.max;
% phaseVar = linspace(ph.min,ph.max,size(beam0.phase,1));
% beam0.phase = repmat(phaseVar,size(ngs.phase,1),1); % Todos los elementos de una misma columna tienen la misma fase (dirección y) que va cambiando linealmente con el cambio de columna.
% EA_beam0 = beam0.amplitude.*exp(1i.*beam0.phase);
%
% eta_EA_beam0(k) = eta_Chen(EA_beam0,w0,lambda,fopt,tel.D);
% k=k+1;
% end
% figure()
% plot(ivector,eta_EA_beam0);
%
% %%