Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6379373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:07:48+00:00 2026-05-25T02:07:48+00:00

For a few weeks now, I have been trying to implement a DFT that

  • 0

For a few weeks now, I have been trying to implement a DFT that takes an arbitrary set of bytes and treats them as a signal. It then transforms them to the frequency domain. Following that it transforms them back. It originally only attempted to use some of the components to reconstruct the original signal. When this failed, I tried using all of the components and it still failed.

I have been following Wikipedia’s Equations as a guide for how to do this and my code seems to match the equations given (in my mind) given this code:

DFT:

for (int k = 0; k < frequency_domain_magnitude.length; k++) {
    for (int n = 0; n < data.length; n++) {
        double val = (-2.0 * Math.PI * n * k / data.length);
        freq_imag[k] += data[n] * -Math.sin(val);
        freq_real[k] += data[n] * Math.cos(val);
    }
    frequency_domain_magnitude[k] = Math.sqrt(freq_imag[k] * freq_imag[k] + freq_real[k] * freq_real[k]);
}

IDFT:

for (int n = 0; n < data.length; n++) {
    doubleValue[n] = 0;
    for (int k = 0; k < freqUsed.length; k++) {
        double val = (2.0 * Math.PI * n * k / data.length);
        doubleValue[n] = freq_real[k] * Math.cos(val) - freq_imag[k] * Math.sin(val);
    }
    time_real[n] = (byte) (Math.floor(doubleValue[n]));
}

Can anybody help me identify what the problem is?

I asked a previous question that is about the same project, but it was worded terribly and editing may have caused more confusion, not less. Also, although that question may have been answered, I still have more to figure out. That can be found here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:07:49+00:00Added an answer on May 25, 2026 at 2:07 am

    At least three things are wrong:

    First, you are not summing over all frequencies in your IDFT. That’s a big, big problem, basically equivalent to only taking the IDFT of one discrete frequency instead of the entire frequency domain data.
    Second, you have a sign flipped in your IDFT.

    Change line 5 of snippet 2 to

        doubleValue[n] += freq_real[k] * Math.cos(val) + freq_imag[k] * Math.sin(val);
    

    and make sure you initialize doubleValue to zeros.

    Third, you’ll want to add a normalization step;

    Change line 7 of snippet 2 to

    time_real[n] = (byte) (Math.floor(doubleValue[n] / data.length))
    

    Fourth, for your own ease, test this floating point algorithm using floating point inputs and outputs before you truncate to an integral data type and don’t assume that you’ll get precisely correct answers doing a round trip on integral data– floating point error is very real.

    It might also help to grab someone else’s implementation of the DFT and IDFT and compare the behavior with your implementation on some very simple inputs to catch other errors. Since the DFT is linear algebra, you may get it less than perfectly correct and still see qualitatively okay-seeming answers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've searched all over and have been trying for a few weeks now (and
I have been playing with nservicebus for a few weeks now and since everything
I have been noticing, over the last few weeks, that my installation of VS2008
I have been writing a JavaScript library for a few weeks now and it
I have been working in Sencha Touch for a few weeks now, and while
I have been using symfony for a few weeks now and I am using
I've been working on a WPF control for a few weeks now that contains
For the past few weeks, I've been trying to learn about just how email
I've been working for a few weeks now with the Google Maps API v3,
I've been using VIM for a few weeks now while messing with various web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.