Skip to content

Commit

Permalink
Frequency test example
Browse files Browse the repository at this point in the history
  • Loading branch information
PIRES, ADRIANO OLIVEIRA (Adriano) committed Jan 12, 2018
1 parent f2946d2 commit b6de677
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 16 deletions.
30 changes: 16 additions & 14 deletions c37118.1/convert_to_struct.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
%
% Performed the data received to PMU struct for tests.
%
% Usage: phasors = convert_to_struct(struct_received)
%
% struct_received = list of the frames received of the PMU about test;
%
% Return
% phase: struct of the PMU to tests.
% phasors: struct of the PMU to tests.
%
% Heverton de Lemos 13/10/2017
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function phase = convert_to_struct(struct_received)
function phasors = convert_to_struct(struct_received)

VS1 = VC = VB = VA = [];
IS1 = IC = IB = IA = [];

for i=1:length(struct_received)
pmu = getfield(struct_received{i}.pmu, '1');
pmu = getfield(struct_received(i).pmu, '1');

VA(1,i) = pmu.phasors{1}(1);
VA(2,i) = pmu.phasors{1}(2);
Expand All @@ -39,17 +41,17 @@
rocof(i) = pmu.dfreq;
endfor

phase = struct();
phase.("VA") = VA;
phase.("VB") = VB;
phase.("VC") = VC;
% phase.("VS1") = VS1;
% phase.("IA") = IA;
% phase.("IB") = IB;
% phase.("IC") = IC;
% phase.("IS1") = IS1;
phase.("frequency") = freq;
phase.("rocof") = rocof;
phasors = struct();
phasors.("VA") = VA;
phasors.("VB") = VB;
phasors.("VC") = VC;
% phasors.("VS1") = VS1;
% phasors.("IA") = IA;
% phasors.("IB") = IB;
% phasors.("IC") = IC;
% phasors.("IS1") = IS1;
phasors.("frequency") = freq;
phasors.("rocof") = rocof;

return;
endfunction
50 changes: 50 additions & 0 deletions c37118.1/steady_state/pmu_reference_1ph_freq_delta_freq.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Generate 1ph PMU reference to frequency test steady state.
%
% Usage:
%
% magnitude = Reference phasor magnitude;
% initial_frequency = Initial frequency in the test (Hz);
% delta_frequency = The increase/decrease of frequency in Hz for each step;
% number_of_steps = The total amount of frequency steps;
% time_per_step = The time, in seconds, per step;
% frames_per_second = Reference Fps (frames per second);
% initial_angle = Refenrece initial angle;
%
% Return
% phasor: Struct of the PMU reference to frequency steady state.
%
% Heverton de Lemos 24/10/2017
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function phasor = pmu_reference_1ph_freq_delta_freq(magnitude,
initial_frequency,
delta_frequency,
number_of_steps,
time_per_step,
frames_per_second,
initial_angle)
Va = [];
freq = [];
rocof = [];
% implement check of all input values;
lenght_frame_step = ceil(frames_per_second * time_per_step);
for i=1:number_of_steps
instantaneous_frequency = initial_frequency + (i - 1) * delta_frequency;
tmp_Va = ss_generic(magnitude,
initial_angle,
instantaneous_frequency,
frames_per_second,
lenght_frame_step);

Va = [Va tmp_Va];
freq = [freq ones(1, lenght_frame_step) * instantaneous_frequency];
rocof = [rocof zeros(1, lenght_frame_step)];
endfor

phasor = struct();
phasor.("VA") = Va;
phasor.("frequency") = freq;
phasor.("rocof") = rocof;
return;
endfunction
77 changes: 77 additions & 0 deletions examples/generate_reference.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
clc
clear all

source("../start_lib.m");

start_lib("../");

voltage_magnitude = 115;
current_magnitude = 5;
Initial_frequency = 45;
delta_frequency = 1;
time_per_step = 2; % two seconds
number_of_steps = 11;
initial_angle = 0;
frames_per_second = 50;
time = linspace(0, number_of_steps * time_per_step,
frames_per_second * number_of_steps * time_per_step);
phasor = struct();
tmp_phasor = pmu_reference_1ph_freq_delta_freq(voltage_magnitude,
Initial_frequency,
delta_frequency,
number_of_steps,
time_per_step,
frames_per_second,
initial_angle);
phasor.VA = tmp_phasor.VA;
phasor.frequency = tmp_phasor.frequency;
phasor.rocof = tmp_phasor.rocof;
tmp_phasor = pmu_reference_1ph_freq_delta_freq(voltage_magnitude,
Initial_frequency,
delta_frequency,
number_of_steps,
time_per_step,
frames_per_second,
initial_angle + 120);
phasor.VB = tmp_phasor.VA;
tmp_phasor = pmu_reference_1ph_freq_delta_freq(voltage_magnitude,
Initial_frequency,
delta_frequency,
number_of_steps,
time_per_step,
frames_per_second,
initial_angle - 120);

phasor.VC = tmp_phasor.VA;
tmp_phasor = pmu_reference_1ph_freq_delta_freq(current_magnitude,
Initial_frequency,
delta_frequency,
number_of_steps,
time_per_step,
frames_per_second,
initial_angle);
phasor.IA = tmp_phasor.VA;
tmp_phasor = pmu_reference_1ph_freq_delta_freq(current_magnitude,
Initial_frequency,
delta_frequency,
number_of_steps,
time_per_step,
frames_per_second,
initial_angle + 120);
phasor.IB = tmp_phasor.VA;
tmp_phasor = pmu_reference_1ph_freq_delta_freq(current_magnitude,
Initial_frequency,
delta_frequency,
number_of_steps,
time_per_step,
frames_per_second,
initial_angle - 120);
phasor.IC = tmp_phasor.VA;

plot(time, phasor.VA(1,:));
figure();
plot(time, phasor.VA(2,:));
figure();
plot(time, phasor.frequency);
figure();
plot(time, phasor.rocof);
19 changes: 17 additions & 2 deletions examples/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
printf("Press 's' to stop befeore the test starts...\n");
fflush (stdout);
nominal_voltage = 115; % Voltage in V
nominal_current = 5; % CUrrent in A

while (1)
if (kbhit (1) == 's')
Expand Down Expand Up @@ -71,6 +72,20 @@
endwhile

printf("All the data was acquired, please wait the results...\n");
fflush (stdout);

fflush(stdout);
initial_frequency = 40; % Hz
delta_frequency = 2; % Hz
time_per_step = 2; % s
number_of_steps = ((initial_frequency - 60) / delta_frequency) + 1;
frames_per_second = 200;
reference_phasors = struct();
tmp_phasor = pmu_reference_1ph_freq_delta_freq(nominal_voltage,
initial_frequency,
delta_frequency,
number_of_steps,
time_per_step,
frames_per_second,
0);
reference_phasors = tmp_phasor;
measured_phasors = convert_to_struct(test_data);
disconnect_socket(sock);

0 comments on commit b6de677

Please sign in to comment.