-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: menambahkan algoritma Konvolusi (#177)
Signed-off-by: slowy07 <slowy.arfy@proton.me>
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package algorithm.math; | ||
|
||
/** | ||
* @brief contoh implementasi dari dua diskret sinyal | ||
*/ | ||
public final class Konvolusi { | ||
private Konvolusi() {} | ||
|
||
/** | ||
* @brief fungsi konvolusi yang memberikan dua input sinyal | ||
* @param angkaPertama nilai diskret sinyal pertama | ||
* @param angkaKedua nilai diskret sinyal kedua | ||
* @return sinyal konvolusi | ||
*/ | ||
public static double[] konvolusi(double[] angkaPertama, double[] angkaKedua) { | ||
double[] konvolu = new double[angkaPertama.length + angkaKedua.length - 1]; | ||
|
||
for (int i = 0; i < konvolu.length; i++) { | ||
konvolu[i] = 0; | ||
int k = Math.max(i - angkaKedua.length + 1, 0); | ||
|
||
while (k < i + 1 && k < angkaPertama.length) { | ||
konvolu[i] += angkaPertama[k] * angkaKedua[i - k]; | ||
k++; | ||
} | ||
} | ||
|
||
return konvolu; | ||
} | ||
} |