Skip to content

Commit 8b5aeb8

Browse files
committed
CF 1.4
1 parent 8cb133f commit 8b5aeb8

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package Catalano.Signal;
8+
9+
/**
10+
*
11+
* @author Diego Catalano
12+
*/
13+
public class Convolution {
14+
15+
public enum Mode {Same, Valid};
16+
private Mode mode = Mode.Valid;
17+
18+
public Convolution() {}
19+
20+
public Convolution(Mode mode){
21+
this.mode = mode;
22+
}
23+
24+
public double[][] Process(double[][] signal, double[] convolve){
25+
26+
int n;
27+
switch(mode){
28+
case Same:
29+
n = signal.length - convolve.length + 1;
30+
if (n > 0){
31+
double[][] result = new double[signal.length][signal[0].length];
32+
for (int i = 0; i < result.length; i++) {
33+
double r = 0;
34+
for (int j = 0; j < convolve.length; j++) {
35+
r += signal[i+j] * convolve[convolve.length -j -1];
36+
}
37+
result[i] = r;
38+
}
39+
}
40+
return result;
41+
else{
42+
throw new IllegalArgumentException("The convolve lenght must be > or = of the signal");
43+
}
44+
break;
45+
case Valid:
46+
n = signal.length - convolve.length + 1;
47+
if (n > 0){
48+
result = new double[signal.length - convolve.length + 1];
49+
for (int i = 0; i < result.length; i++) {
50+
double r = 0;
51+
for (int j = 0; j < convolve.length; j++) {
52+
r += signal[i+j] * convolve[convolve.length -j -1];
53+
}
54+
result[i] = r;
55+
}
56+
}
57+
else{
58+
throw new IllegalArgumentException("The convolve lenght must be > or = of the signal");
59+
}
60+
break;
61+
}
62+
63+
return result;
64+
65+
}
66+
67+
68+
69+
}

0 commit comments

Comments
 (0)