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 7876697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:12:27+00:00 2026-06-03T03:12:27+00:00

I try to calculate the DFT for this array x_1 . It must be

  • 0

I try to calculate the DFT for this array x_1. It must be dead simple, but my values are way too low. What’s wrong with my code?

Please no links to other examples – just looking for a fix for my own code.

#include <iostream>
#include <complex>
#include <cassert>

int main ()
{
    const unsigned int N = 20;

    const double x_1[N] = {0, 0.3, 0.6, 0.8, 1, 1, 0.9, 0.7, 0.5, 0.2, 0.2, 0.5, 0.7, 0.9, 1, 1, 0.8, 0.6, 0.3, 0};

    for(unsigned int k = 0; k < N; k++)
    {
        std::complex<double> sum(0.0,0.0);
        for(unsigned int j = 0; j < N; j++)
        {
            int integers = -2*j*k;
            std::complex<double> my_exponent(0.0, M_PI/N*(double)integers);
            sum += x_1[j] * std::exp(my_exponent);
        }
        std::cout << abs(sum)/N << std::endl;
    }
    return 0;
} 
  • 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-06-03T03:12:28+00:00Added an answer on June 3, 2026 at 3:12 am
    std::cout << abs(sum)/N << std::endl;
    

    Why are you dividing by N?

    The coefficients are without the division. See the wiki.

    These are the values I get with Matlab:

    12.0000000000000 + 0.00000000000000i
    -0.971586454726535 - 0.153884176858763i
    -4.26246117974981 - 1.38495759172886i   
    -0.0712959999079796 - 0.0363271264002681i   
    -0.473606797749979 - 0.344095480117793i
    0.00000000000000 + 0.00000000000000i
    -0.237538820250189 - 0.326944137602412i
    0.0185095954079375 + 0.0363271264002681i
    -0.0263932022500213 - 0.0812299240582274i
    0.0243728592265771 + 0.153884176858763i
    0.00000000000000 + 0.00000000000000i    
    0.0243728592265771 - 0.153884176858763i
    -0.0263932022500213 + 0.0812299240582274i
    0.0185095954079375 - 0.0363271264002681i    
    -0.237538820250189 + 0.326944137602412i 
    0.00000000000000 + 0.00000000000000i    
    -0.473606797749979 + 0.344095480117793i 
    -0.0712959999079796 + 0.0363271264002681i
    -4.26246117974981 + 1.38495759172886i   
    -0.971586454726535 + 0.153884176858763i
    

    and I see more or less the same values when I print using
    std::cout << sum << std::endl;

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

Sidebar

Related Questions

I try to calculate with JS' modulo function, but don't get the right result
I try to calculate a miles per hours. For this I write a code
I try to calculate a List with times. But using LocalTime from Joda Time
Let say I got this function : void int Calculate(double[] array) {} And in
I have this vector [10000000000 10000000001 10000000002] and i try to calculate its variance
When I try to calculate the following integral in Mathematica 8, I get this
Try running this in a .VBS file MsgBox(545.14-544.94) You get a neat little answer
I try to calculate the easter date in php. echo(date(2012: t.n.Y, easter_date(2012)).'<br>'); // 2012:
When I try to calculate the time elapsed using Date Components the date is
I am trying to calculate a SHA-1 Hash from a string, but when I

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.