Error in function with circular buffer for simulink.

5 views (last 30 days)
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

Answers (1)

Vinay
Vinay about 7 hours ago
Edited: Vinay less than a minute ago
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!

Categories

Find more on Simulink in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!