dsp: constructor style

This commit is contained in:
Robert Jördens 2021-02-01 12:37:44 +01:00
parent fdae9d54e8
commit 7748d8eb54
5 changed files with 15 additions and 14 deletions

View File

@ -5,8 +5,8 @@ pub struct Accu {
}
impl Accu {
pub fn new(state: i32, step: i32) -> Accu {
Accu { state, step }
pub fn new(state: i32, step: i32) -> Self {
Self { state, step }
}
}

View File

@ -15,9 +15,9 @@ impl Complex<i32> {
/// Complex::<i32>::from_angle(-1 << 30); // -pi/2
/// ```
#[inline(always)]
pub fn from_angle(angle: i32) -> Complex<i32> {
pub fn from_angle(angle: i32) -> Self {
let (c, s) = cossin(angle);
Complex(c, s)
Self(c, s)
}
/// Return the absolute square (the squared magnitude).

View File

@ -19,7 +19,7 @@ impl Vec5 {
///
/// # Returns
/// 2nd-order IIR filter coefficients in the form [b0,b1,b2,a1,a2]. a0 is set to -1.
pub fn lowpass(f: f32, q: f32, k: f32) -> Vec5 {
pub fn lowpass(f: f32, q: f32, k: f32) -> Self {
// 3rd order Taylor approximation of sin and cos.
let f = f * 2. * PI;
let fsin = f - f * f * f / 6.;
@ -31,7 +31,7 @@ impl Vec5 {
let a1 = (2. * fcos / a0) as _;
let a2 = ((alpha - 1.) / a0) as _;
Vec5([b0, 2 * b0, b0, a1, a2])
Self([b0, 2 * b0, b0, a1, a2])
}
}

View File

@ -1,4 +1,7 @@
use super::{iir_int::{IIR, Vec5}, Accu, Complex};
use super::{
iir_int::{Vec5, IIR},
Accu, Complex,
};
use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, Default, Deserialize, Serialize)]
@ -10,10 +13,8 @@ pub struct Lockin {
impl Lockin {
/// Create a new Lockin with given IIR coefficients.
pub fn new(ba: Vec5) -> Self {
let mut iir = IIR::default();
iir.ba = ba;
Lockin {
iir,
Self {
iir: IIR { ba, ..Default::default() },
state: [Vec5::default(); 2],
}
}

View File

@ -22,8 +22,8 @@ impl RPLL {
///
/// Returns:
/// Initialized RPLL instance.
pub fn new(dt2: u8) -> RPLL {
RPLL {
pub fn new(dt2: u8) -> Self {
Self {
dt2,
..Default::default()
}
@ -107,7 +107,7 @@ mod test {
impl Harness {
fn default() -> Self {
Harness {
Self {
rpll: RPLL::new(8),
dt2: 8,
shift_frequency: 9,