55 %
66 %
77 % Hook up AO0 of DAQ_a to AI0 of DAQ_a and AO0 of DAQ_b to AI1 of DAQ_a
8- %
8+ % Then run, e.g. vidrio.sync.phaseMonitor('DAQ_a','DAQ_b';
9+ % The input args are the device IDs. First is the one with the AI connections.
910 %
1011 % Also see:
1112 % vidrio.sync.sine_AO_AI, vidrio.mixed.AOandAI, vidrio.mixed.AOandAI_OO,
2526 axis_B
2627 axis_C
2728
29+ lastDataHandle_A
30+ lastDataHandle_B
31+ lastDataHandle_BA % Copy of _A
32+ lastDataHandle_C
33+
34+ histData_B
35+ histDataHandle_B
36+ histData_C
37+ histDataHandle_C
38+
39+ minPointsToPlot % We trigger the waveform at the upward 0 V crossing so it looks consistent and we plot at least this many points
2840 end
2941
3042
4759 obj.axis_A = axes(' Parent' , obj .hFig , ' Position' , [0.1 0.12 0.4 0.4 ]);
4860 obj.axis_B = axes(' Parent' , obj .hFig , ' Position' , [0.1 0.55 0.4 0.4 ]);
4961 obj.axis_C = axes(' Parent' , obj .hFig , ' Position' , [0.55 0.12 0.4 0.8 ]);
62+ set([obj .axis_B ,obj .axis_C ],' NextPlot' ,' add' )
5063
5164 % Plot some empty data which we will later modify in readAndPlotData
5265 % in the first two plots we show the two waveforms as a function of time
53- plot(obj .axis_A , zeros(round(obj .taskA .sampleRate * obj .taskA .updatePeriod ),1 ))
54- plot(obj .axis_B , zeros(round(obj .taskA .sampleRate * obj .taskA .updatePeriod ),1 ))
66+ obj.minPointsToPlot = round((obj .taskA .sampleRate * obj .taskA .updatePeriod )/3 );
67+ obj.lastDataHandle_A = plot(obj .axis_A , zeros(obj .minPointsToPlot ,1 ), ' -' ,' color' , [1 ,0.4 ,0.4 ],' linewidth' ,2 );
68+ obj.histData_B = nan(obj .minPointsToPlot ,1 );
69+ obj.histDataHandle_B = plot(obj .axis_B , obj .histData_B , ' -' );
70+ obj.lastDataHandle_B = plot(obj .axis_B , zeros(obj .minPointsToPlot ,1 ), ' -k' ,' linewidth' ,2 );
71+ obj.lastDataHandle_BA = plot(obj .axis_B , zeros(obj .minPointsToPlot ,1 ), ' -' ,' color' , [1 ,0.75 ,0.75 ],' linewidth' ,3 );
72+
5573
5674 % In the third plot we will show AI 1 as a function of AI 0
57- plot(obj .axis_C , zeros(round(obj .taskA .sampleRate * obj .taskA .updatePeriod ),1 ),' .-' )
75+ obj.lastDataHandle_C = plot(obj .axis_C , zeros(round(obj .taskA .sampleRate * obj .taskA .updatePeriod ),1 ),' -k' ,' linewidth' ,2 );
76+ obj.histData_C = nan(obj .minPointsToPlot ,1 ,2 );
77+ obj.histDataHandle_C = plot(obj .axis_C , obj .histData_C(: ,: ,1 ), obj .histData_C(: ,: ,2 ), ' -' );
5878
5979 % Make plots look nice
60- obj.axis_A.YLabel.String= ' Voltage (V)' ;
80+ obj.axis_A.YLabel.String= [ obj . taskA . DAQdevice , ' Voltage (V)' ] ;
6181 obj.axis_A.XLabel.String= ' Samples' ;
6282
63- obj.axis_B.YLabel.String= ' Voltage (V)' ;
83+ obj.axis_B.YLabel.String= [ obj . taskB . DAQdevice , ' Voltage (V)' ] ;
6484 obj.axis_B.XLabel.String= ' ' ;
6585 obj.axis_B.XTickLabel= [];
6686
67- % Set properties of axes together
68- set([obj .axis_A ,obj .axis_B ], ' Box' , ' On' , ' XGrid' , ' On' , ' YGrid' , ' On' , ' YLim' , [obj .taskA .minVoltage ,obj .taskA .maxVoltage ])
69- set(obj .axis_C , ' XLim' , [obj .taskA .minVoltage ,obj .taskA .maxVoltage ])
70-
71-
72-
87+ obj.axis_C.XLabel.String= [obj .taskA .DAQdevice , ' Voltage (V)' ];
88+ obj.axis_C.YLabel.String= [obj .taskB .DAQdevice , ' Voltage (V)' ];
7389
90+ % Set properties of axes together
91+ set([obj .axis_A ,obj .axis_B ,obj .axis_C ], ' Box' , ' On' , ' XGrid' , ' On' , ' YGrid' , ' On' , ' YLim' , [obj .taskA .minVoltage ,obj .taskA .maxVoltage ], ' XLim' ,[0 ,obj .minPointsToPlot ])
7492
7593 addlistener(obj .taskA ,' acquiredData' , ' PostSet' , @(src ,eventData ) obj .plotIt(src ,eventData ) );
7694
@@ -91,16 +109,48 @@ function delete(obj)
91109 function plotIt(obj ,src ,eventData )
92110
93111 AIdata= eventData .AffectedObject .acquiredData ; % Get the data
112+
113+ % lock to the first upward 0 V crossing
114+ tmp= smooth(AIdata(: ,1 ));
115+ tmp= round(tmp ,2 );
116+ f= find(tmp(1 : end - 1 ,1 )==0 & diff(tmp(: ,1 ))>0 );
117+ if isempty(f )
118+ return
119+ end
120+
121+ AIdata(1 : f(1 ),: )=[];
122+ if length(AIdata )<obj .minPointsToPlot
123+ % Do not proceed if not enough points are available to plot
124+ return
125+ end
126+
94127 % We keep the plot objects the same and just change their data properties
95- C= get(obj .axis_A , ' Children' );
96- C(1 ).YData= AIdata(: ,1 );
128+ obj.lastDataHandle_A.YData= AIdata(: ,1 );
129+
130+
131+
132+ obj .histData_B(: ,end + 1 )=AIdata(1 : obj .minPointsToPlot ,2 );
133+ obj.axis_B.ColorOrder= flipud(gray(size(obj .histData_B ,2 ))) ;
134+ delete(obj .histDataHandle_B )
135+ obj.histDataHandle_B= plot(obj .axis_B ,obj .histData_B ,' linewidth' ,1.5 );
136+
137+ obj.lastDataHandle_B.YData= AIdata(: ,2 );
138+ uistack(obj .lastDataHandle_B ,' top' )
139+ obj.lastDataHandle_BA.YData = AIdata(: ,1 );
140+
141+
142+ obj.lastDataHandle_C.XData= AIdata(: ,1 );
143+ obj.lastDataHandle_C.YData= AIdata(: ,2 );
144+
145+
146+ obj .histData_C(: ,end +1,1)=AIdata(1:obj .minPointsToPlot ,1);
147+ obj .histData_C(:,end , 2 )=AIdata(1 : obj .minPointsToPlot ,2 );
97148
98- C= get(obj .axis_B , ' Children' );
99- C.YData= AIdata(: ,2 );
149+ obj.axis_C.ColorOrder= flipud(gray(size(obj .histData_B ,2 ))) ;
150+ delete(obj .histDataHandle_C )
151+ obj.histDataHandle_C= plot(obj .axis_C , obj .histData_C(: ,: ,1 ), obj .histData_C(: ,: ,2 ), ' linewidth' ,2 );
152+ uistack(obj .lastDataHandle_C ,' top' )
100153
101- C= get(obj .axis_C , ' Children' );
102- C.YData= AIdata(: ,1 );
103- C.YData= AIdata(: ,2 );
104154 end % close plotIt
105155
106156
0 commit comments