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

  • Home
  • SEARCH
  • 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 9229465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:34:43+00:00 2026-06-18T05:34:43+00:00

I’ve written a python code to take a 2D signal and FFT it, and

  • 0

I’ve written a python code to take a 2D signal and FFT it, and now I want to extract the frequencies associated with the FFT. The np.fft.fftfreq fails, giving me the error

File "/usr/lib64/python2.7/site-packages/numpy/fft/helper.py", line 153, in fftfreq
    assert isinstance(n,types.IntType) or isinstance(n, integer)
AssertionError

My code is :

import numpy as np
import scipy as sp
import pylab
import sys
import math

filename = sys.argv[1]  # Get name of file to open 

ifp = open(filename, "r")
ifp.seek(0)

nrows = 0
ncols = 0

nrows = sum(1 for line in ifp) # Sum over all the lines in the file ptr

ifp.seek(0) # Set the fptr back to beginning of file
for line in ifp:
   ncols = len(line.split()) #Split and count number of words in a line
   if ncols > 0:
      break

OrigData = np.zeros([nrows, ncols], dtype=np.float32) #Allocate numpy array
FFTData = np.zeros([nrows, ncols], dtype=complex)
IFFTData = np.zeros([nrows, ncols], dtype=complex)
FreqComp = np.zeros([nrows, ncols], dtype=np.float32)

ii = 0
jj = 0
ifp.seek(0)
for line in ifp:
   linedata = line.split()
   jj = 0
   for el in linedata:
      OrigData[ii,jj] = float(el)
      jj+=1
   ii+=1
ifp.close()

FFTData = np.fft.fft2(OrigData)
FreqComp = np.fft.fftfreq(FFTData, d=2)

#--- Continue with more code ---#

I know that everything else works except the np.fft.fftfreq line, because I added that in last. How does one extract 2 dimensional frequency components?

  • 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-18T05:34:44+00:00Added an answer on June 18, 2026 at 5:34 am

    You are passing in an invalid parameter: np.fft.fftfreq takes the size of the signal data as first parameter (an integer) and the timestep as the second parameter. You are passing in an array as the first parameter.

    You need to perform an np.fft.fft on the signal first though.

    Hate to point out the obvious, but read np.fft.fftfreq… the example code is very pretty clear.


    Having performed a 2D FFT, you can obtain the sample frequencies along each dimension as follows:

    FreqCompRows = np.fft.fftfreq(FFTData.shape[0],d=2)
    FreqCompCols = np.fft.fftfreq(FFTData.shape[1],d=2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I want to show the soap response to UIWebview.. my soap response is, <p><img

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.