-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathanalyticalResponseFunctionsFun.m
1041 lines (937 loc) · 34.5 KB
/
analyticalResponseFunctionsFun.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [out,extra] = analyticalResponseFunctionsFun(p,w1_in,w3_in,options)
%Create simulated spectral data using an analytical form for the nth-order
%response function (see Hamm and Zanni Ch. 7 in particular).
% [OUT,EXTRA] = analyticalResponseFunctionsFun(P,W1_IN,W3_IN,OPTIONS) will
% generate a matrix with the simulated response in W1 and W3, based on the
% starting point (P) and options (OPTIONS) you provide.
%
% OPTIONS should be a structure with the fields:
%
% 't2_array' t2 values in ps, in array format, e.g.:
% [1 2 3 4 5]
% 'dt' Size of the timestep (0.4 is the default)
% 'n_t' Number of time points (64 is the default)
% 'noise' (optional)
% 'order' (optional) 1 -- First order (linear)
% 3 -- Third order (2D)
% 5 -- Fifth order (3D)
% 'w_0_cm' Now a fitting parameter -- allows variation
% of w_0 for the fit -- Leave this [].
% 'bootstrap' No bootstrapping for now (set as []).
% ----------------------
% 'damping' Gives the form of the correlation function
% 'pnames' Gives names for the inputs from P
% 'p0' Starting point.
%
% Damping determines the elements in pnames and p0. We'll
% have to make this a little more user friendly over time. The
% general form for OPTIONS.pnames is ~~:
% options.pnames = {'Delta (cm-1)','tau (ps)','anh (cm-1)',...
% 'mu12_2','w0 (cm-1)','phi (rad)'};
% ----------------------
%
%
% ALL TIME PARAMETERS ARE IN UNITS OF PICOSECONDS (ps). By default, this
% function currently simulates 3rd order (2D-IR) spectra.
%----------------------
% system properties
%----------------------
%specify the form and parameters of the frequency fluctuation correlation
%functions. Uncomment a block to use that form and its parameters
%
%%for a single overdamped motion
%damping = 'overdamped'; %i.e. exponential decay
%Delta_cm = 10; %linewidth (sigma) in wavenumbers
%tau = 2.; % correlation time in ps
%
%%for critical damping (slightly more oscillation in the correlation function)
%damping = 'critical';
%Delta_cm = 10; %linewidth (sigma) in wavenumbers
%tau = 2.; % correlation time in ps
%
%%for water one can use a fit to results from simulation (all parameters are
%%hard coded basically)
%damping = 'hynesform';
%
%for multiexponential decay (fast and slow motion).
%damping = 'multiexp';
damping = options.damping;
% Delta1_cm = 8;%linewidth (sigma) in wavenumbers of one motion
% Delta2_cm = 8;%linewidth (sigma) in wavenumbers of the other motion
% tau1 = 0.2; %first timescale (ps)
% tau2 = 15; %second timescale (ps)
%population times to calculate
%t2_array = 0.2; %ps (can be a single time)
%t2_array = [0.2 10 50]; %can be a vector of times
t2_array = options.t2_array; %can be a vector of times
%for 5th order also define t4 times (not used for 2DIR)
t4_array = t2_array;
n_t2_array = length(t2_array);
% THIS NEEDS FIXING!!!
%for an exponential c2(t)
%dt = 2*0.0021108; %ps
%dt = 0.02;
%n_t = 256; %number of time steps
flag_print = 0; %1 => figures or 0 => no figures
flag_plot = 0;
order = 3; %order of spectroscopy to calculate. 3 = 2DIR, 5 = 3DIR
if isfield(options,'dt')
dt = options.dt;
else
dt = 0.400;
end
if isfield(options,'n_t')
n_t = options.n_t;
else
n_t = 64;
end
w_0_cm = options.w_0_cm;% %center frequency
phi = 0; %phase shift (radians) exp(1i*phi)
mu01_2 = 1; %default
mu12_2 = 2; %default
%look to see if parameters from inputs
nparams = length(options.pnames);
for ii = 1:nparams
switch options.pnames{ii}
case 'w0 (cm-1)'
w_0_cm = p(ii);
case 'mu01_2'
mu01_2 = p(ii);
case 'mu12_2'
mu12_2 = p(ii);
case 'phi (rad)'
phi = p(ii);
case 'phi (deg)'
phi = p(ii)*pi/180;
end
end
%check for what order (third
if isfield(options,'order')
order = options.order;
end
flag_rotating_frame = true;
if isfield(options,'flag_rotating_frame')
flag_rotating_frame = options.flag_rotating_frame;
end
two_level_system = false;
%two_level_system = true;
flag_bootstrap = false;
if isfield(options,'bootstrap')
if ~isempty(options.bootstrap)
flag_bootstrap = true;
bootstrap_index = options.bootstrap;
end
end
%details of fft
%fft_type = 'fft';
%fft_type = 'petersfft';
fft_type = 'sgrsfft';
n_interp = 1; %number of points of linear interpolation to use
n_zp = 2*n_t; %total length after zeropadding
%(make n_zp=n_t for no zero padding)
n_under = 0;%2;
apodization = 'none';
%apodization = 'triangular';
%apodization = 'gaussian';
%type of projection to calculate
%projection_type = 'window';
projection_type = 'all';
%simulate noise
if isfield(options,'noise')
if isempty(options.noise)
noise = 0;
else
noise = options.noise;
end
else
noise = 0;
end
% simulate laser bandwidth
simulate_bandwidth = false;
%simulate_bandwidth = true;
bandwidth = 180; %cm-1 fwhm
bandwidth_axes = 2; %2 for scaled by LO spectrum, 3 for without
%
% Body of the calculation
%
extra = [];
%-------------------------------------------------------------
%
% start calculation
%
%-------------------------------------------------------------
c = 2.9979e10;
wavenumbersToInvPs=c*1e-12;
invPsToWavenumbers=1/wavenumbersToInvPs;
c_cmfs = c*1e-15;
t=0:dt:(n_t-1)*dt;
w = fftFreqAxis(t,...
'time_units','ps',...
'freq','wavenumbers',...
'shift','on',...
'zeropad',n_zp,...
'undersampling',n_under);
if flag_rotating_frame
w = w + w_0_cm;
end
dw = w(2)-w(1);
w_0 = w_0_cm*2*pi*wavenumbersToInvPs; %convert to radians
if ~exist('orientational_response','var')
%if it is not defined then assume you don't care
orientational_response = false;
end
% if orientational_response
% disp('Using orentational response functions');
% else
% disp('No orentational response functions');
% end
c2 = [];
g = [];
switch damping,
case 'voigt'
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
T2 = p(2); %first timescale (ps)
anh_cm = p(3);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
anh = anh_cm*wavenumbersToInvPs*2*pi;
c2 = @(t) (t==0)/T2 + Delta1^2;
g = @(t) t./T2 + Delta1^2/2.*t.^2;
case {'overdamped', '1exp'}
%overdamped exp(-t/tau)
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
tau1 = p(2); %first timescale (ps)
anh_cm = p(3);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
anh = anh_cm*wavenumbersToInvPs*2*pi;
c2 = @(t) Delta1^2.*exp(-Lambda1.*t);
g = @(t) Delta1^2/Lambda1^2.*(exp(-Lambda1.*t)-1+Lambda1.*t);
case {'1exp1fast'}
%overdamped exp(-t/tau)
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
tau1 = p(2); %first timescale (ps)
T2 = p(3); %T2 time (fast process)
anh_cm = p(4);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
anh = anh_cm*wavenumbersToInvPs*2*pi;
c2 = @(t) (t==0)/T2 + Delta1^2.*exp(-Lambda1.*t);
g = @(t) t./T2 + Delta1^2/Lambda1^2.*(exp(-Lambda1.*t)-1+Lambda1.*t);
case {'1exp1slow'}
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
tau1 = p(2);%first motion's timescale (ps)
Delta2_cm = p(3);%linewidth (sigma) in wavenumbers of the inhomogeneous component
anh_cm = p(4); %Anharmonicity in wavenumbers
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
anh = anh_cm*wavenumbersToInvPs*2*pi;
c2 = @(t) Delta1^2.*exp(-Lambda1.*t) ...
+ Delta2^2;
g = @(t) Delta1^2/Lambda1^2.*(exp(-Lambda1.*t)-1+Lambda1.*t) ...
+ (Delta2^2).*t.^2/2;
case {'1exp1fast1slow'}
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
tau1 = p(2);%first motion's timescale (ps)
Delta2_cm = p(3);%linewidth (sigma) in wavenumbers of the inhomogeneous component
T2 = p(4); %Homogeneous dephasing time
anh_cm = p(5); %Anharmonicity in wavenumbers
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
anh = anh_cm*wavenumbersToInvPs*2*pi;
c2 = @(t) (t==0)/T2 + Delta1^2.*exp(-Lambda1.*t) ...
+ Delta2^2;
g = @(t) t./T2 + Delta1^2/Lambda1^2.*(exp(-Lambda1.*t)-1+Lambda1.*t) ...
+ (Delta2^2).*t.^2/2;
case {'2exp1fast'}
% Developed for use with Zhe's SCN- data in ILs, where he has two
% inhomogeneous timescales, one longer, and one shorter.
% Expanded form of '1exp1fast' above --Tom
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
tau1 = p(2);%first timescale (ps)
Delta2_cm = p(3); %linewidth of second motion
tau2 = p(4); %second timescale (ps)
T2 = p(5); %T2 time (fast / homogeneous processes)
anh_cm = p(6);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Lambda2 = 1/tau2;
anh = anh_cm*wavenumbersToInvPs*2*pi;
c2 = @(t) (t==0)/T2 + Delta1^2.*exp(-Lambda1.*t) ...
+ Delta2^2.*exp(-Lambda2.*t);
g = @(t) t./T2 + Delta1^2/Lambda1^2.*(exp(-Lambda1.*t)-1+Lambda1.*t) ...
+ Delta2^2/Lambda2^2.*(exp(-Lambda2.*t)-1+Lambda2.*t);
case {'2exp1fast1slow'}
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
tau1 = p(2);%first motion's timescale (ps)
Delta2_cm = p(3);%linewidth (sigma) in wavenumbers of the other motion
tau2 = p(4);%second motion's timescale (ps)
Delta3_cm = p(5);%linewidth (sigma) in wavenumbers of the inhomogeneous component
T2 = p(6); %Homogeneous dephasing time
anh_cm = p(7); %Anharmonicity in wavenumbers
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Lambda2 = 1/tau2;
Delta3 = Delta3_cm*wavenumbersToInvPs*2*pi;
anh = anh_cm*wavenumbersToInvPs*2*pi;
c2 = @(t) (t==0)/T2 + Delta1^2.*exp(-Lambda1.*t) ...
+ Delta2^2.*exp(-Lambda2.*t) + Delta3^2;
g = @(t) t./T2 + Delta1^2/Lambda1^2.*(exp(-Lambda1.*t)-1+Lambda1.*t) ...
+ Delta2^2/Lambda2^2.*(exp(-Lambda2.*t)-1+Lambda2.*t) + (Delta3^2).*t.^2/2;
case {'2exp1slow'}
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
tau1 = p(2);%first motion's timescale (ps)
Delta2_cm = p(3);%linewidth (sigma) in wavenumbers of the other motion
tau2 = p(4);%second motion's timescale (ps)
Delta3_cm = p(5);%linewidth (sigma) in wavenumbers of the inhomogeneous component
anh_cm = p(6); %Anharmonicity in wavenumbers
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Lambda2 = 1/tau2;
Delta3 = Delta3_cm*wavenumbersToInvPs*2*pi;
anh = anh_cm*wavenumbersToInvPs*2*pi;
c2 = @(t) Delta1^2.*exp(-Lambda1.*t) ...
+ Delta2^2.*exp(-Lambda2.*t) + Delta3^2;
g = @(t) Delta1^2/Lambda1^2.*(exp(-Lambda1.*t)-1+Lambda1.*t) ...
+ Delta2^2/Lambda2^2.*(exp(-Lambda2.*t)-1+Lambda2.*t) + (Delta3^2).*t.^2/2;
case {'3exp1fast'}
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
tau1 = p(2);%first timescale (ps)
Delta2_cm = p(3); %linewidth of second motion
tau2 = p(4); %second timescale (ps)
Delta3_cm = p(5);
tau3 = p(6);
T2 = p(7); %T2 time (fast / homogeneous processes)
anh_cm = p(8);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Lambda2 = 1/tau2;
Delta3 = Delta3_cm*wavenumbersToInvPs*2*pi;
Lambda3 = 1/tau3;
anh = anh_cm*wavenumbersToInvPs*2*pi;
c2 = @(t) (t==0)/T2 + Delta1^2.*exp(-Lambda1.*t) ...
+ Delta2^2.*exp(-Lambda2.*t) + Delta3^2.*exp(-Lambda3.*t);
g = @(t) t./T2 + Delta1^2/Lambda1^2.*(exp(-Lambda1.*t)-1+Lambda1.*t) ...
+ Delta2^2/Lambda2^2.*(exp(-Lambda2.*t)-1+Lambda2.*t) ...
+ Delta3^2/Lambda3^2.*(exp(-Lambda3.*t)-1+Lambda3.*t);
case 'critical'
%critically damped (1+2t/tau)exp(-2t/tau)
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
tau1 = p(2); %first timescale (ps)
anh_cm = p(3);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
anh = anh_cm*wavenumbersToInvPs*2*pi;
c2 = @(t) Delta1^2.*(1+2*Lambda1.*t).*exp(-2*Lambda1.*t);
g = @(t) Delta1^2/4/Lambda1^2.*exp(-2.*Lambda1.*t) ...
.*(3 + 2*Lambda1*t + exp(2.*Lambda1.*t).*(4*Lambda1.*t - 3));
case '2expcrit'
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
Delta2_cm = p(2);%linewidth (sigma) in wavenumbers of the other motion
tau1 = p(3); %first timescale (ps)
tau2 = p(4); %second timescale (ps)
anh_cm = p(5);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Lambda2 = 1/tau2;
anh = anh_cm*wavenumbersToInvPs*2*pi;
g = @(t) Delta1^2/4/Lambda1^2 ...
.*(3.*exp(-2.*Lambda1.*t) + 2*Lambda1*t.*exp(-2.*Lambda1.*t) + (4*Lambda1.*t - 3)) ...
+ Delta2^2/4/Lambda2^2 ...
.*(3.*exp(-2.*Lambda2.*t) + 2*Lambda2*t.*exp(-2.*Lambda2.*t) + (4*Lambda2.*t - 3));
case '3expcrit'
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
Delta2_cm = p(2);%linewidth (sigma) in wavenumbers of the other motion
Delta3_cm = p(3);%linewidth (sigma) in wavenumbers of the other motion
tau1 = p(4); %first timescale (ps)
tau2 = p(5); %second timescale (ps)
tau3 = p(6); %second timescale (ps)
anh_cm = p(7);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Delta3 = Delta3_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Lambda2 = 1/tau2;
Lambda3 = 1/tau3;
anh = anh_cm*wavenumbersToInvPs*2*pi;
g = @(t) Delta1^2/4/Lambda1^2 ...
.*(3.*exp(-2.*Lambda1.*t) + 2*Lambda1*t.*exp(-2.*Lambda1.*t) + (4*Lambda1.*t - 3)) ...
+ Delta2^2/4/Lambda2^2 ...
.*(3.*exp(-2.*Lambda2.*t) + 2*Lambda2*t.*exp(-2.*Lambda2.*t) + (4*Lambda2.*t - 3)) ...
+ Delta3^2/4/Lambda3^2 ...
.*(3.*exp(-2.*Lambda3.*t) + 2*Lambda3*t.*exp(-2.*Lambda3.*t) + (4*Lambda3.*t - 3));
case '3exp1offcrit'
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
Delta2_cm = p(2);%linewidth (sigma) in wavenumbers of the other motion
Delta3_cm = p(3);%linewidth (sigma) in wavenumbers of the other motion
Delta4_cm = p(4);%linewidth (sigma) in wavenumbers of static component
tau1 = p(5); %first timescale (ps)
tau2 = p(6); %second timescale (ps)
tau3 = p(7); %second timescale (ps)
anh_cm = p(8);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Delta3 = Delta3_cm*wavenumbersToInvPs*2*pi;
Delta4 = Delta4_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Lambda2 = 1/tau2;
Lambda3 = 1/tau3;
anh = anh_cm*wavenumbersToInvPs*2*pi;
g = @(t) Delta1^2/4/Lambda1^2 ...
.*(3.*exp(-2.*Lambda1.*t) + 2*Lambda1*t.*exp(-2.*Lambda1.*t) + (4*Lambda1.*t - 3)) ...
+ Delta2^2/4/Lambda2^2 ...
.*(3.*exp(-2.*Lambda2.*t) + 2*Lambda2*t.*exp(-2.*Lambda2.*t) + (4*Lambda2.*t - 3)) ...
+ Delta3^2/4/Lambda3^2 ...
.*(3.*exp(-2.*Lambda3.*t) + 2*Lambda3*t.*exp(-2.*Lambda3.*t) + (4*Lambda3.*t - 3)) ...
+ Delta4^2.*t.^2/2;
case '2exp'
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
Delta2_cm = p(2);%linewidth (sigma) in wavenumbers of the other motion
tau1 = p(3); %first timescale (ps)
tau2 = p(4); %second timescale (ps)
anh_cm = p(5);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Lambda2 = 1/tau2;
anh = anh_cm*wavenumbersToInvPs*2*pi;
g = @(t) Delta1^2/Lambda1^2 ...
.*(exp(-Lambda1.*t) - 1 + Lambda1*t) ...
+ Delta2^2/Lambda2^2 ...
.*(exp(-Lambda2.*t) - 1 + Lambda2*t);
case '3exp'
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
Delta2_cm = p(2);%linewidth (sigma) in wavenumbers of the other motion
Delta3_cm = p(3);%linewidth (sigma) in wavenumbers of the other motion
tau1 = p(4); %first timescale (ps)
tau2 = p(5); %second timescale (ps)
tau3 = p(6); %second timescale (ps)
anh_cm = p(7);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Delta3 = Delta3_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Lambda2 = 1/tau2;
Lambda3 = 1/tau3;
anh = anh_cm*wavenumbersToInvPs*2*pi;
g = @(t)Delta1^2/Lambda1^2 ...
.*(exp(-Lambda1.*t) - 1 + Lambda1*t) ...
+ Delta2^2/Lambda2^2 ...
.*(exp(-Lambda2.*t) - 1 + Lambda2*t) ...
+ Delta3^2/Lambda3^2 ...
.*(exp(-Lambda3.*t) - 1 + Lambda3*t);
case '5exp'
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
Delta2_cm = p(2);%linewidth (sigma) in wavenumbers of the other motion
Delta3_cm = p(3);%linewidth (sigma) in wavenumbers of the other motion
Delta4_cm = p(4);
Delta5_cm = p(5);
tau1 = p(6); %first timescale (ps)
tau2 = p(7); %second timescale (ps)
tau3 = p(8); %second timescale (ps)
tau4 = p(9);
tau5 = p(10);
anh_cm = p(11);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Delta3 = Delta3_cm*wavenumbersToInvPs*2*pi;
Delta4 = Delta4_cm*wavenumbersToInvPs*2*pi;
Delta5 = Delta5_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Lambda2 = 1/tau2;
Lambda3 = 1/tau3;
Lambda4 = 1/tau4;
Lambda5 = 1/tau5;
anh = anh_cm*wavenumbersToInvPs*2*pi;
g = @(t)Delta1^2/Lambda1^2.*(exp(-Lambda1.*t) - 1 + Lambda1*t) ...
+ Delta2^2/Lambda2^2.*(exp(-Lambda2.*t) - 1 + Lambda2*t) ...
+ Delta3^2/Lambda3^2.*(exp(-Lambda3.*t) - 1 + Lambda3*t) ...
+ Delta4^2/Lambda4^2.*(exp(-Lambda4.*t) - 1 + Lambda4*t) ...
+ Delta5^2/Lambda5^2.*(exp(-Lambda5.*t) - 1 + Lambda5*t);
case 'toms_5exp_T1_or_rlx'
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
Delta2_cm = p(2);%linewidth (sigma) in wavenumbers of the other motion
Delta3_cm = p(3);%linewidth (sigma) in wavenumbers of the other motion
Delta4_cm = p(4);
Delta5_cm = p(5);
tau1 = p(6); %first timescale (ps)
tau2 = p(7); %second timescale (ps)
tau3 = p(8); %second timescale (ps)
tau4 = p(9);
tau5 = p(10);
T_or = p(11);
T1 = p(12);
anh_cm = p(13);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Delta3 = Delta3_cm*wavenumbersToInvPs*2*pi;
Delta4 = Delta4_cm*wavenumbersToInvPs*2*pi;
Delta5 = Delta5_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Lambda2 = 1/tau2;
Lambda3 = 1/tau3;
Lambda4 = 1/tau4;
Lambda5 = 1/tau5;
anh = anh_cm*wavenumbersToInvPs*2*pi;
g = @(t)Delta1^2/Lambda1^2.*(exp(-Lambda1.*t) - 1 + Lambda1*t) ...
+ Delta2^2/Lambda2^2.*(exp(-Lambda2.*t) - 1 + Lambda2*t) ...
+ Delta3^2/Lambda3^2.*(exp(-Lambda3.*t) - 1 + Lambda3*t) ...
+ Delta4^2/Lambda4^2.*(exp(-Lambda4.*t) - 1 + Lambda4*t) ...
+ Delta5^2/Lambda5^2.*(exp(-Lambda5.*t) - 1 + Lambda5*t) ...
+ t./(3*T_or) + t./(2*T1);
case '3exp1off'
Delta1_cm = p(1);%linewidth (sigma) in wavenumbers of one motion
Delta2_cm = p(2);%linewidth (sigma) in wavenumbers of the other motion
Delta3_cm = p(3);%linewidth (sigma) in wavenumbers of the other motion
Delta4_cm = p(4);%linewidth (sigma) in wavenumbers of static component
tau1 = p(5); %first timescale (ps)
tau2 = p(6); %second timescale (ps)
tau3 = p(7); %second timescale (ps)
anh_cm = p(8);
Delta1 = Delta1_cm*wavenumbersToInvPs*2*pi;
Delta2 = Delta2_cm*wavenumbersToInvPs*2*pi;
Delta3 = Delta3_cm*wavenumbersToInvPs*2*pi;
Delta4 = Delta4_cm*wavenumbersToInvPs*2*pi;
Lambda1 = 1/tau1;
Lambda2 = 1/tau2;
Lambda3 = 1/tau3;
anh = anh_cm*wavenumbersToInvPs*2*pi;
g = @(t)Delta1^2/Lambda1^2 ...
.*(exp(-Lambda1.*t) - 1 + Lambda1*t) ...
+ Delta2^2/Lambda2^2 ...
.*(exp(-Lambda2.*t) - 1 + Lambda2*t) ...
+ Delta3^2/Lambda3^2 ...
.*(exp(-Lambda3.*t) - 1 + Lambda3*t) ...
+ Delta4^2.*t.^2/2;
case 'hynesform'
%fit c2 to hynes type function, double integrate with Mathematica
%to find g(t)
a1 = 0.3232;
k11 = 30.01; %ps-1
k12 = 17.41; %ps-1
a2 = 0.3378;
k2 = 8.270; %ps-1
a3 = 0.3455;
k3 = 1.897; %ps-1
%yuck
g = @(t) Delta^2*exp(-t.*(k12+k2+k3))/(k2^2*k3^2*(k11^2+k12^2)^2) ...
.*(a1*k2^2*k3^2.*exp((k2+k3).*t).*(cos(k11.*t).*(k12^2-k11^2)-2*k11*k12*sin(k11*t) ...
+ exp(k12.*t).*(k11^2*(k12.*t+1)+k12^2*(k12.*t-1))) ...
+ (k11^2+k12^2)^2.*exp(k12.*t).*(a3*k2^2*exp(k2.*t).*(exp(k3.*t).*(k3.*t-1)+1) ...
+a2*k3^2*exp(k3.*t).*(exp(k2.*t).*(k2*t-1)+1)));
otherwise
error('damping value is unknown');
end
if order==1
%S = exp(-g(t)).*cos(w_0.*t);
S1 = exp(-g(t));
%S2 = exp(-g(t)).*cos(w_0.*t).*(2-2*exp(-sqrt(-1)*anh.*t));
switch fft_type
case 'fft'
%disp('fft')
S = fftshift(real(fft(S1,n_zp)));
%S2 = fftshift(real(fft(S2)));
case 'petersfft'
%disp('peter''s fft')
S = fftshift(real(petersfft(S1,n_interp)));
%S2 = fftshift(real(petersfft(S2,n_interp)));
case 'sgrsfft'
%disp('sgr''s fft')
S = fftshift(real(sgrsfft(S1,n_zp)));
%S2 = fftshift(real(sgrsfft(S2)));
end
s.c2 = c2(t);
s.g = g(t);
s.S1 = S1;
s.t = t;
extra = s;
out = interp1(w,S,w1_in,'pchip');
return
end
if order==3
P = zeros(length(w3_in),length(w1_in)); %signle time step
out = zeros(length(w3_in),length(w1_in),n_t2_array); %array for output
[T1,T3] = meshgrid(t,t);
for i=1:n_t2_array
t2 = t2_array(i);
%letting P1 and P2 be complex seems to work
% P1=fft2(exp(sqrt(-1)*w_0.*(-T1+T3)).*exp(-g(T1+phi)+g(t2)-g(T3)-g(T1+phi+t2)-g(t2+T3)+g(T1+phi+t2+T3)).*(2-2.*exp(-sqrt(-1)*anh.*T3)));
% P2=fft2(exp(sqrt(-1)*w_0.*(T1+T3)).*exp(-g(T1-phi)-g(t2)-g(T3)+g(T1-phi+t2)+g(t2+T3)-g(T1-phi+t2+T3)).*(2-2.*exp(-sqrt(-1)*anh.*T3)));
%taking the real part also seems to work
% P1=fft2(real(exp(sqrt(-1)*w_0.*(-T1+T3)).*exp(-g(T1+phi)+g(t2)-g(T3)-g(T1+phi+t2)-g(t2+T3)+g(T1+phi+t2+T3)).*(2-2.*exp(-sqrt(-1)*anh.*T3))));
% P2=fft2(real(exp(sqrt(-1)*w_0.*(T1+T3)).*exp(-g(T1-phi)-g(t2)-g(T3)+g(T1-phi+t2)+g(t2+T3)-g(T1-phi+t2+T3)).*(2-2.*exp(-sqrt(-1)*anh.*T3))));
if two_level_system
%disp('two level system')
P1=real(exp(-1i*w_0.*(-T1+T3)+1i*phi).*exp(-g(T1)+g(t2)-g(T3)-g(T1+t2)-g(t2+T3)+g(T1+t2+T3)));
P2=real(exp(-1i*w_0.*(T1+T3)+1i*phi).*exp(-g(T1)-g(t2)-g(T3)+g(T1+t2)+g(t2+T3)-g(T1+t2+T3)));
else
%disp('multilevel system')
%P1=real(exp(1i*w_0.*(-T1+T3)+1i*phi).*exp(-g(T1)+g(t2)-g(T3)-g(T1+t2)-g(t2+T3)+g(T1+t2+T3)).*(2-2.*exp(-sqrt(-1)*anh.*T3)));
%P2=real(exp(1i*w_0.*(T1+T3)+1i*phi).*exp(-g(T1)-g(t2)-g(T3)+g(T1+t2)+g(t2+T3)-g(T1+t2+T3)).*(2-2.*exp(-sqrt(-1)*anh.*T3)));
P1=exp(-g(T1)+g(t2)-g(T3)-g(T1+t2)-g(t2+T3)+g(T1+t2+T3)).*(2*mu01_2-mu12_2.*exp(-1i*anh.*T3));
P2=exp(-g(T1)-g(t2)-g(T3)+g(T1+t2)+g(t2+T3)-g(T1+t2+T3)).*(2*mu01_2-mu12_2.*exp(-1i*anh.*T3));
end
P1 = exp(1i*phi).*P1;
P2 = exp(-1i*phi).*P2;
if flag_rotating_frame == false
P1 = exp(1i*w_0.*(-T1+T3)).*P1;
P2 = exp(1i*w_0.*(T1+T3)).*P2;
end
if orientational_response
r = orientationalResponse(tau_R,3,T1,t2,T3);
P1 = P1.*r;
P2 = P2.*r;
end
switch lower(apodization)
case 'triangular'
%disp('triangular apodization')
x = 1:-1/(n_t-1):0;
window_fxn = zeros(n_t,n_t);
for j=1:n_t,
for k = 1:n_t
window_fxn(j,k) =x(j)*x(k);
end
end
P1 = P1.*window_fxn;
P2 = P2.*window_fxn;
case {'gauss','gaussian'}
%disp('gaussian apodization')
window_fxn = exp(-(T1.^2+T3.^2)./(2*(n_t*dt/2)^2));
P1 = P1.*window_fxn;
P2 = P2.*window_fxn;
case 'none'
%disp('no apodization')
end
if noise>0
P1 = P1+max(max(real(P1)))*noise.*rand(size(P1));
P2 = P2+max(max(real(P2)))*noise.*rand(size(P2));
end
if flag_plot
figure(1),clf
my2dPlot(t,t,real(P1),12)
figure(2),clf
my2dPlot(t,t,real(P2),12)
x = real(P1);
end
%do fft
switch fft_type
case 'fft'
P1 = fft2(P1,n_zp,n_zp);
P2 = fft2(P2,n_zp,n_zp);
case 'petersfft'
P1=petersfft2(P1,n_interp);
P2=petersfft2(P2,n_interp);
case 'sgrsfft'
P1=sgrsfft2(P1,n_zp);
P2=sgrsfft2(P2,n_zp);
end
%change how data packaged
P=-fftshift(real(fliplr(circshift(P1,[0 -1]))+P2));
%simulate laser bandwidth
if simulate_bandwidth
%disp(['2D simulating laser bandwidth ' num2str(bandwidth) ' cm-1 fwhm, for ' num2str(bandwidth_axes-1) ' axis' ]);
[W1,W3]=meshgrid(w);
switch bandwidth_axes
case 3
BW = exp(-((W1-w_0)+(W3-w_0)).^2 ...
./(2*(bandwidth/2.355)^2));
case 2
BW = exp(-(W1-w_0).^2 ...
./(2*(bandwidth/2.355)^2));
end
P = P.*BW;
else
%disp('2D not simulating bandwidth');
end
[W1,W3] = meshgrid(w,w);
P = P./abs(min(P(:))); %normalize to the 01 band (negative)
out(:,:,i) = interp2(W1,W3,P,w1_in,w3_in','*linear');
end %end t2_array loop
if flag_bootstrap
out = out(bootstrap_index);
end
try
s.c2 = c2(t);
s.g = g(t);
s.t = t;
extra = s;
end
end %end if order 3
if order==5
R = cell(1,n_t2_array);
for i = 1:n_t2_array
%set up the time variables
[T1,T3,T5] = meshgrid(t,t,t);
t2 = t2_array(i);
t4 = t4_array(i);
%cumulant expansion results for response functions
if two_level_system
R1 =exp(1i*w_0.*(T1+T3+T5)+1i*phi).*...
exp(-g(T1)-g(t2)-g(T3)-g(t4)-g(T5) ...
+g(T1+t2)+g(t2+T3)+g(T3+t4)+g(t4+T5) ...
-g(T1+t2+T3)-g(t2+T3+t4)-g(T3+t4+T5) ...
+g(T1+t2+T3+t4)+g(t2+T3+t4+T5) ...
-g(T1+t2+T3+t4+T5));
R2 =exp(1i*w_0.*(-T1+T3+T5)+1i*phi).*...
exp(-g(T1)+g(t2)-g(T3)-g(t4)-g(T5) ...
-g(T1+t2)-g(t2+T3)+g(T3+t4)+g(t4+T5) ...
+g(T1+t2+T3)+g(t2+T3+t4)-g(T3+t4+T5) ...
-g(T1+t2+T3+t4)-g(t2+T3+t4+T5) ...
+g(T1+t2+T3+t4+T5));
R3 =exp(1i*w_0.*(T1-T3+T5)+1i*phi).*...
exp(-g(T1)+g(t2)-g(T3)+g(t4)-g(T5) ...
-g(T1+t2)-g(t2+T3)-g(T3+t4)-g(t4+T5) ...
+g(T1+t2+T3)-g(t2+T3+t4)+g(T3+t4+T5) ...
+g(T1+t2+T3+t4)+g(t2+T3+t4+T5) ...
-g(T1+t2+T3+t4+T5));
R4 =exp(1i*w_0.*(-T1-T3+T5)+1i*phi).*...
exp(-g(T1)-g(t2)-g(T3)+g(t4)-g(T5) ...
+g(T1+t2)+g(t2+T3)-g(T3+t4)-g(t4+T5) ...
-g(T1+t2+T3)+g(t2+T3+t4)+g(T3+t4+T5) ...
-g(T1+t2+T3+t4)-g(t2+T3+t4+T5) ...
+g(T1+t2+T3+t4+T5));
else
R1 =exp(1i*w_0.*(T1+T3+T5)+1i*phi).*...
exp(-g(T1)-g(t2)-g(T3)-g(t4)-g(T5) ...
+g(T1+t2)+g(t2+T3)+g(T3+t4)+g(t4+T5) ...
-g(T1+t2+T3)-g(t2+T3+t4)-g(T3+t4+T5) ...
+g(T1+t2+T3+t4)+g(t2+T3+t4+T5) ...
-g(T1+t2+T3+t4+T5)).* ...
(4-8*exp(-1i*anh.*(T3+T5)) ...
-4*exp(-1i*anh.*T5) ...
+6*exp(-1i*anh.*(T3+2*T5)) ...
+2*exp(-1i*anh*T3));
R2 =exp(1i*w_0.*(-T1+T3+T5)+1i*phi).*...
exp(-g(T1)+g(t2)-g(T3)-g(t4)-g(T5) ...
-g(T1+t2)-g(t2+T3)+g(T3+t4)+g(t4+T5) ...
+g(T1+t2+T3)+g(t2+T3+t4)-g(T3+t4+T5) ...
-g(T1+t2+T3+t4)-g(t2+T3+t4+T5) ...
+g(T1+t2+T3+t4+T5)).* ...
(4-8*exp(-1i*anh.*(T3+T5)) ...
-4*exp(-1i*anh.*T5) ...
+6*exp(-1i*anh.*(T3+2*T5)) ...
+2*exp(-1i*anh*T3));
R3 =exp(1i*w_0.*(T1-T3+T5)+1i*phi).*...
exp(-g(T1)+g(t2)-g(T3)+g(t4)-g(T5) ...
-g(T1+t2)-g(t2+T3)-g(T3+t4)-g(t4+T5) ...
+g(T1+t2+T3)-g(t2+T3+t4)+g(T3+t4+T5) ...
+g(T1+t2+T3+t4)+g(t2+T3+t4+T5) ...
-g(T1+t2+T3+t4+T5)).* ...
(4-8*exp(-1i*anh.*(T5-T3)) ...
-4*exp(-1i*anh.*T5) ...
+6*exp(-1i*anh.*(2*T5-T3)) ...
+2*exp(1i*anh*T3));
R4 =exp(1i*w_0.*(-T1-T3+T5)+1i*phi).*...
exp(-g(T1)-g(t2)-g(T3)+g(t4)-g(T5) ...
+g(T1+t2)+g(t2+T3)-g(T3+t4)-g(t4+T5) ...
-g(T1+t2+T3)+g(t2+T3+t4)+g(T3+t4+T5) ...
-g(T1+t2+T3+t4)-g(t2+T3+t4+T5) ...
+g(T1+t2+T3+t4+T5)).* ...
(4-8*exp(-1i*anh.*(T5-T3)) ...
-4*exp(-1i*anh.*T5) ...
+6*exp(-1i*anh.*(2*T5-T3)) ...
+2*exp(1i*anh*T3));
end
% orientational contribution to dephasing
if orientational_response
r = orientationalResponse(tau_R,5,T1,t2,T3,t4,T5);
R1 = R1.*r;
R2 = R2.*r;
R3 = R3.*r;
R4 = R4.*r;
end
switch lower(apodization)
case 'triangular'
%disp('3D triangular apodization')
x = 1:-1/(n_t-1):0;
window_fxn = zeros(n_t,n_t,n_t);
for j=1:n_t,
for k = 1:n_t
for l = 1:n_t
window_fxn(j,k,l) =x(j)*x(k)*x(l);
end
end
end
R1 = R1.*window_fxn;
R2 = R2.*window_fxn;
R3 = R3.*window_fxn;
R4 = R4.*window_fxn;
case {'gauss','gaussian'}
%disp('3D gaussian apodization')
window_fxn = exp(-(T1.^2+T3.^2)./(2*(n_t*dt/2)^2));
R1 = R1.*window_fxn;
R2 = R2.*window_fxn;
R3 = R3.*window_fxn;
R4 = R4.*window_fxn;
case 'none'
%disp('3D no apodization')
end
if noise>0
R1 = R1+max(max(real(R1)))*noise.*rand(size(R1));
R2 = R2+max(max(real(R2)))*noise.*rand(size(R2));
R3 = R1+max(max(real(R3)))*noise.*rand(size(R3));
R4 = R2+max(max(real(R4)))*noise.*rand(size(R4));
end
switch lower(fft_type)
case 'fft'
R1 = fftn(R1,[n_zp,n_zp,n_zp]);
R2 = fftn(R2,[n_zp,n_zp,n_zp]);
R3 = fftn(R3,[n_zp,n_zp,n_zp]);
R4 = fftn(R4,[n_zp,n_zp,n_zp]);
case 'petersfft'
R1 = petersfft3(R1,n_interp);
R2 = petersfft3(R2,n_interp);
R3 = petersfft3(R3,n_interp);
R4 = petersfft3(R4,n_interp);
case 'sgrsfft'
R1 = sgrsfft3(R1,n_zp);
R2 = sgrsfft3(R2,n_zp);
R3 = sgrsfft3(R3,n_zp);
R4 = sgrsfft3(R4,n_zp);
end
%do the flips
R2 = flipdim(circshift(R2,[0 -1 0]),2);
R3 = flipdim(circshift(R3,[-1 0 0]),1);
R4 = flipdim(flipdim(circshift(R4,[-1 -1 0]),1),2);
R{i} = fftshift(real(R1+R2+R3+R4));
end %end t2_array loop
if simulate_bandwidth
%disp(['3D simulating laser bandwidth ' num2str(bandwidth) ...
% ' cm-1 fwhm, for ' num2str(bandwidth_axes) ' axes' ]);
[W1,W3,W5]=meshgrid(w);
if bandwidth_axes == 3
BW = exp(-((W1-w_0)+(W3-w_0)+(W5-w_0)).^2./(2*(bandwidth/2.355)^2));
elseif bandwidth_axes == 2
BW = exp(-((W1-w_0)+(W3-w_0)).^2./(2*(bandwidth/2.355)^2));
end
R{i} = R{i}.*BW;
else
%disp('3D not simulating bandwidth');
end
end %end if order 5
%
% %
% % Print figures as needed
% %
% if order>=3
% for i = 1:n_t2_array
% figure(1000+i)
% ind = find(w>=range(1)&w<=range(2));
% my2dPlot(w(ind),w(ind),P{i}(ind,ind),'pumpprobe',false)
% end
% end
%
% %%
% if order>=5
% figure(20)
% ind = find(w>=range(1)&w<=range(2));
% for i = 1:n_t2_array,
% clf
% my3dPlot2(w(ind),w(ind),w(ind),R{i}(ind,ind,ind),'labels',labels)
% if n_t2_array>1,pause,end
% end
% end
% %%
%
% return
% %%
%
% figure(1)
% subplot(1,2,1)
% plot(t,g(t))
% title('lineshape function g')
% xlabel('t / ps')
% %set(gca,'Xlim',[0 5*tau]);
% subplot(1,2,2)
% plot(t,exp(-g(t)))
% xlabel('t / ps')
% title('exp(-g)')
% %set(gca,'Xlim',[0 5*tau]);
%
%
% figure(6),clf
% %offset_3d= R1(1,1,1);
% %R1=R1-offset_3d;
% my3dPlot(w,real(fftshift(R1(2:end,2:end,2:end))))
%
% figure(7),clf
% %offset_3d = R2(1,1,1);
% %R2=R2-offset_3d;
% my3dPlot(w,real(fftshift(R2(2:end,2:end,2:end))))
%
% figure(8),clf
% %offset_3d = R3(1,1,1);
% %R3=R3-offset_3d;
% my3dPlot(w,real(fftshift(R3(2:end,2:end,2:end))))
%
% figure(9),clf
% %offset_3d = R4(1,1,1);
% %R4=R4-offset_3d;
% my3dPlot(w,real(fftshift(R4(2:end,2:end,2:end))))
%
%
% %%
% figure(2),clf
% norm_1d = trapz(S)*dw;
% mean_1d = trapz(w.*S)*dw./norm_1d;
% [max_1d,i] = max(S);
% peak_1d = w(i)
% plot(w,S,'-o',[peak_1d peak_1d],[0 max_1d*1.2],'k')
% title('1d spec')
% xlabel('\omega')
% set(gca,'XLim',[-300 300]);
%
% %%
% figure(10)
% for i = 1:n_t2_array,
% clf
% my3dPlot(w,R{i})
% if n_t2_array>1,pause,end
% end
%