Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

PRBS generator

PRBS generator

Hi,

I need to create or use a PRBS (Pseudo-Random Binary Signal), which is based on a logical shift register, in Modelica.

Do you know if is it an existing Modelica function to do that or not ?

Thanks in advance.

Best regards,
DC

Edited by: dcasner - Nov-28-11 11:57:36

Re: PRBS generator

Hi,

I have found a library where the PRBS generator is included : the FuelCellLib one.
This library is available on : https://www.modelica.org/libraries/FuelCellLib (See documentation page 7).

I extracted the code I needed:

Code:

model PRB_Load

   
    extends inter.OnePort;
    SI.Resistance R(start=1);
    parameter SI.Resistance HighVal=1 "High Value Resistance";
    parameter SI.Resistance LowVal=0.01 "Low Value Resistance";
    parameter SI.Time Period=10 "Maximum period of oscillation";
   
    Real sig;
    Real tevent;
equation
   
    //The value of resistance will oscillate aleatorily between
    //"HighVal" and "LowVal" with a maximum period of "Period"   
   
    when time > pre(tevent) then
      sig = 1 - pre(sig);
      tevent = time + (RandomUniform(time))/Period;
      R = ((HighVal - LowVal)*sig) + LowVal;
    end when;
   
    R*i = v;
end PRB_Load;

But when I compile the program, it fails because the following types are missing
- SI.Resistance. Should I change it to Modelica.SIunit.Resistance ?
- inter.OnePort : Is there an equivalent in OpenModelica ?
- RandomUniform (I suppose it is include in inter.OnePort)

Thanks in advance, for your reply.

Best,
DC

Re: PRBS generator

Hi,

I took a look at the FuelCellLib library, and if you look at the top package in FuelCellLib you will see some imports for inter and SI:

Code:


import inter = Modelica.Electrical.Analog.Interfaces;
import SI = Modelica.SIunits;

So inter is simply an alias for Modelica.Electrical.Analog.Interfaces while SI is an alias for Modelica.SIunits. You can just add those imports to the model and it should work, or replace inter and SI with their full paths.

RandomUniform does not exist in either the Modelica Standard Library or FuelCellLib though, so you will have to implement it yourself unless you can find an implementation of it. Based on the name I would guess that it's simply a uniform distribution PRNG. Modelica does not have any random generators built in, but you can write an external C function that calls rand or the PRNG of your choice quite easily.

There are 0 guests and 0 other users also viewing this topic