FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/src/main/java/com/maths/Convolution.java at Development · ailvcheng/Java · GitHub
ailvcheng
/
Java
Public
forked from
TheAlgorithms/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
src
/
main
/
java
/
com
/
maths
/
Convolution.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (41 loc) · 1.32 KB
Breadcrumbs
Java
/
src
/
main
/
java
/
com
/
maths
/
Convolution.java
Copy path
File metadata and controls
47 lines (41 loc) · 1.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
com
.
maths
;
/**
* Class for linear convolution of two discrete signals
*
* @author Ioannis Karavitsis
* @version 1.0
* */
public
class
Convolution
{
/**
* Discrete linear convolution function. Both input signals and the output signal must start from 0.
* If you have a signal that has values before 0 then shift it to start from 0.
*
* @param A The first discrete signal
* @param B The second discrete signal
* @return The convolved signal
* */
public
static
double
[]
convolution
(
double
[]
A
,
double
[]
B
)
{
double
[]
convolved
=
new
double
[
A
.
length
+
B
.
length
-
1
];
/*
The discrete convolution of two signals A and B is defined as:
A.length
C[i] = Σ (A[k]*B[i-k])
k=0
It's obvious that: 0 <= k <= A.length , 0 <= i <= A.length + B.length - 2 and 0 <= i-k <= B.length - 1
From the last inequality we get that: i - B.length + 1 <= k <= i and thus we get the conditions below.
*/
for
(
int
i
=
0
;
i
<
convolved
.
length
;
i
++)
{
convolved
[
i
] =
0
;
int
k
=
Math
.
max
(
i
-
B
.
length
+
1
,
0
);
while
(
k
<
i
+
1
&&
k
<
A
.
length
)
{
convolved
[
i
] +=
A
[
k
] *
B
[
i
-
k
];
k
++;
}
}
return
convolved
;
}
}
Back
|
FazBrowse Home
|
New Git URL