Created
October 1, 2011 16:54
-
-
Save teburd/1256317 to your computer and use it in GitHub Desktop.
Sine Wave Points
This file contains 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
%% @doc Generate a set of points representing a sine wave | |
%% given some parameters (position, points to generate, freqency, amplitude, | |
%% offset, sample rate). | |
%% @end | |
sine(X, N=0, Frequency, Amplitude, Offset, SampleRate) | |
when is_integer(X), is_integer(N), is_float(Frequency), | |
is_float(Amplitude), is_float(Offset), is_float(SampleRate)-> | |
[]; | |
sine(X, N, Frequency, Amplitude, Offset, SampleRate) | |
when is_integer(X), is_integer(N), is_float(Frequency), | |
is_float(Amplitude), is_float(Offset), is_float(SampleRate) -> | |
Y0 = math:sin(2*math:pi()*X*(Frequency/SampleRate)), | |
Y1 = Amplitude*Y0, | |
Y2 = round(Y1), | |
Y3 = Y2 + Offset, | |
[X, Y3 | sine(X+1, N-1, Frequency, Amplitude, Offset, SampleRate)]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment