How i do my RMS function on Embedded Matlab Function
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello.
I need to create my RMS block to use with simulink. This is the first part of a protection relay project. So i'll test many algoritms to do this. I already did this on m-file project but im want to do this a dinamic mode.
I've read about of coder.extrinsic.
Example:
% Mann & Morrison algoritm
f0=60;
w=2*pi*f0;
b=(1/w)^2;
c=1/sqrt(2);
fs=32*f0; % sample frenq. 32 sample per cycle.
dt=1/fs;
der=(I(n) - I(n-2))/(2*dt); %I is a imput (sine wave block)
Ief(n-1)=c*(sqrt(I(n-1)^2 + b*(der)^2)); %Ief is a RMS value at sample n
n=n+1;
I dont know how i work with arrays on the function block. I need a buffer?
Thanks
댓글 수: 0
채택된 답변
Ryan G
2012년 8월 29일
If you don't need to generate code from this Embedded MATLAB block and you are not overly concerned with simulation speed then you can call the entire function extrinsically as long as the output of the block is always the same size. You will need to initialize the output regardless by doing something like:
y = 0;
before the function call.
If the output is variable size you will need to buffer the output. Say you know the output will never exceed 100 elements, you can initialize the output like so:
y = zeros(1,100);
and fill in the block as needed with the actual values as they become available.
댓글 수: 3
Ryan G
2012년 8월 30일
I'm assuming this is still giving you issues I don't see x0 anywhere but the first branch of the if-statement. x0 will need to be initialized in all branches of the if statement because otherwise, say flag never equaled 0, x0 would never be initialized.
You may have an issue with circshift if it's not supported by code generation, however, you can set it with
coder.extrinsic('circshift')
if needed. Same may go for abs, but I bet that is supported.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!