Error in function with circular buffer for simulink.

조회 수: 5 (최근 30일)
Manmohan Butola
Manmohan Butola 2021년 8월 3일
편집: Vinay 2024년 11월 21일 6:47
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