error in space vector modulation function .

조회 수: 2 (최근 30일)
Mohit kumar
Mohit kumar 2021년 3월 28일
댓글: Mohit kumar 2021년 4월 4일
I have written a code in matlab function block to generate switching pulses for three phase VSI ,but i am getting an error ,please suggest something valuable. Thanks in advance.
code:
%Inputs are magnitude u1(:),angle u2(:)
%ramp signal for comparison u3(:)
function [sa,sb,sc]=AAA(u)
ts=0.0002; Vdc=1; peak_peak_max=Vdc/sqrt(3);
x=u(1);y=u(2); mag=(u/peak_peak_max)*ts;
% sector 1
if (x >=0) && (x < (pi/6))
ta=mag*sin(pi/3 - x); tb=mag*sin(x);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1=cumsum(t1);
v1=[ 1, 1, 1,1,1,1]; v2=[1,1,0,0,1,1]; v3=[1,0,0,0,0,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 1.1
elseif(x >=pi/6) && (x < (pi/3))
adv=x-pi/6;
ta=mag*sin(pi/3 - adv); tb=mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1=cumsum(t1);
v1=[ 0, 1, 1,1,1,0]; v2=[0,0,1,1,0,0]; v3=[0,0,0,0,0,0];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
%sector 2
elseif (x >=pi/3) && (x < (pi/2))
adv = x-pi/3;
ta=mag*sin(pi/3 - adv); tb=mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1=cumsum(t1);
v1=[ 0, 0, 1,1,0,0]; v2=[0,1,1,1,0,0]; v3=[0,0,0,0,0,0];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 2.1
elseif (x >=pi/2) && (x < (2*pi/3))
adv=x-pi/2;
ta=mag*sin(pi/3 - adv); tb=mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[ 1, 1, 0,0,1,1]; v2 =[1,1,1,1,1,1]; v3 = [1,0,0,0,0,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 3
elseif (x >=2*pi/3) && (x < (5*pi/6))
adv = x-2*pi/3;
ta= mag*sin(pi/3 - adv); tb= mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[ 1,0,0,0,0,1]; v2 =[1,1,1,1,1,1]; v3 = [1,1,0,0,1,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 3.1
elseif (x >=5*pi/6) && (x < pi )
adv = x- 5*pi/6;
ta= mag*sin(pi/3 - adv); tb= mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[0,0,0,0,0,0]; v2 =[0,1,1,1,1,0]; v3 = [0,0,1,1,0,0];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 4
elseif (x >=pi) && (x < 7*pi/6 )
adv = x- pi;
ta= mag*sin(pi/3 - adv); tb= mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[1,0,0,0,0,1]; v2 =[1,1,0,0,1,1]; v3 = [1,1,1,1,1,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 4.1
elseif (x >=7*pi/6) && (x < 4*pi/3 )
adv = x- 7*pi/6;
ta= mag*sin(pi/3 - adv); tb= mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[1,0,0,0,0,1]; v2 =[1,1,0,0,1,1]; v3 = [1,1,1,1,1,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
% sector 5
elseif (x >=4*pi/3) && (x < 3*pi/2 )
adv = x- 4*pi/3;
ta= mag*sin(pi/3 - adv); tb= mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[0,0,0,1,1,0]; v2 =[0,0,0,0,0,0]; v3 = [0,1,1,1,1,0];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
%sector 5.1
elseif (x >=3*pi/2) && (x < 5*pi/3 )
adv = x- 3*pi/2;
ta= mag*sin(pi/3 - adv); tb= mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[1,1,0,0,1,1]; v2 =[1,0,0,0,0,1]; v3 = [1,1,1,1,1,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb=v2(j); sc=v3(j);
%sector 6
elseif (x >=5*pi/3) && (x < 11*pi/6 )
adv = x- 5*pi/3;
ta= mag*sin(pi/3 - adv); tb= mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[0,1,1,1,1,0]; v2 =[0,0,0,0,0,0]; v3 = [0,0,1,1,0,0];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb= v2(j); sc= v3(j);
%sector 6.1
elseif (x >=11*pi/6) && (x < 2*pi )
adv = x- 11*pi/6;
ta= mag*sin(pi/3 - adv); tb= mag*sin(adv);
to=(ts-ta-tb);
t1=[ to/2,ta/2, tb/2, tb/2, ta/2, to/2];
t1= cumsum(t1);
v1=[1,1,1,1,1,1]; v2 =[1,0,0,0,0,1]; v3 = [1,1,0,0,1,1];
for j= 1:6
if (y < t1(j))
break
end
end
sa=v1(j);sb= v2(j); sc= v3(j);
end
Error i am getting: not able to relate like what it is talking about.

답변 (1개)

Chidvi Modala
Chidvi Modala 2021년 3월 31일
Reason : Your 'x' might fall out of the ranges you've specified. Hence the error 'Output argument sa is not assigned on some execution paths'
Workaround : You may try assigning an initial value for sa or you can replace the last elseif with else, whichever suits your case.
  댓글 수: 1
Mohit kumar
Mohit kumar 2021년 4월 4일
okay sir, I will try it out. Thank you for your precious advice.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

태그

제품


릴리스

R12.1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by