Page 1 of 1

Waveform formulae for signalscope

Posted: 14 Jan 2012 21:30
by dc_Sux
This is a purely cosmetic thing, but I was hoping to program different signalscopes to display sine, sawtooth, reverse sawtooth, triangle and square waves, depending on what was selected for my oscillators/LFOs etc.

Trigonometry isn't exactly my strong point. I can get it to display a scrolling sine wave using the formula:

x=time%1
y=0.5+sin(time)*0.5
timebase=10

Anyone got any clue how I can get it to display these other waveforms?

I'd also like to be able to change the frequency depending on the individual tuning of the oscillators.

Any help on how to do this would be greatly appreciated.

Re: Waveform formulae for signalscope

Posted: 15 Jan 2012 04:28
by Phil999
square wave: round(0.5+sin(time)*0,5)
sawtooth wave: time-floor(time)

but you don't see the vertical lines.


http://en.wikipedia.org/wiki/Sawtooth_wave
http://en.wikipedia.org/wiki/Square_wave

Re: Waveform formulae for signalscope

Posted: 16 Jan 2012 03:03
by analog604
Trig is a struggle point for me, but I can read code.
So I adapted some cpp code to get a triangle waveform:
asin(sin(time%1*3.14159+(time%1/10000)))/1.568
anyone have a better way to get a Tri?

dc_Sux wrote:This is a purely cosmetic thing, but I was hoping to program different signalscopes to display sine, sawtooth, reverse sawtooth, triangle and square waves, depending on what was selected for my oscillators/LFOs etc.

Trigonometry isn't exactly my strong point. I can get it to display a scrolling sine wave using the formula:

x=time%1
y=0.5+sin(time)*0.5
timebase=10

Anyone got any clue how I can get it to display these other waveforms?

I'd also like to be able to change the frequency depending on the individual tuning of the oscillators.

Any help on how to do this would be greatly appreciated.

Re: Waveform formulae for signalscope

Posted: 16 Jan 2012 08:59
by st8_livecontrol
Heres my more primitive triangle generator, where o is some multiple of time
val = o % 4 > 2 ? (2 - o %2)/2 : (o % 2)/2;

i initially went the trigonmetric route with the sine series (http://en.wikipedia.org/wiki/Triangle_wave), you need about 3-5 harmonics for a decent triangle wave but you still get a bit of oscillation near the peaks. The above code cuts down mathematical operations somewhat.