File tree 1 file changed +2
-7
lines changed
src/main/java/com/thealgorithms/audiofilters 1 file changed +2
-7
lines changed Original file line number Diff line number Diff line change 10
10
* <p>Based on the definition from
11
11
* <a href="https://en.wikipedia.org/wiki/Moving_average">Wikipedia link</a>.
12
12
*/
13
- public class EMAFilter {
14
-
13
+ public class EMAFilter {
15
14
private final double alpha ;
16
15
private double emaValue ;
17
-
18
16
/**
19
17
* Constructs an EMA filter with a given smoothing factor.
20
18
*
@@ -28,7 +26,6 @@ public EMAFilter(double alpha) {
28
26
this .alpha = alpha ;
29
27
this .emaValue = 0.0 ;
30
28
}
31
-
32
29
/**
33
30
* Applies the EMA filter to an audio signal array.
34
31
*
@@ -39,16 +36,14 @@ public double[] apply(double[] audioSignal) {
39
36
if (audioSignal .length == 0 ) {
40
37
return new double [0 ];
41
38
}
42
-
43
39
double [] emaSignal = new double [audioSignal .length ];
44
40
emaValue = audioSignal [0 ];
45
41
emaSignal [0 ] = emaValue ;
46
-
42
+
47
43
for (int i = 1 ; i < audioSignal .length ; i ++) {
48
44
emaValue = alpha * audioSignal [i ] + (1 - alpha ) * emaValue ;
49
45
emaSignal [i ] = emaValue ;
50
46
}
51
-
52
47
return emaSignal ;
53
48
}
54
49
}
You can’t perform that action at this time.
0 commit comments