Main Content

Composite Component with Equations — RMS Voltage Sensor

The VoltageSensorRMS component implements a voltage sensor that measures the root mean square (RMS) value of AC voltage between two electrical nodes. The declaration and equation sections of this component are similar to those of a regular voltage sensor, described in No-Flow Component — Voltage Sensor. But in order to calculate the RMS value of the measured voltage, this composite component uses the PS RMS Estimator block from the Simscape™ Foundation library.

The declaration section of the component contains:

  • Two electrical nodes, p and n (for + and – terminals, respectively)

  • One output port, Vrms, to output the RMS value of the measured voltage as a physical signal

  • Parameter f0, to specify base frequency for the RMS calculation

  • An Across variable, voltage v1, to be connected to the electrical domain later in the file

There is no current flow through the sensor. Therefore, a Through variable (current ) is not declared, and there is no branches section.

In the equations section, the first equation, v1 == p.v - n.v, establishes the relationship between the component Across variable, voltage v1, and the component nodes (and therefore the domain Across variable at these nodes). It defines the voltage across the sensor as the difference between the node voltages.

The second equation, RMS.I == v1, defines the voltage sensor action. The voltage across the sensor nodes equals the input signal to the PS RMS Estimator block, which is included as a member component, RMS, later in the file.

The components section contains the PS RMS Estimator block from the Simscape Foundation library, as a member component. The components section also links the top-level parameter, f0, declared in the parameters declaration section of the composite component, to the f0 parameter of the underlying member component. This parameter specifies the base frequency for RMS calculation.

The connections section connects the output of the member component, RMS.O, to the top-level output port, Vrms.

component VoltageSensorRMS
% Voltage Sensor (RMS)
% The block measures root mean square (RMS) value
% of AC voltage between two electrical ports.
% To obtain meaningful results, run the simulation for 
% at least one full time period of the signal.

    nodes
        p = foundation.electrical.electrical; % +
        n = foundation.electrical.electrical; % -
    end
    outputs
        Vrms = {0, 'V'}; % Vrms
    end
    annotations
        p : Side=top;
        n : Side=bottom;
        Vrms : Side=right;
    end
    parameters
        f0 = {60, 'Hz'}; % Base frequency
    end
    variables
        v1 = { 0, 'V' }; % Voltage
    end

    % Component Equations
    equations
        v1 == p.v - n.v;
        RMS.I == v1;
    end

    % Composite Components
    components(ExternalAccess=none)
        RMS = foundation.signal.periodic_operators.RMS(f0=f0);
    end
    connections
        connect(RMS.O,Vrms);
    end
end

Related Topics