Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ifft is not computed correctly #133

Open
alexandrucaraus opened this issue Jun 15, 2024 · 0 comments
Open

Ifft is not computed correctly #133

alexandrucaraus opened this issue Jun 15, 2024 · 0 comments

Comments

@alexandrucaraus
Copy link

The inverse fft is not computed correctly

fun fft1() {
    // Example data
    val magnitudeFrame = doubleArrayOf(1.0, 2.0, 3.0, 4.0)
    val phaseCumulative = doubleArrayOf(0.1, 0.2, 0.3, 0.4)

    val inputFrame = magnitudeFrame.zip(phaseCumulative) { mag, phase -> mag * ComplexNumber(.0, phase).exp() }.asSequence()

    println(inputFrame.toList())

    val output = fft(x = inputFrame, n = 4, inversed = true).map { it.re }
    println("Out ${output.toList()}")
}

[0.9950041652780258+0.09983341664682815i, 1.9601331556824833+0.39733866159012243i, 2.866009467376818+0.8865606199840186i, 3.6842439760115404+1.557673369234602i]
Out [2.3763476910872168, -0.757835002435818, -0.44584087475979484, -0.1776676486135782]

fun ff2() {
    val magnitudeFrame = doubleArrayOf(1.0, 2.0, 3.0, 4.0)
    val phaseCumulative = doubleArrayOf(0.1, 0.2, 0.3, 0.4)

    val inputFrame = magnitudeFrame.zip(phaseCumulative) { mag, phase -> Complex(.0, phase).exp().multiply(mag) }.toTypedArray()

    println(inputFrame.toList())

    val transformer = FastFourierTransformer(DftNormalization.STANDARD)

    val output = transformer.transform(inputFrame, TransformType.INVERSE).map { it.real }

    println("Out ${output.toList()}")

}

[(0.9950041652780258, 0.09983341664682815), (1.9601331556824833, 0.39733866159012243), (2.866009467376818, 0.8865606199840186), (3.6842439760115404, 1.557673369234602)]
Out [2.3763476910872168, -0.1776676486135782, -0.44584087475979495, -0.757835002435818]

fun main () {
    fft1()
    ff2()
}

fft1 is computed using wavebeans

ff2 is computed using implementation("org.apache.commons:commons-math3:3.6.1")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant