如何在Matlab中改变矩形脉冲脉冲序列的幅度

How to change the amplitude of pulsetrain of rectangular pulses in Matlab

我正在绘制矩形脉冲的脉冲串。

pulse_periods = [0:128]*period; %128 pps 
%works for Ampl. default  = 1, 
r1 = pulstran(t,pulse_periods,'rectpuls', w); 

这给出了矩形脉冲的默认振幅 1。

我需要改成0.5

我试过了

    pulse_periods = [[0:128]*period;0.5 * [0:128]]' %128 pps 
    %does not work for Ampl. = 0.5, 
    r1 = pulstran(t,pulse_periods,'rectpuls', w); 

这是对Matlab中给出的周期性高斯脉冲示例的修改 https://www.mathworks.com/help/signal/ref/pulstran.html?searchHighlight=pulstran

我无法更改所需矩形脉冲的幅度。

我做错了什么?

pulse_periods的第二列应该是每个脉冲的幅度。在文档中的示例中,他们希望改变脉冲幅度。如果您希望脉冲幅度保持在恒定的 0.5,那么您应该这样做:

pulse_periods = [(0:128)*period; 0.5 * ones(1,129)]';

作为最小工作示例的一部分:

period = 1/128;
pulse_periods = [(0:128)*period; 0.5 * ones(1,129)]';
w = period * 0.5;
t = linspace(0, 1, 2e3)';
r1 = pulstran(t,pulse_periods,'rectpuls', w);
plot(t,r1);

请注意,您也可以简单地缩放 "default amplitude of 1" 案例的输出(即 r1 = r1 * 0.5);