主要内容

矩形脉冲波形的占空比

此示例说明如何创建矩形脉冲波形并测量其占空比。您可以将矩形脉冲波形想象成一系列的开启关闭状态。一个脉冲周期是一个开启关闭状态的总持续时间。脉冲宽度是开启状态的持续时间。占空比是脉冲宽度与脉冲周期的比率。矩形脉冲的占空比描述脉冲处于开启状态的时间占一个脉冲周期的比率。

创建一个以 1 千兆赫采样的矩形脉冲。脉冲处于开启状态(即等于 1),持续时间为 1 微秒。如果脉冲处于关闭状态(即等于 0),持续时间为 3 微秒。脉冲周期为 4 微秒。绘制波形。

Fs = 1e9;
t = 0:1/Fs:(10*4e-6);

pulsewidth = 1e-6;
pulseperiods = [0:10]*4e-6;

x = pulstran(t,pulseperiods,@rectpuls,pulsewidth);

plot(t,x)
axis([0 4e-5 -0.5 1.5])

Figure contains an axes object. The axes object contains an object of type line.

使用 dutycycle 确定波形的占空比。输入脉冲波形和采样率以输出占空比。dutycycle 为每个检测到的脉冲输出占空比值。

D = dutycycle(x,Fs)
D = 1×9

    0.2500    0.2500    0.2500    0.2500    0.2500    0.2500    0.2500    0.2500    0.2500

在此示例中,每个检测到的脉冲的占空比是相同的,都等于 0.25。这是预期的占空比,因为脉冲在每 4 微秒的周期内开启 1 微秒,关闭 3 微秒。因此,脉冲在每个周期的 1/4 内处于开启状态。以百分比表示,这等于 25% 的占空比。

不带输出参量调用 dutycycle 会生成标记了所有检测到的脉冲宽度的绘图。

dutycycle(x,Fs);

Figure Duty Cycle Plot contains an axes object. The axes object with xlabel Time (seconds), ylabel Level (Volts) contains 9 objects of type line. One or more of the lines displays its values using only markers These objects represent signal, mid cross, upper boundary, upper state, lower boundary, mid reference, lower state.

使用相同的采样率和脉冲周期,以循环方式将脉冲开启时间(脉冲宽度)从 1 微秒更改到 3 微秒,并计算占空比。绘制循环中每步的脉冲波形,并在绘图标题中显示占空比值。占空比随着脉冲宽度的增加从 0.25 (1/4) 增加到 0.75 (3/4)。

nwid = 3;

for nn = 1:nwid
    x = pulstran(t,pulseperiods,@rectpuls,nn*pulsewidth);
    
    subplot(nwid,1,nn)
    plot(t,x)
    axis([0 4e-5 -0.5 1.5])
    
    D = dutycycle(x,Fs);
    title(['Duty cycle is ' num2str(mean(D))])
end

Figure Duty Cycle Plot contains 3 axes objects. Axes object 1 with title Duty cycle is 0.25 contains an object of type line. Axes object 2 with title Duty cycle is 0.5 contains an object of type line. Axes object 3 with title Duty cycle is 0.75 contains an object of type line.

另请参阅

|