3 Description: beam definition and operations
5 Created: 21/07/2013 Modified: 21/07/2013
8 exception Beam_matching of string;;
15 class beam : signal_type array -> beam_type =
16 fun (signals_init : signal_type array) ->
18 val signals = signals_init
21 method width = Array.length signals
23 method sub : int -> int -> beam_type =
26 new beam (Array.sub self#get start len)
28 method cut : int -> beam_type * beam_type =
29 fun (cut_width : int)->
30 ((self#sub 0 cut_width),(self#sub cut_width (self#width - cut_width)))
32 method append : beam_type -> beam_type =
33 fun (b : beam_type) ->
34 new beam (Array.append self#get b#get)
36 method private add_memory : int -> unit =
38 let signal_add_memory : int -> signal_type -> unit =
42 let _ = Array.map (signal_add_memory window) self#get in ()
44 method matching : int -> beam_type =
46 if size = self#width then new beam self#get
48 else if (size > self#width) && (size mod self#width = 0) then
49 let () = self#add_memory 1 in
51 Array.concat (Array.to_list
52 (Array.make (size/self#width) self#get)) in
53 new beam split_signals
55 else if (size < self#width) && (self#width mod size = 0) then
57 fun (sa : signal_type array) ->
60 if i + l < Array.length sa then
61 (sa.(i))#add (merge_rec sa l (i + l))
63 let merge_signals = Array.init size (merge_rec self#get size) in
64 new beam merge_signals
66 else raise (Beam_matching "matching size error")
68 method at : time -> value_type array =
70 let signal_at = fun (t : time) -> fun (s : signal_type) -> s#at t in
71 Array.map (signal_at t) self#get
73 method output : int -> value_type array array =
74 fun (length_max : int) ->
75 let transpose : 'a array array -> 'a array array =
77 let get_element = fun i -> fun array -> array.(i) in
78 let get_column = fun m -> fun i -> Array.map (get_element i) m in
79 Array.init self#width (get_column matrix) in
80 let value_init = new value Error in
81 let container = Array.make length_max
82 (Array.make self#width value_init) in
86 while !index < length_max do
87 container.(!index) <- self#at !index;
95 | Convert_Error s -> "Convert_Error: " ^ s
96 | Basic_operation s -> "Basic_operation: " ^ s
97 | Signal_operation s -> "Signal_operation: " ^ s
98 | Beam_matching s -> "Beam_Matching_Error: " ^ s
99 | _ -> "Compute finished."
101 let () = print_string error_message in
102 transpose (Array.sub container 0 !index)
104 method frequency : int array =
105 let each_rate : signal -> int =
106 fun (s : signal) -> s#frequency in
107 Array.map each_rate self#get