Previous topicNext topic

[solved] how do i convert a sawtooth into a sine?

Questions, comments, feedback, etc.
Post Reply
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

[solved] how do i convert a sawtooth into a sine?

Post by blackdot »

i want to modify an incoming beatclock which is basically like a sawtooth curve in a way that smooths the thing out like a sine. i tried the smooth modifier but that's either too smooth or too biased towards the sawtooth. i figured you math wizards know an easy answer? :D
Magic
Site Admin
Posts: 3441
Joined: Wed Apr 09, 2014 9:28 pm

Re: how do i convert a sawtooth into a sine?

Post by Magic »

Yup, you can use the Expression modifier for that.

The reason I made the Beat Clock do a sawtooth is that most math functions take a linear ramp as an input. A sawtooth is just a repeating linear ramp.

So you can try this:
Expression: sin(2*pi*x)

And it will give you a nice sine wave that repeats perfectly, because sines go from 0 to 2*pi, not from 0 to 1. Make sense?

If you want to be *really* complete though, you should do this (which you probably wouldn't have known):
sin(2*pi*x*23/24)

The Beat Clock starts and ends on the same value (0 and 1 are the same point when repeated), and it uses 24 ticks per beat, so you need to eliminate the last tick otherwise you'll get a stutter.

Try it out :)

Then if you want, you can add a Smooth modifier afterwards to make it a little less jerky (since 24 ticks at low BPMs is noticeable compared to 60fps).
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: how do i convert a sawtooth into a sine?

Post by blackdot »

awesome thanks. yeh from 0 to 2pi makes sense, i wouldnt have known though how to write this. so you multiply it with 2pi, that means when it's 1 it's 2pi and when it's 0 it's 0. but what exactly happens if you put that into sin(). resp. why does it make a sin curve then? O.o
Magic
Site Admin
Posts: 3441
Joined: Wed Apr 09, 2014 9:28 pm

Re: how do i convert a sawtooth into a sine?

Post by Magic »

awesome thanks. yeh from 0 to 2pi makes sense, i wouldnt have known though how to write this. so you multiply it with 2pi, that means when it's 1 it's 2pi and when it's 0 it's 0.
Yup exactly.
but what exactly happens if you put that into sin(). resp. why does it make a sin curve then? O.o
Not sure if I'm understanding correctly, but if you look at a sine curve:
sine-plot.gif
sine-plot.gif (8.79 KiB) Viewed 6676 times
You can see that as the x-value increases linearly from 0 to 2pi, the y-value oscillates between 1 and -1. It repeats exactly every 2pi. The sawtooth wave created by the Beat Clock is what supplies the linearly changing x-value between 0 and 1, which we are scaling so it goes between 0 and 2pi.

The only thing is that the Beat Clock is actually decreasing from 1 to 0, not increasing from 0 to 1, but visually it doesn't really make a difference in this case.
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: how do i convert a sawtooth into a sine?

Post by blackdot »

but couldnt we then just write 2pi*x as an expression? sorry, this isnt propably the right place for me to deal with my math problems :D.
Magic
Site Admin
Posts: 3441
Joined: Wed Apr 09, 2014 9:28 pm

Re: how do i convert a sawtooth into a sine?

Post by Magic »

No worries :). Do you mean 2pi*x instead of 2*pi*x? Either will work; they mean the same thing.
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: how do i convert a sawtooth into a sine?

Post by blackdot »

no i meant 2pi*x instead of sin(2pi*x). but in the mean time a friend who studies electrical engineering explained it to me and i understood it. i think :D. so it's fine, and thanks a lot for the expression :)
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: how do i convert a sawtooth into a sine?

Post by blackdot »

so.. this transformation moves the value into a sine that seems to go from -1 to 1, it's difficult to tell though, as the values are changing rapidly. but if this is correct, is it also correct that i can normalize it between 0 and 1 by using a scale of 0.5 and then an add of 0.5 ? i want to use this sine for a color value that's limited between 0 and 1. it seeems to work, but it's difficult to tell.
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: how do i convert a sawtooth into a sine?

Post by artnik »

Yes, that will work.

Also, you could just use the SIN OSC(illator) modifier. It already is normalized to output from 0 to 1.
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: how do i convert a sawtooth into a sine?

Post by blackdot »

artnik wrote:Yes, that will work.

Also, you could just use the SIN OSC(illator) modifier. It already is normalized to output from 0 to 1.
okay thanks. i need to use the expression modifier because it transforms the incoming beatclock, which is basically a ramp.
Magic
Site Admin
Posts: 3441
Joined: Wed Apr 09, 2014 9:28 pm

Re: how do i convert a sawtooth into a sine?

Post by Magic »

Instead of using more modifiers, you could do:
Expression: sin(2*pi*x*23/24) * .5 + .5

Which is exactly the same as:
Expression: sin(2*pi*x*23/24)
Scale: .5
Offset: .5

Up to you :).
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: how do i convert a sawtooth into a sine?

Post by blackdot »

right, i'm still thinking inside the box
Post Reply