The following notebook demonstrates frequency spectra of all filters wrapped in a MelFilterBank.

We start off with our usual imports:


In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

The following hack won't be necessary after a proper release is made.


In [2]:
import sys
sys.path.append('..')
from dspy.filters import MelFilterBank

Let's set sample frequency (in Hz) and the size of data frames with which the filter bank would work.


In [3]:
sample_frequency = 44100
size = 4096
filter_bank = MelFilterBank(sample_frequency, size)

We can inspect frequency bands for each filter in linear scale:


In [4]:
for i, mel_filter in enumerate(filter_bank.filters):
    print '%2d:  %7.2f - %7.2f - %7.2f' % (i, mel_filter.min_freq, mel_filter.center_freq, mel_filter.max_freq)


 0:     0.00 -   64.95 -  135.93
 1:    64.95 -  135.93 -  213.49
 2:   135.93 -  213.49 -  298.25
 3:   213.49 -  298.25 -  390.87
 4:   298.25 -  390.87 -  492.09
 5:   390.87 -  492.09 -  602.70
 6:   492.09 -  602.70 -  723.57
 7:   602.70 -  723.57 -  855.66
 8:   723.57 -  855.66 - 1000.00
 9:   855.66 - 1000.00 - 1157.74
10:  1000.00 - 1157.74 - 1330.11
11:  1157.74 - 1330.11 - 1518.47
12:  1330.11 - 1518.47 - 1724.32
13:  1518.47 - 1724.32 - 1949.26
14:  1724.32 - 1949.26 - 2195.07
15:  1949.26 - 2195.07 - 2463.69
16:  2195.07 - 2463.69 - 2757.24
17:  2463.69 - 2757.24 - 3078.02
18:  2757.24 - 3078.02 - 3428.57
19:  3078.02 - 3428.57 - 3811.64
20:  3428.57 - 3811.64 - 4230.26
21:  3811.64 - 4230.26 - 4687.72
22:  4230.26 - 4687.72 - 5187.63
23:  4687.72 - 5187.63 - 5733.91

Let's see that on a plot.


In [5]:
frequencies = np.linspace(0, sample_frequency, size, endpoint=False)
for mel_filter in filter_bank.filters:
    plt.plot(frequencies, mel_filter.spectrum)
plt.xlim([0, filter_bank.filters[-1].max_freq])
plt.xlabel('Frequency (linear scale)')
plt.ylabel('Filter spectrum magnitude')
plt.title('Mel filter spectra')
plt.show()



In [ ]:


In [ ]: