Error in function with circular buffer for simulink.

5 次查看(过去 30 天)
Hello.
I have created a simulink function which takes two inputs and put them in separate circular bufffers circBuff_In_1 and circBuff_In_2. This function calls another function 'Linearizer.m' which is adding the first elements of cicular buffers. But there is an error stating 'An error occured while running the simulation and simulation was terminated caused by : circBuff_In_1 ' Kindly help me rectifying this error. Model and function code attached herewith.
Thanks

回答(1 个)

Vinay
Vinay 2024-11-21,6:46
编辑:Vinay 2024-11-21,6:47
The MATLAB function in the simulink model creates two circular buffers named as 'circBuff_In' and 'circBuff_PA' to store the input signal.But the linearizeer function is using different variable names which is causing the issue.
The MATLAB function code can be updated to use the correct variable names as given below
function Output = lin_Fun(In_1,In_2)
coder.extrinsic('Linearizer');
Output= 0;
persistent circBuff_In;
persistent circBuff_PA;
if isempty(circBuff_In)
circBuff_In = zeros(1,10);
end
if isempty(circBuff_PA)
circBuff_PA = zeros(1,10);
end
global N;
global n;
Output = circBuff_In(1)+circBuff_PA(1);
circBuff_In = [In_1 circBuff_In(1:end-1)];
circBuff_PA = [In_2 circBuff_PA(1:end-1)];
end
The figure below shows the result of the spectrum analyzer
Hope this would resolve the issue!

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by