2

So, I'm wondering how to implement a STFT in Julia, possibly using a Hamming window. I can't find anything on the internet.

What is the best way to do it? I'd prefer not to use Python libraries, but pure native Julia if possible. Maybe it's a feature still being developed in Juila...?

Thanks!

  • 1
    I guess you can just do what it says in the first paragraph of the linked Wikipedia page: take the FFT of sections (windows) of the time series? What does this miss? – David P. Sanders May 16 '16 at 14:19

1 Answers1

6

I'm not aware of any native STFT implementation in Julia. As David stated in his comment, you will have to implement this yourself. This is fairly straightforward:

1) Break up your signal into short time sections

2) Apply your window of choice (in your case, Hamming)

3) Take the FFT using Julia's fft function.

All of the above are fairly standard mathematical operations and you will find a lot of references online. The below code generates a Hamming window if you don't have one already (watch out for Julia's 1-indexing when using online references as a lot of the signal processing reference material likes to use 0-indexing when describing window generation).

Wb = Array(Float64, N)
## Hamming Window Generation
for n in 1:N  
    Wb[n] = 0.54-0.46cos(2pi*(n-1)/N)
end

You could also use the Hamming window function from DSP.jl.

P.S If you are running Julia on OS X, check out the Julia interface to Apple's Accelerate framework. This provides a very fast Hamming window implementation, as well as convolution and elementwise multiplication functions that might be helpful.

hyperdelia
  • 1,105
  • 6
  • 26