Skip to main content

FirInstanceF32

Struct FirInstanceF32 

Source
pub struct FirInstanceF32<'a> {
    pub num_taps: u16,
    pub coeffs: &'a [f32],
    pub state: &'a mut [f32],
}
Expand description

Instance structure for the floating-point FIR filter.

Fields§

§num_taps: u16§coeffs: &'a [f32]§state: &'a mut [f32]

Implementations§

Source§

impl<'a> FirInstanceF32<'a>

Source

pub fn init(num_taps: u16, coeffs: &'a [f32], state: &'a mut [f32]) -> Self

Examples found in repository?
examples/basic_usage.rs (line 28)
5fn main() {
6    println!("=== embedded-dsp Basic Usage Example ===");
7
8    // 1. Vector Operations
9    let a = [1.0f32, 2.0, 3.0, 4.0];
10    let b = [10.0f32, 20.0, 30.0, 40.0];
11    let mut vec_out = [0.0f32; 4];
12    add_f32(&a, &b, &mut vec_out);
13    println!("Vector Add: {:?}", vec_out);
14
15    let dot = dot_prod_f32(&a, &b);
16    println!("Vector Dot Product: {}", dot);
17
18    // 2. Q15 Fixed-Point Saturating Math
19    let q15_a = [20000i16, 25000];
20    let q15_b = [15000i16, 10000];
21    let mut q15_out = [0i16; 2];
22    add_q15(&q15_a, &q15_b, &mut q15_out);
23    println!("Q15 Saturating Add (clamped at 32767): {:?}", q15_out);
24
25    // 3. FIR Filtering
26    let coeffs = [0.25f32, 0.5, 0.25]; // 3-tap moving average filter
27    let mut state = [0.0f32; 3 + 4 - 1];
28    let mut fir = FirInstanceF32::init(3, &coeffs, &mut state);
29
30    let input_signal = [1.0f32, 2.0, 3.0, 4.0];
31    let mut filtered_signal = [0.0f32; 4];
32    fir_f32(&mut fir, &input_signal, &mut filtered_signal);
33    println!("FIR Filter Output: {:?}", filtered_signal);
34
35    // 4. PID Motor Controller
36    let mut pid = PidInstanceF32::new(2.0, 0.1, 0.05);
37    let control_output = pid.process(10.0);
38    println!("PID Control Signal: {}", control_output);
39
40    // 5. 64-Point Complex FFT
41    let mut fft_data = [0.0f32; 128]; // 64 complex pairs [re, im, ...]
42    for i in 0..64 {
43        fft_data[2 * i] = (i as f32 * 0.1).sin();
44    }
45    cfft_f32(&mut fft_data, 64, 0, 1);
46    println!("64-Point Complex FFT processed successfully!");
47}

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for FirInstanceF32<'a>

§

impl<'a> Freeze for FirInstanceF32<'a>

§

impl<'a> RefUnwindSafe for FirInstanceF32<'a>

§

impl<'a> Send for FirInstanceF32<'a>

§

impl<'a> Sync for FirInstanceF32<'a>

§

impl<'a> Unpin for FirInstanceF32<'a>

§

impl<'a> UnsafeUnpin for FirInstanceF32<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.