You are on page 1of 2

sampling_interval = 20;

step_size = 0.001;
V_mag = 3;
f1 = 50;
f2 = 10;

index = 1;
zc_flag = 0;
phase_err = zeros(1,sampling_interval*(1/step_size)+1);
phase_out = 0;
phase_ref = 0;
P = 1;
I = 5;
w_out = 0;
w_ref = 0;
E_f = zeros(1,sampling_interval*(1/step_size)+1);
%E_f = beklenen frekans
t = 0:step_size:sampling_interval;

Vref = V_mag*sin(2*pi*f1*t);
Vout = V_mag*sin(2*pi*f2*t);

for i = 0:step_size:(sampling_interval-step_size)

phase_ref = phase_ref + w_ref*step_size;


phase_out = phase_out + w_out*step_size;
phase_err(index) = phase_ref - phase_out;

if((phase_ref > 100)&&(phase_out > 100)) %overflow olmasin diye burasi


phase_ref = phase_ref - 100;
phase_out = phase_out - 100;
end

Iphase_err = sum(phase_err(1:index))/index;
f2 = I*Iphase_err; %PI kontrolcu
if f2 < 10
f2 = 10;
end

Vout(index:(sampling_interval/step_size)) = V_mag*sin(2*pi*f2*t(index:
(sampling_interval/step_size)));
%kalan hepsini yapmasina gerek yok sanirsam da
% simdilik kalsın o kadar yavas degil

if(index ~= 1)
w_ref = abs(asin(Vref(index)/V_mag) - asin(Vref(index-
1)/V_mag))*(1/step_size);
w_out = abs(asin(Vout(index)/V_mag) - asin(Vout(index-
1)/V_mag))*(1/step_size);
Tout = 2*pi/(w_out);
E_f(index) = 1/Tout;
end
index = index + 1;
end
bbss = 1/step_size; %bbss bir_bolu_step_size
aralik = 14;

hold
plot(t(bbss*aralik:bbss*(aralik+0.1)),Vref(bbss*aralik:bbss*(aralik+0.1)))
plot(t(bbss*aralik:bbss*(aralik+0.1)),Vout(bbss*aralik:bbss*(aralik+0.1)))

%plot(t,E_f) %bunu commente alip digerlerine bak yoksa olmuyor nedense xd

You might also like