# How is the Stockwell Transform frequency resolution determined?

**URL:** <https://mne.discourse.group/t/how-is-the-stockwell-transform-frequency-resolution-determined/4193>\
**Category:** Support & Discussions\
**Tags:** eeg\
**Created:** [December 24, 2021, 6:34pm UTC](https://mne.discourse.group/t/how-is-the-stockwell-transform-frequency-resolution-determined/4193 "2021-12-24T18:34:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulF](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@PaulF](https://mne.discourse.group/u/PaulF)\
**Post date:** [December 24, 2021, 6:34pm UTC](https://mne.discourse.group/t/how-is-the-stockwell-transform-frequency-resolution-determined/4193/1 "2021-12-24T18:34:51Z")

</div>

- MNE 0.24.0
- Mac 11.6.1

I’m trying to understand how frequency bins are determined for the stockwell transform of an array. As a simple example, I’m computing it for a 5-second chirp signal with sampling frequency 1000 hz, which starts at 50 hz and ends at 400 hz, increasing in a linear manner.

My code so far:

```
 import numpy as np
 from scipy.signal import chirp
 from mne.time_frequency import tfr_array_stockwell as stockwell

 fs=1000
 L= 5000 #signal length in ms.
 t=np.arange(0,L/1000,1/fs)
 w=chirp(t, f0=5, f1=400, t1=5, method='linear') # 5000 samples in signal

 w1=np.expand_dims(w,axis=(0,1)) # change to 1 epoch -by -1 channel -by- 5000
 fmin = 0  
 fmax = 25  

 S, itc, freqs=stockwell(w1,fs,fmin=fmin,fmax=fmax)

```

In this case freqs contains frequencies that start at fmin=0 and end at fmax=25 with 205 bins.

It’s not clear to me how the number of bins is determined using the values chosen above. Is there an easy way to see this without diving into all the source code for the `stockwell` command?

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [December 25, 2021, 3:20pm UTC](https://mne.discourse.group/t/how-is-the-stockwell-transform-frequency-resolution-determined/4193/2 "2021-12-25T15:20:35Z")

</div>

see n\_fft parameter. it’s what determines the delta frequency (frequency resolution)

```python
import numpy as np
from scipy.signal import chirp
from mne.time_frequency import tfr_array_stockwell as stockwell

fs = 1000
L = 2**12 # signal length in ms.
n_fft = L
t = np.arange(0, L) / fs
w = chirp(t, f0=5, f1=400, t1=5, method="linear") # 5000 samples in signal

# w1 = np.expand_dims(w, axis=(0, 1)) # change to 1 epoch -by -1 channel -by- 5000
w1 = w[np.newaxis, np.newaxis, :]
fmin = 0
fmax = 25

S, itc, freqs = stockwell(w1, fs, fmin=fmin, fmax=fmax, n_fft=n_fft)

delta_freq = np.mean(np.diff(freqs))
print(delta_freq)
print(fs / n_fft)

```

HTH  
Alex

---

<div class="post-metadata">

**Author:** ![PaulF](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@PaulF](https://mne.discourse.group/u/PaulF)\
**Post date:** [December 30, 2021, 1:31pm UTC](https://mne.discourse.group/t/how-is-the-stockwell-transform-frequency-resolution-determined/4193/3 "2021-12-30T13:31:53Z")

</div>

Yes–this is very helpful. Thanks!
