Qu

sine

Builtin index · Signal processing

result = sine(freq, fs, n, [phase=0], [amplitude=1])

Input: freq, fs, n, phase, amplitude · Output: result

What it is

freq, fs: numbers (Hz); n: number (integer sample count); phase (optional number, radians); amplitude (optional number).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = sine(freq, fs, n, [phase=0], [amplitude=1])
freq numberfreq, fs: numbers (Hz).
fs numberfreq, fs: numbers (Hz).
n numbern: number (integer sample count).
phase number, optional (default 0)phase (optional number, radians).
amplitude number, optional (default 1)amplitude (optional number).
Signal —carries Fs=fs
multisine —a sine is a one-tone multisine
Returns a length-n Signal (carries Fs=fs). Single-tone generator built on the same synthesis kernel as multisine (a sine is a one-tone multisine).

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

s = sine(1 kHz, 48 kHz, 4800)             # a single tone

c = chirp(20, 20000, 48 kHz, 48000)       # linear sweep, 20Hz to 20kHz

lc = chirp(20, 20000, 48 kHz, 48000, method="logarithmic")
sq = square(100, 1000, 1000, duty=0.3)    # bipolar (+-1) pulse train

p = pwm(modulator, 5000, 48000)           # natural-sampling PWM against

                                           # a triangle carrier (duty

                                           # follows the modulator's value)

from numerics-dsp

fs = 1000
tone = sine(50, fs, 20)
bits = sigma_delta(tone)            # 1-bit noise-shaping quantizer

print("sigma_delta output range: [{min(bits)}, {max(bits)}]")

s = signal(0 to 9, 10)
trimmed = signal_slice_time(s, 0.2, 0.6)   # same operation `cut` is the friendlier name for

print("signal_slice_time(0.2, 0.6) -> {trimmed}")
output
sigma_delta output range: [-1, 1]
signal_slice_time(0.2, 0.6) -> signal(Fs=10) [2, 3, 4, 5, 6]

from signal-processing

How it works

pwm, plus DIBS excitation signals via composition with the already-real elementwise sign and the new sigma_delta primitive rather than dedicated _signum/_dibs builtins — chirp(...) |> sign is a signum chirp, multisine(...) |> sigma_delta is a DIBS-ΔΣ excitation, with no new surface area needed for either. sine(freq, fs, n, [phase=], [amplitude=]) — a single-tone generator built on the exact same synthesis kernel multisine uses (a sine is a one-tone multisine); returns a Signal (carries Fs, like signal(...)/randn don't but arguably should — this generator family is where Fs metadata earns its keep).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.