0

I am plotting a pulsetrain of rectangular pulses.

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

This gives a default amplitude of 1 for the rectangular pulses.

I need to change it to 0.5

I tried

    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); 

This is a modification of the periodic gaussian pulse example given in Matlab https://www.mathworks.com/help/signal/ref/pulstran.html?searchHighlight=pulstran

I am unable to change the amplitude for the required rectangular pulses .

What is the mistake I am doing ?

AAI
  • 290
  • 1
  • 3
  • 20

1 Answers1

0

The second column of pulse_periods should be the amplitude of each pulse. In the example from the documentation, they wanted the pulse amplitude to change. If you want the pulse amplitude to stay at a constant 0.5, then you should do instead:

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

As part of a minimum working example:

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);

Note that you could have also simply scaled the output from your "default amplitude of 1" case (i.e. r1 = r1 * 0.5);

KQS
  • 1,547
  • 10
  • 21