简体   繁体   中英

Repeated Step functions

I am trying to create a signal in matlab that will be a step function that is initially off then switches on and then off. But, I need to repeat this signal for rest of my interval and would require to repeat this step function thirty or so times.

Instead of writing heaviside for each time it switches on and off. I tried to put the hevistep function inside a for loop, but had little success. I don't think the heaviestep function is designed for a for loop, what are some better methods of creating this signal.

y = 0
    for a = 1:2:10
        x = heaviside(t-a) - heaviside(t-(a+1));
        y = y + x
    end

To get a heavyside function you can do something like this, where t is your independent variable, period is your period, duty is your duty cycle (fraction of cycle you want high) and shift is to shift.

heavy =@(t, period, duty, shift) double( mod( t - shift , period ) < duty * period )

Then you can do something like

t = linspace(0,10,1E4);
plot(t , heavy( t , pi , 0.25 , pi/3 ) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM