Skip to content

Commit

Permalink
feat: menambahkan algoritma Konvolusi (#177)
Browse files Browse the repository at this point in the history
Signed-off-by: slowy07 <slowy.arfy@proton.me>
  • Loading branch information
slowy07 authored Oct 5, 2024
1 parent 8ecf90e commit 5fea89d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/algorithm/math/Konvolusi.java
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;
}
}

0 comments on commit 5fea89d

Please sign in to comment.