Skip to content

Commit 35cb46d

Browse files
committed
adding option for RMS output
1 parent 4482b37 commit 35cb46d

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

vis_stream.m

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function vis_stream(varargin)
8686
arg({'freqfilter','FrequencyFilter','moving_avg','MovingAverageLength'},0,[0 Inf],'Frequency filter. The parameters of a bandpass filter [raise-start,raise-stop,fall-start,fall-stop], e.g., [7 8 14 15] for a filter with 8-14 Hz pass-band and 1 Hz transition bandwidth between passband and stop-bands; if given as a single scalar, a moving-average filter is designed (legacy option).'), ...
8787
arg({'reref','Rereference'},false,[],'Common average reference. Enable this to view the data with a common average reference filter applied.'), ...
8888
arg({'standardize','Standardize'},false,[],'Standardize data.'), ...
89+
arg({'rms','RMS'},true,[],'Show RMS for each channel.'), ...
8990
arg({'zeromean','ZeroMean'},true,[],'Zero-mean data.'), ...
9091
arg_nogui({'parent_fig','ParentFigure'},[],[],'Parent figure handle.'), ...
9192
arg_nogui({'parent_ax','ParentAxes'},[],[],'Parent axis handle.'), ...
@@ -96,7 +97,7 @@ function vis_stream(varargin)
9697
% create stream inlet, figure and stream buffer
9798
inlet = create_inlet(lib,opts);
9899
stream = create_streambuffer(opts,inlet.info());
99-
[fig,ax,lines] = create_figure(opts,@on_key,@on_close);
100+
[fig,axrms,ax,lines] = create_figure(opts,@on_key,@on_close);
100101
% optionally design a frequency filter
101102
if length(opts.freqfilter) == 4
102103
B = design_bandpass(opts.freqfilter,stream.srate,20,true);
@@ -151,7 +152,7 @@ function on_timer(varargin)
151152
plottime = linspace(stream.xmin,stream.xmax,stream.pnts);
152153

153154
% update graphics
154-
if isempty(lines)
155+
if isempty(lines)
155156
lines = plot(ax,plottime,plotdata);
156157
title(ax,opts.streamname);
157158
xlabel(ax,'Time (sec)','FontSize',12);
@@ -164,9 +165,19 @@ function on_timer(varargin)
164165
end
165166

166167
% update the axis limit and tickmarks
167-
axis(ax,[stream.xmin stream.xmax -opts.datascale stream.nbchan*opts.datascale + opts.datascale]);
168+
axis(ax ,[stream.xmin stream.xmax -opts.datascale stream.nbchan*opts.datascale + opts.datascale]);
168169
set(ax, 'YTick',plotoffsets, 'YTickLabel',{stream.chanlocs(channels_to_get).labels});
169170

171+
% compute RMS and show it
172+
if opts.rms
173+
axis(axrms,[stream.xmin stream.xmax -opts.datascale stream.nbchan*opts.datascale + opts.datascale]);
174+
rms = sqrt(mean(bsxfun(@minus, plotdata, mean(plotdata,2)).^2,2));
175+
rmsStr = {};
176+
for iRms = 1:length(rms)
177+
rmsStr{iRms} = sprintf('%2.1f uVrms', rms(iRms));
178+
end
179+
set(axrms, 'YTick',plotoffsets, 'YTickLabel',rmsStr);
180+
end
170181
drawnow;
171182
catch e
172183
% display error message
@@ -225,7 +236,8 @@ function on_close(varargin)
225236
end
226237

227238
% create a new figure and axes
228-
function [fig,ax,lines] = create_figure(opts,on_key,on_close)
239+
function [fig,axrms,ax,lines] = create_figure(opts,on_key,on_close)
240+
axrms = [];
229241
if isempty(opts.parent_ax)
230242
if isempty(opts.parent_fig)
231243
fig = figure('Name',['LSL:Stream''' opts.streamname ''''], 'CloseRequestFcn',on_close, ...
@@ -234,7 +246,12 @@ function on_close(varargin)
234246
else
235247
fig = opts.parent_fig;
236248
end
237-
ax = axes('Parent',fig, 'YDir','reverse');
249+
if opts.rms
250+
axrms = axes('Parent',fig, 'YAxisLocation', 'right', 'YDir','normal', 'position', [0.1300 0.1100 0.7050 0.8150]);
251+
ax = axes('Parent',fig, 'YDir','normal', 'position', [0.1300 0.1100 0.7050 0.8150]);
252+
else
253+
ax = axes('Parent',fig, 'YDir','normal');
254+
end
238255
else
239256
ax = opts.parent_ax;
240257
end

0 commit comments

Comments
 (0)