pwtools.signal.fftsample

pwtools.signal.fftsample(a, b, mode='f', mirr=False)[source]

Convert size and resolution between frequency and time domain.

Convert between maximal frequency to sample (fmax) + desired frequency resolution (df) and the needed number of sample points (N) + time step (dt).

The maximal frequency is also called the Nyquist frequency and is 1/2*samplerate.

Parameters:
  • a (float) –

    mode=’f’: a=fmax b=df
    mode=’t’: a=dt b=N

  • b (float) –

    mode=’f’: a=fmax b=df
    mode=’t’: a=dt b=N

  • mode (string, {'f', 't'}) –

    f : frequency mode
    t : time mode

  • mirr (bool) – consider mirroring of the signal at t=0 before Fourier transform

Returns:

  • mode=’f’ (array([dt, N]))

  • mode=’t’ (array([fmax, df]))

Examples

>>> # fmax = 100 Hz, df = 1 Hz -> you need 200 steps with dt=0.005 sec
>>> fftsample(100, 1, mode='f')
array([  5.00000000e-03,   2.00000000e+03])
>>> fftsample(5e-3, 2e3, mode='t')
array([ 100. ,    1.])
# If you mirror, you only need 100 steps
>>> fftsample(100, 1, mode='f', mirr=True)
array([  5.00000000e-03,   1.00000000e+02])

Notes

These relations hold:

size

resolution

N [t] up

df [f] down

fmax [f] up

dt [t] down

If you know that the signal in the time domain will be mirrored before FFT (N -> 2*N), you will get 1/2*df (double fine resolution), so 1/2*N is sufficient to get the desired df.

Units: In general frequency_unit = 1/time_unit, need not be Hz and s.