You are on page 1of 3

8/4/15 2:29 PM

C:\Users\Indul...\PMU_for_PublicUse_setup.m

1 of 3

clear all;
close all;
fprintf
(1,'=====================================================================================
=====\n');
fprintf(1,'====
====\n');
fprintf(1,'====
Setup TickTock PMU Demonstrations
====\n');
fprintf(1,'====
====\n');
fprintf
(1,'=====================================================================================
=====\n');
FloatToInt32CastingMethod_Round = 0
% Overall scenario and sampling configuration, common for P and M class
SampleFreq = 10000
TsSampling = 1/SampleFreq;
f0_SigGen = 50
f0_PMU = 50
Fs_PMU = f0_PMU
%% Calibration factors for hardware and anti-alias filter
%
%
%
%
%
%
%
%
%
%
%
%
%

The calibrations are given in the form of 2nd-order polynomial coefficients.


Inside the PMU, the measured (linear) amplitude is multiplied by:
GainCoeff(1)*f^2+GainCoeff(2)*f+GainCoeff(3)
where f is in Hz.
So the GainCoeffs should represent the linear attenuation of any hardware
such as VTs, anti-alias filters, etc.
Inside the PMU, the measured phase (in radians) is advanced by:
PhaseCoeff(1)*f^2+PhaseCoeff(2)*f+PhaseCoeff(3)
where f is in Hz.
So the PhaseCoeffs should represent the phase lags of any hardware
such as VTs, anti-alias filters, etc.

% In this simple example simulation, I have stripped out the anti-alias


% filters and there are no modelled effects of hardware
% or finite ADC sampling time/delay (the ADC is assumed to be "instant").
% Therefore:
HardwareAndAntiAlias_GainCorrectCoeffs = [0 0 1.0]; %(The measured amplitude is always
multiplied by 1.0 at any f)
HardwareAndAntiAlias_PhaseCorrectCoeffs = [0 0 0];
%(The measured phase is left
unaltered at any f)

8/4/15 2:29 PM

C:\Users\Indul...\PMU_for_PublicUse_setup.m

%
%
%
%

However, if you want to insert anti-alias filters or sensors with


bandwith-related effects into the simulation, you can do so using code
like that shown below. The effects of the different components can be
carefully combined into single 3-element vectors for amplitude and phase.

%
%
%
%
%
%
%
%
%

If using Simulink to simulate anti-alias filters, be very careful since


it is very easy to accidentally create phase lags due to discrete
low-pass filter models which do not match those you expect from theory.
If you do this, you will also need to simulate the analogue signals and
low-pass filters using a much smaller timestep (or continuous timestep)
than the PMU sampling timestep. When you do this, you will need to
introduce rate transitions to simulate the effects of the ADC.
Be careful to configure the rate transition blocks correctly, or you can
end up with extra sampling delays which you didn't expect.

2 of 3

CalFreqs = [40 ; 55 ; 70]; % Frequencies for calibrations of hardware, anti-alias filters


Hardware_gain_response_linear = [ 1.0 ; 1.0 ; 1.0 ];
% Linear gains of measurement
hardware at cal freqs (Measurement will be corrected by attenuating by these amounts)
Hardware_phase_response_degrees = [ 0.0 ; 0.0 ; 0.0 ]; % Phases of measurement hardware
at cal freqs (Measurement will be corrected by lagging by these amounts)
% In the standard, the P class device does not have an anti-alias filter.
% Here I have allowed for the same (filtered) path into shared P and M-class PMUs
% since the LPF CAN be used if sample rate is high and it adds very little latency.
AntiAlias_Fc = 1e9; % max([SampleFreq/4,Fnom*5]);
% Do not allow filters with low cutoffs at low sampling rates, since these
% introduce too much latency
SamplingDelay = (0.0e-6)/2; % The time delay between the sampling "instant" and the UTC
timeclock
% This might need to be phase by phase for multiplexed ADCs
% Here I assume that 3 parallel ADC channels are used with synchronised
% sampling, and that the sampled value is averaged over 0.0us IMMEDIATELY
% prior to the start of the frame (where the UTC timeclock value is
% synchonised to). Note. This delay is not easy to simulate acurately with
% simple delays, so, I have kept this value to zero just now.
Hardware_GainCorrectCoeffs = polyfit(CalFreqs,1./Hardware_gain_response_linear,2)
Hardware_PhaseCorrectCoeffs = polyfit(CalFreqs,-Hardware_phase_response_degrees*pi/180,2)
% The cal for a simple 1st-order LPF.
% Adjust for more complex filters as appropriate
s = 2*pi*j*CalFreqs;
AntiAlias_Response = 1./(1+s/(2*pi*AntiAlias_Fc));
AntiAliasMag=abs(AntiAlias_Response)
AntiAliasPhase=angle(AntiAlias_Response);
AntiAliasPhaseDeg = AntiAliasPhase*180/pi

8/4/15 2:29 PM

C:\Users\Indul...\PMU_for_PublicUse_setup.m

3 of 3

AntiAlias_GainCorrectCoeffs = polyfit(CalFreqs,1./AntiAliasMag,2);
AntiAlias_PhaseCorrectCoeffs = polyfit(CalFreqs,-AntiAliasPhase,2);
% HardwareAndAntiAlias_GainCorrectCoeffs = MFAJR_MultiplicativeCalCompCombine
(Hardware_GainCorrectCoeffs,AntiAlias_GainCorrectCoeffs,CalFreqs)
% HardwareAndAntiAlias_PhaseCorrectCoeffs = MFAJR_AdditiveCalCompCombine
(Hardware_PhaseCorrectCoeffs,AntiAlias_PhaseCorrectCoeffs,CalFreqs)
HardwareAndAntiAlias_GainCorrectCoeffs = MFAJR_MultiplicativeCalCompCombineNoSymToolbox
(Hardware_GainCorrectCoeffs,AntiAlias_GainCorrectCoeffs,CalFreqs)
HardwareAndAntiAlias_PhaseCorrectCoeffs = MFAJR_AdditiveCalCompCombineNoSymToolbox
(Hardware_PhaseCorrectCoeffs,AntiAlias_PhaseCorrectCoeffs,CalFreqs)
% Add phase delay due to sample "instant" relative to UTC time (start of frame)
% This is a linear phase slope against frequency
SamplingDelayPhasePerHz = 2*pi*SamplingDelay;
% Add this to proportional element of cal
HardwareAndAntiAlias_PhaseCorrectCoeffs(2) = HardwareAndAntiAlias_PhaseCorrectCoeffs(2)
+SamplingDelayPhasePerHz

%% Scenario
InitialSettlingTime = 5
ScenarioLength = 30
FastForwardScenario = 0 % Start scenario at this time instead
ScenarioLength = ScenarioLength - FastForwardScenario;
InitialSettlingTime = InitialSettlingTime - FastForwardScenario;
SimulationLength = InitialSettlingTime + ScenarioLength;

You might also like