-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into dev
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// Creates a flat top filter of size n | ||
/// | ||
/// | ||
/// uses matlab constants, these constants will change the filter. | ||
/// i - Offset add offset maybe other var to take in? | ||
pub fn flat_top_window<const N: usize>(offset:usize) -> [f32; N] { | ||
const A_0: f32 =0.21557895; | ||
const A_1: f32 =0.41663158; | ||
const A_2: f32 =0.277263158; | ||
const A_3: f32 =0.083578947; | ||
const A_4: f32 =0.006947368; | ||
let mut filter: [f32;N] = [0.0; N]; | ||
for i in 0..N{ | ||
let n = (i as f32) - (offset as f32); | ||
filter[i] = A_0 - A_1 * f32::cos(((2 as f32 * std::f32::consts::PI * n as f32)/N as f32)) + A_2 * f32::cos(((4 as f32 * std::f32::consts::PI * n as f32)/N as f32)) - A_3 * f32::cos(((6 as f32 * std::f32::consts::PI * n as f32)/N as f32)) + A_4 * f32::cos(((8 as f32 * std::f32::consts::PI * n as f32)/N as f32)); | ||
} | ||
filter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod gaussian_window; | |
pub mod hamming; | ||
pub mod triangle; | ||
pub mod sin; | ||
pub mod flat_top; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Test Flat Top Window | ||
|
||
use superdsp::filters_and_windows::flat_top; | ||
|
||
const N_SHORT: usize = 16; | ||
|
||
#[test] | ||
pub fn flat_top_window_short(){ | ||
let expected = [ | ||
-0.00042, | ||
-0.00527, | ||
-0.02687, | ||
-0.0627, | ||
-0.05474, | ||
0.10175, | ||
0.44414, | ||
0.82854, | ||
1.0, | ||
0.82854, | ||
0.44414, | ||
0.10175, | ||
-0.05474, | ||
-0.0627, | ||
-0.02687, | ||
-0.00527, | ||
]; | ||
|
||
let window = flat_top::flat_top_window::<N_SHORT>(0); | ||
assert_eq!(window.len(), N_SHORT); | ||
|
||
// make sure the window is correct to 4 decimal places (floating point error) | ||
for i in 0..N_SHORT { | ||
assert!((window[i] - expected[i]).abs() < 0.0001); | ||
} | ||
} |