Simulink error in 2-D CFAR during compile

5 views (last 30 days)
Rainer
Rainer on 8 Apr 2025
Answered: Shubhanshu on 14 Apr 2025
I use the 2-D CFAR Detector block form Phased Array System Toolbox -2.
For algorihm "CA" simulation works for "Interpreted execution" as well as for "Code generation".
For algorithm "SOCA" (and "GOCA") it works for "Interpreted execution" but it throws an error for "Code generation":
An error occurred in the block 'test_model/CFAR detection/2-D CFAR Detector' during compile.
Caused by:
Simulink detected an error
'Unable to write a value of type single into a variable of type double. Code generation does not support changing types through assignment. To investigate the cause of the type mismatch, check preceding assignments or input type specifications.'.
The error occurred for MATLAB System block 'test_model/CFAR detection/2-D CFAR Detector'. See line 377, column 21 in file 'C:\Program Files\MATLAB\R2024b\toolbox\phased\phased\+phased\CFARDetector2D.m'. The error was detected during code generation phase.
Start code generation report.
To prevent this error, use one of the following:
* Modify the System object to avoid code that does not support code generation.
* Change 'Simulate using' parameter to 'Interpreted Execution'.
When I simply insert a typ conversion in line 377 another error pops up at a different line.
Is there any solution or workaround or does this mean that code generation is not possible for SOCA CFAR-2D?

Answers (1)

Shubhanshu
Shubhanshu on 14 Apr 2025
The issue arises because the "Idx" input to the block requires a double data type, while the "X" data input supports both double and single data types for code generation.
To resolve this, please use a "Data Type Conversion" block for the "Idx" input in the Simulink model itself.
In the model, the cutidx (Idx input to the block) is initially of single data type, as generated from the matlab script. By employing a data type conversion block, the 2-D CFAR Simulink block, configured with the SOCA algorithm and Simulation mode set to Code Generation, operates without error, when generated code using Embedded Coder as well as Simulink Coder.
It is advisable not to modify the source code of the block. Instead, you can alter the data type either through the MATLAB interface or directly within the Simulink model. For your convenience, also sharing the documentation for the 2-D CFAR Detector block, which includes the supported data types for the input data. 2-D CFAR Detector

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!