gsl-ocaml / examples /

let read_file init do_line finish f =
  let ic = open_in f in
  let acc = ref init in
      while true do
	let l = input_line ic in
	acc := do_line !acc l
    | End_of_file -> close_in ic
    | exn -> close_in ic ; raise exn
  end ;
  finish !acc

let read_data_file =
  read_file []
    (fun acc l -> float_of_string l :: acc)
    (fun acc -> Array.of_list (List.rev acc))

let main f =
  let data = read_data_file f in
  let n = Array.length data in
  Printf.eprintf "read %d values\n%!" n ;

  let w = Gsl_wavelet.make Gsl_wavelet.DAUBECHIES 4 in
  Gsl_wavelet.transform_forward w data ;
  let high = 
    Gsl_sort.vector_flat_largest_index 20 
      (Gsl_vector_flat.view_array ( abs_float data)) in
  let high_coeff = Array.make n 0. in
  for i = 0 to 20 - 1 do
    let j = high.{i} in
    high_coeff.(j) <- data.(j)
  done ;
  Gsl_wavelet.transform_inverse w high_coeff ;
    (fun f -> Printf.printf "%g\n" f)

let _ = 
  Gsl_error.init () ;
  Gsl_error.handle_exn main "ecg.dat"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.