This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
4rpl:commands:signalgenerator [2024/05/29 19:54] – rewritten Grabz | 4rpl:commands:signalgenerator [2025/09/03 16:43] (current) – [Sine wave in any direction without gaps] kalli | ||
---|---|---|---|
Line 67: | Line 67: | ||
==== Square wave function ==== | ==== Square wave function ==== | ||
<code c#> | <code c#> | ||
- | Square: | + | value = Mathf.Sign(Mathf.Sin(2f * Mathf.PI * t)); |
</ | </ | ||
==== For triangle wave function ==== | ==== For triangle wave function ==== | ||
- | === Time and Frequency === | ||
<code c#> | <code c#> | ||
- | Triangle | + | value = 1f - 4f * (float)Mathf.Abs(Mathf.Round(t - 0.25f) - (t - 0.25f)); |
</ | </ | ||
==== Saw-tooth wave function ==== | ==== Saw-tooth wave function ==== | ||
<code c#> | <code c#> | ||
- | Sawtooth: | + | value = 2f * (t - (float)Mathf.Floor(t + 0.5f)); |
</ | </ | ||
==== Random wave function ==== | ==== Random wave function ==== | ||
Line 142: | Line 140: | ||
1 -> | 1 -> | ||
0.5 -> | 0.5 -> | ||
+ | </ | ||
+ | |||
+ | ==== Sine wave in any direction without gaps ==== | ||
+ | {{ : | ||
+ | |||
+ | <code 4RPL> | ||
+ | 30 30 v2 165 91 v2 15 4.5 0 @getSinusoidCells ->list | ||
+ | <-list 0 do | ||
+ | < | ||
+ | loop | ||
+ | |||
+ | : | ||
+ | ->cell1 | ||
+ | ->cell0 | ||
+ | <-cell1 <-cell0 sub ->dir | ||
+ | <-dir.0 abs <-dir.1 abs max ->length | ||
+ | < | ||
+ | <-cell0 | ||
+ | < | ||
+ | dup <-dirL add | ||
+ | loop | ||
+ | < | ||
+ | |||
+ | : | ||
+ | ->shift # FLOAT between 0 and 1 that will shift the signal from signalgenerator. | ||
+ | -> | ||
+ | ->ampl | ||
+ | ->cell1 | ||
+ | ->cell0 | ||
+ | |||
+ | clearstack | ||
+ | <-cell0 <-cell1 @getSingleLineCells dup -> | ||
+ | < | ||
+ | |||
+ | <-cell1 <-cell0 sub normalize ->dir | ||
+ | <-dir.1 <-dir.0 neg v2 <-ampl mul ->dirP | ||
+ | |||
+ | <-cell0 | ||
+ | < | ||
+ | i <-freq <-shift 0 1 signalgenerator <-dirP mul < | ||
+ | loop | ||
+ | list | ||
+ | |||
</ | </ | ||
< | < |