what is the meaning of this “matlab function block”?what is the purpose?(power factor correction(PFC))

1 view (last 30 days)
function y = fcn(u)
persistent counter;
persistent sum;
persistent out;
if isempty(counter)
counter = fi(0,1,32,0);
end
if isempty(sum)
sum = fi(0,1,32,22);
end
if isempty(out)
out = fi(1,1,32,22);
end
counter = fi(counter + 1,1,32,0);
sum = fi(sum + u,1,32,22);
if (counter == fi(500,1,32,0))
y = fi(sum/counter,1,32,22);
out = y;
sum = fi(0,1,32,22);
counter = fi(0,1,32,0);
else
y = out;
end
end
simulink model's website:
  2 Comments
xin li
xin li on 9 Sep 2020
Hi,How did you find and open this model? it show me this message ''No system or file called 'c28035pfc.slx' found.'', when I try this ''open_system('c28035pfc.slx')'' command in the command window.
Thanks a lot.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 19 Dec 2019
It uses fixed-point calculations with a 32 bit signed integer counter and a 32 bit signed fixed point accumulator with 22 bits of fraction.
It accepts inputs and counts how many it has seen so far, and adds the input to the accumulator. If you have encountered 500 values then the mean of the 500 values is taken and becomes the output and the counter and accumulation are reset. For any iteration that is not the 500th since the last reset, the output is the previous mean.
So you are taking the mean of each 500 samples and holding the mean until the next 500 is ready.
I probably would have investigated using a different approach such as using an integrator block and a zero order hold, but on the other hand that approach might make it more difficult to use the exact precisions desired.
This block could likely be deployed to HDL without requiring a floating point core.
I suspect that it could be made slightly more efficient by recoding the division as multiplication by 1/500 expressed as a constant fi() .
  3 Comments
MARIMUTHU G
MARIMUTHU G on 25 Apr 2020
Hi May I get following other supporting files of PFC model

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!