问题是:使用Matlab计算周期为1 ms的矩形脉冲波形的RMS电压。该波应具有0 V的最小峰值和4 V的最大峰值。计算“ ON”时间占空比的RMS电压为20%,50%和80%。还要计算一个相同电压电平的三角波的RMS电压(从0到4伏到周期结束时回到0伏)。
我有代码来计算所有这四个波的RMS电压,但是我需要绘制三个方波的图,我不确定该怎么做。
我知道square
函数和dutycycle
函数,但是我不知道如何实现它们,以便有一个特定的幅度(在这种情况下,为0到4) 。任何帮助将不胜感激。
% Calculation of RMS value for 20 percent
v_sum = 0.0; % Initial sum is set to zero
% for loop for one cycle
for k = 0.0:1.0:99.0
if k < 20
v = 4; % On period
else
v = 0; % Off period
end
v_sum = v_sum + v.^2; % Sum and Square are implemented
end
% Rms value calculation
v_rms_20 = sqrt(v_sum/100); % Root and Mean implementation
% Display the value
disp(v_rms_20)
%-----------------------------------------
% Calculation of RMS value for 50 percent
% Initial sum is set to zero
v_sum = 0.0;
% for loop for one cycle
for k = 0.0:1.0:99.0
if k < 50
v = 4; % On period
else
v = 0; % Off period
end
v_sum = v_sum + v.^2; % Sum and Square are implemented
end
% Rms value calculation
v_rms_50 = sqrt(v_sum/100); % Root and Mean implementation
% Display the value
disp(v_rms_50)
%-----------------------------------------
% Calculation of RMS value for 80 percent
v_sum = 0.0; % Initial sum is set to zero
% for loop for one cycle
for k = 0.0:1.0:99.0
if k < 80
v = 4; % On period
else
v = 0; % Off period
end
v_sum = v_sum + v.^2; % Sum and Square are implemented
end
% Rms value calculation
v_rms_80 = sqrt(v_sum/100); % Root and Mean implementation
% Display the value
disp(v_rms_80)
%-----------------------------------------
% Calculation of RMS value for triangular wave
v_sum = 0.0; % Initial sum is set to zero
% for loop for one cycle
for k = 0.0:1.0:99.0
if k < 50
v = 4*(k)/50; % Up trend period
else
v = 4*(100-k)/50; % Down trend period
end
v_sum = v_sum + v.^2; % Sum and Square are implemented
end
% Rms value calculation
v_rms_triangle = sqrt(v_sum/100); % Root and Mean implementation
% Display the value
disp(v_rms_triangle)
答案 0 :(得分:0)
您可以设置幅度和电压范围,并根据幅度偏移和缩放square的结果。
square
函数返回值[-1,1]。
示例(基于square的MATLAB示例):
t = 0:1/1e4:5; %Time (X axis).
cyc = 20; %Duty cycle
amp = 4; %Amplitude
cyc20_amp4 = (square(2*pi*t, cyc)+1)*amp/2; %Voltage (Y axis)
%Plot a graph
figure;plot(t, cyc20_amp4);title(['dutycycle=', num2str(cyc), ' amplitude=', num2str(amp)]);
xlabel('t');ylabel('V')