Due to the way np.fft.fft works, if you use 1024 data points, you will get values ββfor 512 frequencies (plus a value of 0 Hz, DC bias). If you want only 8 frequencies, you will need to feed 16 data points.
Perhaps you can do what you want by fetching down with a factor of 64 - then 16 remote points will be equivalent to 1024 original points. I have never investigated this, so I donβt know what this entails or what could be a trap.
You will need to learn something - The Guide for Design Engineers and Digital Signal Engineers is indeed an excellent resource for at least that was for me.
Keep in mind that for cw.wav audio content, the sampling frequency is 44100 Hz - 1024 sample fragments are only 23 ms of sound.
scipy.io.wavfile.read makes it easy to get data.
samp_rate, data = scipy.io.wavfile.read(filename)
data is an array with two numbers with one channel in column zero, data [:, 0], and the other in column 1, data [:, 1]
Matplotlib specgram and psd functions can provide you with the data you need. A graphic analogue of what you are trying to do will be.
from matplotlib import pyplot as plt import scipy.io.wavfile samp_rate, data = scipy.io.wavfile.read(filename) Pxx, freqs, bins, im = plt.specgram(data[:1024,0], NFFT = 16, noverlap = 0, Fs = samp_rate) plt.show() plt.close()
Since you are not making any conspiracies, just use matplolib.mlab.specgram .
Pxx, freqs, t = matplolib.mlab.specgram(data[:1024,0], NFFT = 16, noverlap = 0, Fs = samp_rate)
Its return values ββ(Pxx, freqs, t) are equal
- *Pxx*: 2-D array, columns are the periodograms of successive segments - *freqs*: 1-D array of frequencies corresponding to the rows in Pxx - *t*: 1-D array of times corresponding to midpoints of segments.
Pxx[1:, 0] will be the values ββfor the frequencies for T0, Pxx[1:, 1] for T1, Pxx[1:, 2] for T2, ... This is what you would display on your display. You are not using Pxx[0, :] because it is for 0 Hz.
power spectral density - matplotlib.mlab.psd ()
Perhaps another strategy to go into 8 groups would be to use large chunks and normalize the values. Then you can split the values ββinto eight segments and get the sum of each segment. I think this is true - perhaps only for the power spectral density. sklearn.preprocessing.normalize
w = sklearn.preprocessing.normalize(Pxx[1:,:], norm = 'l1', axis = 0)
But then again, I just did it all.