How to handle large variables in workspace

3 ビュー (過去 30 日間)
진환 유
진환 유 2021 年 7 月 28 日
コメント済み: Frederick Acquah 2022 年 10 月 7 日
I have a code shown below which reads data from data aquisition object and updates variable signal and update time plot and specturm plot. the problem is that, as measurement goes along(which means very large size of variable signal), plot update speed and UIApp(created by app designer) performance get significantly slow. threshold timing depends on sampling frequency. In case of 51200Hz, I found it is approximately 40sec. but I need to measure data while 120sec... so how can I handle this large size of data generated in workspace?
n = ceil(app.daqDevice.Rate/10);
signal = [];
% start measurement
start(app.daqDevice,"continuous")
pause(0.1)
while(1)
% check measurement end condition
if app.Button_2.Value == 1
stop(app.daqDevice)
app.Button.Value = 0;
save(fullfile(app.SaveFolderPath,...
str2double(app.TrialNumber_Value.Text)+...
"_"+app.SpeedList.Value+".mat"),...
'signal')
return;
end
% read data form DataAquisition Obj
data = read(app.daqDevice,n);
% update measured value
signal = [signal; data];
% update time plot
plot(app.Timeplot,data.Time, data.Variables)
ylim(app.Timeplot,[-1,1])
% update spectrum plot
[pxx,f] = pwelch(data.Variables,512,256,1024,32000);
plot(app.PSDplot,f, 10*log10(pxx))
end

採用された回答

Chunru
Chunru 2021 年 7 月 28 日
編集済み: Chunru 2021 年 8 月 2 日
Only process the latest data and throw away old data. You need to consider streaming processing of your data. See suggestions below in the code.
n = ceil(app.daqDevice.Rate/10);
%signal = [];
% Pre-allocate memory space for fixed amount of data
% This will make program faster
signal = zeros(nmax, 1); % nmax number of samples
% For data logging, consider fopen and fwrite for speed.
% start measurement
start(app.daqDevice,"continuous")
pause(0.1)
while(1)
% check measurement end condition
if app.Button_2.Value == 1
stop(app.daqDevice)
app.Button.Value = 0;
% save data block by block not in one-go
save(fullfile(app.SaveFolderPath,...
str2double(app.TrialNumber_Value.Text)+...
"_"+app.SpeedList.Value+".mat"),...
'signal')
return;
end
% read data form DataAquisition Obj
data = read(app.daqDevice,n);
% save data here using fwrite
% update measured value
signal(1:nmax-n) = singal(n+1:nmax); % shift data
signal(nmax-n+1:nmax) = data; % attach new data
%signal(nmax ) = [signal; data];
% update time plot
% plot the buffered signal instead of all signal
plot(app.Timeplot, data.Time, data.Variables)
ylim(app.Timeplot,[-1,1])
% compute spectrum on buffered data signal below
% update spectrum plot
[pxx,f] = pwelch(data.Variables,512,256,1024,32000);
plot(app.PSDplot,f, 10*log10(pxx))
end
  3 件のコメント
Chunru
Chunru 2021 年 8 月 2 日
Nice to learn that.
Frederick Acquah
Frederick Acquah 2022 年 10 月 7 日
I tried this code and I am getting an error because the data type of signal is a double while data is a timetable.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSignal Generation, Manipulation, and Analysis についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by