Created
June 22, 2025 17:00
-
-
Save wheremyfoodat/a504dfe6a64badb59d9649538b68a445 to your computer and use it in GitHub Desktop.
Small F# NWaves demo, to demonstrate how to do basic DSP using F#
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
// Run with "dotnet fsi fft.fsx" | |
#r "nuget: NWaves" | |
open FSharp.Core | |
open NWaves.Signals | |
open NWaves.Transforms | |
let magnitude realPart imagPart = Array.map2 (fun re im -> sqrt (re * re + im * im)) realPart imagPart | |
let samples = [|1.0f; 0.6f; 0.4f; 0.1f; 1.0f; 1.0f; 0.9f; 1.0f|] | |
let signal = DiscreteSignal(32000, samples) | |
let fft = Fft(samples.Length) | |
let reBuffer = Array.copy samples | |
let imBuffer = Array.zeroCreate<float32>(samples.Length) | |
fft.Direct(reBuffer, imBuffer) | |
printfn "Signal Duration: %f seconds (fs = %dHz, %d samples)" signal.Duration signal.SamplingRate signal.Length | |
printfn "Energy: %f, RMS: %f\n" (signal.Energy()) (signal.Rms()) | |
printfn "FFT Magnitudes: %A" (magnitude reBuffer imBuffer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment