[C] 纯文本查看 复制代码
% 定义六种开关状态下的相电压
switch_states = [
0, 0, 1;
0, 1, 0;
0, 1, 1;
1, 0, 0;
1, 0, 1;
1, 1, 0;
];
% 定义基本变量
Vdc = 1; % 直流母线电压
% 空间矢量的角度
angles = linspace(0, 2*pi, 7); % 0 到 360 度,分成6等分
figure;
hold on;
axis equal;
title('SVPWM 空间矢量图');
xlabel('实轴');
ylabel('虚轴');
% 获取当前开关状态的相电压
for i = 1:6
ua = switch_states(i, 1);
ub = switch_states(i, 2);
uc = switch_states(i, 3);
if (((ua + ub + uc) == 0) || (ua + ub + uc) == 3)
ua = 0;
ub = 0;
uc = 0;
elseif ((ua + ub + uc) == 1)
ua = ua * 2/3;
ub = ub * 2/3;
uc = uc * 2/3;
if (ua == 0)
ua = -1/3;
end
if (ub == 0)
ub = -1/3;
end
if (uc == 0)
uc = -1/3;
end
elseif ((ua + ub + uc) == 2)
ua = ua * 1/3;
ub = ub * 1/3;
uc = uc * 1/3;
if (ua == 0)
ua = -2/3;
end
if (ub == 0)
ub = -2/3;
end
if (uc == 0)
uc = -2/3;
end
end
ua = ua * Vdc;
ub = ub * Vdc;
uc = uc * Vdc;
% 计算空间矢量 U_s
U_s = (2/3) * (ua + ub * exp(2*pi/3*1i) + uc * exp(4*pi/3*1i));
% 绘制空间矢量
quiver(0, 0, real(U_s), imag(U_s), 'AutoScale', 'off', 'LineWidth', 2);
% 标注角度
text(real(U_s) * 1.1, imag(U_s) * 1.1, sprintf('(%d,%d,%d)%.0f°',switch_states(i, 1), switch_states(i, 2), switch_states(i, 3), mod(rad2deg(angle(U_s)), 360)), 'FontSize', 12);
end
% 绘制单位圆,表示所有矢量终点应该落在该圆上
theta = linspace(0, 2*pi, 100);
plot(cos(theta), sin(theta), '--k');
hold off;