Created
February 8, 2016 09:06
-
-
Save AlonAm/db30a44ac997b4b04299 to your computer and use it in GitHub Desktop.
Simple Signal Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SignalGenerator | |
{ | |
long startTime = Stopwatch.GetTimestamp(); | |
long ticksPerSecond = Stopwatch.Frequency; | |
float amplitude = 1f; | |
float frequency = 1f; | |
float phase = 1f; | |
float offset = 0f; | |
public float GetValue() | |
{ | |
float time = (float)(Stopwatch.GetTimestamp() - startTime) / ticksPerSecond' | |
return GetValue(time); | |
} | |
public float GetValue(float time) | |
{ | |
var t = frequency * time + phase; | |
var value = (float)Math.Sin(2f * Math.PI * t); | |
return amplitude * value + offset; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment