1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use super::super::{
DspVec, MetaData, NumberSpace, RededicateForceOps, TimeDomain, ToFreqResult, ToSliceMut,
};
use crate::array_to_complex_mut;
use crate::numbers::*;
use crate::window_functions::*;
pub trait TimeDomainOperations<S, T>
where
S: ToSliceMut<T>,
T: RealNumber,
{
fn apply_window(&mut self, window: &WindowFunction<T>);
fn unapply_window(&mut self, window: &WindowFunction<T>);
}
impl<S, T, N, D> TimeDomainOperations<S, T> for DspVec<S, T, N, D>
where
DspVec<S, T, N, D>: ToFreqResult,
<DspVec<S, T, N, D> as ToFreqResult>::FreqResult: RededicateForceOps<DspVec<S, T, N, D>>,
S: ToSliceMut<T>,
T: RealNumber,
N: NumberSpace,
D: TimeDomain,
{
fn apply_window(&mut self, window: &WindowFunction<T>) {
if self.is_complex() {
self.multiply_window_priv(
window.is_symmetric(),
|array| array_to_complex_mut(array),
window,
|f, i, p| Complex::<T>::new(f.window(i, p), T::zero()),
);
} else {
self.multiply_window_priv(
window.is_symmetric(),
|array| array,
window,
|f, i, p| f.window(i, p),
);
}
}
fn unapply_window(&mut self, window: &WindowFunction<T>) {
if self.is_complex() {
self.multiply_window_priv(
window.is_symmetric(),
|array| array_to_complex_mut(array),
window,
|f, i, p| Complex::<T>::new(T::one() / f.window(i, p), T::zero()),
);
} else {
self.multiply_window_priv(
window.is_symmetric(),
|array| array,
window,
|f, i, p| T::one() / f.window(i, p),
);
}
}
}