@Franc
, I can see from your question that you are very good at thinking. Let me extend your question
- Why use mel spectrogram?
- Why use filter banks?
I will reply to your question first for reference only.
set sr is samplate, fftLength is singal length,The effective data length after DFT or FFT is fftLength/2+1.
Re:1+2
- Why divide the Hz scale into bins?
- What exactly is meant by a frequency band?
First, bin can be understood as index,
import numpy as np
sr=32000 # samplate
fftLength=4096 # dataLength 0.128ms
freArr=np.linspace(0,sr/2,fftLength/2+1)
freArr is DFT's frequency band,
bin is freArr's index.
Secondly, the first step for mel spectrogram is to calculate mel frequency band, the order is:
hz fmin, fmax ---> mel scale fmin, fmax ---> mel scale freArr ---> hz freArr
import numpy as np
sr=32000 # samplate
fftLength=4096 # dataLength 0.128ms
mel_num=512 # mel number
# fre range
fmin=0 # index/bin=0
fmax=16000 # index/bin=2049
freArr=np.linspace(0,sr/2,fftLength/2+1)
# hz fre ---> mel scale fre
fmin_mel=2595*np.log10(1+ fmin/700);
fmax_mel=2595*np.log10(1+ fmax/700);
# mel scale freArr
freArr_scale=np.linsapce(fmin_mel,fmax_mel,mel_num)
# mel scale freArr ---> mel frequency bands
freArr_mel=700*(np.power(10, freArr_scale/2595)-1)
# Why divide the Hz scale into bins?
I guess your problem may be this. This bin is freArr_mel
corresponds to the closest index of' freArr '. The answer is that it will be used in subsequent business.
Re:3+4
- Why do we apply triangular filters?
- What exactly is a triangular filter? How is it defined mathematically and from what concept?
In the field of digital signal, filter is a basic and important concept. One of the filter design methods is the window function method. Of course, this is not about filter design, but assuming that you have this part of the basis, triangular window function formula is
$N$ is odd,
$\quad w(n)=\begin{cases} \cfrac{2n}{N+1}, & 1 \le n \le \cfrac {N+1}{2} \\ 2-\cfrac{2n}{N+1}, & \cfrac {N+1}2 \le n \le N \end{cases} $
$N$ is even,
$\quad w(n)=\begin{cases} \cfrac{2n-1}N, & 1 \le n \le \cfrac N{2} \\ 2-\cfrac{2n-1}N, & \cfrac{N}2 +1 \le n \le N \end{cases} $
This is what it looks like

Of course, you can not use triangular filter. These window functions, such as hann, hamm, etc, can also be used, even without any filter.
The following is a spectrum comparison diagram of different windows

In the figure, Slaney and ETSI are the renderings of triangular windows. If you are interested in research, you can use python's audioFlux try various contrast effects such as hann, hamm, gauss, etc. mel is a scale of auditory design, and of course there are also scales such as bar/erb/octave, audioFlux include the following types of spectrum.
- linear spectrogram
- mel spectrogram
- bark spectrogram
- erb spectrogram
- octave spectrogram
- log spectrogram