python - spectrum analyzer of wave files with numpy.rfft -


i'm writing script process wave file in python , display spectrum analyzer, nice visualization of audio files. after reading of doc , forums assumed needed use rfft.

i'm processing samples of 2048 values, creating 1024 bands in output of rfft. thing needs need reduce number of bands dramatically 12 bands (1 octave). since i'm processing audio files , have limited number of bands wonder if there smart way group frequencies 90% of songs nice low-pitched beats on left , high-pitched voices/shouts/notes on right.

with preliminary code below have more bands need peaks concentrated in low frenquencies songs, except test range 20 20k. range realized higher pitch is, lower amplitude is.

def fft(self, sample_range):     # sample_range sample of 2048 ints read self.file wave file     fft_data = abs(numpy.fft.rfft(sample_range)) # real fft gives samplewidth/2 bands     fft_freq = numpy.fft.rfftfreq(len(sample_range))     freq_hz = [abs(fft_freq[i])*self.file.getframerate() i, fft in enumerate(fft_data)]      print len(zip(freq_hz, fft_data)), len(freq_hz), len(fft_data), zip(freq_hz, fft_data) 

here print output first sample of rampe (~20hz):

1025 1025 1025 [(0.0, 1850501.0), (21.533203125, 2779524.1730200453), (43.06640625, 15469093.29481476), ... (22028.466796875, 3538.1225240980043), (22050.0, 3553.0)] 

so questions are:

  • am doing shouldn't in code hereabove? =)

  • what units spectrum analyzers in music players represent , ranges? should convert amplitudes db?

  • is there simple way reduce number of bands 12? guess bandwidth exponential pitch? need manually implement exponential sum.

edit: i'm summing fft frequencies using reference log-scale generate arbitrary number of bands with:

in [22]: num_bands = 10 in [23]: [44100*2**(b-num_bands) b in range(num_bands)] out[23]: [43.06640625,  86.1328125,  172.265625,  344.53125,  689.0625,  1378.125,  2756.25,  5512.5,  11025.0,  22050.0]  in [24]: num_bands = 12 in [25]: [44100*2**(b-num_bands) b in range(num_bands)] out[25]: [10.7666015625,  21.533203125,  43.06640625,  86.1328125,  172.265625,  344.53125,  689.0625,  1378.125,  2756.25,  5512.5,  11025.0,  22050.0] 

i use these maximum frequencies each band. works until num_bands = 10 maximum. 11 , more start getting low frequencies out of audible range. idea shrink range better this? maximum frequency of first band should @ least 40 hz in case.

yes, spectrum displays convert db (or other log scale).

the simplest way reduce number of bands add adjacent fft result bins in groups per octave (or per half or 12th octave, etc.) of equal ratio between highest , lowest frequency represented each band or group of fft result bins. make ratio-sized groups big or small enough end desired number of total bands.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -