Average Power RMS Voltage RMS Current Power Factor Calculation using Matlab

In this tutorial, we will calculate average power, RMS Voltage, RMS Current as well as power factor using Matlab.

Let’s say we have following values of voltage and current:

$\begin{align}  & v(t)=10\cos (120\pi t+{{30}^{o}}) \\ & and \\ & i(t)=6\cos (120\pi t+{{60}^{o}}) \\\end{align}$

We use the following formula to calculate the RMS voltage and current:

${{V}_{rms}}=\sqrt{\frac{1}{T}\int\limits_{0}^{T}{{{v}^{2}}(t)dt}}$

And

${{I}_{rms}}=\sqrt{\frac{1}{T}\int\limits_{0}^{T}{{{i}^{2}}(t)dt}}$

And for power, we have the following relation:

$P=\frac{1}{T}\int\limits_{0}^{T}{v(t)i(t)dt}$

For power factor, we will use the following equation:

$PF=\frac{P}{{{V}_{rms}}{{I}_{rms}}}$

Now, let’s implement above mentioned formulas in Matlab:

clc;clear all;close all;clc
% Power and Power Factor Calculations using Matlab
T = 2*pi/(120*pi); % Sine Wave period (T=2*pi/Omega) where Omega=2*pi*f
x = 0; %Integration Lower Limit for Voltage and Current
y = T; %Integration upper Limit for Voltage and Current
k = 0:0.2:1;
t = k.*y; % Horizontal (x-axis) Scale for one complete cycle (which is from 0 to T=1/f)
% quad command is used to compute integration. Write "help quad" in Maltab GUI for
% detailed understanding
%% Calculating Voltage, Current, and Power using Formulas given in text
v_integ = quad('Voltage1', x, y); % See the formula in text for computing RMS Voltage
v_rms = sqrt(v_integ/y); % RMS Voltage
i_integ = quad('Current1',x,y); % See the formula in text for computing RMS Current
i_rms = sqrt(i_integ/y); % RMS Current
p_integ = quad('Inst_pr', x, y); % See the formula in text for computing Average Power
p_average = p_integ/y; % Average Power
power_factor = p_average/(i_rms*v_rms); % See the formula in text for computing Power Factor
 
%% Printing the Results
fprintf('Average Power:%f \n',p_average)
fprintf('RMS voltage: %f \n',v_rms)
fprintf('Power Factor %f \n', power_factor)
fprintf('RMS Current %f \n', i_rms)

Function Voltage1.m

function vsq = Voltage1(t)
% we just defined the voltage as mentioned in the text
vsq = (10*cos(120*pi*t + 60*pi/180)).^2;
end

Function Current1.m

function isq = Current1(t)
% % we just defined the voltage as mentioned in the text
isq = (6*cos(120*pi*t + 30.0*pi/180)).^2;
end

Function Inst_pr.m

function pt = Inst_pr(t)
% This function is used to compute instantaneous power as mentioned in the
% text
it = 6*cos(120*pi*t + 30.0*pi/180);
vt = 10*cos(120*pi*t + 60*pi/180);
pt = it.*vt;
end

Results:
Average Power: 25.980762
RMS voltage: 7.071068
Power Factor 0.866025
RMS Current 4.242641

Leave a Comment