Error in function with circular buffer for simulink.

5 Ansichten (letzte 30 Tage)
Manmohan Butola
Manmohan Butola am 3 Aug. 2021
Bearbeitet: Vinay am 21 Nov. 2024 um 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

Antworten (1)

Vinay
Vinay am 21 Nov. 2024 um 6:46
Bearbeitet: Vinay am 21 Nov. 2024 um 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!

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by