equivalent to numpy's fftfreq

399 views
Skip to first unread message

Andrei Berceanu

unread,
Jul 2, 2014, 9:28:18 AM7/2/14
to julia...@googlegroups.com
I have written the following function to provide the same functionality as numpy's fftfreq (http://docs.scipy.org/doc/numpy/reference/generated/numpy.fft.fftfreq.html)

```
function fftfreq(n::Int64, d::Float64)
  N = fld(n-1,2)
  p1 = [0:N]
  p2 = [-fld(n,2):-1]
  return [p1, p2]/(d*n)
end
```

From the response on https://github.com/JuliaLang/julia/issues/7317, I understand that such a function is already implemented in the DSP.jl package, perhaps using the immutable Frequencies?
I am not quite sure how to use that though, could anyone please provide a concrete example which reproduces the use of fftfreq? Tnx!

João Felipe Santos

unread,
Jul 2, 2014, 11:01:01 AM7/2/14
to julia...@googlegroups.com
Hi Andrei,

you can use fftfreq in DSP.jl. The syntax is exactly the same as for your function: http://dspjl.readthedocs.org/en/latest/util.html#fftfreq.

Best

--
João Felipe Santos

Andrei Berceanu

unread,
Jul 2, 2014, 1:38:35 PM7/2/14
to julia...@googlegroups.com
Ok, tnx :)
But now `fftshift`, which before used to work, gives:

> fftshift(DSP.fftfreq(10))
type: circshift: in typeassert, expected Frequencies, got Array{Float64,1}

in circshift at abstractarray.jl:417
 in fftshift at dsp.jl:145

João Felipe Santos

unread,
Jul 2, 2014, 2:33:15 PM7/2/14
to julia...@googlegroups.com
Oh, we will need a different implementation to support arrays as well as the Frequencies abstract array. Thanks for reporting this issue, by the way!

--
João Felipe Santos
Reply all
Reply to author
Forward
0 new messages