Created
February 20, 2018 16:51
-
-
Save josesoyo/f45b59a035c3e2ec2cdf0fe1f95cc84b to your computer and use it in GitHub Desktop.
Example with MathNet filtering
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
open System.IO | |
// test filtering | |
#r @"packages/MathNet.Filtering.0.4.0/lib/net40/MathNet.Filtering.dll" | |
open MathNet.Filtering | |
let readLines (filePath:string) = seq { | |
use sr = new StreamReader (filePath) | |
while not sr.EndOfStream do | |
yield sr.ReadLine () | |
sr.Close() | |
} | |
let readDispInfo (filePath:string) = | |
// read the file and transform it into numerical | |
let infoRead = readLines filePath | |
(infoRead) | |
|> Seq.map(fun x -> float(x)) // Transform the strings into floats [line].[value] | |
|> Seq.toArray | |
let pa = Path.Combine(__SOURCE_DIRECTORY__, "SWEB_disp_5KHz_mov.txt") | |
let disp_beam = readDispInfo pa | |
// low pass filter tests | |
let fs ,fcut, order = 5000., 2.5, 5 | |
//let lowPass = MathNet.Filtering.OnlineFilter.CreateLowpass(MathNet.Filtering.ImpulseResponse.Finite,fs,fcut, order) // in case we search for a different order | |
let lowPass = MathNet.Filtering.OnlineFilter.CreateLowpass(MathNet.Filtering.ImpulseResponse.Finite,fs,fcut) | |
//lowPass.Reset() | |
let disp_beam_f = disp_beam |> lowPass.ProcessSamples // apply the filter | |
printfn "See if the max or min are similar: %f %f"(disp_beam_f |> Array.min) (disp_beam |> Array.min ) | |
// | |
// save the data in a file | |
let path_save = Path.Combine(__SOURCE_DIRECTORY__,"filtered_data.dat") | |
let sw = new StreamWriter(path_save) | |
disp_beam_f |> | |
Seq.iter( fun no -> sw.WriteLine( string(no))) | |
sw.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment