19 /// denominator number
24 fn a_tf_set_num(ctx: *mut tf, num_n: uint, num_p: *const float, input: *mut float);
25 fn a_tf_set_den(ctx: *mut tf, den_n: uint, den_p: *const float, output: *mut float);
35 fn a_tf_iter(ctx: *const tf, x: float) -> float;
36 fn a_tf_zero(ctx: *const tf);
40 /// initialize for transfer function
41 pub fn new(num: &[float], input: &mut [float], den: &[float], output: &mut [float]) -> Self {
42 let mut ctx: Self = Self {
43 input: core::ptr::null_mut(),
44 output: core::ptr::null_mut(),
45 num_p: core::ptr::null(),
46 den_p: core::ptr::null(),
64 /// calculate for transfer function
65 pub fn iter(&mut self, x: float) -> float {
66 unsafe { a_tf_iter(self, x) }
69 /// zeroing for transfer function
70 pub fn zero(&mut self) -> &mut Self {
71 unsafe { a_tf_zero(self) };
75 /// get input for transfer function
76 pub fn input(&self) -> &[float] {
77 unsafe { core::slice::from_raw_parts(self.input, self.num_n as usize) }
80 /// get numerator for transfer function
81 pub fn num(&self) -> &[float] {
82 unsafe { core::slice::from_raw_parts(self.num_p, self.num_n as usize) }
85 /// set numerator for transfer function
86 pub fn set_num(&mut self, num: &[float], input: &mut [float]) -> &mut Self {
87 unsafe { a_tf_set_num(self, num.len() as uint, num.as_ptr(), input.as_mut_ptr()) };
91 /// get output for transfer function
92 pub fn output(&self) -> &[float] {
93 unsafe { core::slice::from_raw_parts(self.output, self.den_n as usize) }
96 /// get denominator for transfer function
97 pub fn den(&self) -> &[float] {
98 unsafe { core::slice::from_raw_parts(self.den_p, self.den_n as usize) }
101 /// set denominator for transfer function
102 pub fn set_den(&mut self, den: &[float], output: &mut [float]) -> &mut Self {
103 unsafe { a_tf_set_den(self, den.len() as uint, den.as_ptr(), output.as_mut_ptr()) };
111 let num = [6.59492796e-05, 6.54019884e-05];
112 let den = [-1.97530991, 0.97530991];
113 let mut input = [0.0; 2];
114 let mut output = [0.0; 2];
115 let mut a = crate::tf::tf::new(&num, &mut input, &den, &mut output);
116 a.set_num(&num, &mut input).set_den(&den, &mut output);
117 std::println!("{} {}", a.iter(10.0), a.iter(10.0));
118 std::println!("{:?} {:?}", a.num(), a.input());
119 std::println!("{:?} {:?}", a.den(), a.output());