Why is my Simulink Real-Time "File Scope" missing samples in logged data (R2020a and earlier)?

15 views (last 30 days)
I use File Scopes in my Simulink Real-Time application to log signal data on the target computer (feature available in R2020a and earlier). I notice that if the amount of data entering the scope is high enough, it starts missing samples from the logged data. How can I avoid this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 11 Jan 2023
Edited: MathWorks Support Team on 11 Jan 2023
There is a section in our documentation that explains how and why data loss can happen in a File Scope when Autorestart is on:
“The file scope acquires data and writes it to the file named in the FileName parameter. The scope writes data samples into a memory buffer of size given by the Number of Samples parameter. It copies data from the memory buffer into the file in blocks of size given by the WriteSize parameter.
The Number of samples parameter works with the autorestart setting.
  • Autorestart is on — When the scope triggers, the scope starts collecting data into a memory buffer. A background task examines the buffer and writes data to the disk continuously, appending new data to the end of the file. When the scope reaches the number of samples that you specified, it starts collecting data again, overwriting the memory buffer. If the background task cannot keep pace with data collection, data can be lost.
If the buffer is too small and the model rate is too fast, the background task (which writes the memory buffer to disk) is not yet finished by the time the buffer fills up again. The Autorestart option may lead to a loss of data in such cases.
By increasing the Number of Samples, you can increase the size of the buffer, which means the buffer fills up less frequently. By increasing WriteSize, the background thread can write more data to the disk, hence it helps keep up with the data collection.
You can also switch off Autorestart to avoid this issue.
--------------------------------------------------------------------------------------------------------
NOTE: File Scopes are only available in R2020a and earlier. In R2020b and beyond, use File Logs to log signal data on the target computer: How does the new File Log block work in R2020b and later, and how is it different from the old File Scope block in Simulink Real-Time?

More Answers (0)

Community Treasure Hunt

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

Start Hunting!