style: enable LocalVariableName in CheckStyle (#5191)

* style: enable LocalVariableName in checkstyle

* Removed minor bug

* Resolved Method Name Bug

* Changed names according to suggestions
This commit is contained in:
S. Utkarsh
2024-05-28 23:59:28 +05:30
committed by GitHub
parent 81cb09b1f8
commit 25d711c5d8
45 changed files with 418 additions and 417 deletions

View File

@@ -186,16 +186,16 @@ public final class FFT {
public static ArrayList<Complex> fft(ArrayList<Complex> x, boolean inverse) {
/* Pad the signal with zeros if necessary */
paddingPowerOfTwo(x);
int N = x.size();
int log2N = findLog2(N);
x = fftBitReversal(N, log2N, x);
int n = x.size();
int log2n = findLog2(n);
x = fftBitReversal(n, log2n, x);
int direction = inverse ? -1 : 1;
/* Main loop of the algorithm */
for (int len = 2; len <= N; len *= 2) {
for (int len = 2; len <= n; len *= 2) {
double angle = -2 * Math.PI / len * direction;
Complex wlen = new Complex(Math.cos(angle), Math.sin(angle));
for (int i = 0; i < N; i += len) {
for (int i = 0; i < n; i += len) {
Complex w = new Complex(1, 0);
for (int j = 0; j < len / 2; j++) {
Complex u = x.get(i + j);
@@ -206,24 +206,24 @@ public final class FFT {
}
}
}
x = inverseFFT(N, inverse, x);
x = inverseFFT(n, inverse, x);
return x;
}
/* Find the log2(N) */
public static int findLog2(int N) {
int log2N = 0;
while ((1 << log2N) < N) {
log2N++;
/* Find the log2(n) */
public static int findLog2(int n) {
int log2n = 0;
while ((1 << log2n) < n) {
log2n++;
}
return log2N;
return log2n;
}
/* Swap the values of the signal with bit-reversal method */
public static ArrayList<Complex> fftBitReversal(int N, int log2N, ArrayList<Complex> x) {
public static ArrayList<Complex> fftBitReversal(int n, int log2n, ArrayList<Complex> x) {
int reverse;
for (int i = 0; i < N; i++) {
reverse = reverseBits(i, log2N);
for (int i = 0; i < n; i++) {
reverse = reverseBits(i, log2n);
if (i < reverse) {
Collections.swap(x, i, reverse);
}
@@ -231,12 +231,12 @@ public final class FFT {
return x;
}
/* Divide by N if we want the inverse FFT */
public static ArrayList<Complex> inverseFFT(int N, boolean inverse, ArrayList<Complex> x) {
/* Divide by n if we want the inverse FFT */
public static ArrayList<Complex> inverseFFT(int n, boolean inverse, ArrayList<Complex> x) {
if (inverse) {
for (int i = 0; i < x.size(); i++) {
Complex z = x.get(i);
x.set(i, z.divide(N));
x.set(i, z.divide(n));
}
}
return x;
@@ -247,7 +247,7 @@ public final class FFT {
* FFT algorithm.
*
* <p>
* E.g. num = 13 = 00001101 in binary log2N = 8 Then reversed = 176 =
* E.g. num = 13 = 00001101 in binary log2n = 8 Then reversed = 176 =
* 10110000 in binary
*
* <p>
@@ -255,14 +255,14 @@ public final class FFT {
* https://www.geeksforgeeks.org/write-an-efficient-c-program-to-reverse-bits-of-a-number/
*
* @param num The integer you want to reverse its bits.
* @param log2N The number of bits you want to reverse.
* @param log2n The number of bits you want to reverse.
* @return The reversed number
*/
private static int reverseBits(int num, int log2N) {
private static int reverseBits(int num, int log2n) {
int reversed = 0;
for (int i = 0; i < log2N; i++) {
for (int i = 0; i < log2n; i++) {
if ((num & (1 << i)) != 0) {
reversed |= 1 << (log2N - 1 - i);
reversed |= 1 << (log2n - 1 - i);
}
}
return reversed;