
Creating a SquareWave

ejkeskinoglu
Dear All,
I want to create a square wave where the step is number of pulses I wanna see, unitless, the pulseinter is the is the tickness of the pulse, it's unit is time, and the delay is the time in between the end and the start of the pulse, again the unit is the time. I wonder if you could help me to understand why my function is not working.
function squarewave(k2400, step, maxamp, minamp, pulseinter, delay, direction) variable k2400, step, maxamp, minamp, pulseinter, delay, direction variable sqwave, deltaamp, t0, elapsedTime, phase variable i // Calculate the amplitude change per step deltaamp = (maxamp - minamp) / step phase = pulseinter+delay // Start the timer and get the initial time t0 = stopMSTimer(-2) do elapsedTime= stopMSTimer(-2)-t0 for(i=0; elapsedTime/i<=step; i=floor((elapsedTime+delay))/phase) for(elapsedTime=delay; elapsedTime+pulseinter-i*phase<=0; sqwave=i*deltaamp) sqwave=sqwave print "elapsedTime:", elapsedTime, "i:", Round((elapsedTime+delay)/phase)-1, "sqwave:", sqwave endfor for(elapsedTime=0; elapsedTime+pulseinter-i*phase>0; sqwave=0) sqwave=sqwave print "elapsedTime:", elapsedTime, "i:", Round((elapsedTime+delay)/phase)-1, "sqwave:", sqwave endfor endfor while(elapsedTime<=phase*step) end
P.S. Don't worry about the variable k2400 and the direction, they are for another use.
Can you elaborate on what you want to achieve and what you expect from the function?
Apparently you want to create a wave, but the function doesn't do that, neither does it return anything that could be assigned to a wave element.
EDIT:
Maybe you can adjust the following to your needs, assuming that I interpreted your question halfway correctly:
August 14, 2024 at 12:35 am - Permalink
Thank you! Problem has been solved and here it is with a couple of personal usage parts:
August 19, 2024 at 05:21 am - Permalink