Compute the Discrete Cosine Transform (DCT) basis matrix. Args: dct_filter_num: The number of DCT filters to generate. filter_num: The number of the fbank filters. Returns: The DCT basis matrix. Examples: >>> float(round(discrete_cosine_transform(3, 5)
(dct_filter_num: int, filter_num: int)
| 428 | |
| 429 | |
| 430 | def discrete_cosine_transform(dct_filter_num: int, filter_num: int) -> np.ndarray: |
| 431 | """ |
| 432 | Compute the Discrete Cosine Transform (DCT) basis matrix. |
| 433 | |
| 434 | Args: |
| 435 | dct_filter_num: The number of DCT filters to generate. |
| 436 | filter_num: The number of the fbank filters. |
| 437 | |
| 438 | Returns: |
| 439 | The DCT basis matrix. |
| 440 | |
| 441 | Examples: |
| 442 | >>> float(round(discrete_cosine_transform(3, 5)[0][0], 5)) |
| 443 | 0.44721 |
| 444 | """ |
| 445 | basis = np.empty((dct_filter_num, filter_num)) |
| 446 | basis[0, :] = 1.0 / np.sqrt(filter_num) |
| 447 | |
| 448 | samples = np.arange(1, 2 * filter_num, 2) * np.pi / (2.0 * filter_num) |
| 449 | |
| 450 | for i in range(1, dct_filter_num): |
| 451 | basis[i, :] = np.cos(i * samples) * np.sqrt(2.0 / filter_num) |
| 452 | |
| 453 | return basis |
| 454 | |
| 455 | |
| 456 | def example(wav_file_path: str = "./path-to-file/sample.wav") -> np.ndarray: |