How i do my RMS function on Embedded Matlab Function

1 visualización (últimos 30 días)
Arthur
Arthur el 28 de Ag. de 2012
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

Respuesta aceptada

Ryan G
Ryan G el 29 de Ag. de 2012
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 comentarios
Ryan G
Ryan G el 30 de Ag. de 2012
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.
Mike Hosea
Mike Hosea el 2 de Sept. de 2012
Support for circshift was added in R2008b.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deployment, Integration, and Supported Hardware en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by