simulink SOS block inputs

6 visualizzazioni (ultimi 30 giorni)
Peter
Peter il 5 Mar 2025
Risposto: Aravind il 12 Mar 2025
Hi,
Seems the SOS block works fine if coefficients are entered as "dialog parameters", but using input ports is not working for me. This is the process:
Bcoeffs = px3 array
save('Bcoeffs_file.mat','Bcoeffs','-v7.3');
Then I connect the mat file in simulink to the SOS block numerator coefficients input (using from file) and it throws an error that there are 7 columns. There is clearly a stage when it reads in data which I can't see. I wonder:
  1. Can I monitor what it reads (e.g. place something at the output of the from file block) to see what it's interpreting?
  2. Save the mat file in a different way?
Thanks
Pete

Risposte (2)

praguna manvi
praguna manvi il 12 Mar 2025
Hi @Peter,
As I see it, you are looking to connect a ".mat" file with input parameters to an "SOS" filter block in Simulink. Consider saving the data as a "timeseries" object and loading it using the "From File" block. Here is an example:
r1 = [0.1, 0.1, 0.2]; % Example for num
r2 = [0.3, 0.4, 0.5]; % Example for denom
% Create timeseries objects with the correct format
ts1 = timeseries(reshape(r1, 1, []), 1); % Reshape to 1x3
ts2 = timeseries(reshape(r2, 1, []), 1); % Reshape to 1x3
% Save the timeseries objects
save('r1.mat', 'ts1', '-v7.3');
save('r2.mat', 'ts2', '-v7.3');
With the blocks connected as follows, the output is shown below:

Aravind
Aravind il 12 Mar 2025
Hi @Peter,
It seems you're trying to use the "From File" block in Simulink to load coefficients from a MAT file for the “numerator” port of the "Second-Order Section Filter" block, but you're encountering a dimension error with the output from the "From File" block.
As per the documentation at https://www.mathworks.com/help/simulink/slref/fromfile.html the "From File" block can load data from a MAT file stored as either a timeseries or an array. If loading from an array, the first row is assumed to contain time data, while subsequent rows contain data for each scalar or vector signal.
For instance, to output 3 signals from the MAT file, the array in the MAT file should be 4xN, where the first row is the time data with "N" time points, and the remaining 3 rows have the signal values at those times.
In your situation, you have stored a px3 array in the MAT file. Simulink interprets this as p-1 signals with time data defined for 3 instants in the first row. Consequently, the "From File" block outputs a vector of size p-1, whereas the "numerator" port of the "Second-Order Section Filter" block expects a vector of size 3, causing the error.
To resolve this, adjust the coefficients matrix stored in the MAT file to be a 4xp array. The first row should have the time data, and the following 3 rows should contain the coefficient values at the time points in the first row. This adjustment allows the "From File" block to output a vector of size 3, suitable for the "numerator" port of the "Second-Order Section Filter" block, eliminating the error.
For more details on storing and loading array data from a MAT file in Simulink, refer to this example: https://www.mathworks.com/help/simulink/ug/load-data-using-the-from-file-block.html#d126e233224.
I hope this helps resolve your issue.

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by