原创 6点日记20130813

2014-1-25 02:36 764 8 8 分类: 工程师职场 文集: 6点日记

SVPWM

 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Name           : SVGEN
%% Author           : tam
%% Date              : 20130812
%% Description  : SVPWM generator
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;clc;clf;
 
time=1:1:360;
for theta=1:1:360;
    theta_rad=theta/180*pi;
 
    sin_theta=sin(theta_rad);
    cos_theta=cos(theta_rad);
 
    u_alfa=0.1*cos_theta-0.3*sin_theta;
    u_beta=0.1*sin_theta+0.3*cos_theta;
 
    tmp1=u_beta;
    tmp2=0.5*u_beta+sqrt(3)/2*u_alfa;
    tmp3=tmp2-tmp1;
 
    sector=3;
    if(tmp2>0) sector=sector-1;
    end
    if(tmp3>0) sector=sector-1;
    end
    if(tmp1<0) sector=7-sector;
    end
    
    if(sector==1||sector==4)
       Ta= tmp2;
       Tb= tmp1-tmp3;
       Tc=-tmp2;    
    elseif(sector==2||sector==5)                                   
       Ta= tmp3+tmp2;
       Tb= tmp1;
       Tc=-tmp1;
    elseif(sector==3||sector==6)                                                                        
       Ta= tmp3;
       Tb=-tmp3;
       Tc=-(tmp1+tmp2);
    end
 
    y_u_alfa(theta,1)=u_alfa;
    y_u_beta(theta,1)=u_beta;
    y_tmp1(theta,1)=tmp1;
    y_tmp2(theta,1)=tmp2;
    y_tmp3(theta,1)=tmp3;
    y_sector(theta,1)=sector;
    y_Ta(theta,1)=Ta;
    y_Tb(theta,1)=Tb;
    y_Tc(theta,1)=Tc;
end
 
figure(1);
subplot(221);
plot(time,y_u_alfa,'r',time,y_u_beta,'b');
xlabel('Ualfa,Ubeta');
subplot(222);
plot(time,y_tmp1,'r',time,y_tmp2,'b',time,y_tmp3,'g');
xlabel('tmp1,tmp2,tmp3');
subplot(223);
plot(time,y_sector);
xlabel('sector');
subplot(224);
plot(time,y_Ta,'r',time,y_Tb,'b',time,y_Tc,'g');
xlabel('Ta,Tb,Tc');
 
figure(2);
set(gcf,'Color','w');
line([-0.25,1.25],[0,0],'Color','k');
line([0.5,0.5],[-1,-0.5],'Color','k');
line([0,0],[-1,0.5],'Color','k');
line([1,1],[-1,0.5],'Color','k');
line([-0.25,0],[0,0.5]);
line([0,0.5],[0.5,-0.5]);
line([0.5,1],[-0.5,0.5]);
line([1,1.25],[0.5,0]);
 
line([-0.25,1.25],[y_Ta(1,1),y_Ta(1,1)],'Color','r');
line([-0.25,1.25],[y_Tb(1,1),y_Tb(1,1)],'Color','r');
line([-0.25,1.25],[y_Tc(1,1),y_Tc(1,1)],'Color','r');
 
line([-0.25,1.25],[-1,-1],'Color','k');
 
line([0.1,0.1],[0.3017,-1],'Color','g');
line([0.17,0.17],[0.1641,-1],'Color','g');
line([0.4,0.4],[-0.3017,-1],'Color','g');
line([0.6,0.6],[-0.3017,-1],'Color','g');
line([0.83,0.83],[0.1641,-1],'Color','g');
line([0.9,0.9],[0.3017,-1],'Color','g');
 
%PWM1
line([0,0.17],[-0.7,-0.7],'Color','m');
line([0.17,0.83],[-0.65,-0.65],'Color','m');
line([0.83,1],[-0.7,-0.7],'Color','m');
line([0.17,0.17],[-0.7,-0.65],'Color','m');
line([0.83,0.83],[-0.7,-0.65],'Color','m');
 
%PWM2
line([0,0.1],[-0.8,-0.8],'Color','m');
line([0.1,0.9],[-0.75,-0.75],'Color','m');
line([0.9,1],[-0.8,-0.8],'Color','m');
line([0.1,0.1],[-0.8,-0.75],'Color','m');
line([0.9,0.9],[-0.8,-0.75],'Color','m');
 
%PWM3
line([0,0.4],[-0.9,-0.9],'Color','m');
line([0.4,0.6],[-0.85,-0.85],'Color','m');
line([0.6,1],[-0.9,-0.9],'Color','m');
line([0.4,0.4],[-0.9,-0.85],'Color','m');
line([0.6,0.6],[-0.9,-0.85],'Color','m');
 
text(-0.05,0.1841,'Ta');
text(-0.05,0.3217,'Tb');
text(-0.05,-0.2817,'Tc');
 
text(-0.1,-0.7,'PWM1');
text(-0.1,-0.8,'PWM2');
text(-0.1,-0.9,'PWM3');
 
line([0.17,0.19],[-0.7,-0.7],'Color','c');
line([0.19,0.19],[-0.7,-0.65],'Color','c');
line([0.83,0.85],[-0.65,-0.65],'Color','c');
line([0.85,0.85],[-0.7,-0.65],'Color','c');
 
line([0.1,0.12],[-0.8,-0.8],'Color','c');
line([0.12,0.12],[-0.8,-0.75],'Color','c');
line([0.9,0.92],[-0.75,-0.75],'Color','c');
line([0.92,0.92],[-0.8,-0.75],'Color','c');
 
line([0.4,0.42],[-0.9,-0.9],'Color','c');
line([0.42,0.42],[-0.9,-0.85],'Color','c');
line([0.6,0.62],[-0.85,-0.85],'Color','c');
line([0.62,0.62],[-0.9,-0.85],'Color','c');
 
%%%%%%%%%%%%% The end of the program %%%%%%%%%%%
svpwm1.jpg
 
  svpwm2.jpg
       这是TI用于产生SVPWM的程序,为了理解我将其翻译成了Matlab程序。之前尝试过一次,没能成功,昨晚竟然自然而然地又走到了这个程序。终于成功。发现之前失败的原因是Matlab程序里面的一个数据在360个循环里面只记录了一个数据,我将其改成数组,每次循环都存一次运算结果,最后就成功地得到360个数据。可以正常显示了。
 
tam

文章评论0条评论)

登录后参与讨论
我要评论
0
8
关闭 站长推荐上一条 /2 下一条