Difference between signal passed to Simulink and immediately logged
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I'm working with some Simulink models (2016a) where I pass some Matlab workspace signals to Simulink using the From Workspace block. As a sanity check, I tried to log the very same signal to Matlab using the To Workspace block and I noticed something weird.
Essentially, I get no error between the original Matlab signal and the logged Simulink signal for the first half of the simulation, while for the remaining part of the simulation there is some error building up between the signals. It's not a big error, compared to the signals I'm using, but I'm just wondering if there's any way to get exactly the same result (it doesn't seem to be machine precision).
This is a screenshot of the model (which I also attached):
and this is what I obtain comparing the signals (notice how the difference is of several order of mags, but abruptly goes from 0 to some 1e-13 value):
The code I run
fs = 16e3; % sampling freq
siglen = 1; % 1 second
siglen_samp_rec = siglen*fs;
data = 0.1*rand(1,siglen_samp_rec).';
time_test_ts = (0:1/fs:(siglen_samp_rec-1)/fs);
% Save to time series
test_ts = timeseries(data,time_test_ts);
options = simset('SrcWorkspace','current');
tic
sim('test_diff',[],options)
toc
test_TD = squeeze(test_tsl.signals.values);
figure;
subplot(211); plot(data); hold on; plot(test_TD(1:end-1)); title 'Signals'
subplot(212); plot((data-test_TD(1:end-1))); title 'Error'
norm(abs(data(1:siglen*fs)-test_TD(1:siglen*fs)))
0 comentarios
Respuestas (1)
Mark McBroom
el 9 de Jun. de 2018
Is the "interpolate data" option set for the "from workspace" block? I am guessing there are slight nuerical differences between Simulink time at a given time step and the time in your timeseries. As a result, Simulink is interpolating your timeseries data to match with current simulink time, causing a slight difference.
Ver también
Categorías
Más información sobre Prepare Model Inputs and Outputs en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!