-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsixNMfreqV5b.m
2299 lines (2101 loc) · 101 KB
/
sixNMfreqV5b.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
% % B {Pailtjorpe, U Sydney. sixNMfreqV5b.m (27/4/23 - 24)
% Jansen-Rit 6 node cluster at A10 (pFC): 2 theta, 1 alpha, 2 beta, 1 gamma bands
% uses erfc(1/V) form of V-rate transformation
% Dependencies: JR12v5d.m in RK4 DE solver loop, incl. pass r & wbar for ea NM
% WaveTrains.m for stimuli set up
% Data files: AdjMarmoset_Rescale2b.csv, 116x166 link wts, based on LNe
% V5b. use S[~1/V, erfc (N(w)]; matches twoNM..v5b & sixCluster..v5b (15/4/23)
% & JR12v5d.m : uses tests for erfc; incl param trials 2, 6 & 'the 10'
% Cells (sections):
% 1. ADj set up
% 2. parameters for WC/JR model
% 3. set up stimuli
% 4.0 RK4 DE solver, 1st order, for n variables
% 5.0 various PLOT OUTPUT
% Appx 3.2a,b: calc w-in,out / k-in,out for local & ext links
% Appx 3.3: plot w-bar calc
% 1.0 Set up
addpath('/bap_working/MatLabfiles/MatlabFiles/MarmosetBrain/Models'); % for other model codes
fprintf('\n 6NM: 2+1+2+1; theta, alpha, beta, gamma bands; + delays; S[1/V - erfc], V5b code \n')
fprintf('\n 100 pc stim -> e popn \n')
% Adj, for coupling nodes
nn=6; % number of neural masses (nodes)
% Also: Appx 1, 2 - calc DE driving forces, S[V(t)]
%% 1.01 Adj: zeros (all)
fprintf(' Adj(ij) = 0: no coupling \n')
Adj= zeros(nn) % no coupling: indep NM
%% 1.02 Adj: ones (all)
fprintf(' Adj(ij) = 1: unit coupling, all-all \n')
Adj=ones(nn); % unit coupling, symm
% elim diagonals
for i=1:nn
Adj(i,i)=0;
end
Adj
length(find(Adj(:))) % 30 links
%% 1.1 Adj from Marmoset (LNe 6x6) data
% cf.Appx 2. in orig order: cf. logbook, p58
fprintf(' use marmoset LNe Adj(2): & scale R12=200 (raw Adj/5) \n')
clusterlist=[2, 26, 25, 48, 32, 3]; % as plotted in x-y plane, viewed from Ant.
Anew= csvread('AdjMarmoset_Rescale2b.csv'); % based on LNe
Aclust = Anew(clusterlist, clusterlist);
Adj2=Aclust/1000; % scale used for 6 NM model
Adj=Adj2 % nb use of R12*Adj {R12=100
R12=200 %R12=100 % NM - NM coupling coeff (ie. link wt) (cf. Goodfellow('11))
% base coupling: 100 : cf.scaling of Adj wts; applied in DE solver
% ie. this is Adj/5 : 20% [of expt] link wts
nLinks= length(find(Adj2(:))) % 29 entries
% det(Adj)
clear nLinks Anew Aclust Adj2 clusterlist
%Adj=zeros(nn); % test indep NM.
%Adj=ones(nn); % test unit coupled NM. nb. diagonals (self links) present
% isolate #2,3 [6->4NM]
% Adj(2,:)=0; Adj(:,2)=0 Adj(3,:)=0; Adj(:,3)=0
% nb. set approx dij in Ad6A, below & at Appx 3.2.1
%% 1.0.9 zero delays: dij
fprintf(' d(ij) =0: no signal delays \n')
Ad6A = zeros(nn);
%% 1.0.10 delays: dij (mm / ms) from marm data
% cf # 1.0.4, of sixCluster codes: d(ij) array - set d in bins of 0.1 mm (approx)
fprintf(' d(ij) in 0.1mm bins: from Marm. \n')
%Ad6A=Adist4; % cf appx 1.x below; data for 8x8, use 6x6
Ad6A = [...
0 3.4 2.9 2.4 2.4 2.5, 4.3, 5.0; ...
3.4 0 1.7 3.4 4.1 2.7, 0.0, 4.7; ... % 0 if no link present
2.9 1.7 0 1.9 2.8 2.6, 0.0, 3.2; ...
2.4 3.4 1.9 0 1.8 3.4, 3.2, 2.8; ...
2.4 4.1 0 1.8 0 2.8, 2.1, 3.2; ...
2.5 2.7 2.6 3.4 2.8 0.0 3.6, 4.8; ...
4.3, 4.9, 3.6, 3.2, 2.1, 3.6, 0.0, 2.4; ...
5.0, 4.7, 3.2, 2.8, 3.2, 4.8, 2.4, 0.0]; % checks ok.
tmp =Ad6A(1:6,1:6); max(tmp(:))
Ad6A = tmp;
% figure; hist(tmp(:)); title('pFC(6* cluster) d(ij) distribution'); xlabel('d(i j) (mm / ms)')
%figure; hist(Ad6A(:)); xlim([1 5]); % isolate "0"
% isolate #2,3: Ad6A(2,:)=0; Ad6A(:,2)=0 Ad6A(3,:)=0; Ad6A(:,3)=0
clear tmp
%% 2.0 Parameters: tune freq. band
fprintf('\n 2+1+2+1 NM; 6 star cluster, set parameters \n')
fprintf('\n Tuning #6, for w-av \n')
% time axis & IC (0 mV)
x0=0; xf= 30.0; % t range (sec)
h = 0.0001; % t step (1 ms; [& 0.5, 0.25 ms, for debug])
x = [x0:h:xf]; % t domain array
%time =x/(1000); %time =x/(1000*h); % time (sec) as row vec
tstart=4001; %tstart=2000; %1000; % for plots (@ 1, 0.5, 0.1 ms time steps)
%y = zeros(6,length(x)); % row vec for each variable
yic1=[1.0; 2.0; 1.0; 1.0; 1.0; 0.0]; % IC at t=0 for 1 node (6 DEs), col vec, 6 rows
%yic=5*yic1; % add additional nodes; and stronger?
yic= yic1;
for in=1:nn-1
yic=[yic; yic1]; % add 6 rows per extra node; 12, 18 DEs for 2, 3 ... nodes
end
clear yic1
%
% Model parameters (orig JR) : pass to fn subroutine! cf wb7, p66
v0=6; % (mV) midpoint (switching threshold V) of sigmoid function, for V -> pulse conversion
vm=5; % ie. 2*2.5 (s^-1) max firing rate for sigmoid fn
rvec= [0.5 0.5 0.5 0.5 0.5 0.5] % v2+ revised params (wb7, p57 & 84) % default
% & alt: from prev 6NM [single tau] models
%rvec= [0.56 0.40 0.47 0.43 0.38 0.47] % revised r ~ sqrt(N); cf w/b#4,p42 & 5,p72: tune in BETA band
%rvec= [0.42 0.30 0.37 0.34 0.30 0.37] % ditto: tune in alpha band: corrected (23/7/21)
%rvec= [0.45 0.32 0.38 0.35 0.30 0.38] % tune in ALPHA (or theta) band: wb 5, p70 (18/9/21)
% feedback: tuned to bands
Cvec = [220 200 200 220 200 250] % retuned gamma/ theta/ beta/ alpha/ theta/ beta/; wb7, p86
%Cvec = [220 250 300 220 200 250] % retuned #2,3 to osc ok
% tune feedback gain (based on WtIn, kIn)
CfacVec= [1.0 1.0 1.0 1.0 1.0 1.0]; % pass to fn J12a.m integrator
% nb. Assign in J12: C1=C1*Cfac; C3=C3*Cfac;
% weight/synp link, for Sigmoid response fn:
%wvec= [1.0 1.0 1.0 1.0] % default case: basic S[V] sigmoid
%wvec= [3.0 1.5 3.0 1.5 1.5 3.0] % vary f-i: tuning #1, wb[7],p85
%wvec= [3.0 3.0 3.0 1.5 3.0 3.0] % vary f-i: tuning #1a, wb[8],p40
%wvec= [3.0 5.0 3.0 1.5 4.0 3.0] % vary f-i: tuning: guesses #1a, b, c, d wb[8],p40
%wvec= [1.0 5.0 1.0 1.5 2.7 4.8] % check wt-in/k-in : "Trial 7" (14/12/23)
wvec= [3.0 5.0 3.0 1.5 3.5 3.0] % nb dominant link #16 wb[8],p42 : ** "Trial 6" **
%wvec= [3.0 5.0 3.0 1.5 3.0 3.0] % nb change #5 wb[8],p69 : "Trial 9"
%wvec= [3.0 5.0 3.0 1.5 5.0 3.0] % reassign for theta wb[7], p102, orig f-i tuning: "Trial 2"
%wvec= [3.0 2.5 3.0 1.5 3.5 3.0] % variations ~ theta [8], p37
%wvec=[0.52 3.23 0.48 0.74 1.30 2.35] % for pFC; raw wt/link: av in each NM: wb4,p59a
%wvec=[2.6 1.74 1.14 0.92 0.72 1.41] % based on Av[w-in/k & w-out/k] for 6x6: wb5,p102a
%wvec=[4.24 2.84 1.86 1.5 5.84 2.30] % rescale so #4 matches: [7], p20a
%wvec=[3.4 2.3 1.5 1.2 1.0 1.8] % [orig] rescaled Av[w-in/k & w-out/k] wb5,p102a; [8], p64
%wvec=[3.38 2.35 1.48 1.2 1.0 1.84] % 3a. expt Av[w-in/k & w-out/k] wb[8], p77; mss Table S2
%wvec=[2.6 3.2 1.8 1.5 2.0 2.4] % mix of max or av, Trial 6.1 [8],p74
%wvec=[1.9 1.26 1.17 1.11 2.69 1.1] % and fm 8x8 calc
% signal delay: set by array Ad6a, above; cf. App3.2, based on d(i,j) % d12=1.5-4; % eg. mm / ms
% Rate params - pass to JR12a fn.
A= 3.25; B =22; % Max PSP amplitude for pyramidal (A), inhib (B) & excit (kA * A) interneurons
%a=100; b=50; % (s^-1) / default JR; set to osc at 8Hz (taus: 20, 20 mS)
%taue= 15; taui= 20; % default Time Const (excit, inhib) (ms) : alpha, beta bands
% retune in DE loop: keep a*A & ? b*B const %a=1000/taue; b=1000/taui; % rate const (s^-1)
tauevec=[5.0 25.0 10.0 16.0 25.0 10.0] % revised again (15/4/23): wb7, p68 & 8; % #2 was 25
tauivec=[5.0 25.0 10.0 17.0 25.0 10.0] % for NM 1-6
Drive_1= [1000*A/tauevec(1) 1000*B/tauivec(1)] % check "driving forces"
Drive_6= [1000*A/tauevec(6) 1000*B/tauivec(6)]
% Coupling const for S[v]: cf. Steigler(2011)
kIn2=1; kIn6=1;
clear Drive_*
% >>>>>>>>>>>>>>
%% 3.0 Zero stim - pulse, ran or wave :: Base case
fprintf('\n >> zero inputs: 1 x G ran noise \n') % nb scale units are Hz, not "mV"
Vyt =zeros(1,length(x));
pran=zeros(1,length(x));
IpOn=zeros(nn,1); % switch on/off to ea NM for stim inputs; need IpOn also
IpOnB=zeros(nn,1); % 2nd pulses, default
Pd=zeros(1,length(x)); Pd2=zeros(1,length(x)); % pulse density fn - cf #3.6
%pran = 0.1*rand(1,length(x)); % low noise; Uniform ran noise:
pran = 1.0*randn(1,length(x)); % G ran noise (+-); [Hz]
%pran =7.75*pran; % test: sqrt(60) std, a la W & Z (4/5 popn) models
%
InI =0 % controls stim to Excit/Inhib popn: default - apply stim to Excit popn
%InI =1 % apply stim to Inhib
%% 3.5 Constant stim rate - use Pd;
% nb.not filtered by S[v]
% explore stable pts and limit cycles.
fprintf('\n ++const stimulus: on at 4.0 sec ')
tstart=40001; % also used for plots
StimLevel= 100
Pd=zeros(1,length(x)); tstart0= tstart; %tstart0= 1001; %separate for Pd
%tend=60001; % for short stim [4:5sec] etc
%Pd(tstart0:tend)=StimLevel; % short, const stim
Pd(tstart0:end)=StimLevel; % && turn on the const stim!!
PulseIntegrl = sum(Pd)*h % sum across rows % trapezoidal rule
%Ip6=zeros(1,length(x)); % pulse train/fn for 2nd input (?dphi shifted) - was to node 6
InI =0 % controls stim to Excit/Inhib popn: apply stim to Excit popn (default)
%InI =1 % apply stim to Inhib
clear StimLevel PulseHeight tstart0 PulseIntegrl tstart0
%% 3.5.1 Modulated stim rate - use Pd x |Vyt|, full wave rectification;
% modulate by Vyt fn - set up in WaveTrains.m; not filtered by S[v]
%fprintf('\n ++ modulated stimulus - via Vyt(f/2): at 4.0 sec ')
fprintf('\n ++ modulated stimulus - const * |Vyt(f)|: at 4.0 sec ')
fprintf('\n full wave rectification ( |abs| ) \n')
tstart=40001; % start stim & for plots
StimLevel= 100.0
Pd=zeros(1,length(x)); %tstart0= tstart; %tstart0= 1001; %tstart0= 20001; % separate for Pd
%tend=140001; % for short stim [4:5 sec] etc
%Pd(tstart:tend)=StimLevel*abs(Vyt(tstart:tend)); % short, const*modulated stim
Pd(tstart:end)=StimLevel*abs(Vyt(tstart:end)); % modulated stim! pos. via abs(), so 2*f
%Pd(tstart:end)= StimLevel + 0.1*StimLevel*Vyt(tstart:end); % modulated stim! pos. via abs(), so 2*f
StimStats= [mean(Pd) std(Pd) max(Pd)]
PulseIntegrl = sum(Pd)*h % sum across rows % trapezoidal rule
%test=Pd(tstart:end); %test=Pd(tstart:tend);
%StimStats1sec= [mean(test) std(test) max(test)]
%Vyt =zeros(1,length(x)); % reset Vyt: no V wave
% PdSave=Pd; % for reuse
% Pd=zeros(1,length(x)); tstart=40001; tend=47001; % reset
% Pd(tstart:tend)=PdSave(tstart:tend); % short, modulated stim
InI =0 % controls stim to Excit/Inhib popn: apply stim to Excit popn (default)
% InI =1 % apply stim to Inhib
clear StimLevel PulseHeight tstart0 tend PulseIntegrl StimStats test
%% 3.5.1a Vyt pos only, Half Wave rectification, Modulated stim rate - use Pd x Vyt
% modulate by Vyt fn - set up in WaveTrains.m
fprintf('\n ++ modulated stimulus, pos only (f): at 4.0 sec ')
fprintf('\n Half wave rectification (V>0 only) *2 {const. E \n')
tstart=40001; % start stim & for plots
StimLevel= 200
Pd=zeros(1,length(x));
Vpos=zeros(1,length(x));
tmp=find(Vyt>=0)';
Vtmp=Vyt(tmp)'; % pos only
% figure; plot(tmp,Vtmp); xlim([3.9e4 4.4e4]) % debug
Vpos=zeros(1,length(x));
Vpos(tmp)=Vtmp(1:end)';
% length(xpos) is 80027 for [4.0:20] sec
% figure; plot(x, Vpos); xlim([3.9 4.4]) % check: ok
Pd(tstart:end)=StimLevel*Vpos(tstart:end); % modulated stim! strictly pos.
% tend=100001; % for short stim [4:14 sec] etc
% Pd(tstart:tend)=StimLevel*Vpos(tstart:tend); % alt. short, const*modulated stim
StimStats= [mean(Pd) std(Pd) max(Pd)]
PulseIntegrl = sum(Pd)*h % sum across rows % trapezoidal rule
% Vyt =zeros(1,length(x)); % reset Vyt: no wave
clear StimLevel PulseHeight tstart0 PulseIntegrl StimStats tmp* Vtmp Vpos
%% 3.5.2 Modulated stim rate : const + Pd x Vyt, raw wave;
% modulate by Vyt fn - set up in WaveTrains.m
%fprintf('\n ++ modulated stimulus - via Vyt(f/2): at 4.0 sec ')
fprintf('\n ++ modulated stimulus = const1 + const2 * Vyt(f): at 4.0 sec ')
fprintf('\n raw wave, const offset ) \n')
tstart=40001; % start stim & for plots
StimLevel= 100.0
Pd=zeros(1,length(x)); %tstart0= tstart; %tstart0= 1001; %tstart0= 20001; % separate for Pd
%tend=50001; % for short stim [4:5 sec] etc
%Pd(tstart:tend)=StimLevel*abs(Vyt(tstart:tend)); % short, const stim
Pd(tstart:end)= (StimLevel+0.1)/2 +(StimLevel/2)*(Vyt(tstart:end)); % apply offset, so Pd >0 strictly
%Pd= (StimLevel+0.1)/2 +Pd; % modulated stim! pos. via abs(), so 2*f
StimStats= [mean(Pd) std(Pd) max(Pd)]
PulseIntegrl = sum(Pd)*h % sum across rows % trapezoidal rule
%test=Pd(tstart:end); %test=Pd(tstart:tend);
%StimStats1sec= [mean(test) std(test) max(test)]
%Vyt =zeros(1,length(x)); % reset Vyt: no V wave
figure; plot(Pd); hold on; xlim([3.9e4 4.4e4]); % check form
avline = max(Pd)/2;
line([4.0e4 4.4e4], [avline avline]); %, '--', 'Color', 'g'); % ??
title('Stimulus, modulated + bias');
% PdSave=Pd; % for reuse
% Pd=zeros(1,length(x)); tstart=40001; tend=47001; % reset
% Pd(tstart:tend)=PdSave(tstart:tend); % short, modulated stim
InI =0 % controls stim to Excit/Inhib popn: apply stim to Excit popn (default)
% InI =1 % apply stim to Inhib
clear StimLevel PulseHeight tstart0 tend PulseIntegrl StimStats test avline
%% 3.6.1 Load 1st Pulse density function[s]
% a la JR('93 & '95); set up in code WaveTrain.m @ #1.4
fprintf('+ Load Pulse density stim(@ 4s) + 0 (@0.5s); & 1 mV G ran noise: \n')
Pd= 1.0*Pulse1; % 1 or 2 pulses; vary amplitude (ie. pulse density
tstart=40001; % cf. wave... code, for pulse setup
% Pd= 1.0*PulseN; % N pulses, in train
%Pd = Pd+100.0; % add const stim (all t)
Pd((1001):end) = Pd((1001):end)+ 0.0; % add const stim , with pulse (not before)
PulseStats= [mean(Pd) std(Pd) max(Pd)]
%PulseStatsAtStim = [mean(Pd(40001:50000)) std(Pd(40001:50000)) ]
PulseIntegrl = sum(Pd)*h; % sum across rows % trapezoidal rule
PulseIntegrl=PulseIntegrl'
%Pulse2 =zeros(1,length(x)); % default: no 2nd pulse
InI =0 % controls stim to Excit/Inhib popn: apply stim to Excit popn (default)
%InI =1 % apply stim to Inhib
clear PulseHeight PulseIntegrl PulseStats*
%% 3.6.1 Load 2nd Pulse density function[s]
fprintf(' add in 2nd Pulse fn stim: \n')
StimLevel= 1.0 %100.0
%Pd2= 1.0*Pulse2; % 1 or 2 pulses; vary amplitude (ie. pulse density
%Pd2 = Pd2+155.0; % add const stim
Pd2 = StimLevel*Pulse2; % add 2nd pulse
%Pd = Pd + StimLevel*Pulse2; % alt: add 2nd pulse to orig pulse stream
PulseIntegrl = sum(Pd2)*h; % sum across rows % trapezoidal rule
PulseIntegrl=PulseIntegrl'
IpOnB =zeros(nn,1); % switch 2nd stim on/off to ea node - tbd
% IpOnB=ones(nn,1); % 2nd stimulus On for ALL nodes
IpOnB(1)=1; % A-10 gamma; [Out hub
% IpOnB(2)=1; % [node 2] A-32V theta [In hub
% IpOnB(3)=1; % beta [3] A32
% IpOnB(4)=1; % alpha {A9}
% IpOnB(5)=1; % theta {A46-D
% IpOnB(6)=1; % beta {A11 orig } [another In hub
IpOnB' % read out
clear PulseIntegrl
%% 3.6.2 Load 2nd wave train; Full wave retification
fprintf(' add in 2nd modulated wave stim at: 5.0:5.1 s \n')
Pd2=zeros(1,length(x)); % new array for 2nd stim
StimLevel= 100.0 %100.0
tstart=100001; % start stim & for plots
tend= 101001; % for short stim % 100 ms, et
Pd2(tstart:tend)=StimLevel*abs(Vyt2(tstart:tend)); % short, modulated stim
%Pd(tstart:end)=StimLevel*abs(Vyt(tstart:end)); % modulated stim! pos. via abs(), so 2*f
%Pd(tstart:end)= StimLevel + 0.1*StimLevel*Vyt(tstart:end); % modulated stim! pos. via abs(), so 2*f
StimStats= [mean(Pd2) std(Pd2) max(Pd2)]
PulseIntegrl = sum(Pd2)*h % sum across rows % trapezoidal rule
test=Pd2(tstart:end); %test=Pd(tstart:tend);
StimStats1sec= [mean(test) std(test) max(test)]
%Vyt2 =zeros(1,length(x)); % reset Vyt2: no V 2nd wave left
% set targets
IpOnB =zeros(nn,1); % switch 2nd stim on/off to ea node - tbd
% IpOnB=ones(nn,1); % 2nd stimulus On for ALL nodes
% IpOnB(1)=1; % A-10 gamma; [Out hub
IpOnB(2)=1; % [node 2] A-32V theta [In hub
% IpOnB(3)=1; % beta [3] A32
% IpOnB(4)=1; % alpha {A9}
% IpOnB(5)=1; % theta {A46-D
IpOnB(6)=1; % beta {A11 orig } [another In hub
IpOnB' % read out
clear StimLevel tstart0 tend PulseIntegrl StimStats
%% 3.6.3 Load 2nd wave train; Half wave retification
fprintf(' add in 2nd modulated wave, half wave, stim at: 10.0: 10.1 s \n')
Pd2=zeros(1,length(x)); % new array for 2nd stim
StimLevel= 200.0 %100.0
dphi = 200 % set here
tstart=100001+dphi; % start stim [t steps of 0.1 ms]
tend= 101001+dphi; % for short stim % 100 ms, etc. Nb. need to pass dphi
tstart2= 102001+dphi; tend2= 103001+dphi; % 2nd of 100ms pulse
tstart3= 104001+dphi; tend3= 105001+dphi; % 3rd of 100ms pulse
Vpos=zeros(1,length(x));
tmp=find(Vyt2>=0)'; % use 2nd wave loaded
Vtmp=Vyt2(tmp)'; % pos only
% figure; plot(tmp,Vtmp); xlim([3.9e4 4.4e4]) % debug
Vpos(tmp)=Vtmp(1:end)';
% length(xpos) is 80027 for [4.0:20] sec
% figure; plot(x, Vpos); xlim([3.9 4.4]) % check: ok
%Pd2(tstart:end)=StimLevel*Vpos(tstart:end); % Basic option; continuous from tstart
Pd2(tstart:tend)=StimLevel*Vpos(tstart:tend); % short, modulated stim strictly pos.
Pd2(tstart2:tend2)=StimLevel*Vpos(tstart2:tend2); % 2nd burst
Pd2(tstart3:tend3)=StimLevel*Vpos(tstart3:tend3); % 3rd burst
% %Pd2(tstart:end)=StimLevel*abs(Vyt(tstart:end)); % modulated stim! pos. via abs(), so 2*f
%Pd2(tstart:end)= StimLevel + 0.1*StimLevel*Vyt(tstart:end); % biased, modulated stim! pos. via abs(), so 2*f
StimStats= [mean(Pd2) std(Pd2) max(Pd2)]
PulseIntegrl = sum(Pd2)*h % sum across rows % trapezoidal rule
%test=Pd2(tstart:end); %test=Pd(tstart:tend);
%StimStats1sec= [mean(test) std(test) max(test)]
%Vyt2 =zeros(1,length(x)); % reset Vyt2: no V 2nd wave left
% set targets
IpOnB =zeros(nn,1); % switch 2nd stim on/off to ea node - tbd
IpOnB=ones(nn,1); % 2nd stimulus On for ALL nodes
IpOnB(1)=1; % A-10 gamma; [Out hub
% IpOnB(2)=1; % [node 2] A-32V theta [In hub
% IpOnB(3)=1; % beta [3] A32
% IpOnB(4)=1; % alpha {A9}
% IpOnB(5)=1; % theta {A46-D
% IpOnB(6)=1; % beta {A11 orig } [another In hub
TargetNodes=IpOnB' % read out
clear tstart0 tend PulseIntegrl StimStats tmp Vtmp TargetNodes % StimLevel Vpos
%% 3.7 Load Spike train fn - eg. from from LIF sim
% Load eSR (10ms bins) into eSpikes array in WaveTrains #1.6; from COBN.m .c
fprintf(' add in LIF spike train stim x frn: \n')
Pd=zeros(1,length(x));
%efrStim=csvread('efrStim6_300.csv' ); % read saved file, from LIF sim (M=300, noise 6)
efrStim=csvread('efrStim2_100.csv'); % N=100, frn 0,2, noise 2 ~ that[&beta] dominated
%efrStim=csvread('efrStim6_300_40s.csv' ); % 40s sim
efrStim = [efrStim', 0]; % match length to local variables
%efrStim = [efrStim', efrStim', 0]; % for 40s
Pd= Pd + 400.0*efrStim; % x scale; shape matches arrays lfp, x, y etc [col vec]
% another Alt. use use COBN output eFR (in 0.1ms bins)
%Pd=zeros(1,length(x)); % correct length
%Pd(2:end) = eFR; % matches lengths
PulseHeight= max(Pd)
PulseIntegrl = sum(Pd)*h % sum across rows % trapezoidal rule
[mean(Pd) std(Pd) max(Pd)]
clear PulseHeight PulseIntegrl
%% % 3.7.1 Load Spike train fn from from LIF sim x modulate f-band
% envelope of the wave; at double period (ie half cycle)
fprintf(' + envelope spike train x100: x gamma 32.1 Hz, at 4.0 sec \n')
%fprintf(' + envelope spike train: x alpha 9.6 Hz \n')
%fprintf(' LIF spike train x envelope @ gamma 32.0 Hz \n')
%fprintf(' + envelope spike train: x 1 sec osc \n')
Pd=zeros(1,length(x));
efrStim=csvread('efrStim6_300.csv' ); % read saved file, from LIF sim (N=300, noise 6) ~gamma
%efrStim=csvread('efrStim2_100.csv'); % N=100, frn 0,2, noise 2 ~ that[&beta] dominated
%efrStim=csvread('efrStim6_300_40s.csv' ); % 40s sim
efrStim = [efrStim', 0]; % match length to local variables
%efrStim = [efrStim', efrStim', 0]; % for 40s
Pd=zeros(1,length(x));
% Pd= 100.0*efrStim; % x scale; shape matches lfp, x, y etc [col vec]
% Pd(40001:end) = 250.0*efrStim(40001:end); % 4 sec : or full range t;
%xb=1/5.9; % f-theta modulation: full rectification
% xb=2.0*xb; % full rectification
%xb=1/9.6; % f-alpha modulation
%xb=1/14.3; % f-beta modulation
xb=1/32.1; % f-gamma modulation {32.8 for 4NM, 32.1 for 6NM}
%xb=2.0*xb; % full rectification - ie. appliy f/2
%xb=5.0; %xb=1; %xb=1/6.25; %xb=1; %period of burst modulation (sec);
dphi=0; %40001+ 0;
Wenvelope=1.0*sin(2*pi*x/(2*xb) -dphi);
figure; plot(abs(Wenvelope)); title('envelope'); xlim([5e4 5.6e4]) % debug
% Note - to set scale here:
tmp= abs(Wenvelope).*efrStim*400.0; % pos only [rectified] - full time; or on at 4s
%figure; plot(tmp); %xlim([5e4 5.6e4]) % debug
%Pd=tmp; % full time span
Pd(40001:end)=tmp(40001:end); % start at 4.0 sec
% Pulse1(40001:50000) = tmp(40001:50000); % 1sec burst [4:5] sec
%Pd((1001):end) = Pd((1001):end)+ 0.0; % add const stim , with pulse (not before)
figure; plot(Pd); xlim([5e4 5.6e4]) % debug
% figure; plot(x,Pd); % debug
PulseStats= [mean(Pd) std(Pd) max(Pd)]
%PulseStatsAtStim = [mean(Pd(40001:50000)) std(Pd(40001:50000)) ]
PulseIntegrl = sum(Pd)*h; % sum across rows % trapezoidal rule
PulseIntegrl=PulseIntegrl'
InI =0 % controls stim to Excit/Inhib popn: apply stim to Excit popn (default)
%InI =1 % apply stim to Inhib
clear tmp Pulse1 PulseHeight PulseIntegrl PulseStats* Wenvelope
%% 3.7.1a Load current sim LIF output
eFR =[double(eFR); 0.0]; % match length
Pd= Pd + 10.0*eFR'; % resampled LIF output
%% 3.7 Input channels [of 1st pulse, wave]
% selected nodes to get the stimulus inputs: Pd, etc < 1st stim
%IpOn=ones(nn,1); % 1st stimulus On for ALL nodes
IpOn=zeros(nn,1); % switch 1st stim on/off to ea node
% stimulate Node 2 (A-32V): strongest, more wt, fewer links)
% IpOn(1)=1; % A-10 gamma; cf wb7, p85
IpOn(2)=1; % [2] A-32V theta
% IpOn(3)=1; % beta [3] A32
% IpOn(4)=1; % alpha {A9}
% IpOn(5)=1; % theta {A46-D
IpOn(6)=1; % beta {A11 orig }
StimTo_1 =IpOn' % check
% StimTo_2 =IpOnB'
% direct 2nd pulse, if present? : set at #3.6.1 above
% IpOnB=zeros(nn,1); % switch 2nd stim on/off to ea node; if needed
%IpOnB(2)=1; % 2nd Pulse to NM#2 (1st in Hub A32-V):
%IpOnB(6)=1; % 2nd Pulse to 2nd input (A11)
%IpOnB' % check
clear StimTo*
%% 3.8 Gather stimuli & Plot, to check stim
figure; plot(pran, 'Color', [0.9 0.9 0.9]); hold on
plot(Pd, 'b'); title('stimulus pulse fn + wave + noise');
plot(Pd2, 'k');
plot(Vyt, 'g--');
xlabel('t steps (0.1 msec) ')
if max(Pd+pran+ Vyt) < 5
ylim([-2 2.2]) %ylim([0 1])
else
ylim([-2 (max(max(Pd +pran)) +20)])
end
% xlim([3.9e4 5e4]) % focus on time of stim
confirmTo_Excit0Inhib1 = InI
text(1.05e5, (max(Pd)+9), strcat('Stim To : ', num2str(IpOn')) )
text(1.05e5, (max(Pd)+5), strcat(' and : ', num2str(IpOnB')) )
% xlim([0.5e5 0.6e5]) % to examine details
% xlim([0 2e5]) % stop at 20s
clear confirmTo_*
% >>>>>>>>>>>>>>
%% 4.0 RK4 DE solver, 1st order, for 6n variables
% nb. matlab has default double precision: needed here
fprintf('\n > start sim, DE solver: ')
% signal delay, usually assumes v = 1 m/s; (mm/ms)
vlocal= 1.0; % unmyeln axon vel (~ signal delay) ~ 0.1-1.0 m/s
tic
% reset arrays
y=zeros(nn*6,length(x)); % set up array for solutions; nn nodes (x 6 rows each)
%y=double(y); % enforce double precision (64 bit) : should be default
deltay=zeros(nn,length(x)); % set up array for ye-yi; 6 DEs (1 row ea)
%deltay=double(deltay);
y(:,1)= yic ; % y's are row vec, one for ea DE; IC is a col vec, for i=1 or t=0.
for i=1:50 % may need to escape "trap" at zero
y(:,i)= yic; % extend IC - for delay DE "late start" - eg to ~1-5 ms
end
In12=0; % reset here; and for ea NM
% RK4 DE solution step: iterate forward in time (here x); scan nodes(in) & linked NN (j)
% fn JR12 incl forcing fn. as arguments, at this t-step;
% inputs: pran + p(i,j)+ [NM-NM couplings] {= sum(y1-y2) ;
%fprintf('\n i j wt(ij) dr(ij) index r Cfac ') % debug- header
% start "late" to allow for delay back ref, to L [allow 5ms w 0.1ms steps]
for i = 50:(length(x)-1) % scan time steps & start at 1, 10, 100 [for delay DE]
for in =1:nn % scan nodes in cluster (NM)
j11=(in-1)*6+1; j16=(in-1)*6+6; % working on this node #in
r=rvec(in); C=Cvec(in); Cfac=CfacVec(in); wbar=wvec(in); % for indiv NM : slope of S[v]; Gain C1,3
a=1000.0/tauevec(in); b= 1000.0/tauivec(in); % time const for ea. NM (nb. ms units)
%A=3.25; A=3.25*100/a; % ? rescale, to keep a*A const. Optional?
%[(a*A) (b*B)] % debug
%fprintf(' ... working on node %4.0f \n', in)
% Node #in - gets the ext inputs (Ip, Ii, p and In12 from linked nodes (i <- j)
% and Vwave adds to In12 (a la lfp, at soma)
jlist=find(Adj(:,in)); % linked nodes in (col) to node #in
jnn=length(jlist); % #NN of in
for j=1:jnn % scan NN list of node #in
In12=0; % initialise for ea NM
if isempty(jlist)
continue % no NN, In12 stays at 0
else
jj=jlist(j); j11=(jj-1)*6+1; j16=(jj-1)*6+6; % for nodes 2, 3 ..
%[in jj j11+1 j11+2] % debug: check correct indices for delta-y inputs
% will use: ((j-1)*6) +2 & ((j-1)*6 +3)
% signal delay assumes v = 1 ms/ (mm/ms): set above
% vlocal=1.0; % unmyeln axon vel ~ signal delay ~ 0.1-1.0 m/s
%deltai=int16(Ad6A(jj,in)/(1000*h*vlocal)); % adjust index, for signal delay time from nn, jj->in / as integer
deltai=int32(Ad6A(jj,in)/(1000*h*vlocal)); % check discontinuities
%deltai=Ad6A(jj,in)/(1000*h); % Old: adjust index, for signal delay time from nn, jj->in
dyi= y(j11+1,i-deltai)-y(j11+2,i-deltai); % delta-y of nn.
argm=r*(wbar -v0/dyi); In12=0;
if argm >0 & dyi>0.01 % avoid difficulties of erfc(neg, 0)
In12= R12*Adj(jj,in)*vm*(1.0-erfc(argm)/2); % erfc form for wt; avoid v=0
end
%[i dyi argm In12] % debug
% In12= R12*Adj(jj,in)*vm*(1.0-erfc(r*(wbar -v0/dyi))/2); % erfc form for wt; avoid v=0?
% workin on node in: weight by In link, from j to i: jj -> in
%fprintf('\n %2.0f %2.0f %5.3f %4.1f %4.0f %4.2f %4.2f ', in, jj, Adj(jj,in), Ad6A(jj,in), (i-deltai), r, Cfac )
end % check for NN
end % scan linked NNs; gather inputs (in <- jj) from linked NNs
%In12=In12+Vyt(i); % add travelling/standing wave direct, here, now
%fprintf('\n ') % for debug
%In21=zeros(12,length(x)); % debug, no input from other node[s]
%[jj j11 j16] % debug:
j11=(in-1)*6+1; j16=(in-1)*6+6; % update node #in
% nb. y7:12 in Node-2; y13:18 is Node-3, etc.
% Stimulus pulses to selected node (eg 2, 6), via IpOn switch
% add travelling wave Voltage, at y=16mm (Ant), at this time(i), to _all_ NM
%Istim=Vyt(i)+IpOn(in)*Ip(i); %pstim=IpOn(in)*pran(i); % turn stim on only for selected nodes - set above, at IC.
% gather ran & wave train together: to all NM
%Istim=IpOn(in)*Ip(i); % use if spike train Ip present
pstim=pran(i); % & ran noise to ALL nodes
Pdstim=IpOn(in)*Pd(i); % switch 1st stim pulse on;
Pdstim=Pdstim+IpOnB(in)*Pd2(i);% switch 2nd stim pulse on, if present?;
%pstim=pstim+ vm./(1 +exp(r*(v0- wbar*Vyt(i))) ); % wave stim, to both e & i; via p-ran
% nb/ here InI replaces Ip, and is 0; feed-fwd,bk calc in JR fn.
k_1 = JR12v5d( x(i), y(j11:j16,i), Pdstim, InI, pstim, In12, a, b, A, B, C, Cfac, r, wbar); % these k's should be col vec, one for ea DE
k_2 = JR12v5d( x(i)+0.5*h, y(j11:j16,i)+0.5*h*k_1, Pdstim, InI, pstim, In12, a, b, A, B, C, Cfac, r, wbar); % seem to need to force col vec ?
k_3 = JR12v5d( (x(i) +0.5*h), (y(j11:j16, i) +0.5*h*k_2), Pdstim, InI, pstim, In12, a, b, A, B, C, Cfac, r, wbar);
k_4 = JR12v5d( (x(i)+h), (y(j11:j16,i) +k_3*h), Pdstim, InI, pstim, In12, a, b, A, B, C, Cfac, r, wbar);
y(j11:j16,i+1) = y(j11:j16,i) + (k_1 +2*k_2 +2*k_3 +k_4)*(h/6); % load y1:y6 at this t-step
end % scan nodes
end % scan t-steps
fprintf('\n calc done/ ') % for debug
toc %timing
clear argm i in deltai In12 j* k_ a b Istim pstim pdstim vlocal
%% 5.0 PLOT OUTPUT
% Node 1 output [this is centre of star cluster, and Out-Hub (A-10)
tstart=40001; % 4 sec
%figure; plot(y(1:3,:)'); title('JR/ node-1: y0, y1, y2') % nb. need cols
%title('A-10: JR/ node-1, outputs:');
%legend('y0', 'y1', 'y2'); % orig notation [not array index]
%figure; plot(x, y(1,:)); title('6NM, node-1, pyrm: output: y-e-pyrm '); xlabel('t (s) ')
% title('A-10: JR/ node-1, output: detla-y: y1(1)- y2(1) ');
figure; subplot(3,1,1); plot(x, y(2,:)'); hold on; plot(x, y(3,:)');
title('6NM, node-1: output: y-e, y-i ');
legend('y-e(1)', 'y-i(1)', 'Location', 'SouthEast'); hold off
subplot(3,1,2); plot(x, y(2,:)'); hold on; plot(x, y(3,:)');
xlim([3.9 5.4]);
subplot(3,1,3); plot(x, y(2,:)'); hold on; plot(x, y(3,:)');
grid on; xlabel('t (s) '); xlim([13.6 15.6]);
figure; plot(x, (y(2,:)-y(3,:)) ); title('4-NM, node-1, delta-y ');
hold on; xlabel('t (sec) ') % checktransition in dy1
dy1Sample=y(2,45001:65000)-y(3,45001:65000); % 2 sec sample, 0.5s after stim
dy1Up = mean(dy1Sample) + std(dy1Sample);
dy1Down = mean(dy1Sample) - std(dy1Sample);
plot([4.5, 7], [dy1Up, dy1Up], '--r', 'LineWidth', 1.5)
plot([4.5, 7], [dy1Down, dy1Down], '--r', 'LineWidth', 1.5); hold off
dy1RangeSD = [ mean(dy1Sample) (dy1Up - dy1Down) ]
dy1RangeAbs = max(dy1Sample) - min(dy1Sample)
clear dy1Sample dy1Up dy1Down dy1Range*
% Node 2 outputs [this has the primary inputs]:
figure; plot(x, (y(8,(1):end) - y(9,(1):end)) );
title('6NM Node 2, A32V; delta-y ')
xlabel('t (sec) '); ylabel('dy2(t) = y-e - y-i (mV) ')
% text(3.5, 50, 'On'); text(4, 48, '|'); text(4, 46, '|')
% text(11, 40, 'stim 100Hz * gamma, full wave')
%text(4.0, 50, 'v', 'FontSize', 12); text(4.05, 52, '|', 'FontSize', 12);
%text(4.4, 50, 'Gamma modulated stimulus on')
%
% text(15e4, 45, '6NM, S[erfc], 100Hz x (theta/2)'); text(4e4, -37,'\^'); text(4e3, -37, '|')
figure; subplot(2,1,1); plot(x,y(8,:)'); hold on; plot(x,y(9,:)');
title(' node-2, A32V: output: y-e, y-i ');
legend('y-e (2)', 'y-i (2)', 'Location', 'SouthEast');
ylabel('y-e, y-i (mV)' ); hold off
subplot(2,1,2); plot(x,y(8,:)'); hold on; plot(x,y(9,:)');
plot(x, Pd/2); plot(x, Pd2/2, 'k'); % add stim
legend('y-e (2)', 'y-i (2)', 'Stim/2')
%axis([1.5 2.5 20 100]);
xlim([3.9 5.4]); grid on; xlabel('t (s) ')
%
% other outputs
%figure; plot(y(6,(tstart-100):end)); title('JR model, Node-1 output, y5 ')
%figure; plot(y(12,(tstart-100):end)); title('JR model, Node-2 output, y5 ')
% axis([0 5 -500 0]); axis([0 20 -10000 10000]);
% Node 3 outputs:
figure; plot(y(14,1:end) - y(15,1:end));
title(' node-3 output, dy: y1(3) - y2(3)')
figure; subplot(2,1,1); plot(x, y(14,:)'); hold on; plot(x, y(15,:)');
title(' node-3 output: y1, y2 '); legend('y1(3)', 'y2(3)'); hold off
subplot(2,1,2); plot(x, y(14,:)'); hold on; plot(x, y(15,:)');
xlim([3.9 5.4]); grid on; xlabel('t (s) ')
% Node 4 outputs:
figure; plot(y(20,1:end) - y(21,1:end));
title('JR model: node-4 outputs, dy: y1(4) - y2(4)')
figure; subplot(2,1,1); plot(x, y(20,:)'); hold on; plot(x, y(21,:)');
title(' node-4: output: y1, y2 '); legend('y1(4)', 'y2(4)'); hold off
subplot(2,1,2); plot(x, y(20,:)'); hold on; plot(x, y(21,:)');
xlim([3.9 5.4]); grid on; xlabel('t (s) ')
% Node 5 outputs:
figure; plot(y(26,1:end) - y(27,1:end));
title('node-5 output, y1(5) - y2(5)')
figure; subplot(2,1,1); plot(x,y(26,:)'); hold on; plot(x,y(27,:)');
title('node-5: output: y1, y2 '); legend('y1(5)', 'y2(5)'); hold off
subplot(2,1,2); plot(x,y(26,:)'); hold on; plot(x,y(27,:)');
axis([3.5 5 20 130]); grid on; xlabel('t (s) ')
% Node 6 outputs:
tstart= 40001; % debug
figure; plot(y(32,1:end) - y(33,1:end));
title(' node-6 output, y1(6) - y2(6)')
figure; plot(y(32,:)'); hold on; plot(y(33,:)');
title(' node-6: output: y1, y2 '); legend('y1(6)', 'y2(6)');
figure; subplot(2,1,1); plot(x,y(32,:)'); hold on; plot(x,y(33,:)');
title(' node-6: output: y1, y2 '); legend('y1(6)', 'y2(6)'); hold off
subplot(2,1,2); plot(x,y(32,:)'); hold on; plot(x,y(33,:)');
plot(x, Pd/10) % stim
xlim([3.9 4.4]); grid on; xlabel('t (s) '); legend('y-e (6)', 'y-i (6)', 'Stim')
%
% all 6 nodes together:
tstart= 30001; % debug
figure; plot(x((tstart-800):end), y(2,(tstart-800):end) - y(3,(tstart-800):end), 'k' ); hold on % node #1, A-10
xlim([4.0 5.0]); xlabel('t (s)'); xlabel('t (ms)'); %pause
plot(x((tstart-800):end) ,(y(8,(tstart-800):end) - y(9,(tstart-800):end) )); % #2, A-32V
%pause % - to closely examine waveforms
plot(x((tstart-800):end) ,y(14,(tstart-800):end) - y(15,(tstart-800):end)); % #3, A-32
%pause
plot(x((tstart-800):end) ,y(20,(tstart-800):end) - y(21,(tstart-800):end), 'b'); % #4, A9
%pause
plot(x((tstart-800):end) ,y(26,(tstart-800):end) - y(27,(tstart-800):end)); % #5, A-46D
%pause
plot(x((tstart-800):end) ,y(32,(tstart-800):end) - y(33,(tstart-800):end)); % #6, A-11
plot(x((tstart-800):end) ,Vyt((tstart-800):end), 'r--') % stimulii: wave
legend('delta-y(1)', 'delta-y(2)', 'delta-y(3)', 'delta-y(4)', ...
'delta-y(5)','delta-y(6)', 'stimulus-2' , 'wave' ); %text(3000, 0.3, 'wt(1-2) = 100')
% axis([0 5000 -20 20]); %axis([1 2 -25 25]);
%
% mean and range of detla-y, overall: 6 nodes together:
tstart= 10001; tend = 40000-100;% after transients & before stim
d_yMean=zeros(nn,1); d_yAmpl=zeros(nn,1);
d_yMean(1)=mean(y(2,(tstart+2000):tend) - y(3,(tstart+2000):tend)); % node #1,
d_yAmpl(1)=max(y(2,(tstart+2000):tend) - y(3,(tstart+2000):tend)) ... % sample before/after stim settles
- min(y(2,(tstart+2000):tend) - y(3,(tstart+2000):tend));
d_yMean(2)=mean(y(8,(tstart+2000):tend) - y(9,(tstart+2000):tend)); % #2,
d_yAmpl(2)=max(y(8,(tstart+2000):tend) - y(9,(tstart+2000):tend)) ...
- min (y(8,(tstart+2000):tend) - y(9,(tstart+2000):tend));
d_yMean(3)=mean(y(14,(tstart+2000):tend) - y(15,(tstart+2000):tend)); % #3
d_yAmpl(3)=max(y(14,(tstart+2000):tend) - y(15,(tstart+2000):tend)) ...
-min(y(14,(tstart+2000):tend) - y(15,(tstart+2000):tend));
d_yMean(4)=mean(y(20,(tstart+2000):tend) - y(21,(tstart+2000):tend)); % #4,
d_yAmpl(4)=max(y(20,(tstart+2000):tend) - y(21,(tstart+2000):tend)) ...
- min(y(20,(tstart+2000):tend) - y(21,(tstart+2000):tend));
d_yMean(5)=mean(y(26,(tstart+2000):tend) - y(27,(tstart+2000):tend)); % #5, A-46D
d_yAmpl(5)=max(y(26,(tstart+2000):tend) - y(27,(tstart+2000):tend)) ...
- min(y(26,(tstart+2000):tend) - y(27,(tstart+2000):tend));
d_yMean(6)=mean(y(32,(tstart+2000):tend) - y(33,(tstart+2000):tend)); % #6, A-11
d_yAmpl(6)=max(y(32,(tstart+2000):tend) - y(33,(tstart+2000):tend)) ...
-min(y(32,(tstart+2000):tend) - y(33,(tstart+2000):tend));
disp(' dy(i): mean, amplitude (before) \n'); [d_yMean d_yAmpl] % test/ debug
% mean and range of detla-y, later, after stim
tstart=90001; % [9: end] sec
d_yMean=zeros(nn,1); d_yAmpl=zeros(nn,1);
d_yMean(1)=mean(y(2,(tstart+2000):end) - y(3,(tstart+2000):end)); % node #1,
d_yAmpl(1)=max(y(2,(tstart+2000):end) - y(3,(tstart+2000):end)) ... % sample after stim settles
- min(y(2,(tstart+2000):end) - y(3,(tstart+2000):end));
d_yMean(2)=mean(y(8,(tstart+2000):end) - y(9,(tstart+2000):end)); % #2,
d_yAmpl(2)=max(y(8,(tstart+2000):end) - y(9,(tstart+2000):end)) ...
- min (y(8,(tstart+2000):end) - y(9,(tstart+2000):end));
d_yMean(3)=mean(y(14,(tstart+2000):end) - y(15,(tstart+2000):end)); % #3
d_yAmpl(3)=max(y(14,(tstart+2000):end) - y(15,(tstart+2000):end)) ...
-min(y(14,(tstart+2000):end) - y(15,(tstart+2000):end));
d_yMean(4)=mean(y(20,(tstart+2000):end) - y(21,(tstart+2000):end)); % #4,
d_yAmpl(4)=max(y(20,(tstart+2000):end) - y(21,(tstart+2000):end)) ...
- min(y(20,(tstart+2000):end) - y(21,(tstart+2000):end));
d_yMean(5)=mean(y(26,(tstart+2000):end) - y(27,(tstart+2000):end)); % #5, A-46D
d_yAmpl(5)=max(y(26,(tstart+2000):end) - y(27,(tstart+2000):end)) ...
- min(y(26,(tstart+2000):end) - y(27,(tstart+2000):end));
d_yMean(6)=mean(y(32,(tstart+2000):end) - y(33,(tstart+2000):end)); % #6, A-11
d_yAmpl(6)=max(y(32,(tstart+2000):end) - y(33,(tstart+2000):end)) ...
-min(y(32,(tstart+2000):end) - y(33,(tstart+2000):end));
disp(' dy(i): mean, amplitude (> 9sec) \n'); [d_yMean d_yAmpl] % test/ debug
figure; stem(d_yMean, '+'); hold on; stem(d_yAmpl, ':diamond');
% hs(1).Marker='+'; hs(2).Marker='diamond';
xlim([0 7]); %axis([0 7 -15 60 ]);
xlabel('NM #'); ylabel('delta-y12(i) (mV)'); title('dy(i) after stimulus')
legend('mean', 'p-p ampl.', 'Location', 'northeast') % place out of the way
% text(5.5, 23, 'Adj = 1'); % text(5.5, 10, 'alpha; C x vector')
% %figure; plot(rvec, d_yAmpl, '.', 'MarkerSize', 20); hold on
% plot(rvec, d_yMean, '+', 'MarkerSize', 5);
%
disp(' >> dy(2) after 16.5 sec: ')
tstart=165001; % [9: end] sec
d_yMean(2)=mean(y(8,(tstart+2000):end) - y(9,(tstart+2000):end)); % #2,
d_yAmpl(2)=max(y(8,(tstart+2000):end) - y(9,(tstart+2000):end)) ...
- min (y(8,(tstart+2000):end) - y(9,(tstart+2000):end));
[d_yMean(2) d_yAmpl(2)]
%
% 3 key nodes together:
figure; plot(y(2, (tstart-800):end)-y(3,(tstart-800):end) ); hold on; % #1
plot(y(8,(tstart-800):end) - y(9,(tstart-800):end), 'r') % ', 'Color', [0 0.3 0]); % #2,
%plot(y(32,(tstart-800):end) - y(33,(tstart-800):end),'g'); % #6, A-11 : Input 2nd
plot(y(20,(tstart-800):end) - y(21,(tstart-800):end),'b'); % #4,
plot(Pd((tstart-800):end), 'k'); % stimulii, on same scale
title('6 NM cluster, JR model: delta-y ')
legend('delta-y(1)', 'delta-y(2)', 'delta-y(4)', 'stimulus' );
%
% LFP LFP: net lfp output: sum: detla-y(1) + detla-y(2), for the 4 NM
lfp= (y(2,:) - y(3,:) + y(8,:) - y(9,:) +y(14,:) - y(15,:) ...
+ y(20,:) - y(21,:) + y(26,:) - y(27,:) +y(32,:) - y(33,:) )/6; % av of 6 nodes
% figure; plot(lfp); title('JR model: net lfp output ')
figure; plot(x, lfp); title('6-NM cluster, JR model: net lfp output '); xlabel('t (sec) ')
ylabel('LFT (t) (mV)'); % hold on; plot(20,-1, 'b^'); plot(20,-1.1, 'b^'); % wave starts
% text(15, -3.5, 'wave ampl = 10 mV') % plot(4,-4, 'k^'); % Pulse starts
% text(2.0, -120.0, '6-cluster: ran noise input ')
% text(4000, -2.0, 'stimulate #2, 6 ')
% axis([500 5000 -0.1 0.1]) % axis([500 5000 -2.0 0])
% text(2.5, -4, '16 Hz wave + 100 Hz pulses to A32V')
%lfp_stats_2to5= [mean(lfp25(tstart:end)) (max(lfp25(tstart:end)) - min(lfp25(tstart:end)) )]
clear lfp25 lfp_stats_2to5
% Grouped summary: resize figure [5 by 1 plots]
%figwidth = 1024; figheight = 896; figposition = [100, 100, figwidth, figheight]; % large
figwidth = 560; figheight = 704; figposition = [500, 100, figwidth, figheight]; % tall
figure('position',figposition, 'units','pixels'); %figure; % default
subplot(5,1,1);
plot(y(2,:) - y(3,:),'b'); % #1, A-10 : Output
tlim=length(y(2,:) - y(3,:))-1; axis([0,tlim, -Inf, Inf]) % keep vetical as is
title('6-NM cluster, NM#1, delta-y ')
subplot(5,1,2);
plot(y(8,:) - y(9,:), 'r') % ', 'Color', [0 0.3 0]); % #2,
title(' NM#2, delta-y '); axis([0,tlim, -Inf, Inf])
subplot(5,1,3);
%plot(y(20,:) - y(21,:) ); % #4,
plot(y(32,1:end) - y(33,1:end)); % #6
title(' NM#6, delta-y '); axis([0,tlim, -Inf, Inf])
subplot(5,1,4); plot(lfp,'k'); title(' lfp output '); % net output
xlim([0,tlim]); % xlim([0 3.0e5]); %axis([0,tlim, -Inf, Inf])
subplot(5,1,5);
plot((Pd)*IpOn(1) +pran+Vyt, 'g--'); hold on; % theta
plot((Pd)*IpOn(6) +pran+Vyt, 'r--') % stimulii to gamma, on same scale
plot(pran, 'Color', [0.9 0.9 0.9]);
xlim([0,tlim]); ylim([-10 (max(Pd)+10)])
legend( 'stimulus-1', 'stimulus-6', 'ran' ); title(' Inputs: stimulus-> NM ');
xlabel('t steps (0.1 msec) '); %axis([0,tlim, -Inf, Inf])
% text(5500, 50, 'Stim 300 to both #2, #6')
% & LFP:
lfp_sample=lfp(40001:end); % during stimulus [0.5s sample]
%lfp_sample=lfp(1100:2900); % debug, nb. wider sample for half t-step
lfp_stats= [ mean(lfp_sample), (max(lfp_sample)-min(lfp_sample))]
% figure; plot(lfp_sample - mean(lfp_sample)); title('JR, 6xNM: sum (lfp -mean), during stim. ')
%
%if xf >15 % for longer sim (eg 20 sec)
% lfp_sample=lfp(180000:190000); % V. much later
% lfp_stats_at18secLaterStill= [ mean(lfp_sample), (max(lfp_sample)-min(lfp_sample))]
%end
%
lfp0= (y(1,:) + y(7,:) +y(13,:) + y(19,:) + y(25,:) +y(31,:) )/6; % av of 6 nodes
figure; plot(x, lfp0); title('6-NM cluster, JR model: net lfp[y0] output '); xlabel('t (sec) ')
ylabel('LFT (t) (mV)'); ylim([0 0.2]);
lfp0_sample=lfp0(40001:end); % during stimulus [0.5s sample]
% lfp0_stats= [ mean(lfp0_sample), (max(lfp0_sample)-min(lfp0_sample))]
% Node 2 outputs [this has the primary inputs]:
% figure; plot(x, y(7,(1):end) );
% title('6NM Node 2, A32V; y-0 ')
% xlabel('t (sec) '); ylabel('y-0[2](t) (mV) ')
% mean and range of y0, overall: 4 nodes together, after stim (4s)
d_y0Mean=zeros(nn,1); d_y0Ampl=zeros(nn,1);
d_y0Mean(1)=mean(y(1,(tstart+2000):end) ); % node #1,
d_y0Ampl(1)=max(y(1,(tstart+2000):end) ) - min(y(1,(tstart+2000):end) ); % sample after stim settles
d_y0Mean(2)=mean(y(7,(tstart+2000):end) ); % #2,
d_y0Ampl(2)=max(y(7,(tstart+2000):end) ) - min (y(7,(tstart+2000):end) );
d_y0Mean(3)=mean(y(13,(tstart+2000):end) ); % #3
d_y0Ampl(3)=max( y(13,(tstart+2000):end) ) -min(y(13,(tstart+2000):end) );
d_y0Mean(4)=mean(y(19,(tstart+2000):end) ); % #4,
d_y0Ampl(4)=max(y(19,(tstart+2000):end) ) - min(y(19,(tstart+2000):end) );
d_y0Mean(5)=mean(y(25,(tstart+2000):end) ); % #4,
d_y0Ampl(5)=max(y(25,(tstart+2000):end) ) - min(y(25,(tstart+2000):end) );
d_y0Mean(6)=mean(y(31,(tstart+2000):end) ); % #4,
d_y0Ampl(6)=max(y(31,(tstart+2000):end) ) - min(y(31,(tstart+2000):end) );
%disp(' y0(i): mean, amplitude (after stim) \n'); [d_y0Mean d_y0Ampl] %
clear jlist i j in jj j11 j16 k* In12 deltay lfp_* d_yM* dy6* lfp0* % tstart pran yic
% > > > > >
%% 5.0a 1 x replot dy2
figure; title('6NM Node #2, A32V; delta-y '); hold on
plot(x, (y(8,(1):end) - y(9,(1):end)) );
xlabel('t (sec) '); ylabel('dy2(t) = y-e - y-i (mV) ')
%text(3.5, 50, 'On'); text(4, 48, '|'); text(4, 46, '|')
% text(15, 50, 'gamma stim > #2 & 6'); text(15.5, 47, 'full wave')
% text(14,38,'|'); text(14,40,'|'); text(13.8, 42, 'Off') % label off
%% extra overlay
figure; title('6NM Node #2, A32V; delta-y '); hold on
plot(x(150001:end), (y(8,150001:end) - y(9,150001:end) ), 'Color', [0.3 0.3 0.3] ); % from 15s
xlabel('t (sec) '); ylabel('dy2(t) = y-e - y-i (mV) ')
%% 5.0b Labels on, off
text(4,47,'|'); text(4,48,'|'); text(3.8, 50, 'On') % label on
%text(10,47,'|'); text(10,48,'|'); text(9.8, 50, 'Off') % label off
text(10,44,'|'); text(10,45,'|'); text(9.8, 48, 'Reset pulse') %
% text(14, 47, '6NM + beta stim -> #2,6'); % explain stim
% text(15, 44, 'Half wave'); %text(15, 37, 'full wave, biased');
%% 5.0b : 2 multi plots of dy-2
% Node 2 outputs [this has the primary inputs]:
figure; subplot(2,1,1); %title('6NM Node #2, A32V; delta-y ')
ylabel('dy2(t) = y-e - y-i (mV) ')
subplot(2,1,2); plot(x, (y(8,(1):end) - y(9,(1):end)) );
xlabel('t (sec) '); ylabel('dy2(t) = y-e - y-i (mV) ')
% text(3.5, 50, 'On'); text(4, 48, '|'); text(4, 46, '|')
% text(11, 40, 'stim 100Hz * gamma, full wave')
%text(19, 57, 'd'); text(13, 50, 'gamma')
%% 5.0c : 4 multi plots of dy-2
% Node 2 outputs [this has the primary inputs]:
figure; subplot(2,2,1); title('6NM Node #2, A32V; delta-y ')
ylabel('dy2(t) = y-e - y-i (mV) ')
subplot(2,2,4); % gamma
%subplot(2,2,2); % beta
plot(x, (y(8,(1):end) - y(9,(1):end)) );
xlabel('t (sec)'); ylabel('dy2(t) = y-e - y-i (mV) ')
text(3.5, 50, 'On'); text(4, 48, '|'); text(4, 46, '|')
% text(11, 40, 'stim 100Hz * gamma, full wave')
text(13, 50, 'gamma'); % text(19, 57, 'd');
subplot(2,2,1); text(13, 50, 'theta'); hold on
plot(x, (y(8,(1):end) - y(9,(1):end)) ); ylabel('dy2(t) = y-e - y-i (mV) ')
subplot(2,2,2); text(13, 45, 'alpha'); hold on
plot(x, (y(8,(1):end) - y(9,(1):end)) ); ylabel('dy2(t) = y-e - y-i (mV) ');
subplot(2,2,3); text(13, 53, 'beta'); hold on
plot(x, (y(8,(1):end) - y(9,(1):end)) ); ylabel('dy2(t) = y-e - y-i (mV) '); xlabel('t (sec)');
% publication quality print
% hh =gcf
% print(hh, 'Fig3.tiff', '-dtiff' , '-r300')
%% 5.0.1 mean and range of detla-y, After stim: 6 NM 10:20sec
% check dy3 before stim
%dy3LT4 = max( y(14,1:35000) - y(15,1:35000) ) - min( y(14,1:35000) - y(15,1:35000) )
%figure; plot ( y(14,1:45000) - y(15,1:45000) ); title(' NM # 3 - check state')
% well after stim:
tstart = 110000;
fprintf('\n > dy(i) stats > 11 sec \n')
d_yMean=zeros(nn,1); d_yAmpl=zeros(nn,1);
d_yMean(1)=mean(y(2,(tstart+2000):end) - y(3,(tstart+2000):end)); % node #1, A-10
d_yAmpl(1)=max(y(2,(tstart+2000):end) - y(3,(tstart+2000):end)) ... % sample after stim settles
- min(y(2,(tstart+2000):end) - y(3,(tstart+2000):end));
d_yMean(2)=mean(y(8,(tstart+2000):end) - y(9,(tstart+2000):end)); % #2, A-32V
d_yAmpl(2)=max(y(8,(tstart+2000):end) - y(9,(tstart+2000):end)) ...
- min (y(8,(tstart+2000):end) - y(9,(tstart+2000):end));
d_yMean(3)=mean(y(14,(tstart+2000):end) - y(15,(tstart+2000):end)); % #3 A-32
d_yAmpl(3)=max(y(14,(tstart+2000):end) - y(15,(tstart+2000):end)) ...
-min(y(14,(tstart+2000):end) - y(15,(tstart+2000):end));
d_yMean(4)=mean(y(20,(tstart+2000):end) - y(21,(tstart+2000):end)); % #4, A-9
d_yAmpl(4)=max(y(20,(tstart+2000):end) - y(21,(tstart+2000):end)) ...
- min(y(20,(tstart+2000):end) - y(21,(tstart+2000):end));
d_yMean(5)=mean(y(26,(tstart+2000):end) - y(27,(tstart+2000):end)); % #5, A-46D
d_yAmpl(5)= max(y(26,(tstart+2000):end) - y(27,(tstart+2000):end)) ...
- min(y(26,(tstart+2000):end) - y(27,(tstart+2000):end) );
d_yMean(6)=mean(y(32,(tstart+2000):end) - y(33,(tstart+2000):end)); % #6, A-11
d_yAmpl(6)=max(y(32,(tstart+2000):end) - y(33,(tstart+2000):end)) ...
-min(y(32,(tstart+2000):end) - y(33,(tstart+2000):end));
%
figure; stem(d_yMean, '+'); hold on; stem(d_yAmpl, ':diamond');
% hs(1).Marker='+'; hs(2).Marker='diamond';
axis([0 7 -15 80 ]); xlabel('NM #'); ylabel('delta-y12(i) (mV)'); title('dy(i) 10 : 20 sec')
legend('mean', 'p-p ampl.', 'Location', 'northeast') % place out of the way
% text(5.5, 23, 'Adj = 1'); % text(5.5, 10, 'alpha; C x vector')
dy_mean_ampl = [d_yMean d_yAmpl] % test/ debug
lfp_sample=lfp(tstart:end); % during stimulus [0.5s sample]
%lfp_sample=lfp(1100:2900); % debug, nb. wider sample for half t-step
lfp_stats_10s= [ mean(lfp_sample), (max(lfp_sample)-min(lfp_sample))]
clear dy3LT4 dy_mean_ampl d_y* lfp_st*
%% 5.0.2 compare dy12 vs y0
fprintf('\n > plot yo vs y-e, y-i: \n');
figure; plot(x, (y(1,:)*50.0 +20), 'b' ); % its small - check offsets
hold on; plot(x, y(2,:), 'g', 'LineWidth', 1.2);
plot(x, y(3,:), 'r', 'LineWidth', 1.0 ); % for y-e & y-i
% hold on; plot(x, (y(2,:) -y(3,:)) ) % for lfp
legend('yo *50', 'y1', 'y2'); grid on
% legend('yo *50', 'y1 -y2')
xlim([3.5 5]); % xlim([0.2 0.4]); grid on
% ylim([-25.0 30])
title('4NM, dbl tri; #1, beta; yo lag varies')
%
figure; plot(x, (y(7,:)*50.0 +40), 'b' ); % y0, its small - check offsets
hold on; plot(x, y(8,:), 'g', 'LineWidth', 1.2);
plot(x, y(9,:), 'r', 'LineWidth', 1.0 ); % for y-e & y-i
% hold on; plot(x, (y(2,:) -y(3,:)) ) % for lfp
legend('yo *50', 'y1', 'y2'); grid on;
% legend('yo *50', 'y1 -y2')
xlim([3.5 5]); % xlim([0.2 1.2]); grid on;
% ylim([-25.0 30])
title('4NM, dbl tri; #2, theta; yo & ye, yi')
%
figure; plot(x, (y(13,:)*50.0 +40), 'b' ); % its small - check offsets
hold on; plot(x, y(14,:), 'g', 'LineWidth', 1.2);
plot(x, y(15,:), 'r', 'LineWidth', 1.0 ); % for y-e & y-i
% hold on; plot(x, (y(2,:) -y(3,:)) ) % for lfp
legend('yo *50', 'y1', 'y2'); grid on;
% legend('yo *50', 'y1 -y2')
xlim([3.5 5]); % xlim([0.2 1.2]); grid on;
% ylim([-25.0 30])
title('4NM, dbl tri; #3, alpha; yo & ye, yi')
%
figure; plot(x, (y(19,:)*50.0 +20), 'b' ); % its small - check offsets
hold on; plot(x, y(20,:), 'g', 'LineWidth', 1.3);
plot(x, y(21,:), 'r', 'LineWidth', 0.9 ); % for y-e & y-i
% hold on; plot(x, (y(2,:) -y(3,:)) ) % for lfp
legend('yo *50', 'y1', 'y2'); grid on;
% legend('yo *50', 'y1 -y2')
%xlim([0.2 0.4]);
xlim([3.5 5]); %xlim([0.2 1.2]); % span transition at 4s
% ylim([-25.0 30])
title('.. NM, #4, xx; yo & ye, yi')
%
figure; plot(x, (y(25,:)*50.0 +20), 'b' ); % its small - check offsets
hold on; plot(x, y(26,:), 'g', 'LineWidth', 1.3);
plot(x, y(27,:), 'r', 'LineWidth', 0.9 ); % for y-e & y-i
% hold on; plot(x, (y(2,:) -y(3,:)) ) % for lfp
legend('yo *50', 'y1', 'y2'); grid on;
% legend('yo *50', 'y1 -y2')
%xlim([0.2 0.4]);
xlim([3.5 5]); %xlim([0.2 1.2]); % span transition at 4s
% ylim([-25.0 30])
title('.. NM, #5, xx; yo & ye, yi')
%% 5.0.3 Transitions: dy-2; ln(dy) plot
% Node 2 outputs [this os the primary input Hub]:
figure; plot(x, (y(8,(1):end) - y(9,(1):end)) ); title('6NM Node-2, delta-y p-p amplitude')
ylabel('dy-2 = y-e(2) - y-i(2) (mV) '); xlabel('t (sec) ');
figure; semilogy(x, (y(8,1:end) - y(9,1:end)) );
ylim([1 100]); ylabel('ln[ dy-2 = y-e(2) - y-i(2)] (mV) '); xlabel('t (sec) ');
title('6NM Node-2, log delta-y p-p amplitude')
% text(12,50, '6NM + p=100 * 2alpha -> NM #2, 6')
% overall
d_yMean(2)=mean(y(8,(tstart+2000):end) - y(9,(tstart+2000):end)); % #2,
d_yAmpl(2)=max(y(8,(tstart+2000):end) - y(9,(tstart+2000):end)) ...
- min (y(8,(tstart+2000):end) - y(9,(tstart+2000):end));
%% 5.1 revised LFP: compare dy's, cf 4 NM
% special case: use 4NM code for only
fprintf('\n lfp : sample 4 nodes only ')
lfp= (y(2,:) - y(3,:) ... % omit NM#2 & 3
+ y(20,:) - y(21,:) + y(26,:) - y(27,:) +y(32,:) - y(33,:) )/4; % av of 4 nodes: 1,4,5,6
lfp4_sample=lfp(40001:end); % during stimulus [0.5s sample]
%lfp_sample=lfp(1100:2900); % debug, nb. wider sample for half t-step
lfp4_stats= [ mean(lfp4_sample), (max(lfp4_sample)-min(lfp4_sample))]
% check dy6: cf dy1
figure; subplot(3,1,1); plot(x, y(2,:) - y(3,:)); title('6NM: dy-1'); xlim([5 6]);
%text(5.7, -8,'v-local = 10 m/s')
subplot(3,1,2); plot(x, y(8,:) - y(9,:)); title('6NM: dy-2; [-- dy-1]');
xlim([5 6]); hold on; grid on
plot(x, y(2,:) - y(3,:), 'k--');