#_test_unitary_rfft_parsevals(x, samp_freq, freq_axis, X)
# remove the phase due to our time shift
- j = _numpy.complex(0.0,1.0) # sqrt(-1)
+ j = _numpy.complex(0.0,1.0) # sqrt(-1)
for i in range(len(freq_axis)):
f = freq_axis[i]
inverse_phase_shift = _numpy.exp(j*2.0*_numpy.pi*time_shift*f)
#_test_unitary_rfft_parsevals(x, samp_freq, freq_axis, X)
# remove the phase due to our time shift
- j = _numpy.complex(0.0,1.0) # sqrt(-1)
+ j = _numpy.complex(0.0,1.0) # sqrt(-1)
for i in range(len(freq_axis)):
f = freq_axis[i]
inverse_phase_shift = _numpy.exp(j*2.0*_numpy.pi*time_shift*f)
# >>> help(numpy.fft.fftpack.rfft) for Numpy's explaination.
# See Numerical Recipies for a details.
trans = _numpy.fft.rfft(data[0:nsamps])
- power = (trans * trans.conj()).real # We want the square of the amplitude.
+ power = (trans * trans.conj()).real # we want the square of the amplitude
return (freq_axis, power)
imax = _numpy.argmax(power)
expected = _numpy.zeros((len(freq_axis),), dtype=_numpy.float)
- df = samp_freq/_numpy.float(samples) # df = 1/T, where T = total_time
+ df = samp_freq/_numpy.float(samples) # df = 1/T, where T = total_time
i = int(sin_freq/df)
# average power per unit time is
# P = <x(t)**2>
raise ValueError(
'chunk_size {} should be a power of 2'.format(chunk_size))
- nchunks = len(data)/chunk_size # integer division = implicit floor
+ nchunks = len(data)/chunk_size # integer division = implicit floor
if overlap:
chunk_step = chunk_size/2
else:
chunk_step = chunk_size
- win = window(chunk_size) # generate a window of the appropriate size
+ win = window(chunk_size) # generate a window of the appropriate size
freq_axis = _numpy.linspace(0, freq/2, chunk_size/2+1)
# nsamps/2+1 b/c zero-freq and nyqist-freq are both fully real.
# >>> help(numpy.fft.fftpack.rfft) for Numpy's explaination.
imax = _numpy.argmax(power)
expected = _numpy.zeros((len(freq_axis),), dtype=_numpy.float)
- df = samp_freq/_numpy.float(chunk_size) # df = 1/T, where T = total_time
+ df = samp_freq/_numpy.float(chunk_size) # df = 1/T, where T = total_time
i = int(sin_freq/df)
- expected[i] = 0.5 / df # see _test_unitary_power_spectrum_sin()
+ expected[i] = 0.5 / df # see _test_unitary_power_spectrum_sin()
print('The power should peak at {} Hz of {} ({}, {})'.format(
sin_freq, expected[i], freq_axis[imax], power[imax]))