(1)SPWM的自然采样法
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 现代电力电子与控制技术:SPWM自然采样法
% Author:Juncheng Data:20222/04/13
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
% 参数初始化
f = 50; % 调制波频率(正弦波)
fc = 1050; % 载波频率(三角波)
fs = 50*fc; % 采样频率
ud = 100; % 参考电压值
ratio = 0.9; % 调制比
number = 1; % 计算(绘图)周期个数
N = fs/f * number; % 采样点个数
dt = 1/fs; % 采样间隔
t = (0:N-1) * dt; % 时间序列
xc = ud/2 * sawtooth(2 * pi * fc * t ,0.5); % 载波
Am = ud/2 * ratio;
x = Am * sin(2 * pi* f * t); % 调制波
% 自然采样法
SPWM = zeros(1,length(t)); % 初始化SPWM波序列
for i = 1:length(t)
if x(i) > xc(i)
SPWM(i) = ud/2;
else
SPWM(i) = -ud/2;
end
end
xfft = abs(fft(SPWM,N)) * 2/N; % 对SPWM波进行傅里叶变换
ff = (0:N-1)*fs/N; % 频率序列
% 绘图
figure('color',[1 1 1]); % 白色背景
subplot(311)
plot(t,xc); % 绘制载波
hold on
plot(t,x); % 绘制调制波
hold on
legend('载波','调制波');xlabel('时间/s');ylabel('电压/V');
title('自然采样法载波、调制波波形');
axis([0 number/f -ud*1.2/2 ud*1.2/2]);
subplot(312);
plot(t,SPWM); % 绘制SPWM波
legend('SPWM波');xlabel('时间/s');ylabel('电压/V');
title('自然采样法SPWM波形');
axis([0 number/f -ud*1.2/2 ud*1.2/2]);
hold on
subplot(313);
plot(ff(1:N/2),xfft(1:N/2));
xlabel('频率/Hz');ylabel('振幅');
title('自然规则采样法——频谱图');
axis([0 5*fc 0 ud/2*1.2]); % 显示5倍载波频率范围内的谐波含量
结果:
(2)SPWM的对称规则采样法
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 现代电力电子与控制技术:SPWM对称规则采样法
% Author:Juncheng Data:20222/04/13
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
% 参数初始化
f = 50; % 调制波频率(正弦波)
fc = 1050; % 载波频率(三角波)
fs = 50*fc; % 采样频率
ud = 100; % 参考电压值
ratio = 0.9; % 调制比
number = 1; % 计算(绘图)周期个数
N = fs/f * number; % 采样点个数
dt = 1/fs; % 采样间隔
t = (0:N-1) * dt; % 时间序列
xc = ud/2 * sawtooth(2 * pi * fc * (t+1/(2*fc)) ,0.5); % 载波,移向半个周期
Am = ud/2 * ratio;
x = Am * sin(2 * pi* f * t); % 调制波
% 对称规则采样法
dt = 1/fc; % 调制波采样间隔
Nm = fc/f * number; % 调制波采样个数
tm = (0:Nm-1) * dt; % 调制波时间序列
xm = Am * sin(2 * pi* f * tm); % 调制波采样
stepwave = zeros(1,length(t)); % 初始化阶梯波序列
for i = 1:length(t)
for j = 1:length(tm)-1
if (t(i) >= tm(j)) && (t(i) <= tm(j+1))
stepwave(i) = xm(j); % 生成阶梯波
break;
end
end
end
SPWM = zeros(1,length(t)); % 初始化SPWM波序列
for i = 1:length(t)
if stepwave(i) > xc(i)
SPWM(i) = ud/2;
else
SPWM(i) = -ud/2;
end
end
xfft = abs(fft(SPWM,N)) * 2/N; % 对SPWM波进行傅里叶变换
ff = (0:N-1)*fs/N; % 频率序列
% 绘图
figure('color',[1 1 1]); % 白色背景
subplot(311)
plot(t,xc); % 绘制载波
hold on
plot(t,stepwave); % 绘制阶梯波
hold on
plot(tm,xm,'b:*'); % 绘制调制波
hold on
legend('载波','阶梯波','调制波');xlabel('时间/s');ylabel('电压/V');
title('对称规则采样法载波、调制波波形');
axis([0 number/f -ud*1.2/2 ud*1.2/2]);
subplot(312);
plot(t,SPWM); % 绘制SPWM波
legend('SPWM波');xlabel('时间/s');ylabel('电压/V');
title('对称规则采样法SPWM波形');
axis([0 number/f -ud*1.2/2 ud*1.2/2]);
hold on
subplot(313); % 绘制频谱图
plot(ff(1:N/2),xfft(1:N/2));
title('对称规则采样法——频谱图');
xlabel('频率/Hz');ylabel('振幅');
axis([0 5*fc 0 ud/2*1.2]); % 显示5倍载波频率范围内的谐波含量
结果:
(3)SPWM的不对称规则采样法
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 现代电力电子与控制技术:SPWM不对称规则采样法
% Author:Juncheng Data:20222/04/13
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
% 参数初始化
f = 50; % 调制波频率(正弦波)
fc = 1050; % 载波频率(三角波)
fs = 50*fc; % 采样频率
ud = 100; % 参考电压值
ratio = 0.9; % 调制比
number = 1; % 计算(绘图)周期个数
N = fs/f * number; % 采样点个数
dt = 1/fs; % 采样间隔
t = (0:N-1) * dt; % 时间序列
xc = ud/2 * sawtooth(2 * pi * fc * (t+1/(2*fc)) ,0.5); % 载波,移向半个周期
Am = ud/2 * ratio;
x = Am * sin(2 * pi* f * t); % 调制波
% 不对称规则采样法
dt = 1/(2 * fc); % 调制波采样间隔
Nm = 2 * fc/f * number; % 调制波采样个数
tm = (0:Nm-1) * dt; % 调制波时间序列
xm = Am * sin(2 * pi* f * tm); % 调制波采样
stepwave = zeros(1,length(t)); % 初始化阶梯波序列
for i = 1:length(t)
for j = 1:length(tm)-1
if (t(i) >= tm(j)) && (t(i) <= tm(j+1))
stepwave(i) = xm(j); % 生成阶梯波
break;
end
end
end
SPWM = zeros(1,length(t)); % 初始化SPWM波序列
for i = 1:length(t)
if stepwave(i) > xc(i)
SPWM(i) = ud/2;
else
SPWM(i) = -ud/2;
end
end
xfft = abs(fft(SPWM,N)) * 2/N; % 对SPWM波进行傅里叶变换
ff = (0:N-1)*fs/N; % 频率序列
% 绘图
figure('color',[1 1 1]); % 白色背景
subplot(311)
plot(t,xc); % 绘制载波
hold on
plot(t,stepwave); % 绘制阶梯波
hold on
plot(tm,xm,'b:*'); % 绘制调制波
hold on
legend('载波','阶梯波','调制波');xlabel('时间/s');ylabel('电压/V');
title('不对称规则采样法载波、调制波波形');
axis([0 number/f -ud*1.2/2 ud*1.2/2]);
subplot(312);
plot(t,SPWM); % 绘制SPWM波
legend('SPWM波');xlabel('时间/s');ylabel('电压/V');
title('不对称规则采样法SPWM波形');
axis([0 number/f -ud*1.2/2 ud*1.2/2]);
hold on
subplot(313); % 绘制频谱图
plot(ff(1:N/2),xfft(1:N/2));
title('不对称规则采样法——频谱图');
xlabel('频率/Hz');ylabel('振幅');
axis([0 5*fc 0 ud/2*1.2]); % 显示5倍载波频率范围内的谐波含量
结果: