Trait basic_dsp::InsertZerosOps
source · pub trait InsertZerosOps<T>where
T: RealNumber,{
// Required methods
fn zero_pad(
&mut self,
points: usize,
option: PaddingOption
) -> Result<(), ErrorReason>;
fn zero_interleave(&mut self, factor: u32) -> Result<(), ErrorReason>;
}
Expand description
A trait to insert zeros into the data at some specified positions.
Required Methods§
sourcefn zero_pad(
&mut self,
points: usize,
option: PaddingOption
) -> Result<(), ErrorReason>
fn zero_pad( &mut self, points: usize, option: PaddingOption ) -> Result<(), ErrorReason>
Appends zeros add the end of the vector until the vector has the size given
in the points argument.
If points
smaller than the self.len()
then this operation won’t do anything, however
in future it will raise an error.
Note: Each point is two floating point numbers if the vector is complex.
Note2: Adding zeros to the signal changes its power. If this function is used to
zero pad to a power
of 2 in order to speed up FFT calculation then it might be necessary to multiply it
with len_after/len_before
so that the spectrum shows the expected power. Of course this is depending
on the application.
§Example
use basic_dsp_vector::*;
let mut vector = vec!(1.0, 2.0).to_real_time_vec();
vector.zero_pad(4, PaddingOption::End).expect("Ignoring error handling in examples");
assert_eq!([1.0, 2.0, 0.0, 0.0], vector[..]);
let mut vector = vec!(Complex::new(1.0, 2.0)).to_complex_time_vec();
vector.zero_pad(2, PaddingOption::End).expect("Ignoring error handling in examples");
assert_eq!([Complex::new(1.0, 2.0), Complex::new(0.0, 0.0)], vector[..]);
sourcefn zero_interleave(&mut self, factor: u32) -> Result<(), ErrorReason>
fn zero_interleave(&mut self, factor: u32) -> Result<(), ErrorReason>
Interleaves zeros factor - 1
times after every vector element, so that the resulting
vector will have a length of self.len() * factor
.
Note: Remember that each complex number consists of two floating points and interleaving will take that into account.
If factor is 0 (zero) then self
will be returned.
§Example
use basic_dsp_vector::*;
let mut vector = vec!(1.0, 2.0).to_real_time_vec();
vector.zero_interleave(2);
assert_eq!([1.0, 0.0, 2.0, 0.0], vector[..]);
let mut vector = vec!(Complex::new(1.0, 2.0), Complex::new(3.0, 4.0)).to_complex_time_vec();
vector.zero_interleave(2).expect("Ignoring error handling in examples");
assert_eq!([Complex::new(1.0, 2.0), Complex::new(0.0, 0.0), Complex::new(3.0, 4.0), Complex::new(0.0, 0.0)], vector[..]);