File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -23,10 +23,24 @@ pub fn max_freq(data: &[Complex32], sample_rate: usize) -> f32 {
23
23
}
24
24
}
25
25
26
+ /// Calculate Decibels relative to the full scale
27
+ pub fn dbfs ( sample : & Complex32 , max_power : f32 ) -> f32 {
28
+ 20.0 * ( sample. norm ( ) / max_power) . log10 ( )
29
+ }
30
+
26
31
27
32
/// ------------------------------------------------------------------------------------------------
28
33
/// Module unit tests
29
34
/// ------------------------------------------------------------------------------------------------
30
35
#[ cfg( test) ]
31
36
mod tests {
37
+ use rustfft:: num_traits:: One ;
38
+
39
+ use super :: * ;
40
+
41
+ #[ test]
42
+ fn test_dbfs ( ) {
43
+ assert_eq ! ( dbfs( & Complex32 :: one( ) , 1. ) , 0. ) ;
44
+ assert_eq ! ( dbfs( & Complex32 :: new( 10. , 0. ) , 100. ) , -20. ) ;
45
+ }
32
46
}
You can’t perform that action at this time.
0 commit comments