[−][src]Trait basic_dsp_vector::InsertZerosOpsBuffered
A trait to insert zeros into the data at some specified positions. A buffer is used for types which can't be resized and/or to speed up the calculation.
Required methods
fn zero_pad_b<B>(
&mut self,
buffer: &mut B,
points: usize,
option: PaddingOption
) -> VoidResult where
B: for<'a> Buffer<'a, S, T>,
&mut self,
buffer: &mut B,
points: usize,
option: PaddingOption
) -> VoidResult where
B: for<'a> Buffer<'a, S, T>,
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 will return 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(); let mut buffer = SingleBuffer::new(); vector.zero_pad_b(&mut buffer, 4, PaddingOption::End).expect("Ignoring error handling in examples"); assert_eq!([1.0, 2.0, 0.0, 0.0], vector[..]); let mut vector = vec!(1.0, 2.0).to_complex_time_vec(); vector.zero_pad_b(&mut buffer, 2, PaddingOption::End).expect("Ignoring error handling in examples"); assert_eq!([1.0, 2.0, 0.0, 0.0], vector[..]);
fn zero_interleave_b<B>(&mut self, buffer: &mut B, factor: u32) where
B: for<'a> Buffer<'a, S, T>,
B: for<'a> Buffer<'a, S, T>,
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(); let mut buffer = SingleBuffer::new(); vector.zero_interleave_b(&mut buffer, 2); assert_eq!([1.0, 0.0, 2.0, 0.0], vector[..]); let mut vector = vec!(1.0, 2.0, 3.0, 4.0).to_complex_time_vec(); vector.zero_interleave_b(&mut buffer, 2); assert_eq!([1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0], vector[..]);
Implementors
impl<S, T, N, D> InsertZerosOpsBuffered<S, T> for DspVec<S, T, N, D> where
S: ToSliceMut<T>,
T: RealNumber,
N: NumberSpace,
D: Domain,
[src]
impl<S, T, N, D> InsertZerosOpsBuffered<S, T> for DspVec<S, T, N, D> where
S: ToSliceMut<T>,
T: RealNumber,
N: NumberSpace,
D: Domain,
fn zero_pad_b<B>( | [src] |
fn zero_interleave_b<B>(&mut self, buffer: &mut B, factor: u32) where | [src] |