-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPm_acquireRFaction.m
170 lines (144 loc) · 5.95 KB
/
Pm_acquireRFaction.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
%% acquireRFactionCam
% v1.0 yuanhui 20190221
% acquire fluorescent signal from camera in RF activation of cells
[DG4, DG4Info] = DG4_init();
[PmVid, PmSrc, PmSrcInfo] = Pm_init();
%% setup camera
PmSrc.Exposure = 100; % 0-10000 for both ms and us; 1 us required by camera to synchronize
PmSrc.ExpRes = 'ms'; % 'ms' or 'us'
PmSrc.Binning = '1x1'; % '2x2' makes no sense for sCMOS hoping reduced read noise
PmSrc.Offset = 185;
PmPreview = preview(PmVid);
pause(3)
PmVid.ROIPosition = Pm_selectROI(PmVid,PmPreview,'Manual'); % 'Full', 'Half', 'Manual', 'Keep'
% PmVid.ROIPosition = [0 200 2048 1648];% set FOV; for CMOS no need to trim horizontal
PmSrc.AutoContrast = 'ON';
PmSrc.TriggerMode = 'Internal Trigger'; % 'Internal Trigger' 'Edge Trigger' or 'Trigger First'
stoppreview(PmVid);
PmSrcInfo = get(getselectedsource(PmVid));
%% setup DG4
% 100, 200, 500, 1000, 2000, 5000Hz for all
% transducers, except that maximum PRF is internally
% limited to: 2000Hz for 0.5MHz transducers, 1000Hz
% for 0.25MHz transducers, and 500Hz for 0.1MHz
% transducers.
FIDInfo.PRRHz = 2000; % if >10e3 Hz FID breaks
if FIDInfo.PRRHz > 10e3 FIDInfo.PRRHz = 10e3; end
RFaction.nCycles = 2.5;
DG4Info.PeriodActionSec = 5; % seconds
DG4Info.PeriodRestSec = 25; % seconds
DG4Info.PeriodSec = DG4Info.PeriodActionSec + DG4Info.PeriodRestSec; % seconds
DG4Info.DutyCycle = round(100 * (DG4Info.PeriodRestSec / (DG4Info.PeriodActionSec+DG4Info.PeriodRestSec))); % percentage
% Channel 1
DG4Info.RF_Channel = 1;
DG4Info.RF_Freq = FIDInfo.PRRHz; % Hz
DG4Info.RF_WaveShapeStr = 'PULSe'; % SINusoid|SQUare|RAMP|PULSe|NOISe|USER| etc
DG4Info.RF_PulseWidth = 100e-9; % second. FPG triggers on 100 ns 5V TTL; DG4 accepts 0.3125% of period
DG4Info.RF_DutyCycle = 0.315; % % in percentage
DG4Info.RF_Delay = 0; % second
if DG4Info.RF_PulseWidth<1./DG4Info.RF_Freq
DG4Info.RF_PulseWidth = 1./DG4Info.RF_Freq .* 0.315 ./ 100;
end
DG4Info.RF_High = 5; % Volt. FPG triggers on 100 ns 5V TTL
DG4Info.RF_Low = 0; % Volt
DG4Info.RF_Amplitude = 5; % Vpp.
DG4Info.RF_Offset = 2.5; % Volt.
% Channel 2
DG4Info.Scope_Channel = 2;
DG4Info.Scope_WaveShapeStr = 'PULSe'; % SINusoid|SQUare|RAMP|PULSe|NOISe|USER| etc
DG4Info.Scope_DutyCycle = DG4Info.DutyCycle ; % % in percentage
DG4Info.Scope_High = 5; % Volt. FPG triggers on 100 ns 5V TTL
DG4Info.Scope_Low = 0; % Volt
DG4_setRFact(DG4, DG4Info);
%
trig_output(DG4, 'OFF', DG4Info.RF_Channel);
trig_output(DG4, 'OFF', DG4Info.Scope_Channel);
% trig_output(DG4, 'ON', DG4Info.Scope_Channel);
% trig_output(DG4, 'ON', DG4Info.RF_Channel);
%%
trig_output2Chan(DG4, 'ON', DG4Info);
%%
trig_output2Chan(DG4, 'OFF', DG4Info);
%% Sample name
FileName = 'Gcamp6s20xFish3dpf_8kV'; % eg 'Gcamp6s20xFish10dpf_8kV'
FileName = [FileName num2str(FIDInfo.PRFHz) 'PRF' ...
'_Act' num2str(DG4Info.PeriodActionSec) ...
'Rest' num2str(DG4Info.PeriodActionSec) 's' ...
num2str(RFaction.nCycles) 'cycl'];
%% run 1 Background - Dark
trig_output(DG4, 'OFF', DG4Info.RF_Channel);
trig_output(DG4, 'OFF', DG4Info.Scope_Channel);
SaveMeasName = [FileName '_DARK'];
% % long video required, but fps halved as fastest memory logging
stoppreview(PmVid);
TiffSavingPath = makeVideoDir('C:\Pictures\', 'Long', SaveMeasName);
PmSrc.StreamSavingPath = TiffSavingPath;
PmSrc.AutoContrast = 'OFF';
% PmSrc.FanSpeed = 'Off(Liquid Cooled)';
pause(2)
PmSrc.StreamAcquisition = 'TIFF'; % 'OFF', 'RAW' or 'TIFF' % disk stream give 50 frames/s
% PmPreview = preview(PmVid);
% stoppreview(PmVid)
flushdata(PmVid);
warning('off');
% % using timmer of camera to stop image acquisition
PmVid.TimerPeriod = RFaction.nCycles * DG4Info.PeriodSec; % seconds, calculate the period can take in order not to exceed memory
start(PmVid); tStart = tic;
% pause(PmVid.TimerPeriod)
%% % Stop acquisition MANNUALLY. Don't need if specified frames*triggers
stop(PmVid);
% tElapsed = toc(tStart)
disp(lastwarn); warning('on');
PmSrc.StreamAcquisition = 'OFF'; % 'OFF', 'RAW' or 'TIFF'
% PmSrc.FanSpeed = 'HIGH';
PmSrc.AutoContrast = 'ON';
PmPreview = preview(PmVid);
PmSrcInfo = get(getselectedsource(PmVid));
tElapsed = (PmVid.UserData)
save([TiffSavingPath datestr(now,'yyyymmdd') '_'...
SaveMeasName '_' num2str(PmSrcInfo.Exposure) PmSrcInfo.ExpRes '_'...
num2str(round(length(dir([TiffSavingPath '*F_PV*']))/(tElapsed))) 'fps' '_Meta.mat'],...
'PmSrcInfo');
%% %% run 2 Stimulation
SaveMeasName = [FileName '_RFon'];
trig_output(DG4, 'ON', DG4Info.Scope_Channel);
% trig_output(DG4, 'OFF', DG4Info.RF_Channel);
% % long video required, but fps halved as fastest memory logging
% stoppreview(PmVid);
TiffSavingPath = makeVideoDir('C:\Pictures\', 'Long', SaveMeasName);
PmSrc.StreamSavingPath = TiffSavingPath;
PmSrc.AutoContrast = 'OFF';
% PmSrc.FanSpeed = 'Off(Liquid Cooled)';
pause(2)
PmSrc.StreamAcquisition = 'TIFF'; % 'OFF', 'RAW' or 'TIFF' % disk stream give 50 frames/s
% PmPreview = preview(PmVid);
stoppreview(PmVid)
flushdata(PmVid);
warning('off');
% % using timmer of camera to stop image acquisition
PmVid.TimerPeriod = RFaction.nCycles * DG4Info.PeriodSec; % seconds, calculate the period can take in order not to exceed memory
trig_output(DG4, 'ON', DG4Info.RF_Channel);
pause(2)
start(PmVid); tStart = tic;
% pause(PmVid.TimerPeriod)
%% Stop acquisition MANNUALLY. Don't need if specified frames*triggers
stop(PmVid);
trig_output(DG4, 'OFF', DG4Info.RF_Channel);
trig_output(DG4, 'OFF', DG4Info.Scope_Channel);
% tElapsed = toc(tStart);
disp(lastwarn); warning('on');
PmSrc.StreamAcquisition = 'OFF'; % 'OFF', 'RAW' or 'TIFF'
% PmSrc.FanSpeed = 'HIGH';
PmSrc.AutoContrast = 'ON';
PmPreview = preview(PmVid);
PmSrcInfo = get(getselectedsource(PmVid));
tElapsed = (PmVid.UserData)
save([TiffSavingPath datestr(now,'yyyymmdd') '_'...
SaveMeasName '_' num2str(PmSrcInfo.Exposure) PmSrcInfo.ExpRes '_'...
num2str(round(length(dir([TiffSavingPath '*F_PV*']))/(tElapsed))) 'fps' '_Meta.mat'],...
'PmSrcInfo');
%%
stoppreview(PmVid);
%%
trigger_close(DG4);
Pm_close(PmVid);