Giter Site home page Giter Site logo

nim-fftr's People

Contributors

arnetheduck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

angelezquerra

nim-fftr's Issues

Inverse FFT seems need divider the FFT points

fftr is an very handy library. I am porting some code from numpy to nim and utilize the fftr libaray.
Forward FFT works well, but IFFT seems not match with numpy.fft.ifft.

After divider fftr result with FFT points, they are match again.

fft(some_complex_seq ,true)/fft_num_of_points => this match with numpy.fft.ifft

Example code fails to compile

Code

import fftr, std/math, std/sequtils

let
  signal = (0..1023).mapIt(complex64(sin(TAU * 0.1 * float64(it))))
  freqs = fft(tmp, false) # False for forward, true for inverse FFT

Error message

Hint: used config file '/home/anon/.choosenim/toolchains/nim-2.0.2/config/nim.cfg' [Conf]
Hint: used config file '/home/anon/.choosenim/toolchains/nim-2.0.2/config/config.nims' [Conf]
......................................................................
/home/anon/Documents/ProgrammingLearning/nim/FFT/fftr.nim(1, 8) Error: module 'fftr' cannot import itself
System Info
--------
OS: Arch Linux x86_64
Host: Oryx Pro (oryp8)
Kernel: 6.6.10-arch1-1
Shell: bash 5.2.21
DE: KDE Plasma 5.27.10
WM: KWin (Wayland)
WM Theme: Breeze
CPU: 11th Gen Intel(R) Core(TM) i7-11800H (16) @ 4.60 GHz
GPU 1: Intel UHD Graphics
GPU 2: NVIDIA GeForce RTX 3070 Mobile / Max-Q
Memory:  31.20 GiB

I am not entirely sure why I am getting the import error message. I installed the package using Nimble.

SciPy example

Testing out your code with a SciPy example and I am getting the incorrect inverse. Am I doing something wrong?

SciPy:

>>> from scipy.fft import fft, ifft
>>> import numpy as np
>>> x = np.array([1.0, 2.0, 1.0, -1.0, 1.5])
>>> y = fft(x)
>>> y
array([ 4.5       +0.j        ,  2.08155948-1.65109876j,
       -1.83155948+1.60822041j, -1.83155948-1.60822041j,
        2.08155948+1.65109876j])
>>> yinv = ifft(y)
>>> yinv
array([ 1.0+0.j,  2.0+0.j,  1.0+0.j, -1.0+0.j,  1.5+0.j])

My example:

let input = @[complex64(1.0, 0.0), complex64(2.0, 0.0), complex64(1.0, 0.0), complex64(-1.0, 0.0), complex64(1.5, 0.0)]
let output = fft(input, false)
echo output

let iOutput = fft(output, true)
echo iOutput

Results in:

@[(4.5, -3.608224830031759e-16), (2.081559480312316, -1.651098762732523), (-1.831559480312317, 1.60822040644407), (-1.831559480312316, -1.60822040644407), (2.081559480312317, 1.651098762732523)]

@[(5.0, -8.881784197001252e-16), (10.0, -1.77635683940025e-15), (4.999999999999999, -4.440892098500626e-16), (-4.999999999999999, 8.881784197001252e-16), (7.5, 0.0)]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.