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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:43:05+00:00 2026-06-03T00:43:05+00:00

I created a simple integral function and DFT function that I can use with

  • 0

I created a simple integral function and DFT function that I can use with some other code I wrote.

from math import sin,pi
from time import time
def aintegral(d,step):
    return sum(d)*step

def partialdft(d,step,w):
    i = 0
    x = d
    while i/step < len(d):
        x[int(i/step)]*=sin(w*pi*i)
        i+=step
    return aintegral(x,step)


x = []
y = 0
while y<100:
    x.append(5*sin(4*pi*y))
    y+=.01

print partialdft(x,.01,4)

This code gives an output of 249.028500022 which is close to the expected 250 value. However when I iterate the DFT i get an entirely different value for the transform at 4.

from math import sin,pi
from time import time
def aintegral(d,step):
    return sum(d)*step

def partialdft(d,step,w):
    i = 0
    x = d
    while i/step < len(d):
        x[int(i/step)]*=sin(w*pi*i)
        i+=step
    return aintegral(x,step)


x = []
y = 0
while y<100:
    x.append(5*sin(4*pi*y))
    y+=.01

y = 0
while y<10.:
    print y,partialdft(x,.01,y)
    y+=.1

The output for this code is:
0 0.0514628731431

0.1 0.0514628731431

0.2 0.0514628731431

.
.
.
.

4.0 0.0514628731431

.
.
.
.

9.8 0.0514628731431

9.9 0.0514628731431

10.0 0.0514628731431

Can anyone tell me what is causing this problem? Thanks in advance.

Note: At this time I don’t care about using a more efficient fft function. The sample size isn’t large so it doesn’t matter.

  • 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-03T00:43:07+00:00Added an answer on June 3, 2026 at 12:43 am

    partialdft function modifies x. Here’s x after the first loop:

    >>> x[0:10]
    [0.0, 0.62666616782152129, 1.243449435824274, 1.8406227634233896, 2.4087683705085765, 2.9389262614623659, 3.4227355296434436, 3.852566213878946, 4.2216396275100756, 4.5241352623300983]
    

    Here’s x after you call the function:

    >>> partialdft(x, 0.01, y)
    0.051462873158853464
    >>> x[0:10]
    [0.0, -2.8072359998573911e-13, 1.114040042207106e-12, -2.4744131119314365e-12, 4.316161702819329e-12, -6.5865746141630883e-12, 9.202604511389696e-12, -1.2082375495190468e-11, 1.5129125329320302e-11, -8.1617793532956823e-23]
    

    To avoid overwriting x, make a copy:

    def partialdft(d,step,w):
        i = 0
        x = d[:]
        #...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a simple html file that loads some images from my local hard-drive
I have created simple web service for my website that generates some json based
I created simple Unity application that allows to load different scenes downloaded from internet.
I am new to Repository concept and get some questions. I have created simple
I created a simple detail edit form earlier, and decided to data bind some
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created simple Java class to test file writes from applets: update appeared
I created simple HttpListener that listens to port 9090 and depending on a request's
I have created simple HelloWorld project from Spring MVC template in Spring STS. I
I've created simple Hello world portlet and just added <use-default-template>true</use-default-template> to the portlet section

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.