Added Linear Convolution, FFT, Bluestein's FFT and Circular and Linea… · primary-code-test/Java@4264e0f · GitHub
Skip to content

Commit 4264e0f

Browse files
author
JohnKara
committed
Added Linear Convolution, FFT, Bluestein's FFT and Circular and Linear Convolution using FFT
1 parent f077c8d commit 4264e0f

5 files changed

Lines changed: 516 additions & 0 deletions

File tree

Maths/CircularConvolutionFFT.java

Lines changed: 58 additions & 0 deletions

Maths/Convolution.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.maths;
2+
3+
/**
4+
* Class for linear convolution of two discrete signals
5+
*
6+
* @author Ioannis Karavitsis
7+
* @version 1.0
8+
* */
9+
public class Convolution
10+
{
11+
/**
12+
* Discrete linear convolution function. Both input signals and the output signal must start from 0.
13+
* If you have a signal that has values before 0 then shift it to start from 0.
14+
*
15+
* @param A The first discrete signal
16+
* @param B The second discrete signal
17+
* @return The convolved signal
18+
* */
19+
public static double[] convolution(double[] A, double[] B)
20+
{
21+
double[] convolved = new double[A.length + B.length - 1];
22+
23+
/*
24+
The discrete convolution of two signals A and B is defined as:
25+
26+
A.length
27+
C[i] = Σ (A[k]*B[i-k])
28+
k=0
29+
30+
It's obvious that: 0 <= k <= A.length , 0 <= i <= A.length + B.length - 2 and 0 <= i-k <= B.length - 1
31+
From the last inequality we get that: i - B.length + 1 <= k <= i and thus we get the conditions below.
32+
*/
33+
for(int i = 0; i < convolved.length; i++)
34+
{
35+
convolved[i] = 0;
36+
int k = Math.max(i - B.length + 1, 0);
37+
38+
while(k < i + 1 && k < A.length)
39+
{
40+
convolved[i] += A[k] * B[i - k];
41+
k++;
42+
}
43+
}
44+
45+
return convolved;
46+
}
47+
}

Maths/ConvolutionFFT.java

Lines changed: 61 additions & 0 deletions

0 commit comments

Comments
 (0)