clear all
clc
ma0= sqrt(3)/2;
ma=ma0;
Vdc=563;
Vsr=ma*Vdc;
f0=50;
if ma<=ma0
fmod=f0*ma/ma0;
else
fmod=f0;
end
no_sample=48;
Ts=(1/fmod)/no_sample;
Vm=2/3*Vsr;
alp=2*pi/3;
ts=0:Ts/100:2/fmod;
Va=Vm*sin(2*pi*fmod*ts);
Vb=Vm*sin(2*pi*fmod*ts-alp);
Vc=Vm*sin(2*pi*fmod*ts-2*alp);
Vtri=Ts*(0.5-2*asin(sin(2*pi*ts/Ts+pi/2))/(2*pi));
L=length(ts);
for i=1:1:L
Vds(i)=(Va(i)+Vb(i)*cos(alp)+ Vc(i)*cos(2*alp) );
Vqs(i)=(Vb(i)*sin(alp)+ Vc(i)*sin(2*alp) );
tht(i)=atan2(Vqs(i),Vds(i));
if tht(i) >= 0
theta(i)=tht(i);
else
theta(i)=2*pi+tht(i);
end
if theta(i)>=0 && theta(i)<alp/2
Sn(i)=1;
elseif theta(i)>=alp/2 && theta(i)<alp
Sn(i)=2;
elseif theta(i)>=alp && theta(i)<3/2*alp
Sn(i)=3;
elseif theta(i)>=3/2*alp && theta(i)<2*alp
Sn(i)=4;
elseif theta(i)>=2*alp && theta(i)<5/2*alp
Sn(i)=5;
else Sn(i)=6;
end
if Sn(i)==1
v1=[1 ;0 ;0];
v2=[1 ;1 ;0];
v0=[1 ;1 ;1];
elseif Sn(i)==2
v1=[1; 1; 0];
v2=[0; 1; 0];
v0=[1; 1; 1];
elseif Sn(i)==3
v1=[0; 1; 0];
v2=[0; 1; 1];
v0=[1; 1; 1];
elseif Sn(i)==4
v1=[0; 1; 1];
v2=[0; 0; 1];
v0=[1; 1; 1];
elseif Sn(i)==5
v1=[0; 0; 1];
v2=[1; 0; 1];
v0=[1; 1; 1];
else
v1=[1; 0; 1];
v2=[1; 0; 0];
v0=[1; 1; 1];
end
u=Sn(i);
An_inv=(Ts/(sin(pi/3)*Vdc))*[sin(u*pi/3) -cos(u*pi/3) ; -sin((u-1)*pi/3) cos((u-1)*pi/3) ];
Vref=[Vds(i); Vqs(i)];
tn=An_inv*Vref;
t0by2=(Ts-tn(1)-tn(2))/2;
t120=[tn(1);tn(2); t0by2];
V120=[v1 v2 v0];
tgx(:,i) = (V120)*(t120);
tga(i)=tgx(1,i);
tgb(i)=tgx(2,i);
tgc(i)=tgx(3,i);
if tgx(1,i)>= Vtri(i)
sA(i)=1;
else
sA(i)=-1;
end
if tgx(2,i)>= Vtri(i)
sB(i)=1;
else
sB(i)=-1;
end
if tgx(3,i)>= Vtri(i)
sC(i)=1;
else
sC(i)=-1;
end
Van(i)=1/3*(2*sA(i)-sB(i)-sC(i))*Vdc/2;
Vbn(i)=1/3*(2*sB(i)-sA(i)-sC(i))*Vdc/2;
Vcn(i)=1/3*(2*sC(i)-sB(i)-sA(i))*Vdc/2;
end
k=0:L-1;
f=k*fmod/4;
Vft=fft(Van);
Vmag=abs(Vft);
m=1:1:L;
h=stem(f(m),Vmag(m)/max(Vmag),'k');
set(get(h,'BaseLine'),'LineStyle','-.')
axis([0 5000 0 1])
set(h,'MarkerFaceColor',[0 0 1],'Marker','.','Color',[0 0 0])
title('harmonics spectrum of phase voltage');
xlabel('frequecy');
ylabel('normalised harmonic voltage');
figure;
plot(ts,Van)
hold on
title('ts vs Van');
xlabel('Time in seconds');
ylabel('Volts');
figure
plot(ts,Sn);
hold on
title('ts vs Sn');
xlabel('Time in seconds');
ylabel('Sector no');
figure
plot(ts,tga,ts,tgb,ts,tgc);
hold on
title('ts vs tga tgb tgc');
xlabel('Time in seconds');
ylabel('tga');
figure
plot(ts,Vtri);
hold on
title('ts vs Vtri');
xlabel('Time in seconds');
ylabel('Vtri');
figure
plot(ts,tga,ts,Vtri);
hold on
title('ts vs tga Vtri');
xlabel('Time in seconds');
ylabel('Volts');
figure
plot(ts,sA);
hold on
title('ts vs SA');
xlabel('Time in seconds');
ylabel('SA');