Lgeu wants to merge 1 commit from /u/lgeu/sp-tk/ to master, 2021-07-12
It seems that the filter coefficients lpfcoef.3to2
used in ds
were wrong.
There seemed to be two problems with the old file.
1. the formula for generating the ideal low-pass filter coefficients is incorrect. It seems that 1/2 sinc(n/4) was used, but the correct formula seems to be 2/3 sinc(n/3).
2. the order of the filter is lower than the other files.
As a result, when using ds -s 32
, it seems to produce a cloudier sound than it should.
I used the following Python script to generate the filter coefficients. I have chosen the filter order and window function so that the same method can generate coefficients that are almost identical to lpfcoef.4to3
.
import numpy as np
from scipy import signal
def make_filter_coef(numer, denom, filter_order=409):
if filter_order % 2 == 0:
raise ValueError(f"filter_order should be odd number, got {filter_order}.")
half_filter_order = filter_order // 2
x = np.arange(-half_filter_order, half_filter_order + 1)
filter_coef = np.sinc(x / denom) * (numer / denom)
filter_coef *= signal.kaiser(filter_order, 3 * np.pi)
return filter_coef
print(*make_filter_coef(2, 3), sep="\n")
Thank you for your confirmation.
Thank you for your kind report.
We reviewed the filter coefficients used in
ds
andus
commands. It was found that some of them are wrong. However, the design of new reasonable filter is not trivial problem due to various factors such as ripple, stopband attenuation, signal energy, and anti-aliasing. We decided to temporarily remove-s 32
and-s 74
options fromds
command. We will investigate the suitable design for down/up-sampling.