2020/06/25

STOI Code Test for Matlab and Python

(這篇文章主要是在測試Matlab和Python兩個版本程式所計算出的STOI值是否有差異)
STOI (Short-time objective intelligibility) is a prediction metric useful to replace previous objective prediction measures.

I tried to check if the Matlab and Python versions of STOI codes work equally with the identical output scores.

The Matlab code is available from Cees Taal's web site.

The python version is available from Pariente Manuel's GitHub.

The same processed wav file and reference wav file are tested using Matlab and Python.

The Python version needs a few configurations.

Create minicoda environments
conda create -n py38_STOI python=3.8 pytorch
conda activate py38_STOI

Install sound packages
pip install SoundFile
conda install -c conda-forge librosa

Run the python file.
python STOI_test.py

where the STOI_test.py is modified from Pariente Manuel's GitHub:

import soundfile as sf
from pystoi import stoi #or use from pystoi.stoi import stoi

clean, fs = sf.read('my_clean.wav')
denoised, fs = sf.read('my_processed.wav')

# Clean and den should have the same length, and be 1D
d = stoi(clean, denoised, fs, extended=False)
print(d)

And the result is


0.8157936197843473


The result of Matlab version is

>> d = stoi(y_my_clean, y_my_processed, fs)
d =
    0.8158

The results are similar, but there is still a tiny difference when showing more decimal points using digits() and vpa() commands.

>> digits(16)
>> vpa(d)
ans =
0.8157974711433416

The difference between Matlab and Python versions is small than 0.00001 and hence can be ignored.

References:

Cees Taal's web site
Pariente Manuel's GitHub

Matlab: Show more decimal points for a variable

To show more digits with Matlab, use digits() and vpa()

>> a = 1/3

a =

    0.3333

>> digits(6)
>> vpa(a)

ans =

0.333333

>> digits(10)
>> vpa(a)

ans =

0.3333333333

Reference:

digits (MathWorks)

2020/06/13

Matlab: Log function with base 10

For the logarithmic function with base 10, simply use log10:

>> log10(100)

ans =

     2

>> 10*log10(0.1)

ans =

   -10

>> 20*log10(1000)

ans =

    60

>>