如何在GUI图中更新轴和动画线

时间:2019-04-08 16:18:57

标签: matlab user-interface bluetooth gui-designer

我既无法更新xaxis限制,也无法在我的GUI图上显示动画线。轴滚动并没有出现传感器数据,或者出现了传感器数据并且轴限制设置不正确。

function stream_Callback(hObject, eventdata, handles)
global bt;
% initialize graph
axes(handles.realtime); % associate to plot in gui
zaxis = animatedline('Parent',handles.realtime);
xlabel('Time - s');
j = 1;
ymin = 1.4;
ymax = 2;
viewport = 1000; % size of window that is shown in graph
% initialize filter
lag_smooth = 50; % size of trailing window for moving average filter
buffer = nan(1,lag_smooth);
% initialize analysis
fs = 100; % sampling frequency 
bpm_buffer = 1500; % amount of data analyzed at a time
y = zeros(2,bpm_buffer);
m = 1;
n = 1;
% smoothing zscore parameters
lag = 25; 
threshold = 2.9; 
influence = 0; 
pulsewidth = 40;
% matlab 'findpeaks' parameters - width,height,prominence,threshold,distance
peakwidth = 40; % MinPeakWidth
peakprominence = 0.01; % MinPeakProminence

'''

while get(hObject,'Value') % while toggle button is true, start stream
    %% Filter Data
    % Smoothing Filter
    while(isnan(buffer(lag_smooth))) % if buffer is not full, fill it
        buffer = circshift(buffer,1);
        buffer(1) = fscanf(bt, '%f');
    end
    filtered = mean(buffer); % calculate moving average
    buffer = circshift(buffer,1); % shift points
    buffer(1) = fscanf(bt, '%f'); % add datapoint to buffer

    %% Display Data
    % set scrolling axis
    if(j>viewport) % moving viewport axis limits
        xmin=(j-viewport)/fs;
        xmax=j/fs;
    else % initial viewport
        xmin=0;
        xmax=viewport/fs;
    end

%     % update axis and add data to graph
%     axis([xmin xmax ymin ymax]); % update xaxis
    handles.realtime.XLim = [xmin xmax];
    handles.realtime.YLim = [ymin ymax];
    addpoints(zaxis,j/fs,filtered); % add filtered points to graph
    drawnow limitrate % update graph

    %% Analysis
    if(m == bpm_buffer) % amount of data to be analyzed
        % Smoothing zscore 
        [signals,avg,dev] = ThresholdingAlgo(y(2,:),lag,threshold,influence); % send y to threshold algo
        [numpeaks] = countPeaks(signals,pulsewidth); % count peaks 
        breathingrate(1,n) = numpeaks*(60/(bpm_buffer/fs)); % bpm of zscore algo, convert s to min

        % Matlab findpeaks
        [pks,locs,w,p] = findpeaks(y(2,:),'MinPeakWidth',peakwidth,...
            'MinPeakProminence',peakprominence); 
        breathingrate(2,n) = length(locs)*(60/(bpm_buffer/fs));

        % classify pattern
        if(breathingrate(2,n)<1)
            pattern(n)="Not Breathing - Apnea";
        elseif(breathingrate(2,n)>8 && breathingrate(1,n)<24)
            pattern(n)="Normal - Eupnea";
        end

        data{1,n} = y; % test purposes only, store data

        n=n+1;
        m=1;
    else
        y(1,m) = j/fs; % time
        y(2,m) = filtered; % add point to buffer to be analyzed
        m=m+1;
    end

    j=j+1;

end

当传感器数据添加到绘图中时,我希望x轴滚动。另外,我希望第二个GUI轴使用峰值检测结果进行更新。每当填充“ bpm_buffer”时就会发生这种情况。

0 个答案:

没有答案