<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Real-Time Audio Noise Suppression: From DSP to DeepFilterNet</title>
 <link href="https://audio-processing-self-learning.pages.dev/atom.xml" rel="self"/>
 <link href="https://audio-processing-self-learning.pages.dev/"/>
 <updated>2026-12-05T04:02:45+00:00</updated>
 <id>https://audio-processing-self-learning.pages.dev</id>
 <author>
   <name>Nguyen Le Linh</name>
   <email>nglelinh@gmail.com</email>
 </author>

 
 <entry>
   <title>author-details</title>
   <link href="https://audio-processing-self-learning.pages.dev/home/author-details/"/>
   <updated>2021-05-20T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/home/author-details</id>
   <content type="html">&lt;h3 id=&quot;nguyen-le-linh&quot;&gt;Nguyen Le Linh&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Email: nglelinh@gmail.com&lt;/li&gt;
  &lt;li&gt;GitHub: https://github.com/nglelinh&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For technical issues, open a GitHub issue on &lt;a href=&quot;https://github.com/nglelinh/audio-noise-suppression-self-learning&quot;&gt;audio-noise-suppression-self-learning&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>reference</title>
   <link href="https://audio-processing-self-learning.pages.dev/reference/26_reference/"/>
   <updated>2021-03-28T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/reference/26_reference</id>
   <content type="html">&lt;h1 id=&quot;references-and-resources&quot;&gt;References and Resources&lt;/h1&gt;

&lt;p&gt;This page contains references and resources for the course. Add your own references as needed.&lt;/p&gt;

&lt;h2 id=&quot;textbooks&quot;&gt;Textbooks&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Author, A. (Year). &lt;em&gt;&lt;a href=&quot;https://example.com&quot;&gt;Book Title&lt;/a&gt;&lt;/em&gt;. Publisher.&lt;/li&gt;
  &lt;li&gt;Author, B. (Year). &lt;em&gt;&lt;a href=&quot;https://example.com&quot;&gt;Another Book Title&lt;/a&gt;&lt;/em&gt;. Publisher.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;online-courses-and-lectures&quot;&gt;Online Courses and Lectures&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Instructor, C. (Year). &lt;em&gt;&lt;a href=&quot;https://example.com&quot;&gt;Course Title&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;University. &lt;em&gt;&lt;a href=&quot;https://example.com&quot;&gt;Lecture Series&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;papers-and-articles&quot;&gt;Papers and Articles&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Author, D. et al. (Year). &lt;em&gt;&lt;a href=&quot;https://example.com&quot;&gt;Paper Title&lt;/a&gt;&lt;/em&gt;. Journal Name, Vol. X, pp. XXX-XXX.&lt;/li&gt;
  &lt;li&gt;Author, E. (Year). &lt;em&gt;&lt;a href=&quot;https://example.com&quot;&gt;Article Title&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;online-resources&quot;&gt;Online Resources&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Wikipedia. &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Topic&quot;&gt;Topic Name&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Documentation. &lt;em&gt;&lt;a href=&quot;https://example.com&quot;&gt;Tool/Library Name&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;additional-materials&quot;&gt;Additional Materials&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Author, F. (Year). &lt;em&gt;&lt;a href=&quot;https://example.com&quot;&gt;Tutorial/Guide Title&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Organization. &lt;em&gt;&lt;a href=&quot;https://example.com&quot;&gt;Resource Name&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Replace these placeholder references with actual references relevant to your course content.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>makers</title>
   <link href="https://audio-processing-self-learning.pages.dev/home/makers/"/>
   <updated>2021-02-03T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/home/makers</id>
   <content type="html">&lt;h1 id=&quot;course-creators&quot;&gt;Course creators&lt;/h1&gt;

&lt;h2 id=&quot;lead-instructor&quot;&gt;Lead instructor&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Nguyen Le Linh&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Email: nglelinh@gmail.com&lt;/li&gt;
  &lt;li&gt;GitHub: https://github.com/nglelinh&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Builds bilingual self-learning courses for Vietnamese engineers and connects them to production systems (including Mezon realtime noise suppression).&lt;/p&gt;

&lt;h2 id=&quot;acknowledgments&quot;&gt;Acknowledgments&lt;/h2&gt;

&lt;p&gt;Jekyll multilingual scaffolding follows the course-self-learning template lineage. Product examples reference the public Mezon NS repository without modifying it from this course.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Conventions</title>
   <link href="https://audio-processing-self-learning.pages.dev/contribution/conventions/"/>
   <updated>2021-02-03T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contribution/conventions</id>
   <content type="html">&lt;h2 id=&quot;1-directory-convention&quot;&gt;1. Directory Convention&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Main content lives under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;contents/{lang}/chapterXX/&lt;/code&gt; (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;contents/en/chapter01/&lt;/code&gt;). Images go in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/chapter_img/&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;A typical chapter directory looks like this:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;contents/
├── en/
│   └── chapter01/
│       ├── _posts/
│       │   ├── 21-01-07-01_00_Introduction.md
│       │   ├── 21-01-07-01_01_optimization_problems.md
│       │   └── ...
│       └── index.html
└── vi/
    └── chapter01/
        ├── _posts/
        └── index.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Jekyll treats Markdown or HTML files inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_posts&lt;/code&gt; as blog posts. To add a new post, create a file in the chapter’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_posts/&lt;/code&gt; directory.&lt;/li&gt;
  &lt;li&gt;Post filenames must follow this naming convention:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;YYYY-MM-DD-post_name.md&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Files outside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;contents/&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/&lt;/code&gt; are site configuration. For stability, open an issue instead of editing config directly (config changes can make PR merges difficult).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-posting-convention&quot;&gt;2. Posting Convention&lt;/h2&gt;

&lt;h3 id=&quot;21-header-fields&quot;&gt;2.1. Header Fields&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Every post must include front matter like this:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;---
layout: post
title: Quasi-Newton Methods
chapter: &quot;18&quot;
order: 1
owner: &quot;Your Name&quot;
lang: en
categories:
- chapter18
lesson_type: required
---
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;layout&lt;/strong&gt; must be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;post&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;title&lt;/strong&gt; can be any descriptive string.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;chapter&lt;/strong&gt; is the two-digit chapter number as a string (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;01&quot;&lt;/code&gt; for chapter 1).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;order&lt;/strong&gt; controls sort order within the chapter and prev/next navigation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;owner&lt;/strong&gt; is the post maintainer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;lang&lt;/strong&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;en&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vi&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;categories&lt;/strong&gt; must match the chapter directory name (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chapter18&lt;/code&gt;).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;lesson_type&lt;/strong&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;required&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;optional&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;22-latex&quot;&gt;2.2. LaTeX&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Write formulas using LaTeX syntax.&lt;/li&gt;
  &lt;li&gt;Use double dollar signs (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$$&lt;/code&gt;) to mark math.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$$\theta x_1 + (1-\theta)x_2 \in C$$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;renders as:&lt;/p&gt;

\[\theta x_1 + (1-\theta)x_2 \in C\]

&lt;h3 id=&quot;23-image-convention&quot;&gt;2.3. Image Convention&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;When inserting images in a post, use this format:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;figure class=&quot;image&quot; style=&quot;align: center;&quot;&amp;gt;
&amp;lt;p align=&quot;center&quot;&amp;gt;
  &amp;lt;img src=&quot;{image_path}&quot; alt=&quot;{description of image}&quot; width=&quot;{scale_ratio}%&quot; height=&quot;{scale_ratio}%&quot;&amp;gt;
  &amp;lt;figcaption style=&quot;text-align: center;&quot;&amp;gt;{figcaption}&amp;lt;/figcaption&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;/figure&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;The figure class must be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;image&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{}&lt;/code&gt; placeholders with appropriate values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alternatively, use markdown with the site image URL:&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;![&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Alt text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;/img/chapter_img/your-image.png&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;24-hyperlink-convention&quot;&gt;2.4 Hyperlink Convention&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;For links to other posts in this site, use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;multilang_post_url&lt;/code&gt; tag. Example:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[Your Post Title](#post-not-found)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;For external URLs:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[External Link](&amp;lt;https://example.com&amp;gt;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;3-github-convention&quot;&gt;3. GitHub Convention&lt;/h2&gt;

&lt;p&gt;If you have questions or find something to fix, use one of these:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Leave a comment on the post&lt;/li&gt;
  &lt;li&gt;Open an issue in the repository&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To add or edit content, create a new branch, make your changes, then open a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pull Request&lt;/code&gt;. Anyone can contribute new or updated content.&lt;/p&gt;

&lt;h3 id=&quot;31-repository-policy&quot;&gt;3.1. Repository Policy&lt;/h3&gt;

&lt;p&gt;Merging into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt; requires approval from at least one reviewer. If CODEOWNERS is configured, chapter reviewers are assigned automatically.&lt;/p&gt;

&lt;h3 id=&quot;32-branch-naming-convention&quot;&gt;3.2. Branch Naming Convention&lt;/h3&gt;

&lt;p&gt;Name branches using this pattern:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[feature|bugfix]/[chapter**|settings]-change-description
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Use two prefixes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;feature&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Migration work&lt;/li&gt;
      &lt;li&gt;Changes to text, formulas, or images&lt;/li&gt;
      &lt;li&gt;New content&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;bugfix&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Typo fixes&lt;/li&gt;
      &lt;li&gt;Broken LaTeX rendering&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feature/chapter01-migration&lt;/code&gt;: chapter01 migration&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feature/chapter01-fix-formula&lt;/code&gt;: update formula in chapter01&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feature/settings-update-branch-convention&lt;/code&gt;: update conventions&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bugfix/chapter01-fix-typo&lt;/code&gt;: fix typo in chapter01&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>how to contribute</title>
   <link href="https://audio-processing-self-learning.pages.dev/home/link_to_how_to_contribute/"/>
   <updated>2021-01-27T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/home/link_to_how_to_contribute</id>
   <content type="html">&lt;h1 id=&quot;how-to-contribute&quot;&gt;How to Contribute&lt;/h1&gt;

&lt;p&gt;We welcome contributions from the community! Whether you want to fix a typo, add an example, or contribute a whole new chapter, your help is appreciated.&lt;/p&gt;

&lt;h2 id=&quot;ways-to-contribute&quot;&gt;Ways to Contribute&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Fix errors&lt;/strong&gt;: Found a typo or mistake? Submit a fix!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Add examples&lt;/strong&gt;: Share practical examples or exercises&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Improve explanations&lt;/strong&gt;: Make concepts clearer&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Translate content&lt;/strong&gt;: Help make the course available in more languages&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Add resources&lt;/strong&gt;: Suggest additional reading materials or tools&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;getting-started&quot;&gt;Getting Started&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fork the repository&lt;/strong&gt; on GitHub&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Clone your fork&lt;/strong&gt; to your local machine&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Create a new branch&lt;/strong&gt; for your changes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Make your changes&lt;/strong&gt; following our style guide&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test your changes&lt;/strong&gt; locally&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Submit a pull request&lt;/strong&gt; with a clear description&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;style-guidelines&quot;&gt;Style Guidelines&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Use clear, concise language&lt;/li&gt;
  &lt;li&gt;Follow the existing formatting conventions&lt;/li&gt;
  &lt;li&gt;Include examples where appropriate&lt;/li&gt;
  &lt;li&gt;Test all code snippets&lt;/li&gt;
  &lt;li&gt;Use proper LaTeX formatting for mathematical expressions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;questions&quot;&gt;Questions?&lt;/h2&gt;

&lt;p&gt;If you have questions about contributing, please:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Check our &lt;a href=&quot;/contribution/how_to_contribute/&quot;&gt;Contributing Guide&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Open an issue on GitHub&lt;/li&gt;
  &lt;li&gt;Contact the course maintainers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you for helping improve this course!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Initial Settings</title>
   <link href="https://audio-processing-self-learning.pages.dev/contribution/initial_settings/"/>
   <updated>2021-01-27T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contribution/initial_settings</id>
   <content type="html">&lt;p&gt;The contents of this repository are hosted as a &lt;a href=&quot;https://convex-optimization-for-all.github.io/&quot;&gt;Github Blog&lt;/a&gt; using Jekyll.
Therefore, to edit existing content or create new content, you must follow Jekyll’s directory structure and content writing conventions.
Additionally, you need to verify that changes are properly reflected in your local environment (your current computer) through a web browser.&lt;/p&gt;

&lt;p&gt;We have compiled environment setup instructions for those who are not familiar with GitHub or Jekyll.
If you have difficulties following the guide, please leave an &lt;a href=&quot;https://github.com/convex-optimization-for-all/convex-optimization-for-all.github.io/issues&quot;&gt;issue&lt;/a&gt; in the repository or contact us via the email below for assistance.&lt;/p&gt;

&lt;p&gt;(Kyeongmin Woo, wgm0601@gmail.com)&lt;/p&gt;

&lt;h2 id=&quot;1-git-installation&quot;&gt;1. Git Installation&lt;/h2&gt;

&lt;p&gt;All work management for this blog is performed through Git and GitHub. Please visit the website below to install Git.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://git-scm.com/downloads&quot;&gt;https://git-scm.com/downloads&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;2-downloading-the-repository&quot;&gt;2. Downloading the Repository&lt;/h2&gt;

&lt;p&gt;To modify the blog, enter the following command in the terminal to download the blog’s source code.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/convex-optimization-for-all/convex-optimization-for-all.github.io.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;3-local-hosting&quot;&gt;3. Local Hosting&lt;/h2&gt;

&lt;p&gt;Before applying changed or modified content to the blog, you must verify that the work has been performed as intended through local hosting.
If you merge work content that does not follow Jekyll’s required conventions into the repository, the blog hosted on the actual web may not function properly.
For local hosting setup, you can choose between two methods: using a virtual environment (Docker) (Option 1) or directly installing the Jekyll environment locally (Option 2).
After completing the local hosting setup and running the local server, you can check your blog content through the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.0.0.1:4000&lt;/code&gt; address in your web browser.&lt;/p&gt;

&lt;h3 id=&quot;3-1-option-1-docker-installation&quot;&gt;3-1. (Option 1) Docker Installation&lt;/h3&gt;

&lt;h3 id=&quot;a-docker-installation&quot;&gt;A. Docker Installation&lt;/h3&gt;

&lt;p&gt;Using Docker enables local hosting without direct environment installation on your local machine.
Please visit the website below to install Docker.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.docker.com/get-docker/&quot;&gt;https://docs.docker.com/get-docker/&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;b-local-hosting&quot;&gt;B. Local Hosting&lt;/h3&gt;

&lt;p&gt;Enter the following command in the terminal.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker-compose up
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-2-option-2-jekyll-environment-installation&quot;&gt;3-2. (Option 2) Jekyll Environment Installation&lt;/h3&gt;

&lt;h3 id=&quot;a-jekyll-and-ruby-package-installation&quot;&gt;A. Jekyll and Ruby Package Installation&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://jekyllrb.com/docs/installation/&quot;&gt;Installing Ruby&lt;/a&gt;: Jekyll is built with Ruby. Therefore, you need to install Ruby to use Jekyll.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://jekyllrb.com/docs/&quot;&gt;Installing Jekyll&lt;/a&gt;: Once Ruby is installed, enter the cloned repository and install Jekyll.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://jekyllrb.com/docs/&quot;&gt;Installing Bundle Gem&lt;/a&gt;: You need to additionally install Ruby packages required for hosting. Run the following command in the repository’s project directory.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;bundle &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;b-local-hosting-1&quot;&gt;B. Local Hosting&lt;/h3&gt;

&lt;p&gt;Enter the following command in the terminal.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If hosting doesn’t work, you can also try the following command.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ bundle exec jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If both commands don’t work, the Jekyll environment has not been properly installed.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>How to Contribute</title>
   <link href="https://audio-processing-self-learning.pages.dev/contribution/how_to_contribute/"/>
   <updated>2021-01-27T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contribution/how_to_contribute</id>
   <content type="html">&lt;hr /&gt;

&lt;h2 id=&quot;1-editing-content-directly&quot;&gt;1. Editing Content Directly&lt;/h2&gt;

&lt;h3 id=&quot;1-open-your-local-repository-directory-if-you-do-not-have-a-local-copy-yet-see-initial-settings&quot;&gt;(1) Open your local repository directory. If you do not have a local copy yet, see &lt;a href=&quot;/contribution/2021/01/27/initial_settings/&quot;&gt;Initial Settings&lt;/a&gt;.&lt;/h3&gt;

&lt;h3 id=&quot;2-sync-with-the-remote-repository&quot;&gt;(2) Sync with the remote repository.&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout main
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git pull &lt;span class=&quot;nt&quot;&gt;--all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-create-a-new-branch-for-your-changes-use-prefixchapterreason-see-branch-naming-convention-example&quot;&gt;(3) Create a new branch for your changes. Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[prefix]/[chapter]/[reason]&lt;/code&gt; (see &lt;a href=&quot;/contribution/2021/02/03/conventions/&quot;&gt;Branch Naming Convention&lt;/a&gt;). Example:&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout &lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; bugfix/chapter01-fix-typo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;4-edit-files-follow-the-conventions-when-creating-or-updating-content&quot;&gt;(4) Edit files. Follow the &lt;a href=&quot;/contribution/2021/02/03/conventions/&quot;&gt;Conventions&lt;/a&gt; when creating or updating content.&lt;/h3&gt;

&lt;h3 id=&quot;5-push-to-the-remote-example&quot;&gt;(5) Push to the remote. Example:&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git push origin bugfix/chapter01-fix-typo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;6-open-a-pull-request-to-main-on-github-see-github-docs-for-details&quot;&gt;(6) Open a Pull Request to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt; on GitHub. See GitHub Docs for details:&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request&quot;&gt;Creating a pull request&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;2-requesting-content-changes&quot;&gt;2. Requesting Content Changes&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;You can open an &lt;a href=&quot;https://github.com/your-username/your-repo-name/issues&quot;&gt;Issue&lt;/a&gt; on the GitHub repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;
</content>
 </entry>
 
 <entry>
   <title>introduction</title>
   <link href="https://audio-processing-self-learning.pages.dev/home/introduction/"/>
   <updated>2021-01-20T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/home/introduction</id>
   <content type="html">&lt;h1 id=&quot;welcome--real-time-audio-noise-suppression&quot;&gt;Welcome — Real-Time Audio Noise Suppression&lt;/h1&gt;

&lt;p&gt;This bilingual course takes you from first-principles DSP to shipping neural noise suppression in real-time call stacks. The intended audience is Vietnamese software engineers who already write code and want a rigorous, product-aware path into speech enhancement.&lt;/p&gt;

&lt;h2 id=&quot;what-you-will-learn&quot;&gt;What you will learn&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Frame-based audio processing, STFT/ISTFT, and latency budgets.&lt;/li&gt;
  &lt;li&gt;Classical NS ideas still used as front-ends or fallbacks.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet-style deep filtering and how it differs from magnitude masks.&lt;/li&gt;
  &lt;li&gt;Real-time and on-device constraints (RTF, AudioWorklet, ORT/WASM).&lt;/li&gt;
  &lt;li&gt;Integration patterns with WebRTC and LiveKit.&lt;/li&gt;
  &lt;li&gt;Honest evaluation (SI-SDR, DNSMOS, listening).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;capstone-context&quot;&gt;Capstone context&lt;/h2&gt;

&lt;p&gt;Work is aligned with &lt;strong&gt;Mezon&lt;/strong&gt; noise suppression: GitHub &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt;, npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;. You will learn the techniques behind the product — not only how to call the package.&lt;/p&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Comfortable with TypeScript/JavaScript or similar; willingness to read short Python/Rust snippets.&lt;/li&gt;
  &lt;li&gt;No prior DSP course required.&lt;/li&gt;
  &lt;li&gt;Headphones recommended for listening comparisons.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;how-to-navigate&quot;&gt;How to navigate&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Start at Chapter 00 for framing and the Mezon map.&lt;/li&gt;
  &lt;li&gt;Follow 01 → 03 for foundations and models.&lt;/li&gt;
  &lt;li&gt;Use 04 → 06 when you care about shipping.&lt;/li&gt;
  &lt;li&gt;Chapter 07 before claiming quality wins; Chapter 08 for the capstone; Chapter 09 for reading paths.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;feedback&quot;&gt;Feedback&lt;/h2&gt;

&lt;p&gt;Open issues on &lt;a href=&quot;https://github.com/nglelinh/audio-noise-suppression-self-learning&quot;&gt;GitHub&lt;/a&gt; or contact Nguyen Le Linh (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nglelinh@gmail.com&lt;/code&gt;).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>contents</title>
   <link href="https://audio-processing-self-learning.pages.dev/home/contents/"/>
   <updated>2021-01-20T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/home/contents</id>
   <content type="html">&lt;p&gt;Real-time audio noise suppression for Vietnamese software engineers: &lt;strong&gt;deep Fourier &amp;amp; audio DSP&lt;/strong&gt;, through DeepFilterNet and Mezon product integration. Each required lesson is a full EN/VI article with a labeled figure under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/generated/&lt;/code&gt;, a mini-lab, and exercises with hints. The public integration target is npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; on a LiveKit track).&lt;/p&gt;

&lt;h1 id=&quot;course-objectives&quot;&gt;Course objectives&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;Build strong Fourier / DFT / FFT intuition and a full framed-audio pipeline (STFT/ISTFT, windows, OLA).&lt;/li&gt;
  &lt;li&gt;Connect classical NS / AEC / beamforming front-ends to modern neural SE.&lt;/li&gt;
  &lt;li&gt;Understand the DeepFilterNet family and when ultra-light streaming models fit.&lt;/li&gt;
  &lt;li&gt;Ship constraints: RTF, AudioWorklet, on-device ORT/tract/WASM, WebRTC / LiveKit.&lt;/li&gt;
  &lt;li&gt;Evaluate with SI-SDR, DNSMOS, listening tests, DNS Challenge-style suites.&lt;/li&gt;
  &lt;li&gt;Capstone: techniques behind &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;course-outline&quot;&gt;Course outline&lt;/h2&gt;

&lt;h3 id=&quot;chapter-00--introduction--problem-framing&quot;&gt;Chapter 00 — Introduction &amp;amp; problem framing&lt;/h3&gt;
&lt;p&gt;Noise types, realtime vs offline, course map, Mezon context.&lt;/p&gt;

&lt;h3 id=&quot;chapter-01--fourier--discrete-transforms-deep&quot;&gt;Chapter 01 — Fourier &amp;amp; discrete transforms (deep)&lt;/h3&gt;
&lt;p&gt;Continuous FT intuition → sampling, aliasing, Nyquist → DTFT / DFS / DFT → DFT as basis → FFT (radix-2, complexity) → FFT in realtime frames → engineer pitfalls checklist.&lt;/p&gt;

&lt;h3 id=&quot;chapter-02--audio-processing-pipeline&quot;&gt;Chapter 02 — Audio processing pipeline&lt;/h3&gt;
&lt;p&gt;PCM &amp;amp; rates → frames / hop / OLA → windowing &amp;amp; leakage → STFT/ISTFT for speech (DeepFilterNet tie-in) → time vs frequency filtering → reading spectrograms → pipeline latency–quality tradeoffs.&lt;/p&gt;

&lt;h3 id=&quot;chapter-03--classical-ns--aec--beamforming&quot;&gt;Chapter 03 — Classical NS / AEC / beamforming&lt;/h3&gt;
&lt;p&gt;Spectral subtraction, Wiener, Kalman intuition, WebRTC APM, GSC/IVA as front-ends.&lt;/p&gt;

&lt;h3 id=&quot;chapter-04--neural-se--deepfilternet-family&quot;&gt;Chapter 04 — Neural SE &amp;amp; DeepFilterNet family&lt;/h3&gt;
&lt;p&gt;Complex spectrograms, deep filtering; survey pointers to successors and ultra-light streaming models; RNNoise bridge.&lt;/p&gt;

&lt;h3 id=&quot;chapter-05--real-time-constraints&quot;&gt;Chapter 05 — Real-time constraints&lt;/h3&gt;
&lt;p&gt;RTF, AudioWorklet / callbacks, ring buffers, underruns, streaming state.&lt;/p&gt;

&lt;h3 id=&quot;chapter-06--on-device-inference&quot;&gt;Chapter 06 — On-device inference&lt;/h3&gt;
&lt;p&gt;ONNX / tract / ORT, quantization, SIMD/WASM, packaging.&lt;/p&gt;

&lt;h3 id=&quot;chapter-07--product-integration&quot;&gt;Chapter 07 — Product integration&lt;/h3&gt;
&lt;p&gt;WebRTC / LiveKit TrackProcessor, CDN model loading, Mezon npm surface.&lt;/p&gt;

&lt;h3 id=&quot;chapter-08--evaluation&quot;&gt;Chapter 08 — Evaluation&lt;/h3&gt;
&lt;p&gt;SI-SDR, DNSMOS, listening tests, DNS Challenge-style metrics.&lt;/p&gt;

&lt;h3 id=&quot;chapter-09--capstone&quot;&gt;Chapter 09 — Capstone&lt;/h3&gt;
&lt;p&gt;Mezon NS architecture, techniques beyond the wrapper, optional Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt;, project brief.&lt;/p&gt;

&lt;h3 id=&quot;chapter-10--references--further-paths&quot;&gt;Chapter 10 — References &amp;amp; further paths&lt;/h3&gt;
&lt;p&gt;Curated reading list and maintenance notes.&lt;/p&gt;

&lt;h2 id=&quot;primary-references-starter&quot;&gt;Primary references (starter)&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DeepFilterNet / DeepFilterNet2 / DeepFilterNet3 papers and official code.&lt;/li&gt;
  &lt;li&gt;DNS Challenge (datasets, DNSMOS, baselines).&lt;/li&gt;
  &lt;li&gt;WebRTC APM, SpeexDSP, RNNoise.&lt;/li&gt;
  &lt;li&gt;SI-SDR literature; ONNX Runtime / tract docs.&lt;/li&gt;
  &lt;li&gt;Standard DSP references for FT / DFT / FFT / STFT.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>10-03 Duy trì khóa học này</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter10/10_03_course_changelog/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter10/10_03_course_changelog</id>
   <content type="html">&lt;p&gt;Khóa học này gồm trọn bộ bài giảng song ngữ Anh – Việt từ Chương 00 đến Chương 10. Theo thời gian, các API bên ngoài sẽ thay đổi: gói npm, cấu trúc CDN &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;, bộ trọng số DeepFilterNet và giao diện TrackProcessor của LiveKit đều có thể cập nhật, kéo theo các bài học trích dẫn chúng trở nên lỗi thời. Người bảo trì khóa học cần cập nhật đồng bộ cả hai ngôn ngữ trong cùng một lần thay đổi, sinh lại hình minh họa bằng script thay vì chỉnh sửa thủ công tệp PNG, và luôn coi kho mã nguồn sản phẩm chung là tài liệu nguồn để tham khảo chứ không phải nơi nộp bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/fourier-intuition.png&quot; alt=&quot;Hình trực giác Fourier dùng làm ví dụ cho người giữ khóa&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Tổng các sóng đơn tần theo miền thời gian tương ứng với các vạch rời rạc trên miền tần số. Người bảo trì sinh lại tệp PNG này cùng mọi hình minh họa khác bằng lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 scripts/generate_course_figures.py&lt;/code&gt;; kết quả được ghi vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/generated/&lt;/code&gt; và nhúng trong bài qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/img/generated/fourier-intuition.png&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ biết cách cập nhật bài học khi gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; hoặc bố trí CDN thay đổi, đồng bộ bản tiếng Việt ngay trong cùng một pull request, bổ sung hình minh họa mà không làm hỏng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;baseurl&lt;/code&gt;, mở phiếu theo dõi bảo trì liệt kê đủ cả hai tệp ngôn ngữ, và tự dựng trang web tại máy để kiểm tra cảnh báo từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle exec jekyll build&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;những-thay-đổi-nguồn-gốc-cần-theo-dõi-định-kỳ&quot;&gt;Những thay đổi nguồn gốc cần theo dõi định kỳ&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Nguồn gốc (Upstream)&lt;/th&gt;
      &lt;th&gt;Thành phần dễ bị lệch&lt;/th&gt;
      &lt;th&gt;Vị trí cần cập nhật&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; (sau 1.3.0)&lt;/td&gt;
      &lt;td&gt;Tên API công khai hoặc quy tắc tự thêm tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Chương 07 và 09 (cả hai ngôn ngữ)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;CDN thay đổi cấu trúc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Đường dẫn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Bài 07-03 và 09-01&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;LiveKit cập nhật &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Luồng phát hành track ở bài 09-01&lt;/td&gt;
      &lt;td&gt;Đối chiếu lại &lt;a href=&quot;https://docs.livekit.io/&quot;&gt;docs.livekit.io&lt;/a&gt; và ghi rõ phiên bản&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tên tệp gói ONNX mới&lt;/td&gt;
      &lt;td&gt;Mô tả tài nguyên ở Chương 09 và 10&lt;/td&gt;
      &lt;td&gt;Chỉ cập nhật đúng tên tệp sau khi đã trực tiếp xác nhận&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Checkpoint DNSMOS mới&lt;/td&gt;
      &lt;td&gt;Các bảng đánh giá ở Chương 08&lt;/td&gt;
      &lt;td&gt;Cố định tên checkpoint mới; không gộp chung chuỗi điểm với bản cũ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Các tên giao diện công khai giữ nguyên cho đến khi chính README gốc thay đổi: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;. Không tự ý thêm mô tả các lớp nội bộ.&lt;/p&gt;

&lt;h2 id=&quot;kỷ-luật-cập-nhật-và-ghi-nhận-thay-đổi-changelog&quot;&gt;Kỷ luật cập nhật và ghi nhận thay đổi (Changelog)&lt;/h2&gt;

&lt;p&gt;Mỗi khi chỉnh sửa bài tiếng Anh, bắt buộc cập nhật bản tiếng Việt tương ứng trong cùng một pull request: giữ đồng nhất &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chapter&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;order&lt;/code&gt; và tên tệp, chỉ khác trường &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lang: en&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lang: vi&lt;/code&gt;. Toàn bộ khối mã nguồn, URL và các số liệu kiểm chứng từ bài lab (như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13.80&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;−10.67&lt;/code&gt;, mảng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1.237, -0.237, -0.763, 0.263]&lt;/code&gt;) phải giữ nguyên chính xác; phần văn bản viết bằng tiếng Việt tự nhiên nhưng bảo toàn các thuật ngữ chuẩn như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SI-SDR&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DNSMOS&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTF&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Khi bổ sung hoặc cập nhật hình vẽ, luôn đặt tệp PNG trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/generated/&lt;/code&gt; và nhúng thông qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/img&lt;/code&gt; thay vì dán ảnh chụp rời rạc vào thư mục mới. Chạy lệnh sinh hình:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 scripts/generate_course_figures.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Lệnh này tự động tạo lại toàn bộ hình ảnh trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/generated/&lt;/code&gt; (gồm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fourier-intuition.png&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eval-metric-map.png&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;livekit-trackprocessor.png&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet-erb.png&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnx-wasm-path.png&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf-audioworklet.png&lt;/code&gt;). Hãy commit các tệp PNG mới sinh cùng bài học nhúng chúng; nếu chỉ sửa chú thích hình thì không cần chạy lại script.&lt;/p&gt;

&lt;p&gt;Ghi một dòng nhật ký kèm ngày tháng ngay trong nội dung mô tả pull request thay vì chỉ trao đổi trong tin nhắn:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;2026-09-23 — Chương 08–10 EN và VI: hình, mini-lab, gợi ý đáp án.
             Bản VI cập nhật trong cùng thay đổi. Không sửa repo sản phẩm.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;dựng-và-kiểm-tra-trang-web-tại-máy&quot;&gt;Dựng và kiểm tra trang web tại máy&lt;/h2&gt;

&lt;p&gt;Tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_config.yml&lt;/code&gt; cấu hình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;baseurl: /audio-processing-self-learning&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;imgurl: /audio-processing-self-learning/img&lt;/code&gt;. Chạy kiểm tra cục bộ bằng bộ lệnh:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle &lt;span class=&quot;nb&quot;&gt;install
&lt;/span&gt;bundle &lt;span class=&quot;nb&quot;&gt;exec &lt;/span&gt;jekyll serve
&lt;span class=&quot;c&quot;&gt;# http://127.0.0.1:4000/audio-processing-self-learning/&lt;/span&gt;
bundle &lt;span class=&quot;nb&quot;&gt;exec &lt;/span&gt;jekyll build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Địa chỉ trang xuất bản là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://nglelinh.github.io/audio-processing-self-learning/&lt;/code&gt;. Nếu chèn hình bằng đường dẫn tương đối thay vì &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;site.imgurl&lt;/code&gt;, ảnh có thể hiển thị trên máy cục bộ nhưng bị lỗi 404 khi xuất bản. Sau khi build xong, hãy mở thử một bài thuộc Chương 08 và một bài thuộc Chương 10 để xác nhận URL ảnh đều chứa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/audio-processing-self-learning/img/generated/&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;quản-trị-nội-dung-và-ranh-giới-kho-sản-phẩm&quot;&gt;Quản trị nội dung và ranh giới kho sản phẩm&lt;/h2&gt;

&lt;p&gt;Mọi thay đổi về khung chương trình cần được ghi nhận trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COURSE_OUTLINE.md&lt;/code&gt;. Quy ước trích dẫn chuẩn được lưu trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AGENTS.md&lt;/code&gt;, xoay quanh các nguồn chính thức: DeepFilterNet (cùng DeepFilterNet2/3), DNS Challenge, WebRTC APM, SpeexDSP, RNNoise, SI-SDR, DNSMOS, ONNX Runtime và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; (các tên mô hình khảo sát chỉ giữ ở mức điểm tên). Các bài học chỉ tham khảo tài liệu công khai của &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt; và không nhận bản vá trực tiếp tại đó; mọi thử nghiệm của học viên đều thực hiện trên nhánh fork cá nhân hoặc thư mục &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;mẫu-phiếu-theo-dõi-bảo-trì-issue&quot;&gt;Mẫu phiếu theo dõi bảo trì (Issue)&lt;/h2&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Title: [course] Update Ch09 CDN paths for package x.y.z
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Upstream version:
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Broken lesson paths:
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; EN files:
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; VI files:
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Figure touched (img/generated name) or none:
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; jekyll build: pass/fail
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Verified image URL contains site imgurl: yes/no
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Chỉ mở phiếu bảo trì khi đã liệt kê đủ cả tệp tiếng Anh lẫn tiếng Việt; một bản vá chỉ cập nhật riêng tiếng Anh được coi là chưa hoàn tất.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Từ thư mục gốc của kho khóa học, kiểm tra sự tồn tại của script sinh hình và xác nhận mọi bài tiếng Anh từ Chương 08 đến Chương 10 đều nhúng ảnh qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;site.imgurl&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; scripts/generate_course_figures.py &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;script_ok
python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
from pathlib import Path
bad = []
paths = list(Path(&quot;contents/en&quot;).glob(&quot;chapter0[89]/_posts/*.md&quot;))
paths += list(Path(&quot;contents/en&quot;).glob(&quot;chapter10/_posts/*.md&quot;))
for p in paths:
    if &quot;site.imgurl&quot; not in p.read_text():
        bad.append(p.name)
print(&quot;bad&quot;, bad or &quot;none&quot;)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;script_ok
bad none
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Chỉnh sửa trực tiếp tệp PNG bằng phần mềm đồ họa rồi bỏ quên script sinh hình (lần chạy script kế tiếp sẽ ghi đè mất chỉnh sửa đó); cập nhật số liệu lab ở bản tiếng Anh nhưng để sót số cũ ở bản tiếng Việt; sao chép nhầm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;baseurl&lt;/code&gt; từ kho khác khiến toàn bộ ảnh bị lỗi 404; hoặc mở pull request “sửa bài học” bằng cách chỉnh sửa kho sản phẩm chung.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Đối chiếu README hiện hành của gói npm với bài 09-01 và chỉ ra một nguy cơ sai lệch thông tin theo thời gian.&lt;/li&gt;
  &lt;li&gt;Tạo thử một sửa lỗi chính tả nhỏ ở bài tiếng Anh trên nhánh cục bộ và đồng bộ sửa đổi tương ứng sang tệp tiếng Việt trong cùng một commit (không đẩy lên kho chính trừ khi bạn đang phụ trách bảo trì).&lt;/li&gt;
  &lt;li&gt;Chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle exec jekyll build&lt;/code&gt; và ghi lại mọi cảnh báo liên quan đến Chương 08–10.&lt;/li&gt;
  &lt;li&gt;Điền mẫu phiếu bảo trì cho tình huống giả định phiên bản &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.4.0&lt;/code&gt; bỏ tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;, liệt kê đủ cả tệp EN và VI.&lt;/li&gt;
  &lt;li&gt;Nêu chính xác câu lệnh sinh hình và hai quy tắc đường dẫn bắt buộc khi thêm một hình minh họa mới.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Các dạng sai lệch phổ biến là bổ sung phương thức công khai mới hoặc thay đổi tiền tố đường dẫn CDN; cần trích dẫn đúng dòng tương ứng trong README.&lt;/li&gt;
  &lt;li&gt;Gộp cả hai tệp vào cùng một PR và giữ nguyên trường &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lang&lt;/code&gt; trong YAML frontmatter.&lt;/li&gt;
  &lt;li&gt;Nếu môi trường máy chưa cài Jekyll, ghi trung thực “jekyll not run” thay vì tự tạo nhật ký build giả.&lt;/li&gt;
  &lt;li&gt;Liệt kê đầy đủ đường dẫn cả bản EN và VI; mục hình ảnh ghi “none” nếu sơ đồ không thay đổi.&lt;/li&gt;
  &lt;li&gt;Chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 scripts/generate_course_figures.py&lt;/code&gt; để xuất tệp vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/generated/&amp;lt;name&amp;gt;.png&lt;/code&gt;, và nhúng trong bài bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/img/generated/&amp;lt;name&amp;gt;.png&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Các chi tiết về runtime và đóng gói thường xuyên thay đổi — mọi phiên bản được ghim trong bài đều cần được rà soát định kỳ trong changelog.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d2N0d6CKrbk&quot;&gt;Group calling architectures in WebRTC: MCU, SFU &amp;amp; P2P&lt;/a&gt; — Tsahi Levent-Levi, tiếng Anh. Dù SDK có đổi tên hàm hook, nền tảng kiến trúc SFU, MCU và mesh vẫn là chuẩn mực để đối chiếu độ chính xác của tài liệu.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=rIAIzf6utOc&quot;&gt;What is a CDN (Content Delivery Network) and How does a CDN Work?&lt;/a&gt; — Cloudflare, tiếng Anh. Hành vi lưu đệm tại biên so với máy chủ gốc là phần quan trọng cần lưu ý mỗi khi cập nhật đường dẫn tài nguyên trong changelog.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>10-02 Hướng học tiếp</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter10/10_02_further_paths/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter10/10_02_further_paths</id>
   <content type="html">&lt;p&gt;Sau khi hoàn thành dự án cuối khóa, bước hiệu quả nhất là chọn duy nhất một hướng chuyên sâu và thực hiện lộ trình thực hành 30 ngày tạo ra sản phẩm cụ thể, thay vì gom một danh sách đọc dài nhưng không bao giờ mở. Cả ba hướng dưới đây đều kế thừa chung bản đồ đánh giá của khóa học: SI-SDR xâm nhập khi có bản gốc sạch, DNSMOS (hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;) trên bản ghi thực tế, ghi chú lắng nghe và RTF khi xử lý thời gian thực. Các chủ đề mở rộng đi kèm chỉ nhằm gợi ý những thí nghiệm gọn nhẹ cuối tuần, không phải một khóa học thứ hai bắt buộc phải hoàn thành.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Bản đồ đánh giá để chọn dự án tiếp&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Dù chọn hướng chuyên sâu nào, bản đồ đánh giá vẫn giữ nguyên giá trị: một bộ lọc DSP cổ điển, một bản tái hiện bài báo mạng nơ-ron hay một chính sách tích hợp LiveKit đều được đánh giá dựa trên đúng cột chỉ số mà chúng tác động.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ chọn được một trong ba hướng đi (DSP cổ điển, tăng cường giọng nói bằng mạng nơ-ron hoặc sản phẩm hóa), xây dựng kế hoạch 30 ngày với tệp bàn giao cụ thể theo từng tuần, chọn một chủ đề thực nghiệm cuối tuần kèm phép đo rõ ràng, và hoàn thiện cây thư mục &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/&lt;/code&gt; thành một dự án hồ sơ năng lực (portfolio) độc lập với kho sản phẩm chung.&lt;/p&gt;

&lt;h2 id=&quot;hướng-a--đào-sâu-xử-lý-tín-hiệu-số-dsp-cổ-điển&quot;&gt;Hướng A — Đào sâu xử lý tín hiệu số (DSP) cổ điển&lt;/h2&gt;

&lt;p&gt;Tự cài đặt lại phép cộng chồng lấp (overlap-add) cho đến khi tín hiệu sóng sin được khôi phục trong đúng dung sai bạn in ra. Đọc mã nguồn SpeexDSP (&lt;a href=&quot;https://github.com/xiph/speexdsp&quot;&gt;https://github.com/xiph/speexdsp&lt;/a&gt;) hoặc WebRTC APM (&lt;a href=&quot;https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/&quot;&gt;https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/&lt;/a&gt;) đủ sâu để phân định rõ vai trò của khối khử nhiễu tách biệt khỏi khối khử vọng (AEC). Trên một bản thu stereo tự ghi, phân tích một tình huống thất bại của kỹ thuật tạo chùm tia (beamforming) — ví dụ người nói lệch trục hoặc micro tham chiếu bị nhiễu — mà không cần tự tuyên bố một thuật toán mới.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sản phẩm hoàn thành:&lt;/strong&gt; Tệp ghi chú &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-a/when-classical.md&lt;/code&gt; phân tích một trường hợp cụ thể nơi cổng phổ đơn giản hoặc bộ lọc khuếch đại kiểu Wiener vượt trội mô hình mạng nặng về RTF mà không làm suy giảm kết quả nghe thử (chỉ ghi SI-SDR nếu có bản gốc sạch).&lt;/p&gt;

&lt;h2 id=&quot;hướng-b--tăng-cường-giọng-nói-bằng-mạng-nơ-ron&quot;&gt;Hướng B — Tăng cường giọng nói bằng mạng nơ-ron&lt;/h2&gt;

&lt;p&gt;Mỗi tuần đọc trọn vẹn một bài báo gốc trong danh mục bài 10-01, bắt đầu từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arXiv:2110.05588&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arXiv:2205.05474&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arXiv:2305.08227&lt;/code&gt;. Tái hiện một phép đo tốc độ bằng ONNX Runtime hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; trên CPU laptop, báo cáo RTF bằng thời gian thực tế chia cho thời lượng âm thanh kèm tên CPU cụ thể. Nếu so sánh DeepFilterNet3 với các mô hình siêu nhẹ đã điểm tên (FastEnhancer, μNet, Fast-ULCNet, GTCRN), hãy thực hiện trên chính tập mẫu &lt;strong&gt;của bạn&lt;/strong&gt; và không tự bịa URL bài báo; các tên như DPDFNet, DeepFilterGAN và HDF-Net cũng chỉ nên dùng như mốc tham khảo cho đến khi bạn trực tiếp mở trích dẫn gốc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sản phẩm hoàn thành:&lt;/strong&gt; Tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-b/table.md&lt;/code&gt; theo đúng cấu trúc 6 cột của bài 08-04 kèm một đoạn phân tích giới hạn, tránh văn phong quảng bá bảng xếp hạng.&lt;/p&gt;

&lt;h2 id=&quot;hướng-c--sản-phẩm-hóa-và-triển-khai-thực-tế&quot;&gt;Hướng C — Sản phẩm hóa và triển khai thực tế&lt;/h2&gt;

&lt;p&gt;Bám sát luồng công khai trên LiveKit: micro → &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; → &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; → phát hành track. Đo thời gian khởi động lạnh của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt; (với tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; do bản 1.3.0 tự động thêm) trên điều kiện mạng thực tế của bạn, sau đó kiểm thử lại kịch bản CDN bị chặn. Nhánh mở rộng Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; vẫn là tùy chọn thay thế cho hộp WASM; nếu mới dừng ở bước sao chép thẳng, tệp README trên portfolio phải ghi rõ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sản phẩm hoàn thành:&lt;/strong&gt; Tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-c/design.md&lt;/code&gt; tổng hợp thời gian khởi tạo, chỉ số RTF p95 (hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;) và nhật ký xử lý lỗi khi CDN bị chặn.&lt;/p&gt;

&lt;h2 id=&quot;các-thí-nghiệm-mở-rộng-cuối-tuần&quot;&gt;Các thí nghiệm mở rộng cuối tuần&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Chủ đề&lt;/th&gt;
      &lt;th&gt;Sản phẩm thực hành cuối tuần&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Khử vọng (AEC)&lt;/td&gt;
      &lt;td&gt;Một bản thu có tiếng vọng lấn át tạp âm, kèm giải thích vì sao khử nhiễu (NS) không thể xóa tiếng vọng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đa micro (Multi-mic)&lt;/td&gt;
      &lt;td&gt;Một bản thu stereo kèm đoạn phân tích ngắn giải thích nên tin cậy kênh nào&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tách người nói đích&lt;/td&gt;
      &lt;td&gt;Một đoạn tạp âm đám đông (babble) nơi điểm DNSMOS và cảm nhận tai nghe trái ngược nhau&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bộ mã hóa (Codec)&lt;/td&gt;
      &lt;td&gt;So sánh cùng một câu nói qua Opus bitrate thấp trước và sau khi khử nhiễu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Phụ đề tự động (ASR)&lt;/td&gt;
      &lt;td&gt;Đo WER hoặc đếm lỗi nhận dạng thủ công trên 10 câu (không đánh đồng với MOS)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;lộ-trình-thực-hành-30-ngày&quot;&gt;Lộ trình thực hành 30 ngày&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Giai đoạn&lt;/th&gt;
      &lt;th&gt;Tệp cần bổ sung&lt;/th&gt;
      &lt;th&gt;Tiêu chí hoàn thành&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Ngày 1–3&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;notes/si_sdr.py&lt;/code&gt; chạy lại bài lab &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13.80&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;−10.67&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Cả hai giá trị khớp chính xác bài 08-01&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ngày 4–7&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audio/CLIPS.txt&lt;/code&gt; gồm 20 tên tệp&lt;/td&gt;
      &lt;td&gt;Danh sách được chốt trước khi có điểm số&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ngày 8–14&lt;/td&gt;
      &lt;td&gt;Bản MVP của hướng đã chọn (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-a&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-b&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-c&lt;/code&gt;)&lt;/td&gt;
      &lt;td&gt;Tệp README có lệnh chạy tái lập rõ ràng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ngày 15–21&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;metrics/suite.md&lt;/code&gt; và ghi chú nghe thử cùng nhóm&lt;/td&gt;
      &lt;td&gt;Script kiểm tra bài 08-04 báo đủ 6 hàng dữ liệu (hoặc giải thích rõ nếu ít hơn)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ngày 22–26&lt;/td&gt;
      &lt;td&gt;Kịch bản &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DEMO.md&lt;/code&gt; dài không quá 5 phút&lt;/td&gt;
      &lt;td&gt;Đính kèm tên tệp âm thanh dự phòng rõ ràng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ngày 27–30&lt;/td&gt;
      &lt;td&gt;Cập nhật tài liệu trên fork &lt;strong&gt;cá nhân&lt;/strong&gt; hoặc viết bản ADR tại nơi làm việc&lt;/td&gt;
      &lt;td&gt;Không commit vào kho sản phẩm Mezon chung trừ khi là công việc ngoài khóa học&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;cấu-trúc-hồ-sơ-năng-lực-portfolio&quot;&gt;Cấu trúc hồ sơ năng lực (Portfolio)&lt;/h2&gt;

&lt;p&gt;Một portfolio kỹ thuật thuyết phục nên bao gồm: bản phác thảo kiến trúc, bảng chỉ số 6 cột, quy trình nghe thử AB song ngữ Anh – Việt, bản ghi demo tối đa 3 phút và các thẻ đọc tài liệu từ bài 10-01. Trước khi công khai, nhớ xóa bỏ toàn bộ đường dẫn tuyệt đối của máy cá nhân.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Tạo tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path_plan.md&lt;/code&gt; theo mẫu dưới đây:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;path: A
week1_file: notes/si_sdr.py
weekend: aec
command: python3 notes/si_sdr.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Giá trị &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path&lt;/code&gt; chọn một trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C&lt;/code&gt;; giá trị &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;weekend&lt;/code&gt; chọn một trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;aec&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;multimic&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;target&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;codec&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;captions&lt;/code&gt;. Kiểm tra định dạng bằng đoạn mã sau:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;path_plan.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;path_ok&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;path: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;abc&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;weekend_ok&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;aec&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;multimic&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;codec&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;captions&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path_ok&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fix&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;weekend&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;weekend_ok&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fix&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;command:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fix&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;path ok
weekend ok
command ok
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Ôm đồm cả ba hướng trong cùng một tháng; ghi tên chủ đề cuối tuần mà không có sản phẩm bàn giao cụ thể; đặt mục tiêu RTF mà không nêu thiết bị đo; hoặc bắt đầu kế hoạch bằng việc sửa thẳng kho sản phẩm chung thay vì tạo fork riêng.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Hoàn thiện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path_plan.md&lt;/code&gt; cho hướng đi thực tế bạn chọn rồi chạy script kiểm tra.&lt;/li&gt;
  &lt;li&gt;Bổ sung danh sách tên tệp dự kiến hoàn thành theo từng tuần ngay bên dưới phần tiêu đề 4 dòng của tệp đó.&lt;/li&gt;
  &lt;li&gt;Chỉ ra một điểm thiếu rõ ràng trong tài liệu gốc (trang processor LiveKit, README npm hoặc README DeepFilterNet) mà bạn có thể viết bổ sung một đoạn hướng dẫn, kèm khẳng định chính của đoạn đó.&lt;/li&gt;
  &lt;li&gt;Phác thảo mục README cho portfolio liên kết tới cả 5 nhóm sản phẩm; nếu có nhánh Rust, đảm bảo tuân thủ quy tắc ghi nhãn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Xác định cột nào trên bản đồ đánh giá sẽ ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; trong hướng bạn chọn và giải thích lý do.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Chọn duy nhất một chữ cái (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C&lt;/code&gt;); việc đổi hướng giữa chừng ở ngày 20 đồng nghĩa bắt đầu lại kế hoạch mới.&lt;/li&gt;
  &lt;li&gt;Mọi đường dẫn tệp phải tự tái tạo được trên máy của người đọc, không trỏ tới đường dẫn cục bộ trên máy khác.&lt;/li&gt;
  &lt;li&gt;Các điểm thực tế thường thiếu rõ ràng: quy tắc tự thêm tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; hoặc sự khác biệt giữa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt; và lỗi tải tài nguyên CDN.&lt;/li&gt;
  &lt;li&gt;Liên kết trực tiếp đến từng tệp công khai, không trỏ vào kho riêng tư mà người đánh giá không mở được.&lt;/li&gt;
  &lt;li&gt;Bản ghi thực tế luôn ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; ở cột SI-SDR; còn bài lab khôi phục tín hiệu DSP thuần có thể ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; ở cột DNSMOS.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=E8HeD-MUrjY&quot;&gt;The Fast Fourier Transform (FFT)&lt;/a&gt; — Steve Brunton, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Điểm khởi đầu lý tưởng cho Hướng A: hiểu rõ độ phức tạp của DFT và cơ sở cài đặt FFT.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Trọng tâm cho Hướng B: nắm chắc một kiến trúc và chuỗi bài báo gốc thay vì lướt qua nhiều tên mô hình rời rạc.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Định hướng cốt lõi cho Hướng C: kết hợp dữ liệu thực, kiểm thử lắng nghe và ngân sách độ phức tạp trên cuộc gọi thật.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>10-01 Danh mục đọc có chọn lọc</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter10/10_01_curated_reading/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter10/10_01_curated_reading</id>
   <content type="html">&lt;p&gt;Đọc sâu ba tài liệu gốc có giá trị hơn nhiều so với việc lưu hai mươi bài tóm tắt mà không mở ra xem. Mọi liên kết dưới đây đều là bài báo, kho mã nguồn hoặc bộ tài liệu chính thức được dùng xuyên suốt khóa học. Các tên mô hình khảo sát ở cuối danh sách — gồm DPDFNet, DeepFilterGAN, HDF-Net, FastEnhancer, μNet, Fast-ULCNet và GTCRN — chỉ mang tính điểm tên nhận diện; tuyệt đối không tự bịa tiêu đề hay URL cho chúng. Nếu thẻ đọc cần một chi tiết mà bạn chưa trực tiếp mở nguồn để kiểm tra, hãy ghi rõ “chưa đọc” thay vì suy diễn một câu nghe có vẻ hợp lý.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;Đường ERB và deep filter của DeepFilterNet&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Sơ đồ khối mà bạn cần tự vẽ lại được sau khi đọc các công trình của Schröter và cộng sự: STFT đầu vào → nhánh hệ số ERB và bộ lọc sâu (deep filter) → ISTFT và cộng chồng lấp (overlap-add) ở đầu ra. Mẫu thẻ đọc bên dưới là cách chứng minh bạn đã đọc tài liệu gốc.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ chọn được 3 liên kết từ danh mục chuẩn, hoàn thiện thẻ đọc gồm đúng 4 gạch đầu dòng cho mỗi nguồn theo đúng định dạng kiểm tra, đồng thời giữ nguyên các thuật ngữ tiếng Anh cốt lõi (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SI-SDR&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DNSMOS&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTF&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt;) trong ghi chú ngay cả khi phần diễn giải viết bằng tiếng Việt.&lt;/p&gt;

&lt;h2 id=&quot;danh-mục-tài-liệu-trích-dẫn&quot;&gt;Danh mục tài liệu trích dẫn&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Họ mô hình DeepFilterNet:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter, Escalante-B., Rosenkranz, Maier. &lt;em&gt;“DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio based on Deep Filtering.”&lt;/em&gt; ICASSP 2022. &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;https://arxiv.org/abs/2110.05588&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Schröter và cộng sự. &lt;em&gt;“DeepFilterNet2: Towards Real-Time Speech Enhancement on Embedded Devices for Full-Band Audio.”&lt;/em&gt; &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;https://arxiv.org/abs/2205.05474&lt;/a&gt; (bài báo Interspeech 2023 sau này trích dẫn công trình này theo hội nghị IWAENC 2022).&lt;/li&gt;
  &lt;li&gt;Schröter, Escalante-B., Rosenkranz, Maier. &lt;em&gt;“DeepFilterNet: Perceptually Motivated Real-Time Speech Enhancement.”&lt;/em&gt; Interspeech 2023. &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;https://arxiv.org/abs/2305.08227&lt;/a&gt; — đây là trích dẫn của mô hình DeepFilterNet3 mà README kho gốc sử dụng (các bảng kết quả bên trong gọi tên DeepFilterNet3 dù tiêu đề bài báo không thêm số “3”).&lt;/li&gt;
  &lt;li&gt;Mã nguồn và hướng dẫn gói trọng số mô hình: &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;https://github.com/Rikorose/DeepFilterNet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Các mô hình nền tảng và runtime suy luận:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;RNNoise: &lt;a href=&quot;https://github.com/xiph/rnnoise&quot;&gt;https://github.com/xiph/rnnoise&lt;/a&gt; và Valin, &lt;em&gt;“A Hybrid DSP/Deep Learning Approach to Real-Time Full-Band Speech Enhancement,”&lt;/em&gt; &lt;a href=&quot;https://arxiv.org/abs/1709.08243&quot;&gt;https://arxiv.org/abs/1709.08243&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;WebRTC APM: &lt;a href=&quot;https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/&quot;&gt;https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SpeexDSP: &lt;a href=&quot;https://github.com/xiph/speexdsp&quot;&gt;https://github.com/xiph/speexdsp&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Tài liệu ONNX Runtime: &lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;https://onnxruntime.ai/docs/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Thư viện suy luận Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;: &lt;a href=&quot;https://github.com/sonos/tract&quot;&gt;https://github.com/sonos/tract&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Đánh giá chất lượng và tích hợp sản phẩm:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Le Roux, Wisdom, Erdogan, Hershey. &lt;em&gt;“SDR – Half-baked or Well Done?”&lt;/em&gt; ICASSP 2019 — nền tảng của SI-SDR (không thay thế kiểm thử lắng nghe).&lt;/li&gt;
  &lt;li&gt;Dữ liệu và mô hình nền DNS Challenge: &lt;a href=&quot;https://github.com/microsoft/DNS-Challenge&quot;&gt;https://github.com/microsoft/DNS-Challenge&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;DNSMOS / DNSMOS P.835: Reddy, Gopal, Cutler (Interspeech 2021 và ICASSP 2022) — bộ dự đoán không xâm nhập; khóa học không đặt ngưỡng điểm đạt chính thức.&lt;/li&gt;
  &lt;li&gt;Tài liệu LiveKit: &lt;a href=&quot;https://docs.livekit.io/&quot;&gt;https://docs.livekit.io/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0: &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;https://www.npmjs.com/package/deepfilternet3-noise-filter&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Kho mã nguồn sản phẩm (chỉ dùng để đọc tham khảo, không gửi bản vá bài tập vào đây): &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;https://github.com/mezonai/mezon-noise-suppression&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mẫu-thẻ-đọc-tài-liệu&quot;&gt;Mẫu thẻ đọc tài liệu&lt;/h2&gt;

&lt;p&gt;Mỗi thẻ chỉ gồm đúng 4 gạch đầu dòng theo đúng cấu trúc yêu cầu của mini-lab:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Source: &amp;lt;url&amp;gt;
- Claim: một câu từ abstract hoặc README, không phải đoán.
- Streaming / latency: nhân quả hay không, hop hoặc look-ahead nếu nguồn nêu, không thì &quot;not stated&quot;.
- What it measures or ships: metric, thư viện, hoặc API. Chỉ dùng SI-SDR, DNSMOS, RTF, TrackProcessor khi nguồn thật sự bàn tới.
- What I will reuse: một việc trong harness hoặc capstone của bạn.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ví dụ một thẻ đọc đã điền hoàn chỉnh (không nộp lại nguyên văn URL này làm một trong 3 thẻ trừ khi bạn tự viết thêm 2 nguồn khác):&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Source: https://arxiv.org/abs/2110.05588
- Claim: DeepFilterNet tăng cường tiếng nói full-band bằng tầng gain ERB cộng deep filtering, độ phức tạp thấp.
- Streaming / latency: Khung hướng tới enhance full-band thời gian thực; hãy kiểm tra bài để lấy cửa sổ, hop, và look-ahead trước khi trích một con số mili giây.
- What it measures or ships: Bài báo cáo metric enhance xâm nhập trên tập test và mô tả bộ lọc hai tầng. Đây không phải TrackProcessor của LiveKit.
- What I will reuse: Tôi sẽ vẽ lại khối ERB cộng deep filter trong phác capstone và sẽ không mô tả npm wrapper như thể nó là thuật toán.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Lưu ý rằng ví dụ trên cố tình không tự điền một con số độ trễ chưa kiểm chứng — đây là một phần quan trọng của tính kỷ luật khoa học. Khi bạn đã mở tệp PDF và xác nhận chính xác độ dài hop, bạn có thể thay câu lưu ý bằng con số thực tế đọc được.&lt;/p&gt;

&lt;h2 id=&quot;cách-đọc-hiệu-quả-một-tài-liệu-trong-một-giờ&quot;&gt;Cách đọc hiệu quả một tài liệu trong một giờ&lt;/h2&gt;

&lt;p&gt;Hãy bắt đầu từ các sơ đồ khối thay vì đọc mục tài liệu liên quan (related work) trước. Với các bài báo DeepFilterNet, hãy tìm ngay nhánh tính hệ số ERB và phép lọc sâu đa khung. Với DNSMOS, cần xác nhận bản chất không xâm nhập và ghi nhận giao thức nghe thử mà mô hình được huấn luyện để bám theo. Với README gói npm, chỉ ghi nhận các tên giao diện công khai (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt; và quy tắc nối tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; từ bản ≥ 1.2.0). Với WebRTC APM hay SpeexDSP, hãy xếp chúng vào nhóm nền tảng DSP cổ điển, không phải tệp trọng số để thả vào CDN Mezon.&lt;/p&gt;

&lt;p&gt;Nhắc lại danh sách các tên khảo sát chỉ dùng để nhận diện khi đọc thêm: DPDFNet, DeepFilterGAN, HDF-Net, FastEnhancer, μNet, Fast-ULCNet và GTCRN. Thẻ đọc nào tự bịa mã arXiv cho các tên này sẽ bị đánh trượt.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Chọn &lt;strong&gt;3&lt;/strong&gt; URL trong danh sách chính thức phía trên, soạn tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reading_cards.md&lt;/code&gt; gồm 3 thẻ đúng cấu trúc 4 gạch đầu dòng mỗi thẻ, rồi chạy script kiểm tra:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;reading_cards.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sources&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Source:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;bullets&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;- &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sources&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sources&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bullets&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bullets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;has_url&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;https://&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sources 3
bullets 12
has_url True
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Tổng cộng 12 gạch đầu dòng tương ứng 3 thẻ nhân 4 mục.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Viết phần &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Claim&lt;/code&gt; mâu thuẫn với tiêu đề bài báo do chưa mở đọc; tự bịa URL cho GTCRN hoặc DeepFilterGAN; sao chép nguyên ví dụ mẫu làm cả 3 thẻ; hoặc tự ý đổi chữ viết tắt chuẩn của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SI-SDR&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DNSMOS&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Hoàn thiện 3 thẻ đọc, trong đó có ít nhất một bài báo thuộc họ DeepFilterNet và ít nhất một nguồn không phải bài báo (kho mã nguồn hoặc tài liệu kỹ thuật).&lt;/li&gt;
  &lt;li&gt;Sau khi mở trực tiếp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arXiv:2110.05588&lt;/code&gt;, thêm một dòng ghi chú riêng bên dưới thẻ (nằm ngoài 4 gạch đầu dòng chuẩn) ghi rõ độ dài hop và look-ahead bạn tìm thấy, hoặc ghi trung thực là chưa tìm thấy.&lt;/li&gt;
  &lt;li&gt;Mở kho DNS Challenge đủ lâu để gọi tên một thư mục hoặc script có thật trong kho đó rồi đưa vào mục &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;What it measures or ships&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Viết một câu giải thích vì sao thẻ đọc về DNSMOS không ghi ngưỡng điểm đậu chính thức.&lt;/li&gt;
  &lt;li&gt;Liệt kê lại danh sách các tên mô hình khảo sát mà bạn không được phép gắn URL tự bịa.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Tối thiểu gồm 1 bài báo khoa học và 1 kho mã nguồn hoặc trang tài liệu (trang npm và tài liệu LiveKit đều tính là nguồn ngoài bài báo).&lt;/li&gt;
  &lt;li&gt;Giữ đúng quy ước 4 gạch đầu dòng bên trong thẻ; mọi ghi chú mở rộng đặt riêng phía dưới.&lt;/li&gt;
  &lt;li&gt;Không mô tả tệp chưa trực tiếp kiểm tra; ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;not stated&quot;&lt;/code&gt; khi nguồn không đề cập.&lt;/li&gt;
  &lt;li&gt;Công trình của Reddy, Gopal và Cutler xây dựng bộ dự đoán chất lượng chứ không định nghĩa ngưỡng phát hành cho Mezon, đặc biệt khi có rủi ro lệch miền dữ liệu.&lt;/li&gt;
  &lt;li&gt;DPDFNet, DeepFilterGAN, HDF-Net, FastEnhancer, μNet, Fast-ULCNet và GTCRN.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Xem song song với bài báo DeepFilterNet trong danh sách đọc để nắm nhanh sơ đồ khối trước khi đọc kỹ PDF.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Phần trình bày về DNS Challenge và DNSMOS khớp trực tiếp với nhóm tài liệu đánh giá chất lượng.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=spUNpyF58BY&quot;&gt;But what is the Fourier Transform?  A visual introduction.&lt;/a&gt; — 3Blue1Brown, tiếng Anh. Cung cấp trực giác hình học cho biến đổi Fourier trước khi đi sâu vào các công thức DSP.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-05 Checklist capstone & demo day</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter09/09_05_capstone_checklist/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter09/09_05_capstone_checklist</id>
   <content type="html">&lt;p&gt;Buổi trình diễn cuối khóa (demo day) gói gọn trong 5 phút để chứng minh luồng phát hành âm thanh, bảng số liệu đo đạc và các giới hạn hệ thống đều được kiểm chứng thực tế. Một bộ slide bắt mắt nhưng thiếu chỉ số RTF và không có bản ghi dự phòng được coi là không đạt. Danh mục kiểm tra (checklist) dưới đây đóng vai trò sổ tay vận hành trước ngày demo: bao gồm lệnh kiểm tra, danh sách tệp và các kịch bản tiêm lỗi (fault injection) có chủ đích.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;RTF so với quantum render của AudioWorklet&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. RTF là tỉ số giữa thời gian xử lý thực tế của một quantum và thời lượng của quantum đó. Giá trị trung bình dưới 1 vẫn có thể gây tràn hạn nếu phân vị p95 hoặc p99 vượt ngưỡng callback. Luôn ghi log p95 và tách riêng thời gian tải tài nguyên lúc khởi động.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ rà soát trọn vẹn đường truyền âm thanh, đường tải tài nguyên và các tệp số liệu, luyện tập kịch bản trình bày 5 phút, thực hiện tiêm lỗi chặn CDN mà cuộc gọi không gián đoạn, đồng thời trình bày mẫu âm thanh so sánh kèm nhãn điều kiện rõ ràng.&lt;/p&gt;

&lt;h2 id=&quot;danh-mục-kiểm-tra-kỹ-thuật&quot;&gt;Danh mục kiểm tra kỹ thuật&lt;/h2&gt;

&lt;p&gt;Sao chép các hạng mục sau vào tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/demo_checklist.md&lt;/code&gt; và đánh dấu hoàn thành; mọi mục bỏ trống đều coi là chưa đạt trừ khi ghi rõ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; kèm lý do.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Đường truyền âm thanh:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Quyền truy cập micro hoạt động ổn định trên chính máy dùng để demo.&lt;/li&gt;
  &lt;li&gt;Cả hai trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(true)&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt; đều giữ nguyên track đã phát hành (nếu giao diện buộc phải vào lại phòng, cần ghi rõ đó là giới hạn).&lt;/li&gt;
  &lt;li&gt;Trạng thái bật/tắt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt; của trình duyệt được ghi lại tường minh để tránh quy nhầm hiệu quả của trình duyệt cho &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Khi rời phòng họp, không để rò rỉ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; gây nhiễu ở lần tham gia kế tiếp.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tải mô hình từ CDN:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ở lần tải lạnh, gói ≥ 1.2.0 (gồm 1.3.0) gọi đúng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;; kiểm tra trên tab Network để xác nhận &lt;strong&gt;không&lt;/strong&gt; đưa sẵn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Ở lần tải thứ hai, tài nguyên được phục vụ từ cache (hoặc ghi nhận rõ nếu chưa bật cache).&lt;/li&gt;
  &lt;li&gt;Khi chặn kết nối CDN, cuộc gọi vẫn phát hành tín hiệu gốc chưa xử lý và giao diện hiển thị thông báo lỗi; lưu ảnh chụp hoặc dòng log vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bảng số liệu (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/metrics/suite.md&lt;/code&gt;):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Đủ 6 cột: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clip id&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;condition&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SI-SDR&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DNSMOS&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;listening note&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTF p95&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Có ít nhất một hàng bản ghi thực tế với cột SI-SDR ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Cột &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTF p95&lt;/code&gt; ghi kèm tên thiết bị đo; nếu chỉ mới dừng ở dùng thử nội bộ (dogfood), ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; chứ không ước đoán con số 0,2.&lt;/li&gt;
  &lt;li&gt;Ghi đầy đủ phiên bản: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;, tên gói nén mô hình, phiên bản DNSMOS (hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not run&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Chuẩn bị cho buổi demo:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Có sẵn tệp ghi âm dự phòng phát được ngay nếu micro trực tiếp gặp sự cố.&lt;/li&gt;
  &lt;li&gt;Chuẩn bị sẵn tai nghe trên bàn để tránh vọng loa.&lt;/li&gt;
  &lt;li&gt;Chuẩn bị đủ ba nhóm mẫu: tiếng ồn quán cà phê (babble), tiếng gõ bàn phím và phòng yên tĩnh.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Nhánh Rust (nếu có thực hiện):&lt;/strong&gt; Câu giới thiệu đầu tiên khớp với tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_core_status.md&lt;/code&gt;; nếu ở trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt;, nói rõ “noise suppression is not running”.&lt;/p&gt;

&lt;h2 id=&quot;kịch-bản-trình-bày-5-phút&quot;&gt;Kịch bản trình bày 5 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Mốc thời gian&lt;/th&gt;
      &lt;th&gt;Nội dung trình bày&lt;/th&gt;
      &lt;th&gt;Tệp mở kèm&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;0:00–0:40&lt;/td&gt;
      &lt;td&gt;Bài toán khử nhiễu uplink trên thiết bị cho LiveKit&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;design/sketch.md&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;0:40–1:20&lt;/td&gt;
      &lt;td&gt;Tám bước luồng công khai, không gọi lớp nội bộ&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publish-path.md&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;1:20–2:30&lt;/td&gt;
      &lt;td&gt;Phát đối chiếu bản thô và bản đã xử lý, nêu rõ điều kiện&lt;/td&gt;
      &lt;td&gt;Tệp WAV dự phòng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2:30–3:30&lt;/td&gt;
      &lt;td&gt;Phân tích một hàng cải thiện và một hàng không cải thiện&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;metrics/suite.md&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3:30–4:20&lt;/td&gt;
      &lt;td&gt;Kết luận giả thuyết, kể cả khi kết quả không đạt kỳ vọng&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;design/hypothesis.md&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4:20–5:00&lt;/td&gt;
      &lt;td&gt;Giới hạn: ngôn ngữ, thiết bị, bản DNSMOS, trạng thái Rust&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;notes/limits.md&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nếu chạy thử bị quá 5 phút, hãy rút gọn phần kiến trúc trước, tuyệt đối không cắt bỏ hàng phản ví dụ — việc chỉ ra trường hợp không cải thiện mới chứng minh bạn thực sự làm chủ hệ thống đánh giá.&lt;/p&gt;

&lt;h2 id=&quot;thực-hành-tiêm-lỗi-fault-injection&quot;&gt;Thực hành tiêm lỗi (fault injection)&lt;/h2&gt;

&lt;p&gt;Chủ động chặn tên miền CDN (chuyển chế độ offline trong DevTools hoặc đặt sai &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;) rồi tham gia phòng họp. Kết quả kỳ vọng: phòng họp vẫn có âm thanh, processor không giả vờ mô hình đang chạy, và bạn ghi lại xem công tắc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; có còn phản hồi hay không. Sau đó khôi phục mạng và tải lại trang: kiểm tra tệp WASM cùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tar.gz&lt;/code&gt; tải thành công từ nhánh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;. Nếu hệ thống hành xử khác kỳ vọng, hãy ghi nhận thẳng vào mục giới hạn thay vì giấu đi.&lt;/p&gt;

&lt;p&gt;Nếu có dữ liệu log RTF, hãy kiểm tra ở khung quantum chậm nhất thay vì chỉ nhìn trung bình; cột vượt ngưỡng trên biểu đồ chính là dấu hiệu lỗi. Nếu chưa tính được p95 thì để &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Sau khi hoàn thiện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/demo_checklist.md&lt;/code&gt;, kiểm tra độ đầy đủ bằng script sau:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;capstone/notes/demo_checklist.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setenabled&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;noisesuppression&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;df_bg.wasm&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;deepfilternet3_onnx.tar.gz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;si-sdr&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;dnsmos&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rtf p95&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;backup&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;passthrough&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;missing none
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Vẫn giữ từ khóa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt; trong tệp kể cả khi bạn không làm nhánh Rust (ví dụ ghi: “Rust: not attempted, so not a passthrough claim.”) để đảm bảo checklist không bỏ sót quy tắc xác nhận nhánh mở rộng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Đánh dấu đạt ở mục RTF mà không ghi tên thiết bị; dùng bản ghi dự phòng khác hoàn toàn với kịch bản demo trực tiếp; chèn sẵn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; gây lỗi 404; hoặc giới thiệu bản Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt; là “NS works”.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chạy thử kịch bản demo có bấm giờ, lưu thời lượng vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/rehearsal.txt&lt;/code&gt; và tinh chỉnh đến khi không vượt quá 5 phút.&lt;/li&gt;
  &lt;li&gt;Thực hiện bài kiểm tra chặn CDN và dán ghi nhận thực tế ngay bên dưới checklist.&lt;/li&gt;
  &lt;li&gt;Trao đổi mục giới hạn (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;limits.md&lt;/code&gt;) với một đồng nghiệp để mỗi người tìm ra ít nhất một phát biểu dễ bị hiểu là khẳng định quá mức.&lt;/li&gt;
  &lt;li&gt;Liệt kê danh sách thư mục từ bài 09-04 bạn sẽ nén hoặc đẩy lên fork cá nhân (loại trừ hoàn toàn kho sản phẩm chung).&lt;/li&gt;
  &lt;li&gt;Quan sát cột vượt ngưỡng trên biểu đồ RTF và nêu cách báo cáo trung thực nếu log của bạn hiện chỉ có giá trị trung bình.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Luôn cắt bớt phần giới thiệu kiến trúc trước, giữ lại các hàng phản ví dụ trong bảng số liệu.&lt;/li&gt;
  &lt;li&gt;Ghi nhận trung thực hành vi thực tế, ví dụ: “Âm thanh gốc vẫn được phát hành, mô hình không tải được, giao diện hiển thị thông báo lỗi”.&lt;/li&gt;
  &lt;li&gt;Các phát biểu quá mức thường gặp: báo cáo SI-SDR trên tệp ghi âm thực tế hoặc ghi điểm DNSMOS mà không nêu phiên bản checkpoint.&lt;/li&gt;
  &lt;li&gt;Nộp bốn thư mục &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/design&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audio&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;metrics&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;notes&lt;/code&gt; từ kho cá nhân, không đính kèm tệp nào thuộc kho sản phẩm chung.&lt;/li&gt;
  &lt;li&gt;Báo cáo giá trị trung bình đo được và ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; ở cột RTF p95, tuyệt đối không tự ước đoán phân vị.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Các phần về đánh giá và tích hợp tương ứng trực tiếp với cấu trúc checklist: số liệu, kiểm thử lắng nghe và hệ thống gọi thực tế.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, tiếng Anh. Minh họa cách đo lỗi giật tiếng (glitch) và trễ hạn callback — cơ sở cho bài tiêm lỗi hiệu năng.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Tham khảo cách chuẩn bị mẫu âm thanh dự phòng để buổi demo luôn có âm thanh đối chiếu dù micro trực tiếp gặp sự cố.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-04 Đề bài capstone</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter09/09_04_capstone_project_brief/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter09/09_04_capstone_project_brief</id>
   <content type="html">&lt;p&gt;Dự án cuối khóa (capstone) gồm một bản thiết kế hoàn chỉnh, một bản demo có số liệu đo đạc trên tập mẫu nhỏ và một câu chuyện tích hợp API công khai có cơ sở bảo vệ rõ ràng. Dự án không phải bản vá gửi trực tiếp vào kho sản phẩm chung &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt;; bạn cần triển khai trên nhánh fork cá nhân hoặc trong cấu trúc thư mục &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/&lt;/code&gt; được tạo ở bài lab này.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Bản đồ đánh giá cho báo cáo capstone&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Báo cáo cuối khóa bám sát bản đồ đánh giá: chỉ tính SI-SDR khi có bản gốc sạch, ghi DNSMOS hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, bổ sung ghi chú lắng nghe và một dòng hệ thống cho RTF. Quyết định phát hành phải dựa trên bằng chứng đo đạc.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ khởi tạo được cấu trúc thư mục dự án cuối khóa, tạo hỗn hợp tín hiệu 4 mẫu ở mức SNR cho trước, chọn một nhánh chính phù hợp, liệt kê đầy đủ các tệp sản phẩm mà người chấm sẽ kiểm tra, đồng thời xác định trước các dạng lỗi phổ biến ở từng mốc để tránh bỏ sót.&lt;/p&gt;

&lt;h2 id=&quot;các-nhánh-đề-tài-track&quot;&gt;Các nhánh đề tài (Track)&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A. Đánh giá và chính sách khử nhiễu (khuyến nghị).&lt;/strong&gt; Đóng băng tập mẫu âm thanh, hoàn thiện bảng 6 cột từ bài 08-04 và bảo vệ lựa chọn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; bằng dữ liệu kiểm thử AB.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B. Tích hợp hệ thống.&lt;/strong&gt; Thiết lập &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt; (ví dụ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/code&gt;), kiểm chứng quy tắc tự thêm tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; trên bản ≥ 1.2.0 (gồm 1.3.0), kiểm thử &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; và diễn tập tình huống CDN bị chặn nhưng cuộc gọi vẫn phát hành âm thanh bình thường.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C. Nhánh mở rộng Rust.&lt;/strong&gt; Thử nghiệm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; tùy chọn từ bài 09-03. Nếu backend mới ở mức sao chép thẳng thì bắt buộc ghi nhãn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt; (vẫn được tính điểm thành phần khi trung thực); không có điểm cho bất kỳ báo cáo nào ghi “NS works” trên vòng lặp chép thẳng.&lt;/p&gt;

&lt;p&gt;Hãy chọn duy nhất một nhánh chính; các nhánh còn lại chỉ nên liệt kê trong mục ngoài phạm vi (non-goals).&lt;/p&gt;

&lt;h2 id=&quot;các-mốc-công-việc-và-lỗi-thường-gặp&quot;&gt;Các mốc công việc và lỗi thường gặp&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Mã mốc&lt;/th&gt;
      &lt;th&gt;Sản phẩm bàn giao&lt;/th&gt;
      &lt;th&gt;Lỗi thường gặp&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;M0&lt;/td&gt;
      &lt;td&gt;Phác thảo kiến trúc (09-01) và giả thuyết (09-02)&lt;/td&gt;
      &lt;td&gt;Dùng tên lớp nội bộ không công khai, hoặc thiếu tiêu chí thất bại&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;M1&lt;/td&gt;
      &lt;td&gt;Số liệu nền (baseline) trên danh sách mẫu đóng băng&lt;/td&gt;
      &lt;td&gt;Thay đổi danh sách mẫu sau khi đã nhìn thấy điểm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;M2&lt;/td&gt;
      &lt;td&gt;Mã thay đổi nằm trong fork hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Commit thử nghiệm trực tiếp lên kho sản phẩm chung&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;M3&lt;/td&gt;
      &lt;td&gt;Bảng đánh giá 6 cột, dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; đúng quy tắc&lt;/td&gt;
      &lt;td&gt;Tự bịa số SI-SDR cho bản ghi micro thực tế&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;M4&lt;/td&gt;
      &lt;td&gt;Checklist buổi demo (09-05)&lt;/td&gt;
      &lt;td&gt;Phụ thuộc hoàn toàn vào CDN trực tuyến, không có bản ghi dự phòng&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Cần hoàn thành dứt điểm M0 trước khi thu thập số liệu M3 để tránh việc điều chỉnh ngược giả thuyết cho khớp kết quả.&lt;/p&gt;

&lt;h2 id=&quot;danh-sách-sản-phẩm-người-chấm-sẽ-kiểm-tra&quot;&gt;Danh sách sản phẩm người chấm sẽ kiểm tra&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/design/sketch.md&lt;/code&gt; — mục tiêu, luồng dữ liệu công khai, URL tài nguyên và giới hạn phạm vi.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/design/hypothesis.md&lt;/code&gt; — giả thuyết, thiết kế thí nghiệm, tiêu chí thành công và thất bại.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/audio/&lt;/code&gt; — các tệp WAV nhỏ hoặc tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.npy&lt;/code&gt; từ bộ trộn, kèm README giải thích quy ước đặt tên.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/metrics/suite.md&lt;/code&gt; — bảng 6 cột gồm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clip id&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;condition&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SI-SDR&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DNSMOS&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;listening note&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTF p95&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/reading.md&lt;/code&gt; — tối thiểu 5 gạch đầu dòng liên kết kiến thức Chương 02–08 với API công khai hoặc các nguồn tài liệu ở bài 10-01.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/limits.md&lt;/code&gt; — nêu rõ giới hạn về ngôn ngữ, thiết bị và trạng thái nhánh Rust (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not attempted&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt; hoặc backend thực).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Trang trình chiếu (slide) là tùy chọn; lưu ý ảnh chụp màn hình con số mà người khác không thể chạy lại không được công nhận là kết quả đánh giá.&lt;/p&gt;

&lt;h2 id=&quot;tiêu-chí-và-trọng-số-đánh-giá&quot;&gt;Tiêu chí và trọng số đánh giá&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trọng số cao:&lt;/strong&gt; Kỹ thuật đo đạc có thực chất và bảng kết quả trung thực (kể cả các ô &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;); người chấm có thể chạy lại bộ trộn hoặc script kiểm tra.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trọng số trung bình:&lt;/strong&gt; Kịch bản demo xử lý ổn định tình huống tai nghe và sự cố chặn CDN.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trọng số thấp:&lt;/strong&gt; Hình thức trình bày trực quan.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không tính điểm:&lt;/strong&gt; Chỉnh sửa kho sản phẩm chung khi chưa được phép, hoặc mô tả backend &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt; là “đã khử nhiễu”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Các mục nằm ngoài phạm vi dự án gồm: huấn luyện kiến trúc mô hình mới, yêu cầu nhánh Rust khớp từng bit như điều kiện hoàn thành, và đẩy âm thanh người dùng lên mô hình đám mây khi không có thiết kế bảo mật quyền riêng tư.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Thực hiện từ một thư mục làm việc trống (tuyệt đối &lt;strong&gt;không&lt;/strong&gt; chạy trong kho sản phẩm chung):&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; capstone/&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;design,audio,metrics,notes&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
find capstone &lt;span class=&quot;nt&quot;&gt;-type&lt;/span&gt; d | &lt;span class=&quot;nb&quot;&gt;sort
&lt;/span&gt;python3 &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;import numpy as np; s=np.array([1.,0,-1,.5]); n=np.array([.2,-.2,.2,-.2]); g=np.linalg.norm(s)/(10**(10/20)*np.linalg.norm(n)); y=s+g*n; np.save(&quot;capstone/audio/mix.npy&quot;, y); print(np.round(y,3).tolist())&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;capstone
capstone/audio
capstone/design
capstone/metrics
capstone/notes
[1.237, -0.237, -0.763, 0.263]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Đoạn mã trên trộn tín hiệu tham chiếu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s&lt;/code&gt; từ bài 08-01 với véctơ nhiễu 4 mẫu ở mức SNR 10 dB: hệ số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; chuẩn hóa biên độ nhiễu sao cho \(10\log_{10}(\|s\|^2/\|gn\|^2) = 10\), và các giá trị in ra là \(s + gn\) làm tròn đến 3 chữ số thập phân. Kiểm tra lại bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;find capstone -type f | sort&lt;/code&gt; để chắc chắn tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/audio/mix.npy&lt;/code&gt; đã được lưu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Chạy lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mkdir&lt;/code&gt; bên trong bản sao kho sản phẩm chung; tính sai SNR do áp dụng tỉ số biên độ hai lần; quên lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.save&lt;/code&gt; rồi nộp mỗi cây thư mục rỗng; hoặc nhầm lẫn mảng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1.237, -0.237, -0.763, 0.263]&lt;/code&gt; là đầu ra của DeepFilterNet (thực tế đây là tín hiệu hỗn hợp có nhiễu).&lt;/p&gt;

&lt;p&gt;Sau khi chạy xong, hãy thêm danh sách các mốc M0–M4 (ghi trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;todo&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;done&lt;/code&gt;) vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/design/sketch.md&lt;/code&gt; để người chấm thấy rõ cấu trúc kế hoạch ngay cả khi các mốc mới ở trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;todo&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chọn một trong ba nhánh A, B hoặc C rồi viết bản giả thuyết M0 lưu vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/design/&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Chốt trước 10 tên tệp âm thanh trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/audio/CLIPS.txt&lt;/code&gt; trước khi bắt đầu chấm bất kỳ chỉ số nào.&lt;/li&gt;
  &lt;li&gt;Tạo tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/reading.md&lt;/code&gt; với 5 gạch đầu dòng kèm URL thực tế mà bạn dự định đọc.&lt;/li&gt;
  &lt;li&gt;Chọn một dạng lỗi trong bảng mốc dễ xảy ra nhất với kế hoạch của bạn và chỉ ra tệp nào sẽ giúp phát hiện sớm lỗi đó.&lt;/li&gt;
  &lt;li&gt;Chạy lại câu lệnh trộn ở mức 0 dB (đổi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10/20&lt;/code&gt; thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0/20&lt;/code&gt;) và giải thích nguyên nhân giá trị các mẫu thay đổi.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Nếu chọn nhánh C mà chưa nạp mô hình thực, bắt buộc vẫn phải ghi rõ nhãn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CLIPS.txt&lt;/code&gt; chỉ lưu danh sách tên tệp trước khi có điểm số nhằm tránh chọn lọc thiên lệch.&lt;/li&gt;
  &lt;li&gt;Trích dẫn các URL thực có trong bài 10-01, không tự bịa tài liệu tham khảo.&lt;/li&gt;
  &lt;li&gt;Hai lỗi phổ biến nhất là vi phạm M2 (commit vào kho sản phẩm chung) và M3 (điền SI-SDR giả cho tệp thực tế).&lt;/li&gt;
  &lt;li&gt;Tại mức SNR 0 dB, năng lượng nhiễu bằng năng lượng tín hiệu (\(\|gn\| = \|s\|\)), nên hệ số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; tăng lên và nhiễu chi phối rõ rệt hơn trên dạng sóng đầu ra.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video cho thấy một báo cáo khử nhiễu thuyết phục luôn kết hợp dữ liệu, kiểm thử lắng nghe và chi phí tính toán — đúng mô hình mà dự án cuối khóa thu gọn lại.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Định dạng so sánh trước – sau là hình mẫu trực quan cho phần trình diễn âm thanh trong buổi demo.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Tham khảo cách trình bày sơ đồ hệ thống kèm phân tích độ trễ để bảo vệ thiết kế kỹ thuật.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-03 Lộ trình Rust native (df-core) tùy chọn</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter09/09_03_optional_rust_df_core/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter09/09_03_optional_rust_df_core</id>
   <content type="html">&lt;p&gt;Luồng chạy chính thức được hỗ trợ của Mezon là gói WASM bên trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;: gồm trọng số ONNX, bản dựng WASM SIMD, cấu trúc CDN &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; (được gói tự động thêm từ bản ≥ 1.2.0, bao gồm 1.3.0) và AudioWorklet. Crate Rust tạm gọi là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; chỉ là &lt;strong&gt;nhánh mở rộng tùy chọn thay thế cho hộp WASM đó&lt;/strong&gt;, phục vụ công cụ dòng lệnh (CLI) trên máy tính hoặc tích hợp native trong không gian làm việc cá nhân của bạn. Đây không phải sản phẩm thứ hai, không phải yêu cầu bắt buộc để hoàn thành khóa học và không nằm trong kho mã nguồn sản phẩm. Nếu phiên bản backend ban đầu chỉ sao chép thẳng mẫu đầu vào sang đầu ra, bắt buộc phải ghi rõ là &lt;strong&gt;passthrough&lt;/strong&gt;, tuyệt đối không ghi “NS works” cho một bộ chép thẳng.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;Đường WASM trên thiết bị của deepfilternet3-noise-filter&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Luồng phát hành sản phẩm đi từ PyTorch sang ONNX, biên dịch thành WASM phân phối qua CDN &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; rồi chạy trong AudioWorklet. Nhánh Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; chỉ là phương án mở rộng thay cho hộp WASM này, không phải một sản phẩm song song.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ nêu chính xác những tài nguyên luồng WASM tải về (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;), xác định các tham số mà bản thử nghiệm Rust cá nhân cần đồng bộ (độ dài khung/hop, tần số lấy mẫu, mô hình thực), biết cách kiểm chứng độ tương đương (parity) mà không tuyên bố khớp từng bit khi chưa đo, và giữ nguyên tắc không bao giờ đánh đồng backend rỗng với bộ khử nhiễu thực sự.&lt;/p&gt;

&lt;h2 id=&quot;thành-phần-mặc-định-không-cần-thay-thế&quot;&gt;Thành phần mặc định không cần thay thế&lt;/h2&gt;

&lt;p&gt;Phiên bản 1.3.0 (giống mọi bản ≥ 1.2.0) tải &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;, trong đó client tự nối &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; còn bạn chỉ truyền đường dẫn gốc (ví dụ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/code&gt;). Các điểm điều khiển công khai vẫn giữ nguyên: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;. Việc thử nghiệm bằng Rust không bổ sung thêm API công khai nào vào gói npm; nếu muốn xây dựng CLI, hãy đặt độc lập trong kho cá nhân.&lt;/p&gt;

&lt;p&gt;Các bài báo DeepFilterNet cho thấy việc cài đặt lại trên native đòi hỏi độ chính xác rất cao: âm thanh toàn dải 48 kHz, STFT với hop khoảng 10 ms, tầng hệ số ERB và bộ lọc sâu có thể kèm cửa sổ nhìn trước (look-ahead) ngắn tạo ra độ trễ thuật toán. Đạt cùng RTF không đồng nghĩa khớp dạng sóng: như bài 08-01 đã chứng minh, chỉ cần lệch 1 mẫu cũng khiến SI-SDR tụt từ 13.80 dB xuống −10.67 dB. Do đó, một bản Rust “hơi trễ một chút” sẽ cho điểm SI-SDR rất kém dù nghe qua có vẻ tương tự.&lt;/p&gt;

&lt;h2 id=&quot;tổ-chức-không-gian-làm-việc-cá-nhân-nếu-chọn-thực-hiện&quot;&gt;Tổ chức không gian làm việc cá nhân (nếu chọn thực hiện)&lt;/h2&gt;

&lt;p&gt;Chỉ khởi tạo thư mục này trong fork hoặc kho cá nhân mới, không đặt vào kho sản phẩm chung:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;my-df-stretch/
  df-core/     # API khung của bạn
  df-cli/      # wav vào, wav ra, offline
  README.md    # câu đầu nói passthrough hoặc backend thật
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Các mốc triển khai gợi ý theo thứ tự:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Backend passthrough.&lt;/strong&gt; Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; trả về nguyên vẹn mẫu đầu vào. Dòng đầu tệp README ghi rõ trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt;; các bài kiểm thử chỉ xác nhận độ dài và tính toàn vẹn bản sao, không kiểm tra mức giảm nhiễu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bắt lỗi thiếu tài nguyên.&lt;/strong&gt; Khi thiếu đường dẫn tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tar.gz&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt;, chương trình phải dừng và báo lỗi rõ ràng, không âm thầm cho âm thanh đi thẳng rồi in thông báo “enhanced”.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nạp runtime suy luận thực.&lt;/strong&gt; Dùng &lt;a href=&quot;https://github.com/sonos/tract&quot;&gt;tract&lt;/a&gt; hoặc ONNX Runtime (&lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;onnxruntime.ai/docs&lt;/a&gt;) để chạy cùng gói mô hình DeepFilterNet3 mà CDN phục vụ; lựa chọn thực tế còn lại là &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;libDF&lt;/a&gt; từ kho nguồn gốc. Hãy chọn một phương án và cố định phiên bản.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đồng bộ cấu hình khung.&lt;/strong&gt; Ghi rõ độ dài hop, kích thước cửa sổ và tần số lấy mẫu song song với bản WASM, không tự đặt thêm API nội bộ cho Mezon.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối chiếu trên tệp chuẩn.&lt;/strong&gt; Cho cùng một tệp WAV nhiễu đi qua luồng WASM công khai và qua CLI Rust của bạn, căn chỉnh độ trễ rồi tính SI-SDR &lt;strong&gt;giữa hai tín hiệu đầu ra&lt;/strong&gt;, báo cáo giá trị thực và nghe thử. Lưu ý: SI-SDR cao giữa hai bản đầu ra chỉ chứng minh chúng khớp nhau, chưa tự chứng minh bản nào khớp giọng sạch.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm dừng trung thực.&lt;/strong&gt; Nếu bạn chỉ hoàn thành tới bước 1, kịch bản demo phải nói rõ “passthrough, noise suppression is not running”.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Về giấy phép, cần tuân thủ giấy phép gốc của DeepFilterNet (Apache-2.0 hoặc MIT, tương đồng với gói npm). Không commit trực tiếp tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tar.gz&lt;/code&gt; vào Git; thay vào đó hãy trỏ tới cấu trúc CDN hoặc hướng dẫn tải &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;models/&lt;/code&gt; từ kho nguồn gốc.&lt;/p&gt;

&lt;h2 id=&quot;kiểm-chứng-độ-tương-đương-parity-một-cách-trung-thực&quot;&gt;Kiểm chứng độ tương đương (parity) một cách trung thực&lt;/h2&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;căn delay hop
enh_wasm.wav  từ processor đã phát hành hoặc lượt WASM offline bạn viết script
enh_rust.wav  từ CLI của bạn
in SI-SDR(enh_wasm, enh_rust) sau khi căn
ghi float vào báo cáo
nếu backend là passthrough, bỏ so sánh này và nói vì sao
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Khi chưa hoàn thành bước 3, bài kiểm tra đối chiếu được ghi nhận ở trạng thái &lt;strong&gt;đang chờ&lt;/strong&gt;. Một đầu ra passthrough so với bộ khử nhiễu thực chắc chắn sẽ cho điểm rất thấp — và đó chính là dấu hiệu đúng của phép kiểm tra; không được nới lỏng dung sai để làm đẹp con số.&lt;/p&gt;

&lt;p&gt;Sự đánh đổi giữa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; (hoặc ONNX Runtime) với việc gọi trực tiếp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libDF&lt;/code&gt; nên được phân tích ngắn gọn trong báo cáo: runtime ONNX sử dụng trực tiếp tệp tài nguyên sẵn có trên CDN, còn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libDF&lt;/code&gt; là engine gốc tạo ra bản WASM nên có thể bám sát trạng thái streaming hơn. Dù chọn hướng nào đều phải đo kiểm thực tế dựa trên nền tảng Chương 06.&lt;/p&gt;

&lt;h2 id=&quot;tiêu-chuẩn-hoàn-thành-cho-nhánh-mở-rộng&quot;&gt;Tiêu chuẩn hoàn thành cho nhánh mở rộng&lt;/h2&gt;

&lt;p&gt;Nhánh mở rộng tùy chọn được coi là hoàn tất khi có tệp README đủ rõ để người khác tự biên dịch được, ghi nhãn trung thực &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt; nếu mới dừng ở bước khung, hoặc cung cấp CLI kèm chỉ số SI-SDR đối chiếu với đầu ra WASM nếu đã nạp mô hình thực. Lưu ý không trình bày client native như sản phẩm chính của Mezon — sản phẩm đang vận hành vẫn là gói npm trên luồng LiveKit ở bài 09-01.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Tạo tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_core_status.md&lt;/code&gt; chứa hai dòng trạng thái để script kiểm tra đọc:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;backend: passthrough
claim: noise suppression is not running
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nếu bạn đã nạp thành công mô hình thực, có thể thay bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;backend: tract&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;backend: onnxruntime&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;backend: libdf&lt;/code&gt;, kèm dòng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;claim: compared to wasm SI-SDR &amp;lt;float&amp;gt;&lt;/code&gt;. Tuyệt đối không đặt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt; cạnh tuyên bố rằng khử nhiễu đang chạy.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;df_core_status.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ok_pass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;passthrough&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;not running&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ok_real&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;tract&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;onnxruntime&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;libdf&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;si-sdr&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;bad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ns works&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;noise suppression works&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ok_pass&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ok_real&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bad&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fix&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt; (cho trạng thái mặc định chưa nạp mô hình):&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;status ok
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Ghi “NS works” cho vòng lặp sao chép thẳng; commit tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; vào kho Git; phụ thuộc vào đường dẫn cục bộ trên máy khác; mô tả Rust là bản sản phẩm còn WASM chỉ là bản demo; hoặc báo cáo số SI-SDR đối chiếu mà không ghi bước căn chỉnh thời gian.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Liệt kê 5 mốc thực hiện nhánh Rust mà không cần GPU, đánh dấu rõ mốc nào vẫn ở trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Đề xuất các bài kiểm thử đơn vị (unit test) không cần trọng số mô hình: kiểm tra độ dài khung, tính đồng nhất khi sao chép và xử lý lỗi thiếu tệp.&lt;/li&gt;
  &lt;li&gt;Viết một đoạn ngắn so sánh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; (hoặc ONNX Runtime) với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libDF&lt;/code&gt; gốc khi làm backend cho nhánh mở rộng.&lt;/li&gt;
  &lt;li&gt;Quyết định rõ bạn có thực hiện nhánh Rust trong dự án cuối khóa hay không; nếu không, hãy nêu cụ thể hạng mục WASM bạn chọn thay thế.&lt;/li&gt;
  &lt;li&gt;Nêu đúng chiều so sánh SI-SDR trong bài kiểm tra độ tương đương: so sánh hai tín hiệu ước lượng với nhau, không so với khẩu hiệu.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Bước 1 và 2 là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt;; từ bước 3 (nạp runtime thực) mới được sử dụng thuật ngữ “enhance”.&lt;/li&gt;
  &lt;li&gt;Kiểm tra tính đồng nhất: mẫu đầu ra bằng đúng mẫu đầu vào; kiểm tra thiếu tệp: chương trình thoát với mã lỗi khác 0 và không tạo tệp WAV “enhanced”.&lt;/li&gt;
  &lt;li&gt;Runtime ONNX dùng trực tiếp tệp mô hình phân phối qua CDN, còn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libDF&lt;/code&gt; là engine gốc của tác giả; cả hai hướng đều bắt buộc đối chiếu trên tệp chuẩn.&lt;/li&gt;
  &lt;li&gt;Không chọn nhánh Rust vẫn hoàn thành trọn vẹn dự án cuối khóa miễn là các phần 09-01 và 09-04 được thực hiện đầy đủ và trung thực.&lt;/li&gt;
  &lt;li&gt;Tính &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SI-SDR(wasm, rust)&lt;/code&gt; sau khi đã bù độ trễ; giá trị &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13.80&lt;/code&gt; ở bài lab chỉ minh họa phương pháp, không phải mức điểm mục tiêu của sản phẩm.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nhTxJBgTywc&quot;&gt;Zoom on Web: getting connected with advanced web technology&lt;/a&gt; — Chrome for Developers, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Xem phần về Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; và cờ biên dịch — mốc hiệu năng WASM mà bất kỳ nhánh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; native nào cũng cần so sánh cùng.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, tiếng Anh. Giới thiệu engine ONNX Runtime cho cùng loại đồ thị mà nhánh Rust phải nạp.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, tiếng Anh. Ràng buộc thời gian của callback âm thanh vẫn giữ nguyên bất kể mã nguồn viết bằng JS hay Rust.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-02 Kỹ thuật vượt qua npm wrapper</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter09/09_02_techniques_not_wrapper/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter09/09_02_techniques_not_wrapper</id>
   <content type="html">&lt;p&gt;Điểm đánh giá dự án cuối khóa (capstone) tập trung vào các kỹ thuật đo đạc được: cấu hình khung và chồng lấp, chính sách chọn mức khử nhiễu, bộ công cụ đánh giá (harness), cơ chế ứng phó khi CDN lỗi hoặc kiểm soát ngân sách RTF — không phải việc đổi tên gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; hay tái cấu trúc nhỏ trong kho sản phẩm chung. Lớp wrapper chỉ là phương tiện vận chuyển, còn tầng hệ số ERB và bộ lọc sâu (deep filter) của DeepFilterNet mới là giá trị cốt lõi. Bài học này yêu cầu bạn xác lập trước một giả thuyết rõ ràng, một tập số liệu nền (baseline) và một bảng kết quả mà người quản trị kho mã có thể tự chạy lại để kiểm chứng.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;Khối DeepFilterNet: đường ERB và deep filter nhiều khung&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Chuỗi kỹ thuật nằm dưới lớp wrapper: PCM 48 kHz, STFT, nhánh hệ số khuếch đại ERB, bộ lọc sâu trên phổ phức, sau đó là ISTFT và cộng chồng lấp (overlap-add). Dự án cuối khóa cần nêu rõ bạn đang khảo sát hoặc tối ưu khâu nào.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ đề xuất được một cải tiến gắn chặt với kiến thức Chương 02–08, định nghĩa trước tiêu chí thành công và thất bại trước khi đo lần hai, giữ toàn bộ mã thử nghiệm trong fork cá nhân hoặc thư mục độc lập, đồng thời nêu rõ API công khai nào được tác động (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;, hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;) và chỉ số nào giữ nguyên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;danh-mục-đề-tài-ánh-xạ-theo-chương&quot;&gt;Danh mục đề tài ánh xạ theo chương&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Hướng đề tài&lt;/th&gt;
      &lt;th&gt;Kiến thức nền tảng&lt;/th&gt;
      &lt;th&gt;Sản phẩm kiểm chứng được&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Bộ đánh giá theo bảng 6 cột (bài 08-04)&lt;/td&gt;
      &lt;td&gt;Chương 08&lt;/td&gt;
      &lt;td&gt;Tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suite.md&lt;/code&gt; và script kiểm tra&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Chọn mức khử mặc định bằng kiểm thử AB&lt;/td&gt;
      &lt;td&gt;Bài 08-03&lt;/td&gt;
      &lt;td&gt;Quy trình AB, cỡ mẫu \(N\), bảng thắng/thua theo điều kiện&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ghi log RTF p95 và luật hạ mức tự động&lt;/td&gt;
      &lt;td&gt;Chương 05, 07&lt;/td&gt;
      &lt;td&gt;Tên thiết bị, giá trị p95, hành động hạ tải tương ứng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đối chiếu NS trình duyệt với processor&lt;/td&gt;
      &lt;td&gt;Chương 03, 07&lt;/td&gt;
      &lt;td&gt;Bảng kiểm tra ràng buộc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getSettings()&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đường dẫn CDN, tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; và diễn tập lỗi&lt;/td&gt;
      &lt;td&gt;Chương 07&lt;/td&gt;
      &lt;td&gt;Nhật ký tình huống bị chặn mạng và tải từ cache&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bộ trộn tín hiệu tổng hợp ngoại tuyến và SI-SDR&lt;/td&gt;
      &lt;td&gt;Chương 02, bài 08-01&lt;/td&gt;
      &lt;td&gt;Kiểm chứng mốc 13.80 / −10.67 rồi chạy trên WAV của bạn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Nhánh mở rộng Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Bài 09-03&lt;/td&gt;
      &lt;td&gt;Tùy chọn mở rộng; nếu chỉ chép thẳng phải ghi rõ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Không chấp nhận các đề tài chỉ chỉnh giao diện CSS, nâng phiên bản thư viện mà không có bảng so sánh, hoặc gộp hai giả thuyết không liên quan vào cùng một báo cáo. Nếu bạn chưa nêu được số liệu baseline cần thu thập trước tiên, bạn chưa có một thí nghiệm hợp lệ.&lt;/p&gt;

&lt;h2 id=&quot;cấu-trúc-giả-thuyết--thí-nghiệm--đo-lường&quot;&gt;Cấu trúc Giả thuyết – Thí nghiệm – Đo lường&lt;/h2&gt;

&lt;p&gt;Hãy viết hoàn chỉnh khối này trước khi thay đổi bất kỳ tham số nào:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Hypothesis: Đưa setSuppressionLevel từ 80 xuống 60 giảm phụ âm bị bít
            trên clip bàn phím mà không sụp ở quán.

Experiment: Cùng 12 clip. Mức 80 và 60. AB với ít nhất 6 người.
            SI-SDR chỉ trên cặp tổng hợp. DNSMOS chỉ khi ghim một checkpoint;
            không thì n/a. RTF p95 trên một laptop có tên.

Success:    Nghe bàn phím không thích 80 hơn về độ tự nhiên, quán hòa hoặc
            hơn bypass, đối chứng nói yên chủ yếu hòa, RTF p95 nằm trong
            ngân sách bạn đã ghi.

Fail:       Người nghe quán rõ ràng thích 80, hoặc tiếng yên thua, hoặc
            p95 trễ quantum AudioWorklet. Khi đó bạn không đổi mặc định.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Các con số trong khung trên chỉ là ví dụ định dạng, không phải kết quả thực nghiệm; báo cáo của bạn phải thay bằng số đo thực tế và vẫn không được tự đặt ra ngưỡng chuẩn DNSMOS chính thức.&lt;/p&gt;

&lt;h2 id=&quot;các-chỉ-số-cần-khai-báo-minh-bạch&quot;&gt;Các chỉ số cần khai báo minh bạch&lt;/h2&gt;

&lt;p&gt;Về mặt chất lượng âm thanh, cần có SI-SDR trên các cặp tổng hợp đã căn chỉnh thời gian, DNSMOS (hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;) trên tệp thực tế và ghi chú nghe thử. Về mặt hệ thống, cần báo cáo RTF p95 (hoặc nêu trung thực nếu mới chỉ đo được trung bình) cùng kết quả kiểm tra khởi tạo khi CDN bị chặn. Về trải nghiệm người dùng, cần xác nhận &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt; trả về đúng tín hiệu micro gốc và việc thiếu tài nguyên vẫn cho phép phát hành cuộc gọi. Mọi cột chưa thực hiện phải ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; kèm lý do; không bao giờ sao chép con số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13.80&lt;/code&gt; từ bài lab SI-SDR vào bảng sản phẩm rồi gán cho DeepFilterNet.&lt;/p&gt;

&lt;h2 id=&quot;bản-ghi-quyết-định-kỹ-thuật-dành-cho-người-duy-trì-kho-mã&quot;&gt;Bản ghi quyết định kỹ thuật dành cho người duy trì kho mã&lt;/h2&gt;

&lt;p&gt;Trình bày kết luận của bạn dưới dạng một bản ghi quyết định (decision record) ngắn gọn gồm 5 mục:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bối cảnh:&lt;/strong&gt; API công khai nào và nội dung chương nào đang được đề cập.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quyết định:&lt;/strong&gt; Mức khử nhiễu, cờ tính năng hoặc cấu trúc bộ công cụ đánh giá được chọn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Số liệu đánh giá:&lt;/strong&gt; Bảng 6 cột hoặc đường dẫn tới tệp báo cáo.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Các phương án đã loại bỏ:&lt;/strong&gt; Bao gồm cả lý do không chỉnh sửa kho sản phẩm chung.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phần chưa đo lường:&lt;/strong&gt; Các ngôn ngữ, thiết bị hoặc chỉ số ASR chưa bao phủ.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sơ đồ DeepFilterNet là nền tảng kỹ thuật của bản ghi này: nếu thay đổi chỉ nằm ở chính sách CDN, hãy nêu rõ bạn không can thiệp vào hệ số ERB hay các tap của bộ lọc sâu; nếu thay đổi nằm ở mức khử, hãy ghi rõ bạn chỉ điều chỉnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt; chứ không huấn luyện lại mạng.&lt;/p&gt;

&lt;h2 id=&quot;giới-hạn-phạm-vi-thực-hiện&quot;&gt;Giới hạn phạm vi thực hiện&lt;/h2&gt;

&lt;p&gt;Phiên bản tối thiểu khả thi (MVP) của dự án gồm: danh sách mẫu âm thanh đóng băng, một cột baseline, một thay đổi duy nhất và một báo cáo hoàn chỉnh. Phần mở rộng (stretch) có thể là đo thêm trên thiết bị thứ hai, chạy thêm một checkpoint DNSMOS cố định hoặc thử nghiệm nhánh Rust ở bài 09-03. Các công việc nằm ngoài phạm vi gồm: huấn luyện kiến trúc khử nhiễu mới, chạy suy luận đám mây trên âm thanh người dùng, và gửi bản vá trực tiếp vào kho sản phẩm chung.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Tạo tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hypothesis.md&lt;/code&gt; chứa đủ bốn nhãn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hypothesis:&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Experiment:&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Success:&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Fail:&lt;/code&gt;, đồng thời nêu rõ một API công khai và ít nhất một chỉ số ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, sau đó kiểm tra bằng đoạn mã sau:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hypothesis.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Hypothesis:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Experiment:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Success:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Fail:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;n/a&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;splitlines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nếu giả thuyết của bạn xoay quanh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; thay vì &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, hãy đổi từ khóa cuối trong danh sách &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;need&lt;/code&gt; cho khớp và ghi chú trong tệp.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt; (với đề tài điều chỉnh mức khử nhiễu):&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;missing none
lines &amp;lt;số dòng của bạn, ít nhất 8&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Viết giả thuyết nhưng thiếu tiêu chí thất bại; đặt điều kiện thành công chỉ gói gọn trong “SI-SDR tăng”; chỉnh sửa tệp trong kho sản phẩm chung làm bước triển khai; hoặc hiểu nhầm rằng sơ đồ ERB đòi hỏi bạn phải tự huấn luyện lại bộ lọc.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Viết một câu giả thuyết sẽ dùng để chấm điểm và tự kiểm tra xem một người ngoài có thể bác bỏ (falsify) câu đó bằng số liệu hay không.&lt;/li&gt;
  &lt;li&gt;Liệt kê tập số liệu baseline cần thu thập trước khi thay đổi cấu hình, bao gồm ít nhất một ô &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Chia đề tài của bạn thành phần MVP và phần mở rộng (stretch) trong 5 dòng ngắn gọn.&lt;/li&gt;
  &lt;li&gt;Tạo khung tiêu đề cho bản ghi quyết định kỹ thuật rồi điền trước hai mục &lt;em&gt;Bối cảnh&lt;/em&gt; và &lt;em&gt;Các phương án đã loại bỏ&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Chỉ vào một khối trên sơ đồ DeepFilterNet và nêu rõ dự án của bạn có tác động trực tiếp vào khối đó hay không.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Giả thuyết đạt chuẩn phải nêu rõ tham số điều chỉnh, điều kiện kiểm thử (bàn phím, quán cà phê, phòng yên) và chỉ số đo; câu chung chung kiểu “làm cho tốt hơn” không thể bác bỏ được.&lt;/li&gt;
  &lt;li&gt;Baseline có thể là mức 80 hoặc chế độ bypass trên cùng tập tệp; các đoạn ghi âm thực tế ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; ở cột SI-SDR do không có bản gốc sạch.&lt;/li&gt;
  &lt;li&gt;MVP gồm bảng số liệu 6 cột và kiểm thử AB; phần mở rộng gồm thiết bị thứ hai hoặc nhánh Rust; huấn luyện lại mô hình không nằm trong cả hai.&lt;/li&gt;
  &lt;li&gt;Mục &lt;em&gt;Các phương án đã loại bỏ&lt;/em&gt; nên bao gồm phương án “giữ nguyên không làm gì” và “vá trực tiếp vào kho sản phẩm chung”.&lt;/li&gt;
  &lt;li&gt;Chính sách chọn mức khử hoặc bộ công cụ đánh giá đều không thay đổi trực tiếp thuật toán tính gain ERB — hãy trình bày thẳng thắn điều này.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-Yxj3yfvY-4&quot;&gt;Short-Time Fourier Transform Explained Easily&lt;/a&gt; — Valerio Velardo - The Sound of AI, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Khung xử lý và bước nhảy (hop) là các kỹ thuật đo đạc được — nền tảng cốt lõi cần nắm trước khi triển khai dự án cuối khóa.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Chu trình đánh giá gồm dữ liệu, kiểm thử lắng nghe và chi phí tính toán tương ứng trực tiếp với cấu trúc thí nghiệm trong bài.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Trình bày cụ thể cơ chế kết hợp hệ số ERB và bộ lọc sâu kèm độ trễ thuật toán.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-01 Tour kiến trúc Mezon NS</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter09/09_01_mezon_architecture/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter09/09_01_mezon_architecture</id>
   <content type="html">&lt;p&gt;Bộ khử nhiễu Mezon (Mezon noise suppression) đóng vai trò tình huống nghiên cứu thực tế (case study), không phải một giáo trình riêng biệt. Luồng công khai gồm: micro trình duyệt, track âm thanh cục bộ của LiveKit, và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; từ gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; (phiên bản 1.3.0 trong khóa học này). Toàn bộ quá trình suy luận chạy trực tiếp trên thiết bị. Gói sẽ tải module WASM và gói nén ONNX DeepFilterNet3 từ đường dẫn gốc CDN mà bạn truyền qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;. Từ phiên bản ≥ 1.2.0 (gồm 1.3.0), gói tự động thêm tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;, nên hai tệp được tải là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;, với đường dẫn ví dụ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/code&gt;. Bộ trọng số sử dụng gói DeepFilterNet3 gốc của Rikorose. Khi làm bài tập, bạn không chỉnh sửa trực tiếp kho sản phẩm chung &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt;; hãy làm việc trên nhánh fork cá nhân hoặc thư mục công cụ đánh giá riêng.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;Đường publish LiveKit với DeepFilterNoiseFilterProcessor&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Luồng phát hành công khai: micro → &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; → &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; → mã hóa âm thanh → LiveKit. Tài nguyên CDN cấp cho processor; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; là hai điều khiển lúc chạy. Khi tải tài nguyên lỗi, hệ thống vẫn phát hành âm thanh gốc chưa xử lý.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ lần theo được đủ 8 bước công khai từ micro tới khi phát hành track, chỉ sử dụng đúng các API công khai của gói, ánh xạ từng khối kiến trúc về các chương trước, và viết được bản phác thảo kiến trúc rõ ràng để giảng viên hướng dẫn đánh giá mà không cần truy cập mã nội bộ.&lt;/p&gt;

&lt;h2 id=&quot;các-tên-giao-diện-công-khai&quot;&gt;Các tên giao diện công khai&lt;/h2&gt;

&lt;p&gt;Bề mặt API công khai gồm các thành phần sau:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Thành phần&lt;/th&gt;
      &lt;th&gt;Vai trò&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Processor dành cho LiveKit, duy trì đồ thị xử lý trên thiết bị&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Lớp lõi mức thấp dùng cho đồ thị Web Audio độc lập ngoài LiveKit&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Gắn processor vào track âm thanh cục bộ trước khi phát hành&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Điều chỉnh cường độ khử nhiễu trong lúc chạy&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Chuyển sang bypass mà không giả vờ mô hình đang hoạt động&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Đường dẫn gốc (base)&lt;/strong&gt; của CDN; không tự thêm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Mọi thông tin về truyền báo hiệu (signaling) của LiveKit có thể tra cứu tại &lt;a href=&quot;https://docs.livekit.io/&quot;&gt;docs.livekit.io&lt;/a&gt;. Processor không quản lý token, phòng họp hay SFU. Lớp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; là lựa chọn thay thế khi bạn không dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; của LiveKit — đây vẫn là một phần chính thức của cùng gói npm.&lt;/p&gt;

&lt;h2 id=&quot;tám-bước-trong-luồng-phát-hành-track&quot;&gt;Tám bước trong luồng phát hành track&lt;/h2&gt;

&lt;p&gt;Hãy đọc kỹ một lần rồi đóng lại để tự viết lại trong phần mini-lab:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Trang web xin quyền micro và nhận về đối tượng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStream&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Bọc luồng đó thành một track âm thanh cục bộ (local audio track) của LiveKit — đây là đối tượng sẽ tiếp nhận processor.&lt;/li&gt;
  &lt;li&gt;Khởi tạo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; (hoặc qua hàm factory &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilter(options)&lt;/code&gt;) và truyền vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt; ở dạng đường dẫn gốc không có hậu tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Gói phiên bản ≥ 1.2.0 (gồm 1.3.0) tự động tải &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; để gắn processor lên track, đảm bảo tín hiệu được khử nhiễu trước bước mã hóa.&lt;/li&gt;
  &lt;li&gt;Phát hành (publish) track vào phòng họp; SFU chỉ nhận dòng âm thanh đã mã hóa, không nhận thông tin cấu hình CDN.&lt;/li&gt;
  &lt;li&gt;Trong cuộc gọi, dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; (từ 0 đến 100) để thay đổi cường độ khử nhiễu mà không phải phát hành lại track.&lt;/li&gt;
  &lt;li&gt;Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt; để chuyển sang bypass; nếu tải WASM hoặc gói mô hình thất bại, hệ thống vẫn phải phát hành tín hiệu micro thô và hiển thị thông báo lỗi — một nút tham gia phòng bị treo không bao giờ là hành vi chấp nhận được.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Toàn bộ kiến trúc công khai chỉ gói gọn trong 8 bước trên. Module Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; không nằm trong sơ đồ này; đó là nhánh mở rộng tùy chọn ở bài 09-03, không phải yêu cầu bắt buộc.&lt;/p&gt;

&lt;h2 id=&quot;vai-trò-từng-tầng-và-liên-kết-kiến-thức&quot;&gt;Vai trò từng tầng và liên kết kiến thức&lt;/h2&gt;

&lt;p&gt;Tầng ứng dụng đảm nhiệm vòng đời phòng LiveKit (tham gia, tắt tiếng, rời phòng) theo phạm vi Chương 07. Tầng processor là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; cùng luồng callback âm thanh phải hoàn thành trong giới hạn render quantum (Chương 05). Tầng tài nguyên gồm module WASM và gói nén ONNX đặt trên CDN (Chương 06 và 07). Kiến trúc mô hình bên trong thuộc dòng DeepFilterNet3 từ &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt;, kết hợp tầng hệ số ERB và bộ lọc sâu trên phổ STFT (Chương 02 và 04). Hai điểm điều khiển chính là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, còn việc đánh giá chất lượng tuân theo Chương 08: SI-SDR khi có bản gốc sạch, DNSMOS khi không có, ghi chú nghe thử và RTF p95.&lt;/p&gt;

&lt;p&gt;Lưu ý rằng bộ khử nhiễu và khử vọng tích hợp sẵn của trình duyệt vẫn tồn tại song song với processor này. Nếu bật đồng thời cả hai bộ khử nhiễu, bạn sẽ không thể xác định bên nào đang làm mất phụ âm. Hãy luôn ghi rõ trạng thái ràng buộc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt; của trình duyệt trong bảng kiểm tra.&lt;/p&gt;

&lt;h2 id=&quot;mẫu-phác-thảo-kiến-trúc-gửi-giảng-viên-hướng-dẫn&quot;&gt;Mẫu phác thảo kiến trúc gửi giảng viên hướng dẫn&lt;/h2&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gu&quot;&gt;## Mezon NS — architecture sketch&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Goal: khử nhiễu uplink trên thiết bị cho họp LiveKit
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Data path: mic → setProcessor(DeepFilterNoiseFilterProcessor) → publish
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Asset của bản ≥ 1.2.0 gồm 1.3.0: {cdnUrl}/v2/pkg/df_bg.wasm và {cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Controls: setEnabled, setSuppressionLevel(0–100)
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Eval: SI-SDR trên cặp tổng hợp, DNSMOS hoặc n/a trên clip thật, ghi chú AB, RTF p95
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Non-goals: tải PCM lên mây để suy luận; sửa repo sản phẩm chung
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Stretch (tùy chọn): harness Rust df-core cá nhân, ghi passthrough cho đến khi có backend thật
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Chương&lt;/th&gt;
      &lt;th&gt;Câu hỏi bản phác thảo cần làm rõ&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;02&lt;/td&gt;
      &lt;td&gt;Tần số lấy mẫu và cấu hình khung/hop (không tự suy diễn API bộ đệm ẩn)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;03&lt;/td&gt;
      &lt;td&gt;Có đang bật song song AEC/NS của trình duyệt hay không&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;04&lt;/td&gt;
      &lt;td&gt;Lý do chọn DeepFilterNet3 và sự đánh đổi của thanh mức khử nhiễu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;05&lt;/td&gt;
      &lt;td&gt;Cách xử lý khi callback vượt hạn render quantum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;06&lt;/td&gt;
      &lt;td&gt;Cấu trúc WASM cùng gói ONNX, và quy tắc tự nối &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; từ bản ≥ 1.2.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;07&lt;/td&gt;
      &lt;td&gt;Quy trình gắn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; và cấu hình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;08&lt;/td&gt;
      &lt;td&gt;Chỉ số nào bắt buộc ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; trên bản ghi thực tế&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Soạn tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publish-path.md&lt;/code&gt; liệt kê đúng 8 bước đánh số từ bước lấy micro đến bước phát hành track, chỉ sử dụng các tên API công khai, sau đó chạy script kiểm tra:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;re&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;publish-path.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;findall&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;(?m)^\s*(\d+)\.\s+\S&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setEnabled&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;cdnUrl&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;df_bg.wasm&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;steps 8
missing none
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Thêm bước thứ 9 gọi tới một lớp nội bộ không công khai; đưa sẵn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; vào giá trị &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;; cho cuộc gọi dừng hẳn khi tải tài nguyên lỗi; mô tả Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; như yêu cầu bắt buộc; hoặc trỏ bài lab vào kho sản phẩm chung như một phần bài tập.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Viết lại bản phác thảo kiến trúc một trang bằng văn phong của riêng bạn, ghi đầy đủ URL tài nguyên.&lt;/li&gt;
  &lt;li&gt;Vẽ nhánh xử lý tình huống CDN bị chặn; ở nhánh này, luồng âm thanh nào vẫn được phát hành vào phòng?&lt;/li&gt;
  &lt;li&gt;Liệt kê 3 sự kiện telemetry hữu ích không chứa dữ liệu PCM (ví dụ mã phản hồi HTTP khi tải tài nguyên, thời gian khởi tạo theo mili giây, số lần bật/tắt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;).&lt;/li&gt;
  &lt;li&gt;Phân biệt rõ trường hợp nào trong thiết kế nên dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; và trường hợp nào dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Giải thích vì sao mọi thực nghiệm cần thực hiện trên fork cá nhân thay vì kho GitHub sản phẩm chung.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Ghi đủ cả hai tệp dưới nhánh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; và nêu rõ tiền tố này do gói tự động bổ sung.&lt;/li&gt;
  &lt;li&gt;Khi tải tài nguyên thất bại, ứng dụng phát hành trực tiếp tín hiệu micro gốc chưa lọc kèm thông báo lỗi, không chặn thao tác vào phòng.&lt;/li&gt;
  &lt;li&gt;Chỉ thu thập bộ đếm và thời lượng xử lý; tuyệt đối không gửi mẫu sóng hay bản ghi giọng nói trong cuộc họp.&lt;/li&gt;
  &lt;li&gt;Luồng phát hành trên LiveKit dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;; ứng dụng Web Audio tự dựng có thể gọi trực tiếp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Bài học chỉ dựa trên README và API công khai; các thay đổi thử nghiệm phải tách riêng trong fork cá nhân hoặc thư mục harness độc lập.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video trình bày kiến trúc STFT trên thiết bị và hệ số thời gian thực — chính là mô hình cốt lõi chạy bên trong đường truyền công khai của Mezon.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d2N0d6CKrbk&quot;&gt;Group calling architectures in WebRTC: MCU, SFU &amp;amp; P2P&lt;/a&gt; — Tsahi Levent-Levi, tiếng Anh. Giải thích cách SFU chuyển tiếp các track đã phát hành ở phía máy chủ.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Minh họa các yêu cầu thực tế mà một hệ thống khử nhiễu “trên thiết bị, trước mã hóa” phải đáp ứng trong sản phẩm gọi thoại.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-04 Bộ metric kiểu DNS Challenge</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter08/08_04_dns_challenge_metrics/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter08/08_04_dns_challenge_metrics</id>
   <content type="html">&lt;p&gt;Hãy thử tưởng tượng một buổi họp duyệt phát hành sản phẩm: kỹ sư ML tự tin chiếu lên màn hình một biểu đồ duy nhất — &lt;em&gt;“Bản mới tăng +1,2 dB SI-SDR so với bản cũ, đề nghị ship ngay chiều nay!”&lt;/em&gt; Nhưng khi đưa lên bảng tổng hợp đa chiều kiểu DNS Challenge, câu chuyện lập tức đảo ngược: bản mới làm &lt;strong&gt;tỉ lệ lỗi nhận dạng giọng nói (WER) tăng vọt&lt;/strong&gt;, thua nghe thử ở phòng yên tĩnh và đẩy &lt;strong&gt;RTF p95 lên 0,92&lt;/strong&gt; sát ngưỡng vỡ tiếng! Trong kỹ thuật âm thanh thực chiến, không có một chỉ số vạn năng nào — chỉ có một &lt;strong&gt;hệ thống bảng đo đa trục&lt;/strong&gt; đặt tất cả sự đánh đổi lên cùng một mặt bàn.&lt;/p&gt;

&lt;p&gt;Chỉ dựa vào một con số trung bình SI-SDR là cách nhiều bài báo được trích dẫn nhưng cũng là lý do khiến sản phẩm thực tế gặp sự cố ngoài dự kiến. Cuộc thi Microsoft DNS Challenge (&lt;a href=&quot;https://github.com/microsoft/DNS-Challenge&quot;&gt;microsoft/DNS-Challenge&lt;/a&gt;) cung cấp khuôn mẫu đánh giá công khai mà khóa học mô phỏng lại ở quy mô gọn nhẹ: gồm cặp dữ liệu tổng hợp (nơi các chỉ số xâm nhập có hiệu lực), bản ghi thực tế (nơi chỉ số xâm nhập không áp dụng được), lát cắt kiểm thử lắng nghe và cột hiệu năng hệ thống để chi phí thời gian thực không bị che khuất sau bảng chất lượng âm thanh. Do mỗi năm cuộc thi lại điều chỉnh danh mục chỉ số, bạn cần ghi rõ năm hoặc bài báo đang tham chiếu, và không tuyên bố “đạt chuẩn DNS Challenge” nếu chưa chạy đúng tập kiểm thử mù và quy trình của năm đó.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Cái bẫy ra quyết định bằng một con số duy nhất → Kiến thức cần nhớ (Đánh giá đa nhánh kiểu DNS Challenge, Kỷ luật trung thực &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; &amp;amp; Tái lập thực nghiệm, Tương tác với hệ thống hạ nguồn ASR &amp;amp; Cổng kiểm duyệt RTF) → 5 hạng mục đánh giá &amp;amp; Tổ chức thư mục &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eval/&lt;/code&gt; → Giải thích phân tích bảng đối chiếu 2 bản dựng thực chiến (vì sao bản SI-SDR cao hơn vẫn bị loại) → Khung báo cáo, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Bản đồ đánh giá cho cả bộ metric&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Hệ thống đánh giá là toàn bộ bản đồ chứ không phải một ô đơn lẻ: SI-SDR, DNSMOS, kiểm thử lắng nghe và RTF trả lời những câu hỏi khác nhau. Ô nào không áp dụng được thì ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, tuyệt đối không điền số ước đoán.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ xây dựng được bảng báo cáo 6 cột (mỗi hàng một đoạn âm thanh), chạy script kiểm tra tự động để bắt lỗi thiếu cột, giải thích chính xác ô nào bắt buộc ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, và phân biệt rõ ngưỡng sai số hồi quy nội bộ (epsilon) của phòng lab với các con số xuất hiện trong bài báo.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-thiết-kế-hệ-thống-đánh-giá-toàn-diện-evaluation-harness&quot;&gt;Kiến thức cần nhớ: Thiết kế hệ thống đánh giá toàn diện (Evaluation Harness)&lt;/h2&gt;

&lt;h3 id=&quot;1-kiến-trúc-đa-nhánh-kiểu-dns-challenge-synthetic--real--listening--systems&quot;&gt;1. Kiến trúc đa nhánh kiểu DNS Challenge (Synthetic + Real + Listening + Systems)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Khuôn khổ đánh giá kết hợp bốn góc nhìn không thể thay thế lẫn nhau: dữ liệu tổng hợp (đo SI-SDR/\(\Delta\)SI-SDR), dữ liệu thu thực tế (đo DNSMOS), nghe mù của con người (AB) và chi phí vận hành thời gian thực (RTF p95, thời gian khởi động lạnh).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Phát hiện mọi xung đột tối ưu hóa (ví dụ khử nhiễu quá tay giúp đẹp SI-SDR trên nhiễu dừng nhưng hỏng giọng thực tế hoặc vượt ngân sách CPU).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-tính-tái-lập-reproducibility-và-kỷ-luật-na&quot;&gt;2. Tính tái lập (Reproducibility) và Kỷ luật &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Lưu cố định dữ liệu (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;meta.csv&lt;/code&gt;), phiên bản gói (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.3.0&lt;/code&gt;), tệp nhị phân WASM/ONNX, checkpoint DNSMOS, hạt giống ngẫu nhiên và thiết bị đo; ghi tường minh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; cho mọi ô không hợp lệ (như SI-SDR trên bản ghi thật).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Đảm bảo hai bảng báo cáo cách nhau 3 tháng vẫn so sánh được chính xác từng hàng, không bị nhiễm số liệu bịa hay lẫn phiên bản runtime.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-đánh-giá-hạ-nguồn-downstream-asr--wercer-và-chống-quá-khớp-tập-holdout&quot;&gt;3. Đánh giá hạ nguồn (Downstream ASR — WER/CER) và Chống quá khớp tập Holdout&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Đo thêm tác động của bộ khử nhiễu lên tỉ lệ lỗi từ (WER) hoặc lỗi ký tự (CER) của một bộ nhận dạng giọng nói cố định, đồng thời giữ riêng một tập holdout gồm người nói và bối cảnh chưa từng mở ra khi tinh chỉnh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Bảo vệ các ứng dụng có phụ đề tự động / ghi chú họp AI khỏi những bộ lọc làm mượt tai người nhưng vô tình xóa mất âm cuối làm hỏng phiên âm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;các-hạng-mục-đánh-giá-cần-duy-trì&quot;&gt;Các hạng mục đánh giá cần duy trì&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Hạng mục (Track)&lt;/th&gt;
      &lt;th&gt;Dữ liệu đầu vào&lt;/th&gt;
      &lt;th&gt;Chỉ số hợp lệ&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Tổng hợp&lt;/td&gt;
      &lt;td&gt;Cặp tín hiệu ồn/sạch tự tạo&lt;/td&gt;
      &lt;td&gt;SI-SDR, PESQ/STOI (tùy chọn), mức cải thiện so với bypass&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Thực tế&lt;/td&gt;
      &lt;td&gt;Bản ghi cuộc họp thực, không có bản sạch&lt;/td&gt;
      &lt;td&gt;DNSMOS (khi cố định checkpoint), nếu chưa chạy thì ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lắng nghe&lt;/td&gt;
      &lt;td&gt;Cùng các điều kiện nhiễu, đoạn ngắn&lt;/td&gt;
      &lt;td&gt;Ghi chú kết quả AB: thắng, thua hoặc hòa&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hệ thống&lt;/td&gt;
      &lt;td&gt;Thiết bị dùng để trình diễn (demo)&lt;/td&gt;
      &lt;td&gt;RTF p95, kèm thời gian khởi tạo hoặc fallback nếu có đo&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hạ nguồn (tùy chọn)&lt;/td&gt;
      &lt;td&gt;Một phiên bản nhận dạng giọng nói (ASR) cố định&lt;/td&gt;
      &lt;td&gt;Độ chênh lệch WER hoặc CER (không thay thế MOS)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Dữ liệu tổng hợp mang lại khả năng điều chỉnh SNR linh hoạt và có tín hiệu tham chiếu chính xác, nhưng dễ tạo ảo giác lạc quan khi kho nhiễu quá “sạch” so với môi trường thật. Ngược lại, bản ghi thực tế phản ánh đúng sản phẩm nhưng không thể tính SI-SDR. Nguyên tắc cốt lõi là không tối ưu mô hình chỉ dựa trên một cột duy nhất, đồng thời đóng băng riêng một tập nghe thử cuối cùng mà bạn không mở ra trong lúc tinh chỉnh tham số.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-đọc-bảng-quyết-định-phát-hành-giữa-hai-bản-dựng-thực-chiến&quot;&gt;Giải thích: Đọc bảng quyết định phát hành giữa hai bản dựng thực chiến&lt;/h2&gt;

&lt;p&gt;Giả sử nhóm của bạn đang cân nhắc giữa &lt;strong&gt;Bản A (mặc định hiện tại, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level = 60&lt;/code&gt;)&lt;/strong&gt; và &lt;strong&gt;Bản B (ứng viên mới, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level = 85&lt;/code&gt; + mô hình nặng hơn chút)&lt;/strong&gt;. Dưới đây là kết quả gom đủ 5 trục (số liệu minh họa):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Tiêu chí đánh giá&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Bản A (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level 60&lt;/code&gt;)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Bản B (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level 85&lt;/code&gt;)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Chênh lệch (B so với A)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Tổng hợp — Quạt 10 dB (SI-SDR)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(14{,}50\text{ dB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(15{,}70\text{ dB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(+1{,}20\text{ dB}\)&lt;/strong&gt; (B thắng)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Thực tế — Quán cà phê (SI-SDR)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Đúng quy tắc (không có bản sạch)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Thực tế — Quán cà phê (DNSMOS BAK / SIG)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3{,}75\text{ / }3{,}50\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(4{,}00\text{ / }3{,}15\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;BAK \(+0{,}25\), nhưng SIG &lt;strong&gt;\(-0{,}35\)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Nghe thử AB — Phòng yên (\(N = 10\))&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Thắng 6, Hòa 2&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Thắng 2, Hòa 2&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;B thua 2–6&lt;/strong&gt; (cắt giọng sạch!)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Hạ nguồn ASR (WER)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(8{,}0\%\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(11{,}5\%\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Tăng &lt;strong&gt;\(+3{,}5\%\)&lt;/strong&gt; tuyệt đối (tăng \(43{,}8\%\) tương đối!)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Hệ thống — Laptop đích (RTF p95)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}58\) (dư \(4{,}2\text{ ms}\))&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}92\) (chỉ dư \(0{,}8\text{ ms}\))&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Cực sát trần underrun!&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Kết luận ra quyết định (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Decision&lt;/code&gt;):&lt;/strong&gt; &lt;strong&gt;KHÔNG SHIP Bản B&lt;/strong&gt; làm mặc định! Dù Bản B đẹp hơn ở cột SI-SDR tổng hợp (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+1,20 dB&lt;/code&gt;) và nền quán cà phê yên hơn (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BAK +0,25&lt;/code&gt;), bốn cột còn lại đồng loạt bật đèn đỏ: giọng phòng yên bị méo (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AB 2–6&lt;/code&gt;), phụ đề tự động lỗi tăng gần gấp rưỡi (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WER 8% → 11,5%&lt;/code&gt;) và ngân sách thời gian thực chỉ còn đúng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0,8 ms&lt;/code&gt; dự phòng cho hệ điều hành. Nếu không có bảng đa trục, một nhóm chỉ nhìn SI-SDR sẽ ship ngay một bản cập nhật tệ hơn cho người dùng!&lt;/p&gt;

&lt;h2 id=&quot;tổ-chức-thư-mục-bộ-công-cụ-đánh-giá-harness&quot;&gt;Tổ chức thư mục bộ công cụ đánh giá (harness)&lt;/h2&gt;

&lt;p&gt;Hãy đặt bộ công cụ đánh giá trong kho cá nhân hoặc nhánh fork của riêng bạn, không đưa vào kho sản phẩm chung &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;eval/
  datasets/synthetic/   # clean/, noisy/, meta.csv
  datasets/real/
  systems/bypass/
  systems/level60/
  systems/level80/
  scripts/compute_si_sdr.py
  reports/YYYY-MM-DD.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;meta.csv&lt;/code&gt; cần tối thiểu các cột &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clip_id,condition,snr_db,clean_path,noisy_path&lt;/code&gt;, trong đó các hàng bản ghi thực tế để trống cột &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clean_path&lt;/code&gt;. Để đảm bảo khả năng tái lập, phần đầu báo cáo phải ghi rõ phiên bản gói (ví dụ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0), tên tệp nén mô hình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;, tên checkpoint DNSMOS (hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not run&lt;/code&gt;), hệ điều hành và thiết bị đo RTF. Nếu quá trình xử lý mang tính tất định (deterministic), cần nêu rõ; nếu không, phải ghi lại giá trị hạt giống (seed).&lt;/p&gt;

&lt;p&gt;Không tồn tại ngưỡng SI-SDR hay DNSMOS chính thức nào để sao chép thẳng vào CI. Sau khi có số liệu nền (baseline) trên chính tập dữ liệu của mình, bạn có thể đặt một ngưỡng epsilon nội bộ cho kiểm thử hồi quy và ghi chú rõ nguồn gốc nội bộ đó — bảng số liệu trong bài báo khoa học không phải epsilon cho dự án của bạn.&lt;/p&gt;

&lt;p&gt;Với nhánh đánh giá ASR tùy chọn: cố định một phiên bản engine ASR, phiên âm cả bản gốc nhiễu lẫn bản đã khử nhiễu theo cùng cấu hình rồi báo cáo mức chênh lệch. Việc bộ khử nhiễu giúp tăng điểm DNSMOS nhưng lại làm xấu đi tỉ lệ lỗi từ (WER) là một thực tế sản phẩm quan trọng, không phải mâu thuẫn cần che giấu.&lt;/p&gt;

&lt;h2 id=&quot;khung-báo-cáo-đánh-giá&quot;&gt;Khung báo cáo đánh giá&lt;/h2&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gu&quot;&gt;## NS eval — &amp;lt;date&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; System: deepfilternet3-noise-filter &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;, setSuppressionLevel &lt;span class=&quot;nt&quot;&gt;&amp;lt;n&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; RTF p95: &lt;span class=&quot;nt&quot;&gt;&amp;lt;số&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;và&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;thiết&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;bị&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt; hoặc n/a

&lt;span class=&quot;gu&quot;&gt;### Per clip&lt;/span&gt;
(bảng sáu cột từ mini-lab)

&lt;span class=&quot;gu&quot;&gt;### Decision&lt;/span&gt;
Ship, không ship, hoặc ship sau cờ — và cột nào ép quyết định.

&lt;span class=&quot;gu&quot;&gt;### Limits&lt;/span&gt;
Ngôn ngữ, thiết bị, và metric bạn không chạy.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hiện tượng quá khớp (overfit) lộ rõ khi tập kiểm thử chỉ gồm giọng của chính tác giả, một bối cảnh quán cà phê duy nhất và một con số trung bình gộp không phân tách theo điều kiện. Ngoài ra, bất cứ khi nào thay đổi tệp WASM hoặc cấu hình SIMD, bạn phải chạy lại toàn bộ bộ đánh giá: kết quả khớp từng mẫu hiếm khi giữ nguyên khi đổi runtime, nên chỉ số chất lượng phải luôn gắn liền với đúng tệp nhị phân phát hành.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Tạo tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suite.md&lt;/code&gt; chứa bảng Markdown gồm đúng &lt;strong&gt;6 hàng dữ liệu&lt;/strong&gt;. Hàng tiêu đề bắt buộc có đủ 6 cột: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clip id&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;condition&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SI-SDR&lt;/code&gt; (hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DNSMOS&lt;/code&gt; (hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;listening note&lt;/code&gt;, và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTF p95&lt;/code&gt;. Ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; ở những ô không hợp lệ hoặc chưa chạy; đảm bảo có ít nhất một hàng là bản ghi thực tế (ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; ở cột SI-SDR) và ít nhất một hàng là cặp tổng hợp. Cột ghi chú lắng nghe dùng nhãn ngắn (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;old&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tie&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not listened&lt;/code&gt;), còn cột RTF p95 điền giá trị đo thực tế hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; nếu chưa đo.&lt;/p&gt;

&lt;p&gt;Kiểm tra tệp bằng script &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;check_suite.py&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;suite.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;splitlines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;tables&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;startswith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;header&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tables&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;clip id&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;condition&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;si-sdr&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;dnsmos&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;listening note&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rtf p95&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tables&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;data_rows&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;missing none
data_rows 6
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ví dụ minh họa cấu trúc một hàng (6 hàng trong bài làm phải là dữ liệu của riêng bạn):&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;| clip id | condition | SI-SDR or n/a | DNSMOS or n/a | listening note | RTF p95 |
| --- | --- | --- | --- | --- | --- |
| syn_fan_01 | synthetic fan, 10 dB | 13.80 | n/a | tie | 0.35 |
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Con số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13.80&lt;/code&gt; ở đây được lấy từ bài lab 08-01 nhằm minh họa định dạng cột, không phải số đo thực của DeepFilterNet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Đổi tên tiêu đề cột thành nhãn chung chung kiểu “quality” thay vì 6 tên quy định; điền thiếu số hàng (chỉ có 5 hàng); bịa số SI-SDR cho bản ghi thực tế; sao chép cùng một chỉ số RTF cho mọi hàng mà không ghi chú đó là số đo chung cả phiên; hoặc đặt ra ngưỡng nghe có vẻ chính thức kiểu “DNSMOS phải vượt 3,5”.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Hoàn thiện đủ 6 hàng trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suite.md&lt;/code&gt; kết hợp cả điều kiện tổng hợp và thực tế, sau đó chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;check_suite.py&lt;/code&gt; cho đến khi kết quả trả về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;data_rows 6&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Viết dòng tiêu đề cho tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;meta.csv&lt;/code&gt; kèm một dòng dữ liệu tổng hợp và một dòng dữ liệu thực tế.&lt;/li&gt;
  &lt;li&gt;Đề xuất một quy tắc báo lỗi (fail) trong CI mà không ngụy tạo thành ngưỡng chuẩn chính thức của DNSMOS.&lt;/li&gt;
  &lt;li&gt;Chỉ ra hai cách bộ chỉ số đánh giá dễ bị quá khớp với âm thanh cuộc họp Mezon, và nêu cách thiết lập tập kiểm thử giữ lại (holdout set) để ngăn chặn từng cách.&lt;/li&gt;
  &lt;li&gt;Bổ sung cột đánh giá ASR tùy chọn vào bảng và giải thích vì sao cột này vẫn không thể thay thế cột ghi chú lắng nghe.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Hàng bản ghi thực tế bắt buộc ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; ở cột SI-SDR; hàng chưa chạy mô hình DNSMOS thì ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; ở cột DNSMOS.&lt;/li&gt;
  &lt;li&gt;Với hàng bản ghi thực tế, để trống trường đường dẫn bản sạch (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clean_path&lt;/code&gt;) thay vì tự tạo tệp tham chiếu giả.&lt;/li&gt;
  &lt;li&gt;Ví dụ quy tắc minh bạch: “Trên tập golden set 12 đoạn này, báo lỗi CI nếu điểm trung bình DNSMOS theo từng điều kiện giảm quá mức epsilon đã ghi trong báo cáo” — khẳng định rõ epsilon là quy ước nội bộ.&lt;/li&gt;
  &lt;li&gt;Hai dạng quá khớp phổ biến là chỉ dùng giọng của tác giả và chỉ thử trên bối cảnh quán cà phê; khắc phục bằng cách giữ riêng một tập holdout gồm nhiều người nói khác cùng điều kiện bàn phím hoặc quạt không dùng trong lúc tinh chỉnh.&lt;/li&gt;
  &lt;li&gt;Tỉ lệ lỗi từ (WER) có thể tăng lên khi bộ khử nhiễu cắt hỏng phụ âm dù các chỉ số âm học khác vẫn cao; do đó vẫn cần duy trì cột ghi chú lắng nghe.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Phần giới thiệu cuộc thi DNS Challenge cho thấy cặp dữ liệu tổng hợp, kiểm thử lắng nghe và mô hình dự đoán khách quan luôn được báo cáo đồng thời thay vì dừng ở một điểm SI-SDR trung bình.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Phần trình bày về dữ liệu huấn luyện minh họa cách một mô hình cụ thể vận hành trên bộ dữ liệu DNS — chỉ nên xem là một dòng kết quả trong toàn bộ bảng đánh giá.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-03 Kiểm thử lắng nghe</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter08/08_03_listening_tests/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter08/08_03_listening_tests</id>
   <content type="html">&lt;p&gt;Trong giới kỹ thuật âm thanh có một câu đùa rất thật: &lt;em&gt;“Nếu muốn thuật toán mới của bạn thắng trong buổi nghe thử nội bộ, chỉ cần vặn âm lượng của nó to hơn bản cũ đúng 2 decibel!”&lt;/em&gt; Nghe có vẻ khó tin, nhưng đó là một thiên lệch tâm lý–thính giác đã được chứng minh hàng chục năm nay: tai người có xu hướng đánh giá âm thanh to hơn là “rõ hơn, đầy đặn hơn” — ngay cả khi chất lượng xử lý của nó tệ hơn. Nếu không kiểm soát chặt độ lớn âm lượng, không ẩn nhãn và không tách kết quả theo từng điều kiện, buổi nghe thử sẽ chỉ xác nhận lại định kiến sẵn có của chính bạn.&lt;/p&gt;

&lt;p&gt;Chỉ số SI-SDR có thể vẫn cao dù giọng nói nghe bị kim loại, còn DNSMOS có thể chấm lệch ngay trên miền dữ liệu người dùng thực tế. Bài kiểm thử lắng nghe (listening test) là trụ cột giúp phát hiện cả hai sai sót đó, với điều kiện bạn kiểm soát chặt độ lớn âm lượng (loudness), thứ tự phát và danh mục mẫu âm thanh. Bạn không cần một phòng lab đạt chứng nhận ITU để áp dụng kỷ luật này; điều quan trọng là có quy trình văn bản rõ ràng, ẩn nhãn hệ thống và bảng kết quả cho phép phương án mới có thể thua. Bài học này trình bày thiết kế bài kiểm thử mù AB (hoặc thang điểm kiểu MUSHRA thu gọn) dành cho nhóm kỹ sư đang cân nhắc thay đổi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Thiên lệch âm lượng trong nghe thử → Kiến thức cần nhớ (Thử nghiệm mù &amp;amp; Xáo trộn, Chuẩn hóa độ lớn LUFS/RMS, Thiết kế phân tầng &amp;amp; Kiểm tra tập trung) → Chọn giữa Dogfood, AB, ABC và MUSHRA thu gọn → Ma trận 5 điều kiện nhiễu &amp;amp; bảng kết quả thắng/thua/hòa → Giải thích tính tay hệ số chuẩn hóa âm lượng LUFS và bẫy gộp trung bình bảng AB → Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Bản đồ đánh giá với cột nghe người&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Kiểm thử lắng nghe là cột tốn thời gian nhất nhưng có giá trị quyết định, đóng vai trò phân xử khi SI-SDR và DNSMOS cho kết quả trái ngược nhau trên micro thực tế.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ chọn được hình thức đánh giá phù hợp giữa AB và thang kiểu MUSHRA thu gọn, chuẩn hóa độ lớn âm lượng, xáo trộn thứ tự mẫu, soạn hướng dẫn người nghe song ngữ Anh – Việt, báo cáo kết quả thắng/thua/hòa tách riêng theo từng điều kiện, và phân biệt được khi nào chỉ cần dùng thử nội bộ (dogfood) một ngày là đủ.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-kỷ-luật-khoa-học-thực-nghiệm-trong-đánh-giá-thính-giác&quot;&gt;Kiến thức cần nhớ: Kỷ luật khoa học thực nghiệm trong đánh giá thính giác&lt;/h2&gt;

&lt;h3 id=&quot;1-thiết-kế-mù-blinding-và-xáo-trộn-ngẫu-nhiên-randomization&quot;&gt;1. Thiết kế mù (Blinding) và Xáo trộn ngẫu nhiên (Randomization)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Ẩn hoàn toàn tên hệ thống (“Hệ 1 / Hệ 2” thay vì “DF3-80 / Cũ”) và đảo ngẫu nhiên vị trí A/B trên từng đoạn âm thanh để triệt tiêu hiệu ứng kỳ vọng (confirmation bias) và thói quen bấm một bên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Biến cảm nhận chủ quan thành dữ liệu thực nghiệm đáng tin cậy ngay cả ở quy mô nhóm 5–10 người trong văn phòng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-kiểm-soát-biến-nhiễu-vật-lý-chuẩn-hóa-độ-lớn-âm-lượng-loudness-normalization&quot;&gt;2. Kiểm soát biến nhiễu vật lý: Chuẩn hóa độ lớn âm lượng (Loudness Normalization)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Đưa tất cả các tệp so sánh về cùng một mức độ lớn tích hợp (integrated loudness, ví dụ \(-23\text{ LUFS}\) theo chuẩn phát thanh EBU R128) trước khi phát qua cùng một chuỗi thiết bị.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Loại bỏ thiên lệch “to hơn = hay hơn” và đảm bảo người chấm thực sự so sánh độ rõ phụ âm, độ tự nhiên và nhiễu nền chứ không so sánh mức khuếch đại đầu ra.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-phân-tầng-điều-kiện-stratified-reporting-và-attention-check&quot;&gt;3. Phân tầng điều kiện (Stratified Reporting) và Attention Check&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Thiết kế ma trận mẫu có cả mẫu đối chứng phòng yên tĩnh, lặp lại ngẫu nhiên 2 cặp đảo nhãn để sàng lọc người chấm mất tập trung, và báo cáo thắng/thua/hòa riêng cho từng điều kiện.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Ngăn chặn lỗi gộp trung bình che giấu điểm yếu nghiêm trọng (ví dụ thắng ở tiếng gõ phím nhưng lại làm méo giọng ở quán cà phê hay phòng yên tĩnh).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;chọn-quy-trình-khớp-với-quyết-định-kỹ-thuật&quot;&gt;Chọn quy trình khớp với quyết định kỹ thuật&lt;/h2&gt;

&lt;p&gt;Dùng thử nội bộ (dogfood) — bật bộ khử nhiễu ngay trong các cuộc họp hàng ngày — rất hiệu quả để bắt lỗi treo ứng dụng, CPU tăng vọt hoặc cảm giác khó chịu rõ rệt, nhưng không giúp ước lượng tỉ lệ ưa chuộng giữa hai cấu hình. Kiểm thử AB yêu cầu người nghe chọn thích mẫu A, thích mẫu B hoặc hòa trên từng cặp âm thanh; đây là công cụ chuẩn xác để so sánh mức khử 80 với mức 60, hoặc so sánh bật processor với chế độ bypass (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt;). Biến thể ABC bổ sung thêm mẫu neo (anchor) từ tín hiệu micro thô. Thang điểm kiểu MUSHRA (lấy cảm hứng từ chuẩn ITU-R BS.1534) cho phép chấm đồng thời nhiều hệ thống cùng mẫu neo nhưng đòi hỏi số người nghe lớn hơn. Tương tự, chuẩn ITU-T P.808 mô tả quy trình đánh giá giọng nói qua cộng đồng (crowdsourcing): hãy đọc để nắm vững nguyên tắc, rồi ghi nhận trung thực trong báo cáo rằng bạn đang chạy phiên bản thu gọn thay vì gắn mác “P.808” cho một buổi nghe thử 5 người trong văn phòng.&lt;/p&gt;

&lt;h2 id=&quot;kiểm-soát-biến-nhiễu-để-kết-quả-phản-ánh-đúng-bộ-khử-nhiễu&quot;&gt;Kiểm soát biến nhiễu để kết quả phản ánh đúng bộ khử nhiễu&lt;/h2&gt;

&lt;p&gt;Chênh lệch độ lớn âm lượng là nguồn thiên lệch kinh điển: nếu một tệp nhỏ tiếng hơn, người nghe được yêu cầu chấm độ “dễ chịu” có thể chọn nhầm nó ngay cả khi các âm xát đã bị mất. Vì vậy, cần chuẩn hóa độ lớn âm lượng tích hợp (integrated loudness) về cùng một mức đích và ghi rõ công cụ đã dùng. Xáo trộn ngẫu nhiên vị trí A/B trên từng đoạn âm thanh để mức khử mới không bao giờ cố định ở một bên; hiển thị nhãn ẩn như “Hệ 1” và “Hệ 2” thay vì “DF3-80”. Cố gắng dùng chung một loại tai nghe (hoặc ghi rõ thiết bị nghe nếu khác nhau), ưu tiên các đoạn dài 5–10 giây chứa nhiễu khó cùng phụ âm rõ nét thay vì đoạn dài cả phút gây mệt tai. Đường phát lại phải hoàn toàn đồng nhất: cùng trình duyệt, cùng tần số lấy mẫu, không chèn thêm bộ giới hạn biên độ (limiter) ở riêng một nhánh.&lt;/p&gt;

&lt;p&gt;Luôn đưa vào các đoạn giọng nói sạch làm mẫu đối chứng. Một cấu hình chỉ làm tốt ở quán cà phê nhưng lại làm méo giọng trong phòng yên tĩnh không đủ điều kiện làm giá trị mặc định. Tập mẫu cũng cần có ít nhất một loại nhiễu xung (gõ bàn phím) và một loại nhiễu đám đông (babble), tránh tối ưu quá khớp vào duy nhất một đoạn thu quán cà phê quen thuộc.&lt;/p&gt;

&lt;h2 id=&quot;thiết-kế-ma-trận-mẫu-thay-vì-gom-tệp-rời-rạc&quot;&gt;Thiết kế ma trận mẫu thay vì gom tệp rời rạc&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Loại nhiễu&lt;/th&gt;
      &lt;th&gt;Độ khó&lt;/th&gt;
      &lt;th&gt;Thiết bị thu&lt;/th&gt;
      &lt;th&gt;Vai trò trong ma trận&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Ồn quán cà phê&lt;/td&gt;
      &lt;td&gt;Khó&lt;/td&gt;
      &lt;td&gt;Micro laptop&lt;/td&gt;
      &lt;td&gt;Tạp âm nhiều giọng nói chồng lấn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Gõ bàn phím&lt;/td&gt;
      &lt;td&gt;Vừa&lt;/td&gt;
      &lt;td&gt;Laptop&lt;/td&gt;
      &lt;td&gt;Nhiễu xung; dễ bị cắt nhầm vào phụ âm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Quạt hoặc điều hòa&lt;/td&gt;
      &lt;td&gt;Dễ hơn&lt;/td&gt;
      &lt;td&gt;Điện thoại&lt;/td&gt;
      &lt;td&gt;Nhiễu dừng; kiểm tra băng thông khác&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tiếng giao thông&lt;/td&gt;
      &lt;td&gt;Khó&lt;/td&gt;
      &lt;td&gt;Điện thoại&lt;/td&gt;
      &lt;td&gt;Nhiễu tần số thấp kéo dài&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Phòng yên tĩnh&lt;/td&gt;
      &lt;td&gt;Đối chứng&lt;/td&gt;
      &lt;td&gt;Laptop&lt;/td&gt;
      &lt;td&gt;Phát hiện hiện tượng khử quá tay&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Một bài kiểm thử nhóm nhỏ thường gồm 8–15 đoạn âm thanh và 5–10 người chấm (luôn ghi rõ số lượng \(N\) trong bảng). Lặp lại ngẫu nhiên 2 đoạn với nhãn A/B đảo ngược làm bài kiểm tra mức độ tập trung (attention check); nếu người chấm tự mâu thuẫn trên cả hai cặp lặp, loại phiếu đó ra và ghi chú minh bạch. Khi người chấm sử dụng tiếng Việt, hãy dịch tờ hướng dẫn sang tiếng Việt tự nhiên với cùng hệ tiêu chí: ưu tiên phụ âm rõ ràng, giọng nói tự nhiên, ít tạp âm gây xao nhãng; đồng thời chấm trừ các lỗi giọng bị nghẹt, âm sắc robot hoặc mất từ, và dặn người nghe bỏ qua sai khác âm lượng nhỏ nếu còn sót.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tính-tay-hệ-số-chuẩn-hóa-âm-lượng-và-đọc-bảng-kết-quả-ab-phân-tầng&quot;&gt;Giải thích: Tính tay hệ số chuẩn hóa âm lượng và đọc bảng kết quả AB phân tầng&lt;/h2&gt;

&lt;h3 id=&quot;phép-tính-1-chuẩn-hóa-hai-tệp-lệch-3-db-về-cùng-mức-đích--23text-lufs&quot;&gt;Phép tính 1: Chuẩn hóa hai tệp lệch 3 dB về cùng mức đích \(-23\text{ LUFS}\)&lt;/h3&gt;
&lt;p&gt;Giả sử tệp A đo được độ lớn tích hợp \(L_A = -26\text{ LUFS}\) còn tệp B đo được \(L_B = -23\text{ LUFS}\). Nếu phát thẳng không chuẩn hóa, tệp B có công suất gấp \(10^{3/10} \approx \mathbf{2{,}0\text{ lần}}\) tệp A — người nghe sẽ thiên vị B ngay cả khi hai tệp giống hệt nhau!
Để đưa tệp A về đúng mức đích \(L_{\text{target}} = -23\text{ LUFS}\), ta nhân toàn bộ mẫu của tệp A với hệ số biên độ:
\(g_A = 10^{(L_{\text{target}} - L_A)/20} = 10^{(-23 - (-26))/20} = 10^{3/20} \approx \mathbf{1{,}4125}.\)
(Trước khi lưu WAV, kiểm tra thêm đỉnh cực đại \(\max_n \vert g_A x_A[n] \vert &amp;lt; 1{,}0\) để chắc chắn phép nhân không gây cắt ngọn / clipping!).&lt;/p&gt;

&lt;h3 id=&quot;phép-tính-2-vì-sao-không-bao-giờ-được-gộp-bảng-ab-thành-một-tỉ-lệ-thắng-duy-nhất&quot;&gt;Phép tính 2: Vì sao không bao giờ được gộp bảng AB thành một tỉ lệ thắng duy nhất?&lt;/h3&gt;
&lt;p&gt;Xét bảng kết quả ngay bên dưới (\(N = 10\) người chấm cho mỗi điều kiện, tổng \(30\) lượt chấm):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nếu gộp chung cả 3 hàng:&lt;/strong&gt; Mới thắng \(7 + 4 + 3 = \mathbf{14}\) lượt, Cũ thắng \(2 + 5 + 2 = \mathbf{9}\) lượt, Hòa \(1 + 1 + 5 = \mathbf{7}\) lượt. Nhìn con số tổng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;14–9–7&lt;/code&gt; (tỉ lệ thắng ròng 61% không tính hòa), nhiều người sẽ vội vã bấm nút phát hành!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khi tách riêng từng hàng:&lt;/strong&gt; Ở &lt;strong&gt;Quán cà phê&lt;/strong&gt;, hệ thống mới &lt;strong&gt;thua 4–5&lt;/strong&gt;! Nếu người dùng ứng dụng của bạn họp nhiều ở quán cà phê hoặc không gian mở, việc phát hành cấu hình này sẽ làm tệ đi chính kịch bản quan trọng nhất. Phân tầng giúp bạn quyết định đúng: giữ mặc định cũ hoặc thử một mức khử trung gian (ví dụ 70 thay vì 80).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;cách-trình-bày-báo-cáo-kết-quả&quot;&gt;Cách trình bày báo cáo kết quả&lt;/h2&gt;

&lt;p&gt;Với bài kiểm thử AB, hãy báo cáo đầy đủ số lượt ứng viên mới thắng, hệ nền (baseline) thắng và số lượt hòa — cả tổng thể lẫn tách riêng theo từng điều kiện. Trường hợp thắng ở tiếng bàn phím nhưng thua ở quán cà phê đòi hỏi quyết định phân nhánh rõ ràng: có thể phát hành mức khử thấp hơn làm mặc định kèm ghi nhận phần nhiễu quán còn lại, hoặc từ chối thay đổi mặc định; tuyệt đối không gộp tất cả các hàng thành một con số tỉ lệ thắng duy nhất. Nên đính kèm một mẫu minh họa có quyền phát công khai trong buổi demo (bài 09-05) kèm tên điều kiện cụ thể.&lt;/p&gt;

&lt;p&gt;Mẫu bảng tổng hợp phục vụ ra quyết định:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Điều kiện&lt;/th&gt;
      &lt;th&gt;Mới thắng&lt;/th&gt;
      &lt;th&gt;Cũ thắng&lt;/th&gt;
      &lt;th&gt;Hòa&lt;/th&gt;
      &lt;th&gt;N&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Bàn phím&lt;/td&gt;
      &lt;td&gt;7&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;10&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Quán cà phê&lt;/td&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;10&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Phòng yên&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;10&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Ở hàng phòng yên tĩnh, kết quả chủ yếu là “hòa” được xem là đạt yêu cầu vì bộ khử nhiễu không làm biến dạng giọng sạch; ngược lại, nếu phương án “cũ” thắng áp đảo ở hàng này thì cấu hình mới đang làm hao hụt giọng nói.&lt;/p&gt;

&lt;h2 id=&quot;khi-nào-dùng-thử-nội-bộ-dogfood-là-đủ&quot;&gt;Khi nào dùng thử nội bộ (dogfood) là đủ&lt;/h2&gt;

&lt;p&gt;Chỉ nên dừng ở bước dùng thử nội bộ đối với những thay đổi không làm biến đổi mẫu âm thanh đầu ra, chẳng hạn sửa cơ chế fallback CDN, thêm dòng log, chỉnh header cache hoặc bật cờ thử nghiệm nội bộ không tác động tới trải nghiệm mặc định. Ngược lại, bắt buộc phải chạy kiểm thử lắng nghe có cấu trúc khi đổi mức khử nhiễu mặc định, phát hành tệp WASM hoặc gói mô hình mới, hay điều tra phản hồi “giọng nghe lạ”. Ngay cả các tối ưu tốc độ RTF cũng chỉ được bỏ qua bước nghe thử nếu đầu ra khớp với tệp WAV chuẩn trong đúng dung sai đã quy định; một bản chạy nhanh hơn nhưng lệch mẫu đầu ra phải được xem là một hệ thống mới.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Soạn tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ab_protocol.md&lt;/code&gt; mô tả quy trình kiểm thử AB cho một thay đổi mức khử nhiễu (ví dụ so sánh mức 80 và mức 60 trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;), sau đó chạy script kiểm tra bên dưới. Bài lab đạt yêu cầu khi tài liệu đề cập rõ chuẩn hóa độ lớn âm lượng, ẩn nhãn (nghe mù), lựa chọn hòa, mẫu đối chứng yên tĩnh, các điều kiện nhiễu và hướng dẫn song ngữ.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ab_protocol.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;loudness&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;blind&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;tie&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;quiet&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;keyboard&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;cafe&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;vietnamese&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setsuppressionlevel&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;chars&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;missing none
chars &amp;lt;một số nguyên lớn hơn 400&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Độ dài ký tự phụ thuộc vào phần viết của bạn; dòng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;missing none&lt;/code&gt; xác nhận đạt chuẩn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Để lộ tên tệp trên giao diện chấm điểm; bỏ lựa chọn “hòa” khiến người nghe buộc phải đoán khi hai mẫu giống hệt nhau; thiếu mẫu đối chứng phòng yên; chỉ viết hướng dẫn tiếng Anh cho nhóm chấm tiếng Việt; hoặc chỉ đánh giá thay đổi mức khử trên giọng của duy nhất một người nói.&lt;/p&gt;

&lt;p&gt;Bản quy trình tối thiểu đạt chuẩn cần trình bày nhiệm vụ bằng cả hai ngôn ngữ, ghi rõ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; và liệt kê đủ ba điều kiện nhiễu; hãy viết thành hướng dẫn hoàn chỉnh theo cấu trúc bài học thay vì nhồi từ khóa.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Viết đoạn hướng dẫn người chấm bằng tiếng Anh và bản tiếng Việt tự nhiên tương ứng, giữ thống nhất toàn bộ các tiêu chí chấm trừ.&lt;/li&gt;
  &lt;li&gt;Liệt kê 9 tên tệp cho một ma trận 3×3 (tạp âm đám đông, bàn phím, phòng yên × laptop, điện thoại, tai nghe có micro).&lt;/li&gt;
  &lt;li&gt;Với kết quả: Bàn phím (mới thắng 7–2–1), Quán cà phê (4–5–1), Phòng yên (3–2–5), bạn sẽ chọn giữ mức mặc định nào và cần kiểm thử lại điều gì?&lt;/li&gt;
  &lt;li&gt;Xây dựng quy tắc kiểm tra mức độ tập trung (attention check) dựa trên một đoạn âm thanh lặp lại.&lt;/li&gt;
  &lt;li&gt;Nêu hai thay đổi sản phẩm không cần chạy quy trình nghe thử này, và một thay đổi bắt buộc phải chạy.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Tiêu chí chấm trừ gồm giọng bị nghẹt, âm sắc robot và mất từ; yêu cầu người nghe bỏ qua chênh lệch âm lượng nhỏ. Bản tiếng Việt cần diễn đạt tự nhiên như lời trao đổi với đồng nghiệp, tránh dịch sát từng chữ.&lt;/li&gt;
  &lt;li&gt;Mã hóa rõ điều kiện và thiết bị ngay trong tên tệp, ví dụ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;babble__laptop__01.wav&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Không phát hành chỉ vì thắng ở điều kiện bàn phím: kết quả thua ở quán cà phê và hòa ở phòng yên cho thấy nên giữ mặc định cũ hoặc kiểm thử thêm một mức trung gian, đồng thời nêu rõ lựa chọn cuối cùng.&lt;/li&gt;
  &lt;li&gt;Đảo ngược nhãn A/B trên bản lặp lại của cùng một đoạn; nếu người chấm chọn hai phương án trái ngược nhau thì đánh dấu không đạt kiểm tra tập trung.&lt;/li&gt;
  &lt;li&gt;Sửa cơ chế fallback CDN không làm đổi mẫu âm thanh thì chỉ cần dogfood; thay đổi giá trị mặc định của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; bắt buộc phải chạy kiểm thử lắng nghe.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Xem phần trình bày về đánh giá P.808 qua cộng đồng (tham chiếu, mẫu neo và sàng lọc người chấm) — nền tảng kỷ luật lắng nghe áp dụng ngay cả ở quy mô nhóm nhỏ.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02 DNSMOS và bộ dự đoán MOS không xâm nhập</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter08/08_02_dnsmos/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter08/08_02_dnsmos</id>
   <content type="html">&lt;p&gt;Khi một người dùng phàn nàn &lt;em&gt;“Họp ở quán cà phê hôm nay giọng tôi bị đục”&lt;/em&gt;, bạn mở bản ghi cuộc gọi đó lên và lập tức đụng phải một bức tường: &lt;strong&gt;không hề có tệp giọng gốc sạch \(s\)&lt;/strong&gt; để tính SI-SDR hay PESQ! Chẳng lẽ muốn chấm điểm mọi lần tinh chỉnh mô hình trên âm thanh thực tế, ta phải thuê hàng chục người ngồi nghe thủ công mỗi ngày? Câu trả lời thực dụng của cộng đồng tăng cường tiếng nói là huấn luyện chính một mạng nơ-ron để dự đoán điểm đánh giá của tai người chỉ từ bản ghi đầu ra — đó chính là &lt;strong&gt;DNSMOS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Các bản ghi cuộc gọi thực tế của người dùng không có tệp giọng gốc sạch đi kèm, nên SI-SDR không thể tính được trên chính dữ liệu bạn cần đánh giá. &lt;strong&gt;DNSMOS&lt;/strong&gt; là bộ dự đoán chất lượng không xâm nhập (non-intrusive) gắn liền với cuộc thi Microsoft Deep Noise Suppression Challenge: mô hình ước lượng điểm đánh giá chất lượng cảm nhận trung bình (MOS) chỉ từ tín hiệu sau khi khử nhiễu. Reddy, Gopal và Cutler công bố DNSMOS tại Interspeech 2021 và phiên bản mở rộng DNSMOS P.835 tại ICASSP 2022. Cả hai đều hữu ích để xếp hạng các đoạn âm thanh trong một miền dữ liệu cố định, nhưng không phải là ngưỡng đậu/rớt chính thức, và chênh lệch vài phần trăm điểm số không tự đủ để quyết định phát hành sản phẩm. Bài học này hướng dẫn cách cố định phiên bản mô hình, phân tích hiện tượng lệch miền làm sai lệch điểm số và cách kết hợp DNSMOS với ghi chú nghe thử.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Nút thắt thiếu bản gốc sạch trên dữ liệu thật → Kiến thức cần nhớ (Đánh giá không xâm nhập, Bộ ba thành phần P.835 SIG/BAK/OVRL, Lệch miền &amp;amp; Tập Golden Set đóng băng) → Vị trí của DNSMOS &amp;amp; 5 nguồn lệch miền → Giải thích tính tay hai cái bẫy: “làm đẹp trung bình bằng đoạn im lặng” và “BAK tăng nhưng SIG sập” → Phối hợp CI, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Bản đồ đánh giá: SI-SDR, DNSMOS và nghe người&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. DNSMOS nằm ở cột đánh giá không xâm nhập vì không cần tín hiệu sạch \(s\). Tuy nhiên, nó vẫn không thể thay thế bước nghe thử khi loại tạp âm hoặc ngôn ngữ nằm ngoài miền huấn luyện.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ xác định được đúng tình huống sử dụng DNSMOS (khi thiếu bản gốc sạch \(s\)), trích dẫn chính xác hai bài báo gốc mà không tự đặt ngưỡng tuyệt đối, thiết kế được một tập kiểm chuẩn nhỏ (golden set) để theo dõi &lt;strong&gt;mức biến động điểm&lt;/strong&gt; khi thay đổi mức khử nhiễu, và chỉ ra được các dạng lệch miền khiến điểm DNSMOS cao hơn nhưng lại dẫn đến quyết định sản phẩm sai.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-mô-hình-dự-đoán-cảm-thụ-không-xâm-nhập-hoạt-động-thế-nào&quot;&gt;Kiến thức cần nhớ: Mô hình dự đoán cảm thụ không xâm nhập hoạt động thế nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-đánh-giá-không-xâm-nhập-non-intrusive-quality-estimation&quot;&gt;1. Đánh giá không xâm nhập (Non-Intrusive Quality Estimation)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Một mạng học sâu được huấn luyện có giám sát trên hàng chục nghìn đoạn âm thanh đã được con người chấm điểm (theo chuẩn ITU-T P.808 / P.835), nhận đầu vào duy nhất là tín hiệu đã xử lý \(\hat{s}\) và xuất ra ước lượng điểm MOS trên thang 1–5.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Cho phép chấm điểm tự động các bản ghi cuộc gọi thực tế (nơi SI-SDR phải ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;), miễn nhiễm với sai lệch pha/trễ thời gian nhỏ — nhưng bản thân bộ dự đoán cũng là một mô hình thống kê có sai số.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-phân-tách-ba-chiều-của-dnsmos-p835-sig-bak-ovrl&quot;&gt;2. Phân tách ba chiều của DNSMOS P.835 (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SIG&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BAK&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OVRL&lt;/code&gt;)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Thay vì gộp thành một con số duy nhất, chuẩn P.835 tách cảm nhận thành ba trục độc lập: &lt;strong&gt;SIG&lt;/strong&gt; (độ rõ và tự nhiên của giọng nói), &lt;strong&gt;BAK&lt;/strong&gt; (độ sạch/yên tĩnh của nền nhiễu) và &lt;strong&gt;OVRL&lt;/strong&gt; (chất lượng tổng thể).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Phơi bày ngay đánh đổi cốt lõi của khử nhiễu: tăng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; quá mạnh làm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BAK&lt;/code&gt; tăng vọt nhưng kéo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SIG&lt;/code&gt; tụt sâu vì cắt hỏng giọng nói.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-lệch-miền-domain-shift-và-kỷ-luật-golden-set-đóng-băng&quot;&gt;3. Lệch miền (Domain Shift) và Kỷ luật Golden Set đóng băng&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Sai số hệ thống khi áp dụng bộ dự đoán (huấn luyện chủ yếu trên tiếng Anh, điều kiện challenge) lên tiếng Việt có thanh điệu, méo codec Opus bitrate thấp hoặc nhạc nền.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Thay vì tin vào điểm tuyệt đối, kỹ sư khóa cứng một tập kiểm chuẩn (golden set) đại diện và chỉ theo dõi &lt;strong&gt;độ chênh lệch theo từng điều kiện&lt;/strong&gt; giữa phiên bản mới và cũ, luôn đối chiếu với nghe thử mù.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;vị-trí-trong-hệ-thống-đánh-giá&quot;&gt;Vị trí trong hệ thống đánh giá&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tình huống&lt;/th&gt;
      &lt;th&gt;Có tham chiếu sạch?&lt;/th&gt;
      &lt;th&gt;Chỉ số áp dụng được&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Bản trộn tổng hợp kiểu DNS&lt;/td&gt;
      &lt;td&gt;Có&lt;/td&gt;
      &lt;td&gt;SI-SDR, kèm PESQ hoặc STOI nếu cài đặt thêm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bản ghi thực tế từ laptop hoặc điện thoại&lt;/td&gt;
      &lt;td&gt;Không&lt;/td&gt;
      &lt;td&gt;DNSMOS (đã cố định phiên bản) và ghi chú nghe thử&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Duyệt phát hành sản phẩm&lt;/td&gt;
      &lt;td&gt;Đôi khi có tập nhỏ gắn nhãn&lt;/td&gt;
      &lt;td&gt;Độ chênh lệch điểm dự đoán &lt;strong&gt;kết hợp&lt;/strong&gt; người nghe và RTF&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Dữ liệu, mô hình nền (baseline) và tập kiểm thử mù (blind set) của cuộc thi được lưu tại &lt;a href=&quot;https://github.com/microsoft/DNS-Challenge&quot;&gt;microsoft/DNS-Challenge&lt;/a&gt;. Lưu ý rằng từng năm tổ chức có bộ chỉ số đánh giá khác nhau. Khi đưa cột “DNSMOS” vào bảng kết quả, luôn ghi rõ biến thể đã chạy (DNSMOS kiểu P.808 hay DNSMOS P.835) cùng tên checkpoint; điểm số từ hai checkpoint khác nhau không thể gộp chung thành một chuỗi so sánh.&lt;/p&gt;

&lt;h2 id=&quot;đầu-ra-của-bộ-dự-đoán&quot;&gt;Đầu ra của bộ dự đoán&lt;/h2&gt;

&lt;p&gt;DNSMOS nhận vào một dạng sóng và trả về một điểm số vô hướng, hoặc bộ ba điểm thành phần ở biến thể P.835 (chất lượng giọng nói, mức nhiễu nền và chất lượng tổng thể). Do không có bản thu phòng thu đối chiếu, nó không phạt lỗi lệch thời gian như SI-SDR và cũng không cho ra \(\Delta\mathrm{SI\text{-}SDR}\). Cần cẩn thận vì mô hình vẫn sẵn sàng chấm điểm cho tệp gần như im lặng nếu bạn để tệp đó kéo lệch giá trị trung bình. DNSMOS là công cụ chạy theo lô ngoại tuyến (offline batch), không thay thế dữ liệu telemetry thời gian thực của Chương 05–07 như thời gian khởi tạo, cơ chế fallback khi CDN lỗi hay RTF trong callback âm thanh.&lt;/p&gt;

&lt;p&gt;Điểm mạnh của P.835 là tách riêng chất lượng giọng nói khỏi mức độ sạch của nền nhiễu — rất hữu ích để phát hiện trường hợp nền rất yên nhưng giọng lại bị mỏng. Hãy báo cáo đúng các thành phần đo được và tránh tự đặt quy tắc không chính thức kiểu “trên X là đạt”. Khóa học không quy định ngưỡng đạt tuyệt đối cho DNSMOS; nếu đội ngũ đặt một ngưỡng sai số hồi quy (epsilon) nội bộ, cần ghi rõ đó là quy ước riêng trên tập golden set có tên cụ thể, không phải chuẩn mực từ bài báo.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tự-tính-tay-hai-cái-bẫy-số-học-kinh-điển-khi-đọc-dnsmos&quot;&gt;Giải thích: Tự tính tay hai cái bẫy số học kinh điển khi đọc DNSMOS&lt;/h2&gt;

&lt;h3 id=&quot;bẫy-1-tệp-im-lặng-phù-phép-điểm-trung-bình-gộp-tăng-giả-tạo&quot;&gt;Bẫy 1: Tệp im lặng “phù phép” điểm trung bình gộp tăng giả tạo&lt;/h3&gt;
&lt;p&gt;Giả sử tập golden set ban đầu gồm 4 tệp thoại ồn có điểm OVRL lần lượt là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[3.10, 3.20, 3.00, 3.10]&lt;/code&gt;:
\(\overline{\text{OVRL}}_{\text{4 tệp thoại}} = \frac{3{,}10 + 3{,}20 + 3{,}00 + 3{,}10}{4} = \mathbf{3{,}10}.\)
Một người vô tình thêm vào thư mục 2 tệp gần như im lặng (không có giọng nói, nền sạch tuyệt đối) mà bộ dự đoán chấm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4.20&lt;/code&gt; mỗi tệp. Điểm trung bình gộp lập tức vọt lên:
\(\overline{\text{OVRL}}_{\text{6 tệp}} = \frac{12{,}40 + 2 \times 4{,}20}{6} = \frac{20{,}80}{6} \approx \mathbf{3{,}47} \quad (+0{,}37\text{ điểm ảo!}).\)
Không có một câu nói nào nghe hay hơn, nhưng báo cáo tổng lại trông như một bước nhảy vọt! Đó là lý do tập golden set phải được đóng băng và tách riêng từng điều kiện.&lt;/p&gt;

&lt;h3 id=&quot;bẫy-2-nhìn-bộ-ba-p835-sig--bak--ovrl-để-bắt-lỗi-khử-quá-tay&quot;&gt;Bẫy 2: Nhìn bộ ba P.835 (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SIG / BAK / OVRL&lt;/code&gt;) để bắt lỗi khử quá tay&lt;/h3&gt;
&lt;p&gt;So sánh hai mức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; trên cùng một bản ghi quán cà phê (số liệu minh họa):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Cấu hình&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SIG&lt;/code&gt; (Giọng nói)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BAK&lt;/code&gt; (Nền nhiễu)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OVRL&lt;/code&gt; (Tổng thể)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Nhận định kỹ thuật&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level = 60&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3{,}55\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3{,}80\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3{,}25\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Cân bằng tốt, giữ nguyên phụ âm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level = 95&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3{,}10\) (\(-0{,}45\))&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(4{,}15\) (\(+0{,}35\))&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3{,}05\) (\(-0{,}20\))&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Nền sạch hơn nhưng giọng bị bóp méo rõ rệt&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nếu chỉ nhìn độ sạch nền (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BAK&lt;/code&gt; tăng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+0.35&lt;/code&gt;), ta dễ tưởng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level = 95&lt;/code&gt; thắng áp đảo; chính cột &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SIG&lt;/code&gt; giảm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-0.45&lt;/code&gt; đã gióng hồi chuông cảnh báo buộc phải kiểm chứng bằng nghe mù AB!&lt;/p&gt;

&lt;h2 id=&quot;lệch-miền-là-nguồn-sai-số-chính&quot;&gt;Lệch miền là nguồn sai số chính&lt;/h2&gt;

&lt;p&gt;Các mạng DNSMOS được huấn luyện để khớp với điểm chấm của người nghe trên giọng nói và tạp âm thuộc bộ dữ liệu challenge, trong khi các cuộc họp trên Mezon sinh ra từ bối cảnh khác. Năm điểm gãy thường gặp gồm:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Ngôn ngữ và đặc trưng giọng nói.&lt;/strong&gt; Mô hình bám theo tập người nghe tiếng Anh có thể chấm lệch trên tiếng Việt có thanh điệu, giọng vùng miền hoặc đoạn nói chêm ngoại ngữ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ảnh hưởng của codec.&lt;/strong&gt; Âm thanh Opus ở bitrate thấp vốn có độ ráp riêng, và bộ dự đoán có thể quy nhầm độ ráp đó cho bộ khử nhiễu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tín hiệu phi giọng nói.&lt;/strong&gt; Âm nhạc, tiếng chuông thông báo và âm thanh chia sẻ màn hình nằm ngoài miền tối ưu của challenge.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khử nhiễu quá tay.&lt;/strong&gt; Một số bộ dự đoán ưu ái nền âm cực yên dù phụ âm đã bị cắt mất — điều người dùng thực tế khó chấp nhận.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Băng thông và tần số lấy mẫu.&lt;/strong&gt; Tệp 16 kHz và tệp 48 kHz mang đặc trưng đầu vào khác nhau; cần lấy mẫu lại theo một quy ước nhất quán hoặc báo cáo tách cột theo từng tần số lấy mẫu.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Giải pháp đáng tin cậy là đóng băng một tập golden set đa dạng gồm tiếng ồn quán cà phê, tiếng gõ bàn phím, tiếng quạt, phòng yên tĩnh và một đoạn có tiếng vọng dư nếu sản phẩm còn tồn tại vọng. Lưu cố định toàn bộ tệp WAV, phiên bản DNSMOS và câu lệnh xử lý, rồi theo dõi &lt;strong&gt;độ chênh lệch&lt;/strong&gt; so với phiên bản gói trước đó (như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0) theo từng điều kiện kèm số lượng mẫu rõ ràng. Điểm trung bình nhích lên chỉ vì thêm một tệp im lặng không phải là cải tiến mô hình.&lt;/p&gt;

&lt;h2 id=&quot;phối-hợp-các-cột-đánh-giá&quot;&gt;Phối hợp các cột đánh giá&lt;/h2&gt;

&lt;p&gt;Hãy dùng SI-SDR trên cặp tổng hợp khi có bản gốc (bài 08-01), dùng DNSMOS trên tập golden set thực tế, và thực hiện nghe thử mù AB hoặc MUSHRA thu gọn (bài 08-03) trên cùng các điều kiện đó trước khi thay đổi giá trị mặc định của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. Luôn đặt chỉ số RTF p95 ngay cạnh bảng chất lượng để thấy rõ ngay nếu một cấu hình có điểm MOS cao hơn nhưng lại làm trễ AudioWorklet. Chỉ nên phát hành khi điểm tập thực tế và kết quả nghe thử đồng thuận đồng thời ngân sách thời gian thực được đảm bảo; một đỉnh SI-SDR đơn lẻ trên tập tổng hợp chỉ là ghi nhận nghiên cứu, chưa đủ cơ sở phát hành.&lt;/p&gt;

&lt;p&gt;Phác thảo quy trình CI tham khảo khi có hạ tầng tự động hóa:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;khi thay đổi có thể đổi audio:
  dùng wav golden đã ghim
  enhance offline cùng mức và sample rate
  chạy checkpoint DNSMOS đã ghim
  tải CSV lên
  fail chỉ theo epsilon lab bạn đã ghi cho tập này
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Tránh để quy trình CI tải một kho nhiễu phình to không kiểm soát, và không cài điều kiện dừng build dựa trên một con số trích từ phần tóm tắt của bài báo — con số đó không phải epsilon của tập dữ liệu nội bộ bạn đang dùng.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Tạo tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dnsmos_plan.md&lt;/code&gt; cho một thư mục ghi âm thực tế không có tín hiệu tham chiếu sạch. Bài lab không yêu cầu tải và chạy trọng số DNSMOS (vốn là gói tải riêng cần cố định phiên bản); mục tiêu là lập kế hoạch đánh giá rõ ràng trong đó mọi tệp thực tế đều ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; ở cột SI-SDR và chỉ định một biến thể DNSMOS cụ thể.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;golden/
  cafe__laptop.wav
  keyboard__laptop.wav
  fan__phone.wav
  quiet__laptop.wav
dnsmos_plan.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Đưa bảng sau vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dnsmos_plan.md&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;| clip id | condition | SI-SDR | DNSMOS variant | why this clip can fool the predictor |
| cafe__laptop | babble, no clean ref | n/a | P.835 or the build you will pin | overlapping talkers |
| keyboard__laptop | key clicks | n/a | same build | impulsive noise, not the challenge average |
| fan__phone | stationary hum | n/a | same build | phone bandwidth |
| quiet__laptop | clean-speech control | n/a | same build | over-suppression on an already quiet file |
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Kiểm tra tệp vừa tạo bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 check_dnsmos_plan.py&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;dnsmos_plan.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;n/a&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;p.835&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;cafe__laptop&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;keyboard__laptop&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fan__phone&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;quiet__laptop&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;missing none
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Điền số SI-SDR cho bản ghi thực tế không có bản gốc sạch; trộn điểm P.835 với điểm vô hướng DNSMOS 2021 vào chung một trung bình; bỏ sót mẫu phòng yên tĩnh nên không phát hiện lỗi khử quá tay; hoặc xem một điểm tuyệt đối bất kỳ là ngưỡng chuẩn chính thức của Microsoft.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Viết 4 câu nêu chính sách sử dụng DNSMOS của đội ngũ, bao gồm việc cố định phiên bản, đường dẫn tập golden set và quy định không tự đặt ngưỡng chuẩn chính thức.&lt;/li&gt;
  &lt;li&gt;Nêu 3 tình huống lệch miền đáng kể đối với ứng dụng họp tiếng Việt dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, kèm quy ước đặt tên tệp cho từng tình huống.&lt;/li&gt;
  &lt;li&gt;Giả sử điểm trung bình trên golden set tăng 0,05 sau khi đổi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. Bạn cần yêu cầu thêm bảng số liệu nào trước khi kết luận đây là một cải tiến thực sự?&lt;/li&gt;
  &lt;li&gt;Giải thích vì sao chạy DNSMOS trên tệp trộn stereo hoặc tệp có một nửa thời lượng im lặng có thể cho điểm rất cao trong khi trải nghiệm cuộc gọi thực tế lại kém đi.&lt;/li&gt;
  &lt;li&gt;Cột nào phải ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; trên 4 tệp ghi âm thực tế, và cột nào phải ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; trên cặp tổng hợp khi chưa cài đặt trọng số DNSMOS?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Chạy cố định một biến thể có tên (DNSMOS hoặc DNSMOS P.835), theo dõi độ chênh lệch trên tập golden set đóng băng, và xác định mọi ngưỡng epsilon đều là quy ước nội bộ (bài báo của Reddy, Gopal và Cutler không đặt ngưỡng phát hành).&lt;/li&gt;
  &lt;li&gt;Ba lệch miền tiêu biểu: tiếng Việt có thanh điệu, méo do codec Opus, và tổ hợp tiếng quạt cộng bàn phím trên micro laptop; tên tệp nên mã hóa rõ loại nhiễu và thiết bị thu.&lt;/li&gt;
  &lt;li&gt;Cần xem bảng điểm chi tiết theo từng điều kiện kèm số lượng mẫu (không dùng một con số trung bình gộp), sau đó tiến hành nghe mù trên đúng điều kiện có biến động.&lt;/li&gt;
  &lt;li&gt;Bộ dự đoán chỉ chấm dựa trên dạng sóng nhận vào: phép trộn xuống mono (downmix) có thể che khuất kênh bị lỗi, còn các đoạn im lặng kéo dài sẽ làm lệch trung bình nếu không lọc trước.&lt;/li&gt;
  &lt;li&gt;Với tệp thực tế: cột SI-SDR ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. Với cặp tổng hợp khi chưa có checkpoint: cột DNSMOS ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. Không bao giờ điền số ước đoán vào các ô này.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Xem phần giới thiệu DNSMOS: mô hình dự đoán không xâm nhập được huấn luyện để bám sát điểm đánh giá của người nghe trong bối cảnh không có tín hiệu gốc sạch.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01 SI-SDR và metric xâm nhập liên quan</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter08/08_01_si_sdr/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter08/08_01_si_sdr</id>
   <content type="html">&lt;p&gt;Bạn vừa thử nghiệm một bản cập nhật mô hình khử nhiễu, chạy script đo &lt;strong&gt;SI-SDR&lt;/strong&gt; trên tập kiểm thử và chết lặng khi thấy điểm số rơi tự do từ &lt;strong&gt;+13,80 dB&lt;/strong&gt; xuống tận &lt;strong&gt;−10,67 dB&lt;/strong&gt;! Khoan vội xóa mô hình — rất có thể âm thanh đầu ra hoàn toàn bình thường, chỉ là bạn quên bù trừ độ trễ đúng &lt;strong&gt;1 mẫu&lt;/strong&gt; (20,8 micro giây ở 48 kHz)! Ngược lại, có những mô hình đạt SI-SDR rất đẹp nhưng khi đeo tai nghe vào lại nghe giọng bị bóp kim loại và mất sạch phụ âm gió.&lt;/p&gt;

&lt;p&gt;Các chỉ số đánh giá xâm nhập (intrusive metrics) chấm điểm dạng sóng đã tăng cường bằng cách đối chiếu trực tiếp với bản thu gốc sạch của cùng một câu nói. SI-SDR — do Le Roux, Wisdom, Erdogan và Hershey trình bày trong bài báo &lt;em&gt;“SDR – Half-baked or Well Done?”&lt;/em&gt; (ICASSP 2019) — thường là con số đầu tiên được tính trong các bài thực nghiệm tăng cường giọng nói. Tuy nhiên, chỉ số này chỉ trả lời một câu hỏi hẹp: sau khi triệt tiêu sai lệch hệ số khuếch đại (gain) toàn cục tối ưu, phần tín hiệu ước lượng còn sai khác so với bản tham chiếu bao nhiêu? Nó không cho biết giọng nói có bị méo kim loại hay không, phụ âm có bị mất không, và cũng không phản ánh ứng dụng họp trực tuyến có chạy kịp mô hình theo thời gian thực hay không. Bài học này trình bày công thức toán học, bài lab NumPy với giá trị kiểm chứng cụ thể, và các lỗi căn chỉnh thời gian khiến chỉ số này trở nên sai lệch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Cú sập −24 dB chỉ vì lệch 1 mẫu → Kiến thức cần nhớ (Phép chiếu trực giao trong không gian Hilbert, Bất biến tỉ lệ vs. Nhạy pha/trễ, Giới hạn cảm thụ của tỉ số năng lượng) → Công thức SDR → SI-SDR và \(\Delta\mathrm{SI\text{-}SDR}\) → Giải thích tính tay trọn vẹn từng bước ra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13.80 dB&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-10.67 dB&lt;/code&gt; bằng định lý Pythagoras → Danh mục căn chỉnh, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Bản đồ đánh giá: SI-SDR xâm nhập, DNSMOS không xâm nhập, và nghe người&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. SI-SDR thuộc nhóm đánh giá xâm nhập vì bắt buộc phải có tín hiệu tham chiếu sạch đã căn chỉnh thời gian. Mọi quyết định phát hành bộ khử nhiễu Mezon vẫn cần thêm DNSMOS hoặc ghi chú nghe thử, đi kèm hệ số thời gian thực (RTF).&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ tính được SI-SDR từ công thức phép chiếu, giải thích được vì sao phép nhân hệ số khuếch đại thuần túy không làm giảm điểm và vì sao chỉ lệch 1 mẫu cũng khiến điểm sụp đổ; đồng thời hình thành thói quen chỉ báo cáo SI-SDR trên các cặp tín hiệu đã căn chỉnh thời gian và không lấy điểm cao làm lý do bỏ qua bước nghe thử.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hình-học-tuyến-tính-phía-sau-chỉ-số-si-sdr&quot;&gt;Kiến thức cần nhớ: Hình học tuyến tính phía sau chỉ số SI-SDR&lt;/h2&gt;

&lt;h3 id=&quot;1-phân-rã-trực-giao-orthogonal-projection-trong-không-gian-tín-hiệu&quot;&gt;1. Phân rã trực giao (Orthogonal Projection) trong không gian tín hiệu&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Xem đoạn âm thanh \(N\) mẫu như một vector trong \(\mathbb{R}^N\), SI-SDR chiếu ước lượng \(\hat{s}\) lên đường thẳng sinh bởi tín hiệu sạch \(s\) để tách thành hai thành phần vuông góc nhau: \(s_{\mathrm{target}} = \alpha s\) và \(e_{\mathrm{noise}} = \hat{s} - \alpha s\) với \(\langle e_{\mathrm{noise}}, s \rangle = 0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Biến bài toán so sánh dạng sóng thành bài toán hình học góc \(\theta\) giữa hai vector: \(\mathrm{SI\text{-}SDR} = 10\log_{10}(\cot^2\theta)\). Nhờ đó, nhân toàn bộ tín hiệu với một hằng số dương (vặn to/nhỏ âm lượng) không làm đổi góc \(\theta\) nên điểm SI-SDR bất biến với gain toàn cục.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-tính-xâm-nhập-intrusive-và-độ-nhạy-tuyệt-đối-với-căn-chỉnh-thời-gian&quot;&gt;2. Tính xâm nhập (Intrusive) và Độ nhạy tuyệt đối với căn chỉnh thời gian&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Vì dùng tích vô hướng theo từng mẫu \(\sum_n \hat{s}[n] s[n]\), SI-SDR bắt buộc phải có bản thu sạch \(s\) trùng khớp từng mẫu thời gian với \(\hat{s}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Giải thích vì sao SI-SDR chỉ dùng được trên bản trộn tổng hợp (không dùng cho cuộc gọi thật) và bắt buộc phải bù trừ chính xác độ trễ STFT + look-ahead của DeepFilterNet trước khi chấm điểm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-giới-hạn-cảm-thụ-của-tỉ-số-năng-lượng-energy-ratio-blindness&quot;&gt;3. Giới hạn cảm thụ của tỉ số năng lượng (Energy-Ratio Blindness)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; SI-SDR chỉ đo tổng bình phương năng lượng phần dư \(\|e_{\mathrm{noise}}\|^2\) mà không phân biệt phần dư đó phân bố ở đâu trong phổ tần số hay thời gian.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Vì năng lượng giọng nói tập trung chủ yếu ở nguyên âm, một mô hình cắt hỏng phụ âm nhẹ hoặc tạo nhiễu nhạc năng lượng nhỏ vẫn có thể đạt SI-SDR cao — đòi hỏi phải ghép thêm DNSMOS (bài 08-02) và nghe thử (bài 08-03).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;tập-dữ-liệu-đánh-giá-xâm-nhập&quot;&gt;Tập dữ liệu đánh giá xâm nhập&lt;/h2&gt;

&lt;p&gt;Cần phân biệt rạch ròi ba tín hiệu: tín hiệu tham chiếu sạch \(s\), tín hiệu hỗn hợp thu từ micro \(x = s + n\) (dùng để tính SNR đầu vào và mức cải thiện \(\Delta\mathrm{SI\text{-}SDR}\), không phải tín hiệu tham chiếu), và đầu ra của bộ khử nhiễu \(\hat{s}\). SI-SDR so sánh \(s\) với \(\hat{s}\) ở cùng tần số lấy mẫu, cùng độ dài và cùng mốc thời gian. Với các mô hình kiểu DeepFilterNet, độ trễ thuật toán sinh ra từ hop STFT và cửa sổ nhìn trước (look-ahead) phải được bù trừ hoàn toàn trước khi tính tích vô hướng; chỉ cần lệch một hop cũng đủ đẩy năng lượng giọng nói sang thành phần sai số và làm điểm số tụt dốc mạnh.&lt;/p&gt;

&lt;h2 id=&quot;từ-sdr-đến-si-sdr&quot;&gt;Từ SDR đến SI-SDR&lt;/h2&gt;

&lt;p&gt;Chỉ số SDR cổ điển coi mọi sai lệch về biên độ (gain) đều là méo tín hiệu:&lt;/p&gt;

\[\mathrm{SDR} = 10 \log_{10} \frac{\| s \|^2}{\| \hat{s} - s \|^2}\]

&lt;p&gt;Nếu \(\hat{s} = 2s\), năng lượng phần dư bằng đúng năng lượng tín hiệu gốc khiến SDR rơi về 0 dB, dù về mặt cảm nhận âm thanh chỉ đơn thuần to hơn. SI-SDR khắc phục nhược điểm này bằng cách chiếu tín hiệu ước lượng lên tín hiệu tham chiếu trước — tương đương tìm hệ số khuếch đại vô hướng tối ưu theo bình phương tối thiểu:&lt;/p&gt;

\[s_{\mathrm{target}} = \frac{\langle \hat{s}, s \rangle}{\| s \|^2}\, s\]

\[e_{\mathrm{noise}} = \hat{s} - s_{\mathrm{target}}\]

\[\mathrm{SI\text{-}SDR} = 10 \log_{10} \frac{\| s_{\mathrm{target}} \|^2}{\| e_{\mathrm{noise}} \|^2}\]

&lt;p&gt;Trong đó, \(s_{\mathrm{target}}\) là thành phần của \(\hat{s}\) đồng dạng với \(s\) sau khi co giãn biên độ, còn mọi thành phần trực giao với \(s\) đều được tính là nhiễu và méo (\(e_{\mathrm{noise}}\)). Khi chỉ có sai lệch gain thuần túy, \(e_{\mathrm{noise}} = 0\) và tỉ số tiến tới \(+\infty\). Lưu ý rằng một số thư viện theo bài báo của Le Roux và cộng sự thực hiện bước trừ trung bình (zero-mean) cho từng véctơ trước khi chiếu. Bài lab này &lt;strong&gt;không&lt;/strong&gt; trừ trung bình để khớp chính xác với các con số kiểm chứng bên dưới; hàm có bước zero-mean sẽ không in ra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13.80&lt;/code&gt; trên cặp mẫu này.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tính-tay-từng-bước-cặp-số-1380-db-và--1067-db&quot;&gt;Giải thích: Tính tay từng bước cặp số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13.80 dB&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-10.67 dB&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;Hãy lấy giấy bút kiểm tra trực tiếp hai trường hợp trên vector \(s = [1{,}0,\; 0{,}0,\; -1{,}0,\; 0{,}5]\) (có năng lượng \(\|s\|^2 = 1^2 + 0^2 + (-1)^2 + 0{,}5^2 = \mathbf{2{,}25}\)).&lt;/p&gt;

&lt;h3 id=&quot;trường-hợp-1-đã-căn-chỉnh-thời-gian--hats--08-01--07-06&quot;&gt;Trường hợp 1: Đã căn chỉnh thời gian — \(\hat{s} = [0{,}8,\; 0{,}1,\; -0{,}7,\; 0{,}6]\)&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tích vô hướng và hệ số chiếu \(\alpha\):&lt;/strong&gt;
\(\langle \hat{s}, s \rangle = (0{,}8)(1) + (0{,}1)(0) + (-0{,}7)(-1) + (0{,}6)(0{,}5) = 0{,}8 + 0 + 0{,}7 + 0{,}3 = 1{,}80.\)
\(\alpha = \frac{1{,}80}{2{,}25} = \mathbf{0{,}8}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thành phần mục tiêu và phần dư trực giao:&lt;/strong&gt;
\(s_{\mathrm{target}} = 0{,}8\,s = [0{,}8,\; 0{,}0,\; -0{,}8,\; 0{,}4] \implies \|s_{\mathrm{target}}\|^2 = 0{,}8^2 \times 2{,}25 = \mathbf{1{,}44}.\)
\(e_{\mathrm{noise}} = \hat{s} - s_{\mathrm{target}} = [0{,}0,\; 0{,}1,\; 0{,}1,\; 0{,}2].\)
Kiểm tra nhanh tính trực giao: \(\langle e_{\mathrm{noise}}, s \rangle = 0 + 0 - 0{,}1 + 0{,}1 = \mathbf{0}\)! Năng lượng phần dư:
\(\|e_{\mathrm{noise}}\|^2 = 0^2 + 0{,}1^2 + 0{,}1^2 + 0{,}2^2 = \mathbf{0{,}06}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm SI-SDR:&lt;/strong&gt;
\(\mathrm{SI\text{-}SDR} = 10\log_{10}\left(\frac{1{,}44}{0{,}06}\right) = 10\log_{10}(24) \approx \mathbf{13{,}80\text{ dB}}.\)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;trường-hợp-2-dịch-trễ-đúng-1-mẫu--hats_mathrmdelay--00-08-01--07&quot;&gt;Trường hợp 2: Dịch trễ đúng 1 mẫu — \(\hat{s}_{\mathrm{delay}} = [0{,}0,\; 0{,}8,\; 0{,}1,\; -0{,}7]\)&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tích vô hướng và hệ số chiếu:&lt;/strong&gt;
\(\langle \hat{s}_{\mathrm{delay}}, s \rangle = (0)(1) + (0{,}8)(0) + (0{,}1)(-1) + (-0{,}7)(0{,}5) = -0{,}45 \implies \alpha = \frac{-0{,}45}{2{,}25} = \mathbf{-0{,}2}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Áp dụng định lý Pythagoras&lt;/strong&gt; (\(\|\hat{s}_{\mathrm{delay}}\|^2 = \|s_{\mathrm{target}}\|^2 + \|e_{\mathrm{noise}}\|^2\)):
    &lt;ul&gt;
      &lt;li&gt;\(\|\hat{s}_{\mathrm{delay}}\|^2 = 0^2 + 0{,}8^2 + 0{,}1^2 + (-0{,}7)^2 = 1{,}14\).&lt;/li&gt;
      &lt;li&gt;\(\|s_{\mathrm{target}}\|^2 = (-0{,}2)^2 \times 2{,}25 = \mathbf{0{,}09}\).&lt;/li&gt;
      &lt;li&gt;\(\|e_{\mathrm{noise}}\|^2 = 1{,}14 - 0{,}09 = \mathbf{1{,}05}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm SI-SDR:&lt;/strong&gt;
\(\mathrm{SI\text{-}SDR} = 10\log_{10}\left(\frac{0{,}09}{1{,}05}\right) = 10\log_{10}\left(\frac{3}{35}\right) \approx \mathbf{-10{,}67\text{ dB}}.\)
Chỉ trượt đúng 1 mẫu duy nhất, điểm SI-SDR đã bốc hơi tới &lt;strong&gt;24,47 dB&lt;/strong&gt;!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;cặp-số-kiểm-chứng-bằng-tay&quot;&gt;Cặp số kiểm chứng bằng tay&lt;/h2&gt;

&lt;p&gt;Xét \(s = [1, 0, -1, 0.5]\) và \(\hat{s} = [0.8, 0.1, -0.7, 0.6]\). Với hệ số chiếu \(\langle \hat{s}, s \rangle / \|s\|^2\), phần dư nhỏ nhưng khác 0 và SI-SDR đạt &lt;strong&gt;13.80 dB&lt;/strong&gt;. Nếu dịch tín hiệu ước lượng trễ đi đúng một mẫu thành \(\hat{s}_{\mathrm{delay}} = [0, 0.8, 0.1, -0.7]\), cùng công thức đó trả về &lt;strong&gt;−10.67 dB&lt;/strong&gt; dù cấu trúc phổ gần như không đổi mà chỉ lệch mốc thời gian. Vì vậy, mọi script đánh giá theo lô trong khóa học đều phải căn chỉnh thời gian xong rồi mới tính trung bình.&lt;/p&gt;

&lt;p&gt;Khi có thêm tín hiệu hỗn hợp đầu vào \(x\), nên báo cáo kèm mức cải thiện:&lt;/p&gt;

\[\Delta\mathrm{SI\text{-}SDR} = \mathrm{SI\text{-}SDR}(\hat{s}, s) - \mathrm{SI\text{-}SDR}(x, s)\]

&lt;p&gt;Một mô hình đạt 12 dB trên tệp vốn đã rất sạch vẫn có thể mang giá trị delta âm. Ngoài ra, SNR đầu vào của hỗn hợp là đại lượng khác vì nó so sánh \(s\) với nhiễu \(n\), không so sánh \(\hat{s}\) với \(s\).&lt;/p&gt;

&lt;h2 id=&quot;danh-mục-kiểm-tra-căn-chỉnh&quot;&gt;Danh mục kiểm tra căn chỉnh&lt;/h2&gt;

&lt;p&gt;Nên tạo tín hiệu tham chiếu ở đúng tần số lấy mẫu của mô hình (48 kHz với DeepFilterNet) và ghi chú rõ mọi thao tác lấy mẫu lại (resample). Cắt cả hai tín hiệu về cùng độ dài và ghi rõ cắt ở đầu hay cuối. Bù trừ độ trễ hop đã biết, hoặc ước lượng một lần trên đoạn hiệu chuẩn rồi cố định giá trị dịch đó. Luôn đối chiếu mono với mono. SI-SDR miễn nhiễm với sai lệch gain toàn cục, nhưng không miễn nhiễm với bộ nén động (compressor) làm biên độ phập phồng trong câu nói, cũng không bỏ qua tiếng vọng dư vốn không tồn tại trong bản tham chiếu khô.&lt;/p&gt;

&lt;h2 id=&quot;vì-sao-điểm-cao-vẫn-có-thể-nghe-kim-loại&quot;&gt;Vì sao điểm cao vẫn có thể nghe kim loại&lt;/h2&gt;

&lt;p&gt;SI-SDR suy cho cùng chỉ là tỉ số năng lượng sau khi nhân một hệ số vô hướng; nó không phân biệt được phần dư nằm ở phụ âm quan trọng hay nằm ở tạp âm nhiễu nhạc giữa các họa âm. Việc khử nhiễu quá tay có thể cắt mất các âm xát trong khi các nguyên âm biên độ lớn vẫn bảo toàn tốt về năng lượng. Tương tự, tín hiệu ước lượng còn vang khi so với bản tham chiếu khô sẽ bị phạt nặng dù sản phẩm không đặt mục tiêu khử vang. Các sự cố như cắt ngọn (clipping), trộn nhầm stereo hoặc bật thêm bước trừ trung bình đều làm thay đổi điểm số dù &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; không hề đổi. Đúng như sơ đồ đầu bài, SI-SDR chỉ là một cột trong hệ đánh giá; DNSMOS (bài 08-02) và ghi chú nghe thử (bài 08-03) là hai cột còn lại, còn RTF là cổng kiểm soát hiệu năng riêng. Khi áp dụng quy trình công khai, cần ghi rõ năm của DNS Challenge theo kho &lt;a href=&quot;https://github.com/microsoft/DNS-Challenge&quot;&gt;microsoft/DNS-Challenge&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hai chỉ số PESQ và STOI cũng thường xuất hiện trong báo cáo DNS và các bài báo DeepFilterNet; cả hai đều đòi hỏi tín hiệu tham chiếu đã căn chỉnh thời gian và đều không thể thay thế bước nghe trực tiếp khi giọng nói có cảm giác bị bóp méo.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Sử dụng hai véctơ cố định (không cần tải bộ dữ liệu). Lưu đoạn mã sau thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;si_sdr_lab.py&lt;/code&gt; và chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 si_sdr_lab.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;si_sdr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;estimate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;asarray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dtype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;estimate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;asarray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;estimate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dtype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;estimate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;estimate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s_hat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s_hat_delayed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;si_sdr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s_hat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;si_sdr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s_hat_delayed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;13.80
-10.67
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Các trường hợp lỗi nên tự thử một lần&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Bỏ qua dòng kiểm tra trễ mẫu sẽ tạo cảm giác mô hình nào cũng đạt quanh 14 dB; dòng in thứ hai chính là tín hiệu cảnh báo lỗi căn chỉnh thời gian.&lt;/li&gt;
  &lt;li&gt;Truyền hai véctơ khác độ dài khiến NumPy báo lỗi ở phép tích vô hướng; cần cắt độ dài tường minh.&lt;/li&gt;
  &lt;li&gt;Truyền nhầm hỗn hợp \(x\) vào vị trí của \(s\) vẫn trả về một số thực hợp lệ về mặt cú pháp, nhưng đó không phải SI-SDR của đầu ra khử nhiễu.&lt;/li&gt;
  &lt;li&gt;Đặt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;estimate = 2 * reference&lt;/code&gt;: năng lượng phần dư bằng 0 khiến &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log10&lt;/code&gt; phát cảnh báo hoặc trả về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inf&lt;/code&gt;. Đây là trạng thái khớp gain tuyệt đối chứ không phải lỗi công thức; không nên cộng hằng số epsilon tùy tiện rồi báo cáo kết quả 80 dB.&lt;/li&gt;
  &lt;li&gt;Gọi hàm SI-SDR từ thư viện ngoài có bước trừ trung bình: kết quả sẽ khác &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13.80&lt;/code&gt;. Cần giữ đúng phép chiếu của bài học hoặc ghi chú rõ biến thể đã dùng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Tính tay hệ số chiếu của cặp véctơ đầu tiên và kiểm chứng lại giá trị 13.80 dB bằng công thức \(10\log_{10}(\|s_{\mathrm{target}}\|^2 / \|e\|^2)\).&lt;/li&gt;
  &lt;li&gt;Tăng độ trễ từ 1 mẫu lên 2 mẫu (giữ nguyên độ dài 4 bằng cách đệm số 0 ở đầu và bỏ phần đuôi). Báo cáo SI-SDR mới và nhận xét mức độ suy giảm.&lt;/li&gt;
  &lt;li&gt;Xây dựng hỗn hợp \(x = s + 0.3\,[0.2, -0.2, 0.2, -0.2]\). Tính SI-SDR của \(x\) so với \(s\), của \(\hat{s}\) so với \(s\) và mức cải thiện delta. Con số nào thể hiện đúng “mức cải thiện”?&lt;/li&gt;
  &lt;li&gt;Viết 4 câu cho tệp README của dự án cuối khóa nêu rõ: khi nào báo cáo SI-SDR, khi nào ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, và vì sao một đoạn âm thanh nghe kim loại vẫn có thể đạt điểm cao.&lt;/li&gt;
  &lt;li&gt;Liệt kê các kiểm tra về tần số lấy mẫu và độ trễ cần làm trước khi lấy trung bình SI-SDR cho một mô hình DeepFilterNet có hop 10 ms ở 48 kHz.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(\langle \hat{s}, s \rangle = 0.8\cdot 1 + 0 + (-0.7)\cdot(-1) + 0.6\cdot 0.5 = 1.8\), \(\|s\|^2 = 2.25\), suy ra hệ số chiếu là \(1.8/2.25 = 0.8\). Tính tiếp phần chuẩn năng lượng trong NumPy sẽ thu được đúng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13.80&lt;/code&gt; dB.&lt;/li&gt;
  &lt;li&gt;Dịch trễ thêm thường tiếp tục làm điểm số giảm sâu hơn trên véctơ ngắn này vì tín hiệu ước lượng ít chồng khớp với \(s\) hơn; báo cáo đúng giá trị thực bạn tính được, không sao chép &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;−10.67&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Mức cải thiện delta bằng SI-SDR đầu ra trừ SI-SDR đầu vào, trong đó SI-SDR đầu vào phải tính giữa hỗn hợp \(x\) và tham chiếu \(s\).&lt;/li&gt;
  &lt;li&gt;Chỉ báo cáo SI-SDR cho các cặp tổng hợp có bản gốc sạch kèm giá trị dịch trễ đã ghi nhận; với các bản ghi cuộc gọi thực tế thì ghi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. Âm sắc kim loại nằm ở cấu trúc phân bố của phần dư — điều mà tỉ số năng lượng tổng của SI-SDR không phân biệt được.&lt;/li&gt;
  &lt;li&gt;Kiểm tra đồng nhất tần số 48 kHz, cùng độ dài, tín hiệu mono, và bù đúng độ trễ tối thiểu bằng độ dài hop (10 ms tương ứng 480 mẫu) cộng phần look-ahead nêu trong bài báo.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Xem phần thảo luận về các chỉ số khách quan: một con số duy nhất không phản ánh hết cảm nhận nghe trong cuộc gọi thực tế — đúng với giới hạn của SI-SDR đã phân tích trong bài.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-04 Bề mặt npm Mezon (kỹ thuật, không chỉ wrapper)</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter07/07_04_mezon_npm_surface/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter07/07_04_mezon_npm_surface</id>
   <content type="html">&lt;p&gt;Nếu chỉ nhìn qua đoạn code 10 dòng trên README — &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install deepfilternet3-noise-filter&lt;/code&gt;, tạo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new DeepFilterNoiseFilterProcessor(...)&lt;/code&gt;, gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; — rất dễ nảy sinh cảm giác rằng toàn bộ công việc khử nhiễu chỉ gói gọn trong việc “gọi một thư viện npm”. Nhưng khi có sự cố ngoài đời thực — tiếng vọng dội ngược, giọng nói mỏng đi ở mức 80, hay lỗi biên dịch trên Safari 16.3 — người chỉ biết gọi wrapper sẽ bó tay, còn người nhìn thấu từng phương thức công khai xuống tới đúng khái niệm DSP, AudioWorklet, WASM SIMD và CDN bên dưới sẽ biết ngay cần đo cái gì và sửa ở đâu.&lt;/p&gt;

&lt;p&gt;Gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; là công cụ đưa DeepFilterNet3 vào các ứng dụng LiveKit và Web Audio, chứ không phải toàn bộ nội dung cốt lõi của khóa học. Bài học này ánh xạ từng phương thức công khai của gói về đúng các khái niệm nền tảng như khung xử lý (frame), hệ số khuếch đại (gain), WASM, CDN và TrackProcessor của LiveKit, để dự án cuối khóa (capstone) tập trung cải tiến một kỹ thuật đo đạc được mà không cần can thiệp sửa đổi kho mã nguồn sản phẩm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Nhìn xuyên qua lớp wrapper npm → Kiến thức cần nhớ (Kiến trúc 3 tầng Core/Processor/Assets, Phân biệt Tham số sản phẩm vs. Đại lượng DSP, Quyết định Cấu hình vs. Bọc ngoài vs. Fork) → Giao diện API công khai &amp;amp; bảng ánh xạ kiến thức Chương 02–06 → Giải thích theo dõi luồng gọi hàm qua 4 thao tác người dùng và phân tích thang &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel&lt;/code&gt; 0–100 → Hướng mở rộng capstone, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;API processor công khai đứng trước đường publish TrackProcessor của LiveKit&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Giao diện npm cung cấp một TrackProcessor và một lớp core Web Audio, không phải một thuật toán khử nhiễu thứ hai.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ ánh xạ được từng lời gọi API công khai với kiến thức tương ứng trong khóa học, quyết định được khi nào chỉ cần cấu hình và khi nào bắt buộc phải fork kèm lập luận bảo trì rõ ràng, đồng thời xác định được các hướng mở rộng mà không cần chỉnh sửa mã nguồn gốc của gói.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-giải-phẫu-kiến-trúc-ba-tầng-của-một-gói-khử-nhiễu-web&quot;&gt;Kiến thức cần nhớ: Giải phẫu kiến trúc ba tầng của một gói khử nhiễu web&lt;/h2&gt;

&lt;h3 id=&quot;1-kiến-trúc-phân-tầng-core-deepfilternet3core-vs-adapter-deepfilternoisefilterprocessor-vs-assets&quot;&gt;1. Kiến trúc phân tầng: Core (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;) vs. Adapter (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;) vs. Assets&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Tầng lõi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; quản lý trực tiếp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletNode&lt;/code&gt;; tầng adapter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; bọc lớp lõi đó theo đúng giao diện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; của LiveKit; còn tầng tài nguyên (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;) nằm tách biệt trên CDN.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Tách bạch quyền sở hữu từng phương thức (ví dụ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; thuộc Processor, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled&lt;/code&gt; thuộc Core, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; thuộc LiveKit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack&lt;/code&gt;), giúp bạn dùng lại lớp lõi ngay cả trong ứng dụng WebRTC thuần không có LiveKit.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-tham-số-sản-phẩm-noisereductionlevel-0100-vs-đại-lượng-dsp-đo-đạc-được&quot;&gt;2. Tham số sản phẩm (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel&lt;/code&gt; 0–100) vs. Đại lượng DSP đo đạc được&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Con số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0–100&lt;/code&gt; trên giao diện là thanh trượt điều khiển độ sâu giới hạn suy giảm (attenuation limit / pha trộn wet-dry), &lt;strong&gt;không phải&lt;/strong&gt; chỉ số SI-SDR hay dB SNR mục tiêu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Luôn đánh giá mọi thay đổi tham số bằng thước đo khách quan và chủ quan (SI-SDR, DNSMOS, nghe mù A/B ở Chương 08) kết hợp phân vị p95 RTF trên thiết bị thật.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-kỷ-luật-kỹ-thuật-khi-nào-cấu-hình-khi-nào-bọc-ngoài-wrap-khi-nào-fork&quot;&gt;3. Kỷ luật kỹ thuật: Khi nào Cấu hình, khi nào Bọc ngoài (Wrap), khi nào Fork&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Khung ra quyết định kiến trúc cân nhắc giữa chi phí bảo trì dài hạn (tự gánh bản vá WASM/LiveKit khi fork) và nhu cầu thay đổi đồ thị mô hình.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Tập trung dự án capstone vào các cải tiến đo đạc được mà không sửa kho sản phẩm (bộ đo tự động, chính sách bypass theo RTF, mirror CDN, đối chiếu Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt;), và chỉ fork khi thật sự cần đổi cấu trúc đồ thị ONNX.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Tổng quan ba lớp: Core, TrackProcessor và tài nguyên (asset).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Bảng ánh xạ API sang kiến thức Chương 02–06.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Các tham số điều chỉnh: mức khử, bypass, CDN và SIMD.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Chiến lược cấu hình, bọc lớp trung gian hay fork.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab và ràng buộc cho dự án cuối khóa.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giao-diện-api-công-khai&quot;&gt;Giao diện API công khai&lt;/h2&gt;

&lt;p&gt;Cài đặt thư viện bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install deepfilternet3-noise-filter&lt;/code&gt; (với peer dependency &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;livekit-client&lt;/code&gt; ^2). Theo ghi chú trên README, mã nguồn worklet đã được nhúng nội tuyến dưới dạng blob URL nên các trình đóng gói hiện đại không cần cấu hình thêm plugin sao chép tệp.&lt;/p&gt;

&lt;h3 id=&quot;deepfilternoisefilterprocessor&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;Lớp triển khai giao diện TrackProcessor (móc biến đổi track của LiveKit) với thuộc tính &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;name&lt;/code&gt; là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tham số khởi tạo (constructor options): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enabled&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;static isSupported()&lt;/code&gt; — kiểm tra trình duyệt có hỗ trợ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly&lt;/code&gt; hay không.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; — khởi tạo hoặc dựng lại đồ thị xử lý 48 kHz trên một &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrack&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(level)&lt;/code&gt; — truyền mức khử nhiễu trong khoảng 0–100 xuống lớp core.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await setEnabled(boolean)&lt;/code&gt; — bật khử nhiễu hoặc chuyển sang bypass; trả về trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enabled&lt;/code&gt; sau khi cập nhật.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suspend&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt; — điều khiển trạng thái hoạt động của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; — giải phóng đồ thị xử lý và lớp core.&lt;/li&gt;
  &lt;li&gt;Cách gắn vào LiveKit: gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await audioTrack.setProcessor(filter)&lt;/code&gt;, sau đó gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilter(options)&lt;/code&gt; là hàm factory gọn nhẹ trả về một thể hiện của processor. Trong các đoạn mã học tập, nên ưu tiên dùng trực tiếp lớp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; để dễ theo dõi vòng đời đối tượng.&lt;/p&gt;

&lt;h3 id=&quot;deepfilternet3core&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;Đây là lớp lõi Web Audio được processor gọi bên dưới và cũng có thể sử dụng độc lập:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DeepFilterNet3Core&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DeepFilterNoiseFilter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;deepfilternet3-noise-filter&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// LiveKit: new DeepFilterNoiseFilterProcessor(opts) hoặc DeepFilterNoiseFilter(opts)&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DeepFilterNet3Core&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;sampleRate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;noiseReductionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;createAudioWorkletNode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 0–100&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setNoiseSuppressionEnabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;destroy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize&lt;/code&gt; tải và biên dịch tài nguyên; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt; sẽ ném lỗi nếu bạn bỏ qua bước khởi tạo này. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled(false)&lt;/code&gt; kích hoạt chế độ bypass ở tầng core (và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; của processor chính là lớp gọi lên phương thức này). &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; giải phóng node worklet cùng tài nguyên đã biên dịch.&lt;/p&gt;

&lt;p&gt;AudioWorklet (callback xử lý âm thanh trên luồng thời gian thực) chính là đối tượng node do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt; trả về.&lt;/p&gt;

&lt;h3 id=&quot;tệp-tài-nguyên&quot;&gt;Tệp tài nguyên&lt;/h3&gt;

&lt;p&gt;Tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; là bản dựng WASM (WebAssembly — mã nhị phân chạy trong trình duyệt) được biên dịch bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wasm-pack&lt;/code&gt; (có bật cờ SIMD từ bản ≥ 1.2.0), đi kèm gói mô hình nguồn gốc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;. Ghi chú phát hành bản 1.3.0 nêu việc nâng cấp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; lên &lt;strong&gt;0.23.3&lt;/strong&gt; cho đường WASM này. Cấu trúc đường dẫn CDN (mạng phân phối nội dung) được trình bày chi tiết ở bài 07-03. Kho mã nguồn: &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Lưu ý rằng SIMD (một lệnh xử lý nhiều dữ liệu) là thuộc tính của tệp nhị phân WASM khi biên dịch, không phải một tham số truyền vào constructor.&lt;/p&gt;

&lt;h2 id=&quot;ánh-xạ-api-về-kiến-thức-của-khóa-học&quot;&gt;Ánh xạ API về kiến thức của khóa học&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;API hoặc tệp tài nguyên&lt;/th&gt;
      &lt;th&gt;Kiến thức tương ứng trong khóa học&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt; 48 kHz&lt;/td&gt;
      &lt;td&gt;Chương 02: PCM và âm thanh giọng nói toàn dải&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Node AudioWorklet&lt;/td&gt;
      &lt;td&gt;Chương 05: ràng buộc callback thời gian thực&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Khung xử lý trong WASM&lt;/td&gt;
      &lt;td&gt;Chương 02 về hop; Chương 04 về băng ERB và deep filter&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel&lt;/code&gt; 0–100&lt;/td&gt;
      &lt;td&gt;Độ mạnh của hệ số suy giảm gain, không phải cam kết chỉ số SI-SDR&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; trên CDN&lt;/td&gt;
      &lt;td&gt;Chương 06 về đóng gói và bài 07-03&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;WASM SIMD ≥ 1.2.0&lt;/td&gt;
      &lt;td&gt;Chương 06; mức tăng tốc 20–30% nêu trong README&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Bài 07-01: điểm chèn A trên luồng gửi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await setEnabled(false)&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Chuyển sang bypass mà không cần phát hành lại track&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Trọng số INT8 (nếu lượng tử hóa offline)&lt;/td&gt;
      &lt;td&gt;Bài 06-02: thực hiện trước khi đăng tải lên CDN&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Gói không cung cấp phương thức công khai để đổi tên tensor đầu vào ONNX (định dạng trao đổi đồ thị), đổi phiên bản opset hay định tuyến sang máy chủ xử lý riêng. Nếu dự án cuối khóa yêu cầu đồ thị mô hình hoàn toàn mới, bạn cần fork hoặc dựng runtime riêng thay vì tìm một tùy chọn ẩn.&lt;/p&gt;

&lt;p&gt;Ngoài ra, phần mở rộng tùy chọn phía native sử dụng API xử lý khung bằng Rust (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt;) sẽ được giới thiệu ở Chương 09; không để phần mở rộng này cản trở tiến độ dự án cuối khóa trên trình duyệt.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-dò-luồng-gọi-hàm-qua-4-thao-tác-người-dùng-và-ý-nghĩa-toán-học-của-mức-khử-0100&quot;&gt;Giải thích: Dò luồng gọi hàm qua 4 thao tác người dùng và ý nghĩa toán học của mức khử 0–100&lt;/h2&gt;

&lt;h3 id=&quot;phép-dò-1-ai-gọi-ai-trong-4-sự-kiện-phòng-họp&quot;&gt;Phép dò 1: Ai gọi ai trong 4 sự kiện phòng họp?&lt;/h3&gt;
&lt;p&gt;Hãy theo dõi chính xác chuỗi cuộc gọi đi qua ba lớp (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LiveKit&lt;/code&gt; → &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Processor&lt;/code&gt; → &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Core&lt;/code&gt; → &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt;) để thấy vì sao không cần phát hành lại track khi điều chỉnh thông số:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Thao tác người dùng&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Lời gọi ứng dụng&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Chuỗi thực thi bên dưới&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Có cần thương lượng lại WebRTC?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1. Bật lọc lúc vào phòng&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audioTrack.setProcessor(filter)&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;LiveKit gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter.init&lt;/code&gt; → &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;core.initialize&lt;/code&gt; (CDN + WASM) → &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;core.createAudioWorkletNode&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Không (gắn trước &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt;)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2. Kéo thanh trượt 80 → 40&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter.setSuppressionLevel(40)&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;core.setSuppressionLevel(40)&lt;/code&gt; → gửi thông điệp nhỏ qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MessagePort&lt;/code&gt; tới worklet&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Không&lt;/strong&gt; (áp dụng ở ranh giới hop kế tiếp)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3. Bấm tắt lọc tạm thời&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await filter.setEnabled(false)&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;core.setNoiseSuppressionEnabled(false)&lt;/code&gt; → bật cờ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bypass&lt;/code&gt; trong worklet&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Không&lt;/strong&gt; (đồ thị vẫn sống)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;4. Cắm tai nghe USB mới&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;LiveKit đổi nguồn thiết bị&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;LiveKit gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter.restart({ track })&lt;/code&gt; → nối lại &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source&lt;/code&gt; mới vào đồ thị&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Chỉ thay track nguồn cục bộ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;phép-dò-2-đừng-nhầm-noisereductionlevel--80-với-cắt-80-nhiễu-hay-80-db-snr&quot;&gt;Phép dò 2: Đừng nhầm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel = 80&lt;/code&gt; với “cắt 80% nhiễu” hay “+80 dB SNR”!&lt;/h3&gt;
&lt;p&gt;Nếu mô hình gốc ước lượng một hệ số suy giảm gain \(g_{\text{model}} \in [0, 1]\) và sản phẩm áp đặt một ngưỡng sàn suy giảm (attenuation floor) \(g_{\min}\) tương ứng với mức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level&lt;/code&gt; \(L \in [0, 100]\) — ví dụ mô phỏng đơn giản theo thang giới hạn dB từ \(0\text{ dB}\) đến \(-30\text{ dB}\):
\(\text{Atten}_{\max}(L) = -0{,}3\,L\text{ dB}, \qquad g_{\min}(L) = 10^{\text{Atten}_{\max}(L)/20}.\)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Ở \(L = 40\): giới hạn cắt tối đa \(-12\text{ dB}\) (\(g_{\min} = 10^{-12/20} \approx 0{,}251\)) — giữ lại một phần nền âm êm để giọng nói tự nhiên.&lt;/li&gt;
  &lt;li&gt;Ở \(L = 80\): giới hạn cắt sâu xuống \(-24\text{ dB}\) (\(g_{\min} = 10^{-24/20} \approx 0{,}063\)) — nền rất sạch nhưng dễ làm lộ lỗi ước lượng ở vùng gain nhỏ (như bài 06-02).
(Công thức ánh xạ chính xác bên trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libDF&lt;/code&gt; có thể dùng tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;atten_lim_db&lt;/code&gt; riêng; ví dụ số này minh họa rõ vì sao tăng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L&lt;/code&gt; luôn là sự đánh đổi giữa độ sạch nền và độ tự nhiên của giọng nói!)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;phân-tích-các-tham-số-điều-chỉnh&quot;&gt;Phân tích các tham số điều chỉnh&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tham số&lt;/th&gt;
      &lt;th&gt;Tác động khi tăng/bật&lt;/th&gt;
      &lt;th&gt;Rủi ro đi kèm&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Mức khử nhiễu&lt;/td&gt;
      &lt;td&gt;Hạ thấp nền nhiễu sâu hơn&lt;/td&gt;
      &lt;td&gt;Giọng nghe mỏng, phát sinh nhiễu nhạc ở vùng gain gần 0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Trạng thái bật (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enabled&lt;/code&gt;)&lt;/td&gt;
      &lt;td&gt;Kích hoạt bộ khử nhiễu&lt;/td&gt;
      &lt;td&gt;Tăng tải CPU, tỏa nhiệt và thêm độ trễ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;CDN so với nhúng sẵn&lt;/td&gt;
      &lt;td&gt;Tận dụng cache chung, gói npm gọn hơn&lt;/td&gt;
      &lt;td&gt;Lượt tham gia đầu tiên phụ thuộc vào mạng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bản dựng SIMD&lt;/td&gt;
      &lt;td&gt;Giảm hệ số thời gian thực trên máy hỗ trợ&lt;/td&gt;
      &lt;td&gt;Trình duyệt Safari trước 16.4 báo lỗi không khởi tạo được&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Mọi thay đổi tham số cần được đánh giá cùng hệ thống đo lường của Chương 08 (SI-SDR trên bản trộn tổng hợp, DNSMOS hoặc bài nghe thử trên đoạn âm thực tế) kết hợp đo hệ số thời gian thực trên thiết bị cụ thể. Việc chỉ nâng phiên bản thư viện mà không có bảng số liệu đối chiếu không được tính là kết quả nghiên cứu.&lt;/p&gt;

&lt;h2 id=&quot;các-hướng-mở-rộng-không-cần-sửa-mã-nguồn-sản-phẩm&quot;&gt;Các hướng mở rộng không cần sửa mã nguồn sản phẩm&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Xây dựng bộ công cụ đánh giá tự động: đầu vào WAV, đầu ra WAV, tính toán SI-SDR và DNSMOS.&lt;/li&gt;
  &lt;li&gt;Thiết kế chính sách UX thông minh: tự động tắt khử nhiễu khi chuyển sang chế độ nhạc hoặc khi hệ số thời gian thực duy trì ở mức cao kéo dài.&lt;/li&gt;
  &lt;li&gt;Tự triển khai cấu trúc CDN và tối ưu hóa chính sách header cache.&lt;/li&gt;
  &lt;li&gt;Thu thập telemetry cho thời gian khởi tạo và nguyên nhân fallback (không tải âm thanh người dùng).&lt;/li&gt;
  &lt;li&gt;Lập bản thiết kế kế hoạch fork khi bộ nạp mặc định không đáp ứng được định dạng gói mô hình mới.&lt;/li&gt;
  &lt;li&gt;Phần mở rộng tùy chọn: đối chiếu tương đương API xử lý từng khung trên Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;khi-nào-nên-cấu-hình-và-khi-nào-nên-fork&quot;&gt;Khi nào nên cấu hình và khi nào nên fork&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tình huống&lt;/th&gt;
      &lt;th&gt;Phương án ưu tiên&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Đổi đường dẫn CDN, mức khử mặc định, giao diện bật/tắt&lt;/td&gt;
      &lt;td&gt;Cấu hình qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig&lt;/code&gt; và tham số constructor&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lỗi vòng đời hoặc sai khác phiên bản LiveKit&lt;/td&gt;
      &lt;td&gt;Báo lỗi lên kho gốc, hoặc viết một lớp bọc (wrapper) mỏng trong ứng dụng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đưa vào kiến trúc mô hình mới&lt;/td&gt;
      &lt;td&gt;Fork hoặc tạo gói mới; giữ đúng giấy phép Apache-2.0 hoặc MIT theo kho gốc&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bài tập và dự án khóa học&lt;/td&gt;
      &lt;td&gt;Thực hiện trên kho cá nhân hoặc kho Rust thử nghiệm, không sửa trực tiếp kho sản phẩm&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;đoạn-mã-tích-hợp-có-chú-thích-liên-kết-bài-học&quot;&gt;Đoạn mã tích hợp có chú thích liên kết bài học&lt;/h2&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// 07-01 điểm chèn A, local trước encode&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 07-03 CDN; &amp;gt;= 1.2.0 gồm 1.3.0 tự thêm v2/&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 05 AudioWorklet bên trong init&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 04 trọng số DeepFilterNet3 trong tar.gz&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;sampleRate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;noiseReductionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;assetConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;cdnUrl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;audioTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;room&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;localParticipant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;publishTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;audioTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Lưu đoạn mã sau thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;api_map.py&lt;/code&gt; và chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 api_map.py&lt;/code&gt;. Chương trình ánh xạ từng phương thức công khai về đúng lớp sở hữu nó trong phiên bản 1.3.0.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;calls&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;createAudioWorkletNode&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNet3Core&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;LiveKit LocalAudioTrack&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setEnabled&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setNoiseSuppressionEnabled&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNet3Core&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;isSupported&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sorted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;calls&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;calls&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;createAudioWorkletNode -&amp;gt; DeepFilterNet3Core
isSupported -&amp;gt; DeepFilterNoiseFilterProcessor
setEnabled -&amp;gt; DeepFilterNoiseFilterProcessor
setNoiseSuppressionEnabled -&amp;gt; DeepFilterNet3Core
setProcessor -&amp;gt; LiveKit LocalAudioTrack
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; trên lớp core (phương thức đúng của core là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled&lt;/code&gt;).&lt;/li&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled&lt;/code&gt; trên processor (phương thức đúng của processor là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;, và nên dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt;).&lt;/li&gt;
  &lt;li&gt;Nhầm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; là phương thức thuộc gói npm (thực tế đây là phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack.setProcessor&lt;/code&gt; của LiveKit).&lt;/li&gt;
  &lt;li&gt;Chỉnh sửa trực tiếp kho mã nguồn sản phẩm khi làm bài tập khóa học.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Làm dự án cuối khóa chỉ dừng ở mức nâng cấp phiên bản dependency.&lt;/li&gt;
  &lt;li&gt;Quy lỗi cho mô hình khi nguyên nhân thực sự của lỗi 404 CDN là lặp tiền tố đường dẫn.&lt;/li&gt;
  &lt;li&gt;Phân phối lại tệp trọng số mà chưa đọc kỹ điều khoản giấy phép nguồn gốc.&lt;/li&gt;
  &lt;li&gt;Đưa các commit thử nghiệm của khóa học vào thẳng kho mã nguồn sản phẩm.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Mở rộng bảng ánh xạ trong mini-lab với thêm 4 phương thức: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Đề xuất một cải tiến cho dự án cuối khóa không cần chỉnh sửa mã nguồn của gói, kèm chỉ số đánh giá cụ thể.&lt;/li&gt;
  &lt;li&gt;Đề xuất một cải tiến bắt buộc phải fork mã nguồn và giải thích vì sao tham số cấu hình không thể đáp ứng được.&lt;/li&gt;
  &lt;li&gt;So sánh mức khử nhiễu 40 và 80 trên cùng một đoạn ghi âm nhiều tạp âm; mô tả sự khác biệt nghe thấy ở các đoạn nền yên lặng.&lt;/li&gt;
  &lt;li&gt;Giải thích vì sao dù &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported()&lt;/code&gt; trả về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt;, bạn vẫn không được bỏ qua bước kiểm tra mốc trình duyệt Safari 16.4.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Ba phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; thuộc về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; (trong đó LiveKit gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;); &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; có mặt trên cả hai lớp, với processor chuyển tiếp giá trị xuống core.&lt;/li&gt;
  &lt;li&gt;Ví dụ: xây dựng mirror CDN, thiết lập chính sách bypass tự động theo RTF hoặc viết công cụ đo SI-SDR trên tập WAV; các chỉ số đánh giá tương ứng là độ chênh lệch SI-SDR, DNSMOS hoặc RTF p95.&lt;/li&gt;
  &lt;li&gt;Ví dụ: thay đổi tập toán tử hoặc cấu trúc gói mô hình mà bộ nạp hiện tại không hỗ trợ, bởi cấu hình công khai chỉ cho phép chỉnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt;, mức khử, trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enabled&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Mức 80 cắt nhiễu mạnh hơn nhưng dễ làm mỏng các phụ âm xát hoặc tạo nhiễu nhạc ở nền âm; mức 40 giữ giọng tự nhiên hơn nhưng để lọt nhiều nhiễu dư hơn.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported()&lt;/code&gt; chỉ kiểm tra sự hiện diện của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly&lt;/code&gt;, không kiểm tra hỗ trợ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; (bài 06-03); do đó Safari trước bản 16.4 vẫn báo lỗi biên dịch đối với bản dựng ≥ 1.2.0.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Trang npm &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;deepfilternet3-noise-filter&lt;/a&gt; và kho &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;GitHub&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Dự án gốc &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;DeepFilterNet&lt;/a&gt;, bao gồm bài báo Schröter và cộng sự (ICASSP 2022, arXiv:2110.05588).&lt;/li&gt;
  &lt;li&gt;Tài liệu LiveKit về &lt;a href=&quot;https://docs.livekit.io/transport/media/publish/&quot;&gt;TrackProcessor / setProcessor on LocalAudioTrack&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/sonos/tract&quot;&gt;tract&lt;/a&gt; và &lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;ONNX Runtime&lt;/a&gt; cho tầng runtime ở Chương 06.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Nghe trực tiếp hiệu quả xử lý của bộ khử nhiễu mà gói npm này tích hợp, giúp gắn kết các phương thức công khai với hành vi âm thanh thực tế.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d2N0d6CKrbk&quot;&gt;Group calling architectures in WebRTC: MCU, SFU &amp;amp; P2P&lt;/a&gt; — Tsahi Levent-Levi, tiếng Anh. Giải thích cơ chế chuyển tiếp track của SFU — bối cảnh phía LiveKit của bề mặt API.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=g1L4O1smMC0&quot;&gt;AudioWorklet :: What, Why, and How - Hongchan Choi&lt;/a&gt; — WebAudio PDX, tiếng Anh. Làm rõ giới hạn thời gian của luồng callback nơi processor phải trả về đúng hạn.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03 Tải mô hình qua CDN</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter07/07_03_cdn_model_loading/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter07/07_03_cdn_model_loading</id>
   <content type="html">&lt;p&gt;Hãy thử nghĩ xem chuyện gì xảy ra nếu bạn có 10.000 người dùng vào họp trực tuyến mỗi ngày và mỗi lần mở trình duyệt, ứng dụng lại đi tải mới 3,4 MB mô hình từ một máy chủ gốc duy nhất đặt ở nửa bên kia địa cầu: vừa tốn hàng chục gigabyte băng thông mỗi ngày, vừa khiến người dùng chờ dài cổ, lại chỉ cần một dòng cấu hình thiếu header CORS hay sai tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; là toàn bộ tính năng khử nhiễu biến mất không một dấu vết! Đó là lý do tầng &lt;strong&gt;tải tài nguyên qua CDN&lt;/strong&gt; là mạch máu thầm lặng của mọi sản phẩm AI chạy trên trình duyệt.&lt;/p&gt;

&lt;p&gt;Chạy DeepFilterNet3 trên trình duyệt đòi hỏi hai tệp nhị phân lớn: module &lt;strong&gt;WASM&lt;/strong&gt; (WebAssembly — mã nhị phân chạy trong trình duyệt) và gói trọng số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;. Nếu đóng gói cả hai vào tarball npm, kích thước cài đặt sẽ tăng vọt và mỗi lần cập nhật tệp mô hình đều buộc phải triển khai lại toàn bộ ứng dụng web. Do đó, các hệ thống thực tế tải chúng từ &lt;strong&gt;CDN&lt;/strong&gt; (mạng phân phối nội dung) để tận dụng lớp lưu đệm gần người dùng. Gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; tự động phân giải đường dẫn từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;. Bài học này giúp bạn tính chính xác 4 URL cho hai thế hệ 1.1.2 và 1.3.0, đồng thời đảm bảo một lỗi mạng khi tải tệp không làm gián đoạn cuộc gọi.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Băng thông &amp;amp; độ trễ khi phân phối mô hình AI trên web → Kiến thức cần nhớ (Phân phối biên CDN &amp;amp; HTTP Caching bất biến, Hợp đồng CORS &amp;amp; MIME &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;application/wasm&lt;/code&gt;, Tải song song &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Promise.all&lt;/code&gt; &amp;amp; Sẵn sàng tăng dần) → Cặp tệp tài nguyên &amp;amp; quy tắc đường dẫn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; → Giải thích tính tay tiết kiệm băng thông từ cache 80% và so sánh tải song song vs. tuần tự → Bảng xử lý 6 lỗi tải một phần, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;CDN tải WASM và kho ONNX trước khi AudioWorklet biên dịch&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Máy khách phân giải &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; thành một URL cho tệp WASM và một URL cho gói mô hình, sau đó mới biên dịch WASM.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ viết chính xác các URL đã phân giải cho phiên bản ≤ 1.1.2 và phiên bản 1.3.0 theo quy tắc README, không đưa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;, thiết lập header cache HTTP an toàn khi nâng cấp phiên bản, và cài đặt cơ chế bypass khử nhiễu khi thao tác tải gặp lỗi.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-phân-phối-mô-hình-ai-qua-cdn&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của phân phối mô hình AI qua CDN&lt;/h2&gt;

&lt;h3 id=&quot;1-mạng-phân-phối-biên-cdn-và-lưu-đệm-bất-biến-immutable&quot;&gt;1. Mạng phân phối biên (CDN) và Lưu đệm bất biến (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;immutable&lt;/code&gt;)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Hệ thống máy chủ đặt gần người dùng cuối (edge PoP) phục vụ các tệp tĩnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; kèm header &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control: public, max-age=31536000, immutable&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Biến bài toán tải nhiều megabyte mỗi cuộc gọi thành chi phí một lần duy nhất (0 ms mạng ở mọi lần gọi sau), đồng thời bảo vệ quyền riêng tư tuyệt đối vì CDN chỉ gửi trọng số một chiều xuống máy khách.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-hợp-đồng-giao-thức-trình-duyệt-cors-mime-và-tính-nguyên-tử-cặp-tệp&quot;&gt;2. Hợp đồng giao thức trình duyệt: CORS, MIME và Tính nguyên tử cặp tệp&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Ba điều kiện hạ tầng bắt buộc khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt; tài nguyên khác tên miền: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Access-Control-Allow-Origin&lt;/code&gt; (CORS), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Content-Type: application/wasm&lt;/code&gt; (MIME) và gom cặp WASM + trọng số vào cùng một thư mục phiên bản (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Chẩn đoán nhanh nguyên nhân thất bại lúc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; (404 do lặp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/v2/v2/&lt;/code&gt;, chặn CORS, lệch thế hệ WASM–mô hình) mà không đổ lỗi oan cho thuật toán lọc nhiễu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-sẵn-sàng-tăng-dần-progressive-readiness-với-promiseall&quot;&gt;3. Sẵn sàng tăng dần (Progressive Readiness) với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Promise.all&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Tải song song cả hai tệp trên kết nối HTTP/2, tách biệt khỏi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;room.connect()&lt;/code&gt;, và chuyển êm về bypass/APM khi tải đứt đoạn thay vì treo giao diện.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Tối ưu hóa thời gian khởi động lạnh và độ tin cậy vận hành trên mạng di động chập chờn hoặc mạng doanh nghiệp có tường lửa (mirror nội bộ VPC).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Hai tệp tài nguyên cần tải và thời điểm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; thực hiện tải.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Cấu hình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; và quy tắc tiền tố phiên bản.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Chính sách cache, kiểu MIME và cấu hình CORS.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Trạng thái sẵn sàng tăng dần mà không chặn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab: tính 4 URL chuẩn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;cặp-tệp-tài-nguyên&quot;&gt;Cặp tệp tài nguyên&lt;/h2&gt;

&lt;p&gt;Theo README của gói, có hai tệp chính:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tệp tài nguyên&lt;/th&gt;
      &lt;th&gt;Vai trò&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pkg/df_bg.wasm&lt;/code&gt; (dưới base hoặc dưới &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;)&lt;/td&gt;
      &lt;td&gt;Module WASM (có bật SIMD ở các phiên bản hỗ trợ)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Gói mô hình DeepFilterNet3 từ kho nguồn gốc&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Đường dẫn kho nguồn gốc: &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet/blob/main/models/DeepFilterNet3_onnx.tar.gz&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/a&gt;. Lưu ý rằng CDN chỉ phân phối &lt;strong&gt;trọng số và mã nhị phân&lt;/strong&gt;, hoàn toàn không tiếp nhận âm thanh người dùng; mọi bước suy luận đều diễn ra cục bộ trên thiết bị, không bao giờ thêm tính năng tải PCM lên máy chủ “để gỡ lỗi” trên bản sản phẩm.&lt;/p&gt;

&lt;p&gt;Trong cặp tệp này, đồ thị ONNX (định dạng trao đổi đồ thị) nằm trong tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tar.gz&lt;/code&gt;, còn tối ưu SIMD (một lệnh xử lý nhiều dữ liệu) nằm trong tệp WASM; AudioWorklet (callback xử lý âm thanh trên luồng thời gian thực) chỉ bắt đầu hoạt động sau khi cả hai tệp đã tải xong.&lt;/p&gt;

&lt;h2 id=&quot;cấu-hình-đường-dẫn-gốc&quot;&gt;Cấu hình đường dẫn gốc&lt;/h2&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;sampleRate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;noiseReductionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;assetConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;cdnUrl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nếu bỏ qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;, gói sẽ dùng mặc định chính đường dẫn gốc của Mezon như trên. Khi dựng máy chủ lưu trữ riêng (mirror), bạn chỉ cần thay tên miền gốc và tiền tố đường dẫn tương ứng.&lt;/p&gt;

&lt;h3 id=&quot;quy-tắc-đường-dẫn-theo-phiên-bản&quot;&gt;Quy tắc đường dẫn theo phiên bản&lt;/h3&gt;

&lt;p&gt;README quy định rõ cấu trúc đường dẫn phân giải cho từng dải phiên bản:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phiên bản gói&lt;/th&gt;
      &lt;th&gt;Đường dẫn đã phân giải&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;≤ 1.1.2&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/pkg/df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;≥ 1.2.0, gồm 1.3.0&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Với phiên bản ≥ 1.2.0 (bao gồm 1.3.0), chính thư viện sẽ tự động nối thêm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;; tuyệt đối không tự chèn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;. Đường dẫn gốc ví dụ công khai là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/code&gt;. Cũng theo README, bản dựng SIMD từ 1.2.0 trở lên nhanh hơn khoảng 20–30% (số liệu công bố từ README) và yêu cầu trình duyệt Chrome 91+, Firefox 89+ hoặc Safari 16.4+. Riêng bản 1.3.0 cập nhật &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; lên 0.23.3 cho đường WASM, nhưng thay đổi này không làm đổi quy tắc tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tính-tay-lợi-ích-của-tải-song-song-promiseall-và-cache-bất-biến&quot;&gt;Giải thích: Tính tay lợi ích của tải song song &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Promise.all&lt;/code&gt; và Cache bất biến&lt;/h2&gt;

&lt;h3 id=&quot;phép-tính-1-tải-song-song-vs-tải-tuần-tự-trên-kết-nối-độ-trễ-cao&quot;&gt;Phép tính 1: Tải song song vs. Tải tuần tự trên kết nối độ trễ cao&lt;/h3&gt;
&lt;p&gt;Giả sử cặp tệp nén có dung lượng minh họa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; = \(1{,}2\text{ MB}\) (\(9{,}6\text{ Mb}\)) và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; = \(2{,}2\text{ MB}\) (\(17{,}6\text{ Mb}\)), tổng \(27{,}2\text{ Mb}\), trên mạng 4G có băng thông \(10\text{ Mbps}\) và độ trễ vòng (RTT) \(100\text{ ms}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tải tuần tự (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await fetch(wasm); await fetch(model)&lt;/code&gt;):&lt;/strong&gt; Chịu 2 lần RTT nối tiếp cộng thời gian truyền:
\(T_{\text{seq}} = 2 \times 0{,}10 + \frac{9{,}6 + 17{,}6}{10} = 0{,}20 + 2{,}72 = \mathbf{2{,}92\text{ s}}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tải song song (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Promise.all&lt;/code&gt; trên HTTP/2):&lt;/strong&gt; Chỉ chịu 1 lần RTT chung cho cả hai luồng ghép kênh:
\(T_{\text{par}} = 0{,}10 + \frac{27{,}2}{10} = \mathbf{2{,}82\text{ s}}\)
(trên mạng vệ tinh hoặc kết nối xuyên lục địa có \(\text{RTT} = 300\text{ ms}\), tải song song cắt ngay &lt;strong&gt;300 ms&lt;/strong&gt; chờ rỗi!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phép-tính-2-tác-động-tài-chính-của-một-dòng-header-cache-control-immutable&quot;&gt;Phép tính 2: Tác động tài chính của một dòng header &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control: immutable&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Giả sử hệ thống có &lt;strong&gt;10.000 lượt gọi mỗi ngày&lt;/strong&gt;, trong đó &lt;strong&gt;80%&lt;/strong&gt; là người dùng quay lại trong tuần:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quên bật cache (hoặc gắn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?t=Date.now()&lt;/code&gt; phá cache):&lt;/strong&gt;
\(10\,000 \times 3{,}4\text{ MB} = \mathbf{34\,000\text{ MB} \approx 34\text{ GB/ngày}} \approx \mathbf{1{,}02\text{ TB/tháng}}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bật &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control: public, max-age=31536000, immutable&lt;/code&gt; trên thư mục phiên bản:&lt;/strong&gt; Chỉ 20% lượt gọi đầu (2.000 lượt) cần tải từ CDN:
\(2\,000 \times 3{,}4\text{ MB} = \mathbf{6{,}8\text{ GB/ngày}} \approx \mathbf{204\text{ GB/tháng}}\)
— cắt thẳng &lt;strong&gt;80% chi phí băng thông CDN&lt;/strong&gt;, đồng thời giúp 8.000 lượt gọi mỗi ngày khởi động khử nhiễu gần như tức thì!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;sẵn-sàng-tăng-dần&quot;&gt;Sẵn sàng tăng dần&lt;/h2&gt;

&lt;p&gt;Phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; tải song song cả hai tệp bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Promise.all&lt;/code&gt; rồi biên dịch WASM trên luồng chính. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; sẽ chờ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; chờ quá trình này hoàn tất; tuy nhiên luồng báo hiệu kết nối phòng (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt;) không được phép bị chặn theo.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;connect() ──► phòng đã lên, mic tắt hoặc NS đang bypass
                ├─► tải cặp ──► ok ──► setProcessor, rồi publish, rồi setEnabled(true)
                └─► tải cặp ──► lỗi ──► telemetry, ở lại bypass hoặc chỉ APM
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Khi tài nguyên đã nằm sẵn trong cache, quy trình vẫn đi theo thứ tự chuẩn của README: khởi tạo, gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, rồi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt;. Sai lầm cần tránh là đặt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; chờ tải CDN lạnh ngay &lt;strong&gt;bên trong&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt; trước khi người dùng vào được phòng. Nếu đo được tiến độ tải theo byte, hãy hiển thị trạng thái nhẹ kiểu “đang chuẩn bị lọc nhiễu”, và chỉ hiện một thông báo toast duy nhất nếu tải thất bại.&lt;/p&gt;

&lt;p&gt;Bản thân &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; (móc biến đổi track của LiveKit) không tự quản lý tầng cache; nó chỉ thực hiện yêu cầu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt; tới hai URL nói trên.&lt;/p&gt;

&lt;h2 id=&quot;cấu-hình-cache-http&quot;&gt;Cấu hình cache HTTP&lt;/h2&gt;

&lt;p&gt;Các thư mục phiên bản bất biến nên trả về header &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control: public, max-age=31536000, immutable&lt;/code&gt;. Khi nội dung nhị phân thay đổi, hãy đăng tải sang một thư mục mới để tiền tố phiên bản của gói trỏ tới, tuyệt đối không ghi đè tệp tại URL đã gắn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;immutable&lt;/code&gt;. Không thêm tham số truy vấn kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?t=Date.now()&lt;/code&gt; mỗi lần vào phòng vì sẽ phá hỏng hoàn toàn tỉ lệ trúng cache. Nếu ứng dụng dùng thêm Cache API, hãy lập khóa theo URL đầy đủ có phiên bản, giới hạn dung lượng lưu trữ và cung cấp tùy chọn hỗ trợ xóa cache lọc nhiễu.&lt;/p&gt;

&lt;p&gt;Máy chủ cần phục vụ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; kèm header &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Content-Type: application/wasm&lt;/code&gt;. Thiếu header &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Access-Control-Allow-Origin&lt;/code&gt; thường chỉ hiện ra như một lỗi mạng chung chung, vì vậy cần ghi log rõ mã trạng thái HTTP và kiểu phản hồi. Cặp tệp WASM và gói mô hình phải được xem là một đơn vị nguyên tử: không ghép thử module SIMD của bản 1.3.0 với gói trọng số từ thời 1.1.2.&lt;/p&gt;

&lt;p&gt;Trên mạng di động, độ trễ theo khu vực địa lý ảnh hưởng rõ rệt đến tốc độ tải lần đầu. Với khách hàng doanh nghiệp có tường lửa chặn tên miền công khai, hãy mirror cặp tệp vào hạ tầng VPC của họ (vẫn áp dụng đầy đủ CORS và TLS). API công khai của gói không hỗ trợ header xác thực riêng mà chỉ gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt; tiêu chuẩn.&lt;/p&gt;

&lt;h2 id=&quot;bảng-xử-lý-các-lỗi-tải-một-phần&quot;&gt;Bảng xử lý các lỗi tải một phần&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Loại lỗi&lt;/th&gt;
      &lt;th&gt;Tác động người dùng thấy&lt;/th&gt;
      &lt;th&gt;Hướng xử lý&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;404 WASM hoặc mô hình&lt;/td&gt;
      &lt;td&gt;Không bật được khử nhiễu&lt;/td&gt;
      &lt;td&gt;Sửa cấu hình đường dẫn; phát hành âm thanh gốc&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lỗi CORS&lt;/td&gt;
      &lt;td&gt;Không bật được khử nhiễu&lt;/td&gt;
      &lt;td&gt;Bổ sung header CORS trên CDN&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tệp tải bị đứt đoạn&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize&lt;/code&gt; ném ngoại lệ&lt;/td&gt;
      &lt;td&gt;Thử lại 1 lần, sau đó chuyển sang bypass&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mất mạng sau khi đã cache tốt&lt;/td&gt;
      &lt;td&gt;Có thể vẫn hoạt động bình thường&lt;/td&gt;
      &lt;td&gt;Kiểm chứng lại bằng disk cache hoặc Cache API&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lệch phiên bản giữa hai tệp&lt;/td&gt;
      &lt;td&gt;Âm thanh méo hoặc lỗi biên dịch&lt;/td&gt;
      &lt;td&gt;Khóa chặt hai tệp trong cùng một thư mục phiên bản&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Sai kiểu MIME&lt;/td&gt;
      &lt;td&gt;Bộ nạp streaming báo lỗi&lt;/td&gt;
      &lt;td&gt;Cấu hình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Content-Type: application/wasm&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;ví-dụ-triển-khai-mirror-riêng&quot;&gt;Ví dụ triển khai mirror riêng&lt;/h2&gt;

&lt;p&gt;Tải tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; từ kho gốc cùng tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; tương ứng với phiên bản gói đang dùng. Đối với máy khách phiên bản ≥ 1.2.0 tuân theo README, đăng tải hai tệp vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://assets.example.com/ns/df3/v2/pkg/&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.../v2/models/&lt;/code&gt;, sau đó cấu hình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://assets.example.com/ns/df3&lt;/code&gt;. Thực hiện kiểm thử nhanh (smoke-test) trên hồ sơ trình duyệt trắng có tắt cache, rồi kiểm tra lại lần hai khi bật cache.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Cho &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl = https://example.com/df3&lt;/code&gt;, tính chính xác 4 URL phân giải cho phiên bản ≤ 1.1.2 và phiên bản ≥ 1.2.0 (gồm 1.3.0). Lưu đoạn mã sau thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdn_urls.py&lt;/code&gt; và chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 cdn_urls.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;cdn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;https://example.com/df3&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pairs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;1.1.2&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;pkg/df_bg.wasm&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;models/DeepFilterNet3_onnx.tar.gz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;1.3.0&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;v2/pkg/df_bg.wasm&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;v2/models/DeepFilterNet3_onnx.tar.gz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ver&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wasm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pairs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ver&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cdn&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wasm&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cdn&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1.1.2
https://example.com/df3/pkg/df_bg.wasm
https://example.com/df3/models/DeepFilterNet3_onnx.tar.gz
1.3.0
https://example.com/df3/v2/pkg/df_bg.wasm
https://example.com/df3/v2/models/DeepFilterNet3_onnx.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Đưa sẵn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;, tạo ra URL lỗi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://example.com/df3/v2/v2/pkg/df_bg.wasm&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Đổi sai tên tệp so với chuẩn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Chặn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt; chờ cả bốn URL phản hồi; thực tế mỗi máy khách chỉ tải đúng hai URL ứng với phiên bản gói đã cài, và bước này không được chặn signaling.&lt;/li&gt;
  &lt;li&gt;Nhầm lẫn bản 1.3.0 dùng cấu trúc không tiền tố; từ 1.2.0 trở đi (gồm 1.3.0), máy khách luôn tự nối &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Lỗi lặp tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/v2/v2/&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Chặn giao diện tham gia phòng họp chờ lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Tải âm thanh thô của người dùng lên máy chủ trong môi trường sản phẩm.&lt;/li&gt;
  &lt;li&gt;Dùng chung một thư mục tài nguyên cho cả máy khách ≤ 1.1.2 và ≥ 1.2.0 mà không tách cấu trúc đường dẫn.&lt;/li&gt;
  &lt;li&gt;Cấu hình sai kiểu MIME cho tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Tự viết lại cả 4 URL từ trí nhớ, sau đó đối chiếu với phần kết quả kỳ vọng của mini-lab.&lt;/li&gt;
  &lt;li&gt;Liệt kê các trạng thái giao diện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;idle&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;downloading&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ready&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;error&lt;/code&gt; và chỉ rõ phương thức nào của processor sẽ được gọi khi chuyển sang &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ready&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Viết giá trị header &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control&lt;/code&gt; cho cây thư mục &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; bất biến cùng quy tắc phát hành cây thư mục mới khi cập nhật mô hình.&lt;/li&gt;
  &lt;li&gt;Phác thảo khoảng 10 dòng chính sách xử lý sự cố khi tải tài nguyên lỗi mà vẫn giữ cuộc họp hoạt động bình thường.&lt;/li&gt;
  &lt;li&gt;Giải thích vì sao tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt; và tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tar.gz&lt;/code&gt; bắt buộc phải thuộc cùng một thế hệ thư mục phiên bản.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Có 2 tệp nhân với 2 thế hệ phiên bản; chỉ thế hệ ≥ 1.2.0 (gồm 1.3.0) có thêm tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;, còn đường dẫn gốc vẫn giữ nguyên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://example.com/df3&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ready&lt;/code&gt; đạt được ngay sau khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; hoàn tất; khi đó tiến hành gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; (nếu chưa gọi) và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await setEnabled(true)&lt;/code&gt; nếu người dùng đang bật khử nhiễu.&lt;/li&gt;
  &lt;li&gt;Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public, max-age=31536000, immutable&lt;/code&gt; trên thư mục đã gắn phiên bản; mỗi khi tệp nhị phân thay đổi thì xuất bản thư mục mới, không ghi đè thư mục cũ.&lt;/li&gt;
  &lt;li&gt;Bắt lỗi (rejection) từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize&lt;/code&gt;, chuyển sang phát hành track âm thanh thô, gửi một sự kiện telemetry ghi rõ nguyên nhân lỗi và không lặp lại yêu cầu tải vô hạn.&lt;/li&gt;
  &lt;li&gt;Module WASM SIMD và gói trọng số là một cặp đồng bộ; tách rời hai thế hệ thư mục sẽ khiến module biên dịch đọc nhầm cấu trúc hoặc trọng số không tương thích.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;README của gói, mục &lt;em&gt;Custom CDN&lt;/em&gt;: &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;deepfilternet3-noise-filter&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Tài liệu MDN về &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching&quot;&gt;HTTP caching&lt;/a&gt; và &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS&quot;&gt;CORS&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Gói mô hình nguồn gốc &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet/blob/main/models/DeepFilterNet3_onnx.tar.gz&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Chương 06 về lượng tử hóa, SIMD và quy trình đóng gói cho đúng cặp tệp này.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=rIAIzf6utOc&quot;&gt;What is a CDN (Content Delivery Network) and How does a CDN Work?&lt;/a&gt; — Cloudflare, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Giải thích cơ chế phân phối từ máy chủ biên (edge cache) so với máy chủ gốc — lý do chính để tách tệp WASM và mô hình ra khỏi tarball npm.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, tiếng Anh. Phần suy luận phía máy khách giải thích vì sao trình duyệt phải tải đủ cả đồ thị mô hình lẫn engine thực thi trước hop đầu tiên.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=0VdNflU08yA&quot;&gt;Quantization explained with PyTorch - Post-Training Quantization, Quantization-Aware Training&lt;/a&gt; — Umar Jamil, tiếng Anh. Trọng số gọn nhẹ hơn giúp cải thiện tốc độ tải lần đầu qua CDN, nhưng cần cân nhắc kỹ đánh đổi về độ chính xác.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-02 Pattern TrackProcessor của LiveKit</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter07/07_02_livekit_trackprocessor/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter07/07_02_livekit_trackprocessor</id>
   <content type="html">&lt;p&gt;Hãy thử đặt mình vào vị trí người dùng đang vội vào một cuộc họp quan trọng: họ bấm “Tham gia ngay”, thế nhưng màn hình cứ xoay vòng suốt 4 giây rồi báo lỗi vì tệp mô hình khử nhiễu trên CDN bị chậm mạng! Một tính năng phụ trợ (lọc nhiễu) tuyệt đối không bao giờ được phép trở thành &lt;strong&gt;điểm chết duy nhất (single point of failure)&lt;/strong&gt; chặn đứng thao tác vào phòng họp. Để tách bạch hoàn hảo giữa “kết nối cuộc gọi” và “biến đổi âm thanh cục bộ”, LiveKit thiết kế một mẫu kiến trúc rất thanh lịch mang tên &lt;strong&gt;TrackProcessor&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;SDK máy khách của LiveKit cung cấp giao diện &lt;strong&gt;TrackProcessor&lt;/strong&gt; (móc biến đổi track) cho phép xử lý track âm thanh cục bộ trước khi mã hóa và phát hành (publish). Lớp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; trong gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; chính là cài đặt của giao diện đó cho DeepFilterNet3, đi kèm các phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suspend&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; và phương thức tĩnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported()&lt;/code&gt;. Bài học này trình bày vòng đời hoạt động, thứ tự gọi hàm khi tham gia phòng họp và cơ chế xử lý lỗi giúp cuộc gọi vẫn duy trì ổn định khi CDN hoặc worklet gặp sự cố.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Nguyên tắc không chặn cuộc gọi vì tải mô hình → Kiến thức cần nhớ (Giao diện TrackProcessor, Máy trạng thái bất đồng bộ &amp;amp; Suy giảm êm, Tách biệt Signaling và Media Pipeline) → Phân định trách nhiệm &amp;amp; Mã tích hợp chuẩn bản 1.3.0 → Máy trạng thái &amp;amp; xử lý backpressure → Giải thích so sánh dòng thời gian Blocking vs. Non-Blocking Join → Thiết bị di động, telemetry, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;Vòng đời TrackProcessor từ lúc dựng tới lúc publish trên track audio local của LiveKit&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. TrackProcessor gắn trực tiếp lên track âm thanh cục bộ: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; dựng đồ thị worklet, còn bước publish gửi đi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processedTrack&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ sắp xếp chính xác thứ tự gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new DeepFilterNoiseFilterProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, chỉ ra được các phương thức vòng đời mà LiveKit tự động kích hoạt, và thiết kế luồng kết nối giữ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt; độc lập hoàn toàn với quá trình tải mô hình.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-mẫu-tích-hợp-trackprocessor&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của mẫu tích hợp TrackProcessor&lt;/h2&gt;

&lt;h3 id=&quot;1-giao-diện-biến-đổi-dòng-trackprocessor-interface&quot;&gt;1. Giao diện biến đổi dòng (TrackProcessor Interface)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Một hợp đồng vòng đời chuẩn (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;) cho phép gắn một đồ thị xử lý Web Audio vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack&lt;/code&gt; mà không phá vỡ tầng truyền tải WebRTC bên dưới.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Cho phép LiveKit tự động quản lý việc tạo lại đồ thị khi người dùng cắm micro mới (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;), đồng thời giữ nguyên khe phát hành (sender) khi bật/tắt bypass (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-máy-trạng-thái-bất-đồng-bộ-và-suy-giảm-êm-graceful-degradation&quot;&gt;2. Máy trạng thái bất đồng bộ và Suy giảm êm (Graceful Degradation)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Vòng đời 7 trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Created → LoadingAssets → Ready → Active ↔ Bypassed / Failed → Disposed&lt;/code&gt; tách bạch lỗi tải tài nguyên/biên dịch WASM khỏi trạng thái kết nối phòng họp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Đảm bảo khi CDN trả lỗi 404 hay Safari &amp;lt; 16.4 từ chối SIMD, hệ thống vẫn tự động phát hành âm thanh gốc (hoặc APM trình duyệt) và báo toast nhẹ thay vì làm sập cuộc gọi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-tách-đường-găng-báo-hiệu-signaling-khỏi-đường-tải-tài-nguyên-asset-loading&quot;&gt;3. Tách đường găng Báo hiệu (Signaling) khỏi đường tải Tài nguyên (Asset Loading)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;room.connect()&lt;/code&gt; (WebSocket + ICE/DTLS) chạy song song hoặc trước khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor()&lt;/code&gt; hoàn tất tải WASM + mô hình từ CDN.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Giảm thời gian vào phòng (Time-to-Join) từ vài giây xuống dưới nửa giây trên mạng di động, đồng thời thu thập telemetry (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ns_init_ms&lt;/code&gt;, tỉ lệ trúng cache, lý do fallback) mà không chạm vào âm thanh thô.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Phân định trách nhiệm giữa Processor và Room.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Vòng đời hoạt động và đoạn mã tích hợp chuẩn bản 1.3.0.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Bật/tắt, chế độ bypass, điều chỉnh mức khử nhiễu và xử lý nghẽn (backpressure).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Lưu ý trên thiết bị di động, telemetry và dọn dẹp tài nguyên (dispose).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab về thứ tự gọi hàm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;phân-định-trách-nhiệm&quot;&gt;Phân định trách nhiệm&lt;/h2&gt;

&lt;p&gt;Processor có nhiệm vụ tiếp nhận track nguồn qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack.setProcessor&lt;/code&gt;, tạo ra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processedTrack&lt;/code&gt;, tải bất đồng bộ module WASM (WebAssembly — mã nhị phân chạy trong trình duyệt) cùng gói mô hình, cung cấp các hàm điều khiển trong lúc chạy mà không phải phát hành lại track, và giải phóng worker, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; cùng bộ nhớ WASM khi kết thúc. Ngược lại, processor không quản lý token phòng họp, không tải dữ liệu PCM micro lên máy chủ (kiến trúc mặc định của Mezon xử lý hoàn toàn trên thiết bị), và không được làm treo nút tham gia cuộc gọi hàng chục giây mà thiếu phản hồi trạng thái.&lt;/p&gt;

&lt;p&gt;Phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor.isSupported()&lt;/code&gt; trả về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt; khi trình duyệt có &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly&lt;/code&gt;. Đây chỉ là điều kiện nền tảng, không phải phép kiểm tra hỗ trợ SIMD (một lệnh xử lý nhiều dữ liệu, xem bài 06-03).&lt;/p&gt;

&lt;h2 id=&quot;mã-tích-hợp-tham-chiếu&quot;&gt;Mã tích hợp tham chiếu&lt;/h2&gt;

&lt;p&gt;Phụ thuộc ngang hàng (peer dependency): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;livekit-client&lt;/code&gt; ^2. Cách khởi tạo và thứ tự gọi các phương thức công khai:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DeepFilterNoiseFilter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;deepfilternet3-noise-filter&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// DeepFilterNoiseFilter(options) trả về DeepFilterNoiseFilterProcessor.&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;sampleRate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;noiseReductionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;assetConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;cdnUrl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;audioTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;room&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;localParticipant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;publishTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;audioTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setEnabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// bypass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate: 48000&lt;/code&gt; tương ứng với đồ thị toàn dải (full-band) mà gói khởi tạo (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new AudioContext({ sampleRate: 48000 })&lt;/code&gt;). Hai tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; là thang điều chỉnh sản phẩm từ 0 đến 100 (không phải giá trị SNR mục tiêu); giá trị truyền vào được giới hạn trong khoảng hợp lệ rồi gửi sang cổng worklet. Lưu ý rằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; là hàm bất đồng bộ trả về một Promise và cập nhật cờ bypass qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core.setNoiseSuppressionEnabled&lt;/code&gt;. Dù một số ví dụ ngắn trên README bỏ qua từ khóa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt;, bạn vẫn nên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; lời gọi này. Chế độ bypass giữ nguyên đồ thị âm thanh đang hoạt động nên không làm thay đổi khe phát hành track.&lt;/p&gt;

&lt;p&gt;Trong chuỗi trên, mã ứng dụng gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, còn LiveKit sẽ tự động gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init({ track })&lt;/code&gt;. Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; lưu lại track gốc và gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ensureGraph&lt;/code&gt; để khôi phục &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;, chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; trên lớp core (tải song song WASM và gói mô hình rồi biên dịch bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt;), khởi tạo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletNode&lt;/code&gt; một lần duy nhất, nối chuỗi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source → worklet → destination&lt;/code&gt; và gán kết quả cho &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processedTrack&lt;/code&gt;. Phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; dựng lại đồ thị khi nguồn track micro thay đổi; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suspend&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt; điều khiển trực tiếp trạng thái của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;; còn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; ngắt kết nối các node, đóng context và gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processor.destroy()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Nếu không dùng LiveKit và tự quản lý &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;, bạn có thể sử dụng trực tiếp lớp lõi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; với các phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Việc truy cập CDN (mạng phân phối nội dung) chỉ diễn ra bên trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize&lt;/code&gt;, hoàn toàn tách biệt với quá trình truyền báo hiệu (signaling) của phòng họp.&lt;/p&gt;

&lt;h2 id=&quot;máy-trạng-thái&quot;&gt;Máy trạng thái&lt;/h2&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Created
  → LoadingAssets   (trong init / initialize)
  → Ready
  → Active          (đang bật, frame đang chảy)
  → Bypassed        (await setEnabled(false))
  → Failed          (lỗi asset hoặc compile)
  → Disposed        (destroy)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Khi rơi vào trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Failed&lt;/code&gt;, ứng dụng vẫn cần phát hành âm thanh gốc (hoặc chỉ dùng APM trình duyệt) và hiển thị một thông báo dạng toast không chặn thao tác. Tuyệt đối không từ chối &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt; chỉ vì gói mô hình bị lỗi 404; hãy tách bạch trạng thái “khử nhiễu sẵn sàng” khỏi trạng thái “đã kết nối phòng”.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-so-sánh-dòng-thời-gian-vào-phòng-blocking-vs-non-blocking-join&quot;&gt;Giải thích: So sánh dòng thời gian vào phòng (Blocking vs. Non-Blocking Join)&lt;/h2&gt;

&lt;p&gt;Giả sử trên mạng 4G lần đầu truy cập (chưa có cache):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Kết nối phòng LiveKit (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;room.connect&lt;/code&gt;): \(T_{\text{conn}} = 450\text{ ms}\).&lt;/li&gt;
  &lt;li&gt;Xin quyền &amp;amp; mở micro (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt;): \(T_{\text{mic}} = 200\text{ ms}\).&lt;/li&gt;
  &lt;li&gt;Tải WASM + mô hình từ CDN và biên dịch (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init()&lt;/code&gt; trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;): \(T_{\text{init}} = 2\,800\text{ ms}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hãy tính trực tiếp thời điểm người dùng &lt;strong&gt;thấy mặt đồng nghiệp trong phòng&lt;/strong&gt; (Time-to-Join) và thời điểm &lt;strong&gt;khử nhiễu bắt đầu hoạt động&lt;/strong&gt;:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Kiến trúc luồng vào phòng&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Time-to-Join&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Nếu CDN trả lỗi 404&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Thời điểm NS sẵn sàng&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Chặn tuần tự (Sai):&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await setProcessor&lt;/code&gt; rồi mới &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;room.connect&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(200 + 2800 + 450 = \mathbf{3\,450\text{ ms}}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Không vào được phòng!&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3\,450\text{ ms}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Song song không chặn (Chuẩn):&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;room.connect&lt;/code&gt; độc lập, tải NS nền&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(450\text{ ms}\)&lt;/strong&gt; (nhanh hơn &lt;strong&gt;\(7{,}7\times\)&lt;/strong&gt;)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Vẫn vào phòng &amp;amp; phát tiếng gốc bình thường&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2\,800\text{ ms}\) (chuyển êm không đứt cuộc gọi)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Chú ý chi tiết kỹ thuật tinh tế: khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;room.connect&lt;/code&gt; chạy song song với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, tổng thời gian chờ không phải là tổng (\(450 + 2800\)) mà là \(\max(450,\, 200 + 2800)\) — đồng thời người dùng nghe được ngay âm thanh từ phòng họp chỉ sau &lt;strong&gt;0,45 giây&lt;/strong&gt;!&lt;/p&gt;

&lt;h3 id=&quot;xử-lý-nghẽn-backpressure&quot;&gt;Xử lý nghẽn (backpressure)&lt;/h3&gt;

&lt;p&gt;Luôn tuân thủ nhịp thời gian thực của AudioWorklet: các khung trễ hạn quantum phải chuyển sang đi thẳng (passthrough) hoặc loại bỏ, không bao giờ đẩy dồn vào hàng đợi PCM không giới hạn. Khi hệ số thời gian thực liên tục vượt ngưỡng, giải pháp đúng là hạ mức khử nhiễu hoặc bật bypass chứ không phải đệm thêm vài giây âm thanh.&lt;/p&gt;

&lt;h3 id=&quot;phạm-vi-áp-dụng-theo-track-so-với-theo-phòng&quot;&gt;Phạm vi áp dụng: theo track so với theo phòng&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phạm vi&lt;/th&gt;
      &lt;th&gt;Ví dụ&lt;/th&gt;
      &lt;th&gt;Khi nào áp dụng&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Theo track&lt;/td&gt;
      &lt;td&gt;Gắn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; trên track micro&lt;/td&gt;
      &lt;td&gt;Cấu hình mặc định&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Phòng / Giao diện (UX)&lt;/td&gt;
      &lt;td&gt;Tùy chọn “Bật khử nhiễu” trong cài đặt&lt;/td&gt;
      &lt;td&gt;Lưu vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;localStorage&lt;/code&gt; và áp dụng khi phát hành track&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Người tham gia từ xa&lt;/td&gt;
      &lt;td&gt;Xử lý track đã đăng ký nhận (subscribe)&lt;/td&gt;
      &lt;td&gt;Hiếm gặp; chủ yếu dùng cho bot hoặc hệ thống ghi âm&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Hãy lưu tùy chọn bật/tắt của người dùng ở tầng giao diện, sau đó áp dụng bằng cách khởi tạo processor tương ứng ngay khi tạo track cục bộ.&lt;/p&gt;

&lt;h2 id=&quot;thứ-tự-tham-gia-phòng-và-tải-tài-nguyên-cdn&quot;&gt;Thứ tự tham gia phòng và tải tài nguyên CDN&lt;/h2&gt;

&lt;p&gt;Lời gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await audioTrack.setProcessor(filter)&lt;/code&gt; sẽ chờ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, mà &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; lại chờ tải tài nguyên từ CDN. Đặt bước này &lt;strong&gt;trước &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt;&lt;/strong&gt; là chính xác, nhưng đặt trước &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;room.connect()&lt;/code&gt; là sai lầm. Quy trình chuẩn là kết nối signaling trước, sau đó phát hành track khi sẵn sàng (hoặc giữ micro ở trạng thái tắt/bypass trong lúc tài nguyên đang tải). Ngược lại, nếu gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; sau &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt; mà không gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; khi thay đổi track micro bên dưới, LiveKit sẽ tiếp tục phát đi tín hiệu micro thô. Thứ tự an toàn luôn là: khởi tạo processor, gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt;, rồi mới điều chỉnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;; các lần đổi thiết bị về sau đi qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; thay vì gọi lại &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;lưu-ý-trên-thiết-bị-di-động-và-telemetry&quot;&gt;Lưu ý trên thiết bị di động và telemetry&lt;/h2&gt;

&lt;p&gt;Khi tab chuyển sang chạy nền, trình duyệt sẽ bóp tốc độ các bộ định thời; callback âm thanh tuy được ưu tiên hơn nhưng vẫn tiêu tốn tài nguyên đáng kể. Trên Safari iOS, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; chỉ có thể &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt; từ một thao tác chạm trực tiếp của người dùng, vì vậy hãy gắn bước khởi tạo vào nút tham gia phòng. Ngoài ra, chạy đồng thời camera, mô hình khử nhiễu và bộ mã hóa Opus có thể làm nóng và hạ xung CPU trên điện thoại tầm trung. Tốc độ lấy mẫu của thiết bị Bluetooth SCO đôi khi không đạt 48 kHz, nhưng vẫn nên giữ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; ở 48 kHz theo tài liệu hướng dẫn bất cứ khi nào có thể.&lt;/p&gt;

&lt;p&gt;Dữ liệu telemetry cần thu thập (tuyệt đối không đính kèm âm thanh thô) gồm: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ns_init_ms&lt;/code&gt;, dung lượng tải về, tỉ lệ trúng cache, trạng thái bật/tắt, mức khử nhiễu, các phân vị hệ số thời gian thực và lý do chuyển sang fallback. Đây là các chỉ số độ tin cậy vận hành; còn đánh giá chất lượng nghe như MOS sẽ được học ở Chương 08.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Đọc lại đoạn mã tích hợp tham chiếu ở trên và kiểm tra thứ tự thực thi chuẩn bằng cách chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 join_order.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;new DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;publishTrack&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;. &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;step&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. new DeepFilterNoiseFilterProcessor
2. setProcessor
3. publishTrack
4. setSuppressionLevel
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; sau &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt; mà không xử lý &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; khi đổi micro, khiến phòng họp vẫn phát track chưa lọc.&lt;/li&gt;
  &lt;li&gt;Chặn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt; chờ tải tài nguyên CDN; bước tải nằm trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; bên trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, không thuộc bắt tay signaling.&lt;/li&gt;
  &lt;li&gt;Quên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; trước &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; rồi đọc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isEnabled()&lt;/code&gt; ngay lập tức trước khi thông điệp bypass kịp áp dụng.&lt;/li&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; lần thứ hai trong khi quá trình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; đầu tiên vẫn đang tải.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; trước khi đối tượng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack&lt;/code&gt; được tạo.&lt;/li&gt;
  &lt;li&gt;Chuyển trang hoặc rời phòng mà không gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;, để lại các worklet chạy ngầm.&lt;/li&gt;
  &lt;li&gt;Nghĩ rằng đoạn ví dụ ngắn trên README là toàn bộ API, trong khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suspend&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported&lt;/code&gt; đều là các phương thức công khai quan trọng.&lt;/li&gt;
  &lt;li&gt;Dùng tên lớp cũ không còn tồn tại trong bản 1.3.0; luôn dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Đánh dấu trên sơ đồ máy trạng thái các vị trí giao diện nên hiển thị biểu tượng đang tải (spinner) và vị trí nên hiển thị công tắc bật/tắt.&lt;/li&gt;
  &lt;li&gt;Viết phác thảo hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connectWithNS()&lt;/code&gt; đảm bảo người dùng vẫn vào được phòng họp kể cả khi CDN gặp lỗi.&lt;/li&gt;
  &lt;li&gt;Liệt kê các sự kiện của LiveKit (hoặc vòng đời trang web) nơi ứng dụng cần gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Khi nào nên dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; và khi nào nên dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;?&lt;/li&gt;
  &lt;li&gt;Nếu người dùng bật chế độ bypass ngay trong lúc processor đang ở trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LoadingAssets&lt;/code&gt;, bạn cần lưu lại thông tin gì và phương thức nào sẽ áp dụng trạng thái đó sau khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; hoàn tất?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Hiển thị spinner trong trạng thái &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LoadingAssets&lt;/code&gt;; chỉ hiển thị công tắc bật/tắt khi ở &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Active&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Bypassed&lt;/code&gt;; khi ở &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Failed&lt;/code&gt; cần hiện thông báo toast và tắt hẳn spinner.&lt;/li&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await room.connect(url, token)&lt;/code&gt; độc lập mà không đặt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await filter&lt;/code&gt; chặn phía trước; trong nhánh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;catch&lt;/code&gt; của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, thực hiện phát hành track âm thanh gốc hoặc APM.&lt;/li&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; khi nhận sự kiện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Disconnected&lt;/code&gt; hoặc khi component/route bị gỡ bỏ (unmount); trường hợp đổi thiết bị chỉ cần gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; chứ không cần rời phòng.&lt;/li&gt;
  &lt;li&gt;Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; khi phát hành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack&lt;/code&gt; trong LiveKit; dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; khi tự quản lý đồ thị &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; thuần.&lt;/li&gt;
  &lt;li&gt;Lưu cờ boolean thể hiện mong muốn của người dùng; hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ensureGraph&lt;/code&gt; ở cuối quá trình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; đã tự gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(this.enabled)&lt;/code&gt;, không cần gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; lần thứ hai.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Tài liệu LiveKit: &lt;a href=&quot;https://docs.livekit.io/transport/media/publish/&quot;&gt;TrackProcessor / setProcessor on LocalAudioTrack&lt;/a&gt; và trang chủ &lt;a href=&quot;https://docs.livekit.io/&quot;&gt;https://docs.livekit.io/&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Kho mã nguồn &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt; và trang &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;gói npm&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Chương 05 về nhịp quantum của AudioWorklet và Chương 06 về lỗi biên dịch SIMD trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d2N0d6CKrbk&quot;&gt;Group calling architectures in WebRTC: MCU, SFU &amp;amp; P2P&lt;/a&gt; — Tsahi Levent-Levi, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; LiveKit hoạt động theo mô hình SFU (chuyển tiếp track mà không trộn âm); video này giải thích nền tảng kiến trúc SFU thay vì hướng dẫn chi tiết từng API của TrackProcessor.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Revamping Audio Quality for RTC Part 1: Beryl Echo Cancellation&lt;/td&gt;
          &lt;td&gt;Sriram Srinivasan and Hoang Do](https://www.youtube.com/watch?v=lapq9zvUd-k) — @Scale, tiếng Anh. Minh họa vị trí xử lý tăng cường cục bộ trước bước mã hóa — đúng khoảng thời gian mà TrackProcessor phải hoàn tất công việc.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=g1L4O1smMC0&quot;&gt;AudioWorklet :: What, Why, and How - Hongchan Choi&lt;/a&gt; — WebAudio PDX, tiếng Anh. Trình bày các ràng buộc của luồng callback processor mà bộ xử lý âm thanh của LiveKit vẫn phải tuân thủ.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-01 Điểm chèn trong WebRTC</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter07/07_01_webrtc_integration/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter07/07_01_webrtc_integration</id>
   <content type="html">&lt;p&gt;Một lỗi kinh điển khi lần đầu tích hợp khử nhiễu mạng nơ-ron vào ứng dụng gọi video: kỹ sư cẩn thận gắn bộ lọc vào… &lt;strong&gt;đầu ra loa (track từ xa)&lt;/strong&gt; thay vì đầu vào micro, hoặc bật đồng thời cả &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression: true&lt;/code&gt; của Chrome lẫn DeepFilterNet3! Kết quả là đầu dây bên kia vẫn nghe trọn tiếng quạt máy, còn giọng nói bị bóp nghẹt như nói qua ống bơ vì bị lọc hai lần liên tiếp. Trong một cuộc gọi WebRTC, &lt;em&gt;đặt bộ khử nhiễu ở đâu&lt;/em&gt; quan trọng chẳng kém gì bản thân mô hình bên trong.&lt;/p&gt;

&lt;p&gt;Vị trí chèn bộ khử nhiễu trong một cuộc gọi WebRTC quyết định trực tiếp đến độ trễ, khả năng khử vọng (echo) và việc máy chủ SFU có nhận được tín hiệu giọng nói đã làm sạch hay không. Bài học này ánh xạ các điểm chèn tiềm năng với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt;, bộ xử lý âm thanh tích hợp (Audio Processing Module — APM) của trình duyệt và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTCPeerConnection&lt;/code&gt;, đồng thời phân tích cách &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; trong gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; can thiệp vào luồng phát (uplink) trước bước mã hóa thông qua TrackProcessor (cơ chế biến đổi track của LiveKit).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Sai lầm đặt nhầm vị trí &amp;amp; lọc nhiễu hai lần → Kiến thức cần nhớ (Luồng Uplink/Downlink &amp;amp; SFU, Phối hợp AEC/AGC/NS trong APM trình duyệt, Điểm chèn TrackProcessor trước Opus) → So sánh ba điểm chèn A, B, C → Cấu hình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt; &amp;amp; nội thất đồ thị processor → Giải thích tính tay ngân sách độ trễ hội thoại 150 ms và hiệu ứng suy hao kép khi bật trùng hai bộ NS → Mini-lab, Bẫy thường gặp và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;Track audio local của LiveKit đi qua processor khử nhiễu trước khi publish&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Điểm chèn A là TrackProcessor đặt trên track micro cục bộ (local), ngay trước khi bộ gửi (sender) thực hiện mã hóa.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ biết cách đặt bộ khử nhiễu mạng nơ-ron trên đường phát trước bước mã hóa, giữ lại tính năng khử vọng của trình duyệt đồng thời tắt bộ khử nhiễu mặc định của trình duyệt, và mô tả chính xác những gì &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; thay đổi trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrack&lt;/code&gt; được phát hành mà không cần đẩy bước suy luận ra khỏi thiết bị.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-kiến-trúc-đường-tiếng-trong-cuộc-gọi-webrtc&quot;&gt;Kiến thức cần nhớ: Kiến trúc đường tiếng trong cuộc gọi WebRTC&lt;/h2&gt;

&lt;h3 id=&quot;1-luồng-gửi-uplink-luồng-nhận-downlink-và-kiến-trúc-sfu&quot;&gt;1. Luồng gửi (Uplink), Luồng nhận (Downlink) và Kiến trúc SFU&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Trong WebRTC dùng máy chủ chuyển tiếp có chọn lọc (&lt;strong&gt;SFU — Selective Forwarding Unit&lt;/strong&gt; như LiveKit), mỗi máy khách mã hóa micro thành gói Opus gửi lên (uplink) và giải mã gói của người khác phát ra loa (downlink); SFU chỉ định tuyến gói mà không giải mã hay trộn âm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Khẳng định bộ khử nhiễu phải nằm trên &lt;strong&gt;uplink cục bộ trước khi mã hóa Opus&lt;/strong&gt; để mọi người nghe đều nhận âm thanh sạch, tránh tiêu tốn băng thông Opus cho nhiễu và giữ chi phí CPU tỉ lệ theo số người đang nói (publisher) chứ không theo số người nghe.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-phối-hợp-với-audio-processing-module-apm-của-trình-duyệt&quot;&gt;2. Phối hợp với Audio Processing Module (APM) của trình duyệt&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Trình duyệt tích hợp sẵn ba khối DSP chạy gần tầng phần cứng: &lt;strong&gt;AEC&lt;/strong&gt; (khử vọng dựa trên tín hiệu tham chiếu loa), &lt;strong&gt;AGC&lt;/strong&gt; (tự động cân bằng âm lượng) và &lt;strong&gt;NS&lt;/strong&gt; (khử nhiễu cổ điển).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Khi chèn bộ khử nhiễu mạng nơ-ron (như DeepFilterNet3), ta giữ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;echoCancellation: true&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoGainControl: true&lt;/code&gt;, nhưng &lt;strong&gt;tắt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression: false&lt;/code&gt;&lt;/strong&gt; để tránh hiệu ứng “khử nhiễu kép” (double suppression) làm đục giọng và cắt cụt phụ âm nhẹ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-móc-chèn-trackprocessor-và-mediastreamdestination&quot;&gt;3. Móc chèn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamDestination&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Cơ chế chuẩn hóa của LiveKit (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audioTrack.setProcessor(filter)&lt;/code&gt;) dựng đồ thị Web Audio &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source → AudioWorkletNode → MediaStreamDestination&lt;/code&gt; để xuất ra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processedTrack&lt;/code&gt; đưa vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTCPeerConnection&lt;/code&gt; sender mà không cần tải PCM lên đám mây.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Cho phép bật/tắt bypass (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt;) và chỉnh mức khử nhiễu ngay trong cuộc gọi mà không làm đứt kết nối RTP hay phải thương lượng lại SDP.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Toàn cảnh chuỗi truyền âm: micro, xử lý, mã hóa, SFU, giải mã và phát loa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — So sánh ba điểm chèn A, B và C.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Đối chiếu APM trình duyệt với processor bản 1.3.0.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Xử lý tình huống đổi thiết bị, tắt tiếng (mute) và vòng đời đồ thị worklet.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab, bẫy thường gặp và làm bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;đồ-thị-âm-thanh-hội-nghị&quot;&gt;Đồ thị âm thanh hội nghị&lt;/h2&gt;

&lt;p&gt;Đường gửi cục bộ (uplink):&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Microphone
  → getUserMedia MediaStreamTrack
  → [tuỳ chọn: AudioContext / AudioWorklet NS]
  → [tuỳ chọn: APM trình duyệt: AEC / NS / AGC]
  → RTCPeerConnection sender (encode Opus)
  → SFU / peers
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Đường nhận (downlink):&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;RTP từ xa
  → decode phía receiver
  → MediaStreamTrack
  → phần tử audio hoặc AudioContext
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Bộ khử nhiễu cho &lt;strong&gt;luồng gửi của bạn&lt;/strong&gt; cần được chạy trên đường gửi cục bộ, trước khi mã hóa. Nếu đặt khử nhiễu sau bước giải mã trên track từ xa (remote), bạn chỉ làm sạch nhiễu của người khác cho riêng tai mình nghe; cách đó không làm giảm nhiễu trong tín hiệu bạn gửi đi và cũng không đúng vị trí để xử lý tiếng vọng phát sinh từ phía bạn.&lt;/p&gt;

&lt;p&gt;AudioWorklet (callback xử lý âm thanh trên luồng thời gian thực) chỉ xuất hiện tường minh ở điểm A khi bạn tự dựng đồ thị Web Audio; còn khi dùng LiveKit, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; sẽ bao bọc lớp worklet đó.&lt;/p&gt;

&lt;h2 id=&quot;điểm-chèn-a-b-và-c&quot;&gt;Điểm chèn A, B và C&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A — Xử lý cục bộ, trước bước mã hóa.&lt;/strong&gt; Tín hiệu micro được lọc ngay trên máy khách trước khi phát hành track. Nhờ đó, SFU và mọi người tham gia khác đều nhận được giọng nói đã làm sạch. Đổi lại, bạn phải chịu độ trễ thuật toán trên đường găng và đảm bảo không làm lệch nhịp tham chiếu của bộ khử vọng. Đây chính là thiết kế của gói Mezon: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; triển khai giao diện TrackProcessor của LiveKit. Quy trình gồm khởi tạo processor, gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await audioTrack.setProcessor(filter)&lt;/code&gt;, rồi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await room.localParticipant.publishTrack(audioTrack)&lt;/code&gt;. LiveKit sẽ tự gọi phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; của processor để dựng đồ thị xử lý, hoàn toàn không tải PCM lên một máy chủ tăng cường riêng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B — Chỉ sử dụng APM của trình duyệt.&lt;/strong&gt; Các ràng buộc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;echoCancellation&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoGainControl&lt;/code&gt; ủy thác toàn bộ xử lý cho Audio Processing Module sẵn có của Chromium. Cách này tốn rất ít tài nguyên, nhưng phần điều khiển chủ yếu chỉ ở mức bật/tắt (boolean), hiệu quả với nhiễu không dừng thường kém hơn DeepFilterNet3 và không có thanh điều chỉnh mức khử nhiễu 0–100.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C — Xử lý trên SFU hoặc máy chủ đám mây.&lt;/strong&gt; Máy khách tiết kiệm CPU và chất lượng đồng đều giữa các thiết bị, nhưng phải đánh đổi bằng quyền riêng tư, chi phí máy chủ và độ trễ cộng thêm. Khử vọng trên máy chủ cũng khó khăn hơn nhiều vì máy chủ không nắm được tín hiệu tham chiếu đang phát ra loa của từng thiết bị. Hướng kiến trúc này thuộc một dòng sản phẩm khác với gói npm hiện tại.&lt;/p&gt;

&lt;h2 id=&quot;kết-hợp-apm-trình-duyệt-với-bộ-khử-nhiễu-mạng-nơ-ron&quot;&gt;Kết hợp APM trình duyệt với bộ khử nhiễu mạng nơ-ron&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khía cạnh&lt;/th&gt;
      &lt;th&gt;Khử nhiễu APM&lt;/th&gt;
      &lt;th&gt;DeepFilterNoiseFilterProcessor&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Điều khiển&lt;/td&gt;
      &lt;td&gt;Bật/tắt (boolean) theo mặc định trình duyệt&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; (0–100), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Độ trễ&lt;/td&gt;
      &lt;td&gt;Thường nhỏ&lt;/td&gt;
      &lt;td&gt;Độ trễ hop cộng mô hình; phải nằm trong ngân sách RTF&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Khử vọng (Echo)&lt;/td&gt;
      &lt;td&gt;AEC tích hợp sẵn trong APM&lt;/td&gt;
      &lt;td&gt;Cần giữ nguyên nhịp tham chiếu cho AEC&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Phân phối&lt;/td&gt;
      &lt;td&gt;Có sẵn trong trình duyệt&lt;/td&gt;
      &lt;td&gt;Tải WASM và mô hình từ CDN (bài 06-03, 07-03)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Phần lớn ứng dụng giữ nguyên &lt;strong&gt;khử vọng (AEC) và tự động cân bằng âm lượng (AGC)&lt;/strong&gt;, đồng thời đặt &lt;strong&gt;khử nhiễu mặc định của trình duyệt về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;&lt;/strong&gt; khi chạy processor mạng nơ-ron. Chạy nối tiếp hai bộ khử nhiễu sẽ khiến giọng nói bị đục và méo. Ví dụ cấu hình ràng buộc đầu vào:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;stream&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;navigator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mediaDevices&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getUserMedia&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;audio&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;echoCancellation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;noiseSuppression&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;autoGainControl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;channelCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Luôn ghi log kết quả từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;track.getSettings()&lt;/code&gt; trên trình duyệt đích, vì Chrome và Safari không phải lúc nào cũng áp dụng đúng mọi ràng buộc bạn yêu cầu.&lt;/p&gt;

&lt;p&gt;Các thành phần như WASM (WebAssembly — mã nhị phân chạy trong trình duyệt) và CDN (mạng phân phối nội dung) thuộc phạm vi triển khai của điểm chèn A, không phải điểm B.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tính-tay-ngân-sách-độ-trễ-một-chiều-và-hậu-quả-lọc-nhiễu-kép&quot;&gt;Giải thích: Tính tay ngân sách độ trễ một chiều và hậu quả lọc nhiễu kép&lt;/h2&gt;

&lt;h3 id=&quot;phép-tính-1-cộng-dồn-độ-trễ-từ-miệng-tới-tai-mouth-to-ear-ở-điểm-chèn-a-vs-điểm-c&quot;&gt;Phép tính 1: Cộng dồn độ trễ từ miệng tới tai (Mouth-to-Ear) ở điểm chèn A vs. điểm C&lt;/h3&gt;
&lt;p&gt;Theo khuyến nghị hội thoại thời gian thực (mốc thực hành chuẩn \(&amp;lt; 150\text{ ms}\) một chiều để không giẫm lời nhau):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Điểm chèn A (Local trước Opus):&lt;/strong&gt;
\(\underbrace{10\text{ ms}}_{\text{thu + AEC}} + \underbrace{40\text{ ms}}_{\text{DF3 look-ahead}} + \underbrace{12{,}7\text{ ms}}_{\text{ring buffer}} + \underbrace{20\text{ ms}}_{\text{khung Opus}} + \underbrace{35\text{ ms}}_{\text{mạng 1 chiều}} + \underbrace{20\text{ ms}}_{\text{jitter buffer}} = \mathbf{137{,}7\text{ ms}} &amp;lt; 150\text{ ms}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điểm chèn C (Giải mã → Khử nhiễu → Mã hóa lại trên SFU):&lt;/strong&gt; Phải gánh thêm giải mã + khung mới + hàng đợi máy chủ (\(\ge 35\text{ ms}\)), đẩy tổng độ trễ lên \(\ge \mathbf{172{,}7\text{ ms}}\), vượt ngưỡng dễ gây nói đè trong cuộc họp đông người!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phép-tính-2-vì-sao-bật-trùng-noisesuppression-true--deepfilternet3-làm-bay-màu-phụ-âm-gió&quot;&gt;Phép tính 2: Vì sao bật trùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression: true&lt;/code&gt; + DeepFilterNet3 làm “bay màu” phụ âm gió?&lt;/h3&gt;
&lt;p&gt;Xét một phụ âm xát nhẹ như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/s/&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/f/&lt;/code&gt; có năng lượng ban đầu \(P_0\).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Giả sử bộ NS của APM trình duyệt nhầm một phần phụ âm này là nhiễu gió nên suy giảm \(-12\text{ dB}\) (hệ số biên độ \(g_1 = 10^{-12/20} \approx 0{,}251\)).&lt;/li&gt;
  &lt;li&gt;Tín hiệu đã bị làm yếu đó lại đi tiếp vào DeepFilterNet3; thấy tỉ số SNR đã tụt sâu, bộ lọc thứ hai tiếp tục suy giảm thêm \(-8\text{ dB}\) (\(g_2 = 10^{-8/20} \approx 0{,}398\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng suy giảm nối tiếp:&lt;/strong&gt; \(-12 + (-8) = \mathbf{-20\text{ dB}}\) (biên độ tổng \(g_1 g_2 = 0{,}10\), công suất chỉ còn &lt;strong&gt;\(1\%\)&lt;/strong&gt; ban đầu!). Tắt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression: false&lt;/code&gt; trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt; giữ nguyên \(g_1 = 1\) để mạng nơ-ron tự quyết định trên tín hiệu trung thực.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;những-gì-processor-thực-sự-chèn-vào-đồ-thị&quot;&gt;Những gì processor thực sự chèn vào đồ thị&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; là lớp tích hợp công khai dành cho LiveKit, hoạt động dựa trên lớp lõi Web Audio bên dưới là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;. Khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; được gọi, processor khởi tạo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; ở tần số 48 kHz, gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; để tải mô hình và biên dịch WASM, rồi gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt;. Đồ thị tín hiệu có dạng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source → worklet → MediaStreamDestination&lt;/code&gt;, trong đó &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processedTrack&lt;/code&gt; là track âm thanh của destination mà LiveKit sẽ phát hành. Phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; giới hạn tham số về số nguyên trong khoảng 0–100 rồi gửi qua cổng của worklet. Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await filter.setEnabled(false)&lt;/code&gt; sẽ chuyển sang chế độ bypass mà không phá hủy đồ thị. Cuối cùng, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; sẽ đóng context và gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;proc.destroy()&lt;/code&gt; trên lớp core.&lt;/p&gt;

&lt;p&gt;Với các ứng dụng WebRTC thuần không sử dụng LiveKit, bạn vẫn có thể dựng đồ thị tương tự bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; rồi thay track gửi đi bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sender.replaceTrack(processedTrack)&lt;/code&gt;. Dù gói khai báo peer dependency là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;livekit-client&lt;/code&gt; ^2, lớp core vẫn hoạt động độc lập tốt bên ngoài LiveKit Room.&lt;/p&gt;

&lt;h3 id=&quot;đổi-thiết-bị-và-tắt-tiếng-mute&quot;&gt;Đổi thiết bị và tắt tiếng (mute)&lt;/h3&gt;

&lt;p&gt;Khi người dùng đổi micro, cần dọn đồ thị cũ bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; hoặc để LiveKit tự gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrack&lt;/code&gt; mới, sau đó phát hành lại track đã xử lý mới. Khi tắt tiếng, hãy tắt track hoặc gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt; và cập nhật giao diện trung thực với trạng thái thực tế, tránh để worklet bị treo mà người dùng không thấy cảnh báo. Chỉ yêu cầu cấp lại quyền micro khi trình duyệt thực sự đòi hỏi.&lt;/p&gt;

&lt;h2 id=&quot;khử-vọng-kích-thước-hop-và-sfu&quot;&gt;Khử vọng, kích thước hop và SFU&lt;/h2&gt;

&lt;p&gt;Bộ khử vọng (AEC) cần tín hiệu tham chiếu đồng bộ thời gian chặt chẽ với tín hiệu micro. Nếu bộ khử nhiễu chèn thêm độ trễ bất thường hoặc chạy lệch thứ tự kỳ vọng của AEC trình duyệt, cuộc gọi sẽ xuất hiện tiếng vọng dư hoặc bị cắt giọng. Do đó, hãy tận dụng AEC sẵn có của nền tảng, duy trì kích thước hop DeepFilter gần 10 ms ở 48 kHz (480 mẫu) theo đúng thiết kế khung của mô hình, và không tự viết thêm một lớp AEC thứ hai bằng JavaScript nếu chưa đo đạc kỹ.&lt;/p&gt;

&lt;p&gt;SFU chỉ chuyển tiếp các gói Opus mà không chia sẻ tín hiệu tham chiếu loa giữa các máy khách. Chi phí CPU cho khử nhiễu phát sinh theo từng người tham gia đang phát âm thanh (publisher), không phụ thuộc số lượng người nghe (subscriber). Nếu chỉ một nhóm máy khách nhất định được bật tính năng này, cần ghi rõ trong tài liệu hỗ trợ kỹ thuật.&lt;/p&gt;

&lt;h2 id=&quot;cấu-hình-kiến-trúc-đề-xuất&quot;&gt;Cấu hình kiến trúc đề xuất&lt;/h2&gt;

&lt;p&gt;Đối với ứng dụng họp trực tuyến trên trình duyệt dùng SFU LiveKit: chọn điểm chèn &lt;strong&gt;A&lt;/strong&gt;, sử dụng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, cấu hình trình duyệt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;echoCancellation: true&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression: false&lt;/code&gt;, đồng thời tải tài nguyên từ CDN do đội ngũ tự kiểm soát (bài 07-03) để việc hỗ trợ mạng nội bộ/mạng cách ly chỉ là vấn đề cấu hình đóng gói chứ không phải fork mã nguồn.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Lưu đoạn mã sau thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;insertion_check.py&lt;/code&gt; và chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 insertion_check.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;getUserMedia&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;new DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;publishTrack&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;constraints&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;echoCancellation&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;noiseSuppression&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;autoGainControl&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;order=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;browser_ns=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;constraints&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;noiseSuppression&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;order=getUserMedia &amp;gt; new DeepFilterNoiseFilterProcessor &amp;gt; setProcessor &amp;gt; publishTrack
browser_ns=False
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Bật đồng thời &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression: true&lt;/code&gt; cùng processor mạng nơ-ron, gây khử nhiễu hai lần liên tiếp.&lt;/li&gt;
  &lt;li&gt;Gắn processor lên track &lt;strong&gt;từ xa (remote)&lt;/strong&gt; rồi nhầm tưởng là đã làm sạch luồng gửi đi.&lt;/li&gt;
  &lt;li&gt;Chặn hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;room.connect()&lt;/code&gt; chờ tải xong tệp từ CDN; vì &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; chờ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, cần để tiến trình kết nối phòng chạy độc lập (bài 07-02).&lt;/li&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;replaceTrack&lt;/code&gt; bằng track micro thô sau khi đổi thiết bị, vô tình bỏ qua track đã xử lý.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Khử nhiễu hai lần khiến giọng nói bị đục và nghẹt.&lt;/li&gt;
  &lt;li&gt;Mặc định chạy khử nhiễu trên track từ xa, gây tốn CPU sai mục đích sản phẩm.&lt;/li&gt;
  &lt;li&gt;Vô tình lấy mẫu lại (resample) ra khỏi tần số 48 kHz trước khi đưa vào mô hình.&lt;/li&gt;
  &lt;li&gt;Quên đóng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; khi rời phòng, gây rò rỉ tài nguyên, chiếm giữ micro và hao pin.&lt;/li&gt;
  &lt;li&gt;Mặc định mọi ràng buộc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt; đều được áp dụng mà không kiểm tra lại bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getSettings()&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Vẽ sơ đồ luồng gửi và luồng nhận âm thanh của ứng dụng bạn đang phát triển, đồng thời đánh dấu điểm chèn bạn chọn để triển khai.&lt;/li&gt;
  &lt;li&gt;Trên Chrome, ghi lại kết quả &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getSettings()&lt;/code&gt; trong hai trường hợp yêu cầu bật và tắt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt; của trình duyệt.&lt;/li&gt;
  &lt;li&gt;Liệt kê ba tình huống thay đổi trạng thái thiết bị (chuyển tai nghe Bluetooth, cắm micro USB, chuyển tab sang nền) và xác định khi nào cần gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; hay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Trong khoảng 5 câu, giải thích vì sao khử nhiễu phía máy chủ SFU là một bài toán sản phẩm khác với gói npm này.&lt;/li&gt;
  &lt;li&gt;Lời gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await filter.setEnabled(false)&lt;/code&gt; tác động ở vị trí nào so với bước mã hóa, và tín hiệu nào vẫn tiếp tục được gửi tới SFU?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Triển khai điểm A trên track micro cục bộ; điểm B chỉ đóng vai trò phương án dự phòng chứ không chạy song song làm tầng xử lý thứ hai.&lt;/li&gt;
  &lt;li&gt;Luôn ghi lại giá trị &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt; thực tế trình duyệt cấp phát thay vì chỉ lưu đối tượng ràng buộc đầu vào.&lt;/li&gt;
  &lt;li&gt;Chuyển tai nghe Bluetooth hoặc micro USB đều cần gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; hoặc khởi tạo processor mới gắn với track mới. Khi tab chuyển sang nền, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; có thể bị &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suspend&lt;/code&gt; và cần &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt; sau thao tác tương tác của người dùng. Luôn gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; khi rời phòng.&lt;/li&gt;
  &lt;li&gt;Khử nhiễu trên đám mây xử lý âm thanh ở phía máy chủ, làm tăng chi phí hạ tầng, băng thông và đặt ra yêu cầu cao hơn về quyền riêng tư; đồng thời máy chủ không có tín hiệu tham chiếu loa của từng máy khách để phối hợp khử vọng. Gói npm giữ toàn bộ quá trình suy luận ngay trên trình duyệt.&lt;/li&gt;
  &lt;li&gt;Chế độ bypass vẫn nằm tại điểm chèn A: SFU tiếp tục nhận luồng micro trên cùng track đã phát hành nhưng không áp dụng bộ khử nhiễu, không cần mở khe phát hành mới.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bộ ví dụ chuẩn &lt;a href=&quot;https://webrtc.github.io/samples/&quot;&gt;WebRTC samples&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Tài liệu &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack&quot;&gt;MDN: MediaStreamTrack&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Tài liệu phát hành media của LiveKit: &lt;a href=&quot;https://docs.livekit.io/transport/media/publish/&quot;&gt;TrackProcessor / setProcessor on LocalAudioTrack&lt;/a&gt; và trang chủ tài liệu &lt;a href=&quot;https://docs.livekit.io/&quot;&gt;https://docs.livekit.io/&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Chương 03 về khử vọng (AEC) và Chương 05 về ngân sách xử lý của AudioWorklet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Revamping Audio Quality for RTC Part 1: Beryl Echo Cancellation&lt;/td&gt;
          &lt;td&gt;Sriram Srinivasan and Hoang Do](https://www.youtube.com/watch?v=lapq9zvUd-k) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video trình bày trọn chuỗi xử lý từ miệng người nói tới tai người nghe (thu âm, tăng cường, mã hóa, truyền mạng, giải mã, phát loa) — nền tảng để xác định đúng các điểm chèn.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d2N0d6CKrbk&quot;&gt;Group calling architectures in WebRTC: MCU, SFU &amp;amp; P2P&lt;/a&gt; — Tsahi Levent-Levi, tiếng Anh. Phân tích sự khác biệt giữa Mesh, MCU và SFU trong việc xử lý luồng âm thanh trên máy chủ, làm rõ vì sao cần khử nhiễu trước bước mã hóa.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Phần tích hợp cho thấy cách bộ khử nhiễu mạng nơ-ron vận hành chung với khử vọng và mất gói trong một hệ thống gọi thực tế.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-04 Đóng gói mô hình cho sản phẩm</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter06/06_04_model_packaging/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter06/06_04_model_packaging</id>
   <content type="html">&lt;p&gt;Bạn vừa hoàn thành một đồ thị ONNX chuẩn chỉnh, lượng tử hóa cẩn thận và biên dịch WASM SIMD chạy mượt trên máy cá nhân. Thế nhưng ngày ra mắt sản phẩm, hàng loạt người dùng lại báo khử nhiễu không bật lên được vì lỗi &lt;strong&gt;404 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.../v2/v2/pkg/df_bg.wasm&lt;/code&gt;&lt;/strong&gt;, hoặc phải chờ 5 giây mới vào được cuộc gọi vì trình duyệt cứ tải lại mô hình từ đầu mỗi lần tải trang! Đưa một mô hình học sâu vào sản phẩm không dừng lại ở thuật toán — nó còn là bài toán &lt;strong&gt;đóng gói, phân phối và quản trị phiên bản&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Một đồ thị ONNX (định dạng trao đổi đồ thị) chuẩn xác vẫn có thể thất bại khi đưa vào sản phẩm nếu khâu &lt;strong&gt;đóng gói&lt;/strong&gt; sai sót: dung lượng tải lần đầu quá lớn, URL không được lưu đệm (cache), tệp WASM và gói mô hình lệch phiên bản, hoặc vướng rào cản giấy phép phân phối. Gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; tách bạch hai lớp này: gói npm chỉ chứa mã kết nối JavaScript, AudioWorklet (callback xử lý âm thanh trên luồng thời gian thực) được nhúng nội tuyến và bộ nạp; còn hai tệp dung lượng lớn là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; được tải từ CDN (mạng phân phối nội dung) thông qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;. Bài học này trình bày bố cục tệp, quy tắc tiền tố phiên bản, kiểm tra tính toàn vẹn và phương án khôi phục (rollback). Chi tiết ghép nối URL đầy đủ sẽ được trình bày ở bài 07-03.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Vì sao mô hình tốt vẫn hỏng ở khâu phát hành → Kiến thức cần nhớ (Tách mã điều khiển vs. Tài nguyên nhị phân CDN, Cache bất biến &amp;amp; Mã băm SHA-256, Ma trận tương thích &amp;amp; Rollback không ghi đè) → Bố cục thư mục sidecar &amp;amp; quy tắc đường dẫn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; → Giải thích tính tay thời gian khởi động lạnh theo băng thông mạng và dò lỗi lặp tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/v2/v2/&lt;/code&gt; → Giấy phép, Staged rollout, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;WASM và kho ONNX đã đóng gói ở phía CDN của đường vào trình duyệt&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Khâu đóng gói quyết định chính xác những tệp nhị phân nào sẽ đi tới bước biên dịch WASM trên trình duyệt.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ tách bạch được gói npm khỏi các tệp tài nguyên trên CDN, áp dụng đúng quy tắc đường dẫn cho các phiên bản ≤ 1.1.2 và ≥ 1.2.0 (bao gồm bản 1.3.0 vốn tự động nối tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;), phát hiện và loại bỏ các &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; đã chứa sẵn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt;, đồng thời liệt kê đầy đủ các hạng mục kiểm tra giấy phép và cache trước khi phát hành.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-kỹ-thuật-đóng-gói-mô-hình-âm-thanh-web&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của kỹ thuật đóng gói mô hình âm thanh web&lt;/h2&gt;

&lt;h3 id=&quot;1-phân-tách-gói-điều-khiển-npm-và-tài-nguyên-nhị-phân-lớn-cdn-assets&quot;&gt;1. Phân tách Gói điều khiển (npm) và Tài nguyên nhị phân lớn (CDN Assets)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Gói npm chỉ giữ mã JavaScript/TypeScript gọn nhẹ và mã AudioWorklet nội tuyến, còn các tệp nặng hàng megabyte (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;) được tải bất đồng bộ từ CDN biên (edge cache).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Tránh làm phình kích thước bundle chính của ứng dụng web (giúp trang web tải nhanh), đồng thời cho phép tải trễ mô hình khử nhiễu mà không chặn thao tác bấm “Tham gia cuộc gọi”.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-đường-dẫn-bất-biến-immutable-versioned-urls-và-toàn-vẹn-sha-256&quot;&gt;2. Đường dẫn bất biến (Immutable Versioned URLs) và Toàn vẹn SHA-256&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Gắn mỗi đợt phát hành vào một thư mục phiên bản cố định kèm header &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control: public, max-age=31536000, immutable&lt;/code&gt; và khóa cặp tệp WASM + mô hình bằng bảng băm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SHA256SUMS&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Đưa thời gian tải mạng về &lt;strong&gt;0 ms&lt;/strong&gt; từ lần gọi thứ hai trở đi, đồng thời ngăn chặn lỗi lệch phiên bản (module SIMD mới chạy với gói trọng số cũ) và cho phép rollback tức thì bằng cách đổi con trỏ đường dẫn mà không bao giờ ghi đè URL cũ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-quản-trị-hợp-đồng-phiên-bản-compatibility-matrix-và-pháp-lý-trọng-số&quot;&gt;3. Quản trị hợp đồng phiên bản (Compatibility Matrix) và Pháp lý trọng số&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Hồ sơ đi kèm (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.json&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LICENSE_WEIGHTS.txt&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CHANGELOG.md&lt;/code&gt;) ràng buộc chặt phiên bản gói JS, opset ONNX, phiên bản &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;/ORT, cờ SIMD và điều khoản bản quyền trọng số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Đảm bảo tính tái lập trong CI/CD và tuân thủ pháp lý khi phân phối lại trọng số mã nguồn mở trong sản phẩm thương mại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Lượt tải lần đầu chặn cuộc gọi, và vì sao dung lượng gói npm không phản ánh đúng tải trọng thực tế.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Cặp tệp tài nguyên, tệp cấu hình đi kèm và quy ước phiên bản (semver).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Quy tắc tiền tố đường dẫn, nén dữ liệu và chính sách cache bất biến.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Kiểm tra toàn vẹn, tuân thủ giấy phép và phát hành theo từng giai đoạn (staged rollout).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab, bẫy thường gặp và làm bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;hai-thành-phần-một-sản-phẩm-thống-nhất&quot;&gt;Hai thành phần, một sản phẩm thống nhất&lt;/h3&gt;

&lt;p&gt;Lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install deepfilternet3-noise-filter&lt;/code&gt; cài đặt thư viện kèm phụ thuộc ngang hàng (peer dependency) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;livekit-client&lt;/code&gt; ^2. Theo README, mã nguồn worker và worklet đã được nhúng sẵn dưới dạng blob URL, nên các công cụ đóng gói như Webpack, Vite, Rollup, esbuild hay Parcel không cần cài thêm plugin sao chép tệp. Tuy nhiên, phần cài qua npm mới chỉ là lớp giao diện JavaScript gọn nhẹ, chưa bao gồm mô hình. Khi chạy, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core.initialize()&lt;/code&gt; tải song song hai tệp trọng yếu là module WASM (WebAssembly — mã nhị phân chạy trong trình duyệt) và gói nén mô hình — đây mới là phần quyết định thời gian khởi động lạnh. Lượng tử hóa (bài 06-02) và tối ưu SIMD (bài 06-03) giúp cải thiện dung lượng và tốc độ của hai tệp này, nhưng chỉ phát huy tác dụng khi cặp tệp được đăng tải lên đúng đường dẫn mà client gọi tới.&lt;/p&gt;

&lt;h3 id=&quot;tệp-siêu-dữ-liệu-đi-kèm-sidecar-nên-duy-trì&quot;&gt;Tệp siêu dữ liệu đi kèm (sidecar) nên duy trì&lt;/h3&gt;

&lt;p&gt;Kho lưu trữ tài nguyên của đội ngũ nên chứa đầy đủ siêu dữ liệu đi kèm để tránh việc wrapper và mô hình lệch nhau âm thầm. Một bố cục thư mục chuẩn cho quá trình quản lý có dạng như sau:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;models/df3-mono-48k/
  df_bg.wasm
  DeepFilterNet3_onnx.tar.gz
  config.json             # hop, sample_rate, shape state
  LICENSE_WEIGHTS.txt
  SHA256SUMS
  CHANGELOG.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.json&lt;/code&gt; đóng vai trò bảng kê kỹ thuật (manifest) ghi rõ tần số lấy mẫu (48000 Hz với gói này), độ dài hop, tên tensor đầu vào và kích thước trạng thái. API công khai của gói npm không yêu cầu bạn phải tải tệp này lên CDN — bản thân client chỉ yêu cầu đúng hai đường dẫn dưới &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; — nhưng việc lưu manifest song song giúp kỹ sư và hệ thống CI dễ dàng đối chiếu.&lt;/p&gt;

&lt;h3 id=&quot;quy-tắc-đường-dẫn-trong-readme&quot;&gt;Quy tắc đường dẫn trong README&lt;/h3&gt;

&lt;p&gt;README của gói quy định cấu trúc đường dẫn theo phiên bản như sau:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Phiên bản gói&lt;/th&gt;
      &lt;th&gt;Đường dẫn WASM&lt;/th&gt;
      &lt;th&gt;Đường dẫn gói mô hình&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;≤ 1.1.2&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/pkg/df_bg.wasm&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;≥ 1.2.0, gồm 1.3.0&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Với các phiên bản từ 1.2.0 trở lên, client sẽ tự động thêm tiền tố &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;; người cấu hình không được tự thêm vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;. Nếu đường dẫn gốc đã kết thúc bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/v2&lt;/code&gt;, URL sinh ra sẽ trở thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.../v2/v2/...&lt;/code&gt; và gặp lỗi 404. Đường dẫn gốc minh họa trong README là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/code&gt;. Tên gói mô hình là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; (từ kho DeepFilterNet gốc của Rikorose), còn tên tệp WASM là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tính-tay-ngân-sách-tải-lạnh-cold-start-và-kiểm-chứng-ghép-url&quot;&gt;Giải thích: Tính tay ngân sách tải lạnh (Cold Start) và kiểm chứng ghép URL&lt;/h2&gt;

&lt;h3 id=&quot;phép-tính-1-thời-gian-khởi-động-lạnh-từ-dung-lượng-nén-và-tốc-độ-mạng&quot;&gt;Phép tính 1: Thời gian khởi động lạnh từ dung lượng nén và tốc độ mạng&lt;/h3&gt;
&lt;p&gt;Giả sử cặp tệp sau khi nén trên CDN có tổng dung lượng minh họa là \(3{,}4\text{ MB}\) (gồm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; \(1{,}2\text{ MB}\) và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; \(2{,}2\text{ MB}\)), tương đương \(3{,}4 \times 8 = \mathbf{27{,}2\text{ Mb}}\) (megabit). Cộng thêm thời gian biên dịch WASM khoảng \(0{,}20\text{ s}\):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Kịch bản mạng&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Băng thông hiệu dụng&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Thời gian tải + RTT&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Biên dịch WASM&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Tổng khởi động lạnh&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;4G di động (lần đầu)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(10\text{ Mbps}\), RTT \(80\text{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\frac{27{,}2}{10} + 0{,}08 = 2{,}80\text{ s}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}20\text{ s}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(3{,}00\text{ s}\)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Wi-Fi laptop (lần đầu)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(50\text{ Mbps}\), RTT \(20\text{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\frac{27{,}2}{50} + 0{,}02 = 0{,}56\text{ s}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}20\text{ s}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(0{,}76\text{ s}\)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Lần gọi thứ 2 (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;immutable&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Cache cục bộ trình duyệt&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(0{,}00\text{ s}\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}20\text{ s}\) (hoặc cache mã máy)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(\le 0{,}20\text{ s}\)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nhìn vào dòng 4G di động (3 giây): nếu bạn chặn nút “Vào phòng họp” cho tới khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; xong, người dùng di động sẽ tưởng ứng dụng bị treo! Thay vào đó, hãy vào cuộc gọi ngay ở chế độ bypass rồi bật khử nhiễu mượt (crossfade) ngay khi cặp tệp tải xong.&lt;/p&gt;

&lt;h3 id=&quot;phép-tính-2-dò-lỗi-nối-đường-dẫn-v2-bằng-mắt-thường&quot;&gt;Phép tính 2: Dò lỗi nối đường dẫn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; bằng mắt thường&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Cấu hình đúng: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl = &quot;https://cdn.example.com/df3&quot;&lt;/code&gt; \(\xrightarrow{\text{client 1.3.0 nối } \texttt{/v2/}}\) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.example.com/df3/v2/pkg/df_bg.wasm&lt;/code&gt; (&lt;strong&gt;200 OK&lt;/strong&gt;).&lt;/li&gt;
  &lt;li&gt;Cấu hình sai: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl = &quot;https://cdn.example.com/df3/v2&quot;&lt;/code&gt; \(\xrightarrow{\text{client 1.3.0 nối } \texttt{/v2/}}\) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.example.com/df3/v2/v2/pkg/df_bg.wasm&lt;/code&gt; (&lt;strong&gt;404 Not Found&lt;/strong&gt;!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;cache-nén-dữ-liệu-và-kiểm-tra-toàn-vẹn&quot;&gt;Cache, nén dữ liệu và kiểm tra toàn vẹn&lt;/h3&gt;

&lt;p&gt;Cặp tệp tài nguyên cần được phục vụ kèm nén Brotli hoặc gzip (gói ONNX thường nén giảm dung lượng rất tốt; tệp WASM nén ít hơn nhưng vẫn đáng kể). Nên đặt tên tệp theo mã băm nội dung hoặc đặt trong thư mục phiên bản cố định kèm header &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control: public, max-age=31536000, immutable&lt;/code&gt;. Công bố mã băm SHA-256 và tự động đối chiếu sau khi tải về trong quy trình CI; chặn bản thử nghiệm canary nếu mã băm của WASM và mô hình không thuộc cùng một đợt phát hành. Một module SIMD mới chạy chung với gói mô hình từ tháng trước là lỗi đóng gói, không phải lỗi chất lượng mô hình.&lt;/p&gt;

&lt;p&gt;Tuyệt đối không ghi đè trực tiếp lên một URL đã gắn chính sách cache một năm vì điều đó sẽ gây xung đột dữ liệu ở máy khách. Khi nâng cấp, hãy xuất bản sang thư mục phiên bản mới và giữ nguyên thư mục cũ để có thể chuyển &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; ngược về hoặc hạ phiên bản gói ngay lập tức khi cần rollback mà không phải biên dịch lại toàn bộ hệ thống. Phiên bản gói JavaScript và thư mục tài nguyên phải luôn được quản lý theo cặp trong ma trận tương thích (gồm opset, phiên bản &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; hoặc ORT, tập tính năng SIMD và phiên bản trình duyệt tối thiểu).&lt;/p&gt;

&lt;h3 id=&quot;dung-lượng-là-quyết-định-theo-từng-kênh-triển-khai&quot;&gt;Dung lượng là quyết định theo từng kênh triển khai&lt;/h3&gt;

&lt;p&gt;Về mặt ngân sách kỹ thuật (mức định hướng thiết kế, không phải số đo cố định của khóa học): nền tảng web di động cần cặp tệp nén nhỏ gọn cho lượt tải đầu tiên, nền tảng máy tính để bàn có thể chấp nhận tải trễ bản đầy đủ hơn, còn ứng dụng native chịu giới hạn kích thước riêng của kho ứng dụng. Trọng số INT8 và các mô hình siêu nhẹ (bài 04-05) là công cụ chính để đáp ứng ngân sách di động; quyết định này phải được chốt trước bước tải lên CDN, đúng như vị trí của khâu lượng tử hóa nằm trước bước biên dịch WASM trong hình minh họa.&lt;/p&gt;

&lt;h3 id=&quot;đóng-gói-và-tuân-thủ-giấy-phép&quot;&gt;Đóng gói và tuân thủ giấy phép&lt;/h3&gt;

&lt;p&gt;Gói npm áp dụng giấy phép kép Apache-2.0 hoặc MIT, kế thừa từ dự án DeepFilterNet gốc. Khi phân phối lại tệp trọng số, bạn cần tuân thủ đúng điều khoản giấy phép của kho nguồn gốc và đính kèm đầy đủ thông báo bản quyền của các thư viện runtime bên thứ ba. Tuyệt đối không đưa tệp âm thanh của khách hàng vào gói phát hành; dù tệp mô hình không chứa bản ghi, dữ liệu telemetry ghi nhận chỉ số giọng nói vẫn có thể bị xếp vào nhóm dữ liệu cá nhân cần bảo vệ.&lt;/p&gt;

&lt;h3 id=&quot;phát-hành-theo-từng-giai-đoạn-staged-rollout&quot;&gt;Phát hành theo từng giai đoạn (staged rollout)&lt;/h3&gt;

&lt;p&gt;Hãy bắt đầu triển khai thử nghiệm (canary) trên một nhóm nhỏ người dùng máy tính để bàn, theo dõi sát tỉ lệ underrun và lỗi khởi tạo rồi mới mở rộng phạm vi. Cần tách bạch hai nhóm lỗi trong hệ thống log: các lỗi xảy ra lúc khởi động lạnh (như 404, CORS, sai kiểu MIME, lặp tiền tố đường dẫn) thuộc về khâu đóng gói, còn lỗi underrun trong trạng thái chạy ổn định thuộc về ngân sách hệ số thời gian thực.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Lưu đoạn mã sau thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prefix_check.py&lt;/code&gt; và chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 prefix_check.py&lt;/code&gt;. Hàm này kiểm tra đúng quy tắc từ README: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; dùng cho bản 1.3.0 không được kết thúc sẵn bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/v2&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;prefix_ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rstrip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/v2&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;double-prefix risk&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;base-ok&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;prefix_ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;https://example.com/df3&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;prefix_ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;https://example.com/df3/v2&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;base-ok
double-prefix risk
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tự thêm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/v2&lt;/code&gt; vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; vì nhìn thấy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; trong cột đường dẫn đã phân giải của bảng README, khiến client bản ≥ 1.2.0 nối thêm một lần nữa và gửi yêu cầu lỗi 404 tới &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.../v2/v2/...&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Chỉ tải &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; lên đường dẫn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/pkg/&lt;/code&gt; nhưng lại để tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tar.gz&lt;/code&gt; ở đường dẫn cũ của bản 1.1.2, làm lệch thế hệ giữa hai tệp.&lt;/li&gt;
  &lt;li&gt;Tính mã băm SHA-256 trên máy cá nhân nhưng lại tải một bản biên dịch khác lên CDN.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Đánh giá tải trọng mạng của sản phẩm chỉ dựa vào dung lượng lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Thiếu tệp manifest, khiến việc thay đổi độ dài hop vẫn nạp thành công về mặt kỹ thuật nhưng làm hỏng bước overlap-add.&lt;/li&gt;
  &lt;li&gt;Phát hành tệp WASM bản debug lên môi trường sản phẩm.&lt;/li&gt;
  &lt;li&gt;Gắn chuỗi truy vấn phá cache ở mỗi lần tải trang (ví dụ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?t=Date.now()&lt;/code&gt;), làm vô hiệu hóa hoàn toàn lợi ích của CDN.&lt;/li&gt;
  &lt;li&gt;Phục vụ lẫn lộn client bản ≤ 1.1.2 và ≥ 1.2.0 trên cùng một thư mục khi chưa bố trí đủ cả hai cấu trúc đường dẫn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Liệt kê các trường bắt buộc cần có trong tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.json&lt;/code&gt; để đảm bảo cấu hình hop 48 kHz của DeepFilter không bị lệch giữa các phiên bản.&lt;/li&gt;
  &lt;li&gt;Đề xuất ngân sách dung lượng nén phù hợp cho web di động và web máy tính để bàn, đồng thời nêu rõ biện pháp tương ứng (INT8, mô hình siêu nhẹ, tải trễ) để đạt từng ngân sách.&lt;/li&gt;
  &lt;li&gt;Mô tả quy trình rollback khôi phục lại cặp tệp tài nguyên phiên bản trước mà không cần chỉnh sửa mã nguồn kho sản phẩm.&lt;/li&gt;
  &lt;li&gt;Liệt kê các câu hỏi pháp lý về giấy phép cần làm rõ trước khi phân phối lại tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; cho mục đích thương mại.&lt;/li&gt;
  &lt;li&gt;Một đồng nghiệp cấu hình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.example.com/df3/v2&lt;/code&gt;. Client phiên bản ≥ 1.2.0 tuân theo README sẽ gửi yêu cầu tới những URL nào?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Cần ghi rõ tần số lấy mẫu (sample rate), độ dài hop, kích thước cửa sổ, tên các tensor đầu vào, kích thước tensor trạng thái và phiên bản gói đã dùng để kiểm chứng các kích thước đó.&lt;/li&gt;
  &lt;li&gt;Trên di động: ưu tiên lượng tử hóa hoặc chọn mô hình nhỏ hơn, đặt cặp tệp trên CDN thay vì gộp vào npm. Trên máy tính để bàn: có thể chấp nhận tải trễ miễn là không chặn thao tác tham gia cuộc gọi (bài 07-02).&lt;/li&gt;
  &lt;li&gt;Giữ nguyên thư mục tài nguyên cũ trên CDN; khi cần rollback chỉ cần trỏ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; về đường dẫn gốc của phiên bản trước hoặc ghim lại phiên bản gói cũ, tuyệt đối không ghi đè lên URL đã gắn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;immutable&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Cần kiểm tra điều khoản giấy phép của kho nguồn gốc, giấy phép kép Apache-2.0/MIT của gói, quy định về nhãn hiệu và quyền tự lưu trữ lại (mirror) tệp trọng số; luôn đọc kỹ model card gốc thay vì tự suy đoán là “phi thương mại”.&lt;/li&gt;
  &lt;li&gt;Client sẽ yêu cầu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.example.com/df3/v2/v2/pkg/df_bg.wasm&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.../v2/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt; — đây chính là lỗi lặp tiền tố.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;README của gói, mục &lt;em&gt;Custom CDN Configuration&lt;/em&gt;: &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;deepfilternet3-noise-filter&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;Tài liệu ONNX Runtime&lt;/a&gt; về định dạng tệp mô hình đã tối ưu hóa.&lt;/li&gt;
  &lt;li&gt;Tệp trọng số gốc &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet/blob/main/models/DeepFilterNet3_onnx.tar.gz&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Chương 07 về quy trình nạp mô hình qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; của LiveKit và chính sách xử lý khi CDN gặp sự cố.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video minh họa chặng đường chuyển đổi từ đồ thị huấn luyện sang tệp triển khai gọn nhẹ cho máy khách — nền tảng của bước đóng gói kết hợp WASM và cache.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=rIAIzf6utOc&quot;&gt;What is a CDN (Content Delivery Network) and How does a CDN Work?&lt;/a&gt; — Cloudflare, tiếng Anh. Giải thích cơ chế cache tại biên so với máy chủ gốc, giúp hình dung rõ cách phân phối các tệp mô hình tĩnh có dung lượng lớn.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=0VdNflU08yA&quot;&gt;Quantization explained with PyTorch - Post-Training Quantization, Quantization-Aware Training&lt;/a&gt; — Umar Jamil, tiếng Anh. Trình bày vai trò của lượng tử hóa trong việc giảm kích thước gói tải và cái giá phải đánh đổi về độ chính xác.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03 SIMD và triển khai WASM</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter06/06_03_simd_wasm/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter06/06_03_simd_wasm</id>
   <content type="html">&lt;p&gt;Cùng một tệp trọng số DeepFilterNet3, cùng một chiếc laptop — vậy mà trên trình duyệt này nó chạy mượt với RTF dưới 0,7, còn trên trình duyệt cũ hơn một chút nó lại vỡ tiếng hoặc thậm chí &lt;strong&gt;từ chối khởi động ngay ở dòng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt;&lt;/strong&gt;! Thủ phạm không nằm ở mô hình học sâu mà nằm ở tầng lệnh phần cứng bên dưới trình duyệt: &lt;strong&gt;WASM SIMD (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;)&lt;/strong&gt; và ranh giới tương thích Safari 16.4.&lt;/p&gt;

&lt;p&gt;Hiệu quả triển khai khử nhiễu mạng nơ-ron trên nền web phụ thuộc rất lớn vào thông lượng &lt;strong&gt;WASM&lt;/strong&gt; (WebAssembly — mã nhị phân chạy trong trình duyệt). Các yếu tố hạ tầng như &lt;strong&gt;SIMD&lt;/strong&gt; (một lệnh xử lý đồng thời nhiều dữ liệu với tập lệnh 128-bit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;), đa luồng khi trang web đủ điều kiện cấp phép và kiểu MIME của tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt; thường có ảnh hưởng ngang bằng với việc lựa chọn kiến trúc mô hình. Gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; từ phiên bản &lt;strong&gt;≥ 1.2.0&lt;/strong&gt; (bao gồm &lt;strong&gt;1.3.0&lt;/strong&gt;) phát hành bản dựng WASM có bật SIMD; README của gói cho biết bản này nhanh hơn khoảng &lt;strong&gt;20–30%&lt;/strong&gt; — lưu ý đây là số liệu công bố từ README, không phải kết quả đo đạc của khóa học. Bài học này trình bày cách phát hiện hỗ trợ tính năng trên trình duyệt, lý do Safari 16.4 là ranh giới bắt buộc, và cách AudioWorklet (callback xử lý âm thanh trên luồng thời gian thực) duy trì ngân sách xử lý khi thiết bị thiếu SIMD.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Tại sao cùng một mô hình lại có số phận khác nhau trên hai trình duyệt → Kiến thức cần nhớ (Vector hóa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;, Ranh giới cứng Safari 16.4 &amp;amp; Feature Detection, Cô lập nguồn gốc COOP/COEP cho đa luồng) → Cách SIMD tác động lên hop &amp;amp; mã dò &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.validate&lt;/code&gt; → Giải thích tính tay thông lượng thanh ghi 128-bit và Định luật Amdahl giải thích mức tăng tốc 20–30% → Ba trạng thái lỗi, chiến lược fallback, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;Bản WASM SIMD trên đường từ kho ONNX tới trình duyệt&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Gói từ phiên bản ≥ 1.2.0 tải module WASM SIMD theo cấu trúc đường dẫn CDN trình bày ở bài 07-03.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;Hệ số realtime của một hop AudioWorklet khi có và khi không có dư địa SIMD&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Hệ số thời gian thực so sánh thời gian xử lý với độ dài âm thanh của một hop; việc có hay không có SIMD có thể quyết định trực tiếp tỉ số này nằm dưới hay trên ngưỡng 1.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ giải thích được vì sao &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; tác động mạnh tới hệ số thời gian thực của các bộ tăng cường giọng nói nặng phép nhân ma trận, biết cách kiểm tra hỗ trợ tính năng ngay trên trình duyệt mà không cần trình biên dịch, áp dụng đúng mức phiên bản trình duyệt tối thiểu trong README (Chrome 91+, Firefox 89+, Safari 16.4+), và thiết kế phương án dự phòng (fallback) khi thiếu SIMD hoặc máy chủ trả sai kiểu MIME cho tệp WASM.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-hiệu-năng-webassembly-cho-âm-thanh&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của hiệu năng WebAssembly cho âm thanh&lt;/h2&gt;

&lt;h3 id=&quot;1-tập-lệnh-vector-hóa-128-bit-simd128--single-instruction-multiple-data&quot;&gt;1. Tập lệnh Vector hóa 128-bit (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; — Single Instruction, Multiple Data)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Phần mở rộng của WebAssembly ánh xạ trực tiếp xuống thanh ghi vector CPU (SSE/AVX trên x86, NEON trên ARM), cho phép một lệnh CPU nhân-cộng đồng thời &lt;strong&gt;4 số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;&lt;/strong&gt; (hoặc 8 số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i16&lt;/code&gt;, 16 số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i8&lt;/code&gt;) trong cùng một chu kỳ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Tăng tốc các nhân nhân ma trận (GEMM) của GRU và lớp tích chập mà không cần mở thêm luồng phụ — đặc biệt quý giá trong AudioWorklet vốn chạy đơn luồng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-ranh-giới-biên-dịch-cứng-và-dò-tính-năng-feature-detection&quot;&gt;2. Ranh giới biên dịch cứng và Dò tính năng (Feature Detection)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Mã nhị phân WASM chứa opcode &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; không tự động hạ cấp về chạy vô hướng trên trình duyệt cũ — bước &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt; sẽ ném ngoại lệ ngay lập tức trên Safari ≤ 16.3.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Dùng đoạn byte kiểm tra chuẩn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.validate(...)&lt;/code&gt; trước khi nạp module để chủ động rẽ nhánh sang bản không SIMD, bộ lọc APM trình duyệt hoặc bypass.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-cô-lập-nguồn-gốc-coopcoep-và-giới-hạn-đơn-luồng-mặc-định&quot;&gt;3. Cô lập nguồn gốc (COOP/COEP) và Giới hạn đơn luồng mặc định&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Đa luồng WASM cần &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt;, nhưng sau lỗ hổng Spectre, trình duyệt chỉ mở khóa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt; khi trang web gửi đủ hai header bảo mật &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cross-Origin-Opener-Policy&lt;/code&gt; (COOP) và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cross-Origin-Embedder-Policy&lt;/code&gt; (COEP).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Vì nhiều hệ thống web thực tế không thể bật COOP/COEP ngay (do nhúng iframe/tài nguyên bên thứ ba), mọi ngân sách RTF sản phẩm đều phải lập kế hoạch cho &lt;strong&gt;1 luồng WASM duy nhất&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Cùng một mô hình nhưng khác hệ số thời gian thực, và con số 20–30% từ README.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Tập lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;, kỹ thuật dò tính năng và mốc Safari 16.4.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Đa luồng, header COOP/COEP và lý do ngân sách mặc định chỉ tính cho 1 luồng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Khởi tạo AudioWorklet và phân loại ba trạng thái lỗi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab, bẫy thường gặp và làm bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;simd-thay-đổi-gì-trong-một-hop-xử-lý&quot;&gt;SIMD thay đổi gì trong một hop xử lý&lt;/h3&gt;

&lt;p&gt;Phép nhân ma trận và phép tích chập chiếm phần lớn thời gian tính toán trong một hop của họ mô hình DeepFilter. Tập lệnh SIMD xử lý thanh ghi 128-bit — tương ứng 4 phần tử &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; hoặc 8 phần tử &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i16&lt;/code&gt; trong cùng một lệnh — giúp tăng rõ rệt thông lượng số học. Hệ số thời gian thực của một hop dài \(H\) được định nghĩa là:&lt;/p&gt;

\[\mathrm{RTF} = \frac{T_{\mathrm{wall}}}{H}.\]

&lt;p&gt;Điều kiện \(\mathrm{RTF} &amp;lt; 1\) chỉ là điều kiện cần trên thiết bị đích và vẫn chưa đủ, bởi AudioWorklet còn phải gánh thêm thời gian cho STFT, sao chép bộ nhớ và bước mã hóa. README của gói nêu rằng bản dựng SIMD (từ bản ≥ 1.2.0) nhanh hơn khoảng 20–30%. Lấy ví dụ minh họa: một hop đang có RTF \(0.90\) sẽ giảm xuống khoảng \(0.63\)–\(0.72\) nếu mức tăng tốc đó đạt được trên laptop của bạn. Tuy nhiên, bạn luôn cần tự kiểm chứng bằng phân vị đo thực tế, không trích dẫn 20–30% như một kết quả thực nghiệm của bài lab.&lt;/p&gt;

&lt;p&gt;Quy trình biên dịch WASM công khai trong README kho mã nguồn bật các tính năng ngay lúc build: cờ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wasm-opt&lt;/code&gt; bao gồm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--enable-simd&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--enable-bulk-memory&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--enable-nontrapping-float-to-int&lt;/code&gt;, còn biến &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RUSTFLAGS&lt;/code&gt; bổ sung &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+simd128&lt;/code&gt; (các phiên bản ≤ 1.1.2 không bật nhóm tính năng này). Bài học này không yêu cầu bạn tự biên dịch, nhưng cần nắm rõ một đặc điểm quan trọng: module đã biên dịch với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; sẽ &lt;strong&gt;không thể khởi tạo&lt;/strong&gt; trên engine không hỗ trợ, chứ không tự động chuyển sang chạy chậm hơn.&lt;/p&gt;

&lt;p&gt;Trong chuỗi xử lý này, ONNX (định dạng trao đổi đồ thị) vẫn là tệp nguồn nằm trong gói mô hình; tối ưu SIMD nằm ở tầng mã máy của module WASM đã biên dịch chứ không nằm trong các tensor số thực bạn quan sát ở Python.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tính-tay-thông-lượng-simd128-và-định-luật-amdahl&quot;&gt;Giải thích: Tính tay thông lượng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; và Định luật Amdahl&lt;/h2&gt;

&lt;p&gt;Một sinh viên mới học SIMD thường hỏi: &lt;em&gt;“Thanh ghi 128-bit xử lý 4 số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; cùng lúc, vậy tại sao README lại chỉ nói nhanh hơn 20–30% chứ không phải nhanh gấp 4 lần (400%)?”&lt;/em&gt; Hãy dùng hai phép tính ngắn để giải đáp triệt để:&lt;/p&gt;

&lt;h3 id=&quot;phép-tính-1-số-lệnh-cho-một-phép-nhân-ma-trận-gru-256-times-256&quot;&gt;Phép tính 1: Số lệnh cho một phép nhân ma trận GRU \(256 \times 256\)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Số phép nhân-cộng (MAC): \(256 \times 256 = 65\,536\) phép.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chạy vô hướng (scalar):&lt;/strong&gt; cần \(65\,536\) lệnh nhân-cộng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chạy với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; (4 làn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;/lệnh):&lt;/strong&gt; số lệnh giảm xuống còn \(65\,536 / 4 = \mathbf{16\,384}\) lệnh vector — lý thuyết nhanh gấp \(4\times\) trên riêng nhân tính toán, nhưng thực tế bị băng thông cache và chi phí nạp thanh ghi kéo về khoảng \(3\times\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phép-tính-2-áp-dụng-định-luật-amdahl-lên-trọn-vẹn-một-hop-audioworklet&quot;&gt;Phép tính 2: Áp dụng Định luật Amdahl lên trọn vẹn một hop AudioWorklet&lt;/h3&gt;
&lt;p&gt;Trong một hop 10 ms hoàn chỉnh, không phải 100% thời gian đều nằm trong phép nhân ma trận vector hóa tốt — còn có STFT/iSTFT, hàm phi tuyến (sigmoid/tanh), điều phối bộ nhớ JS/WASM, sao chép ring buffer và các lớp kích thước nhỏ.
Giả sử phần vector hóa tốt chiếm tỉ trọng \(p = 0{,}40\) (40%) tổng thời gian hop và được tăng tốc \(S_{\text{vec}} = 3\times\) nhờ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;, còn \(60\%\) thời gian còn lại giữ nguyên:
\(\frac{T_{\text{SIMD}}}{T_{\text{scalar}}} = (1 - p) + \frac{p}{S_{\text{vec}}} = 0{,}60 + \frac{0{,}40}{3} \approx 0{,}733.\)
Mức giảm thời gian thực tế là \(1 - 0{,}733 = \mathbf{26{,}7\%}\) — rơi đúng vào giữa khoảng 20–30% công bố! Nếu trước đó hop của bạn chạy hết \(9{,}0\text{ ms}\) (\(\text{RTF} = 0{,}90\), cực kỳ sát trần), mức giảm \(26{,}7\%\) kéo thời gian xuống \(9{,}0 \times 0{,}733 \approx \mathbf{6{,}6\text{ ms}}\) (\(\text{RTF} = 0{,}66\)), mở ra tới &lt;strong&gt;3,4 ms khoảng dự phòng&lt;/strong&gt; quan trọng cho hệ điều hành!&lt;/p&gt;

&lt;h3 id=&quot;phiên-bản-trình-duyệt-tối-thiểu-và-ranh-giới-safari-164&quot;&gt;Phiên bản trình duyệt tối thiểu và ranh giới Safari 16.4&lt;/h3&gt;

&lt;p&gt;README của gói quy định bản dựng SIMD yêu cầu &lt;strong&gt;Chrome 91+&lt;/strong&gt;, &lt;strong&gt;Firefox 89+&lt;/strong&gt; và &lt;strong&gt;Safari 16.4+&lt;/strong&gt;. Mốc Safari 16.4 là ranh giới cứng, không phải tùy chọn có thể tinh chỉnh: Safari 16.3 trở về trước (bao gồm cả các phiên bản iOS dùng chung engine) sẽ từ chối module SIMD ngay ở bước biên dịch hoặc khởi tạo. Không tồn tại chế độ “SIMD một phần” để bản 1.3.0 chạy chậm lại trên các trình duyệt này. Do đó, ứng dụng cần chính sách dự phòng rõ ràng: chủ động dò tính năng rồi chuyển sang bản dựng không SIMD (như bản ≤ 1.1.2), dùng bộ khử nhiễu APM sẵn có của trình duyệt, hoặc bật bypass. Lưu ý rằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor.isSupported()&lt;/code&gt; chỉ kiểm tra sự tồn tại của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly&lt;/code&gt;, &lt;strong&gt;không&lt;/strong&gt; kiểm tra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;. Một trang web hoàn toàn có thể vượt qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported()&lt;/code&gt; nhưng sau đó vẫn lỗi trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt; từ chối module.&lt;/p&gt;

&lt;p&gt;Đoạn mã dò tính năng chuẩn dưới đây trả về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt; trên các engine hỗ trợ SIMD:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;simd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;WebAssembly&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Uint8Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;97&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;115&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;109&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;96&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;123&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;65&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;253&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;253&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;98&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hãy ưu tiên dùng đoạn dò chuẩn này — hoặc hàm tiện ích có trong tài liệu của runtime — thay vì tự ghép một danh sách opcode chưa được kiểm chứng.&lt;/p&gt;

&lt;h3 id=&quot;đa-luồng-đòi-hỏi-điều-kiện-hạ-tầng-khác&quot;&gt;Đa luồng đòi hỏi điều kiện hạ tầng khác&lt;/h3&gt;

&lt;p&gt;WASM đa luồng phụ thuộc vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt;, vốn chỉ được trình duyệt cấp phép trên các trang bật cơ chế cô lập nguồn gốc (cross-origin isolation thông qua header COOP và COEP). Nhiều hệ thống web thực tế không thể triển khai các header này ngay lập tức. Vì vậy, luôn lập ngân sách thời gian thực cho &lt;strong&gt;một&lt;/strong&gt; luồng WASM làm chuẩn; đa luồng chỉ nên xem là bước tối ưu bổ sung sau khi đã xác nhận trang cô lập nguồn gốc thành công, và cũng không nằm trong mức tăng tốc SIMD nêu ở README.&lt;/p&gt;

&lt;h3 id=&quot;kết-hợp-audioworklet-với-module-wasm&quot;&gt;Kết hợp AudioWorklet với module WASM&lt;/h3&gt;

&lt;p&gt;Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core.initialize()&lt;/code&gt; đảm nhiệm việc biên dịch WASM ngay trên luồng chính; sau đó &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt; mới khởi tạo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletNode&lt;/code&gt; mang tên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilter-audio-processor&lt;/code&gt;. Toàn bộ bước này phải hoàn tất trước khi luồng âm thanh bắt đầu chạy, vì worklet không bao giờ được phép biên dịch một module nặng nhiều megabyte bên trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt;. Đồng thời, cần giữ vùng nhớ heap ổn định: việc cấp phát bộ nhớ ở mỗi quantum qua ranh giới JS/WASM sẽ nhanh chóng triệt tiêu toàn bộ khoảng thời gian mà SIMD vừa tiết kiệm được. Các bước STFT và áp cửa sổ nằm ngoài đồ thị cũng phải tuân thủ kỷ luật tương tự và cần được đo thời gian tách biệt khỏi bước suy luận.&lt;/p&gt;

&lt;h3 id=&quot;ba-trạng-thái-kiểm-tra-hai-lỗi-triển-khai&quot;&gt;Ba trạng thái kiểm tra, hai lỗi triển khai&lt;/h3&gt;

&lt;p&gt;Phần mini-lab phân loại ba trạng thái triển khai cụ thể. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; là tính năng mà gói ≥ 1.2.0 yêu cầu, nên trên các trình duyệt đạt chuẩn README đây là trạng thái hợp lệ. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;missing simd&lt;/code&gt; là lỗi cứng vì module không thể khởi tạo. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wrong wasm mime&lt;/code&gt; gây lỗi khi bộ nạp dùng phương thức biên dịch trực tuyến (streaming compilation) nhưng máy chủ không trả về kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;application/wasm&lt;/code&gt;. Dù lớp core bản 1.3.0 biên dịch từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArrayBuffer&lt;/code&gt; lấy qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt; — ít phụ thuộc kiểu MIME hơn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;instantiateStreaming&lt;/code&gt; — CDN (mạng phân phối nội dung) vẫn bắt buộc phải phục vụ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; với kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;application/wasm&lt;/code&gt;, tránh việc các proxy trung gian đoán sai định dạng hoặc làm hỏng đường tải streaming sau này (bài 07-03).&lt;/p&gt;

&lt;h3 id=&quot;chiến-lược-suy-giảm-có-kiểm-soát&quot;&gt;Chiến lược suy giảm có kiểm soát&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if missing simd or wrong wasm mime or RTF p95 over budget:
    fallback = bản không SIMD HOẶC NS APM trình duyệt HOẶC bypass
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Không để một worklet phát ra tiếng nổ lách cách liên tục được coi là hoạt động thành công. Khi node đã khởi tạo xong, bạn có thể chuyển sang bypass bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled(false)&lt;/code&gt; trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await filter.setEnabled(false)&lt;/code&gt; trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;. Nếu lỗi xảy ra ngay từ bước biên dịch, đừng phát hành (publish) một processor đang dựng dở; thay vào đó hãy phát hành track âm thanh chưa qua xử lý và ghi nhận một cảnh báo không chặn luồng (bài 07-02).&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Bài lab không yêu cầu trình biên dịch. Lưu đoạn mã sau thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd_fail.py&lt;/code&gt; và chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 simd_fail.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;checks&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;simd128&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;pass&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing simd&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fail&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;wrong wasm mime&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fail&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;failed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;checks&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fail&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sorted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;failed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sorted&lt;/code&gt; giúp thứ tự in ra luôn nhất quán; tập hợp lỗi tương ứng là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{&quot;missing simd&quot;, &quot;wrong wasm mime&quot;}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[&apos;missing simd&apos;, &apos;wrong wasm mime&apos;]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;In trực tiếp kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;set&lt;/code&gt; mà không sắp xếp, khiến thứ tự phần tử thay đổi theo hash ngẫu nhiên của phiên Python.&lt;/li&gt;
  &lt;li&gt;Hiểu nhầm Safari 16.3 là “có hỗ trợ SIMD nhưng chạy chậm”; ranh giới cứng là Safari 16.4 và các bản cũ hơn sẽ báo lỗi khi nạp module.&lt;/li&gt;
  &lt;li&gt;Mặc định &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported()&lt;/code&gt; đã bao gồm kiểm tra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Cấu hình máy chủ trả về tệp WASM với kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text/plain&lt;/code&gt; rồi mất thời gian đi gỡ lỗi gói mô hình.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Chỉ kiểm thử trên Chrome phiên bản máy tính để bàn (nơi SIMD đã được hỗ trợ từ rất lâu).&lt;/li&gt;
  &lt;li&gt;Quên rằng Safari trên iOS cũng tuân theo mốc phiên bản 16.4.&lt;/li&gt;
  &lt;li&gt;Đưa bản dựng WASM tối ưu mức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-O0&lt;/code&gt; hoặc bản debug lên môi trường sản phẩm.&lt;/li&gt;
  &lt;li&gt;Bật chế độ đa luồng khi chưa cấu hình header COOP/COEP rồi nhầm lẫn hiện tượng treo là lỗi mô hình.&lt;/li&gt;
  &lt;li&gt;Trích dẫn mức tăng tốc 20–30% từ README như thể đây là số liệu tự đo được trong khóa học.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chạy đoạn mã dò &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.validate&lt;/code&gt; cho SIMD trên hai trình duyệt khác nhau và ghi lại kết quả đạt/không đạt kèm chuỗi phiên bản trình duyệt.&lt;/li&gt;
  &lt;li&gt;Nếu bản dựng vô hướng (không SIMD) có RTF p95 bằng \(1.1\) còn bản SIMD đạt \(0.45\), bạn sẽ triển khai phương án nào cho Safari 16.3?&lt;/li&gt;
  &lt;li&gt;Viết một ghi chú ngắn giải thích về header COOP/COEP gửi cho kỹ sư vận hành web trong trường hợp tuần này họ chưa thể thay đổi header của origin.&lt;/li&gt;
  &lt;li&gt;Đề xuất cách đo tách biệt thời gian chạy của STFT và thời gian suy luận mô hình bên trong AudioWorklet.&lt;/li&gt;
  &lt;li&gt;Vì sao lỗi sai kiểu MIME vẫn được xếp vào nhóm lỗi triển khai ngay cả khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt; trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArrayBuffer&lt;/code&gt; không kiểm tra header &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Content-Type&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Chrome 91+ và Firefox 89+ sẽ trả về đạt; Safari đạt từ bản 16.4 trở lên và không đạt ở các phiên bản trước đó.&lt;/li&gt;
  &lt;li&gt;Không gửi module SIMD tới Safari 16.3. Hãy chuyển sang bypass, dùng khử nhiễu APM của trình duyệt hoặc cấp bản dựng không SIMD; mức RTF 0,45 là vô nghĩa nếu module không khởi tạo được.&lt;/li&gt;
  &lt;li&gt;WASM đa luồng bắt buộc cần cơ chế cô lập nguồn gốc (COOP/COEP) để mở khóa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt;. Khi chưa thể bật header này, hệ thống phải thiết kế ngân sách xử lý dựa trên 1 luồng duy nhất.&lt;/li&gt;
  &lt;li&gt;Ghi nhận mốc thời gian riêng cho đoạn STFT và đoạn suy luận trong worklet rồi gửi định kỳ về luồng chính để tổng hợp phân vị p95; tuyệt đối không gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; trong mỗi quantum.&lt;/li&gt;
  &lt;li&gt;Phương thức khởi tạo streaming cũng như nhiều lớp proxy trung gian yêu cầu đúng kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;application/wasm&lt;/code&gt;; bài lab đánh dấu đây là lỗi để nhấn mạnh hợp đồng cấu hình chuẩn cho CDN.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Tài liệu MDN về WebAssembly SIMD và phương thức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.validate&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Ghi chú triển khai Web của &lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;ONNX Runtime&lt;/a&gt; về SIMD và đa luồng, dành cho các sản phẩm gọi trực tiếp ORT trên trình duyệt.&lt;/li&gt;
  &lt;li&gt;Ma trận hỗ trợ trình duyệt và thông tin SIMD trong README của gói &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;deepfilternet3-noise-filter&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Tài liệu MDN về &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;AudioWorklet&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nhTxJBgTywc&quot;&gt;Zoom on Web: getting connected with advanced web technology&lt;/a&gt; — Chrome for Developers, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video trình bày cách tận dụng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; và biên dịch từ Rust sang WebAssembly để tối ưu thông lượng xử lý trên trình duyệt.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, tiếng Anh. Phần về âm thanh minh họa WASM chạy trong callback thời gian thực — chính là ngữ cảnh bộ khử nhiễu khai thác SIMD.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, tiếng Anh. Giải thích rõ lý do tệp WASM SIMD và đồ thị ONNX phải luôn đồng bộ thành một cặp tương thích.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-02 Lượng tử hóa cho mô hình tiếng nói</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter06/06_02_quantization/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter06/06_02_quantization</id>
   <content type="html">&lt;p&gt;Trong thị giác máy tính, lượng tử hóa một mạng phân loại ảnh xuống INT8 thường chỉ làm độ chính xác top-1 nhích xuống 0,3% — mắt người chẳng hề nhận ra. Thế nhưng khi bạn mang đúng công thức lượng tử hóa đó áp vào một mô hình khử nhiễu giọng nói, chỉ một sai số làm tròn vỏn vẹn &lt;strong&gt;0,004&lt;/strong&gt; ở tầng xuất mặt nạ gain cũng đủ biến khoảng lặng thành tiếng rít kim loại khó chịu (musical noise) hoặc thổi bay toàn bộ phụ âm gió nhẹ! Tại sao bài toán tiếng nói lại nhạy cảm với độ phân giải gần 0 đến vậy?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lượng tử hóa (quantization)&lt;/strong&gt; giúp thu nhỏ dung lượng trọng số và thường đẩy nhanh tốc độ suy luận của mô hình tăng cường giọng nói. Điều này ảnh hưởng trực tiếp tới dung lượng tải xuống của bản WASM (WebAssembly — mã nhị phân chạy trong trình duyệt) và hệ số thời gian thực trên CPU. Tuy nhiên, lượng tử hóa không cẩn thận có thể làm méo giọng nói hoặc gây trôi trạng thái hồi tiếp. Rủi ro lớn nhất không nằm ở các trọng số có giá trị lớn mà nằm ở các hệ số khuếch đại (gain) gần 0, vì chúng nhân trực tiếp lên từng bin tần số. Bài học này trình bày lượng tử hóa INT8 ở góc độ kỹ thuật triển khai, cách hiệu chuẩn trên dữ liệu giọng nói thay vì ảnh, kèm một bài lab số học tự kiểm chứng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Vì sao tiếng nói nhạy hơn ảnh khi nén xuống INT8 → Kiến thức cần nhớ (Ánh xạ tuyến tính INT8, Độ nhạy tương đối theo thang dB gần 0, Hiệu chuẩn theo miền giọng nói &amp;amp; giữ lớp nhạy cảm ở &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;) → Công thức lượng tử hóa đối xứng &amp;amp; bảng 4 chế độ (Dynamic, Static PTQ, QAT, Weight-only) → Giải thích tính tay sai số theo dB trên 4 bin gain và so sánh tỉ lệ per-tensor vs. per-channel → Cổng kiểm duyệt phát hành, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;Trọng số đã lượng tử hóa được đóng vào kho mô hình trước khi trình duyệt tải WASM&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Quá trình lượng tử hóa diễn ra trước bước đóng gói và biên dịch WASM mà trình duyệt sẽ tải về.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ phân biệt được lượng tử hóa INT8 động và tĩnh, tính được hệ số tỉ lệ đối xứng cùng sai số tuyệt đối lớn nhất trên một véctơ gain, giải thích được vì sao các bin có gain gần 0 gây suy giảm chất lượng nghe rõ rệt nhất, và thiết kế được quy trình kiểm duyệt kết hợp nghe thử A/B với SI-SDR trước khi phát hành trọng số lượng tử hóa.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-toán-học-và-cảm-thụ-âm-thanh-phía-sau-lượng-tử-hóa-int8&quot;&gt;Kiến thức cần nhớ: Toán học và cảm thụ âm thanh phía sau lượng tử hóa INT8&lt;/h2&gt;

&lt;h3 id=&quot;1-lượng-tử-hóa-tuyến-tính-uniform-affine--symmetric-quantization&quot;&gt;1. Lượng tử hóa tuyến tính (Uniform Affine / Symmetric Quantization)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Nén số thực 32-bit (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;, 4 byte) xuống số nguyên 8-bit (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int8&lt;/code&gt;, 1 byte, 255 mức đối xứng trong \([-127, 127]\)) bằng phép chia cho bước lượng tử \(s\) và làm tròn: \(q = \mathrm{clip}(\mathrm{round}(g / s), -128, 127)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Giảm gấp 4 lần dung lượng trọng số và lưu lượng băng thông bộ nhớ, đồng thời cho phép dùng các lệnh nhân-cộng số nguyên nhanh hơn trên CPU — đổi lại là nhiễu làm tròn bị chặn bởi \(s/2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-sai-số-tuyệt-đối-đều-vs-cảm-thụ-logarit-db-của-tai-người&quot;&gt;2. Sai số tuyệt đối đều vs. Cảm thụ logarit (dB) của tai người&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Lượng tử hóa đều tạo ra sai số &lt;em&gt;tuyệt đối&lt;/em&gt; như nhau (\(\le s/2\)) trên toàn dải giá trị, nhưng tai người cảm nhận âm lượng theo thang &lt;strong&gt;logarit (decibel)&lt;/strong&gt; — tức phụ thuộc vào sai số &lt;em&gt;tương đối&lt;/em&gt; \(\hat{g}/g\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Giải thích nghịch lý cốt lõi của bài: cùng một sai số tuyệt đối \(0{,}0039\) là hoàn toàn vô hại ở \(g = 0{,}5\) (chỉ lệch 0,07 dB), nhưng lại là thảm họa gần &lt;strong&gt;+6 dB&lt;/strong&gt; ở bin nhiễu có \(g = 0{,}004\)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-hiệu-chuẩn-calibration-và-lượng-tử-hóa-hỗn-hợp-mixed-precision&quot;&gt;3. Hiệu chuẩn (Calibration) và Lượng tử hóa hỗn hợp (Mixed Precision)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Quy trình chạy một tập âm thanh đại diện (khoảng lặng, giọng nhỏ, tạp âm đám đông, SNR thấp) qua mô hình để ước lượng dải động từng lớp (Static PTQ), kết hợp giữ nguyên các lớp nhạy cảm (tầng xuất gain, trạng thái hồi tiếp GRU) ở &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Tránh hai lỗi chí mạng: dải tỉ lệ bị kéo giãn bởi một giá trị ngoại lai (per-tensor thay vì per-channel) và sai số lượng tử hóa tích lũy thành trôi trạng thái trên cuộc gọi dài.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Dung lượng tải và hệ số thời gian thực của bản WASM họ DeepFilter.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Lượng tử hóa INT8 đối xứng, tỉ lệ theo tensor so với tỉ lệ theo kênh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Dữ liệu âm thanh hiệu chuẩn và vì sao không thể dùng thống kê của ImageNet.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Các bin gain gần 0, nhiễu dư và hiện tượng trôi trạng thái.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab, bẫy thường gặp và làm bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;công-thức-tỉ-lệ-lượng-tử-hóa&quot;&gt;Công thức tỉ lệ lượng tử hóa&lt;/h3&gt;

&lt;p&gt;Một giá trị dấu phẩy động \(g\) được ánh xạ sang mã số nguyên \(q\) thông qua hệ số tỉ lệ \(s\) và điểm không (zero-point) tùy chọn \(z\):&lt;/p&gt;

\[g \approx s\,(q - z).\]

&lt;p&gt;Với véctơ gain sử dụng lượng tử hóa đối xứng (không có zero-point):&lt;/p&gt;

\[s = \frac{\max_i |g_i|}{127}, \qquad q_i = \mathrm{clip}\big(\mathrm{round}(g_i / s), -128, 127\big), \qquad \hat g_i = s\, q_i.\]

&lt;p&gt;Khi phép làm tròn hoạt động chuẩn, sai số khôi phục trên mỗi phần tử không vượt quá khoảng nửa bước lượng tử \(s/2\). Các nhân tính toán GEMM sẽ thực hiện phép nhân trên số nguyên rồi quy đổi ngược về thang số thực. Đối với lớp tích chập (convolution), dùng hệ số tỉ lệ &lt;strong&gt;theo từng kênh (per-channel)&lt;/strong&gt; thường vượt trội so với dùng một hệ số duy nhất cho cả tensor, bởi một kênh có giá trị ngoại lai lớn sẽ làm phình hệ số \(s\) của toàn bộ các kênh còn lại.&lt;/p&gt;

&lt;h3 id=&quot;nơi-sai-số-lượng-tử-hóa-trở-thành-tạp-âm-nghe-thấy-được&quot;&gt;Nơi sai số lượng tử hóa trở thành tạp âm nghe thấy được&lt;/h3&gt;

&lt;p&gt;Giả sử giá trị gain lớn nhất bằng \(1\). Khi đó \(s = 1/127 \approx 0.00787\), và sai số tuyệt đối chỉ ở mức vài phần nghìn. So với một bin có biên độ đầy thang, sai số này không đáng kể; nhưng với một bin có gain thực là \(0.004\), chỉ một mức mã nguyên đã tương đương toàn bộ tín hiệu. Trong bài mini-lab, véctơ \([1.0,\ 0.5,\ 0.02,\ 0.004,\ 0.0]\) được lượng tử hóa thành các mã \([127,\ 64,\ 3,\ 1,\ 0]\). Bin \(0.004\) bị đẩy lên thành \(1/127 \approx 0.00787\) — tức gần gấp đôi giá trị thật của một bin yếu — trong khi sai số tuyệt đối lớn nhất trên cả véctơ là khoảng \(0.00394\), xuất phát từ nửa bước làm tròn ở giá trị \(0.5\) chứ không phải ở bin đầy thang.&lt;/p&gt;

&lt;p&gt;Trong khử nhiễu giọng nói, những giá trị gain nhỏ đó đại diện cho các bin bị nhiễu lấn át và các họa âm yếu. Ép một họa âm về mã \(0\) sẽ khiến nguyên âm nghe mỏng và khô; ngược lại, làm tròn một bin gần im lặng lên 1 mức lượng tử sẽ làm rò rỉ một nền âm đơn điệu (tonal floor) — nguyên nhân phổ biến gây nhiễu nhạc (musical noise). Sai số trọng số trong lớp tích chập còn được các lớp phía sau làm mượt bớt, nhưng sai số ở đầu ra gain lại nhân thẳng vào các bin STFT rồi được cộng dồn ở bước overlap-add. Vì vậy, cần hiệu chuẩn cẩn thận và nghe kiểm tra trực tiếp đầu ra gain, kể cả khi giữ riêng nhánh này ở &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tính-tay-sai-số-lượng-tử-hóa-theo-thang-db-và-bẫy-per-tensor&quot;&gt;Giải thích: Tính tay sai số lượng tử hóa theo thang dB và bẫy Per-Tensor&lt;/h2&gt;

&lt;h3 id=&quot;phép-tính-1-quy-đổi-sai-số-lượng-tử-hóa-int8-sang-decibel-trên-4-bin-mẫu&quot;&gt;Phép tính 1: Quy đổi sai số lượng tử hóa INT8 sang decibel trên 4 bin mẫu&lt;/h3&gt;
&lt;p&gt;Với \(s = 1/127 \approx 0{,}007874\), hãy lập bảng kiểm tra từng phần tử của véctơ \(g = [1{,}0,\; 0{,}5,\; 0{,}02,\; 0{,}004]\) và tính sai số cảm thụ \(\Delta\text{dB} = 20\log_{10}(\hat{g}/g)\):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Gain thật \(g\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;\(g / s\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Mã nguyên \(q\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Gain khôi phục \(\hat{g} = s\,q\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Sai số tuyệt đối \(\vert \hat{g} - g \vert\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Sai số theo dB (\(20\log_{10}(\hat{g}/g)\))&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1{,}000\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(127{,}00\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(127\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1{,}0000\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}0000\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}00\text{ dB}\) (chính xác)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}500\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(63{,}50\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(64\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}5039\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}00394\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+0{,}07\text{ dB}\) (không nghe thấy)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}020\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2{,}54\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}0236\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}00362\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+1{,}45\text{ dB}\) (bắt đầu nhận ra)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}004\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}508\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}00787\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0{,}00387\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(+5{,}88\text{ dB}\)&lt;/strong&gt; (rò rỉ nhiễu rõ rệt!)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Hãy nhìn cột cuối cùng: dù sai số tuyệt đối ở \(0{,}500\) còn &lt;em&gt;lớn hơn&lt;/em&gt; ở \(0{,}004\) một chút (\(0{,}00394\) so với \(0{,}00387\)), nhưng trên thang logarit mà tai người nghe, bin \(0{,}004\) bị khuếch đại vọt gần &lt;strong&gt;+6 dB&lt;/strong&gt; (gấp đôi biên độ, gấp bốn lần công suất nhiễu lọt qua!).&lt;/p&gt;

&lt;h3 id=&quot;phép-tính-2-vì-sao-per-channel-thắng-áp-đảo-per-tensor-trên-lớp-tích-chập&quot;&gt;Phép tính 2: Vì sao Per-Channel thắng áp đảo Per-Tensor trên lớp tích chập?&lt;/h3&gt;
&lt;p&gt;Giả sử một lớp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Conv&lt;/code&gt; có 2 kênh: kênh 0 có trọng số cực đại \(4{,}0\), còn kênh 1 chỉ có trọng số cực đại \(0{,}1\).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lượng tử hóa Per-Tensor (dùng chung một \(s\)):&lt;/strong&gt; \(s = 4{,}0 / 127 \approx 0{,}0315\). Toàn bộ kênh 1 bị ép vào chỉ \(\lfloor 0{,}1 / 0{,}0315 \rfloor = 3\) mức số nguyên \(\{-3, -2, -1, 0, 1, 2, 3\}\) — mất hơn &lt;strong&gt;5 bit&lt;/strong&gt; độ phân giải!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lượng tử hóa Per-Channel (mỗi kênh một \(s_c\)):&lt;/strong&gt; Kênh 0 dùng \(s_0 = 4{,}0/127\), còn kênh 1 dùng \(s_1 = 0{,}1/127 \approx 0{,}000787\) — giữ trọn vẹn cả 255 mức INT8 cho kênh 1!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;các-phương-pháp-lượng-tử-hóa&quot;&gt;Các phương pháp lượng tử hóa&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Chế độ&lt;/th&gt;
      &lt;th&gt;Nguyên lý&lt;/th&gt;
      &lt;th&gt;Ưu điểm&lt;/th&gt;
      &lt;th&gt;Hạn chế&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Động (Dynamic)&lt;/td&gt;
      &lt;td&gt;Lượng tử hóa giá trị kích hoạt ngay khi chạy&lt;/td&gt;
      &lt;td&gt;Dễ thử nghiệm&lt;/td&gt;
      &lt;td&gt;Phát sinh chi phí tính toán thêm; độ trễ biến động&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;PTQ tĩnh (Static PTQ)&lt;/td&gt;
      &lt;td&gt;Hiệu chuẩn dải giá trị trước khi triển khai&lt;/td&gt;
      &lt;td&gt;Suy luận nhanh&lt;/td&gt;
      &lt;td&gt;Cần tập âm thanh hiệu chuẩn mang tính đại diện&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;QAT&lt;/td&gt;
      &lt;td&gt;Huấn luyện có mô phỏng nhiễu lượng tử&lt;/td&gt;
      &lt;td&gt;Chất lượng tốt khi hội tụ&lt;/td&gt;
      &lt;td&gt;Chi phí huấn luyện cao&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Chỉ trọng số (Weight-only)&lt;/td&gt;
      &lt;td&gt;Lưu trọng số ở INT8 hoặc INT4, giữ kích hoạt dạng float&lt;/td&gt;
      &lt;td&gt;Giảm dung lượng đơn giản&lt;/td&gt;
      &lt;td&gt;Mức tăng tốc thấp hơn&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Với bài toán tăng cường giọng nói streaming, lượng tử hóa sau huấn luyện dạng tĩnh (Static PTQ) bằng bộ công cụ của ONNX Runtime là bước thử nghiệm đầu tiên hợp lý. Chỉ nên chuyển sang huấn luyện có nhận biết lượng tử hóa (QAT) nếu chỉ số SI-SDR hoặc kết quả nghe thử bị sụt giảm rõ rệt. Lượng tử hóa là công đoạn thuộc khâu &lt;strong&gt;đóng gói&lt;/strong&gt;: nó phải thực hiện trước khi nén tệp mô hình và trước khi trình duyệt biên dịch WASM (bài 06-04, bài 07-03). Không nên lượng tử hóa một đồ thị khi bước STFT vẫn còn lệch với môi trường sản phẩm.&lt;/p&gt;

&lt;p&gt;Trong quy trình này, ONNX vẫn giữ vai trò định dạng trao đổi đồ thị: tệp sau khi lượng tử hóa được đưa vào gói mô hình rồi mới tới bước chạy trên WASM.&lt;/p&gt;

&lt;h3 id=&quot;tập-hiệu-chuẩn-phải-là-giọng-nói-không-phải-imagenet&quot;&gt;Tập hiệu chuẩn phải là giọng nói, không phải ImageNet&lt;/h3&gt;

&lt;p&gt;Nếu chỉ hiệu chuẩn trên nhiễu trắng (white noise), hệ số tỉ lệ thu được sẽ sai lệch khi gặp tạp âm đám đông (babble) ở quán cà phê hoặc giọng nói gần micro. Tập hiệu chuẩn cần bao phủ đầy đủ các tình huống: khoảng lặng, chỉ có nhiễu, giọng nói gần âm lượng lớn, bản trộn SNR thấp và đoạn mẫu có tiếng vọng dư nếu hệ thống có xử lý vọng. Một phút bản trộn đa dạng kiểu DNS là mức tối thiểu để thực hành; trong môi trường sản phẩm cần tập dữ liệu rộng hơn và được đóng băng cố định. Nếu bỏ qua bước này, mô hình dễ gặp hiện tượng bơm tiếng (pumping) hoặc nhiễu dư gắt mà các phép đo trên giọng sạch không phát hiện ra.&lt;/p&gt;

&lt;h3 id=&quot;các-thành-phần-thường-giữ-nguyên-float32&quot;&gt;Các thành phần thường giữ nguyên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;Các cổng tính toán theo từng phần tử (elementwise) nhạy cảm, tầng xuất hệ số gain cuối cùng và những lớp quá nhỏ (nơi chi phí chuyển đổi INT8 lớn hơn lợi ích mang lại) thường được giữ lại ở &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;. Nguyên tắc giữ lớp đầu và lớp cuối là kinh nghiệm thực tiễn phổ biến chứ không phải định lý cố định, nên vẫn cần đo kiểm thực tế. Trạng thái hồi tiếp là trường hợp đặc biệt cần lưu ý: một lỗi tràn số vốn chỉ gây ra một tiếng tách nhỏ trên mạng truyền thẳng lại có thể tích lũy và dao động đến hết cuộc gọi trong mạng hồi tiếp. Cần theo dõi dải giá trị trạng thái trên luồng âm thanh liên tục dài 30 phút (bài 05-04).&lt;/p&gt;

&lt;h3 id=&quot;cổng-kiểm-duyệt-trước-khi-phát-hành&quot;&gt;Cổng kiểm duyệt trước khi phát hành&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Đo độ chênh lệch SI-SDR và DNSMOS so với mô hình &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float&lt;/code&gt; trên tập kiểm thử đóng băng (Chương 08).&lt;/li&gt;
  &lt;li&gt;Nghe thử bắt buộc chọn (forced-choice) trên tối thiểu 10 cặp đoạn âm thanh, bao gồm cả các trường hợp có gain gần 0.&lt;/li&gt;
  &lt;li&gt;Chạy thử trên luồng âm thanh dài để phát hiện sớm hiện tượng trôi trạng thái.&lt;/li&gt;
  &lt;li&gt;Đo trực tiếp hệ số thời gian thực trên thiết bị đích, không suy diễn tốc độ chỉ từ việc dung lượng tệp giảm.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các ghi chú khảo sát về FastEnhancer và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;faster-enhancer.c&lt;/code&gt; cho thấy các nhân tính toán INT8 hợp nhất có thể cải thiện hệ số thời gian thực đáng kể, trong khi PTQ mặc định của ORT thường cho mức cải thiện khiêm tốn hơn — do đó luôn cần tự đo đạc. Ngoài ra, mức tăng tốc 20–30% mà README của gói gán cho SIMD (bài 06-03) là một cơ chế tối ưu khác, không phải kết quả của lượng tử hóa.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Lưu đoạn mã sau thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;quant_gain.py&lt;/code&gt; và chạy bằng lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 quant_gain.py&lt;/code&gt;. Script sử dụng hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;round&lt;/code&gt; của Python (quy tắc làm tròn nửa về số chẵn), khớp với các mã đầu ra bên dưới.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.004&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;scale&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;127.0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;127&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))))&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scale&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;qi&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;qi&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;q=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;max_abs_error=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;scale=0.00787402
q=[127, 64, 3, 1, 0]
max_abs_error=0.00393701
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Chia nhầm cho \(128\): biên dương của kiểu INT8 có dấu là \(127\), nên mã đầy thang phải là \(127\) chứ không phải \(128\).&lt;/li&gt;
  &lt;li&gt;Chỉ kiểm tra sai số tương đối trên bin \(1.0\) rồi kết luận bộ lượng tử hóa vô hại, trong khi bin \(0.004\) mới là trường hợp tiêu biểu của khử nhiễu giọng nói.&lt;/li&gt;
  &lt;li&gt;Lượng tử hóa trước khi đồng bộ chuẩn hóa STFT, khiến độ lệch dù chỉ một bin tần số bị đóng cứng vào hệ số tỉ lệ.&lt;/li&gt;
  &lt;li&gt;Nhầm lẫn rằng bài lab minh họa dùng cùng cơ chế zero-point với bộ lượng tử hóa tĩnh của ORT trong sản phẩm; công cụ thực tế có thể dùng lược đồ affine có zero-point, còn bài lab chủ đích dùng lược đồ đối xứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Chỉ hiệu chuẩn mô hình trên dữ liệu nhiễu trắng.&lt;/li&gt;
  &lt;li&gt;Phát hành mô hình INT8 nhưng không ghi lại độ chênh lệch chất lượng cho nhóm hỗ trợ kỹ thuật.&lt;/li&gt;
  &lt;li&gt;Bỏ qua nguy cơ tràn số bên trong các tensor trạng thái.&lt;/li&gt;
  &lt;li&gt;Coi tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tar.gz&lt;/code&gt; có dung lượng nhỏ hơn là bằng chứng cho thấy AudioWorklet đã đáp ứng ngân sách thời gian thực.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Tính lại hệ số tỉ lệ đối xứng cho tập trọng số nằm trong khoảng \([-0.8,\ 0.8]\). Giá trị \(s\) bằng bao nhiêu và \(0.8\) ánh xạ sang mã nguyên nào?&lt;/li&gt;
  &lt;li&gt;Liệt kê 8 loại đoạn âm thanh cần có trong một tập hiệu chuẩn sau huấn luyện kiểu Mezon.&lt;/li&gt;
  &lt;li&gt;Thiết kế một phiếu đánh giá nghe mù so sánh bản &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float&lt;/code&gt; với bản INT8, trong đó có ít nhất hai điều kiện kiểm tra vùng gain gần 0 (giọng nói nhỏ và nền nhiễu).&lt;/li&gt;
  &lt;li&gt;Tra cứu tài liệu chính thức của ONNX Runtime và nêu tên điểm vào (entry point) cho tác vụ lượng tử hóa mà bạn sẽ sử dụng (chưa cần chạy thực tế).&lt;/li&gt;
  &lt;li&gt;Dựa trên bin \(0.004\) trong bài mini-lab, giải thích vì sao tầng xuất gain là ứng viên kém phù hợp cho lượng tử hóa INT8 mạnh, ngay cả khi các lớp tích chập vẫn lượng tử hóa tốt.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(s = 0.8 / 127\). Vì \(0.8\) là giá trị tuyệt đối lớn nhất, nó ánh xạ tới mã \(127\). Không dùng \(255\) trừ khi chuyển sang lược đồ affine không dấu và nêu rõ quy ước.&lt;/li&gt;
  &lt;li&gt;Tám loại đoạn âm thanh gồm: khoảng lặng, chỉ có nhiễu, giọng nói âm lượng lớn, tiếng nói thì thầm, tạp âm đám đông ở SNR thấp, tiếng gõ bàn phím không dừng, một âm đơn tần (tone), và đoạn mẫu có tiếng vọng dư.&lt;/li&gt;
  &lt;li&gt;Sử dụng bài kiểm thử bắt buộc chọn (forced-choice), cân bằng âm lượng giữa hai mẫu, ẩn nhãn thuật toán và bổ sung tiêu chí đánh giá “nhiễu nhạc / giọng bị mỏng”.&lt;/li&gt;
  &lt;li&gt;Bắt đầu từ mục lượng tử hóa trong tài liệu ONNX Runtime: sử dụng quy trình Static PTQ kèm một &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CalibrationDataReader&lt;/code&gt;. Tên lớp cụ thể có thể thay đổi theo phiên bản API, nên cần trích dẫn đúng trang tài liệu đang dùng.&lt;/li&gt;
  &lt;li&gt;Giá trị \(0.004\) bị làm tròn lên xấp xỉ \(0.00787\), tức sai lệch tương đối gần gấp đôi áp thẳng lên một bin tần số. Khác với sai số trọng số ở các lớp ẩn vốn được các lớp sau lọc bớt, sai số trực tiếp trên mặt nạ gain sẽ đi thẳng ra tín hiệu âm thanh.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Hướng dẫn lượng tử hóa trong &lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;tài liệu ONNX Runtime&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Jacob và cộng sự — tài liệu nền tảng kinh điển về lượng tử hóa cho suy luận thuần số nguyên trên thiết bị di động.&lt;/li&gt;
  &lt;li&gt;Các ghi chú về FastEnhancer / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;faster-enhancer.c&lt;/code&gt; liên quan tới runtime tăng cường giọng nói dùng INT8 (tài liệu tham khảo mở rộng).&lt;/li&gt;
  &lt;li&gt;Các thảo luận về dung lượng mô hình và hiệu năng thời gian thực trong kho mã nguồn gốc DeepFilterNet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=0VdNflU08yA&quot;&gt;Quantization explained with PyTorch - Post-Training Quantization, Quantization-Aware Training&lt;/a&gt; — Umar Jamil, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video trình bày rõ lượng tử hóa sau huấn luyện (PTQ) và lượng tử hóa có nhận biết khi huấn luyện (QAT), giải thích vì sao một giá trị ngoại lai lớn trong khoảng min-max lại làm giảm độ phân giải của toàn bộ các giá trị gain nhỏ.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, tiếng Anh. Đoạn nói về INT8 minh họa cách đưa lượng tử hóa vào ONNX Runtime sau phần lý thuyết trên PyTorch.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=phmFvMOHt4I&quot;&gt;Enable Model Quantization for ONNX and TensorRT!&lt;/a&gt; — Nicolai Nielsen Tech, tiếng Anh. Minh họa quy trình nạp một đồ thị ONNX đã lượng tử hóa (phần TensorRT chỉ mang tính tham khảo, trọng tâm của bài vẫn là rủi ro trên mô hình giọng nói).&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-01 ONNX, tract và ORT</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter06/06_01_onnx_tract_ort/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter06/06_01_onnx_tract_ort</id>
   <content type="html">&lt;p&gt;Bạn vừa huấn luyện xong một mô hình khử nhiễu giọng nói đẹp như mơ trong PyTorch trên máy chủ GPU. Nhưng người dùng của bạn không mở Jupyter Notebook để gọi điện — họ mở một tab Chrome trên chiếc laptop mỏng nhẹ! Bạn không thể nhét cả thư viện PyTorch nặng hàng trăm megabyte vào trình duyệt, cũng không thể bắt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; chạy Python. Để băng qua vực thẳm giữa phòng thí nghiệm và sản phẩm thực tế, ta cần một bản thiết kế đồ thị độc lập ngôn ngữ (&lt;strong&gt;ONNX&lt;/strong&gt;) cùng một động cơ thực thi tinh gọn (&lt;strong&gt;ONNX Runtime&lt;/strong&gt; hoặc &lt;strong&gt;tract&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Khử nhiễu trực tiếp trên thiết bị gần như luôn yêu cầu &lt;strong&gt;xuất (export)&lt;/strong&gt; đồ thị đã huấn luyện sang một runtime suy luận chuyên biệt. &lt;strong&gt;ONNX&lt;/strong&gt; (định dạng trao đổi đồ thị) đóng vai trò tệp trung gian; &lt;strong&gt;ONNX Runtime (ORT)&lt;/strong&gt; là engine đa nền tảng phổ biến (bao gồm cả phiên bản Web); còn &lt;strong&gt;tract&lt;/strong&gt; là thư viện suy luận viết bằng Rust khi bạn cần một chuỗi thực thi thuần Rust. Gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; không đưa PyTorch vào trình duyệt: ghi chú phát hành công khai cho biết đường thực thi WASM (WebAssembly — mã nhị phân chạy trong trình duyệt) được xây dựng lại với &lt;strong&gt;tract 0.23.3&lt;/strong&gt;. Trình duyệt chỉ tải module đã biên dịch cùng tệp nén &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;, chứ không chạy một session Python. Bài học này xác định tiêu chí chọn runtime, hợp đồng đầu vào/đầu ra khi chạy streaming, và các lỗi kích thước tensor (shape) khiến đồ thị chạy được trong notebook nhưng lại lỗi khi đưa vào AudioWorklet (callback xử lý âm thanh trên luồng thời gian thực).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Vực thẳm từ PyTorch sang trình duyệt → Kiến thức cần nhớ (Đồ thị tĩnh ONNX &amp;amp; Opset, Runtime ORT vs. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;, Hợp đồng Tensor Streaming &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, T, F]&lt;/code&gt;) → Cấu trúc tệp ONNX &amp;amp; cố định phiên bản → Bảng so sánh ORT và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; → Giải thích tính tay dung lượng I/O từng hop và hậu quả của lỗi cố định trục &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T=100&lt;/code&gt; / sót &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; → Mini-lab, Bẫy thường gặp và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;Đồ thị ONNX được xuất thành module WASM, trình duyệt tải cạnh kho mô hình&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. ONNX là định dạng tệp trao đổi; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; hoặc ORT đảm nhiệm việc thực thi; cuối cùng trình duyệt khởi tạo module WASM.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ giải thích được vai trò định dạng trao đổi của ONNX trong tăng cường giọng nói, so sánh được ORT với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; cho ứng dụng trình duyệt và tệp thực thi Rust, liệt kê được các lỗi export chỉ bộc lộ khi chạy từng hop, đồng thời phân biệt được tensor ảnh kiểu NCHW với khung đặc trưng kiểu DeepFilter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, T, F]&lt;/code&gt; trước khi khởi tạo session.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-chuỗi-biên-dịch-và-thực-thi-suy-luận-trên-thiết-bị-biên-gồm-những-gì&quot;&gt;Kiến thức cần nhớ: Chuỗi biên dịch và thực thi suy luận trên thiết bị biên gồm những gì?&lt;/h2&gt;

&lt;h3 id=&quot;1-biểu-diễn-trung-gian-onnx--open-neural-network-exchange-và-opset&quot;&gt;1. Biểu diễn trung gian (ONNX — Open Neural Network Exchange) và Opset&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Một định dạng nhị phân (Protobuf) mô tả mạng nơ-ron dưới dạng &lt;strong&gt;đồ thị có hướng không chu trình (DAG)&lt;/strong&gt; gồm các nút toán tử chuẩn hóa (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Conv&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GRU&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MatMul&lt;/code&gt;…) và các tensor trọng số cố định (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initializer&lt;/code&gt;), được đánh phiên bản qua &lt;strong&gt;opset&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Tách rời công cụ &lt;em&gt;huấn luyện&lt;/em&gt; (PyTorch/JAX) khỏi công cụ &lt;em&gt;thực thi&lt;/em&gt; (C++, Rust, WASM), giúp đồ thị được tối ưu hóa tĩnh (gộp lớp, loại bỏ nút thừa, tiền tính hằng số) trước khi chạy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-động-cơ-suy-luận-inference-runtime-onnx-runtime-ort-vs-tract&quot;&gt;2. Động cơ suy luận (Inference Runtime): ONNX Runtime (ORT) vs. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Chương trình đọc tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt;, lập lịch bộ nhớ tĩnh (memory arena) và gọi các nhân tính toán tối ưu hóa phần cứng (SIMD, AVX, NEON, WebGPU).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Lựa chọn đúng công cụ theo đích triển khai: ORT mạnh về độ phủ toán tử đa nền tảng và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnxruntime-web&lt;/code&gt;; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; thuần Rust giúp biên dịch gọn cùng lõi DSP &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libDF&lt;/code&gt; sang một tệp WASM thống nhất như trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-hợp-đồng-tensor-streaming-1-t-f--state_instate_out&quot;&gt;3. Hợp đồng Tensor Streaming (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, T, F]&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state_in&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state_out&lt;/code&gt;)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Giao diện cố định giữa phần DSP bên ngoài (STFT/iSTFT, cửa sổ, OLA) và đồ thị ONNX bên trong — yêu cầu chính xác bậc tensor, trục thời gian &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T = 1&lt;/code&gt; và các cổng truyền trạng thái tường minh.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Ngăn chặn nhóm lỗi “chạy mượt khi test offline theo lô nhưng nổ tung ở thời gian thực” do trục tĩnh, lệch kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; hoặc thiếu tensor trạng thái.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Vì sao AudioWorklet không chứa framework huấn luyện.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Đồ thị tính toán, initializer, phiên bản opset và bên nào đảm nhiệm STFT.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — So sánh ORT với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;, bao gồm phiên bản &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; cố định ở bản 1.3.0.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Trục động, tensor trạng thái và kiểm tra shape.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab, bẫy thường gặp và làm bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;tệp-onnx-thực-sự-chứa-gì&quot;&gt;Tệp ONNX thực sự chứa gì&lt;/h3&gt;

&lt;p&gt;Một tệp ONNX biểu diễn đồ thị tính toán gồm các tensor vào/ra có tên, danh sách toán tử (như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Conv&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GRU&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MatMul&lt;/code&gt;) và bộ trọng số lưu trong mục initializer. Framework huấn luyện xuất ra tệp này, còn runtime suy luận sẽ tối ưu hóa và thực thi nó. Trong bài toán tăng cường giọng nói, đồ thị có thể tích hợp sẵn bước trích xuất đặc trưng hoặc kỳ vọng ứng dụng tự chạy STFT ở bên ngoài session. Các mô hình họ DeepFilter thường đi theo hướng thứ hai: runtime nhận từng khung phổ làm đầu vào, còn bước cộng chồng lấp (overlap-add) nằm ở phía ngoài. Nếu hai bên lệch nhau về bước nhảy (hop), cửa sổ hoặc số bin tần số, session vẫn trả về tensor hợp lệ nhưng âm thanh đầu ra sẽ bị sai.&lt;/p&gt;

&lt;h3 id=&quot;cố-định-phiên-bản-opset-và-runtime&quot;&gt;Cố định phiên bản opset và runtime&lt;/h3&gt;

&lt;p&gt;Tập toán tử của ONNX được đánh số theo &lt;strong&gt;opset&lt;/strong&gt;. Một mô hình xuất bằng opset 17 có thể không nạp được trên phiên bản ORT cũ hơn. Do đó, cần cố định đồng thời ba yếu tố: phiên bản opset khi xuất, phiên bản ORT hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; đưa vào sản phẩm, và một tác vụ CI kiểm tra nạp đúng tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt; trên chính runtime sẽ phát hành. Ghi chú phát hành bản 1.3.0 của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; nêu rõ phiên bản &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; &lt;strong&gt;0.23.3&lt;/strong&gt; cho bản dựng WASM. Đây là thông tin phát hành thực tế, không phải lý do để bỏ qua bước kiểm tra toán tử: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; và ORT không hỗ trợ hoàn toàn cùng một tập toán tử. Một đồ thị mở được bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnxruntime&lt;/code&gt; trong Python vẫn có thể gặp lỗi trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; nếu lớp lọc sâu (deep filter) tùy biến chưa được gộp thành các toán tử được hỗ trợ.&lt;/p&gt;

&lt;h3 id=&quot;so-sánh-ort-và-tract&quot;&gt;So sánh ORT và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tiêu chí&lt;/th&gt;
      &lt;th&gt;ONNX Runtime&lt;/th&gt;
      &lt;th&gt;tract&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Ngôn ngữ&lt;/td&gt;
      &lt;td&gt;C/C++, Python, Java, C#, JS/WASM&lt;/td&gt;
      &lt;td&gt;Ưu tiên Rust&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đường triển khai web&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnxruntime-web&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Không phải đường trình duyệt mặc định&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tối ưu hóa&lt;/td&gt;
      &lt;td&gt;Tối ưu đồ thị và execution provider&lt;/td&gt;
      &lt;td&gt;Đồ thị thuần Rust, phù hợp streaming&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Phù hợp sản phẩm&lt;/td&gt;
      &lt;td&gt;Đồng nhất trên nhiều nền tảng&lt;/td&gt;
      &lt;td&gt;Đường Rust được ghi chú WASM 1.3.0 đề cập&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Độ phủ toán tử&lt;/td&gt;
      &lt;td&gt;Rộng theo mặc định&lt;/td&gt;
      &lt;td&gt;Cần kiểm chứng trực tiếp trên bản xuất DeepFilter&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Hãy chọn ORT khi cần một tệp ONNX dễ kiểm chứng từ Python đi kèm backend Web có tài liệu đầy đủ. Hãy chọn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; khi sản phẩm phát hành là tệp thực thi Rust và bạn đã kiểm tra xong toàn bộ toán tử. Trên trình duyệt, gói của Mezon sử dụng WASM biên dịch từ ngăn xếp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libDF&lt;/code&gt; của DeepFilter với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; được nhắc tới trong changelog 1.3.0. Phần thực hành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; tùy chọn ở Chương 09 là nơi bạn trực tiếp ghép nối với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;; không nên biến wrapper npm thành một mô hình thứ hai.&lt;/p&gt;

&lt;h3 id=&quot;quy-ước-trục-dữ-liệu-khi-chạy-streaming&quot;&gt;Quy ước trục dữ liệu khi chạy streaming&lt;/h3&gt;

&lt;p&gt;Mô hình streaming cần khai báo khung đầu vào có trục thời gian đúng bằng một hop, đi kèm các tensor trạng thái hồi tiếp ở đầu vào và đầu ra. Hợp đồng tiêu chuẩn ở đây là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;features&lt;/code&gt; có kích thước &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, T, F]&lt;/code&gt; với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T = 1&lt;/code&gt; trong callback, cùng cặp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state_in&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state_out&lt;/code&gt; có kích thước cố định. Trục batch động hữu ích khi chạy kiểm thử offline, nhưng trong callback âm thanh gần như luôn bằng 1. Cần khai báo rõ ràng các trục này khi xuất mô hình; một số kịch bản kiểm thử offline vô tình cố định cứng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T = 100&lt;/code&gt; lúc export, khiến đồ thị vẫn nạp thành công nhưng từ chối mọi hop thời gian thực.&lt;/p&gt;

&lt;p&gt;Định dạng NCHW như &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 3, 224, 224]&lt;/code&gt; là quy ước cho dữ liệu ảnh. Dù chiều đầu tiên bằng 1, tensor bậc 4 vẫn sai kích thước đối với khung đặc trưng DeepFilter; hợp đồng của bài học chỉ chấp nhận tensor bậc 3 với chiều batch bằng 1. Bước triển khai thực tế sau bài kiểm tra minh họa này là khởi tạo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ort.InferenceSession&lt;/code&gt; và đối chiếu &lt;strong&gt;tên đầu vào&lt;/strong&gt; khớp hoàn toàn với đồ thị, chứ không chỉ kiểm tra số chiều.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tính-tay-ngân-sách-io-của-một-hop-onnx-và-hai-cái-bẫy-export-kinh-điển&quot;&gt;Giải thích: Tính tay ngân sách I/O của một hop ONNX và hai cái bẫy export kinh điển&lt;/h2&gt;

&lt;h3 id=&quot;phép-tính-1-kích-thước-byte-truyền-qua-ranh-giới-session-ở-mỗi-hop-t--1&quot;&gt;Phép tính 1: Kích thước byte truyền qua ranh giới session ở mỗi hop (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T = 1&lt;/code&gt;)&lt;/h3&gt;
&lt;p&gt;Xét một hop kiểu DeepFilter ở 48 kHz với kiểu dữ liệu chuẩn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; (4 byte/phần tử):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Đặc trưng băng ERB &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feat_erb&lt;/code&gt; shape &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 1, 32]&lt;/code&gt;: \(32 \times 4 = \mathbf{128\text{ byte}}\).&lt;/li&gt;
  &lt;li&gt;Đặc trưng phổ phức tần số thấp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feat_spec&lt;/code&gt; shape &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 1, 96, 2]&lt;/code&gt; (phần thực + ảo cho 96 bin): \(96 \times 2 \times 4 = \mathbf{768\text{ byte}}\).&lt;/li&gt;
  &lt;li&gt;Trạng thái ẩn GRU &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h_in&lt;/code&gt; shape &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 1, 256]&lt;/code&gt;: \(256 \times 4 = \mathbf{1\,024\text{ byte}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tổng đầu vào cho 1 hop:&lt;/strong&gt; \(128 + 768 + 1024 = \mathbf{1\,920\text{ byte} \approx 1{,}88\text{ KB}}\) — nằm gọn trong bộ nhớ đệm L1 của CPU!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phép-tính-2-cái-giá-của-hai-lỗi-export-phổ-biến&quot;&gt;Phép tính 2: Cái giá của hai lỗi export phổ biến&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cố định cứng trục &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T = 100&lt;/code&gt; lúc export (lấy nhầm mẫu 1 giây làm dummy input):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tensor đầu vào phình gấp 100 lần; nếu cố “chữa cháy” bằng cách gom đủ 100 hop mới gọi session một lần, bạn lập tức cộng thêm \(100 \times 10\text{ ms} = \mathbf{1\,000\text{ ms}}\) (1 giây trọn vẹn!) độ trễ vào cuộc gọi — biến hội thoại thời gian thực thành bộ đàm!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sót kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; (mặc định của NumPy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.zeros&lt;/code&gt;) thay vì &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Mỗi tensor tăng gấp đôi dung lượng byte (từ 4 lên 8 byte/phần tử).&lt;/li&gt;
      &lt;li&gt;Trên thanh ghi WASM &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; (128 bit), một lệnh chỉ xử lý được \(128 / 64 = \mathbf{2}\) số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; thay vì \(128 / 32 = \mathbf{4}\) số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;, làm thông lượng số học giảm ngay một nửa trước khi tính đến chi phí ép kiểu!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;các-lỗi-thường-gặp-khi-xuất-mô-hình&quot;&gt;Các lỗi thường gặp khi xuất mô hình&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Toán tử không được hỗ trợ&lt;/strong&gt; trong các lớp deep filter tùy biến: cần gộp thành các toán tử chuẩn của ONNX hoặc đăng ký toán tử mở rộng cho runtime, tránh tự đặt tên toán tử tùy tiện.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Rẽ nhánh điều khiển (control-flow) và thao tác ghi đè (in-place)&lt;/strong&gt; cho kết quả khác nhau giữa quá trình huấn luyện và đồ thị đã xuất.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thiếu cổng truyền trạng thái&lt;/strong&gt; của GRU, khiến mô hình trở thành không trạng thái và gây hiện tượng bơm tiếng giữa các hop.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sót kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;:&lt;/strong&gt; cần ép toàn bộ về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; trước khi lượng tử hóa hoặc biên dịch sang WASM.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lệch tiền xử lý:&lt;/strong&gt; phép tính STFT bằng NumPy lúc huấn luyện không khớp với STFT trong WASM khi chạy sản phẩm.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;vì-sao-trình-duyệt-biên-dịch-trước-một-module-chuẩn-hóa&quot;&gt;Vì sao trình duyệt biên dịch trước một module chuẩn hóa&lt;/h3&gt;

&lt;p&gt;Gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; không yêu cầu trang web tự dựng session ORT. Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core.initialize()&lt;/code&gt; sẽ tải dữ liệu nhị phân WASM cùng tệp nén mô hình rồi gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt; trên luồng chính; hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt; chỉ chạy sau khi biên dịch xong. Nhờ đó, phần việc nặng được tách hoàn toàn khỏi callback âm thanh (Chương 05). Dù vậy, ORT vẫn là công cụ chuẩn để kiểm tra độ tương đương số học trong Python cũng như cho các sản phẩm gọi trực tiếp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnxruntime-web&lt;/code&gt;. Khi đánh giá hiệu năng, luôn đo hệ số thời gian thực trên chính bản WASM phát hành vì thời gian chạy ORT trên Python thuộc một môi trường hoàn toàn khác.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Nếu đã cài đặt ONNX Runtime, bạn có thể kiểm tra nhanh bằng lệnh tùy chọn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 -c &quot;import onnxruntime&quot;&lt;/code&gt;. Phần bắt buộc của bài lab là viết chương trình kiểm tra kích thước tensor: lưu đoạn mã sau thành &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shape_check.py&lt;/code&gt; và chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 shape_check.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;verdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rank&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rank&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;NCHW rejected-by-df-frame&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rank&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DF frame [1, T, F] accepted&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rejected&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;224&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;224&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;96&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;96&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,)]:&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;verdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[1, 3, 224, 224] -&amp;gt; NCHW rejected-by-df-frame
[1, 1, 96] -&amp;gt; DF frame [1, T, F] accepted
[96] -&amp;gt; rejected
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Coi kết quả “accepted” ở đây là bằng chứng cho thấy đồ thị thực tế sẽ chạy trơn tru; đoạn mã chỉ kiểm tra bậc tensor và chiều batch bằng 1.&lt;/li&gt;
  &lt;li&gt;Khi chuyển sang &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ort.InferenceSession&lt;/code&gt;, lỗi &lt;strong&gt;lệch tên đầu vào của session (session input name mismatch)&lt;/strong&gt; rất hay xảy ra: shape đúng nhưng mã gọi tên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input&lt;/code&gt; trong khi đồ thị đặt là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feat_erb&lt;/code&gt; hoặc tên khác. Hãy luôn kiểm tra bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session.get_inputs()&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Trục thời gian bị cố định cứng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T = 100&lt;/code&gt; lúc xuất vẫn vượt qua bài kiểm tra bậc lỏng lẻo nhưng sẽ báo lỗi ngay khi nhận hop độ dài 1.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Phát hành các tệp ONNX khác nhau theo từng hệ điều hành mà không có bài kiểm thử nạp tự động.&lt;/li&gt;
  &lt;li&gt;Bật execution provider CUDA cho sản phẩm cần chạy trên laptop chỉ có CPU.&lt;/li&gt;
  &lt;li&gt;Mặc định rằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; chạy được mọi mô hình mà ORT chấp nhận.&lt;/li&gt;
  &lt;li&gt;Dùng chỉ số hệ số thời gian thực của ORT trên Python để ước lượng cho bản WASM.&lt;/li&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt; trước khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; biên dịch xong module, khiến lớp core ném ngoại lệ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Lập bảng mô tả các tensor cho một hop GRU minh họa: nêu rõ tên, bậc tensor và tensor nào đóng vai trò trạng thái.&lt;/li&gt;
  &lt;li&gt;Chọn một phiên bản ORT cụ thể, tra cứu danh sách opset được hỗ trợ trong &lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;tài liệu ONNX Runtime&lt;/a&gt; và xác định phiên bản opset phù hợp để xuất mô hình.&lt;/li&gt;
  &lt;li&gt;Viết khoảng 150 từ phân tích việc chọn ORT hay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; cho một tiện ích mở rộng (extension) trên Chrome, sau đó phân tích lại cho một công cụ dòng lệnh (CLI) khử nhiễu viết bằng Rust.&lt;/li&gt;
  &lt;li&gt;Thiết kế một bước kiểm thử CI tự động báo lỗi khi đầu ra ONNX và bản tham chiếu PyTorch lệch quá ngưỡng SI-SDR quy định trên một đoạn âm thanh chuẩn.&lt;/li&gt;
  &lt;li&gt;Giải thích vì sao không thể đưa tensor kích thước &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 3, 224, 224]&lt;/code&gt; vào mô hình xử lý khung âm thanh dù chiều batch bằng 1.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Bảng cần có &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frame&lt;/code&gt; dạng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 1, F]&lt;/code&gt;, cùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state_in&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state_out&lt;/code&gt; có chung kích thước chiều ẩn. Nếu đồ thị không chứa toán tử FFT, ghi rõ bước STFT nằm ngoài session.&lt;/li&gt;
  &lt;li&gt;Phiên bản opset lúc xuất phải nằm trong danh sách mà runtime phát hành hỗ trợ, không tự động lấy opset mới nhất của framework huấn luyện.&lt;/li&gt;
  &lt;li&gt;Với extension trình duyệt: chọn runtime WASM phù hợp với ma trận trình duyệt hỗ trợ. Với CLI viết bằng Rust: chọn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; nếu kiểm tra toán tử đạt yêu cầu để tránh phụ thuộc thêm thư viện native. Cả hai phương án đều bắt buộc có bước kiểm chứng toán tử.&lt;/li&gt;
  &lt;li&gt;Cố định sẵn tệp âm thanh chuẩn, độ dài hop và ngưỡng sai số trong job CI; cho job báo lỗi cả khi thiếu tensor trạng thái đầu ra chứ không chỉ khi lệch SI-SDR.&lt;/li&gt;
  &lt;li&gt;Tensor bậc 4 tương ứng định dạng ảnh NCHW, trong khi hợp đồng khung đặc trưng trong mini-lab yêu cầu tensor bậc 3.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;Tài liệu ONNX Runtime&lt;/a&gt;, bao gồm các phần về lượng tử hóa và triển khai Web dùng ở các bài kế tiếp.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/sonos/tract&quot;&gt;tract&lt;/a&gt;, thư viện suy luận viết bằng Rust được đề cập trong ghi chú phát hành bản 1.3.0.&lt;/li&gt;
  &lt;li&gt;Gói npm &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;&lt;/a&gt; và &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;kho mã nguồn&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Các thảo luận về xuất mô hình DeepFilterNet sang ONNX (luôn tự kiểm chứng tệp ONNX từ cộng đồng trước khi sử dụng).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video giải thích vai trò tệp trao đổi của ONNX và cách ONNX Runtime thực thi mô hình trên CPU, GPU và thiết bị biên — nền tảng trước khi so sánh với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Wp5PaRpudlk&quot;&gt;Introduction to ONNX Runtime&lt;/a&gt; — NVIDIA Developer, tiếng Anh. Tài liệu giới thiệu chính thức thứ hai về ONNX Runtime, giúp làm rõ cơ chế execution provider trước khi triển khai sang WASM.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>05-04 Trạng thái mô hình streaming</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter05/05_04_streaming_state/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter05/05_04_streaming_state</id>
   <content type="html">&lt;p&gt;Hãy thử bấm nút “Bật khử nhiễu” ngay giữa một câu nói trong cuộc gọi video: nếu kỹ sư quên xử lý mượt ranh giới trạng thái, bạn sẽ nghe ngay một tiếng &lt;em&gt;tách&lt;/em&gt; chói tai, theo sau là một chùm nhiễu rít dài đúng 10 mili giây trước khi giọng nói mới êm lại. Tại sao một mô hình chạy nhanh dư dả (RTF chỉ 0,04) vẫn phát ra tiếng tách đúng lúc người dùng bấm nút? Câu trả lời không nằm ở tốc độ CPU — mà nằm ở &lt;strong&gt;trí nhớ ẩn (streaming state)&lt;/strong&gt; mà mô hình mang theo từ hop này sang hop khác.&lt;/p&gt;

&lt;p&gt;Một bộ tăng cường giọng nói chạy theo luồng (streaming) là hàm của cả hop hiện tại lẫn toàn bộ trạng thái (state) được giữ lại từ hop trước đó: đuôi chồng lấp của STFT (short-time Fourier transform, biến đổi Fourier thời gian ngắn), véctơ trạng thái của GRU (gated recurrent unit, đơn vị hồi tiếp có cổng), lịch sử khung của bộ lọc sâu (deep filter) và các mẫu chưa đọc trong ring buffer. Nếu xóa trắng cụm trạng thái này giữa cuộc gọi, hop kế tiếp sẽ không còn khớp với phần đuôi trước đó, khiến người nghe nghe thấy tiếng tách (click) hoặc một chùm nhiễu kéo dài bằng một hop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Tiếng tách khi bấm nút dù RTF rất thấp → Kiến thức cần nhớ (Hàm có trạng thái trong DSP/RNN, Tái tạo liên tục OLA, Crossfade không gián đoạn) → Bảng kiểm kê 7 thành phần trạng thái ở 48 kHz → Chính sách xử lý 5 sự kiện (khởi động lạnh, bật/tắt, đổi thiết bị, underrun) → Giải thích tính tay bước nhảy gián đoạn khi xóa đuôi OLA và công thức crossfade 480 mẫu → Cuộc gọi dài, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/ring-buffer.png&quot; alt=&quot;Ring buffer mà các mẫu chưa đọc là state phải sống qua hop kế&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Cung chứa các mẫu chưa đọc trong ring buffer là một phần của trạng thái: nó phải nằm trên cùng vùng nhớ đó ở callback kế tiếp. Quy tắc tương tự áp dụng cho véctơ ẩn của GRU và cho 4 khung STFT quá khứ mà bộ lọc sâu 5 tap vẫn cần dùng. Xóa bất kỳ thành phần nào trong số này tại biên hop đều tạo ra một bước nhảy đột ngột, nghe thành tiếng tách hoặc một chùm nhiễu ngắn.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ liệt kê được đầy đủ các trạng thái mà một hop kiểu DeepFilterNet phải truyền ngược lại cho bước tiếp theo, tính được độ dài đuôi chồng lấp ở cấu hình cửa sổ 20 ms / hop 10 ms đã công bố, và áp dụng kỹ thuật chuyển mờ chéo (crossfade) khi tắt/bật tiếng (mute) thay vì xóa trắng phần đuôi đó.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-vì-sao-bộ-khử-nhiễu-streaming-là-một-máy-trạng-thái-stateful-machine&quot;&gt;Kiến thức cần nhớ: Vì sao bộ khử nhiễu streaming là một máy trạng thái (stateful machine)?&lt;/h2&gt;

&lt;h3 id=&quot;1-hệ-thống-có-nhớ-stateful-system-trong-dsp-và-mạng-hồi-tiếp&quot;&gt;1. Hệ thống có nhớ (Stateful System) trong DSP và Mạng hồi tiếp&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Một bộ khử nhiễu streaming không phải hàm thuần \(y_t = f(x_t)\), mà là một cặp ánh xạ \((y_t, s_t) = f(x_t, s_{t-1})\), trong đó \(s_{t-1}\) gói gọn toàn bộ lịch sử từ ring buffer, đuôi STFT, bộ lọc 5 tap, bộ chuẩn hóa mức tín hiệu đến vector ẩn GRU.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Giải thích vì sao mọi thao tác tạo mới session mỗi hop, dùng chung biến trạng thái giữa hai cuộc gọi, hay tua (seek) file mà không phân tách trạng thái đều lập tức phá vỡ chất lượng âm thanh.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-điều-kiện-tái-tạo-hoàn-hảo-của-cộng-chồng-lấp-overlap-add--cola&quot;&gt;2. Điều kiện tái tạo hoàn hảo của Cộng chồng lấp (Overlap-Add / COLA)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Khi phân tích và tổng hợp khung 20 ms (960 mẫu) với hop 10 ms (480 mẫu), mỗi mẫu âm thanh đầu ra là tổng của &lt;strong&gt;nửa sau khung trước&lt;/strong&gt; (đuôi OLA) và &lt;strong&gt;nửa đầu khung hiện tại&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Khi xóa trắng đuôi OLA về 0, tổng trọng số cửa sổ bị sụp đổ đột ngột tạo nên một bước nhảy gián đoạn (step discontinuity) — trong miền tần số, bước nhảy này chứa năng lượng trải rộng khắp dải tần, nghe chính xác là một tiếng &lt;em&gt;tách&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-chuyển-tiếp-mượt-bằng-crossfade-và-quản-trị-vòng-đời-trạng-thái&quot;&gt;3. Chuyển tiếp mượt bằng Crossfade và Quản trị vòng đời trạng thái&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Kỹ thuật pha trộn tuyến tính (hoặc cosin nâng) giữa luồng gốc (dry) và luồng đã xử lý (wet) trong 10–20 ms khi bật/tắt khử nhiễu, thay vì cắt chuyển đột ngột hoặc xóa trắng GRU.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Phân biệt rõ sự kiện nào &lt;strong&gt;cấm&lt;/strong&gt; xóa trạng thái (mute/unmute, underrun ngắn) và sự kiện nào &lt;strong&gt;bắt buộc&lt;/strong&gt; reset sạch (khởi động lạnh, đổi micro hoặc đổi tần số lấy mẫu).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Phân tích một tiếng tách lúc bật khử nhiễu và truy vết về lỗi xóa đuôi chồng lấp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Kiểm kê trạng thái: ring buffer, đuôi STFT, GRU, lịch sử 5 tap và cổng SNR.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Tắt tiếng (mute), đổi thiết bị và underrun: ba tình huống reset khác nhau.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Cuộc gọi kéo dài và hiện tượng trôi trạng thái (drift).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab và làm bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;những-thành-phần-trạng-thái-phải-được-duy-trì-sang-hop-kế-tiếp&quot;&gt;Những thành phần trạng thái phải được duy trì sang hop kế tiếp&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Trạng thái&lt;/th&gt;
      &lt;th&gt;Kích thước ở 48 kHz&lt;/th&gt;
      &lt;th&gt;Hệ quả nếu xóa giữa cuộc gọi&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Ring buffer đầu vào&lt;/td&gt;
      &lt;td&gt;0–479 mẫu đang chờ đủ hop 480 mẫu&lt;/td&gt;
      &lt;td&gt;Tạo khoảng trống âm thanh hoặc lặp lại một quantum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Đuôi cộng chồng (OLA)&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;480 mẫu = 10 ms&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tạo bước nhảy biên độ kéo dài 10 ms, nghe thành tiếng tách&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Trạng thái ẩn GRU&lt;/td&gt;
      &lt;td&gt;256 phần tử trong cấu hình DeepFilterNet2&lt;/td&gt;
      &lt;td&gt;Hệ số khuếch đại nhảy đột ngột về trạng thái khởi tạo, thường gây chùm nhiễu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lịch sử bộ lọc sâu&lt;/td&gt;
      &lt;td&gt;4 khung quá khứ trên 96 bin tần số thấp (demo 2023)&lt;/td&gt;
      &lt;td&gt;Các thành phần hài bị sụt giảm trong tối đa 4 hop (40 ms)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bộ chuẩn hóa mức tín hiệu&lt;/td&gt;
      &lt;td&gt;Trung bình trượt mũ, hằng số suy giảm 1 s (đặc trưng ICASSP)&lt;/td&gt;
      &lt;td&gt;Mức âm lượng bị nhảy bậc trong khoảng một giây&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Cổng SNR&lt;/td&gt;
      &lt;td&gt;Giá trị \(\xi\) đang cập nhật liên tục (bài 04-03)&lt;/td&gt;
      &lt;td&gt;Gây im lặng đột ngột nếu ép \(\xi&amp;lt;-10\) dB&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hệ số khuếch đại làm trơn&lt;/td&gt;
      &lt;td&gt;Một giá trị cho mỗi băng tần (\(\lambda=0{,}6\) trong RNNoise)&lt;/td&gt;
      &lt;td&gt;Tạo gai khuếch đại kéo dài một khung&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;ONNX Runtime chỉ duy trì cụm trạng thái này nếu đồ thị mô hình khai báo rõ các tensor trạng thái ở đầu vào/đầu ra và bạn sao chép đầu ra của hop này đưa ngược lại làm đầu vào cho hop kế tiếp. Một lời gọi không trạng thái (stateless) vẫn trả về tensor hợp lệ về mặt cú pháp, nhưng đó không phải là bộ khử nhiễu streaming đúng nghĩa. Việc khởi tạo lại session ở mỗi hop cũng phá vỡ hoàn toàn ngân sách RTF (real-time factor, hệ số thời gian thực; xem bài 05-01). Nguyên tắc bất di bất dịch là mỗi cuộc gọi sở hữu một véctơ trạng thái riêng: nếu hai tab dùng chung một vùng trạng thái, chúng sẽ ghi đè cập nhật của nhau và cả hai đều phát ra tiếng tách.&lt;/p&gt;

&lt;h3 id=&quot;hiện-tượng-nghe-được-khi-reset-trạng-thái&quot;&gt;Hiện tượng nghe được khi reset trạng thái&lt;/h3&gt;

&lt;p&gt;Với cửa sổ 960 mẫu và hop 480 mẫu, mỗi khung sau khi biến đổi ngược sẽ giữ lại &lt;strong&gt;480 mẫu (10 ms)&lt;/strong&gt; đuôi để cộng chồng vào khung kế tiếp. Nếu hop \(n\) kết thúc ở biên độ khoảng 0,3 mà bạn xóa trắng phần đuôi này, tín hiệu đầu ra sẽ nhảy bậc một lượng xấp xỉ 0,3. Bước nhảy gián đoạn đó chính là tiếng tách, vì phần chồng lấp cần thiết để tái tạo liên tục cửa sổ đã bị loại bỏ.&lt;/p&gt;

&lt;p&gt;Trong khi đó, xóa trạng thái GRU thường gây ra một chùm nhiễu ngắn. Khi bị ép về 0, các ước lượng SNR và hệ số khuếch đại ở một hoặc hai hop 10 ms đầu tiên sẽ phản ánh giá trị kích hoạt khởi tạo — thường là “không có giọng nói” hoặc “giữ nguyên biên độ (gain đầy)”. Giữ gain đầy trên các bin chứa nhiễu sẽ tạo thành một chùm nhiễu, còn cổng SNR ép \(\xi&amp;lt;-10\) dB (bài 04-03) sẽ tạo thành một khoảng lặng hụt hơi. Cả hai hiện tượng đều xảy ra ngay thời điểm người dùng vừa bấm nút.&lt;/p&gt;

&lt;p&gt;Do đó, xóa cứng bộ đệm là cách xử lý mute sai. Cách đúng là thực hiện chuyển mờ chéo (crossfade) từ tín hiệu đã xử lý (wet) sang tín hiệu gốc (dry) trong khoảng một hop (480 mẫu, tương ứng khoảng 3,75 quantum 128 mẫu). Nếu GRU vẫn được giữ ấm trong lúc bypass, chỉ cần áp dụng fade trên các mẫu trong ring buffer chứ không can thiệp vào trạng thái ẩn của mạng.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tự-tính-tay-cú-rơi-biên-độ-khi-xóa-đuôi-ola-và-đường-cong-crossfade&quot;&gt;Giải thích: Tự tính tay cú rơi biên độ khi xóa đuôi OLA và đường cong crossfade&lt;/h2&gt;

&lt;h3 id=&quot;phép-tính-1-chuyện-gì-xảy-ra-khi-xóa-đuôi-ola-trên-tín-hiệu-hằng-xn--10&quot;&gt;Phép tính 1: Chuyện gì xảy ra khi xóa đuôi OLA trên tín hiệu hằng \(x[n] = 1{,}0\)?&lt;/h3&gt;
&lt;p&gt;Xét cặp cửa sổ phân tích và tổng hợp hình sin (cùng bản chất Princen–Bradley với Vorbis) độ dài \(N = 960\), chồng lấp 50% (\(H = 480\)):
\(w(n) = \sin\left(\frac{\pi n}{960}\right), \qquad 0 \le n &amp;lt; 960.\)
Tại mọi vị trí \(0 \le n &amp;lt; 480\) trong hop hiện tại:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Đuôi khung trước đóng góp: \(w^2(n + 480) = \sin^2\left(\frac{\pi n}{960} + \frac{\pi}{2}\right) = \cos^2\left(\frac{\pi n}{960}\right)\).&lt;/li&gt;
  &lt;li&gt;Nửa đầu khung hiện tại đóng góp: \(w^2(n) = \sin^2\left(\frac{\pi n}{960}\right)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khi giữ nguyên đuôi OLA:&lt;/strong&gt; \(y[n] = \cos^2\left(\frac{\pi n}{960}\right) + \sin^2\left(\frac{\pi n}{960}\right) = \mathbf{1{,}0}\) phẳng tuyệt đối!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khi xóa trắng đuôi OLA về 0 tại \(n = 0\):&lt;/strong&gt; Phần \(\cos^2\) biến mất!
    &lt;ul&gt;
      &lt;li&gt;Tại \(n = 0\): \(y_{\text{reset}}[0] = \sin^2(0) = \mathbf{0{,}0}\) (biên độ rơi thẳng đứng từ \(1{,}0 \to 0{,}0\)!).&lt;/li&gt;
      &lt;li&gt;Tại \(n = 240\) (giữa hop, 5 ms sau): \(y_{\text{reset}}[240] = \sin^2(\pi/4) = \mathbf{0{,}5}\).&lt;/li&gt;
      &lt;li&gt;Phải đến tận cuối hop (\(n = 479\)), đầu ra mới bò lên lại gần \(1{,}0\). Cả một rãnh hình sin kéo dài đúng 10 ms kèm vách dựng đứng độ cao 1,0 — đó chính là tiếng &lt;em&gt;tách&lt;/em&gt; đinh tai!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phép-tính-2-kiểm-tra-công-thức-crossfade-tuyến-tính-480-mẫu-10-ms&quot;&gt;Phép tính 2: Kiểm tra công thức Crossfade tuyến tính 480 mẫu (10 ms)&lt;/h3&gt;
&lt;p&gt;Khi người dùng bật khử nhiễu tại mẫu \(n = 0\), thay vì chuyển đột ngột từ tín hiệu gốc \(y_{\text{dry}}[n]\) sang tín hiệu đã xử lý \(y_{\text{wet}}[n]\), ta trộn bằng hệ số \(\alpha_n = \frac{n}{479}\) với \(0 \le n \le 479\):
\(y[n] = (1 - \alpha_n)\,y_{\text{dry}}[n] + \alpha_n\,y_{\text{wet}}[n].\)
Giả sử tại ranh giới chuyển mạch, \(y_{\text{dry}} = 0{,}80\) và \(y_{\text{wet}} = 0{,}20\) (lệch nhau \(0{,}60\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu cắt cứng: nhảy bậc ngay lập tức \(0{,}80 \to 0{,}20\) trong \(1\) mẫu (\(20{,}8\,\mu\text{s}\)).&lt;/li&gt;
  &lt;li&gt;Với crossfade 480 mẫu:
    &lt;ul&gt;
      &lt;li&gt;\(n = 0\) (\(\alpha_0 = 0\)): \(y[0] = 0{,}8000\) (khớp liên tục với mẫu trước).&lt;/li&gt;
      &lt;li&gt;\(n = 1\) (\(\alpha_1 = 1/479\)): \(y[1] = 0{,}7987\) (chỉ thay đổi \(0{,}00125\) mỗi mẫu — nhỏ hơn &lt;strong&gt;480 lần&lt;/strong&gt; cú cắt cứng!).&lt;/li&gt;
      &lt;li&gt;\(n = 240\) (\(\alpha_{240} \approx 0{,}501\)): \(y[240] \approx 0{,}499\).&lt;/li&gt;
      &lt;li&gt;\(n = 479\) (\(\alpha_{479} = 1\)): \(y[479] = 0{,}2000\) (chuyển hoàn toàn sang tín hiệu đã khử nhiễu mà tai người không hề nghe thấy vết nối).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;chính-sách-xử-lý-theo-từng-sự-kiện&quot;&gt;Chính sách xử lý theo từng sự kiện&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khởi động lạnh (cold start).&lt;/strong&gt; Khởi tạo toàn bộ trạng thái bằng 0 trước hop âm thanh nghe được đầu tiên, đồng thời chạy trước vài hop im lặng trước khi cuộc gọi bắt đầu để bộ chuẩn hóa 1 giây ổn định dần khỏi điểm 0 tuyệt đối.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bật bộ khử nhiễu.&lt;/strong&gt; Không xóa đuôi chồng lấp đang chứa tín hiệu gốc; thực hiện crossfade từ tín hiệu gốc sang tín hiệu đã xử lý trong 10–20 ms, đồng thời giữ GRU ở trạng thái ấm trong suốt thời gian bypass.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tắt bộ khử nhiễu.&lt;/strong&gt; Thực hiện crossfade từ tín hiệu đã xử lý sang tín hiệu gốc và đóng băng trạng thái GRU; nếu xóa trắng GRU, lần bật lại kế tiếp sẽ phát sinh một chùm nhiễu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đổi thiết bị hoặc tần số lấy mẫu.&lt;/strong&gt; Thực hiện reset toàn bộ trạng thái và cập nhật lại độ dài hop. Một chuỗi quantum 44,1 kHz đưa vào bộ STFT thiết kế cho 48 kHz sẽ không thể khắc phục bằng crossfade.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Underrun.&lt;/strong&gt; Chuyển sang bypass (bài 05-03) cho tới khi ring buffer đầu ra tích lũy đủ một hop rồi mới fade quay lại. Xóa đuôi chồng lấp mà không fade sẽ tạo ra thêm một tiếng tách ngay tại thời điểm bạn đang cố che giấu một tiếng tách khác.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;cuộc-gọi-kéo-dài&quot;&gt;Cuộc gọi kéo dài&lt;/h3&gt;

&lt;p&gt;Một cuộc gọi dài 45 phút với hop 10 ms trải qua \(45\times 60\times 100=270\,000\) bước cập nhật GRU liên tiếp. Hiện tượng trôi trạng thái (drift) là sự dịch chuyển chậm của véctơ ẩn theo thời gian — khiến âm thanh bị đục dần hoặc có cảm giác bơm tiếng — khác hẳn với tiếng tách đột ngột dài một hop. Lưu ý rằng bài 04-05 chỉ liệt kê Fast-ULCNet trong danh sách tham khảo cho chủ đề luồng dài, chứ không trích dẫn bài báo nào tại đây. Một biện pháp thực tế là kéo dần trạng thái về 0 trong vài trăm mili giây khi phát hiện khoảng lặng (kéo tức thì sẽ tương đương một lần reset), đồng thời so sánh bản ghi của cùng một đoạn âm thanh hiệu chuẩn ở phút thứ 1 và phút thứ 40 để kiểm tra độ ổn định.&lt;/p&gt;

&lt;h3 id=&quot;vòng-lặp-phản-hồi-trạng-thái&quot;&gt;Vòng lặp phản hồi trạng thái&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;state = initial   # zeros only before audio starts
for hop in stream:
    y, state = model(hop, state)
    emit y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Cần kiểm tra kích thước (shape) của từng tensor ngay lúc khởi tạo: đầu vào/đầu ra GRU (256 trong cấu hình DF2), 4 khung phức quá khứ dưới ngưỡng tần số của bộ lọc sâu, và đuôi chồng lấp 480 số thực. Nếu gán lệch thứ tự binding, mô hình sẽ đọc nhầm sang tensor kế tiếp và phát ra âm thanh méo như thể trọng số bị hỏng.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Tạo session suy luận mới ở mỗi hop, vừa làm mất toàn bộ trạng thái vừa phá hỏng RTF.&lt;/li&gt;
  &lt;li&gt;Dùng chung một đối tượng trạng thái cho hai tab trình duyệt khác nhau.&lt;/li&gt;
  &lt;li&gt;Tua (seek) trong tệp âm thanh offline mà không reset trạng thái, khiến tệp thứ hai thừa kế trạng thái GRU từ tệp thứ nhất.&lt;/li&gt;
  &lt;li&gt;Mặc định rằng khi tải lại AudioWorklet thì trạng thái bên trong WASM vẫn còn; thực tế mỗi module nạp mới đều là một lần khởi động lạnh.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Định lượng tác động của việc xóa trạng thái bằng một con số cụ thể. Xây dựng phép cộng chồng lấp (overlap-add) cho hai hop với đuôi chồng lấp dài 4 mẫu (mô hình thu gọn thay cho 480 mẫu), xuất kết quả bình thường, sau đó xóa trắng phần đuôi về 0 và so sánh sự chênh lệch.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
import numpy as np

def ola(prev_tail, frame):
    # frame layout: [overlap_with_previous | new_tail]
    mixed = prev_tail + frame[: len(prev_tail)]
    new_tail = frame[len(prev_tail) :].copy()
    return mixed, new_tail

frame0 = np.array([0.2, 0.2, 0.4, 0.4])  # tail that hop 1 will need
frame1 = np.array([0.4, 0.4, 0.1, 0.1])
mixed, tail = ola(frame0[2:], frame1)
print(&quot;continuous&quot;, mixed.tolist(), &quot;tail&quot;, tail.tolist())
mixed_reset, tail_reset = ola(np.zeros(2), frame1)
print(&quot;after_zero_tail&quot;, mixed_reset.tolist())
print(&quot;step&quot;, float(mixed[0] - mixed_reset[0]))
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;continuous [0.8, 0.8] tail [0.1, 0.1]&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;after_zero_tail [0.4, 0.4]&lt;/code&gt;, và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;step 0.4&lt;/code&gt;. Ở đường xử lý liên tục, đuôi của khung trước (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0.4, 0.4]&lt;/code&gt;) được cộng vào phần chồng lấp của khung kế tiếp. Khi xóa đuôi về 0, phần đóng góp đó biến mất và đầu ra bị hụt một bậc bằng 0,4. Khi phóng đại lên hop thực tế 480 mẫu, bước nhảy gián đoạn đó sẽ nghe rõ thành một tiếng tách. Reset trạng thái GRU cũng có bản chất tương tự với một véctơ phức tạp hơn: hop đầu tiên sau khi xóa về 0 rơi vào trạng thái quá độ chưa từng gặp lúc huấn luyện, phát ra tiếng tách hoặc một chùm nhiễu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Xóa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tail&lt;/code&gt; “cho chắc ăn” ở mỗi hop rồi tạo ra tiếng tách đều đặn sau từng hop; reset trạng thái khi mute mà không crossfade; dùng chung một biến &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tail&lt;/code&gt; cho hai luồng âm thanh khiến chúng cộng chồng lấp sang nhau; hoặc chẩn đoán nhầm bước nhảy 0,4 là lỗi RTF trong khi CPU vẫn xử lý đúng hạn còn nguyên nhân nằm ở quản lý trạng thái.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm kê trạng thái.&lt;/strong&gt; Với một hop kiểu DF3, hãy liệt kê 5 thành phần trạng thái quan trọng cùng đối tượng nắm giữ chúng (thuộc tính worklet, đầu vào ONNX hay ring buffer).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ dài vùng bị ảnh hưởng.&lt;/strong&gt; Với cửa sổ 960 mẫu, hop 480 mẫu ở tần số 48 kHz, một lần reset cứng sẽ xóa mất bao nhiêu mili giây của phần đuôi chồng lấp?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chính sách vận hành.&lt;/strong&gt; Hãy viết ngắn gọn (mỗi tình huống một câu) cách xử lý khi mute, unmute và đổi micro. Trường hợp nào trong ba trường hợp này được phép xóa trạng thái GRU?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân biệt trôi trạng thái và reset.&lt;/strong&gt; Một người dùng phản ánh nghe tiếng tách đúng lúc bật khử nhiễu, trong khi người khác báo âm thanh bị đục dần sau 40 phút gọi. Lỗi nào do reset trạng thái, lỗi nào do trôi trạng thái?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Năm thành phần gồm: các mẫu đang nằm trong ring buffer đầu vào, đuôi OLA 480 số thực, trạng thái ẩn GRU (256 phần tử trong cấu hình DF2; cần xác nhận lại trên I/O của file ONNX thực tế), 4 khung lịch sử của bộ lọc sâu, và trung bình trượt của đặc trưng ERB. Worklet quản lý các ring buffer; giao diện I/O của đồ thị quản lý trạng thái GRU nếu nó được tách thành tensor đầu vào.&lt;/li&gt;
  &lt;li&gt;\(480/48000=10\) ms âm thanh. Đây là thời lượng của đoạn gián đoạn gây tiếng tách, không liên quan đến RTF.&lt;/li&gt;
  &lt;li&gt;Khi mute và unmute: áp dụng crossfade trong 10–20 ms và giữ/đóng băng trạng thái GRU. Khi đổi micro hoặc tần số lấy mẫu: reset sạch trạng thái khi chưa phát âm thanh, làm nóng mô hình trên vài hop im lặng rồi mới mở luồng. Chỉ trường hợp thứ ba mới được phép xóa GRU.&lt;/li&gt;
  &lt;li&gt;Tiếng tách xuất hiện đúng lúc bật tính năng là lỗi reset trạng thái. Âm thanh bị đục dần sau 40 phút (tương đương \(240\,000\) hop) là hiện tượng trôi trạng thái hoặc suy giảm RTF do quá nhiệt; việc xóa trạng thái giữa câu nói không giải quyết được lỗi trôi.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bài 04-02 và 04-03 về lịch sử 5 tap, GRU độ rộng 256 trong DeepFilterNet2 và cổng SNR trong &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Bài 05-03 về ring buffer giữ phần đuôi giữa các quantum 128 mẫu.&lt;/li&gt;
  &lt;li&gt;Tài liệu I/O binding của ONNX Runtime về cách truyền ngược tensor trạng thái mà không cần khởi tạo lại session.&lt;/li&gt;
  &lt;li&gt;MDN, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;AudioWorklet&lt;/a&gt;, về vòng đời processor: nạp mới worklet đồng nghĩa tạo trạng thái mới và hop đầu tiên là khởi động lạnh.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Gated Recurrent Unit&lt;/td&gt;
          &lt;td&gt;GRU&lt;/td&gt;
          &lt;td&gt;Explained in detail](https://www.youtube.com/watch?v=IBs8D8PWMc8) — Learn With Jay, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video giải thích cách cổng cập nhật duy trì trạng thái qua từng bước thời gian — đúng với vai trò véctơ GRU giữa các hop trong bộ khử nhiễu streaming.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Bộ mã hóa GRU chính là trạng thái hồi tiếp không được phép xóa giữa cuộc gọi.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nsscrYdrGRE&quot;&gt;RNNoise, Neural Speech Enhancement, and the Browser&lt;/a&gt; — W3C, tiếng Anh. Mô hình GRU gọn nhẹ xuất hệ số khuếch đại theo từng khung là ví dụ trực quan ở quy mô giảng dạy cho khái niệm trạng thái streaming.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>05-03 Ring buffer và underrun</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter05/05_03_ring_buffers_underruns/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter05/05_03_ring_buffers_underruns</id>
   <content type="html">&lt;p&gt;Hãy hình dung hai dây chuyền lắp ráp nối tiếp nhau trong một nhà máy: dây chuyền thứ nhất cứ mỗi 2,67 mili giây lại đẩy ra một khay 128 linh kiện, còn dây chuyền thứ hai chỉ chịu khởi động khi gom đủ đúng 480 linh kiện. Nếu bạn đặt giữa chúng một chiếc bàn quá nhỏ, linh kiện sẽ tràn rơi xuống đất; nếu đặt một nhà kho khổng lồ, sản phẩm sẽ bị tồn kho nằm chờ hàng trăm mili giây trước khi tới tay khách hàng. Trong lập trình âm thanh thời gian thực, chiếc bàn xoay nối hai nhịp đồng hồ lệch pha ấy chính là &lt;strong&gt;bộ đệm vòng (ring buffer)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Một hop của DeepFilterNet dài 480 mẫu, trong khi một render quantum của AudioWorklet (luồng render của Web Audio) thường chỉ dài 128 mẫu. Hai nhịp đồng hồ khác nhau này được nối với nhau bằng một &lt;strong&gt;bộ đệm vòng (ring buffer)&lt;/strong&gt;: một mảng có kích thước cố định đi kèm chỉ số đọc và chỉ số ghi. Khi bên đọc tiêu thụ nhanh hơn khiến bộ đệm cạn dữ liệu, ta gặp lỗi &lt;strong&gt;underrun&lt;/strong&gt; (gây tiếng tách hoặc khoảng mất tiếng). Ngược lại, khi bên ghi đẩy dữ liệu vào nhanh hơn và vượt quá chỗ trống, ta gặp lỗi &lt;strong&gt;overrun&lt;/strong&gt; (khiến độ trễ phình dần cho đến khi buộc phải bỏ bớt mẫu hoặc chuyển sang bypass). Bài học này hướng dẫn cách tính dung lượng ring buffer và cài đặt cả hai chính sách xử lý trên mô hình minh họa 8 mẫu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Bài toán nối hai nhịp đồng hồ lệch pha → Kiến thức cần nhớ (Hàng đợi vòng SPSC không khóa, Dung lượng lũy thừa của hai &amp;amp; ngân sách độ trễ, Chính sách phi chặn cho Underrun/Overrun) → Cơ chế mặt nạ bit &amp;amp; sơ đồ hai tầng Ring A / Ring B → Giải thích dò tay phép quay vòng mặt nạ bit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index &amp;amp; 7&lt;/code&gt; và tính độ trễ tích lũy → Bảng chính sách, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/ring-buffer.png&quot; alt=&quot;Bộ đệm vòng với chỉ số ghi đi trước chỉ số đọc&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Một mảng bộ nhớ có kích thước cố định. Bên ghi tăng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;write_pos&lt;/code&gt; mỗi khi một quantum mới đến; bên đọc tăng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read_pos&lt;/code&gt; mỗi khi đủ một hop để xử lý. Mức chiếm chỗ (occupancy) là khoảng cách giữa hai chỉ số này. Vùng tô xám chính là trạng thái duy nhất phải được giữ nguyên sang callback kế tiếp, và dung lượng mảng không bao giờ tự mở rộng.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ tính được mức chiếm chỗ (occupancy) và số chỗ trống sau khi ghi 6 mẫu rồi đọc 4 mẫu; cài đặt được chính sách xử lý overrun bằng cách bỏ mẫu cũ nhất thay vì cấp phát thêm bộ nhớ; và chọn được dung lượng lũy thừa của hai phù hợp cho hop 480 mẫu, quantum 128 mẫu cùng một khoảng dự phòng jitter nhỏ mà không vô tình cộng thêm 100 ms độ trễ vào bộ đệm.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-thiết-kế-bộ-đệm-vòng-thời-gian-thực&quot;&gt;Kiến thức cần nhớ: Ba trụ cột thiết kế bộ đệm vòng thời gian thực&lt;/h2&gt;

&lt;h3 id=&quot;1-hàng-đợi-vòng-một-bên-ghi--một-bên-đọc-spsc-lock-free-ring-buffer&quot;&gt;1. Hàng đợi vòng một bên ghi – một bên đọc (SPSC Lock-Free Ring Buffer)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Một mảng tĩnh kích thước cố định \(C = 2^m\) với hai con trỏ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;write_pos&lt;/code&gt; (chỉ do producer cập nhật) và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read_pos&lt;/code&gt; (chỉ do consumer cập nhật).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Cho phép truyền dữ liệu liên tục giữa hai nhịp xử lý (hoặc hai luồng trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt;) với &lt;strong&gt;0 lần cấp phát bộ nhớ&lt;/strong&gt; và &lt;strong&gt;0 khóa mutex&lt;/strong&gt;, tránh tuyệt đối hiện tượng đảo ưu tiên (priority inversion).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-sự-đánh-đổi-kinh-điển-chống-jitter-vs-độ-trễ-hội-thoại&quot;&gt;2. Sự đánh đổi kinh điển: Chống Jitter vs. Độ trễ hội thoại&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Công thức chọn dung lượng \(C \gtrsim H + J\cdot H + Q\) cân bằng giữa khả năng hấp thụ dao động lịch trình (jitter \(J\) hop) và thời gian tồn lưu tối đa \(C / f_s\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Tránh sai lầm “càng to càng an toàn”: mỗi lần nhân đôi \(C\) từ 2048 lên 4096 mẫu ở 48 kHz có thể đẩy thêm hơn 40 ms độ trễ tiềm ẩn nếu hàng đợi bị đầy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-chính-sách-xử-lý-sự-cố-phi-chặn-non-blocking-overrun--underrun-policies&quot;&gt;3. Chính sách xử lý sự cố phi chặn (Non-Blocking Overrun &amp;amp; Underrun Policies)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Quy tắc ứng xử tất định khi hàng đợi đầy (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;overrun&lt;/code&gt;) hoặc rỗng (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;underrun&lt;/code&gt;): bỏ mẫu cũ nhất ở đầu vào (giữ cận trên độ trễ) và chuyển bypass hoặc fade mượt ở đầu ra (tránh tiếng nổ).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Đảm bảo luồng âm thanh tự phục hồi trong vài mili giây thay vì treo cứng hoặc tích lũy độ trễ vĩnh viễn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Tiếng tách, mất tiếng (dropout) và độ trễ phình dần nghe như thế nào trong thực tế.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Chỉ số đọc/ghi, mặt nạ bit, mức chiếm chỗ và ví dụ minh họa ghi 6 rồi đọc 4.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Hai ring buffer bao quanh một hop 10 ms và phép tính dung lượng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Chọn bỏ mẫu hay chuyển sang bypass khi bên ghi chạy trước.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab và làm bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;cơ-chế-hoạt-động&quot;&gt;Cơ chế hoạt động&lt;/h3&gt;

&lt;p&gt;Dữ liệu PCM được lưu trong một mảng có độ dài \(C\), trong đó nên chọn \(C=2^m\) để thao tác quay vòng chỉ số chỉ cần phép toán bit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index &amp;amp; (C-1)&lt;/code&gt; mà không phải dùng phép chia trên luồng âm thanh. Với mô hình một bên ghi và một bên đọc (SPSC — single-producer single-consumer), ta chỉ cần duy trì hai chỉ số. Số mẫu sẵn có (occupancy) và số chỗ trống được xác định như sau:&lt;/p&gt;

\[\mathrm{available}=(\mathrm{write\_pos}-\mathrm{read\_pos})\bmod C,\qquad \mathrm{free}=C-\mathrm{available}.\]

&lt;p&gt;Nếu duy trì thêm một biến đếm số phần tử như trong bài lab, bạn không cần tính phép chia dư cho mọi phép kiểm tra, nhưng vẫn phải quay vòng chỉ số khi ghi hoặc đọc. Bên ghi chỉ được phép ghi \(n\) mẫu khi \(\mathrm{free}\ge n\), và bên đọc chỉ được phép đọc \(n\) mẫu khi \(\mathrm{available}\ge n\). Vi phạm điều kiện này sẽ gây lỗi ngay lập tức: ghi vượt quá chỗ trống sẽ ghi đè lên các mẫu chưa kịp phát, còn đọc vượt quá số mẫu hiện có sẽ phát lặp lại dữ liệu PCM cũ hoặc toàn số 0.&lt;/p&gt;

&lt;p&gt;Phần cung tô xám trong hình minh họa chính là mức chiếm chỗ — một dạng trạng thái streaming. Nếu xóa trắng mảng mỗi lần bật hoặc tắt bộ khử nhiễu, phần dữ liệu này bị vứt bỏ và người nghe sẽ nghe thấy một khoảng khựng (xem bài 05-04).&lt;/p&gt;

&lt;h3 id=&quot;vị-trí-của-các-ring-buffer-trong-chuỗi-xử-lý&quot;&gt;Vị trí của các ring buffer trong chuỗi xử lý&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;quantum mic (128) → ring A → gom 480 → hop NS → ring B → quantum ra (128)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ring A có nhiệm vụ quy đổi nhịp “3,75 quantum cho mỗi hop” thành từng hop nguyên vẹn. Vì \(480/128=3{,}75\), sau 3 callback đầu tiên ring A chứa 384 mẫu nên hop chưa thể chạy; đến callback thứ 4, ring A đạt 512 mẫu, hop lấy đi 480 mẫu và để lại 32 mẫu. Ở đầu ra, ring B nhận khối 480 mẫu sau bước overlap-add rồi nhả dần ra từng quantum 128 mẫu. Không nên dùng chung một ring buffer duy nhất cho cả hai nhịp đồng hồ nếu không kiểm soát chặt quyền ghi, bởi micro và mô hình xử lý sẽ trở thành hai bên ghi cùng tranh chấp một bộ đệm. Cách thiết kế an toàn là cấp riêng một ring buffer cho mỗi chiều.&lt;/p&gt;

&lt;h3 id=&quot;tính-toán-dung-lượng&quot;&gt;Tính toán dung lượng&lt;/h3&gt;

&lt;p&gt;Gọi độ dài hop là \(H\) mẫu, độ dài quantum là \(Q\) mẫu, và \(J\) là số hop dự phòng cho dao động thời gian (jitter) mà hệ thống cần hấp thụ:&lt;/p&gt;

\[C \gtrsim H + J\cdot H + Q.\]

&lt;p&gt;Với \(H=480\), \(Q=128\) và \(J=2\), ta có \(480+960+128=1568\) mẫu; lũy thừa của hai lớn hơn kế tiếp là &lt;strong&gt;2048&lt;/strong&gt; mẫu, tương ứng \(2048/48000\approx 42{,}7\) ms ở riêng tầng đệm này. Nếu tăng \(J=3\), tổng rơi đúng vào 2048 mẫu nên lũy thừa của hai kế tiếp có khoảng dư an toàn là &lt;strong&gt;4096&lt;/strong&gt; mẫu (khoảng 85 ms). Khi cộng dồn hai tầng ring buffer cùng 40 ms look-ahead của mô hình, độ trễ hội thoại đã trở nên rất đáng kể. Mỗi lần nhân đôi dung lượng bộ đệm không cần thiết đều tạo thêm độ trễ mà người dùng sẽ quy lỗi cho bộ khử nhiễu.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-dò-tay-phép-quay-vòng-mặt-nạ-bit-và-ngân-sách-độ-trễ-hai-tầng&quot;&gt;Giải thích: Dò tay phép quay vòng mặt nạ bit và ngân sách độ trễ hai tầng&lt;/h2&gt;

&lt;h3 id=&quot;phép-tính-1-kiểm-tra-mặt-nạ-bit-index--c---1-qua-điểm-quay-vòng-wrap-around&quot;&gt;Phép tính 1: Kiểm tra mặt nạ bit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index &amp;amp; (C - 1)&lt;/code&gt; qua điểm quay vòng (wrap-around)&lt;/h3&gt;
&lt;p&gt;Chọn \(C = 8 = 2^3\) nên mặt nạ bit là \(C - 1 = 7 = \text{0b111}\). Bắt đầu với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w = 0, r = 0&lt;/code&gt;:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Ghi 6 mẫu (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1..6&lt;/code&gt;):&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w = (0 + 6) &amp;amp; 7 = 6&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r = 0&lt;/code&gt;. Số mẫu sẵn có: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(6 - 0) &amp;amp; 7 = 6&lt;/code&gt;, chỗ trống: \(8 - 6 = 2\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đọc 4 mẫu (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1..4&lt;/code&gt;):&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r = (0 + 4) &amp;amp; 7 = 4&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w = 6&lt;/code&gt;. Còn lại 2 mẫu ở chỉ số 4 (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5&lt;/code&gt;) và 5 (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6&lt;/code&gt;); chỗ trống: \(8 - 2 = 6\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ghi thêm 5 mẫu (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10..14&lt;/code&gt;):&lt;/strong&gt; Lúc này chỉ số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt; &lt;strong&gt;quay vòng&lt;/strong&gt; qua 7 về đầu mảng!
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w = (6 + 5) &amp;amp; 7 = 11 &amp;amp; 7 = 3&lt;/code&gt; (hai mẫu đầu ghi vào ô 6, 7; ba mẫu sau vòng về ô 0, 1, 2).&lt;/li&gt;
      &lt;li&gt;Bây giờ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w = 3 &amp;lt; r = 4&lt;/code&gt;! Thử kiểm tra công thức mặt nạ bit trên số bù hai:
\((w - r) \mathbin{\&amp;amp;} 7 = (3 - 4) \mathbin{\&amp;amp;} 7 = (-1) \mathbin{\&amp;amp;} \text{0b111} = \mathbf{7}.\)
Đúng phóc \(2 + 5 = 7\) mẫu đang nằm trong bộ đệm, không cần một câu lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt; hay phép chia &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%&lt;/code&gt; nào! (Lưu ý duy nhất: nếu ghi đủ 8 mẫu khiến &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w == r&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(w - r) &amp;amp; 7 == 0&lt;/code&gt; sẽ trùng trạng thái rỗng — đó là lý do ta giữ thêm biến đếm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n&lt;/code&gt; hoặc dùng chỉ số tăng đơn điệu không cắt trước rồi mới mặt nạ lúc truy cập &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;buf[w &amp;amp; 7]&lt;/code&gt;).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;phép-tính-2-cộng-tổng-độ-trễ-ở-trạng-thái-ổn-định-vs-lúc-bộ-đệm-đầy&quot;&gt;Phép tính 2: Cộng tổng độ trễ ở trạng thái ổn định vs. lúc bộ đệm đầy&lt;/h3&gt;
&lt;p&gt;Xét pipeline &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;128 → Ring A (2048) → Hop DF2 (480, look-ahead 40 ms) → Ring B (2048) → 128&lt;/code&gt; ở \(f_s = 48\,000\text{ Hz}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ở trạng thái bình thường (không nghẽn):&lt;/strong&gt; Ring A chỉ tích tối đa 1 hop trước khi xả (\(480\) mẫu = \(10\text{ ms}\)), cộng thêm độ lệch pha tối đa 1 quantum (\(128\) mẫu = \(2{,}67\text{ ms}\)), cộng \(40\text{ ms}\) look-ahead thuật toán \(\implies\) tổng độ trễ khoảng &lt;strong&gt;\(52{,}7\text{ ms}\)&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nếu lỗi lập lịch làm cả Ring A lẫn Ring B bị đầy 90% mà không có chính sách drop-oldest:&lt;/strong&gt; Riêng hai tầng đệm đã giam tới \(0{,}9 \times (2048 + 2048) = 3686\) mẫu \(\approx \mathbf{76{,}8\text{ ms}}\), đẩy tổng độ trễ lên gần &lt;strong&gt;117 ms&lt;/strong&gt; (chưa tính mạng WebRTC)!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;underrun-overrun-và-hai-chính-sách-xử-lý&quot;&gt;Underrun, overrun và hai chính sách xử lý&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Sự kiện&lt;/th&gt;
      &lt;th&gt;Điều kiện xảy ra&lt;/th&gt;
      &lt;th&gt;Cách xử lý chuẩn&lt;/th&gt;
      &lt;th&gt;Hệ quả nếu xử lý tùy tiện&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Underrun đầu ra&lt;/td&gt;
      &lt;td&gt;Ring B có ít hơn \(Q\) mẫu&lt;/td&gt;
      &lt;td&gt;Sao chép quantum tín hiệu gốc (bypass) hoặc fade ngắn về 0&lt;/td&gt;
      &lt;td&gt;Gây tiếng tách hoặc một khoảng lặng đột ngột&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Overrun đầu vào&lt;/td&gt;
      &lt;td&gt;Ring A có &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free &amp;lt; n&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Bỏ các mẫu chưa đọc cũ nhất rồi ghi mẫu mới&lt;/td&gt;
      &lt;td&gt;Âm thanh nhảy cóc nhẹ, nhưng độ trễ được giữ trong giới hạn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mô hình trễ hạn&lt;/td&gt;
      &lt;td&gt;Thời gian xử lý hop \(&amp;gt; 10\) ms (RTF p95 \(&amp;gt; 1\))&lt;/td&gt;
      &lt;td&gt;Giữ nguyên các mẫu đầu ra đã xếp hàng; bypass quantum mới đến khi hop đuổi kịp&lt;/td&gt;
      &lt;td&gt;Gây tiếng nứt liên tục nếu chặn luồng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Việc chặn luồng âm thanh để “chờ suy luận chạy xong” sẽ biến lỗi overrun thành hiện tượng đảo ưu tiên (priority inversion): quantum 2,67 ms chắc chắn sẽ trễ hạn trong lúc bạn giữ khóa. Cả hai chiến lược bypass và bỏ mẫu đều không chặn luồng. Bypass giữ đúng nhịp thời gian nhưng để lọt nhiễu nền; bỏ mẫu duy trì hoạt động của bộ khử nhiễu nhưng đánh đổi bằng việc mất một đoạn ngắn âm thanh. Nguyên tắc thực tế là bỏ mẫu cũ trên ring thu (vì mẫu micro cũ đằng nào cũng sẽ bị phát muộn) và dùng bypass trên ring phát (loa không thể đột ngột nhận toàn số 0 mà không fade, nhưng cũng không thể dừng lại chờ).&lt;/p&gt;

&lt;h3 id=&quot;các-chỉ-số-cần-ghi-log&quot;&gt;Các chỉ số cần ghi log&lt;/h3&gt;

&lt;p&gt;Cần theo dõi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;underrun_count&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;overrun_count&lt;/code&gt;, mức chiếm chỗ cực đại (high-water mark) và mức chiếm chỗ cực tiểu (low-water mark), đồng thời đối chiếu số lần overrun với chỉ số RTF p95 ở bài 05-01. Nếu một ring buffer thường xuyên đầy tới 95%, đó là phần độ trễ thừa hoàn toàn có thể cắt giảm; ngược lại, mỗi lần ring buffer chạm mức 0 tương ứng với một tiếng tách đã phát tới tai người dùng.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Để hai bên ghi cùng truy cập một ring buffer mà không có cơ chế đồng bộ tách biệt.&lt;/li&gt;
  &lt;li&gt;Ghi dữ liệu stereo xen kẽ (interleaved) vào ring buffer dạng tách kênh (planar) hoặc ngược lại; bố cục kênh là một phần bắt buộc của phép tính dung lượng (dùng hai ring riêng hoặc mảng có kích thước \(2C\)).&lt;/li&gt;
  &lt;li&gt;Tăng dung lượng \(C\) quá lớn cho đến khi cuộc gọi có độ trễ như liên lạc qua vệ tinh (chỉ riêng 4096 mẫu đã chiếm 85 ms).&lt;/li&gt;
  &lt;li&gt;Xóa trắng ring buffer mỗi khi người dùng tắt hoặc bật micro (mute/unmute); thay vào đó hãy tháo dần bộ đệm hoặc dùng crossfade (bài 05-04).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Trên một ring buffer dung lượng 8 mẫu, thực hiện ghi 6 mẫu, đọc 4 mẫu, in mức chiếm chỗ hiện tại, sau đó ghi thêm 7 mẫu theo chính sách xử lý overrun bỏ mẫu cũ nhất và quan sát các mẫu còn lại trong bộ đệm.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
import numpy as np

class Ring:
    def __init__(self, cap):
        self.buf = np.zeros(cap, dtype=np.float64)
        self.cap = cap
        self.w = 0
        self.r = 0
        self.n = 0
    def free(self):
        return self.cap - self.n
    def write(self, samples):
        if len(samples) &amp;gt; self.free():
            raise RuntimeError(&quot;overrun&quot;)
        for v in samples:
            self.buf[self.w] = v
            self.w = (self.w + 1) % self.cap
            self.n += 1
    def read(self, k):
        if k &amp;gt; self.n:
            raise RuntimeError(&quot;underrun&quot;)
        out = np.empty(k, dtype=np.float64)
        for i in range(k):
            out[i] = self.buf[self.r]
            self.r = (self.r + 1) % self.cap
            self.n -= 1
        return out
    def write_drop_oldest(self, samples):
        dropped = 0
        for v in samples:
            if self.free() == 0:
                self.r = (self.r + 1) % self.cap
                self.n -= 1
                dropped += 1
            self.buf[self.w] = v
            self.w = (self.w + 1) % self.cap
            self.n += 1
        return dropped

rb = Ring(8)
rb.write([1, 2, 3, 4, 5, 6])
print(&quot;after_write6&quot;, rb.n, rb.free())
got = rb.read(4)
print(&quot;read4&quot;, got.tolist(), &quot;occ&quot;, rb.n)
dropped = rb.write_drop_oldest([10, 11, 12, 13, 14, 15, 16])
print(&quot;dropped&quot;, dropped, &quot;occ&quot;, rb.n)
print(&quot;next4&quot;, rb.read(4).tolist())
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;after_write6 6 2&lt;/code&gt;, tiếp theo là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read4 [1.0, 2.0, 3.0, 4.0] occ 2&lt;/code&gt;, sau đó &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dropped 1 occ 8&lt;/code&gt;, và cuối cùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;next4 [6.0, 10.0, 11.0, 12.0]&lt;/code&gt;. Sau bước đọc 4 mẫu, ring buffer còn lại hai mẫu 5 và 6 (tức còn 6 chỗ trống). Khi ghi 7 mẫu mới, bộ đệm thiếu đúng 1 ô nên mẫu chưa đọc cũ nhất (5) bị loại bỏ; mẫu 6 được giữ lại, nối tiếp bởi 10, 11 và 12.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Tự động nới rộng dung lượng mảng thay vì bỏ mẫu cũ (làm độ trễ tăng ngầm mà không để lại dấu vết trong log); chặn luồng khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free &amp;lt; n&lt;/code&gt;; áp dụng chính sách bypass nhưng vẫn kỳ vọng số mẫu bị bỏ như trên (chính sách bypass sẽ từ chối lần ghi đó và giữ nguyên mức chiếm chỗ bằng 2); hoặc quên quay vòng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt; theo phép chia dư cho 8 khiến mẫu 16 vượt ra ngoài biên mảng.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Theo dõi trạng thái.&lt;/strong&gt; Sau khi ghi 6 mẫu và đọc 4 mẫu trên một ring buffer dung lượng 8 mới khởi tạo, mức chiếm chỗ bằng bao nhiêu và những mẫu nào còn nằm trong bộ đệm?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn lũy thừa của hai.&lt;/strong&gt; Với \(H=480\), \(Q=128\) và \(J=3\), hãy tính \(H+JH+Q\) và lũy thừa của hai kế tiếp. Dung lượng đó tương ứng bao nhiêu mili giây ở tần số 48 kHz?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lựa chọn chính sách.&lt;/strong&gt; Ring buffer đầu vào chỉ còn 100 chỗ trống trong khi callback đưa tới 128 mẫu. Bạn chọn bỏ 28 mẫu cũ nhất hay bypass mô hình? Mỗi phương án tác động thế nào đến độ trễ?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tách riêng hai ring buffer.&lt;/strong&gt; Vì sao mô hình không được ghi 480 mẫu đầu ra ngược trở lại vào ring A?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Mức chiếm chỗ bằng 2; hai mẫu còn lại là 5 và 6 (các mẫu từ 1 đến 4 đã được đọc ra).&lt;/li&gt;
  &lt;li&gt;\(480+3\times 480+128=2048\) vừa khít, nên chọn dung lượng 2048 sẽ không còn mẫu dự phòng nào. Cần chọn 4096 nếu muốn có bất đẳng thức nghiêm ngặt; mức này tương ứng \(4096/48000\approx 85{,}3\) ms cho riêng một tầng đệm.&lt;/li&gt;
  &lt;li&gt;Nếu bỏ 28 mẫu cũ nhất trên ring thu: độ trễ được giới hạn cố định và âm thanh bị nhảy qua 28 mẫu (\(28/48000\approx 0{,}58\) ms). Nếu chọn bypass: mô hình không xử lý quantum này, độ trễ không tăng nhưng nhiễu nền đi thẳng qua đầu ra. Chặn luồng chờ không phải là lựa chọn hợp lệ.&lt;/li&gt;
  &lt;li&gt;Bên ghi của ring A là micro; nếu mô hình cũng ghi vào ring A thì sẽ xảy ra tranh chấp dữ liệu với callback quantum. Ring B tồn tại riêng để làm hàng đợi đầu ra cho mô hình.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bài 05-01 về phân vị p95 giúp dự báo nguy cơ overrun, và bài 05-02 về nguồn cung cấp quantum 128 mẫu.&lt;/li&gt;
  &lt;li&gt;MDN, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;AudioWorklet&lt;/a&gt;, tài liệu về luồng render không được phép chặn khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free&lt;/code&gt; bằng 0.&lt;/li&gt;
  &lt;li&gt;Ghi chú về kích thước bộ đệm của JACK hoặc PipeWire — tham khảo thêm một hệ thuật ngữ khác cho mối quan hệ giữa chu kỳ (period) và độ sâu bộ đệm vòng, không phải API bắt buộc phải gọi.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video phân tích sự chênh lệch giữa kích thước callback phần cứng và khối xử lý lớn hơn của thuật toán; ring buffer trong bài chính là cầu nối giữa hai nhịp đồng hồ đó.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=g1L4O1smMC0&quot;&gt;AudioWorklet :: What, Why, and How - Hongchan Choi&lt;/a&gt; — WebAudio PDX, tiếng Anh. Callback &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; đóng vai trò bên đọc không được phép chặn, và một lần đọc trên bộ đệm rỗng chính là hiện tượng underrun được trình bày trong bài.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>05-02 AudioWorklet và audio callback</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter05/05_02_audioworklet_callbacks/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter05/05_02_audioworklet_callbacks</id>
   <content type="html">&lt;p&gt;Hầu hết lập trình viên web đều quen với một phản xạ gỡ lỗi quen thuộc: thấy chương trình có vấn đề là chèn ngay một dòng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log(...)&lt;/code&gt; vào bên trong hàm đang chạy. Thế nhưng trên luồng xử lý âm thanh thời gian thực của trình duyệt, chính dòng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; vô hại đó lại là &lt;strong&gt;thủ phạm&lt;/strong&gt; biến một cuộc gọi đang mượt mà thành một chuỗi tiếng tách và mất tiếng liên tục! Tại sao một dòng lệnh in ra màn hình lại nguy hiểm đến thế?&lt;/p&gt;

&lt;p&gt;Âm thanh trên trình duyệt được xử lý trên một luồng thời gian thực chuyên biệt. &lt;strong&gt;AudioWorklet&lt;/strong&gt; (luồng render của Web Audio API) là giao diện cho phép đưa mã xử lý của bạn chạy trực tiếp trên luồng đó theo trình tự: gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audioWorklet.addModule&lt;/code&gt;, khởi tạo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletNode&lt;/code&gt;, và nhận lệnh gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process(inputs, outputs, parameters)&lt;/code&gt; một lần cho mỗi render quantum. Mỗi quantum thường dài &lt;strong&gt;128 mẫu&lt;/strong&gt;, tương ứng \(128/48000\approx 2{,}67\) ms ở tần số lấy mẫu 48 kHz. Bên trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;, bạn tuyệt đối không được cấp phát bộ nhớ, chờ khóa (lock) hay gọi mạng. Một lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; vi phạm cả ba nguyên tắc này và không thể dùng để gỡ lỗi mất tiếng (dropout).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Cú sốc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; trên luồng âm thanh → Kiến thức cần nhớ (Tách luồng Main vs. Audio Render, Ba lệnh cấm thời gian thực, Độ lệch nhịp 128 vs. 480 mẫu) → Vòng đời AudioWorklet &amp;amp; hợp đồng bypass → Vì sao &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; bị cấm → Giải thích theo dõi từng callback trong chu kỳ 15 quantum = 4 hop (40 ms) → Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;Quantum AudioWorklet như ngân sách thời gian tường cạnh RTF&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Mỗi callback chỉ quản lý một khối dữ liệu ngắn — thường là 128 mẫu, xấp xỉ 2,67 ms ở 48 kHz — và phải trả về trước khi khối kế tiếp đến hạn. Hệ số thời gian thực (real-time factor, RTF) được đo trên đơn vị khối mà bạn chọn bấm giờ (một quantum hoặc một hop 10 ms gom từ nhiều quantum). Biểu đồ này thể hiện giới hạn thời gian, không phải sự cho phép để chạy trọn một lượt suy luận của DeepFilterNet ngay trong một lần gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ nắm được vòng đời của AudioWorklet, viết được hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; sao chép thẳng tín hiệu đầu vào sang đầu ra khi bật cờ bypass, giải thích được vì sao &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; bị cấm trên luồng render âm thanh, và biết cách ghép hop 480 mẫu của DeepFilterNet lên chuỗi quantum 128 mẫu mà không giả định chúng chia hết cho nhau.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-kiến-trúc-luồng-âm-thanh-thời-gian-thực-trong-trình-duyệt&quot;&gt;Kiến thức cần nhớ: Kiến trúc luồng âm thanh thời gian thực trong trình duyệt&lt;/h2&gt;

&lt;h3 id=&quot;1-tách-biệt-luồng-chính-main-thread-và-luồng-render-âm-thanh-audioworklet-thread&quot;&gt;1. Tách biệt Luồng chính (Main Thread) và Luồng Render âm thanh (AudioWorklet Thread)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Trong trình duyệt, luồng chính bận vẽ giao diện (DOM layout, cuộn trang, phân tích JSON) và có thể bị treo hàng chục mili giây. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; đẩy toàn bộ hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt; sang một luồng ưu tiên thời gian thực riêng biệt, giao tiếp với luồng chính bất đồng bộ qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MessagePort&lt;/code&gt; (hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt;).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Bảo vệ nhịp phát/thu âm thanh khỏi những cú giật của giao diện người dùng (điều mà API cũ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ScriptProcessorNode&lt;/code&gt; không làm được).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-tính-an-toàn-thời-gian-thực-real-time-safety-no-alloc-no-lock-no-io&quot;&gt;2. Tính an toàn thời gian thực (Real-Time Safety: No-Alloc, No-Lock, No-I/O)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Quy tắc thép chung cho mọi hệ thống âm thanh từ CoreAudio, WASAPI, AAudio đến AudioWorklet: thời gian chạy xấu nhất (worst-case execution time) bên trong callback phải bị chặn chặt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Mọi thao tác có thời gian thực thi không xác định — cấp phát heap (có thể kích hoạt GC), chờ mutex (gây đảo ưu tiên), hay gọi mạng/ổ đĩa — đều bị cấm tuyệt đối; toàn bộ bộ đệm nháp (scratch buffer) phải cấp phát sẵn một lần duy nhất trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;constructor&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-hợp-đồng-bypass-và-độ-lệch-pha-kích-thước-khối-block-size-mismatch&quot;&gt;3. Hợp đồng Bypass và Độ lệch pha kích thước khối (Block-Size Mismatch)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Trình duyệt cấp dữ liệu theo quantum \(Q = 128\) mẫu, còn mạng DeepFilterNet xử lý theo hop \(H = 480\) mẫu; đồng thời trong lúc WASM đang tải hoặc khi hop bị trễ, luồng âm thanh vẫn phải trả về đúng 128 mẫu mà không được đứng chờ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Thiết kế đường dự phòng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bypass&lt;/code&gt; sao chép không cấp phát (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;output.set(input)&lt;/code&gt;) kết hợp bộ đệm gom mẫu ở ranh giới giữa hai nhịp đồng hồ không chia hết cho nhau.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Vì sao luồng chính (main thread) không được đảm nhận callback micro.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Vòng đời AudioWorklet, quantum 128 mẫu và giá trị trả về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return true&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Cơ chế sao chép bypass cùng lệnh cấm cấp phát bộ nhớ, khóa đồng bộ và gọi mạng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Đồ thị ONNX của DF3 được phép thực thi ở đâu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab (chỉ cần mã giả) và làm bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;vòng-đời&quot;&gt;Vòng đời&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Trên luồng chính, gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audioContext.audioWorklet.addModule(&apos;ns-processor.js&apos;)&lt;/code&gt; để nạp tệp script của processor. Quá trình biên dịch diễn ra tại bước này, không phải bên trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new AudioWorkletNode(audioContext, &apos;ns-processor&apos;, options)&lt;/code&gt; để khởi tạo node. Tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;options.processorOptions&lt;/code&gt; dùng để truyền kích thước hop và số kênh một lần duy nhất lúc khởi tạo.&lt;/li&gt;
  &lt;li&gt;Kết nối đường tín hiệu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source → nsNode → destination&lt;/code&gt;, hoặc nối vào luồng track của WebRTC (Chương 07).&lt;/li&gt;
  &lt;li&gt;Trình duyệt sẽ gọi hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; trên &lt;strong&gt;luồng render âm thanh&lt;/strong&gt;, một lần cho mỗi quantum trong suốt vòng đời của node. Bạn có thể xem thêm tài liệu tham chiếu chuẩn về AudioWorklet trên MDN tại &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;registerProcessor(&apos;ns-processor&apos;, NsProcessor)&lt;/code&gt; chỉ chạy một lần khi module được nạp lúc dựng đường dẫn âm thanh, không chạy lặp lại ở từng buffer. Việc trả về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt; từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; giữ cho node tiếp tục hoạt động; nếu trả về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;, trình duyệt có thể thu hồi node, khiến bộ khử nhiễu đột ngột ngừng hoạt động giữa cuộc gọi.&lt;/p&gt;

&lt;h3 id=&quot;hợp-đồng-bypass&quot;&gt;Hợp đồng bypass&lt;/h3&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;NsProcessor&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;AudioWorkletProcessor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bypass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// model not ready: copy, do not block&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onmessage&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// Control messages are delivered between callbacks, not during them.&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;setBypass&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bypass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nf&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;outputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;outputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;outputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bypass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// output already exists. set() copies bytes; it does not allocate the buffer.&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Enhancement would use only preallocated scratch and a ready model.&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;registerProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ns-processor&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;NsProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bypass&lt;/code&gt; được bật, người nghe vẫn nhận được tín hiệu micro với độ trễ đúng bằng độ trễ của đồ thị âm thanh, chỉ không qua bộ khử nhiễu. Đây là hành vi chuẩn mực trong thời gian WASM đang biên dịch hoặc khi hop trước đó bị trễ hạn (bài 05-03). Lưu ý rằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;output.set(input)&lt;/code&gt; yêu cầu hai mảng có độ dài tương thích; nếu ghi một quantum 128 mẫu vào bộ đệm đích có kích thước nhỏ hơn, trình duyệt sẽ ném ngoại lệ và chấm dứt hoạt động của node. Vì vậy, cần kiểm tra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input.length&lt;/code&gt; trước khi sao chép.&lt;/p&gt;

&lt;p&gt;Gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; áp dụng kiến trúc tương tự: chạy ONNX/WASM trong AudioWorklet với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; và mức khử nhiễu từ 0 đến 100 qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. Gói này không khớp từng bit với công cụ dòng lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepFilter&lt;/code&gt;, và đoạn mã bypass ở trên chỉ là mã minh họa giảng dạy, không phải mã nguồn của gói đó.&lt;/p&gt;

&lt;h3 id=&quot;vì-sao-consolelog-bị-cấm-trong-process&quot;&gt;Vì sao &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; bị cấm trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;Luồng render âm thanh chịu giới hạn thời gian cứng khoảng 2,67 ms cho mỗi quantum 128 mẫu ở 48 kHz. Ba nguyên tắc bắt buộc được suy ra từ giới hạn này, và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; phá vỡ cả ba:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Không cấp phát bộ nhớ.&lt;/strong&gt; Việc định dạng một dòng log sẽ tạo ra chuỗi mới trên heap. Cấp phát bộ nhớ có thể kích hoạt bộ thu gom rác (GC), mà chỉ một khoảng dừng GC kéo dài vài mili giây đã vượt quá thời lượng một quantum.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không chờ khóa (lock).&lt;/strong&gt; Việc chuyển dòng log sang giao diện console hoặc DevTools phải đi qua một luồng khác và có thể phải chờ mutex. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Atomics.wait&lt;/code&gt; cũng như mọi cơ chế giao tiếp liên tiến trình (IPC) đồng bộ khác đều thuộc cùng nhóm lỗi này.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Không gọi mạng.&lt;/strong&gt; Nếu đầu ra log được gửi tới trình gỡ lỗi từ xa hoặc hệ thống thu thập telemetry, luồng sẽ phải chờ thao tác I/O, trong khi thiết bị âm thanh không bao giờ dừng lại chờ.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lệnh cấm này cũng áp dụng cho &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSON.parse&lt;/code&gt; tệp trọng số, tạo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new Float32Array&lt;/code&gt; trong mỗi callback, biên dịch WASM hay bị chặn trên một mutex do luồng chính nắm giữ. Các thay đổi điều khiển (như bật/tắt bypass, chỉnh mức khử nhiễu, báo hiệu mô hình đã sẵn sàng) phải đi qua thông điệp nhỏ trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MessagePort&lt;/code&gt; và chỉ được áp dụng ở ranh giới giữa các quantum. Toàn bộ trọng số phải được nạp sẵn trên luồng chính hoặc một worker riêng trước khi node tắt chế độ bypass.&lt;/p&gt;

&lt;p&gt;Việc viết một script Node.js import &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wrtc&lt;/code&gt; hoặc chạy bản dựng WASM là phần thực hành mở rộng, không bắt buộc để hoàn thành bài lab này. Tiêu chuẩn đạt yêu cầu chỉ cần phần mã giả và giải thích đúng như trên.&lt;/p&gt;

&lt;h3 id=&quot;quan-hệ-giữa-quantum-và-hop&quot;&gt;Quan hệ giữa quantum và hop&lt;/h3&gt;

&lt;p&gt;Bước nhảy đã công bố của DeepFilterNet là 10 ms, tương đương &lt;strong&gt;480 mẫu&lt;/strong&gt; ở tần số lấy mẫu 48 kHz (bài 04-02, 04-03). Tỉ số \(480/128=3{,}75\) cho thấy hai kích thước này không chia hết cho nhau: 3 callback chỉ tích lũy được 384 mẫu, còn 4 callback tích lũy được 512 mẫu. Do đó, cần đưa dữ liệu vào một ring buffer (bài 05-03) cho đến khi đủ 480 mẫu để chạy một hop, sau đó cắt phần đầu ra overlap-add trở lại thành từng quantum 128 mẫu. Giả định cứng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input.length === 480&lt;/code&gt; sẽ dẫn đến mất mẫu hoặc lặp âm thanh.&lt;/p&gt;

&lt;p&gt;Biến &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt; luôn có sẵn trong phạm vi toàn cục của worklet, vì vậy hãy đọc trực tiếp giá trị này. Ở tần số 44,1 kHz, cùng khối 128 mẫu kéo dài \(128/44100\approx 2{,}90\) ms, đồng thời hop 480 mẫu sẽ không còn tương ứng 10 ms cho một mô hình huấn luyện ở 48 kHz. Các API âm thanh native như CoreAudio, WASAPI và AAudio đều tuân theo nguyên tắc tương tự dưới những tên gọi khác: phải hoàn thành trước kỳ kế tiếp và chuyển sang bypass nếu mô hình xử lý bị trễ.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-dò-tay-chu-kỳ-ghép-128-mẫu-và-480-mẫu&quot;&gt;Giải thích: Dò tay chu kỳ ghép 128 mẫu và 480 mẫu&lt;/h2&gt;

&lt;p&gt;Tại sao ta nói không bao giờ được giả định “cứ đúng 4 callback là chạy 1 hop”? Hãy tính &lt;strong&gt;bội chung nhỏ nhất&lt;/strong&gt; của \(Q = 128 = 2^7\) và \(H = 480 = 2^5 \cdot 3 \cdot 5\):
\(\operatorname{LCM}(128, 480) = 2^7 \cdot 3 \cdot 5 = \mathbf{1920\text{ mẫu}}.\)
Ở 48 kHz, \(1920\) mẫu đúng bằng \(40\text{ ms}\), tương ứng &lt;strong&gt;15 callback&lt;/strong&gt; (\(15 \times 128 = 1920\)) và &lt;strong&gt;4 hop&lt;/strong&gt; (\(4 \times 480 = 1920\)). Bây giờ hãy dò từng callback để thấy số dư mẫu trong bộ đệm biến thiên tuần hoàn ra sao:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Callback thứ&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Mẫu tích lũy trước khi chạy hop&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Chạy hop 480?&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Mẫu còn dư trong ring A&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1, 2, 3&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(128 \to 256 \to 384\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Chưa&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(384\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;4&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(384 + 128 = 512\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Có (Hop #1)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(512 - 480 = \mathbf{32}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5, 6, 7&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(160 \to 288 \to 416\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Chưa&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(416\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;8&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(416 + 128 = 544\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Có (Hop #2)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(544 - 480 = \mathbf{64}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;9, 10, 11&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(192 \to 320 \to 448\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Chưa&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(448\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;12&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(448 + 128 = 576\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Có (Hop #3)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(576 - 480 = \mathbf{96}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;13, 14&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(224 \to 352\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Chưa&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(352\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;15&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(352 + 128 = 480\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Có (Hop #4)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(480 - 480 = \mathbf{0}\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Bài học rút ra từ bảng trên:&lt;/strong&gt; Hop #1, #2, #3 chạy sau mỗi &lt;strong&gt;4 callback&lt;/strong&gt;, nhưng Hop #4 lại rơi vào đúng &lt;strong&gt;3 callback&lt;/strong&gt; sau Hop #3 (tại callback 15)! Nếu một lập trình viên ngây thơ viết &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if (callbackCount % 4 === 0) runHop()&lt;/code&gt;, mỗi chu kỳ 40 ms sẽ bị rò rỉ đúng 128 mẫu — chỉ sau 1 giây đã trượt mất 3.200 mẫu (66,7 ms âm thanh)! Ring buffer ở bài 05-03 chính là cấu trúc loại bỏ hoàn toàn kiểu đếm tay sai lầm này.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Gỡ lỗi mất tiếng bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt;, vô tình làm tình trạng mất tiếng nghiêm trọng hơn.&lt;/li&gt;
  &lt;li&gt;Khởi tạo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new Float32Array(128)&lt;/code&gt; ngay bên trong hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Ghi cứng tần số 48000 thay vì đọc biến &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt; thực tế của worklet.&lt;/li&gt;
  &lt;li&gt;Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;postMessage&lt;/code&gt; (structured clone) sao chép toàn bộ buffer PCM sang luồng chính ở mỗi quantum; nếu bắt buộc phải chuyển dữ liệu sang luồng khác, hãy dùng ring buffer trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt; và đo chi phí sao chép.&lt;/li&gt;
  &lt;li&gt;Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ScriptProcessorNode&lt;/code&gt;, kéo toàn bộ quá trình xử lý âm thanh về luồng chính.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Hiện thực thao tác sao chép bypass bằng mã giả Python để bài lab không phụ thuộc vào trình duyệt hay Node.js. Phần triển khai bằng AudioWorklet đã được trình bày trong khối mã phía trên; bộ chạy thử trên Node là phần tùy chọn, không bắt buộc để đạt yêu cầu.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
def process(frame, bypass, output):
    &quot;&quot;&quot;Copy input to the caller-provided output when bypass is set.
    console.log is illegal: it allocates a string, can lock against
    the console thread, and may touch the network. Do none of that here.
    &quot;&quot;&quot;
    if bypass:
        for i, sample in enumerate(frame):
            output[i] = sample
        return True
    for i, sample in enumerate(frame):
        output[i] = sample  # enhancement would write here, still no allocation
    return True

frame = [0.1, -0.2, 0.3, -0.4]
out = [0.0] * 4
alive = process(frame, bypass=True, output=out)
print(alive, out)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;True [0.1, -0.2, 0.3, -0.4]&lt;/code&gt;. Đối tượng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;output&lt;/code&gt; là bộ đệm do bên gọi cấp phát sẵn từ trước; hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; không tạo thêm danh sách mới, không in ra màn hình và không thực hiện thao tác chờ nào.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Cấp phát mới &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;out = frame.copy()&lt;/code&gt; bên trong hàm rồi coi đó là an toàn thời gian thực; chèn lệnh in “tạm cho bài lab” rồi quên xóa khi đưa vào worklet; yêu cầu phải chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install&lt;/code&gt; hoặc mở trình duyệt mới công nhận đạt; hoặc coi việc sao chép thành công là bằng chứng cho thấy đồ thị DF3 đáp ứng được ngân sách 2,67 ms — sao chép bộ nhớ chỉ tốn vài lệnh đọc ghi, còn suy luận đồ thị thì nặng hơn rất nhiều.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Giới hạn thời gian.&lt;/strong&gt; Với quantum 256 mẫu ở tần số 48 kHz, bạn có bao nhiêu mili giây để xử lý? Nếu tần số lấy mẫu là 44,1 kHz thì con số đó là bao nhiêu?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tích lũy mẫu.&lt;/strong&gt; Mô hình cần hop 480 mẫu trong khi mỗi lần gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; chỉ cung cấp 128 mẫu. Sau bao nhiêu callback thì lần đầu tiên bạn có đủ một hop, và còn dư lại bao nhiêu mẫu?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thông điệp điều khiển mức khử nhiễu.&lt;/strong&gt; Hãy viết payload cho &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;postMessage&lt;/code&gt; để đặt mức khử nhiễu bằng 40 trên một processor có hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; trong dải 0–100. Điều gì xảy ra nếu áp dụng thay đổi này ngay giữa quá trình chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;output.set&lt;/code&gt;?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích sự cố.&lt;/strong&gt; Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; thỉnh thoảng mất 15 ms trong khi thời lượng quantum chỉ là 2,67 ms. Người dùng sẽ nghe thấy hiện tượng gì, và các callback kế tiếp nên xử lý ra sao?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Ở 48 kHz: \(256/48000\approx 5{,}33\) ms. Ở 44,1 kHz: \(256/44100\approx 5{,}80\) ms. Cả hai khoảng thời gian đều vẫn quá nhỏ cho một session ONNX khởi động lạnh, và 5,33 ms mới chỉ bằng một nửa hop 10 ms nên một quantum vẫn chưa thể tương đương một hop.&lt;/li&gt;
  &lt;li&gt;Sau 4 callback, tổng số mẫu tích lũy là \(4\times 128=512\) mẫu. Một hop tiêu thụ 480 mẫu và còn dư &lt;strong&gt;32&lt;/strong&gt; mẫu nằm lại trong ring buffer đầu vào (3 callback chỉ mới có 384 mẫu).&lt;/li&gt;
  &lt;li&gt;Payload là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{type: &quot;setSuppressionLevel&quot;, value: 40}&lt;/code&gt;, được tiếp nhận trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onmessage&lt;/code&gt;, lưu tạm vào một thuộc tính của processor và chỉ áp dụng ở ranh giới hop kế tiếp. Nếu thay đổi hệ số khuếch đại ngay giữa quá trình sao chép, hai nửa của cùng một quantum sẽ có mức khuếch đại khác nhau và gây ra tiếng tách.&lt;/li&gt;
  &lt;li&gt;Thiết bị âm thanh sẽ bị underrun: người dùng nghe thấy tiếng tách, một đoạn âm bị lặp lại hoặc khoảng lặng ngắn tùy cách xử lý của từng trình duyệt. Callback phục hồi cần chuyển sang đường bypass (sao chép tín hiệu gốc) hoặc phát tiếp các mẫu sẵn có trong ring buffer đầu ra, tuyệt đối không chặn luồng để chờ suy luận đuổi kịp.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;MDN, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;AudioWorklet&lt;/a&gt; và tài liệu tham chiếu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletProcessor.process&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Bài 05-01 về RTF và ngân sách hop 10 ms; bài 05-03 về ring buffer dùng để hấp thụ độ lệch 3,75 quantum mỗi hop.&lt;/li&gt;
  &lt;li&gt;Kho mã &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt; tham khảo giao diện sản phẩm với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; (không phải mã nguồn của bài học này).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=g1L4O1smMC0&quot;&gt;AudioWorklet :: What, Why, and How - Hongchan Choi&lt;/a&gt; — WebAudio PDX, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Hongchan Choi giải thích vì sao luồng âm thanh không được phụ thuộc vào luồng chính, đồng thời trình bày rõ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;addModule&lt;/code&gt;, processor và callback.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, tiếng Anh. Phần trình bày về Chrome minh họa sự kết hợp giữa AudioWorklet và WebAssembly ngay trên cùng callback, kèm các số liệu độ trễ khứ hồi đo được.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>05-01 RTF và ngân sách thiết bị</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter05/05_01_rtf_budgets/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter05/05_01_rtf_budgets</id>
   <content type="html">&lt;p&gt;Trong thế giới xử lý âm thanh ngoại tuyến (offline), nếu máy tính của bạn chậm đi một giây, bạn chỉ cần chờ thêm một giây rồi uống ngụm cà phê. Nhưng trong một cuộc gọi thời gian thực, &lt;strong&gt;đồng hồ âm thanh không bao giờ chờ ai cả&lt;/strong&gt;: cứ đúng mỗi 10 mili giây, card âm thanh lại gõ cửa đòi đúng 480 mẫu mới. Nếu mô hình của bạn chạy trung bình hết 4,3 ms — nghe có vẻ dư dả hơn nửa thời gian! — nhưng thi thoảng lại vấp lên 12 ms do bộ thu gom rác hay tiến trình nền chen ngang, người nghe sẽ nhận ngay những tiếng &lt;em&gt;tách&lt;/em&gt; chói tai bất kể điểm PESQ trên giấy có đẹp đến đâu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hệ số thời gian thực (Real-time factor, RTF)&lt;/strong&gt; là tỉ số giữa thời gian xử lý thực tế (wall-clock time) và thời lượng của đoạn âm thanh vừa được xử lý. Bài học này định nghĩa RTF, chỉ ra cách giá trị trung bình che khuất các lần trễ hạn, đồng thời đặt các con số RTF đã công bố trên laptop của DeepFilterNet cạnh render quantum của AudioWorklet để tránh lấy nhầm chúng làm ngân sách tính toán cho điện thoại.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Hạn thời gian cứng của âm thanh thời gian thực → Kiến thức cần nhớ (RTF vs. Độ trễ thuật toán, Thống kê phân vị đuôi p95/p99, Ngân sách thiết bị &amp;amp; hạ xung nhiệt) → Định nghĩa RTF &amp;amp; quy trình đo 4 bước → Bảng ngân sách trình duyệt vs. native → Giải thích tính tay tốc độ lỗi tiếng tách từ p99 và tách bạch RTF khỏi độ trễ → Khởi động lạnh, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;RTF là thời gian tường trên thời gian audio, vẽ cạnh callback AudioWorklet ngắn&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. RTF \(= T_{\mathrm{wall}}/T_{\mathrm{audio}}\). Khối ngắn trong hình là một render quantum, thường dài 128 mẫu. Ở tần số lấy mẫu 48 kHz, khối này tương ứng \(128/48000\approx 2{,}67\) ms. Bước nhảy (hop) của DeepFilterNet dài 10 ms âm thanh và không bắt buộc phải chạy xong trong một quantum duy nhất, nhưng phân vị p95 của thời gian xử lý mỗi hop phải nhỏ hơn 10 ms; nếu không, bộ đệm vòng (ring buffer) đầu ra sẽ bị cạn dữ liệu (underrun, xem bài 05-03).&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ tính được RTF từ một danh sách thời gian xử lý từng khung — bao gồm đúng giá trị trung bình và phân vị p95 trong phần mini-lab; phân biệt rõ RTF với độ trễ thuật toán; và xây dựng ngân sách xử lý tách biệt giữa laptop dùng CPU Core i5, luồng âm thanh trên trình duyệt và thiết bị di động chưa được đo đạc thực tế.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-của-kỹ-thuật-ngân-sách-thời-gian-thực&quot;&gt;Kiến thức cần nhớ: Ba trụ cột của kỹ thuật ngân sách thời gian thực&lt;/h2&gt;

&lt;h3 id=&quot;1-thông-lượng-xử-lý-rtf-vs-độ-trễ-thuật-toán-algorithmic-latency&quot;&gt;1. Thông lượng xử lý (RTF) vs. Độ trễ thuật toán (Algorithmic Latency)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; RTF đo &lt;em&gt;tốc độ chạy của phần cứng&lt;/em&gt; (\(T_{\mathrm{wall}} / T_{\mathrm{audio}}\) — đại lượng không thứ nguyên), còn độ trễ thuật toán đo &lt;em&gt;lượng tín hiệu tương lai phải chờ&lt;/em&gt; (cửa sổ phân tích + số khung look-ahead — đơn vị mili giây).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Tránh nhầm lẫn kinh điển khi thiết kế sản phẩm: nâng cấp CPU làm RTF tụt xuống 0,01 nhưng không bao giờ xóa được 40 ms độ trễ thuật toán của DeepFilterNet2!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-phân-phối-lệch-phải-và-phân-vị-đuôi-tail-latency-p95-p99&quot;&gt;2. Phân phối lệch phải và phân vị đuôi (Tail Latency: p95, p99)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Thời gian xử lý từng hop trên hệ điều hành đa nhiệm không tuân theo phân phối chuẩn đối xứng mà có &lt;strong&gt;đuôi phải dài&lt;/strong&gt; do ngắt hệ thống, đẩy cache và thu gom rác (GC).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Giải thích vì sao giá trị trung bình (mean) là thước đo nguy hiểm cho âm thanh thời gian thực: tai người nghe thấy chính các sự kiện đuôi (p95, p99) dưới dạng tiếng tách (glitch).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-ngân-sách-chia-sẻ-theo-thiết-bị-và-trạng-thái-nhiệt-thermal-throttling&quot;&gt;3. Ngân sách chia sẻ theo thiết bị và trạng thái nhiệt (Thermal Throttling)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Khoảng thời gian hop \(H\) phải nuôi toàn bộ chuỗi xử lý trên luồng âm thanh (AEC + STFT + suy luận mạng + sao chép bộ đệm + dự phòng hệ điều hành), trên CPU đang nóng sau 20 phút chạy liên tục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Thiết lập khoảng dự phòng (headroom) thực tế — ví dụ yêu cầu \(\text{RTF}_{p95} &amp;lt; 0{,}5\) khi chạy song song AEC — và tách riêng thời gian khởi động lạnh (cold start) khỏi trạng thái ổn định.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Vì sao RTF trung bình 0,43 vẫn gây trễ hạn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Định nghĩa RTF, giai đoạn làm nóng (warm-up) và các phân vị.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Render quantum 2,67 ms, hop 10 ms và các chỉ số đã công bố (0,04 và 0,19).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Khởi động lạnh (cold start) và trạng thái hoạt động ổn định.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Thực hành mini-lab và làm bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;định-nghĩa&quot;&gt;Định nghĩa&lt;/h3&gt;

\[\mathrm{RTF}=\frac{T_{\mathrm{wall}}(\text{xử lý }D\text{ giây audio})}{D}.\]

&lt;p&gt;Điều kiện \(\mathrm{RTF}&amp;lt;1\) mới chỉ là điều kiện cần trên &lt;strong&gt;đúng thiết bị đó&lt;/strong&gt;, &lt;strong&gt;bản dựng (build) đó&lt;/strong&gt; và &lt;strong&gt;số luồng đó&lt;/strong&gt;. Điều kiện này chưa đủ trong thực tế vì hệ điều hành có thể ngắt ngang tiến trình, các tiến trình khác tranh giành nhân CPU làm kéo dài phần đuôi phân phối thời gian, trong khi thiết bị âm thanh không bao giờ chờ đợi. Với mỗi hop dài \(H\) giây, toàn bộ công việc trên luồng âm thanh — bao gồm biến đổi Fourier thời gian ngắn (short-time Fourier transform, STFT), suy luận mạng nơ-ron và sao chép bộ đệm — phải gói gọn trong ngân sách xấp xỉ \(H\), chứ không phải riêng mạng nơ-ron được phép chiếm trọn \(H\) rồi các bước còn lại chạy ở thời gian dư. Nếu riêng mạng đã chiếm \(0{,}7H\), phần còn lại cho FFT và các thao tác sao chép ring buffer chỉ còn 30%.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Độ trễ thuật toán không phải là RTF.&lt;/strong&gt; DeepFilterNet2 và bản demo năm 2023 công bố độ trễ thuật toán &lt;strong&gt;40 ms&lt;/strong&gt; với cửa sổ 20 ms, hop 10 ms và nhìn trước (look-ahead) 2 khung (arXiv:2205.05474, arXiv:2305.08227). Độ trễ này vẫn giữ nguyên ngay cả khi RTF chỉ bằng 0,04. Người dùng phải chờ 40 ms là do bộ lọc cần dữ liệu tương lai để tính toán, không phải vì CPU xử lý chậm.&lt;/p&gt;

&lt;h3 id=&quot;phân-vị-quan-trọng-vì-tai-người-nghe-thấy-phần-đuôi&quot;&gt;Phân vị quan trọng vì tai người nghe thấy phần đuôi&lt;/h3&gt;

&lt;p&gt;Xét 10 giá trị thời gian xử lý hop (tính bằng mili giây):&lt;/p&gt;

\[[2{,}0,\;3{,}0,\;2{,}5,\;4{,}0,\;2{,}2,\;8{,}0,\;3{,}1,\;2{,}8,\;3{,}4,\;12{,}0],\]

&lt;p&gt;với độ dài hop là 10 ms. Thời gian trung bình là \(43{,}0/10=4{,}3\) ms, tương ứng RTF trung bình bằng \(4{,}3/10=0{,}43\). Khi sắp xếp tăng dần, ta có \([2{,}0, 2{,}2, 2{,}5, 2{,}8, 3{,}0, 3{,}1, 3{,}4, 4{,}0, 8{,}0, 12{,}0]\). Theo phép tính phân vị nội suy tuyến tính của NumPy, phân vị thứ 95 rơi vào chỉ số \(9\times 0{,}95=8{,}55\), nội suy giữa 8,0 và 12,0:&lt;/p&gt;

\[8{,}0+0{,}55\times(12{,}0-8{,}0)=10{,}2\text{ ms}.\]

&lt;p&gt;Khi đó, RTF p95 đạt \(10{,}2/10=1{,}02\). Cùng một tập số liệu nhưng có hai cách nhìn hoàn toàn trái ngược: nhìn vào trung bình (0,43) có vẻ vẫn còn nhiều khoảng dư, nhưng thiết bị âm thanh lại chứng kiến khung xử lý không kịp trước khi 10 ms âm thanh kế tiếp đến hạn. Do đó, khi đo đạc cần báo cáo đầy đủ p50, p95 và giá trị cực đại trên cửa sổ trượt. Một mô hình có RTF trung bình 0,35 nhưng p99 vượt quá 1 sẽ gây ra tiếng tách trung bình một lần sau mỗi 100 hop — tức cứ mỗi giây một lần với hop 10 ms.&lt;/p&gt;

&lt;p&gt;Quy trình đo chuẩn gồm 4 bước:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Làm nóng (warm-up).&lt;/strong&gt; Chạy trước khoảng 50 hop trước khi bắt đầu ghi nhận số liệu để trình biên dịch JIT, vùng nhớ arena của ONNX Runtime và bộ nhớ đệm (cache) đi vào trạng thái ổn định. Hop đầu tiên thường xuất hiện gai thời gian do cấp phát bộ nhớ; cần báo cáo riêng như thời gian khởi động lạnh (cold start) thay vì gộp vào RTF.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cố định số luồng.&lt;/strong&gt; Luôn dùng 1 luồng cho mọi phép so sánh trên WebAssembly (WASM). Nếu ONNX Runtime bản native sử dụng nhiều luồng intra-op, cần ghi rõ số luồng đó vì chúng sẽ cạnh tranh trực tiếp các nhân CPU mà callback âm thanh đang cần.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chỉ bấm giờ hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;.&lt;/strong&gt; Không gộp thời gian đọc file WAV từ ổ đĩa hay thời gian khởi tạo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session&lt;/code&gt; vào phép đo.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đo trên đúng thiết bị đích.&lt;/strong&gt; Một chiếc điện thoại đang bị hạ xung do quá nhiệt có hiệu năng rất khác so với một chiếc laptop đang mát. Các chỉ số &lt;strong&gt;RTF 0,04&lt;/strong&gt; của DeepFilterNet2 và &lt;strong&gt;RTF 0,11&lt;/strong&gt; của phiên bản trước đó đều được đo trên laptop dùng CPU Core i5-8250U ở mức khoảng 0,35 GMAC. Vòng lặp chạy bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; trong bản demo năm 2023 cũng báo cáo &lt;strong&gt;RTF 0,19&lt;/strong&gt; trên một luồng của CPU i5-8250U. Không một con số nào trong ba chỉ số trên phản ánh RTF trên điện thoại.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;giải-thích-tự-tính-tay-tổng-độ-trễ-và-tần-suất-tiếng-tách-từ-số-liệu-đo&quot;&gt;Giải thích: Tự tính tay tổng độ trễ và tần suất tiếng tách từ số liệu đo&lt;/h2&gt;

&lt;p&gt;Để không bao giờ nhầm giữa &lt;strong&gt;RTF&lt;/strong&gt;, &lt;strong&gt;độ trễ thuật toán&lt;/strong&gt; và &lt;strong&gt;tần suất vỡ tiếng&lt;/strong&gt;, hãy tính tay một bài toán ngân sách trọn vẹn cho một ứng dụng gọi thoại 48 kHz dùng hop \(H = 10\text{ ms}\).&lt;/p&gt;

&lt;h3 id=&quot;bài-toán-1-so-sánh-hai-cấu-hình--chạy-nhanh-nhưng-trễ-vs-chạy-sát-trần-nhưng-ít-trễ&quot;&gt;Bài toán 1: So sánh hai cấu hình — “chạy nhanh nhưng trễ” vs. “chạy sát trần nhưng ít trễ”&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cấu hình A (kiểu DF2):&lt;/strong&gt; Cửa sổ \(20\text{ ms}\), nhìn trước 2 khung (\(2\times 10 = 20\text{ ms}\)), suy luận mất \(T_{\mathrm{wall}} = 0{,}4\text{ ms/hop}\) (\(\text{RTF} = 0{,}04\)).
\(\text{Tổng độ trễ tối thiểu} = \underbrace{20 + 20}_{\text{thuật toán}} + \underbrace{0{,}4}_{\text{tính toán}} = 40{,}4\text{ ms}.\)
Nếu thay CPU mạnh gấp 10 lần (\(\text{RTF} = 0{,}004\)), độ trễ chỉ giảm từ \(40{,}4\text{ ms}\) xuống \(40{,}04\text{ ms}\) — gần như không đổi!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cấu hình B (nhân quả hoàn toàn, 0 khung look-ahead):&lt;/strong&gt; Cửa sổ \(20\text{ ms}\), nhìn trước \(0\text{ ms}\), nhưng suy luận nặng có \(\text{RTF}_{p50} = 0{,}70\) và \(\text{RTF}_{p95} = 1{,}05\).
Dù độ trễ lý thuyết thấp hơn (\(20 + 7 = 27\text{ ms}\)), cấu hình B &lt;strong&gt;hỏng hoàn toàn trong sản phẩm&lt;/strong&gt; vì p95 đã vượt hạn 10 ms.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bài-toán-2-quy-đổi-tỉ-lệ-trễ-hạn-sang-số-tiếng-tách-mỗi-phút&quot;&gt;Bài toán 2: Quy đổi tỉ lệ trễ hạn sang số tiếng tách mỗi phút&lt;/h3&gt;
&lt;p&gt;Giả sử một mô hình chạy ở hop \(H = 10\text{ ms}\) (\(100\text{ hop/giây} = 6\,000\text{ hop/phút}\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nếu \(\text{RTF}_{p99} = 1{,}02 &amp;gt; 1\): có ít nhất \(1\%\) số hop bị trễ hạn \(\implies 0{,}01 \times 6\,000 = \mathbf{60\text{ tiếng tách mỗi phút}}\) (cứ 1 giây lại nổ lách tách một lần!).&lt;/li&gt;
  &lt;li&gt;Nếu ngân sách chia sẻ trên luồng âm thanh gồm: AEC chiếm \(2{,}5\text{ ms}\), STFT + iSTFT + ring buffer chiếm \(1{,}0\text{ ms}\), và ta cần giữ tối thiểu \(20\%\) (\(2{,}0\text{ ms}\)) dự phòng cho hệ điều hành, thì trần thời gian tối đa cho mạng nơ-ron chỉ còn:
\(T_{\max,\text{NN}} = 10{,}0 - 2{,}5 - 1{,}0 - 2{,}0 = \mathbf{4{,}5\text{ ms}} \iff \text{RTF}_{p95,\text{NN}} \le \mathbf{0{,}45}.\)
Đó là lý do trong bảng dưới, mức đạt yêu cầu cho NS khi chạy chung với AEC luôn phải nằm dưới \(0{,}5\) chứ không phải \(&amp;lt; 1{,}0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;so-sánh-ngân-sách-giữa-trình-duyệt-và-ứng-dụng-native-tính-bằng-mili-giây&quot;&gt;So sánh ngân sách giữa trình duyệt và ứng dụng native (tính bằng mili giây)&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Đích triển khai&lt;/th&gt;
      &lt;th&gt;Hạn thời gian tính được&lt;/th&gt;
      &lt;th&gt;Mức đạt yêu cầu&lt;/th&gt;
      &lt;th&gt;Bẫy thường gặp&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Quantum AudioWorklet&lt;/td&gt;
      &lt;td&gt;128 mẫu ở 48 kHz: \(128/48000=2.\overline{6}\) ms, xấp xỉ &lt;strong&gt;2,67 ms&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Hầu như không chạy suy luận nặng tại đây; gom nhiều quantum thành một hop&lt;/td&gt;
      &lt;td&gt;Cố chạy trọn một hop DeepFilterNet 10 ms ngay trong một quantum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hop kiểu DeepFilterNet&lt;/td&gt;
      &lt;td&gt;480 mẫu, tương ứng &lt;strong&gt;10 ms&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Thời gian thực tế p95 \(\ll 10\) ms trên thiết bị đích&lt;/td&gt;
      &lt;td&gt;Chỉ trích dẫn RTF trung bình&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Callback native 10 ms&lt;/td&gt;
      &lt;td&gt;10 ms, dùng chung với bộ khử vọng (AEC)&lt;/td&gt;
      &lt;td&gt;RTF p95 dưới khoảng 0,5 nếu vẫn phải chạy song song AEC&lt;/td&gt;
      &lt;td&gt;Dành trọn 10 ms chỉ cho bộ khử nhiễu (NS)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DSP siêu nhẹ&lt;/td&gt;
      &lt;td&gt;Khoảng 1–4 ms&lt;/td&gt;
      &lt;td&gt;Mô hình GRU hoặc mô hình băng tần nhỏ (bài 04-05, 04-06)&lt;/td&gt;
      &lt;td&gt;Nạp trực tiếp trọng số DF3&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Độ dài render quantum phụ thuộc vào từng trình duyệt, vì vậy cần đo trực tiếp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inputs[0][0].length&lt;/code&gt; khi chạy (bài 05-02). Con số 128 mẫu là trường hợp phổ biến nhất, không phải cam kết cứng trong đặc tả kỹ thuật.&lt;/p&gt;

&lt;h3 id=&quot;khởi-động-lạnh-là-một-phép-đo-độc-lập&quot;&gt;Khởi động lạnh là một phép đo độc lập&lt;/h3&gt;

&lt;p&gt;Việc tải trọng số, biên dịch WASM và khởi tạo session ONNX Runtime có thể mất vài giây, do đó cần hoàn tất trước khi cuộc gọi bắt đầu phát âm thanh. Ngay cả hop ổn định đầu tiên đôi khi vẫn phát sinh cấp phát bộ nhớ; hãy tách nó ra khỏi phép tính phân vị hoặc ghi nhận trên một dòng báo cáo riêng. Khi theo dõi thực tế ngoài sản phẩm, các chỉ số log hữu ích gồm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frames_total&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frames_late&lt;/code&gt; (số khung có thời gian xử lý thực tế \(&amp;gt; H\)), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf_p95&lt;/code&gt; trên cửa sổ 1 giây, tên model thiết bị và cờ trạng thái nhiệt nếu nền tảng hỗ trợ. Thiết lập cảnh báo khi tỉ lệ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frames_late / frames_total&lt;/code&gt; vượt lên khỏi nền nhiễu, mà không cần tải âm thanh thô của người dùng lên máy chủ để vẽ đồ thị này.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bấm giờ cả lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read()&lt;/code&gt; đọc file WAV ngay bên trong vòng lặp xử lý hop.&lt;/li&gt;
  &lt;li&gt;Để runtime đa luồng tranh giành nhân CPU của luồng âm thanh rồi quy lỗi cho mô hình.&lt;/li&gt;
  &lt;li&gt;Dùng chỉ số RTF đo trên GPU để báo cáo cho một sản phẩm chạy trên CPU.&lt;/li&gt;
  &lt;li&gt;Bỏ qua chế độ tiết kiệm pin và hiện tượng hạ xung do quá nhiệt sau khoảng 20 phút sử dụng liên tục.&lt;/li&gt;
  &lt;li&gt;Viết nhầm kiểu “độ trễ 40 ms nên RTF bằng 0,04”, trong khi hai con số này đến từ hai phép đo khác nhau và trả lời hai câu hỏi hoàn toàn khác nhau.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Từ danh sách thời gian xử lý hop cố định ở trên, tính và in ra RTF trung bình cùng RTF p95. Kết quả kỳ vọng khớp với phép tính phân vị nội suy tuyến tính của NumPy.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
import numpy as np
times_ms = np.array([2.0, 3.0, 2.5, 4.0, 2.2, 8.0, 3.1, 2.8, 3.4, 12.0])
hop_ms = 10.0
mean_ms = float(times_ms.mean())
p95_ms = float(np.percentile(times_ms, 95))  # linear, index (n-1)*0.95
print(f&quot;mean_ms={mean_ms:.1f}&quot;)
print(f&quot;p95_ms={p95_ms:.1f}&quot;)
print(f&quot;rtf_mean={mean_ms/hop_ms:.2f}&quot;)
print(f&quot;rtf_p95={p95_ms/hop_ms:.2f}&quot;)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mean_ms=4.3&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p95_ms=10.2&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf_mean=0.43&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf_p95=1.02&lt;/code&gt;. Giá trị trung bình cho cảm giác hop chạy ổn, nhưng p95 chỉ ra hệ thống đã vượt hạn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Dùng phương pháp tính phân vị không nội suy (chọn thẳng 12,0 hoặc 8,0) rồi đánh giá nhầm kết quả đúng 10,2 là sai; chia nhầm cho độ dài cửa sổ 20 ms thay vì hop 10 ms (làm cả hai giá trị RTF giảm đi một nửa); loại bỏ mẫu 12 ms như một điểm ngoại lai dù tai người vẫn nghe thấy tiếng tách; hoặc đem tập số liệu minh họa này so sánh trực tiếp với con số 0,04 đã công bố của DeepFilterNet2.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Khoảng dự phòng (Headroom).&lt;/strong&gt; Với hop 10 ms và thời gian xử lý p95 là 6 ms, RTF p95 và phần ngân sách còn lại của hop là bao nhiêu?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Render quantum.&lt;/strong&gt; Một hop 480 mẫu ở 48 kHz chứa bao nhiêu quantum 128 mẫu? Vì sao tỉ số không nguyên này khiến bộ lập lịch không thể giả định số callback cố định cho mỗi hop?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng số liệu.&lt;/strong&gt; Một đồng nghiệp dán con số “RTF 0,04” vào kế hoạch đánh giá hiệu năng trên điện thoại. Con số này xuất phát từ bài báo nào, trên CPU nào, và bạn cần yêu cầu đo lại những gì?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích sự cố.&lt;/strong&gt; Tiếng rè/nứt bắt đầu xuất hiện sau 20 phút chạy trên một chiếc laptop vốn có RTF bằng 0,3 lúc mới khởi động. Hãy nêu bốn cơ chế làm tăng p95 mà không hề thay đổi file mô hình ONNX.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;RTF p95 \(=6/10=0{,}60\). Phần ngân sách còn lại là \((10-6)/10=0{,}40\), tương ứng 4 ms cho FFT, sao chép bộ đệm và chi phí hệ điều hành.&lt;/li&gt;
  &lt;li&gt;\(480/128=3{,}75\). Ba quantum chỉ cho 384 mẫu, còn bốn quantum cho 512 mẫu. Do đó cần gom mẫu qua ring buffer và không được giả định cứ đúng 4 callback là có một hop.&lt;/li&gt;
  &lt;li&gt;Con số 0,04 thuộc bài báo DeepFilterNet2 (arXiv:2205.05474), đo trên laptop dùng CPU Core i5-8250U cho phiên bản mô hình đã rút gọn. Cần yêu cầu đo lại phân vị p95 ngay trên điện thoại mục tiêu, chạy đơn luồng, trong trạng thái máy đã nóng, trên ít nhất vài nghìn hop. Chỉ số 0,19 (arXiv:2305.08227, dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;, cùng họ CPU) là kết quả của một tệp thực thi khác.&lt;/li&gt;
  &lt;li&gt;Bốn cơ chế phổ biến gồm: CPU hạ xung do quá nhiệt; một tiến trình hoặc luồng khác chiếm nhân (như AEC, thu gom rác GC hoặc ghi log); dữ liệu trong cache bị đẩy ra khi tab trình duyệt khác cấp phát bộ nhớ; và đường xử lý trạng thái chậm dần khi bộ đệm phình to. File đồ thị mô hình không đổi, nhưng \(T_{\mathrm{wall}}\) đã tăng lên.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter et al., &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt;, bảng so sánh RTF 0,11 và 0,04 trên CPU Core i5-8250U.&lt;/li&gt;
  &lt;li&gt;Schröter et al., &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt;, chỉ số RTF 0,19 đơn luồng cho vòng lặp thời gian thực đã công bố.&lt;/li&gt;
  &lt;li&gt;MDN, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;AudioWorklet&lt;/a&gt;, tài liệu về luồng render nơi các quantum được thực thi.&lt;/li&gt;
  &lt;li&gt;Tài liệu hiệu năng của ONNX Runtime về quản lý luồng và khởi tạo session — tham khảo như một phương pháp đo đạc, không phải mức RTF cam kết.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Bài trình bày phân tích sự đánh đổi giữa chi phí tính toán của mô hình và chất lượng cuộc gọi; RTF chính là chi phí thời gian chia cho thời lượng âm thanh, và giá trị trung bình dễ che khuất các lần trễ hạn.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Mức RTF trên CPU laptop trong bài báo là một điểm tham chiếu trong ngân sách mà bạn cần tự đo lại trên thiết bị đích.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, tiếng Anh. Hạn thời gian callback trên Android và Chrome minh họa trực tiếp vế thời gian thực tế của ngân sách RTF.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-06 RNNoise như cầu nối giảng dạy</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_06_rnnoise_bridge/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_06_rnnoise_bridge</id>
   <content type="html">&lt;p&gt;Năm 2017, giữa làn sóng mạng học sâu hàng chục triệu tham số đòi hỏi GPU đắt tiền, kỹ sư âm thanh Jean-Marc Valin (đồng tác giả codec Opus) đặt ra một câu hỏi táo bạo: &lt;em&gt;nếu ta để DSP cổ điển làm phần việc mà toán học đã giải rất tốt — chia băng tần cảm thụ và lọc lược cao độ — rồi chỉ giao cho một mạng nơ-ron tí hon đúng việc duy nhất mà DSP luôn chật vật (ước lượng độ lợi từng băng theo ngữ cảnh), thì kết quả sẽ nhẹ đến mức nào?&lt;/em&gt; Câu trả lời là &lt;strong&gt;RNNoise&lt;/strong&gt;: chỉ 87.503 trọng số, nằm gọn trong bộ nhớ đệm L2 và chạy trên CPU laptop với vỏn vẹn 1,3% tải một nhân!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RNNoise&lt;/strong&gt; (Jean-Marc Valin, arXiv:1709.08243; &lt;a href=&quot;https://github.com/xiph/rnnoise&quot;&gt;xiph/rnnoise&lt;/a&gt;) kết hợp tầng tiền xử lý theo băng Bark, một bộ lọc lược cao độ (pitch comb filter) và một mạng GRU nhỏ dự đoán 22 hệ số độ lợi. Dù không đạt mức điểm Voicebank+Demand như DeepFilterNet3 (PESQ 3,17 trong arXiv:2305.08227), RNNoise minh họa trọn vẹn cùng một triết lý kiến trúc — ước lượng đường bao thô kết hợp tầng xử lý họa âm — với các con số đủ nhỏ để bạn kiểm chứng trực tiếp bằng tay.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Triết lý lai DSP + Học sâu của Valin → Kiến thức cần nhớ (Thang Bark &amp;amp; cửa sổ Vorbis, Bộ lọc lược cao độ, Hàm mất mát nén mũ &amp;amp; làm mượt độ lợi) → 22 băng Bark &amp;amp; 42 đặc trưng đầu vào → Kiến trúc GRU 215 đơn vị &amp;amp; ngân sách 40 Mflop/s → Giải thích tính tay trọn vẹn độ lợi \(g_b\), hệ số lược \(\alpha_b\), hàm mất mát và 3 bước làm mượt → So sánh DF3, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;Đường ERB của DeepFilterNet, dùng để đối chiếu 22 băng Bark và gain GRU của RNNoise&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Sơ đồ của DeepFilterNet gồm 32 độ lợi ERB và bộ lọc phức 5 tap trên các bin STFT thấp. RNNoise nằm ở phía đối chiếu (không phải bản vẽ lại sơ đồ này): dùng 22 băng thang Bark, một mạng GRU dự đoán độ lợi từng băng và một bộ lọc lược cao độ giữa các họa âm. Cả hai đều theo hướng kiến trúc lai, nhưng khác nhau về thang băng tần, cơ chế tầng hai và quy mô mạng.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ tính được độ lợi băng tần của RNNoise từ mặt nạ IRM, liệt kê đúng 42 đặc trưng đầu vào cùng kiến trúc GRU 215 đơn vị trong bài báo, đối chiếu pipeline này với 32 băng ERB và bộ lọc phức 5 tap của DeepFilterNet, đồng thời rút ra các thực hành kỹ thuật hệ thống (giao diện khung, làm mượt độ lợi, tối ưu trọng số vừa bộ nhớ đệm) có thể áp dụng cho AudioWorklet ngay cả khi triển khai DF3.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-kiến-trúc-lai-dsp--học-sâu-của-rnnoise-gồm-những-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Kiến trúc lai DSP + Học sâu của RNNoise gồm những trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-biểu-diễn-theo-băng-cảm-thụ-bark-scale-bands-và-cửa-sổ-princenbradley&quot;&gt;1. Biểu diễn theo băng cảm thụ (Bark-scale Bands) và cửa sổ Princen–Bradley&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Thay vì dự đoán mặt nạ cho cả 481 bin DFT ở 48 kHz, RNNoise gom phổ thành &lt;strong&gt;22 băng Bark&lt;/strong&gt; bằng các bộ lọc tam giác chồng lấp, trên khung 20 ms dùng cửa sổ Vorbis thỏa mãn điều kiện tái tạo hoàn hảo \(w^2(n) + w^2(n + N/2) = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Nén không gian đầu ra gấp hơn 20 lần (từ 481 xuống 22) mà vẫn giữ nguyên độ phân giải mà tai người thực sự phân biệt được, giúp mạng nơ-ron không lãng phí tham số vào các bin tần số cao dày đặc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-bộ-lọc-lược-cao-độ-pitch-comb-filter-cho-cấu-trúc-họa-âm&quot;&gt;2. Bộ lọc lược cao độ (Pitch Comb Filter) cho cấu trúc họa âm&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Khi giọng nói phát âm hữu thanh (như các nguyên âm), năng lượng tập trung ở các đỉnh họa âm cách đều nhau đúng tần số cơ bản \(f_0 = 1/T\), còn nhiễu nằm xen kẽ giữa các đỉnh đó. Cộng tín hiệu với phiên bản trễ đúng chu kỳ cao độ \(T\) — tức \(X(k) + \alpha_b P(k)\) — sẽ khuếch đại họa âm và triệt tiêu nhiễu nằm ở khe giữa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Thực hiện cùng nhiệm vụ khôi phục cấu trúc tinh như bộ lọc phức 5 tap (deep filtering) của DeepFilterNet, nhưng bằng DSP thuần túy tốn rất ít flop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-hàm-mất-mát-nén-mũ-gamma--12-và-bộ-giữ-mức-chống-nhiễu-nhạc&quot;&gt;3. Hàm mất mát nén mũ (\(\gamma = 1/2\)) và bộ giữ mức chống nhiễu nhạc&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Sai số huấn luyện được tính trên căn bậc hai của độ lợi \((g_b^{1/2} - \hat{g}_b^{1/2})^2\), và khi suy luận độ lợi đầu ra được làm mượt bằng bộ lọc một cực \(\tilde{g}_b = \max(\lambda \tilde{g}_b^{(\mathrm{prev})}, \hat{g}_b)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Tránh hai cực đoan phổ biến trong khử nhiễu: khử quá tay làm mất phụ âm nhẹ (khi dùng log-loss) và độ lợi bật/tắt đột ngột giữa các khung gây tiếng “nhiễu nhạc” (musical noise).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — So sánh trực quan giữa độ lợi theo băng tần với bộ lọc phức đa tap.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Cấu trúc 22 băng Bark, công thức độ lợi và bộ lọc lược cao độ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — 42 đặc trưng đầu vào, mạng GRU, hàm mất mát mũ \(\gamma=1/2\) và phân tích độ phức tạp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Những thực hành hệ thống chuyển giao sang WASM và kỳ vọng thực tế về PESQ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Mini-lab và bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;chia-khung-và-gom-băng-tần&quot;&gt;Chia khung và gom băng tần&lt;/h3&gt;

&lt;p&gt;RNNoise hoạt động ở 48 kHz với cửa sổ &lt;strong&gt;20 ms&lt;/strong&gt; và chồng lấp &lt;strong&gt;50%&lt;/strong&gt; (hop 10 ms, 480 mẫu) — trùng khớp về khung thời gian với DeepFilterNet. Bước phân tích và tổng hợp dùng hàm cửa sổ Vorbis:&lt;/p&gt;

\[w(n)=\sin\left(\frac{\pi}{2}\sin^{2}\left(\frac{\pi n}{N}\right)\right),\]

&lt;p&gt;thỏa mãn tiêu chí Princen–Bradley để phép cộng chồng lấp tái tạo chính xác tín hiệu hằng. Phổ tần số được gom thành &lt;strong&gt;22 băng&lt;/strong&gt; theo xấp xỉ thang Bark của codec Opus (chia theo bước Bark ở tần số cao và giữ tối thiểu bốn bin DFT mỗi băng ở tần số thấp), với các trọng số tam giác \(w_b(k)\) có tổng bằng 1. Năng lượng mỗi băng là:&lt;/p&gt;

\[E(b)=\sum_k w_b(k)\,|X(k)|^{2}.\]

&lt;p&gt;Thay vì dự đoán mặt nạ cho cả 481 bin, mạng chỉ xuất một độ lợi cho mỗi băng. Giá trị mục tiêu khi huấn luyện là căn bậc hai của IRM:&lt;/p&gt;

\[g_b=\sqrt{\frac{E_s(b)}{E_x(b)}},\]

&lt;p&gt;sau đó nội suy ngược lên từng bin bằng chính các trọng số tam giác đó: \(r(k)=\sum_b w_b(k)\,\hat{g}_b\). Nhờ độ lợi luôn bị chặn trong đoạn \([0,1]\), mạng nhỏ giữ được độ ổn định cao — trái ngược với mạng ánh xạ (mapping) dự đoán biên độ thô không có biên chặn tự nhiên.&lt;/p&gt;

&lt;p&gt;Tầng đường bao của DeepFilterNet kế thừa trực tiếp ý tưởng này trên thang khác: &lt;strong&gt;32 băng ERB&lt;/strong&gt; kèm một độ lợi thực thay vì 22 băng Bark. Sự khác biệt lớn nằm ở tầng thứ hai: RNNoise không dự đoán hệ số lọc STFT phức mà dùng một &lt;strong&gt;bộ lọc lược cao độ (pitch comb filter)&lt;/strong&gt;. Với \(P(k)\) là DFT của tín hiệu trễ đúng chu kỳ cao độ \(T\), bộ lọc tổ hợp \(X(k)+\alpha_b P(k)\) rồi chuẩn hóa lại năng lượng từng băng. Hệ số pha trộn \(\alpha_b\) được tính theo tương quan cao độ \(p_b\) và độ lợi băng:&lt;/p&gt;

\[\alpha_b=\min\left(\sqrt{\frac{p_b^{2}(1-g_b^{2})}{(1-p_b^{2})g_b^{2}}},\,1\right),\]

&lt;p&gt;kèm điều kiện biên \(\alpha_b=1\) khi \(p_b\ge g_b\), và \(\alpha_b=0\) khi \(g_b=1\) hoặc \(p_b=0\). Tổng phức 5 tap của DeepFilterNet đạt hiệu quả củng cố họa âm tương tự ngay bên trong mạng (tới khoảng 5 kHz) nhưng tốn chi phí MAC cao hơn nhiều; còn bộ lọc lược của RNNoise thuần DSP, rất nhẹ nhưng phụ thuộc chặt vào độ chính xác của bộ ước lượng cao độ.&lt;/p&gt;

&lt;h3 id=&quot;đặc-trưng-đầu-vào-và-kiến-trúc-gru&quot;&gt;Đặc trưng đầu vào và kiến trúc GRU&lt;/h3&gt;

&lt;p&gt;Bài báo cố định 42 đặc trưng đầu vào gồm: 22 hệ số cepstrum thang Bark, đạo hàm bậc một và bậc hai của 6 hệ số đầu (thêm 12), 6 hệ số DCT của tương quan cao độ, chu kỳ cao độ và 1 đặc trưng đo độ không dừng: \(22+12+6+1+1=42.\) Do không chuẩn hóa trung bình cepstrum, mức năng lượng tuyệt đối vẫn được giữ lại. Đáp ứng tần số micro được mô phỏng trong lúc huấn luyện bằng bộ lọc bậc hai ngẫu nhiên với hệ số thuộc \([-3/8,3/8]\).&lt;/p&gt;

&lt;p&gt;Mạng nơ-ron gồm &lt;strong&gt;215 đơn vị&lt;/strong&gt; chia trên &lt;strong&gt;bốn lớp ẩn&lt;/strong&gt; (lớp lớn nhất có 96 đơn vị); Valin ghi nhận GRU hoạt động nhỉnh hơn LSTM và đơn giản hơn trong bài toán này. Một đầu ra phát hiện tiếng nói (VAD) chỉ tốn thêm 24 trọng số nhưng giúp định hướng một lớp GRU phân tách rõ tiếng nói và nhiễu khi huấn luyện. Hàm mất mát cho độ lợi là:&lt;/p&gt;

\[L(g_b,\hat{g}_b)=\left(g_b^{\gamma}-\hat{g}_b^{\gamma}\right)^{2},\qquad \gamma=\tfrac{1}{2},\]

&lt;p&gt;thay vì dùng binary cross-entropy. Khi \(\gamma\to 0\), hàm mất mát tiến gần sai số log-năng lượng và dễ gây khử quá mức; \(\gamma=1/2\) là điểm cân bằng được chọn trong bài báo. Các băng không có cả tiếng nói lẫn nhiễu được đánh dấu không xác định và loại khỏi hàm mất mát để tránh dạy mạng xuất giá trị 0 trên khoảng lặng hoặc âm thanh đã lọc thông thấp.&lt;/p&gt;

&lt;p&gt;Bước làm mượt độ lợi giới hạn tốc độ suy giảm của từng băng:&lt;/p&gt;

\[\tilde{g}_b=\max\left(\lambda \tilde{g}_b^{(\mathrm{prev})},\,\hat{g}_b\right),\qquad \lambda=0{,}6,\]

&lt;p&gt;trong đó \(\lambda=0{,}6\) ở hop 10 ms tương đương thời gian tắt (reverberation time) khoảng &lt;strong&gt;135 ms&lt;/strong&gt;. Giảm \(\lambda\) làm âm thanh nghe khô hơn, còn \(\lambda=1\) khiến độ lợi không bao giờ hạ xuống. Bộ giữ mức một cực này chính là kỹ thuật chống nhiễu nhạc kế thừa từ tư duy ngưỡng sàn phổ ở Chương 03.&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-tính-tay-trọn-vẹn-một-băng-bark-của-rnnoise&quot;&gt;Giải thích: Tính tay trọn vẹn một băng Bark của RNNoise&lt;/h2&gt;

&lt;p&gt;Giả sử tại một băng tần hữu thanh (ví dụ băng 300–500 Hz), năng lượng tiếng nói sạch là \(E_s(b) = 16\) và năng lượng nhiễu không tương quan là \(E_n(b) = 9\), nên năng lượng tín hiệu hỗn hợp là \(E_x(b) = 16 + 9 = 25\). Tương quan cao độ đo được ở băng này là \(p_b = 0{,}6\).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính độ lợi mục tiêu \(g_b\):&lt;/strong&gt;
\(g_b = \sqrt{\frac{E_s(b)}{E_x(b)}} = \sqrt{\frac{16}{25}} = 0{,}8.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hệ số pha trộn bộ lọc lược \(\alpha_b\):&lt;/strong&gt; Vì \(p_b = 0{,}6 &amp;lt; g_b = 0{,}8\), ta thay thẳng vào công thức:
\(\alpha_b = \sqrt{\frac{0{,}6^2(1 - 0{,}8^2)}{(1 - 0{,}6^2)\cdot 0{,}8^2}} = \sqrt{\frac{0{,}36 \times 0{,}36}{0{,}64 \times 0{,}64}} = \frac{0{,}36}{0{,}64} = 0{,}5625.\)
Kiểm tra nhanh trường hợp cực đoan: nếu tín hiệu có rất nhiều nhiễu (\(g_b = 0{,}5 &amp;lt; p_b = 0{,}6\)), điều kiện biên lập tức kẹp \(\alpha_b = 1\) để bộ lọc lược lọc mạnh nhất giữa các họa âm; còn nếu tín hiệu sạch hoàn toàn (\(g_b = 1\)), \(\alpha_b = 0\) để không làm méo giọng sạch!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính hàm mất mát với \(\gamma = 1/2\):&lt;/strong&gt; Nếu mạng dự đoán \(\hat{g}_b = 0{,}5\) thay vì \(g_b = 0{,}8\):
\(L(0{,}8,\,0{,}5) = \left(\sqrt{0{,}8} - \sqrt{0{,}5}\right)^2 \approx (0{,}8944 - 0{,}7071)^2 \approx 0{,}0351.\)
So sánh với vùng độ lợi nhỏ (ví dụ \(g_b = 0{,}3\) và \(\hat{g}_b = 0{,}0\), cùng sai số tuyệt đối \(0{,}3\)): \((\sqrt{0{,}3} - 0)^2 = 0{,}3000\) — phạt nặng gấp &lt;strong&gt;8,5 lần&lt;/strong&gt;! Nhờ căn bậc hai, hàm mất mát rất nhạy với việc khử sạch âm nhỏ xuống 0.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theo dõi 3 hop làm mượt độ lợi (\(\lambda = 0{,}6\)):&lt;/strong&gt; Giả sử hop trước đang ở \(\tilde{g}_b^{(0)} = 0{,}9\) và tiếng nói đột ngột ngừng nên mạng dự đoán \(\hat{g}_b = 0{,}3\) ở các hop kế tiếp:
    &lt;ul&gt;
      &lt;li&gt;Hop 1: \(\tilde{g}_b^{(1)} = \max(0{,}6 \times 0{,}9,\; 0{,}3) = 0{,}54\).&lt;/li&gt;
      &lt;li&gt;Hop 2: \(\tilde{g}_b^{(2)} = \max(0{,}6 \times 0{,}54,\; 0{,}3) = 0{,}324\).&lt;/li&gt;
      &lt;li&gt;Hop 3: \(\tilde{g}_b^{(3)} = \max(0{,}6 \times 0{,}324,\; 0{,}3) = \max(0{,}1944,\; 0{,}3) = 0{,}30\).
Độ lợi hạ êm trong 30 ms thay vì tụt thẳng đứng từ \(0{,}9 \to 0{,}3\) trong một hop, tránh hẳn tiếng “khựng” cơ học.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;so-sánh-độ-phức-tạp-với-deepfilternet&quot;&gt;So sánh độ phức tạp với DeepFilterNet&lt;/h3&gt;

&lt;p&gt;Mạng có tổng cộng &lt;strong&gt;87.503&lt;/strong&gt; trọng số — khi lượng tử hóa 8-bit, toàn bộ trọng số nằm gọn trong bộ nhớ đệm L2 mà bài báo ghi nhận không suy giảm chất lượng. Tính mỗi phép nhân-cộng là 2 flop, mạng tiêu tốn khoảng 175.000 flop mỗi khung, tương ứng &lt;strong&gt;17,5 Mflop/s&lt;/strong&gt; ở tốc độ 100 khung/giây. Cộng thêm khoảng 7,5 Mflop/s cho FFT và 10 Mflop/s cho tìm cao độ ở 12 kHz, tổng chi phí chỉ vào khoảng &lt;strong&gt;40 Mflop/s&lt;/strong&gt;. Mã C chưa vector hóa chỉ dùng khoảng &lt;strong&gt;1,3%&lt;/strong&gt; một nhân Haswell i7-4800MQ và khoảng &lt;strong&gt;14%&lt;/strong&gt; trên Cortex-A53 1,2 GHz. Con số này thấp hơn rất nhiều so với ngân sách ~0,35 GMAC/s của DeepFilterNet. Trên bảng so sánh của DeepFilterNet2, RNNoise đạt PESQ &lt;strong&gt;2,33&lt;/strong&gt; và RTF &lt;strong&gt;0,027&lt;/strong&gt;, so với bản DF2 tinh gọn đạt PESQ &lt;strong&gt;3,08&lt;/strong&gt; và RTF &lt;strong&gt;0,04&lt;/strong&gt; (tốc độ trên laptop cùng bậc, nhưng chất lượng PESQ của RNNoise thấp hơn trên tập kiểm thử đó).&lt;/p&gt;

&lt;p&gt;Tập huấn luyện của RNNoise chỉ gồm khoảng 6 giờ tiếng nói và 4 giờ nhiễu (mở rộng thành 140 giờ qua lấy mẫu lại giữa 40 và 54 kHz), nhỏ hơn rất nhiều so với hơn 750 giờ tiếng nói trong cấu hình DeepFilterNet ICASSP. Do đó, các dạng xung click hay ngôn ngữ ngoài tập 6 giờ ban đầu rất dễ vượt khỏi khả năng của mô hình mặc định.&lt;/p&gt;

&lt;h3 id=&quot;thực-hành-hệ-thống-chuyển-giao-sang-sản-phẩm&quot;&gt;Thực hành hệ thống chuyển giao sang sản phẩm&lt;/h3&gt;

&lt;p&gt;Chuỗi sản phẩm vẫn sử dụng AudioWorklet theo hướng DF3 (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;) chứ không thay bằng RNNoise. Tuy vậy, nhiều kỷ luật hệ thống từ RNNoise có giá trị trực tiếp: xử lý đúng một hop mỗi lần gọi (480 mẫu; quantum 128 mẫu vẫn cần bộ đệm vòng ở bài 05-03); tính trước hàm cửa sổ và bảng trọng số băng; cân nhắc làm mượt độ lợi (lưu ý \(\lambda=0{,}6\) là hằng số của RNNoise, không tự áp mặc định cho DF3 mà chưa nghe kiểm tra); lượng tử hóa để giữ trọng số gọn trong cache; và giữ nguyên bộ lọc lược cao độ nếu triển khai mạng siêu nhỏ cỡ này (bỏ bộ lọc lược sẽ biến nó thành một thuật toán khác).&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Phủ nhận giá trị kỹ thuật của mã nguồn C chỉ vì điểm PESQ 2,33 trên bảng so sánh.&lt;/li&gt;
  &lt;li&gt;Kỳ vọng mô hình RNNoise mặc định đạt chất lượng ngang mức PESQ 3,17 của DF3.&lt;/li&gt;
  &lt;li&gt;Tái cài đặt phần GRU nhưng xóa bỏ bộ lọc lược cao độ.&lt;/li&gt;
  &lt;li&gt;Dùng RNNoise làm mục tiêu thay vì làm ngưỡng sàn kiểm thử hồi quy (“chất lượng tối thiểu phải vượt qua”) cho DF3 48 kHz.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Kiểm chứng tổng số đặc trưng, ngân sách flop mỗi giây và một bước làm mượt độ lợi bằng chính các hằng số trong bài báo (không cần tệp âm thanh hay kết nối mạng).&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
bfcc, deriv, pitch_dct, pitch_period, nonstat = 22, 12, 6, 1, 1
features = bfcc + deriv + pitch_dct + pitch_period + nonstat
weights = 87503
flops_per_frame = weights * 2  # multiply-add counted as two flops
mflops = flops_per_frame * 100 / 1e6  # 10 ms hop
g_hat, g_prev, lam = 0.3, 0.9, 0.6
g_smooth = max(lam * g_prev, g_hat)
print(features, flops_per_frame, round(mflops, 1), round(g_smooth, 2))
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;42 175006 17.5 0.54&lt;/code&gt;. Độ lợi sau làm mượt giữ ở mức \(0{,}6\times 0{,}9=0{,}54\) vì ước lượng tức thời 0,3 sẽ hạ băng quá nhanh; con số “175.000” trong bài báo là giá trị làm tròn của \(2\times 87503=175006\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Quên cộng các thành phần đạo hàm nên báo 22 đặc trưng; dùng nhầm hop 20 ms làm giảm một nửa xuống 8,8 Mflop/s; đặt \(\lambda=0\) nhưng vẫn gọi là “đã làm mượt”; hoặc triển khai RNNoise vào sản phẩm và kỳ vọng chất lượng ngang DF3.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Sơ đồ chuỗi xử lý.&lt;/strong&gt; Vẽ luồng PCM → cửa sổ 960 điểm → 22 băng → 42 đặc trưng → GRU → 22 độ lợi → bộ lọc lược cao độ → tổng hợp, và đánh dấu rõ bước nhảy hop 10 ms.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ số pha trộn.&lt;/strong&gt; Khi \(g_b=1\), hệ số \(\alpha_b\) bằng bao nhiêu và bộ lọc lược tác động như thế nào lên khung tiếng nói sạch?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính bước làm mượt.&lt;/strong&gt; Cho độ lợi làm mượt trước đó bằng 0,8, ước lượng mới bằng 0,2 và \(\lambda=0{,}6\). Độ lợi đầu ra hiện tại là bao nhiêu? Cần bao nhiêu hop liên tiếp có ước lượng 0,2 để độ lợi giảm xuống dưới 0,3?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thiết kế API.&lt;/strong&gt; Phác thảo giao diện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process_frame(state, in[480], out[480])&lt;/code&gt; và liệt kê ít nhất ba trường trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state&lt;/code&gt; bắt buộc phải bảo toàn qua các lần gọi.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Bước nhảy hop 480 mẫu ở 48 kHz; mạng GRU nhận 42 đặc trưng đầu vào và xuất 22 độ lợi kèm 1 tín hiệu VAD; bộ lọc lược dùng chu kỳ cao độ \(T\) cùng hệ số \(\alpha_b\) theo từng băng trước khi chuẩn hóa lại năng lượng băng.&lt;/li&gt;
  &lt;li&gt;Nhờ điều kiện biên, khi \(g_b=1\) thì \(\alpha_b=0\): bộ lọc lược được bỏ qua hoàn toàn để tiếng nói sạch không bị méo do lọc cao độ.&lt;/li&gt;
  &lt;li&gt;Hop đầu: \(\max(0{,}6\times 0{,}8,\,0{,}2)=\max(0{,}48,\,0{,}2)=0{,}48\); hop thứ hai: \(\max(0{,}6\times 0{,}48,\,0{,}2)=0{,}288 &amp;lt; 0{,}3\). Vậy cần đúng 2 hop.&lt;/li&gt;
  &lt;li&gt;Tối thiểu gồm trạng thái ẩn GRU, mảng độ lợi đã làm mượt \(\tilde{g}_b\) và bộ đệm lịch sử OLA / cao độ; xóa bất kỳ thành phần nào giữa luồng sẽ gây tiếng click hoặc lọt một đoạn nhiễu ngắn (bài 05-04).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Valin, “A Hybrid DSP/Deep Learning Approach to Real-Time Full-Band Speech Enhancement,” &lt;a href=&quot;https://arxiv.org/abs/1709.08243&quot;&gt;arXiv:1709.08243&lt;/a&gt; (công bố tại IEEE MMSP 2018 và được DeepFilterNet trích dẫn).&lt;/li&gt;
  &lt;li&gt;Mã nguồn và trọng số lượng tử hóa 8-bit: &lt;a href=&quot;https://github.com/xiph/rnnoise&quot;&gt;github.com/xiph/rnnoise&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Bộ khử MMSE của SpeexDSP — mốc đối chiếu cổ điển trong cùng bài báo.&lt;/li&gt;
  &lt;li&gt;Schröter et al., &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt; và &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt; — đối chiếu 32 băng ERB và bảng PESQ 2,33 so với 3,08.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nsscrYdrGRE&quot;&gt;RNNoise, Neural Speech Enhancement, and the Browser&lt;/a&gt; — W3C, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày trực tiếp sự kết hợp giữa đặc trưng DSP, mạng GRU nhỏ và độ lợi theo băng chạy trong trình duyệt với look-ahead rất ngắn.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Dùng để đối chiếu kiến trúc ERB + deep filter quy mô lớn hơn mà RNNoise không đặt mục tiêu thay thế về mặt điểm số.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Đặt RNNoise trong bức tranh thước đo chất lượng sản phẩm thực tế.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-05 Mô hình streaming siêu nhẹ</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_05_ultralight_streaming/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_05_ultralight_streaming</id>
   <content type="html">&lt;p&gt;Hãy thử tưởng tượng bạn vừa tìm thấy trên mạng một mô hình khử nhiễu tiếng nói chỉ tốn &lt;strong&gt;0,05 GMAC&lt;/strong&gt; — nhẹ hơn DeepFilterNet2 tới bảy lần trên giấy. Bạn hăm hở xuất sang ONNX, nhúng vào trình duyệt hay bo mạch nhúng, rồi bật micro thử nghiệm… và lập tức nghe thấy tiếng &lt;em&gt;tách, tách&lt;/em&gt; liên hồi vì mỗi khung xử lý bị trễ hạn! Chuyện gì vừa xảy ra? Một mô hình ít phép nhân-cộng hơn tại sao lại chạy &lt;em&gt;chậm hơn&lt;/em&gt; ngoài đời thực, và tại sao một mạng GRU chạy êm ru suốt đoạn demo 3 giây lại bỗng dưng méo tiếng sau 40 phút họp trực tuyến?&lt;/p&gt;

&lt;p&gt;Nhiều sản phẩm không đủ ngân sách tài nguyên như mức laptop mà DeepFilterNet2 giả định. Các tên gọi &lt;strong&gt;GTCRN&lt;/strong&gt;, &lt;strong&gt;FastEnhancer&lt;/strong&gt;, &lt;strong&gt;μNet&lt;/strong&gt; và &lt;strong&gt;Fast-ULCNet&lt;/strong&gt; thường xuất hiện trong danh sách rút gọn (shortlist) cho nhóm bộ tăng cường tiếng nói streaming siêu nhẹ. Bài học này &lt;strong&gt;không&lt;/strong&gt; gắn tiêu đề bài báo, năm xuất bản hay URL cho bốn cái tên đó; thay vào đó, bài tập trung vào phương pháp đo kiểm để ra quyết định: lý giải vì sao bảng số phép tính MAC và hệ số RTF thực tế (wall-clock) thường tách rời nhau, và vì sao hiện tượng trôi trạng thái GRU sau một giờ chạy liên tục là một dạng lỗi khác hẳn với lỗi hop chậm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mạch bài học:&lt;/strong&gt; Ngộ nhận “ít MAC = chạy nhanh” → Kiến thức cần nhớ (Nghẽn băng thông bộ nhớ, Độ trễ đuôi p95, Ổn định hệ động lực hồi tiếp dài hạn) → Đối chiếu ngân sách phần cứng &amp;amp; số liệu DF2 → Bốn cái tên định hướng trong shortlist → Giải thích tính tay sự tách rời MAC/RTF và cơ chế tích lũy trôi trạng thái sau 270.000 hop → Danh mục kiểm tra, Mini-lab và Bài tập.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;RTF đối chiếu quantum AudioWorklet: thời gian tường mỗi khối audio, không phải bảng MAC&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. RTF là tỷ số giữa thời gian xử lý thực tế và thời lượng âm thanh. Một quantum AudioWorklet 128 mẫu ở 48 kHz dài khoảng 2,67 ms. Mô hình siêu nhẹ đạt yêu cầu là mô hình giữ được phân vị p95 thời gian xử lý nằm gọn trong hop thực tế trên đúng CPU đích; bốn cái tên GTCRN, FastEnhancer, μNet và Fast-ULCNet chỉ đóng vai trò điểm neo trong danh sách rút gọn.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ giải thích được (thông qua bảng số liệu có thể kiểm chứng của DeepFilterNet2) vì sao GMAC và RTF có thể biến thiên ngược chiều nhau; đưa bốn tên mô hình siêu nhẹ vào danh mục kiểm tra lựa chọn mà không suy đoán kết quả; và thiết kế bài kiểm tra ổn định trạng thái dài hạn độc lập với từng bài báo.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-điều-gì-quyết-định-tốc-độ-và-độ-bền-của-mô-hình-streaming-siêu-nhẹ&quot;&gt;Kiến thức cần nhớ: Điều gì quyết định tốc độ và độ bền của mô hình streaming siêu nhẹ?&lt;/h2&gt;

&lt;h3 id=&quot;1-nghẽn-tính-toán-compute-bound-vs-nghẽn-bộ-nhớ-memory-bound&quot;&gt;1. Nghẽn tính toán (Compute-bound) vs. Nghẽn bộ nhớ (Memory-bound)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Trong kiến trúc máy tính hiện đại, thời gian chạy một lớp mạng nơ-ron bị chặn bởi giá trị lớn hơn giữa thời gian tính toán (số MAC / tốc độ ALU) và thời gian vận chuyển dữ liệu từ RAM/cache vào thanh ghi (số byte đọc-ghi / băng thông bộ nhớ).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Giải thích vì sao một lớp tích chập nhóm tinh vi hoặc thao tác &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gather&lt;/code&gt; cắt lát băng tần có số MAC rất nhỏ nhưng lại chạy chậm rì trên CPU/WASM: bộ xử lý dành phần lớn thời gian &lt;em&gt;chờ&lt;/em&gt; dữ liệu từ cache thay vì nhân-cộng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-phân-phối-thời-gian-thực-tế-wall-clock-rtf-và-phân-vị-đuôi-p95-p99&quot;&gt;2. Phân phối thời gian thực tế (Wall-clock RTF) và phân vị đuôi (p95, p99)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Thay vì đánh giá tốc độ bằng số trung bình hay GMAC lý thuyết, kỹ thuật thời gian thực đo thời gian tường (wall-clock) từng hop trên đúng thiết bị đích và khóa ngưỡng ở phân vị p95/p99.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Đảm bảo không xảy ra underrun (vỡ tiếng) trong dòng âm thanh liên tục — nơi chỉ cần 1% số khung vượt quá hạn hop 10 ms là người nghe đã thấy tiếng nổ lách tách mỗi giây.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-tính-ổn-định-của-hệ-hồi-tiếp-rời-rạc-recurrent-state-drift&quot;&gt;3. Tính ổn định của hệ hồi tiếp rời rạc (Recurrent State Drift)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Là gì:&lt;/strong&gt; Một mạng GRU chạy streaming là một hệ động lực rời rạc \(h_t = F(h_{t-1}, x_t)\) lặp hàng trăm nghìn bước liên tiếp mà không reset.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nghiên cứu gì:&lt;/strong&gt; Nếu các cổng quên (update/reset gate) tiến gần 1 và xuất hiện sai số lượng tử hóa nhỏ hoặc tín hiệu đầu vào lệch phân bố (như khoảng lặng kéo dài), sai số nhỏ ở mỗi hop có thể tích lũy thành &lt;strong&gt;trôi trạng thái (state drift)&lt;/strong&gt; — lỗi vô hình ở đoạn test 3 giây nhưng phá hỏng cuộc gọi 45 phút.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — So sánh hai ngân sách tài nguyên: chip DSP tai nghe và tab trình duyệt trên laptop.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Dùng số liệu DF2 để chứng minh số MAC tách rời khỏi RTF thực tế.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Định vị ngắn gọn bốn cái tên siêu nhẹ và danh mục thông số bắt buộc phải tự đo.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Hiện tượng trôi trạng thái (state drift) qua hàng chục phút gọi liên tục.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Mini-lab, danh mục kiểm tra và bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;hai-ngân-sách-phần-cứng-khác-hẳn-bảng-đo-df2&quot;&gt;Hai ngân sách phần cứng khác hẳn bảng đo DF2&lt;/h3&gt;

&lt;p&gt;DeepFilterNet2 (arXiv:2205.05474) báo cáo RTF &lt;strong&gt;0,04&lt;/strong&gt; ở mức &lt;strong&gt;0,356 GMAC&lt;/strong&gt; trên laptop Core i5-8250U, so với bản ICASSP đạt 0,348 GMAC nhưng RTF &lt;strong&gt;0,11&lt;/strong&gt;; trong khi vòng chạy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; năm 2023 ghi nhận RTF &lt;strong&gt;0,19&lt;/strong&gt; trên cùng i5-8250U. Trên cùng bảng DF2, RNNoise có khoảng 0,06 M tham số, RTF 0,027 và PESQ 2,33 (so với PESQ 3,08 của DF2). Đây là những con số hiệu năng duy nhất đã được công bố mà bài học này trích dẫn. Tai nghe hay điện thoại là lớp phần cứng hoàn toàn khác, nên RTF laptop không thể suy diễn sang RTF di động. Các kiến trúc siêu nhẹ hướng tới bộ nhớ cực nhỏ và hop ngắn, thường chấp nhận điểm PESQ gần mức 2,33 hơn là 3,17 — sự đánh đổi hoàn toàn hợp lý khi lựa chọn còn lại là vỡ tiếng do underrun.&lt;/p&gt;

&lt;h3 id=&quot;vì-sao-cột-mac-trong-bài-báo-dễ-gây-hiểu-nhầm&quot;&gt;Vì sao cột MAC trong bài báo dễ gây hiểu nhầm&lt;/h3&gt;

&lt;p&gt;Đếm số phép nhân-cộng (MAC) ngầm giả định mọi phép tính đều mất thời gian thực tế như nhau, nhưng trên phần cứng thực tế điều này không đúng:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Các thao tác gom dữ liệu theo nhóm hoặc theo băng tần (gather) phải nhảy cóc trong bộ nhớ, khiến đơn vị tính toán (ALU) phải chờ bộ nhớ đệm (cache) — lập luận này thường gắn với tên gọi FastEnhancer (chỉ nêu tên, không trích bài báo ở đây).&lt;/li&gt;
  &lt;li&gt;Một phép nhân ma trận dày (GEMM) lớn hơn một chút nhưng được runtime hợp nhất (fused) thường hoàn thành nhanh hơn một lớp tích chập nhóm tinh vi mà ONNX Runtime không vector hóa tốt.&lt;/li&gt;
  &lt;li&gt;Lớp tích chập theo trục thời gian phải duy trì vòng đệm activation quá khứ. DF2 rút kernel từ \(2\times 3\) xuống \(1\times 3\) (trừ lớp đầu vào) giúp RTF giảm từ 0,11 xuống 0,04 dù GMAC hầu như đứng yên. Đây là nguyên tắc cốt lõi khi đánh giá mọi mô hình siêu nhẹ: hãy đếm lưu lượng byte di chuyển ở mỗi hop chứ không chỉ nhìn số MAC.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Quy tắc đo kiểm (Chương 05):&lt;/strong&gt; Chạy đơn luồng, loại bỏ giai đoạn khởi động (warm-up), đo phân vị p50 và p95 thời gian xử lý thực tế mỗi hop rồi chia cho độ dài hop trên đúng thiết bị đích theo nhịp callback. Cột MAC trong bài báo chỉ nên coi là giả thuyết ban đầu.&lt;/p&gt;

&lt;h3 id=&quot;bốn-cái-tên-định-hướng-chỉ-ở-mức-danh-mục&quot;&gt;Bốn cái tên định hướng (chỉ ở mức danh mục)&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tên&lt;/th&gt;
      &lt;th&gt;Vai trò trong danh sách rút gọn&lt;/th&gt;
      &lt;th&gt;Phạm vi bài học này không nêu&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;GTCRN&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Mạng tích chập–hồi tiếp theo nhóm siêu nhẹ, thường được nhắc tới&lt;/td&gt;
      &lt;td&gt;Không nêu tiêu đề, năm, URL, MAC hay MOS&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;FastEnhancer&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tên gắn với định hướng tối ưu tốc độ trên thiết bị (kể cả đo trên ONNX Runtime)&lt;/td&gt;
      &lt;td&gt;Không nêu số liệu kết quả&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;μNet&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tên gắn với ràng buộc bộ nhớ cực thấp (DSP, tai nghe)&lt;/td&gt;
      &lt;td&gt;Không nêu số liệu kết quả&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Fast-ULCNet&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Tên gắn với nhánh ULCNet và bài toán trạng thái RNN trong luồng dài&lt;/td&gt;
      &lt;td&gt;Không nêu số liệu kết quả&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Một số cái tên cùng nhóm như ULCNet, UL-UNAS, AdaptCRN, CoFi-Lite hay FSPEN chỉ là từ vựng mở rộng tùy chọn, không nằm trong phạm vi kiểm tra và không gắn trích dẫn tại đây.&lt;/p&gt;

&lt;h3 id=&quot;vấn-đề-trạng-thái-khi-chạy-dài-hơn-đoạn-demo&quot;&gt;Vấn đề trạng thái khi chạy dài hơn đoạn demo&lt;/h3&gt;

&lt;p&gt;Các đoạn nghe thử dài 3 giây che giấu hoàn toàn hiện tượng trôi trạng thái GRU. Với hop 10 ms, một cuộc gọi 45 phút tương ứng \(45\times 60\times 100=270\,000\) bước cập nhật liên tiếp. Sai số lượng tử hóa, cổng hồi tiếp kém ổn định hoặc các khoảng lặng kéo dài ngoài phân bố huấn luyện có thể đẩy trạng thái ẩn lệch dần, gây ra nhiễu nhạc tăng chậm hoặc giọng nói bị suy hao dần theo thời gian thay vì lỗi tức thời tại \(t=0\). Trong khi Fast-ULCNet thường được nhắc đến trong chủ đề này, bạn có thể áp dụng ngay các phép kiểm tra kỹ thuật độc lập sau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Trong các khoảng lặng đã phát hiện, kéo mượt trạng thái GRU về 0 dần trong vài trăm mili giây thay vì đặt về 0 đột ngột trong một hop (đặt 0 cứng sẽ gây click hoặc lọt nhiễu như bài 05-04).&lt;/li&gt;
  &lt;li&gt;Giới hạn chuẩn (norm) của vector trạng thái nếu kiến trúc cho phép mà không làm sai lệch độ lợi.&lt;/li&gt;
  &lt;li&gt;Ghi biểu đồ phân bố (histogram) độ lợi tại phút thứ 1 và phút thứ 40 với cùng mức tín hiệu vào — sự dịch chuyển rõ rệt là dấu hiệu trôi trạng thái.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-tự-tính-tay-sự-tách-rời-macrtf-và-cơ-chế-tích-lũy-trôi-trạng-thái&quot;&gt;Giải thích: Tự tính tay sự tách rời MAC/RTF và cơ chế tích lũy trôi trạng thái&lt;/h2&gt;

&lt;p&gt;Hãy kiểm chứng hai hiện tượng cốt lõi của bài bằng hai phép tính ngắn gọn trên giấy.&lt;/p&gt;

&lt;h3 id=&quot;phép-tính-1-vì-sao-gmac-tăng-23-mà-rtf-lại-giảm-gần-3-lần&quot;&gt;Phép tính 1: Vì sao GMAC tăng 2,3% mà RTF lại giảm gần 3 lần?&lt;/h3&gt;
&lt;p&gt;Lấy đúng hai hàng số liệu công bố của DeepFilterNet2 trên cùng CPU Core i5-8250U:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bản DF ICASSP:&lt;/strong&gt; \(\text{GMAC}_1 = 0{,}348\), \(\text{RTF}_1 = 0{,}11 \implies\) mỗi hop 10 ms mất \(T_1 = 0{,}11 \times 10 = 1{,}10\text{ ms}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bản DF2 tinh gọn:&lt;/strong&gt; \(\text{GMAC}_2 = 0{,}356\) (tăng \(\frac{0{,}356 - 0{,}348}{0{,}348} \approx +2{,}3\%\)), nhưng \(\text{RTF}_2 = 0{,}04 \implies\) mỗi hop 10 ms chỉ mất \(T_2 = 0{,}04 \times 10 = 0{,}40\text{ ms}\) (&lt;strong&gt;nhanh hơn \(2{,}75\times\)&lt;/strong&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lý do nằm ở &lt;strong&gt;cường độ số học (arithmetic intensity)&lt;/strong&gt;: giả sử một nhân CPU có thông lượng thực dụng \(40\text{ GMAC/s}\) và băng thông cache/RAM hiệu dụng \(20\text{ GB/s}\). Nếu một lớp nhỏ phải đọc-ghi \(160\text{ KB}\) tensor trung gian (vòng đệm activation của kernel \(2\times 3\)) chỉ để thực hiện \(50\,000\) MAC:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Thời gian tính toán thuần: \(\frac{50\,000}{40\times 10^9} = 1{,}25\,\mu\text{s}\).&lt;/li&gt;
  &lt;li&gt;Thời gian di chuyển bộ nhớ: \(\frac{160\,000\text{ B}}{20\times 10^9\text{ B/s}} = 8{,}00\,\mu\text{s}\) — &lt;strong&gt;chậm gấp \(6{,}4\) lần thời gian tính toán!&lt;/strong&gt;
Chỉ cần rút kernel từ \(2\times 3\) xuống \(1\times 3\) và hợp nhất lớp (operator fusion) để giữ activation trong thanh ghi, ta cắt mạnh vế bộ nhớ \(8{,}00\,\mu\text{s}\) dù tổng số MAC gần như không giảm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phép-tính-2-sai-số-lượng-tử-hóa-tí-hon-varepsilon--10-4-tích-lũy-thành-trôi-trạng-thái-ra-sao&quot;&gt;Phép tính 2: Sai số lượng tử hóa tí hon \(\varepsilon = 10^{-4}\) tích lũy thành trôi trạng thái ra sao?&lt;/h3&gt;
&lt;p&gt;Mô hình hóa một chiều trạng thái ẩn GRU trong khoảng lặng kéo dài bằng phương trình sai phân tuyến tính hóa:
\(h_t = a\,h_{t-1} + \varepsilon,\)
với hệ số giữ trạng thái \(a = 0{,}999\) (cổng cập nhật rất nhỏ để nhớ ngữ cảnh dài) và sai số làm tròn/lượng tử hóa mỗi bước \(\varepsilon = 10^{-4}\), khởi đầu \(h_0 = 0\).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Sau đoạn demo 3 giây (\(t = 300\) hop ở hop 10 ms):
\(h_{300} = \varepsilon\,\frac{1 - a^{300}}{1 - a} = 10^{-4} \cdot \frac{1 - 0{,}999^{300}}{0{,}001} \approx 0{,}1 \times (1 - 0{,}741) = 0{,}0259.\)
Giá trị nhỏ này hầu như chưa gây méo đáng kể khi nghe thử 3 giây.&lt;/li&gt;
  &lt;li&gt;Sau 1 phút (\(t = 6\,000\) hop) và kéo dài tới phút thứ 45 (\(t = 270\,000\) hop): vì \(0{,}999^{6000} \approx 0{,}0025 \to 0\), trạng thái tiến tới giới hạn lệch:
\(h_\infty = \frac{\varepsilon}{1 - a} = \frac{10^{-4}}{10^{-3}} = 0{,}1000\)
— lớn gấp &lt;strong&gt;1.000 lần&lt;/strong&gt; sai số một bước! Nếu hệ số giữ \(a = 0{,}9995\), độ lệch tăng gấp đôi lên \(0{,}20\), đủ đẩy đầu ra cổng sigmoid dịch khỏi vùng hiệu chuẩn và làm mờ giọng nói khi người dùng bắt đầu nói lại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;khi-nào-nhánh-deepfilternet3-vẫn-là-lựa-chọn-phù-hợp&quot;&gt;Khi nào nhánh DeepFilterNet3 vẫn là lựa chọn phù hợp&lt;/h3&gt;

&lt;p&gt;Hãy ưu tiên mô hình thuộc nhánh DeepFilterNet3 trên trình duyệt laptop khi WASM SIMD giữ vững ngân sách hop và kích thước trọng số vài megabyte là chấp nhận được. Ngược lại, hãy cân nhắc nhóm siêu nhẹ cho chip DSP hoặc CPU rất yếu nơi chấp nhận một phần nhiễu dư. Một phương án phân tầng hợp lý là dùng AEC cổ điển kết hợp bộ khử dư siêu nhẹ trên thiết bị nhúng, và dùng DF3 trên trình duyệt. Lưu ý không đưa trực tiếp trọng số 16 kHz vào đồ thị 48 kHz rồi coi đó là “DF3 bản nhẹ” — luôn phải lấy mẫu lại có chủ đích.&lt;/p&gt;

&lt;h2 id=&quot;danh-mục-kiểm-tra-cho-danh-sách-rút-gọn&quot;&gt;Danh mục kiểm tra cho danh sách rút gọn&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Đồ thị có nhân quả không và cần bao nhiêu khung nhìn trước?&lt;/li&gt;
  &lt;li&gt;Hoạt động ở 16 kHz hay 48 kHz, và bộ lấy mẫu lại đặt ở đâu?&lt;/li&gt;
  &lt;li&gt;Phân vị p95 của RTF trên &lt;strong&gt;đúng thiết bị đích&lt;/strong&gt; (đơn luồng, cache nóng, theo nhịp callback).&lt;/li&gt;
  &lt;li&gt;Dung lượng trọng số và thời gian khởi động lạnh (tách biệt khỏi RTF).&lt;/li&gt;
  &lt;li&gt;Kết quả chạy thử liên tục ít nhất 30 phút có xen lẫn khoảng lặng.&lt;/li&gt;
  &lt;li&gt;Giấy phép sử dụng của bộ trọng số.&lt;/li&gt;
  &lt;li&gt;Mọi toán tử trong đồ thị đều được hỗ trợ bởi phiên bản ONNX Runtime hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; đang dùng.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Chọn mô hình triển khai chỉ dựa trên cột MAC nhỏ nhất.&lt;/li&gt;
  &lt;li&gt;Chuyển đổi các lớp tích chập nhóm mà runtime WASM lại thực thi bằng vòng lặp vô hướng (scalar).&lt;/li&gt;
  &lt;li&gt;Bỏ qua bài kiểm tra ổn định liên tục 30 phút.&lt;/li&gt;
  &lt;li&gt;Đưa dữ liệu PCM 48 kHz trực tiếp vào mô hình có lưới STFT huấn luyện ở 16 kHz.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Kiểm chứng hiện tượng “GMAC xấp xỉ nhau nhưng RTF chênh lệch lớn” từ bảng số liệu công bố của DeepFilterNet2, sau đó áp dụng tiêu chí chọn theo p95 RTF trên một cặp mô hình giả định.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
# Numbers from the DeepFilterNet2 paper&apos;s Voicebank table (notebook i5).
rows = [
    (&quot;DF ICASSP row&quot;, 0.348, 0.11),
    (&quot;DF2 simplified&quot;, 0.356, 0.04),
]
for name, gmac, rtf in rows:
    print(f&quot;{name}: gmac={gmac:.3f} rtf={rtf:.2f} rtf_per_gmac={rtf/gmac:.3f}&quot;)
# Hypothetical shortlist. These MACs are lab fiction, not paper results.
fake = [(&quot;modelA&quot;, 0.05, 0.30), (&quot;modelB&quot;, 0.08, 0.12)]
best = min(fake, key=lambda r: r[2])
print(&quot;lower_p95_rtf&quot;, best[0])
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DF ICASSP row: gmac=0.348 rtf=0.11 rtf_per_gmac=0.316&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DF2 simplified: gmac=0.356 rtf=0.04 rtf_per_gmac=0.112&lt;/code&gt;, và cuối cùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lower_p95_rtf modelB&lt;/code&gt;. Dù &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;modelB&lt;/code&gt; có số MAC cao hơn, nó vẫn thắng vì đạt RTF thực tế thấp hơn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Nhầm cặp số giả định là kết quả thực của GTCRN hay FastEnhancer; dùng RTF 0,04 của laptop cho điện thoại; hoặc chỉ xếp hạng theo tỷ số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf_per_gmac&lt;/code&gt; trong khi phân vị p95 lại vượt hạn hop.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chọn kiến trúc theo thiết bị.&lt;/strong&gt; Với ba môi trường: DSP tai nghe, Chrome trên laptop tầm trung và thiết bị loa họp cỡ Raspberry Pi, hãy chọn DF3 hoặc “một mô hình siêu nhẹ” và giải thích lý do ngân sách trong một câu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thiết kế bài đo hiệu năng.&lt;/strong&gt; Xác định số hop warm-up, độ dài hop và phân vị dùng làm ngưỡng đạt/không đạt; giải thích vì sao không dùng giá trị trung bình làm ngưỡng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính toán trôi trạng thái.&lt;/strong&gt; Với hop 10 ms trong cuộc gọi 40 phút, mạng GRU thực hiện bao nhiêu lần cập nhật? Cần so sánh đại lượng nào giữa đầu và cuối phiên chạy?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định vị danh mục.&lt;/strong&gt; Viết đúng một câu mô tả vai trò cho từng cái tên GTCRN, FastEnhancer, μNet và Fast-ULCNet mà không kèm con số hay năm xuất bản.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;DSP tai nghe: chọn mô hình siêu nhẹ vì RTF 0,04 của DF2 đo trên Core i5; Chrome trên laptop: chọn DF3 nếu WASM SIMD giữ p95 gọn trong hop và kích thước tải chấp nhận được; bo mạch cỡ Raspberry Pi: bài báo DF2 nêu khả năng chạy thời gian thực trên Pi 4 cho chính mô hình đó, còn mô hình siêu nhẹ là phương án dự phòng nếu p95 bản biên dịch thực tế không đạt.&lt;/li&gt;
  &lt;li&gt;Bỏ qua 50 hop đầu để làm nóng cache, chọn hop = 10 ms = 0,01 s, và đặt ngưỡng trên p95 (đồng thời theo dõi p99) vì giá trị trung bình che giấu các khung trễ gây underrun (Chương 05).&lt;/li&gt;
  &lt;li&gt;Tổng số bước cập nhật là \(40\times 60\times 100=240\,000\) lần. Hãy so sánh histogram độ lợi băng tần hoặc chuẩn của vector trạng thái trên cùng một đoạn âm thanh hiệu chuẩn lặp lại, thay vì so trực tiếp hai dạng sóng khác nhau.&lt;/li&gt;
  &lt;li&gt;Chỉ sử dụng phần mô tả vai trò một dòng trong bảng ở trên; việc thêm số liệu cụ thể khi chưa đọc tài liệu gốc đồng nghĩa với suy đoán.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter et al., DeepFilterNet2, &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt; — đối chiếu hai hàng RTF 0,11 và 0,04 minh họa sự tách rời giữa MAC và RTF.&lt;/li&gt;
  &lt;li&gt;Schröter et al., Interspeech 2023, &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt; — số đo RTF 0,19 của bản &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Valin, &lt;a href=&quot;https://arxiv.org/abs/1709.08243&quot;&gt;arXiv:1709.08243&lt;/a&gt; — mốc đối chiếu kiến trúc lai nhỏ gọn (bài 04-06).&lt;/li&gt;
  &lt;li&gt;Các tài liệu gốc bạn tự tra cứu cho GTCRN, FastEnhancer, μNet và Fast-ULCNet (bài này cố ý không gắn đường dẫn).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nsscrYdrGRE&quot;&gt;RNNoise, Neural Speech Enhancement, and the Browser&lt;/a&gt; — W3C, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Minh họa một bộ khử nhiễu đủ gọn cho trình duyệt và Raspberry Pi — đúng bài toán ngân sách của nhóm streaming siêu nhẹ.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Biểu đồ đánh đổi giữa độ phức tạp và chất lượng làm rõ tiêu chuẩn mà các mô hình siêu nhẹ phải đáp ứng.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nhTxJBgTywc&quot;&gt;Zoom on Web: getting connected with advanced web technology&lt;/a&gt; — Chrome for Developers, tiếng Anh. Phần nói về SIMD giải thích vì sao ngay cả mô hình rất nhỏ vẫn cần runtime vector hóa khi hop chỉ dài vài mili giây.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-04 Khảo sát kế tục: DPDFNet, DeepFilterGAN, HDF-Net</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_04_successors_survey/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_04_successors_survey</id>
   <content type="html">&lt;p&gt;DPDFNet, DeepFilterGAN và HDF-Net trong khóa học này chỉ đóng vai trò &lt;strong&gt;các điểm neo khảo sát (survey pointers)&lt;/strong&gt;. Bài học này cố ý không gán tiêu đề bài báo, năm xuất bản, hội nghị hay liên kết URL cho ba tên gọi đó: khi chưa trực tiếp mở đọc tệp PDF gốc, ta chưa có thông tin thư mục hợp lệ và không được suy đoán. Trọng tâm của buổi học là đặt các hướng phát triển kế tục bên cạnh khung kiến trúc ERB + deep filter để đánh giá xem một bản triển khai DeepFilterNet3 có thực sự cần thay đổi hay không.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;Bộ xương ERB cộng deep filter mà mọi tên kế tục vẫn phải thắng trên RTF và lượt nghe&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. DPDFNet, DeepFilterGAN và HDF-Net chỉ là các tên gọi khảo sát trong danh sách đọc, không phải checkpoint tải trực tiếp từ bài học này. Mọi phương án thay thế đều phải duy trì bước nhảy hop STFT nhân quả, kích thước trạng thái bị chặn và hệ số RTF dưới 1 trên CPU đích.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Trong nghiên cứu học sâu cho âm thanh, hầu như mỗi tháng đều xuất hiện một cái tên kiến trúc mới hứa hẹn nhích thêm \(0{,}05\) điểm PESQ hay \(0{,}2\text{ dB}\) SI-SDR trên bảng xếp hạng. Nhưng dưới góc nhìn của một kỹ sư hệ thống đang vận hành sản phẩm thời gian thực (như bộ lọc nhiễu trên trình duyệt hay ứng dụng gọi thoại), &lt;strong&gt;một cái tên mới trên bảng benchmark chưa bao giờ tự động trở thành lý do để thay mô hình đang chạy ổn định&lt;/strong&gt;. Bài khảo sát này giúp bạn xây dựng “bộ lọc tư duy kỹ thuật” khi đứng trước các hướng kế tục xoay quanh họ DeepFilterNet — như kiến trúc hai đường (dual-path), huấn luyện đối nghịch (GAN) hay lọc phân cấp (hierarchical) — dựa trên ba thước đo không biết nói dối: ngân sách RTF, độ trễ thuật toán và tính tương thích thực thi ONNX/AudioWorklet.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-hướng-mở-rộng-kiến-trúc-và-chi-phí-kỹ-thuật-đi-kèm&quot;&gt;Kiến thức cần nhớ: Ba hướng mở rộng kiến trúc và chi phí kỹ thuật đi kèm&lt;/h2&gt;

&lt;h3 id=&quot;1-hai-đường-thời-giantần-số-dual-path-thời-gian--tần-số&quot;&gt;1. Hai đường thời gian–tần số (Dual-Path: Thời gian + Tần số)&lt;/h3&gt;
&lt;p&gt;Các mạng RNN/GRU chuẩn trong DeepFilterNet quét mạnh theo trục thời gian, còn trục tần số chủ yếu xử lý bằng tích chập cục bộ. Tư duy &lt;strong&gt;Dual-Path&lt;/strong&gt; (như trong các biến thể kiểu DPDFNet) luân phiên quét dọc theo &lt;em&gt;trục tần số&lt;/em&gt; (để nắm bắt quan hệ họa âm cách xa nhau trên cùng một khung) rồi quét dọc theo &lt;em&gt;trục thời gian&lt;/em&gt; (để bám quỹ đạo giọng nói). Lợi ích là nắm bắt cấu trúc họa âm toàn cục tốt hơn, nhưng cái giá phải trả là thêm nhiều lớp tuần tự/chú ý trên mỗi khung, dễ đội RTF và làm tăng số toán tử khó tối ưu trên WebAssembly/ONNX Runtime.&lt;/p&gt;

&lt;h3 id=&quot;2-huấn-luyện-đối-nghịch-gan--chi-phí-0-lúc-suy-luận-nhưng-rủi-ro-ảo-giác&quot;&gt;2. Huấn luyện đối nghịch (GAN) — chi phí 0 lúc suy luận nhưng rủi ro “ảo giác”&lt;/h3&gt;
&lt;p&gt;Ý tưởng của các nhánh kiểu &lt;strong&gt;DeepFilterGAN&lt;/strong&gt; là giữ một bộ sinh (Generator) gọn nhẹ để chạy lúc suy luận, còn bộ phân biệt (Discriminator — ví dụ phân biệt phổ đa thang đo) chỉ tồn tại &lt;em&gt;lúc huấn luyện&lt;/em&gt; nhằm ép âm thanh đầu ra nghe sắc nét, giống tiếng người thật thay vì bị mờ đục do hàm mất mát MSE. Điểm cộng tuyệt vời là &lt;strong&gt;không tăng thêm RTF lúc triển khai&lt;/strong&gt; nếu giữ nguyên bộ sinh; điểm trừ là mô hình GAN có thể sinh ra các thành phần tần số cao giả hoặc méo nhẹ ở tình huống ngoài phân bố (OOD), đòi hỏi kiểm thử nghe mù kỹ lưỡng.&lt;/p&gt;

&lt;h3 id=&quot;3-lọc-phân-cấp-hierarchical-và-nguyên-tắc-kỷ-luật-thư-mục-khoa-học&quot;&gt;3. Lọc phân cấp (Hierarchical) và nguyên tắc kỷ luật thư mục khoa học&lt;/h3&gt;
&lt;p&gt;Các hướng lọc phân cấp (kiểu HDF-Net) chia bài toán khử nhiễu theo nhiều mức độ phân giải hoặc nhiều chặng tinh chỉnh liên tiếp. Tuy nhiên, mỗi tầng tinh chỉnh bổ sung đều có nguy cơ cộng thêm khung nhìn trước (&lt;em&gt;look-ahead&lt;/em&gt;) hoặc tăng dung lượng trạng thái cần giữ trong bộ nhớ cache. Quan trọng không kém về mặt học thuật: bài học này rèn thói quen &lt;strong&gt;kỷ luật trích dẫn&lt;/strong&gt; — chỉ ghi nhận con số, năm xuất bản và cấu trúc khi đã tự tay mở đọc bài báo gốc, tuyệt đối không suy đoán từ tên gọi.&lt;/p&gt;

&lt;h3 id=&quot;giải-thích-cầm-tay-tính-ngân-sách-độ-phức-tạp-và-quyết-định-đổi-hay-giữ-trong-audioworklet&quot;&gt;Giải thích: Cầm tay tính ngân sách độ phức tạp và quyết định “Đổi hay Giữ” trong AudioWorklet&lt;/h3&gt;

&lt;p&gt;Giả sử bạn đang vận hành một luồng âm thanh \(48\text{ kHz}\) với hop \(H = 10\text{ ms}\) trong trình duyệt (AudioWorklet + WASM/ONNX). Để đảm bảo không bao giờ giật tiếng (buffer underrun) trên laptop tầm trung khi còn chạy kèm WebRTC AEC và video, đội kỹ thuật đặt trần an toàn:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Thời gian suy luận tối đa mỗi khung: \(T_{\max} = 2{,}5\text{ ms}\) (tương ứng \(\mathrm{RTF} \le 0{,}25\)).&lt;/li&gt;
  &lt;li&gt;Tổng độ trễ thuật toán tối đa: \(L_{\max} = 40\text{ ms}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ta đặt lên bàn cân một phép tính nhanh cho 3 kịch bản nâng cấp giả định so với nền &lt;strong&gt;DeepFilterNet3&lt;/strong&gt; (đang chạy \(T_{\text{base}} = 0{,}8\text{ ms/khung}\), \(\mathrm{RTF} = 0{,}08\), độ trễ \(40\text{ ms}\)):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Kịch bản nâng cấp&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Phép tính chi phí cốt lõi&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Thời gian / khung ước tính&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Độ trễ thuật toán&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Quyết định kỹ thuật&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;1. Thêm Self-Attention toàn cục dọc \(F = 96\) bin (Dual-Path ngây thơ)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Số cặp tương tác mỗi khung tăng từ \(O(F) = 96\) lên \(O(F^2) = 96^2 = 9\,216\) (gấp \(96\times\) tương tác)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Giả sử đội \(3\times \to 2{,}4\text{ ms}\) (\(\mathrm{RTF}=0{,}24\))&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(40\text{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Rủi ro cao&lt;/strong&gt; — sát trần \(2{,}5\text{ ms}\), dễ rớt khung khi CPU bận&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;2. Huấn luyện lại Generator cũ bằng Discriminator (hướng GAN)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Discriminator bỏ hoàn toàn khi xuất ONNX \(\implies +0\text{ ms}\) suy luận&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0{,}8\text{ ms}\) (\(\mathrm{RTF}=0{,}08\))&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(40\text{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Đáng thử&lt;/strong&gt; — miễn là vượt qua bài nghe mù không sinh lỗi giả&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;3. Thêm 1 tầng tinh chỉnh phân cấp cần thêm \(1\) khung nhìn trước&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Độ trễ cộng thêm \(+1 \times H = +10\text{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Giả sử \(1{,}3\text{ ms}\) (\(\mathrm{RTF}=0{,}13\))&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(40 + 10 = 50\text{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Vượt trần độ trễ&lt;/strong&gt; \(L_{\max} = 40\text{ ms}\) — cần cân nhắc kỹ với VoIP&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Bảng tính gọn này minh họa một nguyên tắc vàng của kỹ thuật âm thanh thực chiến: &lt;strong&gt;chỉ chuyển đổi mô hình khi bạn chứng minh được bằng con số rằng nó sửa được một lỗi nghe tái hiện được mà không phá vỡ trần RTF và độ trễ của sản phẩm&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ tóm tắt được trọng tâm nghiên cứu gắn với từng cái tên DPDFNet, DeepFilterGAN và HDF-Net; tuân thủ nguyên tắc không trích dẫn tiêu đề hay năm xuất bản nếu chưa đọc trực tiếp PDF; và ra quyết định triển khai, theo dõi hay bỏ qua dựa trên RTF, khả năng hỗ trợ toán tử ONNX và một lỗi nghe tái hiện được.&lt;/p&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Vì sao một tên mô hình mới chưa phải là kế hoạch chuyển đổi (migration).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Mẫu thẻ đọc bốn ô: chỉ ghi nhận những gì kiểm chứng được từ tài liệu gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Chi phí thực tế của “dual-path”, “tầng GAN” và “bộ lọc phân cấp” bên trong AudioWorklet.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Hiện tượng suy hao quá mức (over-attenuation) như một lỗi sản phẩm độc lập.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Mini-lab và quy tắc chuẩn hóa trích dẫn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;phạm-vi-khẳng-định-hợp-lệ-của-một-bài-khảo-sát&quot;&gt;Phạm vi khẳng định hợp lệ của một bài khảo sát&lt;/h3&gt;

&lt;p&gt;Bài 04-02 và 04-03 trích dẫn bảng số liệu vì các bảng đó xuất hiện trực tiếp trong arXiv:2110.05588, arXiv:2205.05474 và arXiv:2305.08227. Bài này không đặt thêm trích dẫn mới mà chỉ định vị ba cái tên trên bản đồ đọc:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;DPDFNet&lt;/strong&gt; — cái tên thường được tra cứu khi cần giải quyết bài toán ngữ cảnh dài và hiện tượng khử quá mức (over-attenuation) trên khung kiểu DeepFilterNet2.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;DeepFilterGAN&lt;/strong&gt; — cái tên thường được tra cứu khi nối thêm một tầng sinh (generative) phía sau tầng dự đoán kiểu DeepFilterNet nhằm khôi phục phần chi tiết giọng nói đã bị xóa.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;HDF-Net&lt;/strong&gt; — cái tên thường được tra cứu khi cơ chế deep filtering được phân tách phân cấp theo thời gian và tần số thay vì dùng một đầu lọc đơn lẻ.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ba mô tả trên chỉ mang tính định hướng tra cứu chứ không phải tóm tắt bài báo, do đó không đi kèm số tham số, độ chênh PESQ, biểu đồ hay đường dẫn. Một số cái tên lân cận (cũng chỉ nêu ở mức định hướng, không trích dẫn) gồm pDeepFilterNet2 (cá nhân hóa theo người nói) và DFingerNet (điều kiện theo dấu vân nhiễu) — hướng cá nhân hóa nằm ngoài phạm vi trừ khi đề tài tổng kết yêu cầu riêng.&lt;/p&gt;

&lt;h3 id=&quot;mẫu-thẻ-đọc-bốn-ô&quot;&gt;Mẫu thẻ đọc bốn ô&lt;/h3&gt;

&lt;p&gt;Với mỗi tệp PDF thực sự mở đọc, hãy ghi nhận đúng bốn mục sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bài toán&lt;/strong&gt; tác giả đo lường (suy hao quá mức, mất họa âm, giới hạn độ trễ).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cơ chế&lt;/strong&gt; theo đúng tên khối được in trong bài báo gốc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khả năng triển khai:&lt;/strong&gt; số lượng tham số (nếu công bố), đồ thị có nhân quả hay không, có thông tin xuất ONNX hoặc đo RTF hay không.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hành động:&lt;/strong&gt; bỏ qua, tiếp tục theo dõi hoặc làm thử nghiệm (prototype) — bản thử nghiệm phải xác định rõ hop, thiết bị đích và đoạn mẫu nghe thử.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nếu mục 3 bị bỏ trống vì bài báo không đề cập đến streaming, hành động chắc chắn không phải là “triển khai”. Các mô hình đứng đầu bảng xếp hạng dùng lớp hồi tiếp hai chiều sẽ không thể chạy trong hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;phân-tích-chi-phí-giả-định-ở-thể-điều-kiện&quot;&gt;Phân tích chi phí giả định (ở thể điều kiện)&lt;/h3&gt;

&lt;p&gt;Phần này dịch ý nghĩa kỹ thuật của &lt;strong&gt;tên kiến trúc&lt;/strong&gt; để ước lượng ngân sách cho một đợt thử nghiệm khảo sát (spike), không phải tóm tắt kết quả từ bài báo gốc.&lt;/p&gt;

&lt;p&gt;Cấu trúc &lt;strong&gt;dual-path&lt;/strong&gt; (gắn với tên DPDFNet) xử lý song song hoặc luân phiên một nhánh theo thời gian và một nhánh theo tần số. Với hop 10 ms, nhánh thời gian bắt buộc phải duy trì trạng thái GRU cố định hoặc chờ thêm các hop tương lai. Chờ thêm 4 hop tương lai đồng nghĩa cộng thêm 40 ms lên trên độ trễ 40 ms đã công bố của DeepFilterNet2, đẩy tổng độ trễ thuật toán lên 80 ms (con số này tách biệt với RTF), đồng thời hai khối GRU có thể làm tăng gấp đôi phân vị p95. Lưu ý rằng hiện tượng suy hao quá mức (như mất các phụ âm xát nhẹ) hoàn toàn có thể kiểm chứng thực tế trên sản phẩm mà không cần chờ bài báo mới.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tầng tái tạo GAN&lt;/strong&gt; (gắn với tên DeepFilterGAN) đặt thêm một mạng thứ hai sau tầng dự đoán. Dù chạy hai phiên ONNX hay gộp thành một đồ thị, hệ thống đều gánh thêm chi phí MAC và khó bảo đảm tính tất định trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt;. Trên bề mặt gói npm hiện có, cường độ khử đã có thể điều chỉnh qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt; — hãy thử hạ mức khử trước khi tính đến việc bổ sung mạng GAN.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deep filter phân cấp&lt;/strong&gt; (gắn với tên HDF-Net) vẫn dựa trên phép lọc phức dạng:&lt;/p&gt;

\[\hat{S}(t,f)=\sum_{i} W_i(t,f)\,X(t-i+\ell,f),\]

&lt;p&gt;nhưng tách thành nhiều đầu lọc. Riêng 5 tap trên 96 bin đã tiêu tốn 480 phép nhân phức mỗi khung (bài 04-02); một đầu lọc bổ sung theo trục tần số có thể kết hợp thêm các bin lân cận, còn tính nhân quả cụ thể phải kiểm tra trực tiếp trên sơ đồ của bài báo gốc.&lt;/p&gt;

&lt;h3 id=&quot;phân-loại-sản-phẩm-dựa-trên-mốc-df3-đã-kiểm-chứng&quot;&gt;Phân loại sản phẩm dựa trên mốc DF3 đã kiểm chứng&lt;/h3&gt;

&lt;p&gt;Bảng số liệu duy nhất của DeepFilterNet3 được trích dẫn trong khóa là kết quả Voicebank+Demand từ arXiv:2305.08227: PESQ 3,17, CSIG 4,34, CBAK 3,61, COVL 3,77 và STOI 0,944 (so với PESQ 3,08 của DF2), cùng các số đo RTF đã công bố là 0,04 (DF2 trên laptop Core i5) và 0,19 (bản &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; năm 2023 trên i5-8250U). Một kiến trúc kế tục chỉ đáng đầu tư thử nghiệm khi tệp âm thanh sản phẩm bộc lộ lỗi mà các checkpoint trên không xử lý được, đồng thời đồ thị nhân quả vẫn đáp ứng kịp hop 10 ms (nhớ rằng quantum 2,67 ms là đơn vị callback, không phải ngân sách hop).&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tên&lt;/th&gt;
      &lt;th&gt;Ý tưởng định hướng&lt;/th&gt;
      &lt;th&gt;Triển khai từ bài này?&lt;/th&gt;
      &lt;th&gt;Lý do&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;DPDFNet&lt;/td&gt;
      &lt;td&gt;Ngữ cảnh dual-path; thường tra cứu cho lỗi suy hao quá mức&lt;/td&gt;
      &lt;td&gt;Không&lt;/td&gt;
      &lt;td&gt;Chưa có tiêu đề, năm xuất bản hay URL kiểm chứng trong bài&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DeepFilterGAN&lt;/td&gt;
      &lt;td&gt;Tầng dự đoán nối tiếp tầng sinh&lt;/td&gt;
      &lt;td&gt;Không&lt;/td&gt;
      &lt;td&gt;Phát sinh mạng thứ hai; chưa rõ RTF và tính tất định khi chưa đọc gốc&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;HDF-Net&lt;/td&gt;
      &lt;td&gt;Deep filter phân cấp&lt;/td&gt;
      &lt;td&gt;Không&lt;/td&gt;
      &lt;td&gt;Tương tự trên&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mốc DeepFilterNet3&lt;/td&gt;
      &lt;td&gt;32 băng ERB + bộ lọc 5 tap (trích dẫn 2023 trong README)&lt;/td&gt;
      &lt;td&gt;Có (làm mốc chuẩn khóa học)&lt;/td&gt;
      &lt;td&gt;Số liệu kiểm chứng đầy đủ ở bài 04-03&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Các tầng tiền xử lý không gian ở Chương 03 (GSC hoặc IVA nối vào bộ tăng cường đơn kênh) thuộc một hướng mở rộng khác vì chúng thay đổi số lượng micro; chúng ở mức kiến trúc lai tham khảo, không phải lý do để loại bỏ DF3.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Viết lại toàn bộ đồ thị ONNX chỉ sau khi đọc lướt phần tóm tắt (abstract).&lt;/li&gt;
  &lt;li&gt;Tự điền tiêu đề, năm xuất bản hoặc mã arXiv theo trí nhớ cho DPDFNet, DeepFilterGAN hay HDF-Net.&lt;/li&gt;
  &lt;li&gt;Cho rằng bổ sung tầng GAN vẫn giữ nguyên được phân vị p95 của tầng dự đoán ban đầu.&lt;/li&gt;
  &lt;li&gt;Đưa vào một toán tử lọc tùy biến mà &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; hoặc ONNX Runtime WASM không hỗ trợ rồi mới phát hiện lỗi trên luồng âm thanh.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Khởi tạo mẫu thẻ bốn ô với mọi trường chưa kiểm chứng để giá trị trống (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;None&lt;/code&gt;) nhằm ngăn việc điền thông tin trích dẫn suy đoán.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
names = [&quot;DPDFNet&quot;, &quot;DeepFilterGAN&quot;, &quot;HDF-Net&quot;]
# Fill only from a PDF you opened. Leave unknown fields as None.
cards = {
    name: {&quot;problem&quot;: None, &quot;mechanism&quot;: None, &quot;params&quot;: None,
           &quot;causal&quot;: None, &quot;url&quot;: None, &quot;year&quot;: None, &quot;title&quot;: None}
    for name in names
}
for name, card in cards.items():
    missing = [k for k, v in card.items() if v is None]
    print(f&quot;{name}: missing={missing}&quot;)
print(&quot;survey_pointers_only=True&quot;)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Mỗi cái tên đều in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;missing=[&apos;problem&apos;, &apos;mechanism&apos;, &apos;params&apos;, &apos;causal&apos;, &apos;url&apos;, &apos;year&apos;, &apos;title&apos;]&lt;/code&gt; cho đến khi bạn tự điền từ tệp PDF đã mở, và dòng cuối in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;survey_pointers_only=True&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Chép tiêu đề hoặc năm từ đoạn trích tìm kiếm mà chưa mở bài gốc; điền &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;params&lt;/code&gt; bằng con số không có trong PDF; coi trường &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;causal&lt;/code&gt; bỏ trống là “đủ nhân quả”; hoặc gắn các đường dẫn chưa được kiểm chứng.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Điền thẻ bốn ô.&lt;/strong&gt; Sau khi tự tìm và mở đọc từng tệp PDF gốc, hãy điền đầy đủ bốn ô; nếu không tiếp cận được tệp gốc thì để trống và ghi rõ lý do.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng suy hao quá mức không cần bài báo.&lt;/strong&gt; Ghi âm 10 giây chứa các phụ âm xát nhẹ (như “see”, “fish”) ở hai mức âm lượng vừa và nhỏ, cho chạy qua đường DF3 tại mức &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; 30 và 90, rồi mô tả sự khác biệt nghe thấy trong hai câu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ngân sách độ trễ.&lt;/strong&gt; Nếu một khối dual-path cần chờ thêm 4 hop dài 10 ms chồng lên độ trễ 40 ms đã công bố của DeepFilterNet2, tổng độ trễ thuật toán là bao nhiêu và tổng đó có phải là RTF không?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bản ghi nhớ kỹ thuật.&lt;/strong&gt; Trong tối đa 150 từ, đề xuất với trưởng nhóm kỹ thuật nên giữ nguyên mốc DF3 hay mở một đợt thử nghiệm đọc tài liệu; chỉ được phép trích dẫn arXiv:2110.05588, arXiv:2205.05474 và arXiv:2305.08227.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Một thẻ để trống trung thực có giá trị hơn một tiêu đề suy đoán; phần cơ chế phải dùng đúng thuật ngữ xuất hiện trong PDF gốc.&lt;/li&gt;
  &lt;li&gt;Bạn sẽ nghe thấy sự khác biệt rõ ở việc phụ âm nhẹ bị cắt mất hoặc phần đuôi âm bị khô/bơm chứ không phải một con số MOS; tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; nằm trên thang 0–100, không phải giá trị dB trong bài báo.&lt;/li&gt;
  &lt;li&gt;Tổng độ trễ thuật toán là \(40+4\times 10=80\) ms nếu khối đó bổ sung thêm look-ahead; RTF là tỷ số thời gian xử lý thực tế trên thời lượng âm thanh nên có thể bằng 0,2 hoặc 1,4 hoàn toàn độc lập với mốc 80 ms.&lt;/li&gt;
  &lt;li&gt;Mốc chuẩn có cơ sở bảo vệ là kết quả DF3 từ trích dẫn năm 2023 cùng các thông số 40 ms và RTF đã công bố; đợt thử nghiệm nên giới hạn ở việc đọc tài liệu gốc và chạy kiểm thử khói (smoke test) đồ thị ONNX nhân quả, không viết lại hệ thống ngay.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Bài 04-02 và 04-03 cùng ba nguồn đã kiểm chứng: &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt; và &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Các tệp PDF gốc bạn tự tra cứu cho DPDFNet, DeepFilterGAN và HDF-Net (bài học này cố ý không gắn đường dẫn cho chúng).&lt;/li&gt;
  &lt;li&gt;Chương 05 cho các ràng buộc RTF và AudioWorklet mà mọi kiến trúc kế tục đều phải đáp ứng.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày khung ERB + deep filter dùng làm mốc so sánh với các mô hình kế tục trong bài.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Phần dữ liệu, nghe thử và độ phức tạp cung cấp khung phương pháp so sánh khách quan trước khi quyết định nâng cấp mô hình.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-03 DeepFilterNet2 và DeepFilterNet3</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_03_deepfilternet2_3/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_03_deepfilternet2_3</id>
   <content type="html">&lt;p&gt;DeepFilterNet2 và DeepFilterNet3 giữ nguyên kiến trúc hai tầng gồm độ lợi ERB kết hợp deep filter, đồng thời cải tiến hàm mất mát huấn luyện, dung lượng bộ đệm thời gian, bổ sung bộ hậu lọc (post-filter) và cổng điều khiển theo SNR. Bài học này chỉ sử dụng các số liệu công bố trong arXiv:2205.05474 và arXiv:2305.08227, không suy đoán tên khối chưa công bố và không khẳng định gói npm khớp từng bit với các checkpoint trong bài báo.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;Cùng bộ xương ERB cộng deep filter qua các thế hệ DeepFilterNet&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Khung kiến trúc cốt lõi được giữ nguyên qua các thế hệ: 32 độ lợi ERB cho đường bao phổ, theo sau bởi bộ lọc phức 5 tap trên các bin thấp của STFT. Các thay đổi công bố giữa các phiên bản nằm ở hàm mất mát và dữ liệu (STFT đa phân giải, DNS4, post-filter), giảm bộ đệm thời gian trong mạng và bổ sung cổng SNR để tắt tầng xử lý khi không cần thiết.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Một kiến trúc học sâu hiếm khi dừng lại ở phiên bản đầu tiên. Sau bài báo ICASSP 2022 chứng minh ý tưởng ERB + Deep Filter hoạt động tốt, nhóm tác giả của DeepFilterNet đối mặt với câu hỏi khắc nghiệt hơn của kỹ thuật triển khai thực tế: &lt;em&gt;làm sao để mô hình chạy nhanh gấp nhiều lần trên CPU phổ thông, không bị méo khi gặp khoảng lặng hoàn toàn, và nghe tự nhiên hơn trên dữ liệu thực tế?&lt;/em&gt; Câu trả lời mang tên &lt;strong&gt;DeepFilterNet2&lt;/strong&gt; (2022) và &lt;strong&gt;DeepFilterNet3&lt;/strong&gt; (Interspeech 2023) — hai bản nâng cấp giữ nguyên bộ xương hai tầng sáng giá, nhưng tinh chỉnh sắc sảo từng khớp nối từ tầng tính toán nhóm, bộ hậu lọc cho tới cổng điều khiển theo SNR.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-trụ-cột-tiến-hóa-từ-deepfilternet1-sang-2-và-3&quot;&gt;Kiến thức cần nhớ: Ba trụ cột tiến hóa từ DeepFilterNet1 sang 2 và 3&lt;/h2&gt;

&lt;h3 id=&quot;1-tối-ưu-hóa-tính-toán-thời-gian-thực-grouped-linear--gru--giảm-bộ-đệm&quot;&gt;1. Tối ưu hóa tính toán thời gian thực (Grouped Linear / GRU &amp;amp; giảm bộ đệm)&lt;/h3&gt;
&lt;p&gt;Các lớp tuyến tính dày đặc và GRU kích thước lớn là nút thắt cổ chai lớn nhất trên CPU đơn luồng. DeepFilterNet2 tái cấu trúc các lớp tuyến tính và GRU theo dạng &lt;strong&gt;nhóm (grouped)&lt;/strong&gt; kết hợp rút gọn kích thước trạng thái/bộ đệm thời gian, giúp kéo hệ số thời gian thực (RTF) xuống mức công bố chỉ khoảng \(0{,}04\) trên CPU hiện đại — nghĩa là chỉ dùng \(4\%\) thời gian của một nhân CPU để xử lý luồng \(48\text{ kHz}\)!&lt;/p&gt;

&lt;h3 id=&quot;2-hàm-mất-mát-đa-phân-giải-và-bộ-hậu-lọc-post-filter&quot;&gt;2. Hàm mất mát đa phân giải và Bộ hậu lọc (Post-Filter)&lt;/h3&gt;
&lt;p&gt;Huấn luyện chỉ trên một độ phân giải STFT duy nhất (\(20\text{ ms}\)) đôi khi để lại hiện tượng nhòe nhẹ ở các âm bật nhanh (&lt;em&gt;transients&lt;/em&gt;) hoặc nhiễu nền li ti ở độ lợi trung bình. DeepFilterNet2 bổ sung &lt;strong&gt;hàm mất mát STFT đa phân giải&lt;/strong&gt; (đánh giá đồng thời ở nhiều kích thước cửa sổ khác nhau) và một &lt;strong&gt;bộ hậu lọc (post-filter)&lt;/strong&gt; phi tuyến nhẹ nhằm nén thêm phần nhiễu dư ở những bin có độ lợi trung bình mà gần như giữ nguyên những bin tiếng nói rõ.&lt;/p&gt;

&lt;h3 id=&quot;3-cổng-điều-khiển-theo-snr-cục-bộ-local-snr-gating-trong-deepfilternet3&quot;&gt;3. Cổng điều khiển theo SNR cục bộ (Local SNR Gating) trong DeepFilterNet3&lt;/h3&gt;
&lt;p&gt;Khi không có ai nói (SNR cục bộ cực âm) hoặc khi môi trường hoàn toàn yên tĩnh (SNR cục bộ cực dương), việc chạy hết công suất cả tầng lọc sâu vừa dư thừa vừa có nguy cơ tạo nhiễu giả nhẹ. DeepFilterNet3 giới thiệu cơ chế ước lượng &lt;strong&gt;SNR cục bộ (LSNR)&lt;/strong&gt; để điều phối: khi tín hiệu sạch rõ ràng hoặc thuần nhiễu, mô hình điều chỉnh mượt mà cường độ can thiệp, giúp giọng nói tự nhiên hơn và nâng chất lượng nhận thức (PESQ/DNSMOS) trên tập chuẩn Voicebank+Demand.&lt;/p&gt;

&lt;h3 id=&quot;giải-thích-cầm-tay-kiểm-tra-ngân-sách-cpu-ở-mathrmrtf--004-và-cách-hoạt-động-của-bộ-hậu-lọc&quot;&gt;Giải thích: Cầm tay kiểm tra ngân sách CPU ở \(\mathrm{RTF} = 0{,}04\) và cách hoạt động của Bộ hậu lọc&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phần A — Con số \(\mathrm{RTF} = 0{,}04\) và độ trễ \(40\text{ ms}\) có nghĩa là gì trên thực tế?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Cấu hình khung chuẩn: cửa sổ \(20\text{ ms}\), bước nhảy hop \(H = 10\text{ ms}\), nhìn trước \(2\text{ khung} = 20\text{ ms}\).&lt;/li&gt;
  &lt;li&gt;Tổng độ trễ thuật toán: \(L_{\text{alg}} = 20 + 20 = 40\text{ ms}\).&lt;/li&gt;
  &lt;li&gt;Với \(\mathrm{RTF} = 0{,}04\), thời gian CPU cần để xử lý trọn vẹn 1 khung hop \(10\text{ ms}\) là:
\(T_{\text{proc}} = \mathrm{RTF} \times H = 0{,}04 \times 10\text{ ms} = 0{,}40\text{ ms}.\)
Như vậy, sau khi tốn \(0{,}40\text{ ms}\) để suy luận, CPU còn dư tới \(9{,}60\text{ ms}\) (\(96\%\) quỹ thời gian) trong mỗi nhịp hop để chạy AEC, giải mã codec Opus và giao diện ứng dụng!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phần B — Minh họa trực giác công thức Bộ hậu lọc (Post-Filter) trên độ lợi ERB:&lt;/strong&gt;
Một dạng hậu lọc kinh điển (kiểu Valin/Schröter) điều chỉnh độ lợi dự đoán \(G \in [0, 1]\) thành \(G_{\text{pf}} = G \cdot \sin\!\left(\frac{\pi}{2} G\right)\). Hãy tính thử ở hai bin đại diện:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bin tiếng nói rõ (\(G = 0{,}95\)):&lt;/strong&gt;
\(\sin\!\left(\frac{\pi}{2} \times 0{,}95\right) = \sin(85{,}5^\circ) \approx 0{,}997 \implies G_{\text{pf}} \approx 0{,}95 \times 0{,}997 = 0{,}947.\)
Tiếng nói sạch gần như không hề bị suy hao (chênh lệch dưới \(0{,}03\text{ dB}\))!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bin nhiễu nền còn lấp lửng (\(G = 0{,}60\)):&lt;/strong&gt;
\(\sin\!\left(\frac{\pi}{2} \times 0{,}60\right) = \sin(54^\circ) \approx 0{,}809 \implies G_{\text{pf}} \approx 0{,}60 \times 0{,}809 = 0{,}485.\)
Biên độ nhiễu dư bị kéo thêm \(-1{,}85\text{ dB}\) xuống sâu hơn, làm nền âm thanh sạch và tĩnh hẳn mà không đụng chạm tới độ dày của giọng nói chính.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ nắm được các cải tiến của DeepFilterNet2 so với bản ICASSP 2022 (bộ đệm thời gian thực, hàm mất mát đa phân giải, post-filter và RTF công bố), vai trò của cổng SNR cục bộ cùng kết quả bảng Voicebank+Demand của DeepFilterNet3 trong bài báo Interspeech 2023, và hiểu rõ vị trí của gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; trong hệ sinh thái này.&lt;/p&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Nhắc lại khung chuẩn: 32 băng ERB, 5 tap, cửa sổ 20 ms / hop 10 ms, độ trễ thuật toán 40 ms.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — DeepFilterNet2: giải thích nguồn gốc con số RTF 0,04.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Cơ chế cổng SNR năm 2023 và hàng kết quả DeepFilterNet3 trên bảng đánh giá.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Lệch phân bố vang phòng (RIR), xuất mô hình ONNX và bề mặt gói npm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Mini-lab và bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;cùng-kiến-trúc-nền-tảng-khác-phiên-bản-checkpoint&quot;&gt;Cùng kiến trúc nền tảng, khác phiên bản checkpoint&lt;/h3&gt;

&lt;p&gt;Cả ba thế hệ đều hướng tới tần số 48 kHz, cửa sổ 20 ms, chồng lấp 50%, 32 băng ERB và bộ lọc phức 5 tap tới khoảng 5 kHz, với 2 khung nhìn trước tạo ra độ trễ thuật toán &lt;strong&gt;40 ms&lt;/strong&gt;. Khi triển khai, luôn cố định cụ thể tệp trọng số thay vì chỉ ghi chung chung “DeepFilterNet”: nạp checkpoint DF2 vào cấu hình DF3 sẽ gây lỗi kích thước tensor hoặc méo âm sắc.&lt;/p&gt;

&lt;h3 id=&quot;deepfilternet2--arxiv220505474&quot;&gt;DeepFilterNet2 — arXiv:2205.05474&lt;/h3&gt;

&lt;p&gt;Bài báo DeepFilterNet2, “Towards Real-Time Speech Enhancement on Embedded Devices for Full-Band Audio” (IWAENC 2022, arXiv:2205.05474), giữ nguyên lưới STFT và đưa ra các cải tiến quyết định về chất lượng lẫn tốc độ:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mất mát.&lt;/strong&gt; Áp dụng khởi động (warmup) 3 epoch rồi giảm tốc độ học theo hàm cosine sau mỗi bước. Sử dụng hàm mất mát phổ đa phân giải sau ISTFT trên các cửa sổ 5, 10, 20 và 40 ms với hệ số nén \(c=0{,}3\). Hạng trọng số pha trộn \(\alpha\) của bản ICASSP được loại bỏ: bộ lọc 5 tap có thể tự “nghỉ” bằng cách đưa phần thực của tap hiện tại về 1 và các tap còn lại về 0.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dữ liệu huấn luyện.&lt;/strong&gt; Dùng tập DNS4 tiếng Anh kết hợp mở rộng các dạng suy giảm: tín hiệu đích giữ ít vang hơn hỗn hợp đầu vào và khôi phục cả đoạn âm bị cắt đỉnh (clipping). Đây là cải thiện hữu ích cho bối cảnh phòng họp, nhưng không phải bảo đảm tuyệt đối cho mọi không gian thực tế.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Giảm bộ đệm thời gian trong mạng.&lt;/strong&gt; Kích thước kernel theo thời gian thu gọn từ \(2\times 3\) xuống \(1\times 3\) (ngoại trừ một lớp đầu vào nhân quả \(3\times 3\)), kích thước ẩn của GRU là 256, và các lớp tuyến tính theo nhóm được gom thành một phép nhân ma trận. Trên CPU nhỏ, chi phí lưu lượng truy xuất bộ nhớ của vòng đệm activation thường lấn át bản thân số phép MAC.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bộ hậu lọc (Post-filter).&lt;/strong&gt; Áp dụng phép biến đổi dạng sin lên độ lợi ERB theo công thức \(G \leftarrow G\sin(\pi G/2)\) để suy hao mạnh hơn các băng nhiễu, sau đó trộn theo hệ số cường độ \(\beta\) (cần kiểm tra giá trị mặc định trong mã nguồn thay vì suy đoán; cờ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--pf&lt;/code&gt; bật bộ hậu lọc này trên CLI).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cùng CPU nhưng RTF khác biệt rõ rệt.&lt;/strong&gt; Đo trên Voicebank+Demand với CPU Core i5-8250U: bản ICASSP có 1,778 M tham số, 0,348 GMAC, RTF 0,11 và PESQ 2,81; bản DF2 tinh gọn có 2,306 M tham số, 0,356 GMAC, &lt;strong&gt;RTF 0,04&lt;/strong&gt; và PESQ 3,08 (CSIG 4,30, CBAK 3,40, COVL 3,699, STOI 0,9429). Dù GMAC gần như tương đương, RTF giảm mạnh nhờ tối ưu kernel và cấu trúc GRU. Khi bật post-filter, RTF vẫn là 0,04 nhưng PESQ giảm nhẹ xuống &lt;strong&gt;3,03&lt;/strong&gt; — nếu chỉ nhìn điểm PESQ mà không nghe thử, kỹ sư rất dễ loại bỏ một cải tiến cảm thụ có giá trị.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Phần tóm tắt bài báo cũng nêu tốc độ này đủ chạy trên Raspberry Pi 4, nhưng điều đó không đồng nghĩa với biên độ chịu nhiệt trên điện thoại di động.&lt;/p&gt;

&lt;h3 id=&quot;bài-báo-năm-2023-và-deepfilternet3--arxiv230508227&quot;&gt;Bài báo năm 2023 và DeepFilterNet3 — arXiv:2305.08227&lt;/h3&gt;

&lt;p&gt;Bài báo “DeepFilterNet: Perceptually Motivated Real-Time Speech Enhancement” (Interspeech 2023, arXiv:2305.08227) hệ thống hóa lại framework và là trích dẫn mà tệp README dự án gắn trực tiếp với mô hình &lt;strong&gt;DeepFilterNet3&lt;/strong&gt; (cần giữ đúng trích dẫn này, không tự đặt tiêu đề khác).&lt;/p&gt;

&lt;p&gt;Quy tắc vận hành công bố của bản demo gồm:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tần số lấy mẫu 48 kHz, cửa sổ 20 ms, hop 10 ms, nhìn trước 2 khung, độ trễ thuật toán &lt;strong&gt;40 ms&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;32 độ lợi ERB cho tầng đường bao.&lt;/li&gt;
  &lt;li&gt;Bộ lọc phức \(N=5\) áp dụng trên &lt;strong&gt;96 bin&lt;/strong&gt; thấp nhất (4,8 kHz); các bin cao hơn giữ nguyên độ lợi ERB.&lt;/li&gt;
  &lt;li&gt;Bộ mã hóa dự đoán thêm SNR cục bộ \(\xi\in[-15,35]\) dB để điều khiển cổng: nếu \(\xi&amp;lt;-10\) dB, cả hai bộ giải mã đều tắt và khung đầu ra bằng im lặng; nếu \(\xi&amp;gt;20\) dB, bộ giải mã deep filter tắt; trong khoảng còn lại cả hai tầng cùng chạy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hệ quả thực tế: đoạn tiếng nói rơi xuống dưới −10 dB sẽ bị cắt về im lặng số, còn tiếng nói trên 20 dB bỏ qua tầng khôi phục họa âm nên tiếng ù nhẹ vẫn có thể sót lại giữa các họa âm. Vòng chạy bằng thư viện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; trong bài báo này ghi nhận &lt;strong&gt;RTF 0,19&lt;/strong&gt; trên một luồng Core i5-8250U — khác với mức &lt;strong&gt;0,04&lt;/strong&gt; đo trên bản biên dịch khác của DF2; không nên lấy trung bình hai con số này hay coi chúng là RTF trên điện thoại.&lt;/p&gt;

&lt;p&gt;Trên bảng Voicebank+Demand, DeepFilterNet3 ghi nhận PESQ 3,17, CSIG 4,34, CBAK 3,61, COVL 3,77 và STOI 0,944 (so với PESQ 3,08 của DF2 và 2,81 của bản gốc). Cần nhớ đây chỉ là kết quả trên một tập kiểm thử chuẩn.&lt;/p&gt;

&lt;h3 id=&quot;gói-bọc-xuất-onnx-và-điều-kiện-phòng-thực-tế&quot;&gt;Gói bọc, xuất ONNX và điều kiện phòng thực tế&lt;/h3&gt;

&lt;p&gt;Gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 (&lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt;) chạy ONNX/WASM trong AudioWorklet với bề mặt API gồm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; và mức khử 0–100 qua &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. Không nên giả định đầu ra khớp từng bit với CLI hay bảng bài báo; bất kỳ sự thay đổi nào về hop, look-ahead hay tần số lấy mẫu đều tạo thành một hệ thống khác.&lt;/p&gt;

&lt;p&gt;Chuỗi xuất mô hình điển hình là PyTorch → ONNX → ONNX Runtime / WASM / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; → AudioWorklet hoặc callback native, trong đó trạng thái ẩn GRU phải được truyền tường minh như đầu vào và đầu ra của đồ thị (một đồ thị trục động nạp cả tệp chỉ là mô hình ngoại tuyến). Vì dữ liệu mô phỏng RT60 của bài báo đầu dừng ở 1 giây, hiện tượng khử quá mức trong phòng thực tế vang lớn thường bắt nguồn từ khoảng trống dữ liệu này — hãy nghe kiểm tra (Chương 08) trước khi tăng kích thước mạng.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Nạp trọng số DF2 đi kèm ngưỡng cổng SNR của DF3 hoặc ngược lại.&lt;/li&gt;
  &lt;li&gt;Trích dẫn PESQ 3,17 như thể đó là “điểm MOS thực tế của sản phẩm”.&lt;/li&gt;
  &lt;li&gt;Xem RTF 0,04 hay 0,19 đo trên Intel i5 là ngân sách chạy ổn định trên laptop không quạt hoặc điện thoại.&lt;/li&gt;
  &lt;li&gt;Bật &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--pf&lt;/code&gt;, thấy PESQ giảm từ 3,08 xuống 3,03 rồi hủy bỏ ngay mà chưa nghe thử.&lt;/li&gt;
  &lt;li&gt;Cho rằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(100)&lt;/code&gt; tái hiện chính xác mức suy hao tuyệt đối (dB) trong bài báo, trong khi đây là tham số sản phẩm theo thang 0–100.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Chạy CLI hai lần (có và không có cờ post-filter) khi tải được trọng số, đồng thời luôn thực thi đoạn NumPy tính phép biến dạng sin không thứ nguyên trên bốn giá trị độ lợi để kiểm chứng ngoại tuyến.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;deepFilter &lt;span class=&quot;nt&quot;&gt;--output-dir&lt;/span&gt; out/noisy/ noisy.wav
deepFilter &lt;span class=&quot;nt&quot;&gt;--pf&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--output-dir&lt;/span&gt; out/pf/ noisy.wav
python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
import numpy as np
G = np.array([0.0, 0.2, 0.5, 1.0])
Gp = G * np.sin(0.5 * np.pi * G)
np.set_printoptions(precision=6, suppress=True)
print(Gp)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Khi có trọng số và đầu vào 48 kHz: thu được hai tệp WAV đã xử lý khác nhau kèm log thời gian/RTF. Đoạn NumPy luôn in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0. 0.061803 0.353553 1.]&lt;/code&gt;, cho thấy độ lợi thấp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.2&lt;/code&gt; bị kéo xuống mạnh hơn nhiều so với độ lợi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.0&lt;/code&gt; — đúng cơ chế tăng suy hao vùng nhiễu của post-filter (bước pha trộn thứ hai dùng tham số \(\beta\) cố ý không đưa vào đoạn mã này).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Không có mạng để tải trọng số (giữ phần kết quả NumPy và ghi chú lỗi CLI); đưa tệp khác 48 kHz vào bản Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deep-filter&lt;/code&gt;; so sánh trực tiếp RTF laptop với điện thoại; hoặc giả định đầu ra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--pf&lt;/code&gt; khớp hoàn toàn với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; của gói npm.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bảng ba thế hệ.&lt;/strong&gt; Với bản ICASSP 2022, DeepFilterNet2 và DeepFilterNet3, hãy liệt kê hội nghị, mã arXiv, một cải tiến cơ chế nổi bật và một con số đánh giá bạn có thể bảo vệ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cơ chế cổng SNR.&lt;/strong&gt; Với các mức SNR cục bộ lần lượt là −12 dB, +25 dB và +5 dB, những tầng xử lý nào sẽ hoạt động?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phân tích RTF.&lt;/strong&gt; Bảng DF2 ghi GMAC 0,356 với RTF 0,04, trong khi bản trước ghi GMAC 0,348 nhưng RTF tới 0,11. Vì sao mô hình có số MAC cao hơn một chút lại chạy nhanh hơn đáng kể?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bề mặt gói npm.&lt;/strong&gt; Nêu hai biểu tượng API công khai trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; và hai trách nhiệm kỹ thuật về hop và trạng thái mà gói không tự động miễn trừ cho người tích hợp.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;ICASSP 2022 (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2110.05588&lt;/code&gt;): kiến trúc hai tầng ERB + deep filter, PESQ 2,81 / 1,778 M tham số; IWAENC 2022 (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2205.05474&lt;/code&gt;): rút gọn kernel thời gian, hàm mất mát đa phân giải và post-filter, RTF 0,04 và PESQ 3,08 trên bảng đo i5; Interspeech 2023 (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2305.08227&lt;/code&gt;, gắn với DF3 trong README): cổng SNR cục bộ và PESQ 3,17. Tất cả điểm PESQ đều đo trên Voicebank+Demand, không phải dữ liệu sản phẩm.&lt;/li&gt;
  &lt;li&gt;Tại −12 dB: cả hai bộ giải mã tắt, xuất im lặng; tại +25 dB: chỉ chạy tầng ERB; tại +5 dB: chạy đầy đủ cả hai tầng.&lt;/li&gt;
  &lt;li&gt;Số phép MAC không phản ánh lưu lượng truy xuất bộ nhớ. Kernel thời gian ngắn hơn của DF2 giảm lượng activation phải đệm ở mỗi hop, giúp RTF hạ từ 0,11 xuống 0,04 dù GMAC giữ quanh 0,35.&lt;/li&gt;
  &lt;li&gt;Bề mặt công khai gồm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt;. Người tích hợp vẫn phải xử lý đúng chênh lệch giữa hop 10 ms và quantum 128 mẫu, duy trì trạng thái GRU/STFT xuyên qua các callback, và không mặc định khớp bit với CLI.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter et al., DeepFilterNet2, IWAENC 2022, &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Schröter et al., Interspeech 2023, &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt; (trích dẫn DeepFilterNet3 trong README).&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt; cho checkpoint và công cụ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepFilter&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt; cho phần đóng gói AudioWorklet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày khung kiến trúc nền tảng (STFT, độ lợi ERB và deep filter) mà DeepFilterNet2 và DeepFilterNet3 tiếp tục kế thừa.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Đoạn nghe thử của tác giả để đánh giá trực tiếp bằng tai (các chỉ số DF2/DF3 cụ thể nằm trong bài báo).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Minh họa quy trình thẩm định thế hệ mô hình mới dựa trên cùng bài toán, ngân sách độ phức tạp và đánh giá nghe — đúng tinh thần so sánh giữa DF2 và DF3.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-02 DeepFilterNet: ý tưởng deep filtering</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_02_deepfilternet_core/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_02_deepfilternet_core</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;DeepFilterNet&lt;/strong&gt; (Schröter et al., ICASSP 2022, arXiv:2110.05588) là bộ tăng cường tiếng nói toàn băng tập trung dung lượng tính toán vào đường bao thính giác thô và một bộ lọc phức ngắn, thay vì dùng một mạng dày đặc trên toàn bộ 481 bin. Bài học này trình bày tường minh công thức tổng lọc sâu và chạy thử trên phổ mẫu hai tap, giúp bạn thực hành ngay cả khi không tải được trọng số đã huấn luyện sẵn.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;Sơ đồ hai tầng DeepFilterNet: gain ERB trên đường bao, deep filter trên hài tần số thấp&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Tầng 1 dự đoán độ lợi thực trên 32 băng ERB (băng thông chữ nhật tương đương) rồi trải lên toàn bộ lưới STFT. Tầng 2 dự đoán bộ lọc phức 5 tap và chỉ áp dụng cho vùng tần số thấp, nơi tập trung phần lớn năng lượng tuần hoàn của tiếng nói; các bin cao hơn giữ nguyên độ lợi ERB.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Nếu bạn muốn chạy tăng cường tiếng nói toàn băng \(48\text{ kHz}\) theo thời gian thực ngay trên một nhân CPU laptop hay bên trong trình duyệt, bài toán khó nhất không phải là “làm sao đạt điểm chất lượng cao nhất”, mà là &lt;strong&gt;phân bổ ngân sách phép tính vào đúng chỗ tai người cần nhất&lt;/strong&gt;. Áp một mạng nơ-ron phức dày đặc lên toàn bộ \(481\) bin tần số vừa tốn kém vừa lãng phí — bởi trên \(5\text{ kHz}\), giọng người chủ yếu là nhiễu xát không tuần hoàn (như chữ “s”, “f”), nơi tai người chỉ quan tâm đến đường bao năng lượng thô chứ không phân biệt nổi từng họa âm chi tiết. &lt;strong&gt;DeepFilterNet&lt;/strong&gt; (Schröter và cộng sự, ICASSP 2022) tỏa sáng chính nhờ một thiết kế hai tầng bám sát sinh lý học thính giác: rẻ và thô cho toàn băng, sâu và phức cho vùng họa âm tần số thấp.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-thang-thính-giác-erb-và-bộ-lọc-phức-đa-khung-deep-filtering&quot;&gt;Kiến thức cần nhớ: Thang thính giác ERB và bộ lọc phức đa khung (Deep Filtering)&lt;/h2&gt;

&lt;h3 id=&quot;1-thang-erb-equivalent-rectangular-bandwidth--nén-481-bin-về-32-băng-thính-giác&quot;&gt;1. Thang ERB (Equivalent Rectangular Bandwidth) — nén 481 bin về 32 băng thính giác&lt;/h3&gt;
&lt;p&gt;Ốc tai người không phân chia tần số đều nhau theo tuyến tính (Hz), mà có độ phân giải mịn ở tần số thấp và thô dần theo kiểu logarit ở tần số cao. Thang &lt;strong&gt;ERB&lt;/strong&gt; mô hình hóa chính xác độ rộng bộ lọc thính giác đó: thay vì dự đoán \(481\) độ lợi riêng lẻ, tầng 1 của DeepFilterNet chỉ dự đoán đúng &lt;strong&gt;32 độ lợi thực&lt;/strong&gt; trên 32 băng ERB, sau đó nội suy ngược lên toàn bộ 481 bin. Chỉ riêng bước này đã dọn sạch phần lớn nhiễu băng rộng với chi phí tính toán cực nhỏ.&lt;/p&gt;

&lt;h3 id=&quot;2-deep-filtering--tổng-quát-hóa-crm-từ-1-khung-sang-n-khung-n--5&quot;&gt;2. Deep Filtering — tổng quát hóa CRM từ 1 khung sang \(N\) khung (\(N = 5\))&lt;/h3&gt;
&lt;p&gt;Mặt nạ phức CRM (bài 04-01) chỉ nhân mỗi ô \(Y(t, k)\) với &lt;strong&gt;1&lt;/strong&gt; hệ số phức \(M(t, k)\). Khi tiếng nói có cấu trúc tuần hoàn mạnh (các họa âm của nguyên âm kéo dài nhiều chục mili-giây), thông tin ở các khung lân cận \(t-2, t-1, t, t+1, t+2\) chứa manh mối cực mạnh để tái tạo lại cả biên độ lẫn pha bị nhiễu che khuất. &lt;strong&gt;Deep Filtering&lt;/strong&gt; (Mack &amp;amp; Habets, 2020) thay phép nhân đơn bằng một bộ lọc FIR phức bậc \(N\) chạy dọc trục thời gian ngay trên từng bin tần số thấp:
\(\hat{S}(t, k) = \sum_{i=0}^{N-1} C_i(t, k)\, Y(t - i + l,\; k),\)
với \(l\) là số khung nhìn trước (&lt;em&gt;look-ahead&lt;/em&gt;, bằng \(2\) khung trong cấu hình chuẩn).&lt;/p&gt;

&lt;h3 id=&quot;3-tính-nhân-quả-và-nguồn-gốc-chính-xác-của-độ-trễ-thuật-toán-40-ms&quot;&gt;3. Tính nhân quả và nguồn gốc chính xác của độ trễ thuật toán 40 ms&lt;/h3&gt;
&lt;p&gt;Trong xử lý thời gian thực, độ trễ thuật toán không phải là thời gian chạy CPU (RTF), mà là thời gian chờ tối thiểu do cấu trúc cửa sổ và nhìn trước quy định. Với STFT cửa sổ \(20\text{ ms}\) (\(960\) mẫu ở \(48\text{ kHz}\)), bước nhảy hop \(10\text{ ms}\) (\(480\) mẫu), và \(2\) khung nhìn trước (\(2 \times 10\text{ ms} = 20\text{ ms}\)), tổng độ trễ thuật toán tối thiểu đúng bằng \(20 + 20 = 40\text{ ms}\) — hoàn toàn nằm gọn trong ngân sách \(150\text{ ms}\) của VoIP.&lt;/p&gt;

&lt;h3 id=&quot;giải-thích-cầm-tay-đếm-số-tham-số-đầu-ra-và-tính-thử-1-bước-deep-filter-phức-2-tap&quot;&gt;Giải thích: Cầm tay đếm số tham số đầu ra và tính thử 1 bước Deep Filter phức 2 tap&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phần A — Vì sao tách 2 tầng tiết kiệm gấp gần 5 lần đầu ra?&lt;/strong&gt;
Với STFT \(48\text{ kHz}\), \(N_{\text{FFT}} = 960 \implies 481\) bin tần số (mỗi bin rộng \(50\text{ Hz}\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cách làm ngây thơ (5-tap phức trên cả 481 bin):&lt;/strong&gt;
\(481\text{ bin} \times 5\text{ tap} \times 2\text{ (thực/ảo)} = 4\,810\text{ hệ số mỗi khung}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thiết kế 2 tầng của DeepFilterNet (32 ERB + 5-tap phức chỉ cho 96 bin thấp, tức \(0\text{–}4{,}8\text{ kHz}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tầng 1 (ERB gain): \(32\) hệ số thực.&lt;/li&gt;
      &lt;li&gt;Tầng 2 (Deep Filter dưới \(4{,}8\text{ kHz}\)): \(96 \times 5 \times 2 = 960\) hệ số.&lt;/li&gt;
      &lt;li&gt;Tổng đầu ra mỗi khung: \(32 + 960 = 992\text{ hệ số}\) — gọn hơn &lt;strong&gt;\(4{,}85\) lần&lt;/strong&gt; so với cách làm toàn băng!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phần B — Tự tay tính 1 bước Deep Filter phức 2 tap trên một bin tần số thấp \(k\):&lt;/strong&gt;
Giả sử tại bin \(k\) ta có hai khung đầu vào liên tiếp:
\(Y(t-1, k) = 1 + j, \qquad Y(t, k) = 2 - j,\)
và mạng nơ-ron dự đoán 2 hệ số lọc phức cho khung \(t\) là:
\(c_{-1} = 0{,}5j, \qquad c_0 = 0{,}5 + 0{,}5j.\)
Áp dụng công thức tổng lọc sâu \(\hat{S}(t, k) = c_{-1} Y(t-1, k) + c_0 Y(t, k)\):&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Số hạng khung trước:
\(c_{-1} Y(t-1, k) = 0{,}5j(1 + j) = 0{,}5j + 0{,}5j^2 = -0{,}5 + 0{,}5j.\)&lt;/li&gt;
  &lt;li&gt;Số hạng khung hiện tại:
\(c_0 Y(t, k) = (0{,}5 + 0{,}5j)(2 - j) = 1{,}0 - 0{,}5j + 1{,}0j - 0{,}5j^2 = 1{,}5 + 0{,}5j.\)&lt;/li&gt;
  &lt;li&gt;Cộng hai số hạng phức:
\(\hat{S}(t, k) = (-0{,}5 + 1{,}5) + (0{,}5 + 0{,}5)j = 1{,}0 + 1{,}0j.\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Chỉ với hai phép nhân phức và một phép cộng, bộ lọc sâu đã vừa tổng hợp năng lượng từ khung trước, vừa xoay góc pha của bin hiện tại về đúng pha sạch mà mặt nạ thực không bao giờ làm được.&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ tính được trực tiếp một bước áp độ lợi ERB và một tổng lọc sâu đa khung trên bin phức; giải thích được vì sao bộ lọc 5 tap dưới ngưỡng khoảng 5 kHz nhẹ hơn nhiều so với CRM trên toàn bộ các bin ở 48 kHz; nêu đúng cấu hình STFT công bố (cửa sổ 20 ms, hop 10 ms) cùng độ trễ thuật toán 40 ms (gồm 2 khung nhìn trước); và chạy được công cụ CLI &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepFilter&lt;/code&gt; hoặc kịch bản NumPy thay thế.&lt;/p&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Vì sao cả 481 bin ở 48 kHz không cần chung một ngân sách phép nhân-cộng (MAC).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Tầng ERB: dự đoán 32 độ lợi thực và phép nhân theo điểm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Tổng lọc sâu (deep filter) so với độ lợi Wiener hay CRM một tap.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Độ nhìn trước (look-ahead), tính nhân quả và kho mã nguồn chính thức.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Mini-lab (CLI hoặc NumPy) và bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;kiến-trúc-hai-tầng-với-các-thông-số-công-bố&quot;&gt;Kiến trúc hai tầng với các thông số công bố&lt;/h3&gt;

&lt;p&gt;Tai người phân giải tần số tinh hơn ở dải tần thấp, và DeepFilterNet khai thác đặc tính này ở cả hai tầng:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tầng đường bao.&lt;/strong&gt; Dãy lọc ERB dạng chữ nhật nén phổ log-công suất xuống \(N_{\mathrm{ERB}}=32\) băng. Mạng dự đoán 32 hệ số độ lợi thực, dãy lọc nghịch trải các độ lợi này lên các bin STFT rồi nhân với phổ nhiễu. Đầu vào đặc trưng được chuẩn hóa theo trung bình trượt hàm mũ với hằng số suy giảm 1 giây, nhờ đó sự thay đổi đột ngột độ lợi micro không bị nhận nhầm thành nhiễu mới.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tầng thành phần tuần hoàn.&lt;/strong&gt; Bộ lọc phức 5 tap chỉ hoạt động tới ngưỡng \(f_{\mathrm{DF}}=5\) kHz (trong bài báo ICASSP và DeepFilterNet2). Bản demo năm 2023 (arXiv:2305.08227) nêu rõ phạm vi là 96 bin thấp nhất: với FFT 960 điểm ở 48 kHz (bước bin 50 Hz), ta có \(96\times 50\,\mathrm{Hz}=4{,}8\) kHz. Trên ngưỡng này, đầu ra chỉ sử dụng độ lợi ERB.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các bảng thực nghiệm sử dụng tần số 48 kHz, \(N_{\mathrm{FFT}}=960\) (20 ms) và chồng lấp 50% (hop 480 mẫu = 10 ms). DeepFilterNet2 và bản demo 2023 dùng 2 khung nhìn trước, đạt &lt;strong&gt;độ trễ thuật toán 40 ms&lt;/strong&gt;. Công thức độ trễ trong bài báo ICASSP bằng độ trễ cửa sổ cộng \(\max(l_{\mathrm{DNN}}, l_{\mathrm{DF}})\), với cấu hình huấn luyện \(l_{\mathrm{DNN}}=2\) và \(l_{\mathrm{DF}}=1\). Các khung tương lai này là độ trễ cố hữu cần được cộng đủ trước khi đánh giá khả năng thời gian thực.&lt;/p&gt;

&lt;p&gt;Trên bảng kết quả VCTK/DEMAND của bài báo ICASSP, mô hình đầy đủ có 1,778 triệu tham số và 0,348 GMAC/s, đạt WB-PESQ 2,81 và SI-SDR 16,63 dB. Khi bỏ tầng 2, mô hình còn 0,885 triệu tham số và 0,251 GMAC/s, với PESQ giảm xuống 2,57 và SI-SDR xuống 13,81 dB. Tầng 2 chiếm xấp xỉ nửa số tham số nhưng đảm nhiệm phần lớn khả năng khôi phục cấu trúc họa âm.&lt;/p&gt;

&lt;h3 id=&quot;bộ-lọc-sâu-khác-với-mặt-nạ-một-tap&quot;&gt;Bộ lọc sâu khác với mặt nạ một tap&lt;/h3&gt;

&lt;p&gt;Mặt nạ một tap (kể cả độ lợi Wiener dưới mô hình Gauss) chỉ là phép nhân trên cùng một khung:&lt;/p&gt;

\[\hat{S}(k,\ell)=M(k,\ell)\,Y(k,\ell).\]

&lt;p&gt;Ngược lại, kỹ thuật lọc sâu (deep filtering — Mack &amp;amp; Habets, tiếp nối nhánh lọc tuyến tính phức CLC) dự đoán các hệ số tap \(W_i\) và tổ hợp một đoạn lịch sử ngắn theo thời gian. Với bộ lọc 5 tap và độ nhìn trước tùy chọn \(\ell\):&lt;/p&gt;

\[\hat{S}(t,f)=\sum_{i=0}^{4} W_i(t,f)\,X(t-i+\ell,f).\]

&lt;p&gt;Bài báo ICASSP đánh chỉ số bậc \(N=5\) theo tổng \(\sum_{i=0}^{N}\), còn bản demo 2023 viết vector \(N=5\) hệ số \(W_0,\ldots,W_{N-1}\). Dù theo quy ước chỉ số nào, bản chất vẫn là một bộ lọc FIR theo trục thời gian cho từng bin chứ không phải một phép nhân đơn lẻ. Phần Mini-lab bên dưới sử dụng hai tap để phép tính gọn trong một dòng; ba tap còn lại tuân theo đúng cấu trúc tương tự.&lt;/p&gt;

&lt;p&gt;Nhờ các hệ số phức kết hợp với khung quá khứ, bộ lọc sâu có thể xoay và chỉnh pha trên từng bin — điều mặt nạ biên độ không làm được. Vì có nhiều tập hệ số tap khác nhau cùng tạo ra một phổ đầu ra tương đương, bài báo huấn luyện mô hình trực tiếp bằng hàm mất mát phổ nén từ bài 04-01 (\(c=0{,}6\)) thay vì ép khớp một bộ lọc lý tưởng dạng đóng. Mô hình ICASSP cũng học thêm trọng số pha trộn \(\alpha(k)\) giữa đầu ra deep filter và đầu ra ERB, trong khi bản demo 2023 chuyển sang cơ chế cổng SNR (bài 04-03) — cần phân biệt hai cơ chế này thay vì gộp chung.&lt;/p&gt;

&lt;h3 id=&quot;vì-sao-chi-phí-mac-giảm-mạnh&quot;&gt;Vì sao chi phí MAC giảm mạnh&lt;/h3&gt;

&lt;p&gt;Bộ giải mã đường bao chỉ cần xuất 32 độ lợi thay vì 481 (tỷ lệ \(32/481\approx 0{,}067\)). Tầng tinh chỉ tính bộ lọc phức 5 tap trên 96 bin thấp thay vì CRM trên toàn phổ. Ngoài ra, mạng ICASSP chia các lớp tuyến tính và GRU thành \(P=8\) nhóm với kích thước ẩn \(512/8=64\). Tên gọi các lớp có thể thay đổi giữa các phiên bản, nhưng nguyên lý phân bổ ngân sách tính toán này vẫn giữ nguyên.&lt;/p&gt;

&lt;h3 id=&quot;tính-nhân-quả-và-kho-mã-nguồn&quot;&gt;Tính nhân quả và kho mã nguồn&lt;/h3&gt;

&lt;p&gt;Các tap lọc chỉ được phép truy cập các khung nằm trong giới hạn nhìn trước đã khai báo. Trạng thái ẩn của GRU, bộ chuẩn hóa trượt 1 giây và bộ đệm các khung phổ quá khứ đều là trạng thái streaming (bài 05-04); việc xóa chúng giữa cuộc gọi sẽ gây tiếng lách tách hoặc lọt một đoạn nhiễu ngắn.&lt;/p&gt;

&lt;p&gt;Cấu hình và trọng số chính thức nằm tại &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt;. Công cụ dòng lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepFilter&lt;/code&gt; trong gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet&lt;/code&gt; mặc định sử dụng trọng số DeepFilterNet3, còn bản biên dịch Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deep-filter&lt;/code&gt; yêu cầu tệp WAV 48 kHz. Gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; (&lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt;) chạy đồ thị ONNX/WASM trong AudioWorklet (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;) và không cam kết khớp từng bit với CLI.&lt;/p&gt;

&lt;h2 id=&quot;danh-mục-kiểm-tra-trước-khi-gọi-một-hệ-thống-là-deepfilternet&quot;&gt;Danh mục kiểm tra trước khi gọi một hệ thống là DeepFilterNet&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;STFT toàn băng 48 kHz, không phải mô hình ngoại tuyến 16 kHz.&lt;/li&gt;
  &lt;li&gt;Dự đoán 32 độ lợi ERB cho tầng đường bao.&lt;/li&gt;
  &lt;li&gt;Áp dụng bộ lọc phức nhiều tap chỉ trên dải bin tần số thấp.&lt;/li&gt;
  &lt;li&gt;Tính đủ độ nhìn trước vào độ trễ thuật toán 40 ms, tách biệt khỏi RTF.&lt;/li&gt;
  &lt;li&gt;Bảo toàn trạng thái nhân quả xuyên suốt các hop.&lt;/li&gt;
  &lt;li&gt;Cố định phiên bản trọng số bằng tên tệp hoặc mã commit trước khi xuất đồ thị (Chương 06).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Gọi chung mọi mạng tạo mặt nạ là “DeepFilterNet”.&lt;/li&gt;
  &lt;li&gt;Áp bộ lọc 5 tap lên cả 481 bin rồi thắc mắc vì sao chi phí GMAC tăng vọt.&lt;/li&gt;
  &lt;li&gt;Đo PESQ ở 16 kHz rồi gán nhầm vào bảng đánh giá 48 kHz.&lt;/li&gt;
  &lt;li&gt;Quên độ dài cửa sổ 20 ms khi chỉ nhìn thông số “khung/hop 10 ms”.&lt;/li&gt;
  &lt;li&gt;Dùng lẫn checkpoint của DF, DF2 và DF3 trên cùng một tệp cấu hình (xem bài tiếp theo).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Chạy tăng cường tiếng nói cho một tệp âm thanh bằng CLI chính thức; trường hợp không tải được trọng số, thực hiện trực tiếp một tổng lọc sâu hai tap bằng NumPy để đối chiếu với mặt nạ một tap.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;deepfilternet
deepFilter &lt;span class=&quot;nt&quot;&gt;--output-dir&lt;/span&gt; out/ noisy.wav
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Các cờ dòng lệnh đã được tài liệu hóa gồm: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--model-base-dir&lt;/code&gt; (trỏ tới trọng số cục bộ), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--pf&lt;/code&gt; (bật post-filter, bài 04-03), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--output-dir&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--compensate-delay&lt;/code&gt;. Lưu ý bản Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deep-filter&lt;/code&gt; yêu cầu đầu vào WAV 48 kHz.&lt;/p&gt;

&lt;p&gt;Kịch bản chạy ngoại tuyến (hai tap của tổng lọc sâu):&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
import numpy as np
Y_now = np.complex64(1.0 + 0.5j)
Y_prev = np.complex64(0.2 - 0.1j)
H0 = np.complex64(0.8 + 0.0j)
H1 = np.complex64(0.1 - 0.2j)
deep = H0 * Y_now + H1 * Y_prev
mask = np.complex64(0.8) * Y_now
print(deep)
print(mask)
print(round(abs(deep), 6), round(abs(mask), 6))
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Với CLI: tạo ra tệp WAV đã khử nhiễu trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;out/&lt;/code&gt; kèm dòng log thời gian chạy hoặc RTF. Với kịch bản NumPy: luôn in ra kết quả deep filter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(0.8+0.35j)&lt;/code&gt;, mặt nạ một tap &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(0.8+0.4j)&lt;/code&gt;, và biên độ lần lượt khoảng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.873212&lt;/code&gt; với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.894427&lt;/code&gt;. Phần ảo thay đổi nhờ hệ số \(H_1\) khai thác khung quá khứ \(Y_{\mathrm{prev}}\) — điều mặt nạ đơn điểm không thực hiện được.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Thiếu kết nối mạng khiến CLI không tải được trọng số (hãy giữ kết quả NumPy và ghi nhận lỗi, không tự tạo tệp WAV giả); đưa tệp không phải 48 kHz vào bản Rust; lấy RTF đo trên laptop làm RTF điện thoại; hoặc quên cờ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--output-dir&lt;/code&gt; rồi tìm nhầm thư mục đầu ra.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Đối chiếu công thức.&lt;/strong&gt; Viết cạnh nhau công thức độ lợi Wiener một tap và tổng lọc sâu 5 tap; chỉ rõ đại lượng nào do mạng học và đại lượng nào do bộ theo dõi nhiễu cổ điển ước lượng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính số bin.&lt;/strong&gt; Ở 48 kHz với FFT 960 điểm, ngưỡng 4,8 kHz tương ứng chỉ số bin cuối cùng là bao nhiêu? Với bộ lọc 5 tap, mỗi khung có bao nhiêu hệ số tap phức?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ước lượng MAC.&lt;/strong&gt; Đầu ra tầng đường bao chỉ có 32 giá trị thay vì 481. Hãy tính tỷ số này và giải thích vì sao tỷ số đó chưa phản ánh toàn bộ chi phí GMAC.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra độ trễ.&lt;/strong&gt; Với hop 10 ms, nhìn trước 2 khung và cửa sổ 20 ms, độ trễ thuật toán là bao nhiêu? Cờ CLI nào chỉ dịch căn chỉnh tệp đầu ra chứ không loại bỏ độ trễ này?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Lọc Wiener dùng \(M=\xi/(\xi+1)\) (một phép nhân duy nhất, với \(\xi\) ước lượng từ bộ theo dõi nhiễu); deep filter dùng năm hệ số phức \(W_i\) do mạng dự đoán để tính tích vô hướng với năm khung \(X\). Đại lượng học được là \(W_i\) và độ lợi ERB; hệ cổ điển ước lượng \(\xi\) hoặc PSD nhiễu.&lt;/li&gt;
  &lt;li&gt;Bước bin là 50 Hz nên bin thứ 96 nằm tại 4,8 kHz (đúng với “96 bin thấp nhất” trong demo 2023), tương ứng \(96\times 5=480\) hệ số tap phức mỗi khung trước khi áp một độ lợi thực cho các bin cao hơn.&lt;/li&gt;
  &lt;li&gt;Tỷ số là \(32/481\approx 0{,}0665\), nhưng chưa bao gồm chi phí STFT, bước trải ngược ERB và phép nhân 5 tap trên 96 bin. Bài DeepFilterNet2 còn cho thấy cách nhóm lớp và kích thước kernel làm thay đổi mạnh RTF thực tế ngay cả khi GMAC gần như không đổi.&lt;/li&gt;
  &lt;li&gt;Độ trễ thuật toán là 40 ms. Cờ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--compensate-delay&lt;/code&gt; chỉ căn chỉnh lại thời gian trên tệp để chấm điểm ngoại tuyến chứ không thể xóa bỏ look-ahead trong cuộc gọi thời gian thực.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter et al., ICASSP 2022, &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt; — độ lợi ERB, deep filtering và bảng số liệu 1,778 M tham số / 0,348 GMAC.&lt;/li&gt;
  &lt;li&gt;Mack &amp;amp; Habets, “Deep Filtering,” &lt;em&gt;IEEE Signal Processing Letters&lt;/em&gt;, 2020 — nền tảng bộ lọc phức đa khung được DeepFilterNet kế thừa.&lt;/li&gt;
  &lt;li&gt;README tại &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt; cho hướng dẫn CLI &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepFilter&lt;/code&gt; và model card.&lt;/li&gt;
  &lt;li&gt;Bài tiếp theo: những thay đổi cốt lõi của DeepFilterNet2 và trích dẫn năm 2023 gắn với DeepFilterNet3.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày trực tiếp cơ chế tách tầng đường bao ERB và tầng lọc sâu phức trên các bin thấp.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Nên nghe ngay sau khi xem sơ đồ để gắn hai tầng xử lý với cảm nhận âm thanh thực tế.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nsscrYdrGRE&quot;&gt;RNNoise, Neural Speech Enhancement, and the Browser&lt;/a&gt; — W3C, tiếng Anh. Hữu ích để đối chiếu mô hình độ lợi theo băng đơn giản với bộ lọc phức đa khung trong bài.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-01 Tổng quan tăng cường tiếng nói bằng mạng nơ-ron</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_01_neural_se_overview/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter04/04_01_neural_se_overview</id>
   <content type="html">&lt;p&gt;Tăng cường tiếng nói bằng mạng nơ-ron thay thế các công thức độ lợi chỉnh tay bằng mô hình học từ các cặp dữ liệu nhiễu–sạch. Bài học này hệ thống hóa ba hướng tiếp cận chính — tạo mặt nạ (masking), ánh xạ trực tiếp (mapping) và mô hình sinh (generative) — đối chiếu xử lý trên miền dạng sóng với miền biến đổi Fourier thời gian ngắn (STFT), đồng thời phân tích hàm mất mát mà mô hình thực sự tối ưu. Qua đó, DeepFilterNet (từ bài 04-02) và RNNoise (bài 04-06) được đặt trên cùng một bản đồ kiến trúc rõ ràng để bạn có cơ sở lập luận khi đánh giá thiết kế. Kiến trúc trọng tâm của khóa học là sơ đồ hai tầng ở hình dưới.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;Đồ thị DeepFilterNet hai tầng: gain ERB cho đường bao và deep filter phức trên STFT&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Kiến trúc hai tầng trọng tâm của khóa học: tầng đầu sử dụng băng thông chữ nhật tương đương (equivalent rectangular bandwidth, ERB) để ước lượng đường bao phổ thô, sau đó một bộ lọc sâu (deep filter) phức ngắn khôi phục cấu trúc họa âm. Các bài sau sẽ đi sâu vào từng khối; bài này tập trung dựng bản đồ tổng thể.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Sau ba chương đi từ biến đổi Fourier đến trừ phổ, Wiener và Kalman, ta nhận ra một giới hạn chung của trường phái cổ điển: chúng đều phải đặt ra các giả định thống kê đơn giản (nhiễu dừng, phân bố Gauss, pha nhiễu giữ nguyên) để viết được công thức đóng. Nhưng thế giới thực lại đầy rẫy tiếng gõ phím cơ, tiếng chó sủa, tiếng xe cộ biến đổi từng phần trăm giây — những thứ không vừa với bất kỳ phương trình giải tích gọn gàng nào. &lt;strong&gt;Tăng cường tiếng nói bằng mạng nơ-ron (Neural Speech Enhancement)&lt;/strong&gt; lật ngược cách tiếp cận: thay vì tự viết công thức độ lợi, ta cho mạng nơ-ron nghe hàng nghìn giờ cặp âm thanh &lt;em&gt;nhiễu – sạch&lt;/em&gt; để nó tự học cấu trúc họa âm phức tạp của giọng người và tách nhiễu ngay cả trong những tình huống phi dừng khắc nghiệt nhất.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-hệ-hình-học-sâu-cho-âm-thanh-và-bài-toán-pha&quot;&gt;Kiến thức cần nhớ: Ba hệ hình học sâu cho âm thanh và bài toán pha&lt;/h2&gt;

&lt;h3 id=&quot;1-masking-mapping-và-generative--ba-cách-đặt-đầu-ra-của-mạng&quot;&gt;1. Masking, Mapping và Generative — ba cách đặt đầu ra của mạng&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Masking (Tạo mặt nạ):&lt;/strong&gt; mạng dự đoán một tỷ lệ (thực như IRM hoặc phức như CRM) rồi nhân với tín hiệu đầu vào \(Y\). Vì mặt nạ bị chặn trong phạm vi nhỏ và tận dụng sẵn cấu trúc của \(Y\), mô hình học nhanh, nhẹ và ít bị “bịa” giọng lạ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mapping (Ánh xạ trực tiếp):&lt;/strong&gt; mạng dự đoán thẳng phổ sạch \(\hat{S}\) hoặc dạng sóng sạch \(\hat{s}[t]\). Linh hoạt hơn nhưng dễ bị mờ chi tiết tần số cao khi SNR thấp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Generative (Mô hình sinh — Diffusion / Flow / Codec):&lt;/strong&gt; sinh lại giọng nói sạch có điều kiện trên bản ghi nhiễu. Nghe rất tự nhiên ngay cả ở SNR cực âm, nhưng thường nặng, độ trễ cao và có nguy cơ “ảo giác” phát âm sai từ nếu không kiểm soát chặt.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-tại-sao-hàm-mất-mát-loss-quan-trọng-không-kém-kiến-trúc-mạng&quot;&gt;2. Tại sao hàm mất mát (Loss) quan trọng không kém kiến trúc mạng?&lt;/h3&gt;
&lt;p&gt;Nếu huấn luyện mạng chỉ bằng sai số bình phương (MSE) trên biên độ STFT thô, các bin năng lượng lớn ở tần số thấp sẽ thống trị toàn bộ gradient, khiến mạng bỏ mặc các phụ âm xát yếu ở tần số cao (như “s”, “x”, “th”). Vì vậy, các hệ thống hiện đại như DeepFilterNet dùng &lt;strong&gt;hàm mất mát phổ nén (compressed spectral loss)&lt;/strong&gt; với lũy thừa \(c \approx 0{,}3\text{–}0{,}6\) (\(\vert S \vert^c\)) kết hợp cả thành phần biên độ lẫn thành phần phức để cân bằng giữa năng lượng lớn và chi tiết thính giác tinh tế — khác hẳn với chỉ số đánh giá SI-SDR thường dùng khi báo cáo kết quả.&lt;/p&gt;

&lt;h3 id=&quot;3-mặt-nạ-thực-irm-bất-lực-trước-sai-số-pha--lý-do-mặt-nạ-phức-crm-ra-đời&quot;&gt;3. Mặt nạ thực (IRM) bất lực trước sai số pha — lý do mặt nạ phức (CRM) ra đời&lt;/h3&gt;
&lt;p&gt;Ở SNR cao, pha nhiễu \(\angle Y\) gần với pha sạch \(\angle S\). Nhưng khi nhiễu mạnh bằng hoặc lớn hơn tiếng nói (\(\text{SNR} \le 0\text{ dB}\)), vector nhiễu \(N\) kéo lệch góc pha của \(Y = S + N\) đi hàng chục độ. Một mặt nạ thực chỉ có thể kéo dài hoặc rút ngắn vector \(Y\) dọc theo đúng hướng sai đó, không bao giờ xoay nó trở về đúng góc của \(S\) được!&lt;/p&gt;

&lt;h3 id=&quot;giải-thích-cầm-tay-so-sánh-mặt-nạ-thực-irm-và-mặt-nạ-phức-crm-trên-một-bin-stft-nhiễu&quot;&gt;Giải thích: Cầm tay so sánh Mặt nạ thực (IRM) và Mặt nạ phức (CRM) trên một bin STFT nhiễu&lt;/h3&gt;

&lt;p&gt;Xét đúng một ô thời gian–tần số STFT nơi tiếng nói sạch và nhiễu là hai số phức:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tiếng nói sạch: \(S = 3 + 4j\) (biên độ \(\vert S \vert = \sqrt{3^2 + 4^2} = 5\), pha \(\approx 53{,}1^\circ\)).&lt;/li&gt;
  &lt;li&gt;Nhiễu tại ô đó: \(N = 1 - 4j\) (biên độ \(\vert N \vert = \sqrt{17} \approx 4{,}12\), SNR cục bộ khoảng \(+1{,}7\text{ dB}\)).&lt;/li&gt;
  &lt;li&gt;Quan sát micro thu được:
\(Y = S + N = (3 + 1) + (4 - 4)j = 4 + 0j \qquad (\vert Y \vert = 4,\; \angle Y = 0^\circ).\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hãy thử khôi phục \(S\) bằng hai loại mặt nạ lý tưởng (oracle):&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Mặt nạ biên độ thực tốt nhất (Oracle Real Mask):&lt;/strong&gt;
Để khớp đúng biên độ \(\vert S \vert = 5\) từ \(\vert Y \vert = 4\), hệ số thực duy nhất là \(M_{\text{real}} = \frac{5}{4} = 1{,}25\).
    &lt;ul&gt;
      &lt;li&gt;Kết quả khôi phục: \(\hat{S}_{\text{real}} = 1{,}25 \times (4 + 0j) = 5 + 0j\).&lt;/li&gt;
      &lt;li&gt;Sai số phức còn lại:
\(\vert S - \hat{S}_{\text{real}} \vert = \vert (3 + 4j) - (5 + 0j) \vert = \vert -2 + 4j \vert = \sqrt{4 + 16} = \sqrt{20} \approx 4{,}47!\)
Dù đã biết trước biên độ sạch một cách hoàn hảo, sai số vẫn lên tới \(4{,}47\) (gần bằng cả biên độ tiếng nói \(5\)!) chỉ vì mặt nạ thực không thể xoay góc pha từ \(0^\circ\) lên \(53{,}1^\circ\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mặt nạ tỷ số phức (Oracle Complex Ratio Mask — CRM):&lt;/strong&gt;
\(M_{\text{CRM}} = \frac{S}{Y} = \frac{3 + 4j}{4} = 0{,}75 + 1{,}00j.\)
    &lt;ul&gt;
      &lt;li&gt;Kết quả khôi phục:
\(\hat{S}_{\text{CRM}} = (0{,}75 + 1{,}00j) \times 4 = 3 + 4j = S \implies \vert S - \hat{S}_{\text{CRM}} \vert = 0.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Phép nhân số phức đơn giản này là cốt lõi của cả kỷ nguyên tăng cường tiếng nói hiện đại: muốn khử nhiễu sâu ở SNR thấp mà giọng vẫn trong, mạng nơ-ron phải can thiệp được vào &lt;strong&gt;cả biên độ lẫn pha&lt;/strong&gt; — và DeepFilterNet ở bài 04-02 sẽ còn tiến thêm một bước bằng cách dùng bộ lọc phức &lt;em&gt;đa khung&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ phân biệt được masking, mapping và generative; tách bạch hàm mất mát phổ nén mà DeepFilterNet dùng khi huấn luyện với chỉ số SI-SDR dùng để báo cáo đánh giá; đồng thời phân biệt rõ độ trễ thuật toán với hệ số thời gian thực (real-time factor, RTF).&lt;/p&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Bước chuyển từ mặt nạ tỷ số lý tưởng (IRM) kiểu Wiener sang mặt nạ học sâu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — So sánh masking, mapping và generative; đối chiếu miền dạng sóng và miền STFT.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Quy trình trộn dữ liệu kiểu DNS và hàm mất mát trong bài báo DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Ràng buộc streaming: phân biệt độ trễ thuật toán 40 ms với RTF.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Mini-lab, các bẫy thường gặp và bài tập.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;mạng-nơ-ron-dự-đoán-đại-lượng-nào&quot;&gt;Mạng nơ-ron dự đoán đại lượng nào&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Tạo mặt nạ (Masking).&lt;/strong&gt; Mạng dự đoán mặt nạ \(M(k,\ell)\) rồi tính \(\hat{S}=M\odot Y\). Mặt nạ thực giữ nguyên pha của tín hiệu nhiễu. Mặt nạ tỷ số phức (Complex Ratio Mask, CRM) nhân cả phần thực lẫn phần ảo nên xoay được pha từng bin, nhưng vẫn chỉ là bộ lọc một tap (một hệ số tác động lên một bin). IRM phản ánh trực tiếp độ lợi Wiener \(\xi/(\xi+1)\) ở Chương 03. Bài báo ICASSP 2022 (arXiv:2110.05588) xem CRM như trường hợp riêng của deep filtering khi bậc \(N=1\) và độ nhìn trước \(\ell=0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Ánh xạ trực tiếp (Mapping).&lt;/strong&gt; Mạng dự đoán thẳng biên độ sạch hoặc phổ phức \(\hat{S}=f_\theta(Y)\). Vì không có cơ chế neo đầu ra quanh \(Y\), hàm mất mát thiếu chặt chẽ dễ làm mờ các họa âm thành một đường bao nhòe.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Mô hình sinh (Generative).&lt;/strong&gt; Các mô hình GAN hoặc khuếch tán (diffusion) lấy mẫu tiếng nói từ phân bố hậu nghiệm. Dù chất lượng cảm thụ có thể cao, toàn bộ mạng vẫn phải hoàn tất trong cùng một ngân sách hop khi chạy streaming. DeepFilterGAN (bài 04-04) chỉ được đề cập ở mức tên khảo sát trong khóa học này.&lt;/p&gt;

&lt;h3 id=&quot;miền-thời-gian-và-miền-phổ-đồ&quot;&gt;Miền thời gian và miền phổ đồ&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Họ mô hình&lt;/th&gt;
      &lt;th&gt;Đầu vào&lt;/th&gt;
      &lt;th&gt;Chi phí phải trả&lt;/th&gt;
      &lt;th&gt;Lợi thế đạt được&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Miền dạng sóng (kiểu Conv-TasNet)&lt;/td&gt;
      &lt;td&gt;Khung PCM&lt;/td&gt;
      &lt;td&gt;Bộ mã hóa học trực tiếp trên từng mẫu&lt;/td&gt;
      &lt;td&gt;Xử lý pha ngầm; chi phí rất cao ở 48 kHz toàn băng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mặt nạ STFT&lt;/td&gt;
      &lt;td&gt;Phổ đồ phức&lt;/td&gt;
      &lt;td&gt;Độ trễ tối thiểu một cửa sổ&lt;/td&gt;
      &lt;td&gt;Độ lợi dễ diễn giải; CRM khó tái tạo hài đã bị cửa sổ làm nhòe&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Độ lợi ERB + deep filter&lt;/td&gt;
      &lt;td&gt;32 băng ERB, kèm vài tap phức&lt;/td&gt;
      &lt;td&gt;Phải triển khai kiến trúc hai tầng&lt;/td&gt;
      &lt;td&gt;Điểm cân bằng hiệu quả của DeepFilterNet&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Ở tần số lấy mẫu 48 kHz, cửa sổ 20 ms (960 mẫu) cho khoảng cách giữa các bin là \(48000/960=50\) Hz. Mặt nạ từng điểm đơn thuần không thể tách nhiễu nằm xen giữa các họa âm mảnh hơn một bin — đó là lý do tầng thứ hai ra đời. Các mô hình toàn băng đã công bố chủ yếu chọn miền phổ đồ để phù hợp với ngân sách CPU.&lt;/p&gt;

&lt;h3 id=&quot;quy-trình-trộn-dữ-liệu-kiểu-dns-theo-số-liệu-bài-báo&quot;&gt;Quy trình trộn dữ liệu kiểu DNS (theo số liệu bài báo)&lt;/h3&gt;

&lt;p&gt;Framework ICASSP 2022 huấn luyện trên dữ liệu Deep Noise Suppression (DNS): hơn 750 giờ tiếng nói sạch toàn băng và 180 giờ nhiễu (VCTK và PTDB được lấy mẫu lặp 10 lần), trộn tối đa năm nguồn nhiễu tại các mức SNR trong \(\{-5,0,5,10,20,40\}\) dB, áp dụng bộ lọc bậc hai ngẫu nhiên, thay đổi độ lợi trong \(\{-6,0,6\}\) dB rồi tích chập với đáp ứng xung phòng. Tập huấn luyện bổ sung 10.000 đáp ứng xung phòng (RIR) mô phỏng theo phương pháp nguồn ảnh ở 48 kHz với RT60 từ 0,05 s đến 1,00 s. Do đó, một quán cà phê có RT60 vượt khoảng này hoặc một loại nhiễu không xuất hiện trong 180 giờ nói trên nằm ngoài phân bố đã học. DNSMOS (Chương 08) dùng để chấm điểm kết quả, nhưng thứ hạng bảng xếp hạng không đồng nghĩa với tiêu chuẩn triển khai sản phẩm.&lt;/p&gt;

&lt;h3 id=&quot;các-họ-hàm-mất-mát-và-hàm-mất-mát-thực-tế-của-deepfilternet&quot;&gt;Các họ hàm mất mát và hàm mất mát thực tế của DeepFilterNet&lt;/h3&gt;

&lt;p&gt;Các họ hàm mất mát phổ biến trong lĩnh vực này gồm MSE biên độ, sai số phổ phức, SI-SDR miền thời gian, STFT đa phân giải và bộ phân biệt đối kháng (adversarial critic). Lưu ý rằng công thức trong bài báo ICASSP 2022 &lt;strong&gt;không&lt;/strong&gt; huấn luyện trực tiếp bằng SI-SDR, mà sử dụng hàm mất mát phổ nén với số mũ \(c=0{,}6\):&lt;/p&gt;

\[\mathcal{L}_{\mathrm{spec}}=\sum_{k,f}\left\||Y|^{c}-|S|^{c}\right\|^{2}+\sum_{k,f}\left\||Y|^{c}e^{j\varphi_Y}-|S|^{c}e^{j\varphi_S}\right\|^{2},\]

&lt;p&gt;kèm một hạng phụ (trọng số \(0{,}05\)) kéo trọng số pha trộn của deep filter về 0 khi SNR cục bộ thấp hơn \(-10\) dB và về 1 khi SNR vượt trên \(-5\) dB. Trong bài báo đó, SI-SDR chỉ là chỉ số &lt;strong&gt;đánh giá&lt;/strong&gt;: đạt 16,63 dB cho mô hình đầy đủ trên VCTK/DEMAND so với 13,81 dB khi bỏ tầng 2 (WB-PESQ tương ứng là 2,81 so với 2,57). Chỉ trích dẫn các con số này gắn đúng với bảng kết quả, tập dữ liệu và checkpoint tương ứng.&lt;/p&gt;

&lt;h3 id=&quot;streaming-là-một-đồ-thị-xử-lý-khác-biệt&quot;&gt;Streaming là một đồ thị xử lý khác biệt&lt;/h3&gt;

&lt;p&gt;Một mô hình Transformer ngoại tuyến có thể áp dụng attention trên toàn bộ câu nói, nhưng một hop VoIP thì không. Bản demo năm 2023 (arXiv:2305.08227) dùng cửa sổ 20 ms, bước nhảy hop 10 ms và hai khung nhìn trước, tương ứng &lt;strong&gt;độ trễ thuật toán 40 ms&lt;/strong&gt;. Độ trễ này tách biệt hoàn toàn với RTF:&lt;/p&gt;

\[\mathrm{RTF}=\frac{T_{\mathrm{wall}}}{T_{\mathrm{audio}}}.\]

&lt;p&gt;Nếu CPU tiêu tốn 4 ms cho một hop 10 ms thì RTF bằng 0,4, trong khi người nghe vẫn chịu độ trễ thuật toán 40 ms. Tích chập nhân quả và trạng thái đơn vị hồi tiếp có cổng (GRU) kích thước cố định thay thế bộ nhớ đệm attention tăng dần theo độ dài câu. Chương 05 sẽ phân tích phân vị đuôi của \(T_{\mathrm{wall}}\): RTF trung bình 0,4 nhưng phân vị p95 vượt quá 1 vẫn gây vỡ tiếng.&lt;/p&gt;

&lt;h3 id=&quot;bản-đồ-vị-trí-các-hệ-thống-tiêu-biểu&quot;&gt;Bản đồ vị trí các hệ thống tiêu biểu&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; phức tạp thấp                         chất lượng cao hơn trên tập full-band đã công bố
     │                                              │
  RNNoise ── tên siêu nhẹ (04-05) ── DeepFilterNet / 2 / 3 ── tên khảo sát (04-04)
  22 băng Bark + GRU                 32 băng ERB + filter phức 5 tap
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;RNNoise (Valin, arXiv:1709.08243) dự đoán 22 hệ số độ lợi theo băng Bark bằng mạng GRU nhỏ kết hợp bộ lọc lược theo cao độ (pitch comb filter). DeepFilterNet dự đoán 32 độ lợi ERB rồi áp bộ lọc phức 5 tap trên các bin tần số thấp. Gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; vận hành đồ thị ONNX/WASM theo nhánh DF3 bên trong AudioWorklet (luồng render của Web Audio); gói này không cam kết khớp từng bit với checkpoint trong bài báo và không thuộc nhánh RNNoise (bài 04-06).&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Đặt điểm PESQ ngoại tuyến bên cạnh chỉ số RTF thời gian thực như hai thước đo cùng điều kiện.&lt;/li&gt;
  &lt;li&gt;Quy kết một đoạn ghi âm tàu điện ở −15 dB là lỗi mô hình khi tập huấn luyện chỉ trộn xuống tới −5 dB.&lt;/li&gt;
  &lt;li&gt;Chỉ kiểm tra phổ biên độ mà bỏ qua việc nghe thử để phát hiện lỗi giữ pha nhiễu.&lt;/li&gt;
  &lt;li&gt;Đồng nhất gói bọc npm với thuật toán cốt lõi — thực chất thuật toán nằm ở STFT, độ lợi ERB, các hệ số tap và quản lý trạng thái xuyên hop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Tính độ trễ thuật toán và RTF cho cấu hình công bố (cửa sổ 20 ms, hop 10 ms, nhìn trước 2 khung) để thấy rõ đây là hai đại lượng độc lập.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
window_ms, hop_ms, lookahead_frames = 20.0, 10.0, 2
# Published overall delay for this configuration: window plus two hops.
algo_ms = window_ms + lookahead_frames * hop_ms
wall_ms = 4.0  # one hop of steady compute on a laptop you just timed
rtf = wall_ms / hop_ms
print(f&quot;algorithmic_latency_ms={algo_ms:.1f}&quot;)
print(f&quot;rtf={rtf:.2f}&quot;)
print(&quot;latency_is_rtf&quot;, algo_ms == wall_ms)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;algorithmic_latency_ms=40.0&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf=0.40&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;latency_is_rtf False&lt;/code&gt;. Mốc 40 ms là độ trễ tổng thể công bố cho cấu hình cửa sổ và look-ahead này trong bài báo DeepFilterNet2 và bản demo 2023; mức thời gian xử lý thực tế 4 ms chỉ là con số giả định minh họa cho máy tính xách tay, không phải số đo trên điện thoại.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Coi bước nhảy hop là toàn bộ độ trễ (báo 10 ms mà bỏ qua cửa sổ 20 ms và 2 khung nhìn trước); chia thời gian xử lý thực tế cho độ dài cửa sổ thay vì cho hop (làm RTF giảm sai một nửa); hoặc mang RTF đo trên laptop áp vào ngân sách điện thoại.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Phân loại.&lt;/strong&gt; Xếp RNNoise, U-Net IRM biên độ, Conv-TasNet và DeepFilterNet vào các nhóm masking / mapping / generative và miền dạng sóng / STFT; nêu rõ mỗi hệ nhân hay lọc đại lượng nào.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ trễ.&lt;/strong&gt; Với cửa sổ 20 ms, hop 10 ms và nhìn trước 2 khung, độ trễ thuật toán trước khi đo thời gian chạy mạng nơ-ron là bao nhiêu? Nếu bộ đệm vòng tổng hợp giữ thêm một hop thì tăng thêm bao nhiêu?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hàm mất mát.&lt;/strong&gt; Quá trình huấn luyện dùng số mũ nén \(c=0{,}6\) trên biên độ kèm thành phần pha, trong khi bảng bài báo ghi SI-SDR đạt 16,63 dB. Chỉ số nào dùng để theo dõi khi huấn luyện, chỉ số nào chỉ dùng trên tập kiểm thử cố định?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dữ liệu.&lt;/strong&gt; Nêu một hiện tượng lỗi người dùng nghe thấy ứng với từng giới hạn dữ liệu: SNR chỉ xuống tới −5 dB, RT60 chỉ tới 1 s, và tập 180 giờ nhiễu thiếu tiếng gõ bàn phím.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;RNNoise: độ lợi băng thực (masking) trên lưới STFT/Bark kèm bộ lọc lược cao độ DSP; U-Net IRM: masking trên STFT; Conv-TasNet: cơ sở dạng sóng học được, gần hướng mapping; DeepFilterNet: mặt nạ ERB thực kết hợp bộ lọc phức nhiều tap trên STFT (không phải mô hình sinh).&lt;/li&gt;
  &lt;li&gt;Độ trễ thuật toán là \(20+2\times 10=40\) ms. Giữ thêm một hop trong bộ đệm vòng cộng thêm 10 ms độ trễ đệm nhưng không làm thay đổi RTF.&lt;/li&gt;
  &lt;li&gt;Theo dõi \(\mathcal{L}_{\mathrm{spec}}\) (cùng hạng phụ cổng) trong quá trình huấn luyện; chỉ báo cáo SI-SDR trên tập kiểm thử cố định vì bài báo đó không lấy SI-SDR làm hàm mục tiêu huấn luyện.&lt;/li&gt;
  &lt;li&gt;Nhiễu −15 dB rơi ngoài phạm vi trộn huấn luyện; phòng vang 1,5 s vượt quá dải RT60 0,05–1,00 s; xung gõ phím ngắn khác biệt với các đoạn nhiễu kéo dài trong tập 180 giờ.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter et al., ICASSP 2022, &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Schröter et al., DeepFilterNet2, IWAENC 2022, &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Schröter et al., Interspeech 2023, &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt; (README dự án gắn trích dẫn này với DeepFilterNet3). Kho mã nguồn: &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Valin, &lt;a href=&quot;https://arxiv.org/abs/1709.08243&quot;&gt;arXiv:1709.08243&lt;/a&gt;, &lt;a href=&quot;https://github.com/xiph/rnnoise&quot;&gt;xiph/rnnoise&lt;/a&gt;; tài liệu tổng quan DNS Challenge cho quy ước trộn dữ liệu.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày quá trình chuyển dịch từ bộ khử DSP sang mô hình học sâu, bao gồm hàm mất mát và quy trình kiểm thử chất lượng thực tế.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nsscrYdrGRE&quot;&gt;RNNoise, Neural Speech Enhancement, and the Browser&lt;/a&gt; — W3C, tiếng Anh. Minh họa mô hình lai giữa đặc trưng DSP và mạng hồi tiếp nhỏ, đại diện cho đầu gọn nhẹ trên bản đồ masking so với mapping.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Trình bày sự kết hợp giữa độ lợi đường bao thực và bộ lọc phức — hai cơ chế tăng cường mạng nơ-ron trọng tâm của bài.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-05 Beamforming / GSC / IVA như front-end</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter03/03_05_beamforming_frontends/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter03/03_05_beamforming_frontends</id>
   <content type="html">&lt;p&gt;Khi thiết bị có &lt;strong&gt;từ hai micro trở lên&lt;/strong&gt;, hình học mảng thu mang lại một lợi thế mà khử nhiễu đơn kênh không có: khả năng chọn lọc theo hướng không gian. Beamforming, bộ triệt búp phụ tổng quát (Generalized Sidelobe Canceller, GSC) và phân tích vector độc lập (Independent Vector Analysis, IVA) là các tầng tiền xử lý đa kênh cổ điển có thể cung cấp đầu vào sạch hơn cho bộ khử nhiễu mạng nơ-ron đơn kênh. Bài học này trình bày trực giác kỹ thuật về delay-and-sum, MVDR giản lược, ma trận chặn của GSC, IVA theo hướng tách nguồn mù, cùng các mô hình lai như GSC+DeepFilterNet2 hay IVA+GTCRN trong bối cảnh SNR thấp, drone hoặc thiết bị hai micro (ở mức định hướng khảo sát).&lt;/p&gt;

&lt;p&gt;Tại sao con người lại có &lt;strong&gt;hai&lt;/strong&gt; cái tai thay vì một? Không phải để nghe to gấp đôi, mà để biến &lt;em&gt;hình học không gian&lt;/em&gt; thành một bộ lọc vật lý: một âm thanh phát ra từ bên phải sẽ chạm vào tai phải sớm hơn tai trái khoảng vài trăm micro-giây. Khi một chiếc laptop, điện thoại hay loa thông minh sở hữu từ hai micro trở lên, ta có thể làm điều tương tự bằng toán học: tạo ra một “đèn pin âm học” chiếu thẳng vào miệng người nói và đẩy tiếng quạt hay tiếng người nói chuyện bên cạnh vào vùng tối — kỹ thuật gọi là &lt;strong&gt;tạo búp sóng (beamforming)&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-mảng-micro-hình-học-sóng-phẳng-và-lọc-không-gian&quot;&gt;Kiến thức cần nhớ: Mảng micro, hình học sóng phẳng và lọc không gian&lt;/h2&gt;

&lt;h3 id=&quot;1-độ-trễ-thời-gian-đến-tdoa-và-vector-lái-hướng-steering-vector&quot;&gt;1. Độ trễ thời gian đến (TDOA) và Vector lái hướng (Steering Vector)&lt;/h3&gt;
&lt;p&gt;Với hai micro đặt cách nhau khoảng cách \(d\) trong không khí (tốc độ âm thanh \(c \approx 343\text{ m/s}\)), một sóng phẳng đến từ góc lệch \(\theta\) so với phương trực diện phải đi thêm quãng đường \(\Delta r = d \sin\theta\) để tới micro thứ hai, tạo ra độ trễ \(\Delta\tau = \frac{d \sin\theta}{c}\). Trên miền tần số \(f\), độ trễ thời gian biến thành phép xoay pha \(e^{-j 2\pi f \Delta\tau}\). Xếp pha của tất cả \(M\) micro thành một cột ta thu được &lt;strong&gt;vector lái hướng&lt;/strong&gt; \(\mathbf{a}(\theta, f)\).&lt;/p&gt;

&lt;h3 id=&quot;2-từ-delay-and-sum-đến-mvdr-và-cấu-trúc-gsc&quot;&gt;2. Từ Delay-and-Sum đến MVDR và cấu trúc GSC&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Delay-and-Sum (DSB):&lt;/strong&gt; đơn giản bù lại đúng độ trễ của hướng mục tiêu \(\theta_s\) rồi cộng trung bình các micro. Tín hiệu mục tiêu cộng đồng pha nên giữ nguyên biên độ, còn nhiễu từ hướng khác lệch pha nên tự triệt tiêu một phần.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;MVDR (Minimum Variance Distortionless Response):&lt;/strong&gt; tối ưu vector trọng số phức \(\mathbf{w}(f)\) để cực tiểu hóa tổng công suất nhiễu đầu ra \(\mathbf{w}^H \mathbf{R}_{vv} \mathbf{w}\) với ràng buộc giữ nguyên hướng mục tiêu \(\mathbf{w}^H \mathbf{a}(\theta_s, f) = 1\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;GSC (Generalized Sidelobe Canceller):&lt;/strong&gt; viết lại bài toán tối ưu có ràng buộc MVDR thành hai nhánh song song dễ chạy thời gian thực: nhánh trên cố định hướng vào người nói, nhánh dưới dùng &lt;em&gt;ma trận chặn (blocking matrix)&lt;/em&gt; xóa người nói để chỉ lấy nhiễu tham chiếu rồi trừ dần khỏi nhánh trên.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-tách-nguồn-mù-đa-kênh-iva-và-giới-hạn-vật-lý-của-mảng-nhỏ&quot;&gt;3. Tách nguồn mù đa kênh (IVA) và giới hạn vật lý của mảng nhỏ&lt;/h3&gt;
&lt;p&gt;Khi không biết trước hướng người nói, &lt;strong&gt;IVA (Independent Vector Analysis)&lt;/strong&gt; khai thác giả định các nguồn âm độc lập thống kê nhau và liên kết các tần số của cùng một nguồn để tránh hoán vị tần số (&lt;em&gt;permutation problem&lt;/em&gt;). Tuy nhiên, vật lý sóng đặt ra một giới hạn cứng: khi bước sóng âm thanh \(\lambda = c/f\) lớn hơn nhiều so với khoảng cách micro \(d\) (ở tần số trầm), lệch pha giữa hai micro quá bé nên beamforming đơn thuần suy giảm mạnh — đó là lý do các hệ thống hiện đại ghép tiền xử lý không gian với hậu lọc mạng nơ-ron đơn kênh.&lt;/p&gt;

&lt;h3 id=&quot;giải-thích-cầm-tay-tính-độ-trễ-tdoa-và-kiểm-tra-điểm-mù-tần-số-trầm-của-mảng-2-micro-laptop&quot;&gt;Giải thích: Cầm tay tính độ trễ TDOA và kiểm tra “điểm mù tần số trầm” của mảng 2 micro laptop&lt;/h3&gt;

&lt;p&gt;Xét một chiếc laptop có 2 micro đặt cách nhau \(d = 4\text{ cm} = 0{,}04\text{ m}\), tốc độ âm thanh \(c = 343\text{ m/s}\), tần số lấy mẫu \(f_s = 48\,000\text{ Hz}\).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Người nói ngồi chính diện trước màn hình: \(\theta_s = 0^\circ \implies \Delta\tau_s = 0\).&lt;/li&gt;
  &lt;li&gt;Một nguồn nhiễu (quạt hoặc người nói chuyện) nằm lệch góc \(\theta_n = 30^\circ\):
    &lt;ul&gt;
      &lt;li&gt;Quãng đường chênh lệch: \(\Delta r = d \sin 30^\circ = 0{,}04 \times 0{,}5 = 0{,}02\text{ m}\).&lt;/li&gt;
      &lt;li&gt;Độ trễ thời gian đến (TDOA): \(\Delta\tau_n = \frac{0{,}02}{343} \approx 58{,}3\,\mu\text{s}\) (tương đương \(58{,}3 \times 10^{-6} \times 48\,000 \approx 2{,}8\) mẫu!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ta dùng bộ Delay-and-Sum hướng thẳng \(0^\circ\): \(y(t) = \frac{1}{2}[x_1(t) + x_2(t)]\). Biên độ đáp ứng theo tần số cho nguồn có độ trễ \(\Delta\tau\) là:
\(\vert H(f) \vert = \left\vert \frac{1 + e^{-j 2\pi f \Delta\tau}}{2} \right\vert = \vert \cos(\pi f \Delta\tau) \vert.\)&lt;/p&gt;

&lt;p&gt;Hãy thay số trực tiếp ở 2 tần số để thấy sức mạnh và điểm yếu của mảng 2 micro:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tại tần số cao \(f = 8\,575\text{ Hz}\):&lt;/strong&gt;
\(\pi f \Delta\tau_n = \pi \times 8\,575 \times \frac{0{,}02}{343} = \frac{\pi}{2}\text{ rad} \implies \vert H(8\,575\text{ Hz}) \vert = \left\vert \cos\!\left(\frac{\pi}{2}\right) \right\vert = 0.\)
Sóng nhiễu đến hai micro ngược pha nhau hoàn toàn (\(180^\circ\)) và &lt;strong&gt;tự triệt tiêu \(100\%\)&lt;/strong&gt; trong khi tiếng nói chính diện (\(\Delta\tau_s = 0\)) vẫn giữ nguyên độ lợi \(1{,}0\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tại tần số trầm \(f = 500\text{ Hz}\) (vùng năng lượng chính của giọng nói và tiếng ù):&lt;/strong&gt;
\(\pi f \Delta\tau_n \approx \pi \times 500 \times 58{,}3 \times 10^{-6} \approx 0{,}0916\text{ rad} \implies \vert H(500\text{ Hz}) \vert = \cos(0{,}0916) \approx 0{,}996 \quad (-0{,}04\text{ dB}).\)
Nhiễu \(500\text{ Hz}\) gần như đi qua nguyên vẹn vì bước sóng \(\lambda = 343/500 = 68{,}6\text{ cm}\) quá dài so với khoảng cách micro \(4\text{ cm}\). Con số \(0{,}996\) này giải thích trọn vẹn vì sao mảng 2 micro trên laptop không bao giờ thay thế được tầng khử nhiễu đơn kênh (như DeepFilterNet) ở dải tần thấp!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ giải thích được mục tiêu của delay-and-sum và MVDR bằng ngôn ngữ trực quan, phác thảo cấu trúc GSC (beamformer cố định + ma trận chặn + bộ hủy nhiễu thích nghi), tóm tắt vai trò tách nguồn mù đa kênh của IVA, và xác định khi nào kết hợp tầng tiền xử lý không gian với DeepFilterNet đơn kênh hiệu quả hơn chạy NS đơn kênh thuần túy.&lt;/p&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Tình huống mở đầu với laptop 2 micro: tách người nói mục tiêu khỏi nguồn nhiễu ở hướng khác.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Vector lái hướng (steering vector), delay-and-sum và bài toán tối ưu MVDR.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Cấu trúc GSC và vai trò triệt nhiễu của nhánh thích nghi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Định hướng IVA / tách nguồn mù (BSS) và kiến trúc lai tiền xử lý không gian + tinh chỉnh mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Các bẫy thường gặp, bài tập và thực tế sản phẩm (Mezon chủ yếu vẫn xử lý mono).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;mô-hình-không-gian-xấp-xỉ-trường-xa&quot;&gt;Mô hình không gian (xấp xỉ trường xa)&lt;/h3&gt;

&lt;p&gt;Với mảng gồm \(m=1\ldots M\) micro, một sóng phẳng đến từ hướng \(\theta\) tại tần số \(f\) được đặc trưng bởi &lt;strong&gt;vector lái hướng (steering vector)&lt;/strong&gt; \(\mathbf{a}(\theta,f)\). Vector phổ xếp chồng từ các micro có dạng:&lt;/p&gt;

\[\mathbf{y}(f,\ell)=\mathbf{a}(\theta,f)\,S(f,\ell)+\mathbf{v}(f,\ell).\]

&lt;p&gt;Đầu ra của beamformer tuyến tính là tổ hợp phức \(Z=\mathbf{w}^H\mathbf{y}\).&lt;/p&gt;

&lt;h3 id=&quot;delay-and-sum&quot;&gt;Delay-and-sum&lt;/h3&gt;

&lt;p&gt;Phương pháp này bù độ trễ (dịch pha) giữa các micro sao cho tín hiệu từ hướng mục tiêu cộng đồng pha rồi lấy trung bình. Kỹ thuật này cải thiện tốt với nhiễu &lt;strong&gt;không tương quan (incoherent)&lt;/strong&gt;, còn nhiễu giao thoa &lt;strong&gt;tương quan (coherent)&lt;/strong&gt; đến từ hướng khác chỉ giảm một phần. Đây là mốc đối chiếu nền tảng rất hữu ích khi giảng dạy và kiểm thử.&lt;/p&gt;

&lt;h3 id=&quot;mô-hình-giản-lược-mvdr&quot;&gt;Mô hình giản lược MVDR&lt;/h3&gt;

\[\min_{\mathbf{w}}\mathbf{w}^H\mathbf{R}_{yy}\mathbf{w}\quad\text{s.t.}\quad\mathbf{w}^H\mathbf{a}=1.\]

&lt;p&gt;Nghiệm chuẩn hóa \(\mathbf{w}\propto\mathbf{R}_{yy}^{-1}\mathbf{a}\) giữ nguyên độ lợi ở hướng mục tiêu đồng thời hướng vùng triệt tiêu (null) về phía nguồn nhiễu giao thoa. Thách thức lớn nhất trong thực tế là ước lượng ổn định ma trận hiệp phương sai \(\mathbf{R}\): chỉ cần lệch hướng lái (steering mismatch) sẽ dẫn tới &lt;strong&gt;tự triệt tiêu chính tín hiệu mục tiêu&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;cấu-trúc-gsc&quot;&gt;Cấu trúc GSC&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fixed beamformer (FBF)&lt;/strong&gt; — hướng búp chính về phía người nói mục tiêu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Blocking matrix (BM)&lt;/strong&gt; — chiếu vuông góc để loại bỏ tín hiệu mục tiêu, tạo ra tín hiệu tham chiếu “chỉ gồm nhiễu”.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive noise canceler&lt;/strong&gt; — dùng bộ lọc thích nghi NLMS/RLS để trừ phần nhiễu ước lượng từ nhánh BM khỏi đầu ra của FBF.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ưu điểm của GSC:&lt;/strong&gt; Nhánh thích nghi hoạt động không ràng buộc trên tín hiệu tham chiếu nhiễu và rất dễ kết hợp với VAD để đóng băng cập nhật mỗi khi người nói mục tiêu lên tiếng.&lt;/p&gt;

&lt;h3 id=&quot;iva-định-hướng-khảo-sát&quot;&gt;IVA (định hướng khảo sát)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;IVA&lt;/strong&gt; và các kỹ thuật tách nguồn mù (BSS) liên quan tách các nguồn âm từ hỗn hợp đa micro dựa trên tính độc lập thống kê mà không cần biết trước vector lái hướng tường minh. Ở phạm vi khóa học này, hãy nắm hai ý chính:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Xem IVA như một &lt;strong&gt;tầng tiền xử lý không gian mù&lt;/strong&gt; tạo ra ước lượng sơ bộ cho tín hiệu mục tiêu và nguồn nhiễu giao thoa.&lt;/li&gt;
  &lt;li&gt;Dùng một mạng gọn nhẹ (nhóm GTCRN) phía sau để tinh chỉnh đầu ra của IVA — đây là mẫu thiết kế phổ biến trong các bài báo xử lý hai kênh ở SNR thấp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;kiến-trúc-lai-kết-hợp-mạng-nơ-ron-đơn-kênh&quot;&gt;Kiến trúc lai kết hợp mạng nơ-ron đơn kênh&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;GSC → DeepFilterNet2&lt;/strong&gt;: hủy nhiễu có hướng (như tiếng cánh quạt drone) ở tầng không gian, sau đó DeepFilterNet2 dọn phần nhiễu khuếch tán còn sót.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;IVA → GTCRN&lt;/strong&gt;: tách nguồn mù đa kênh rồi tinh chỉnh bằng mạng CRN gọn nhẹ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chỉ dùng DF3 đơn kênh&lt;/strong&gt;: lựa chọn mặc định hợp lý khi \(M=1\) (phần lớn các tab trình duyệt).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ghi chú về Mezon:&lt;/strong&gt; Đường tích hợp npm/WASM mặc định là &lt;strong&gt;đơn kênh (mono)&lt;/strong&gt;. Xử lý đa micro thuộc phần mở rộng — học các tầng tiền xử lý không gian giúp bạn thiết kế pipeline ứng dụng native về sau mà không phải viết lại lõi mạng nơ-ron. Trong kiến trúc đó, beamformer đóng vai trò bộ lọc không gian đặt trước bộ xử lý đơn kênh: nhận nhiều micro, xuất ra một kênh duy nhất rồi mới đi vào bộ khử nhiễu theo bin. Hình dưới minh họa luồng xuất bản đơn kênh của sản phẩm (không chứa beamformer); nếu bổ sung, beamformer sẽ nằm ngay phía trước &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;Đường publish LiveKit qua DeepFilterNoiseFilterProcessor một kênh, chặng mà beamformer sẽ phải nuôi&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Sơ đồ luồng xuất bản đơn kênh; beamformer không nằm trong sơ đồ này mà sẽ đứng ngay trước &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; để bộ xử lý vẫn chỉ nhận đúng một kênh đầu vào.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;danh-mục-quyết-định-nhanh&quot;&gt;Danh mục quyết định nhanh&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;\(M=1\) → dùng NS đơn kênh (cổ điển hoặc mạng nơ-ron), bỏ qua beamforming.&lt;/li&gt;
  &lt;li&gt;\(M\ge 2\), biết rõ hướng mục tiêu và có nhiễu định hướng mạnh → chọn GSC hoặc MVDR.&lt;/li&gt;
  &lt;li&gt;\(M\ge 2\), không rõ hình học mảng hoặc người nói di chuyển → cân nhắc IVA hoặc beamforming thích nghi bền vững kết hợp mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;Ngân sách CPU rất hẹp → kết hợp delay-and-sum đơn giản với NS siêu nhẹ thay vì chạy IVA đầy đủ.&lt;/li&gt;
  &lt;li&gt;Lưu ý &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt; đôi khi đã bị hệ điều hành gộp sẵn thành mono — luôn kiểm tra số kênh thực tế nhận được.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Lệch vector lái hướng → &lt;strong&gt;tự triệt tiêu tiếng nói mục tiêu&lt;/strong&gt; (nghe giống như NS cắt mất giọng).&lt;/li&gt;
  &lt;li&gt;Để GSC thích nghi ngay lúc mục tiêu đang nói mà thiếu VAD → tiếng nói rò vào ma trận chặn BM và bị xóa ngược lại.&lt;/li&gt;
  &lt;li&gt;Mặc định cặp micro stereo trên laptop đã được hiệu chuẩn chính xác về mặt hình học.&lt;/li&gt;
  &lt;li&gt;Tính STFT đa kênh trên các micro bị lệch đồng hồ hoặc lệch trễ kênh (như thiết bị USB riêng lẻ).&lt;/li&gt;
  &lt;li&gt;Kỳ vọng beamforming tự xử lý được &lt;strong&gt;tiếng vọng&lt;/strong&gt; mà không cần tham chiếu far-end — hệ thống vẫn bắt buộc phải có AEC.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Tính độ trễ truyền âm trường xa giữa hai micro đặt cách nhau 2 cm tại góc thẳng đứng (broadside, 0°) và góc nghiêng 45°.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;343.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# mét, m/s, Hz
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;deg&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;tau&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;deg2rad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;deg&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tau&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;us&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tau&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;samples&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Tại góc broadside (0°): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.0 µs&lt;/code&gt;, tương đương &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.0&lt;/code&gt; mẫu. Tại góc 45°: khoảng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;41.2 µs&lt;/code&gt;, tương đương khoảng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.98&lt;/code&gt; mẫu ở 48 kHz. Có thể thấy delay-and-sum ở 48 kHz đòi hỏi phép dịch phân số mẫu (fractional delay) chứ không phải bộ lọc nhiều tap cỡ cả căn phòng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Truyền trực tiếp đơn vị độ vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.sin&lt;/code&gt; mà quên đổi sang radian sẽ cho kết quả vô nghĩa (góc 45° không còn gần 2 mẫu); quên nhân (\sin\theta) và lấy (d/c) cho mọi góc sẽ làm góc broadside cho kết quả giống góc dọc trục (endfire); nếu đổi sang 16 kHz thì góc 45° chỉ tương ứng khoảng 0.66 mẫu, nên giả định 48 kHz phải được thể hiện rõ trong mã nguồn.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Với mảng 2 micro cách nhau \(d=2\,\mathrm{cm}\), tần số \(f=2\,\mathrm{kHz}\) và tốc độ âm thanh \(c=343\,\mathrm{m/s}\), hãy tính độ trễ giữa hai micro ở góc broadside và góc 45°.&lt;/li&gt;
  &lt;li&gt;Vẽ sơ đồ khối GSC và đánh dấu rõ vị trí gắn bộ hậu lọc mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;Viết bản tóm tắt thiết kế dài một trang cho chế độ hai micro trên ứng dụng native: tái sử dụng mô hình DF3 ONNX đơn kênh và chỉ bổ sung thêm delay-and-sum ở phía trước.&lt;/li&gt;
  &lt;li&gt;Đọc tóm tắt (abstract) của một bài báo kiến trúc lai (GSC+DF2 hoặc IVA+GTCRN) và tóm lược trong 3 gạch đầu dòng phần đóng góp của tầng cổ điển so với tầng mạng nơ-ron.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Độ trễ ở góc broadside bằng 0; ở góc 45°, (\tau=d\sin\theta/c\approx 41.2\,\mu\mathrm{s}), tương đương gần 2 mẫu ở 48 kHz.&lt;/li&gt;
  &lt;li&gt;Bộ hậu lọc mạng nơ-ron được gắn ngay sau đầu ra đơn kênh của GSC (sau phép trừ của nhánh thích nghi).&lt;/li&gt;
  &lt;li&gt;Delay-and-sum gộp hai tín hiệu micro thành một dạng sóng đơn kênh duy nhất, nên đồ thị ONNX mono hiện có không cần thêm đầu vào thứ hai.&lt;/li&gt;
  &lt;li&gt;Tầng cổ điển khai thác thông tin không gian từ nhiều micro (tạo hướng triệt tiêu hoặc dùng tính độc lập thống kê), còn tầng mạng nơ-ron vẫn đóng vai trò bộ tăng cường đơn kênh xử lý phần nhiễu dư lọt qua tầng không gian.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Van Trees, &lt;em&gt;Optimum Array Processing&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Griffiths &amp;amp; Jim — bài báo kinh điển về cấu trúc GSC.&lt;/li&gt;
  &lt;li&gt;Tài liệu kỹ thuật xử lý đa micro của WebRTC và thiết bị di động.&lt;/li&gt;
  &lt;li&gt;Các mốc tham khảo kiến trúc lai: GSC–DeepFilterNet2 và IVA+GTCRN (ở mức khái niệm).&lt;/li&gt;
  &lt;li&gt;DeepFilterNet2 — ví dụ điển hình cho tầng mạng nơ-ron đơn kênh đặt &lt;em&gt;sau&lt;/em&gt; khâu lọc không gian.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=A1n5Hhwtz78&quot;&gt;What is Beamforming? (“the best explanation I’ve ever heard”)&lt;/a&gt; — Iain Explains Signals, Systems, and Digital Comms, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Minh họa cách căn chỉnh độ trễ theo một hướng trước khi cộng tín hiệu — đúng trực giác hình học của delay-and-sum làm nền cho GSC và IVA.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04 Ngữ cảnh AEC và WebRTC APM</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter03/03_04_aec_and_webrtc_apm/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter03/03_04_aec_and_webrtc_apm</id>
   <content type="html">&lt;p&gt;Khử tiếng vọng âm học (Acoustic Echo Cancellation, AEC) là bài toán đi liền với khử nhiễu: ở đây, thành phần gây nhiễu là bản sao đã qua lọc của &lt;strong&gt;tín hiệu đầu xa (far-end)&lt;/strong&gt; phát ra từ loa rồi dội ngược vào micro. Các hệ thống VoIP trên trình duyệt và ứng dụng native hầu như luôn chạy AEC &lt;strong&gt;trước&lt;/strong&gt; hoặc &lt;strong&gt;song song&lt;/strong&gt; với NS bên trong khối xử lý âm thanh. Bài học này đặt AEC vào đúng vị trí trong đồ thị cuộc gọi, phác thảo nguyên lý triệt vọng bằng bộ lọc thích nghi và giới thiệu &lt;strong&gt;WebRTC Audio Processing Module (APM)&lt;/strong&gt; như tiêu chuẩn công nghiệp bạn sẽ gặp khi tích hợp Mezon, LiveKit hoặc trình duyệt (Chương 07).&lt;/p&gt;

&lt;p&gt;Trong một cuộc gọi video không dùng tai nghe, không có gì gây ức chế bằng việc vừa nói xong nửa câu thì nghe chính giọng mình dội ngược lại sau nửa giây. Nếu khử nhiễu (NS) là bài toán “mù” — bạn không hề có bản ghi riêng của tiếng quạt hay tiếng xe cộ — thì &lt;strong&gt;khử tiếng vọng âm học (AEC)&lt;/strong&gt; lại có một lợi thế vàng: thiết bị của bạn &lt;em&gt;biết chính xác&lt;/em&gt; tín hiệu đầu xa \(x[t]\) mà nó vừa đẩy ra loa! Nhiệm vụ của AEC vì thế trở thành bài toán nhận dạng hệ thống theo thời gian thực: học bản sao đường truyền phòng \(\hat{\mathbf{h}}\), tự tổng hợp tiếng vọng dự đoán rồi trừ thẳng trước khi giọng nói đi vào tầng khử nhiễu.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-nhận-dạng-hệ-thống-thích-nghi-và-kiến-trúc-đường-ống-webrtc-apm&quot;&gt;Kiến thức cần nhớ: Nhận dạng hệ thống thích nghi và kiến trúc đường ống WebRTC APM&lt;/h2&gt;

&lt;h3 id=&quot;1-tích-chập-đường-vọng-và-bộ-lọc-thích-nghi-nlms&quot;&gt;1. Tích chập đường vọng và bộ lọc thích nghi NLMS&lt;/h3&gt;
&lt;p&gt;Âm thanh phát từ loa dội qua bàn, tường, trần nhà rồi mới tới micro; chuỗi phản xạ đó được mô tả bằng đáp ứng xung phòng \(\mathbf{h}\) (tích chập tuyến tính \(d[n] = (\mathbf{h} * \mathbf{x})[n]\)). Bộ lọc thích nghi kinh điển &lt;strong&gt;NLMS (Normalized Least Mean Squares)&lt;/strong&gt; cập nhật vector trọng số \(\mathbf{w}[n]\) bằng cách đi ngược hướng gradient của sai số tức thời \(e[n] = y[n] - \mathbf{w}[n]^T \mathbf{x}[n]\), có chuẩn hóa theo năng lượng đầu vào \(\|\mathbf{x}[n]\|^2\) để tốc độ hội tụ không bị bùng nổ khi loa phát to hay ì ạch khi loa phát nhỏ.&lt;/p&gt;

&lt;h3 id=&quot;2-bài-toán-nói-đè-double-talk-và-lý-do-bộ-lọc-thích-nghi-dễ-phát-điên&quot;&gt;2. Bài toán nói đè (Double-Talk) và lý do bộ lọc thích nghi dễ “phát điên”&lt;/h3&gt;
&lt;p&gt;Khi cả hai đầu cùng nói cùng lúc (&lt;em&gt;double-talk&lt;/em&gt;), tín hiệu micro \(y[n] = s[n] + d[n] + n[n]\) chứa giọng nói đầu gần \(s[n]\) rất lớn. Nếu bộ lọc thích nghi không biết mà vẫn cập nhật \(\mathbf{w}[n]\) theo sai số \(e[n]\) (vốn đang chứa đầy \(s[n]\)), nó sẽ phá hỏng hoàn toàn ước lượng đường phòng \(\mathbf{w}\) vừa học được! Do đó mọi bộ AEC thực tế (như WebRTC AEC3) đều cần cơ chế phát hiện nói đè (Double-Talk Detector) hoặc bước học thích nghi theo tỷ lệ năng lượng.&lt;/p&gt;

&lt;h3 id=&quot;3-vai-trò-của-webrtc-apm-và-phần-vọng-dư-phi-tuyến&quot;&gt;3. Vai trò của WebRTC APM và phần vọng dư phi tuyến&lt;/h3&gt;
&lt;p&gt;Trong các ứng dụng gọi điện hiện đại (trình duyệt, Mezon, LiveKit), &lt;strong&gt;WebRTC APM&lt;/strong&gt; xếp các khối theo thứ tự có chủ đích: lọc thông cao (HPF) bỏ rung ù tần số cực thấp → &lt;strong&gt;AEC&lt;/strong&gt; dùng tham chiếu loa để triệt vọng tuyến tính → &lt;strong&gt;NS&lt;/strong&gt; dọn nhiễu nền và &lt;strong&gt;vọng dư phi tuyến&lt;/strong&gt; (do loa laptop nhỏ bị bão hòa/rè, thứ mà bộ lọc tuyến tính \(\mathbf{h} * \mathbf{x}\) không bao giờ mô hình hóa hết được) → &lt;strong&gt;AGC&lt;/strong&gt; cân bằng âm lượng.&lt;/p&gt;

&lt;h3 id=&quot;giải-thích-cầm-tay-cập-nhật-1-bước-bộ-lọc-thích-nghi-nlms-và-tính-chỉ-số-erle&quot;&gt;Giải thích: Cầm tay cập nhật 1 bước bộ lọc thích nghi NLMS và tính chỉ số ERLE&lt;/h3&gt;

&lt;p&gt;Giả sử đường vọng thực của phòng được mô hình gọn bằng 2 tap \(\mathbf{h} = [0{,}5,\; -0{,}2]^T\). Tại thời điểm \(n\), loa đang phát vector tham chiếu \(\mathbf{x}[n] = [1{,}0,\; 0{,}5]^T\) và người dùng đầu gần đang im lặng (\(s[n] = 0\), bỏ qua nhiễu nhỏ):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tiếng vọng thực tế micro thu được:
\(d[n] = \mathbf{h}^T \mathbf{x}[n] = 0{,}5 \times 1{,}0 + (-0{,}2) \times 0{,}5 = 0{,}50 - 0{,}10 = 0{,}40.\)&lt;/li&gt;
  &lt;li&gt;Hiện tại, bộ lọc thích nghi mới ước lượng được \(\mathbf{w}[n] = [0{,}2,\; 0{,}0]^T\), nên tiếng vọng dự đoán là:
\(\hat{d}[n] = \mathbf{w}[n]^T \mathbf{x}[n] = 0{,}2 \times 1{,}0 + 0{,}0 \times 0{,}5 = 0{,}20.\)&lt;/li&gt;
  &lt;li&gt;Sai số dư (residual echo) còn sót lại:
\(e[n] = d[n] - \hat{d}[n] = 0{,}40 - 0{,}20 = +0{,}20.\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bước cập nhật NLMS&lt;/strong&gt; với tốc độ học \(\mu = 0{,}5\) (bỏ qua hằng số ổn định \(\epsilon \approx 0\)):&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Tính năng lượng tín hiệu tham chiếu:
\(\|\mathbf{x}[n]\|^2 = 1{,}0^2 + 0{,}5^2 = 1{,}00 + 0{,}25 = 1{,}25.\)&lt;/li&gt;
  &lt;li&gt;Tính lượng hiệu chỉnh trọng số:
\(\Delta \mathbf{w} = \frac{\mu}{\|\mathbf{x}[n]\|^2}\, e[n]\, \mathbf{x}[n] = \frac{0{,}5}{1{,}25} \times 0{,}20 \times \begin{bmatrix} 1{,}0 \\ 0{,}5 \end{bmatrix} = 0{,}08 \times \begin{bmatrix} 1{,}0 \\ 0{,}5 \end{bmatrix} = \begin{bmatrix} 0{,}08 \\ 0{,}04 \end{bmatrix}.\)&lt;/li&gt;
  &lt;li&gt;Trọng số mới:
\(\mathbf{w}[n+1] = \begin{bmatrix} 0{,}20 \\ 0{,}00 \end{bmatrix} + \begin{bmatrix} 0{,}08 \\ 0{,}04 \end{bmatrix} = \begin{bmatrix} 0{,}28 \\ 0{,}04 \end{bmatrix}.\)
Kiểm tra nhanh: nếu cùng vector \(\mathbf{x}\) lặp lại ngay sau đó, tiếng vọng dự đoán tăng lên \(0{,}28(1{,}0) + 0{,}04(0{,}5) = 0{,}30\), kéo sai số từ \(0{,}20\) giảm ngay một nửa xuống \(0{,}10\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Đo chất lượng triệt vọng bằng ERLE (Echo Return Loss Enhancement):&lt;/strong&gt;
Sau khi hội tụ, giả sử công suất tiếng vọng thu vào là \(P_d = 0{,}16\) còn công suất vọng dư sau AEC chỉ còn \(P_e = 0{,}0016\):
\(\mathrm{ERLE} = 10\log_{10}\!\left(\frac{P_d}{P_e}\right) = 10\log_{10}\!\left(\frac{0{,}16}{0{,}0016}\right) = 10\log_{10}(100) = 20\text{ dB}.\)
Trong thực tế, một bộ AEC tuyến tính tốt đạt ERLE khoảng \(15\text{–}25\text{ dB}\); phần vọng dư phi tuyến còn lại sẽ được tầng hậu lọc NS (hoặc DeepFilterNet) dọn nốt.&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ vẽ được luồng tín hiệu đầu gần (near-end) và đầu xa (far-end) với đường vọng \(\mathbf{h}\), giải thích được vì sao bộ lọc thích nghi có tín hiệu tham chiếu khác biệt với khử nhiễu mù, liệt kê các khối chính trong WebRTC APM (AEC, NS, AGC, HPF, VAD), và phân tích các ràng buộc thực tế (độ trễ, lệch đồng hồ, méo phi tuyến) khiến tiếng vọng dư tràn sang tầng NS.&lt;/p&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Phân biệt tiếng vọng và nhiễu nền qua nghe trực tiếp; xác định tín hiệu tham chiếu far-end.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Mô hình \(y=s+\mathbf{h}*\mathbf{x}+n\) và bài toán ước lượng \(\hat{\mathbf{h}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Tổng quan pipeline WebRTC APM (ở mức khối khái niệm).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Tiếng vọng dư sau AEC và lý do vẫn cần NS hoặc bộ hậu lọc mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Các bẫy thường gặp, bài tập và danh mục kiểm tra khi tích hợp sản phẩm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;tiếng-vọng-là-nhiễu-có-cấu-trúc&quot;&gt;Tiếng vọng là “nhiễu có cấu trúc”&lt;/h3&gt;

\[y[t]=s[t]+\underbrace{(h*x)[t]}_{\text{echo}}+n[t],\]

&lt;p&gt;trong đó \(x[t]\) là tín hiệu đầu xa (thiết bị phát đã biết trước), còn \(h\) là đường truyền âm học của tiếng vọng (phòng + loa + micro). Khối AEC ước lượng \(\hat{h}\) và tính tín hiệu sai số (phần dư):&lt;/p&gt;

\[e[t]=y[t]-(\hat{h}*x)[t].\]

&lt;p&gt;Khi \(\hat{h}\approx h\) và đường vọng tuyến tính biến đổi chậm, ta thu được \(e\approx s+n\), cho phép tầng NS phía sau tập trung xử lý nhiễu nền \(n\).&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;far-end x ──► loa ──► phòng h ──► mic y
near-end s ─────────────────────► mic y
nhiễu nền n ────────────────────► mic y
AEC:  e = y − ĥ ∗ x
NS:   chạy trên e, không chạy trên y thô
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Chính phần dư sau phép trừ này mới là đầu vào thực tế của bộ khử nhiễu phía sau. Khi bộ hủy vọng hoạt động đúng, (e) có dạng hỗn hợp cộng tính như hình minh họa: tiếng nói đầu gần cộng với phần chưa bị triệt tiêu (nhiễu nền và tiếng vọng dư nhỏ hơn). Lưu ý hình minh họa chỉ biểu diễn hỗn hợp cộng tính đó chứ không vẽ đường truyền âm học trong phòng.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/noise-mixture.png&quot; alt=&quot;Tiếng sạch, nhiễu cộng, và tổng của chúng — dạng phần dư sau khi echo đã bị trừ&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Sau bước AEC tuyến tính, phần dư có dạng hỗn hợp cộng tính giữa tiếng nói đầu gần và các thành phần chưa hủy hết; sơ đồ này minh họa hỗn hợp cộng tính đó chứ không mô tả đường truyền tiếng vọng.&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;trực-giác-về-bộ-lọc-thích-nghi-nlms&quot;&gt;Trực giác về bộ lọc thích nghi (NLMS)&lt;/h3&gt;

&lt;p&gt;Một bộ lọc FIR độ dài \(L\) cập nhật trọng số theo quy tắc NLMS:&lt;/p&gt;

\[\mathbf{h}_{\ell+1}=\mathbf{h}_\ell+\mu\frac{e_\ell\,\mathbf{x}_\ell}{\|\mathbf{x}_\ell\|^2+\varepsilon}.\]

&lt;p&gt;Các bộ lọc thích nghi miền tần số dạng chia khối (partitioned-block, phổ biến trong AEC của WebRTC) vận hành trên cùng ý tưởng nhưng kiểm soát độ phức tạp và độ trễ tốt hơn. &lt;strong&gt;Liên hệ với Kalman (bài 03-03):&lt;/strong&gt; thay vì dùng bước học vô hướng \(\mu\), bộ lọc Kalman điều chỉnh bước cập nhật theo ma trận hiệp phương sai.&lt;/p&gt;

&lt;h3 id=&quot;so-sánh-aec-và-ns&quot;&gt;So sánh AEC và NS&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tiêu chí&lt;/th&gt;
      &lt;th&gt;AEC&lt;/th&gt;
      &lt;th&gt;NS&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Tín hiệu tham chiếu&lt;/td&gt;
      &lt;td&gt;Bắt buộc có far-end \(x\)&lt;/td&gt;
      &lt;td&gt;Thường là ước lượng mù&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Thành phần cần loại bỏ&lt;/td&gt;
      &lt;td&gt;Tiếng vọng \(h*x\)&lt;/td&gt;
      &lt;td&gt;Nhiễu nền và tạp âm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Nguyên nhân dễ lỗi&lt;/td&gt;
      &lt;td&gt;Lệch trễ, nói chồng (double-talk), méo phi tuyến của loa&lt;/td&gt;
      &lt;td&gt;Nhiễu không dừng, méo nhiễu nhạc&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Vị trí trong chuỗi&lt;/td&gt;
      &lt;td&gt;Đầu APM&lt;/td&gt;
      &lt;td&gt;Sau AEC / kết hợp khử vọng dư&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Tình huống nói chồng (&lt;strong&gt;double-talk&lt;/strong&gt; — cả hai đầu gần và đầu xa nói cùng lúc) là phép thử khắc nghiệt nhất của AEC: bộ lọc thích nghi bắt buộc phải đóng băng hoặc giảm mạnh tốc độ cập nhật để không phá hỏng ước lượng đường vọng.&lt;/p&gt;

&lt;h3 id=&quot;mô-hình-khái-niệm-của-webrtc-apm&quot;&gt;Mô hình khái niệm của WebRTC APM&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;High-pass (HPF)&lt;/strong&gt; — loại bỏ thành phần DC và tiếng ù tần số cực thấp.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Echo canceller (AEC / AECM)&lt;/strong&gt; — hủy vọng theo tham chiếu; thiết bị di động có thể dùng biến thể nhẹ hơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Noise suppression (NS)&lt;/strong&gt; — khử nhiễu phổ / Wiener cổ điển (cho phép chọn mức cường độ).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;AGC&lt;/strong&gt; — tự động điều chỉnh âm lượng (rất dễ xung đột với NS nếu đặt sai thứ tự).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;VAD / các mô-đun mở rộng&lt;/strong&gt; — tùy cờ biên dịch.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thứ tự và tên cụ thể có thể thay đổi giữa các phiên bản WebRTC; hãy xem danh sách trên là &lt;strong&gt;sơ đồ kiến trúc khái niệm&lt;/strong&gt; và đối chiếu tài liệu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioProcessing&lt;/code&gt; khi tích hợp thực tế.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liên hệ với sản phẩm:&lt;/strong&gt; Mezon và nhiều ứng dụng LiveKit/WebRTC kết hợp AEC sẵn có của trình duyệt &lt;strong&gt;với&lt;/strong&gt; bộ khử nhiễu mạng nơ-ron (như DeepFilterNet3 qua AudioWorklet). Khi tích hợp, cần xác minh AEC đã thực sự hoạt động chưa, tiếng vọng dư còn đáng kể không, và mô hình NS có được huấn luyện để xử lý vọng dư như “nhiễu” hay không.&lt;/p&gt;

&lt;h3 id=&quot;tiếng-vọng-dư-và-bộ-hậu-lọc-mạng-nơ-ron&quot;&gt;Tiếng vọng dư và bộ hậu lọc mạng nơ-ron&lt;/h3&gt;

&lt;p&gt;AEC tuyến tính vẫn để lại tiếng vọng dư khi loa méo phi tuyến, ước lượng độ trễ bị lệch (ví dụ tai nghe Bluetooth), lệch đồng hồ giữa phát và thu, hoặc đường vọng \(h\) thay đổi nhanh. Các nghiên cứu kiến trúc lai (như ULCNet + bộ lọc thích nghi) huấn luyện mạng gọn nhẹ trực tiếp trên &lt;strong&gt;phần dư của AEC&lt;/strong&gt;. Trong thực hành, hãy đo chỉ số suy hao vọng ERLE trước và sau AEC; nếu vẫn nghe rõ tiếng vọng dư, cần sửa khâu căn chỉnh độ trễ hoặc bổ sung bộ khử vọng dư chuyên dụng thay vì chỉ trông chờ vào NS thông thường.&lt;/p&gt;

&lt;h2 id=&quot;danh-mục-kiểm-tra-tích-hợp&quot;&gt;Danh mục kiểm tra tích hợp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Xác nhận tín hiệu tham chiếu far-end thực sự được cấp vào khối AEC.&lt;/li&gt;
  &lt;li&gt;Đo độ trễ đệm vòng và căn chỉnh thời gian của tín hiệu tham chiếu.&lt;/li&gt;
  &lt;li&gt;Kiểm thử bằng các đoạn mẫu &lt;strong&gt;nói chồng (double-talk)&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Xác định rõ vị trí chèn NS: bên trong APM, ngay sau PCM của APM hay trong AudioWorklet mạng nơ-ron (Chương 05, 07).&lt;/li&gt;
  &lt;li&gt;Tắt các khối AGC trùng lặp để tránh chúng điều chỉnh chồng chéo lẫn nhau.&lt;/li&gt;
  &lt;li&gt;Phân loại phản hồi người dùng theo nhóm tiếng vọng hay nhiễu nền để định tuyến gỡ lỗi đúng giữa AEC và NS.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Chạy NS mạng nơ-ron trực tiếp trên tín hiệu còn nguyên tiếng vọng lớn → bộ khử sẽ đè mạnh giọng người nói đầu gần mỗi khi đầu xa phát tiếng.&lt;/li&gt;
  &lt;li&gt;Mặc định rằng AEC của trình duyệt luôn hoạt động ổn định mà không kiểm thử các đặc thù trên thiết bị di động.&lt;/li&gt;
  &lt;li&gt;Huấn luyện và đánh giá NS thuần túy trên nhiễu cộng tính DNS rồi triển khai trên laptop dùng loa ngoài đầy tiếng vọng.&lt;/li&gt;
  &lt;li&gt;Đặt AGC trước AEC khiến hệ số khuếch đại làm biến thiên liên tục đường vọng.&lt;/li&gt;
  &lt;li&gt;Nhầm lẫn giữa tiếng vọng &lt;strong&gt;âm học (acoustic echo)&lt;/strong&gt; với tiếng vọng &lt;strong&gt;đường dây (line echo)&lt;/strong&gt; ở cổng điện thoại.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Mô phỏng định lượng sự khác biệt giữa công suất tiếng vọng dư thực sự và công suất lỗi đo được, đặc biệt ở khung có nói chồng (double-talk). Lưu ý đoạn mã này chỉ minh họa khái niệm, không gọi WebRTC hay Audio Processing Module.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;far&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;near&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# double-talk chỉ ở frame 3
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.45&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;residual_echo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hhat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;far&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;near&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;residual_echo&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;residual echo power&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_echo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;measured error power&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Công suất vọng dư giữ ở mức nhỏ: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0, 0.0001, 0.0025, 0.0025, 0.0002, 0.0036]&lt;/code&gt;. Công suất lỗi đo được trùng khớp ở mọi khung trừ khung 3, nơi giọng nói đầu gần đẩy tổng công suất lên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.7225&lt;/code&gt; dù vọng dư thực sự vẫn chỉ là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.0025&lt;/code&gt;. Nếu tiếp tục cập nhật (\hat{h}) tại khung này, bộ lọc sẽ nhầm giọng người nói là tiếng vọng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Nếu hai mảng công suất trùng nhau ở khung 3 thì &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;near&lt;/code&gt; vẫn bằng 0 và chưa có tình huống double-talk; nếu công suất vọng dư lớn ở mọi khung có tín hiệu far-end thì ước lượng (\hat{h}) đang lệch xa (h); dùng trực tiếp công suất lỗi làm nền nhiễu cho độ lợi Wiener sẽ đè mất giọng đầu gần.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Vẽ sơ đồ luồng thu (capture), phát (render), \(\hat{h}\), \(e\) và NS, đánh dấu rõ vị trí chèn AudioWorklet mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;Giải thích điều gì xảy ra với bộ lọc NLMS khi tín hiệu tham chiếu bị sớm hoặc muộn 40 ms so với tiếng vọng thực thu ở micro.&lt;/li&gt;
  &lt;li&gt;Tra cứu tài liệu WebRTC APM và liệt kê tên các tùy chọn bật/tắt AEC và mức cường độ NS.&lt;/li&gt;
  &lt;li&gt;Viết quy trình hỗ trợ chẩn đoán nhanh (playbook): từ triệu chứng người dùng báo → khoanh vùng AEC/NS/AGC → bước kiểm tra đầu tiên.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Khối NS mạng nơ-ron đặt trên tín hiệu dư (e) ngay sau (\hat{h}); trên trình duyệt, vị trí này thường nằm sau AEC của nền tảng và trước bộ mã hóa.&lt;/li&gt;
  &lt;li&gt;Độ lệch 40 ms đẩy tiếng vọng ra ngoài cửa sổ các hệ số tap đang ước lượng (h), khiến (e) vẫn còn nguyên tiếng vọng và bộ lọc thích nghi hội tụ sai độ trễ.&lt;/li&gt;
  &lt;li&gt;Tra cứu cấu hình mức NS và công tắc AEC trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioProcessing&lt;/code&gt;; vì tên trường có thể đổi giữa các bản phát hành, cần ghi lại mã phiên bản tài liệu đã đối chiếu.&lt;/li&gt;
  &lt;li&gt;Đầu xa nói trong khi đầu gần im là bài kiểm tra AEC; đầu gần nói trong môi trường ồn khi đầu xa im là bài kiểm tra NS; âm lượng nhảy đột ngột khi một phía ngừng nói thường xuất phát từ AGC.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Tài liệu WebRTC Audio Processing Module và API &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioProcessing&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Bộ khử vọng và tiền xử lý SpeexDSP.&lt;/li&gt;
  &lt;li&gt;Haykin, &lt;em&gt;Adaptive Filter Theory&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;Các mốc kiến trúc lai AENR: ULCNet + bộ lọc thích nghi và Align-ULCNet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Revamping Audio Quality for RTC Part 1: Beryl Echo Cancellation&lt;/td&gt;
          &lt;td&gt;Sriram Srinivasan and Hoang Do](https://www.youtube.com/watch?v=lapq9zvUd-k) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Minh họa đường truyền từ loa đến micro và vị trí đặt khối khử vọng trong chuỗi âm thanh thời gian thực — đúng ngữ cảnh WebRTC APM của bài.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Phần bàn về tiếng vọng cho thấy AEC và NS là hai bài toán kế cận nhau, lý giải vì sao không thể gộp chung thành một công tắc duy nhất.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-03 Theo dõi kiểu Kalman (trực giác)</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter03/03_03_kalman_tracking/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter03/03_03_kalman_tracking</id>
   <content type="html">&lt;p&gt;Bộ lọc Kalman không phải là “một dạng mặt nạ phổ khác” mà là một &lt;strong&gt;bộ theo dõi Bayes đệ quy&lt;/strong&gt;: ở mỗi bước, nó dự đoán trạng thái tiếng nói tiếp theo rồi hiệu chỉnh lại dựa trên phép đo có nhiễu mới nhận được. Trong tăng cường tiếng nói (SE) và khử vọng (AEC), tư duy Kalman xuất hiện ở các bộ lọc thích nghi, bộ theo dõi tiếng vọng dư và các kiến trúc lai AEC+NS (ví dụ AEC Kalman cổ điển nối tiếp bộ hậu lọc mạng nơ-ron gọn nhẹ). Bài học này dừng ở mức &lt;strong&gt;trực giác và sơ đồ khối&lt;/strong&gt; — đủ để đọc bài báo và gỡ lỗi hệ thống lai — mà không đi sâu vào lý thuyết điều khiển tổng quát.&lt;/p&gt;

&lt;p&gt;Hãy tưởng tượng bạn đang theo dõi vị trí một con tàu giữa biển sương mù bằng chiếc radar bị nhiễu nặng. Nếu chỉ tin hoàn toàn vào chấm sáng nhảy nhót trên màn hình radar ở giây hiện tại, con tàu trông như đang dịch chuyển tức thời; nhưng nếu bạn nhớ vận tốc con tàu ở giây trước để &lt;em&gt;dự đoán&lt;/em&gt; nó sẽ ở đâu, rồi chỉ &lt;em&gt;kéo nhẹ&lt;/em&gt; dự đoán đó về phía chấm radar mới theo mức độ tin cậy của radar, quỹ đạo ước lượng sẽ mượt mà đến kinh ngạc. Đó chính là linh hồn của &lt;strong&gt;bộ lọc Kalman&lt;/strong&gt; — không phải một chiếc mặt nạ cắt phổ độc lập từng khung, mà là một cỗ máy suy luận Bayes đệ quy biết cân đo đong đếm giữa &lt;em&gt;niềm tin vào mô hình quá khứ&lt;/em&gt; và &lt;em&gt;bằng chứng từ phép đo nhiễu hiện tại&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-không-gian-trạng-thái-và-suy-luận-bayes-đệ-quy&quot;&gt;Kiến thức cần nhớ: Không gian trạng thái và suy luận Bayes đệ quy&lt;/h2&gt;

&lt;h3 id=&quot;1-mô-hình-không-gian-trạng-thái-state-space-model&quot;&gt;1. Mô hình không gian trạng thái (State-Space Model)&lt;/h3&gt;
&lt;p&gt;Thay vì coi mỗi khung âm thanh là một ốc đảo tách biệt, bộ lọc Kalman mô tả tín hiệu ẩn \(x_k\) (có thể là mẫu tiếng nói theo mô hình tự hồi quy AR, hoặc vector đáp ứng xung đường vọng \(\mathbf{h}_k\)) tiến hóa theo thời gian qua hai phương trình:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Phương trình trạng thái (động học):&lt;/strong&gt; \(x_k = A x_{k-1} + w_k\), với nhiễu quá trình \(w_k \sim \mathcal{N}(0, Q)\) đo mức độ “thay đổi bất ngờ” của trạng thái.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phương trình quan sát (phép đo):&lt;/strong&gt; \(y_k = H x_k + v_k\), với nhiễu đo \(v_k \sim \mathcal{N}(0, R)\) đo độ ồn của micro.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-độ-lợi-kalman-kalman-gain--chiếc-cân-tự-động-giữa-mô-hình-và-dữ-liệu&quot;&gt;2. Độ lợi Kalman (Kalman Gain) — chiếc cân tự động giữa mô hình và dữ liệu&lt;/h3&gt;
&lt;p&gt;Ở mỗi bước, thuật toán chạy đúng hai pha: &lt;strong&gt;Dự đoán (Predict)&lt;/strong&gt; đẩy ước lượng cũ và độ bất định \(P\) về phía trước; sau đó &lt;strong&gt;Cập nhật (Update)&lt;/strong&gt; tính sai lệch bất ngờ (&lt;em&gt;innovation&lt;/em&gt;) \(e_k = y_k - H \hat{x}_{k\vert k-1}\) và nhân với &lt;strong&gt;độ lợi Kalman&lt;/strong&gt; \(K_k\). Khi phép đo rất ồn (\(R \gg P\)), \(K_k \to 0\) (tin vào dự đoán hơn); ngược lại khi trạng thái biến đổi mạnh còn phép đo sạch (\(P \gg R\)), \(K_k \to 1\) (bám sát phép đo mới).&lt;/p&gt;

&lt;h3 id=&quot;3-vì-sao-kalman-sống-khỏe-trong-các-hệ-thống-aecns-lai-hiện-đại&quot;&gt;3. Vì sao Kalman sống khỏe trong các hệ thống AEC+NS lai hiện đại?&lt;/h3&gt;
&lt;p&gt;Khử vọng tuyến tính (AEC) có cấu trúc vật lý rõ ràng: đáp ứng xung phòng thay đổi chậm theo thời gian (trừ khi có người di chuyển hoặc đổi vị trí loa), cực kỳ hợp với bộ lọc Kalman miền tần số (như trong kiến trúc của Enzner &amp;amp; Vary). Một tầng Kalman gọn nhẹ có thể triệt sạch phần vọng tuyến tính ổn định mà không cần học lại từ đầu, để phần việc khó còn lại (vọng phi tuyến do loa rè, nhiễu nền không dừng) cho một mạng nơ-ron nhỏ gọn phía sau xử lý.&lt;/p&gt;

&lt;h3 id=&quot;giải-thích-cầm-tay-chạy-1-chu-kỳ-dự-đoán--cập-nhật-của-bộ-lọc-kalman-vô-hướng&quot;&gt;Giải thích: Cầm tay chạy 1 chu kỳ Dự đoán – Cập nhật của bộ lọc Kalman vô hướng&lt;/h3&gt;

&lt;p&gt;Xét một bài toán 1 chiều theo dõi biên độ trạng thái tiếng nói \(x_k\) với mô hình tự hồi quy bậc 1:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Động học: \(x_k = 0{,}9\,x_{k-1} + w_k\), phương sai nhiễu quá trình \(Q = 0{,}09\).&lt;/li&gt;
  &lt;li&gt;Phép đo có nhiễu: \(y_k = x_k + v_k\) (\(H = 1\)), phương sai nhiễu đo \(R = 0{,}50\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Giả sử ở bước trước (\(k-1\)), ta đã có ước lượng hậu nghiệm \(\hat{x}_{k-1\vert k-1} = 2{,}00\) với phương sai sai số \(P_{k-1\vert k-1} = 0{,}20\). Nay micro thu được mẫu nhiễu mới \(y_k = 2{,}60\). Hãy tính tay từng bước:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Dự đoán (Predict):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Trạng thái dự đoán: \(\hat{x}_{k\vert k-1} = 0{,}9 \times 2{,}00 = 1{,}80\).&lt;/li&gt;
      &lt;li&gt;Phương sai bất định dự đoán: \(P_{k\vert k-1} = 0{,}9^2 \times 0{,}20 + Q = 0{,}81 \times 0{,}20 + 0{,}09 = 0{,}162 + 0{,}09 = 0{,}252\).
&lt;em&gt;(Lưu ý: sau bước dự đoán, độ bất định tăng từ \(0{,}20\) lên \(0{,}252\) vì ta chưa nhìn thấy phép đo mới.)&lt;/em&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bước 2 — Tính độ lợi Kalman (Kalman Gain):&lt;/strong&gt;
\(K_k = \frac{P_{k\vert k-1}}{P_{k\vert k-1} + R} = \frac{0{,}252}{0{,}252 + 0{,}50} = \frac{0{,}252}{0{,}752} \approx 0{,}335.\)
Vì nhiễu đo \(R = 0{,}50\) lớn gần gấp đôi bất định dự đoán \(P^- = 0{,}252\), bộ lọc chỉ đặt niềm tin khoảng \(33{,}5\%\) vào phép đo mới.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 3 — Cập nhật trạng thái và thu hẹp độ bất định (Update):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Phần bất ngờ (innovation): \(y_k - \hat{x}_{k\vert k-1} = 2{,}60 - 1{,}80 = +0{,}80\).&lt;/li&gt;
      &lt;li&gt;Ước lượng hậu nghiệm mới: \(\hat{x}_{k\vert k} = 1{,}80 + 0{,}335 \times 0{,}80 = 1{,}80 + 0{,}268 = 2{,}068\).&lt;/li&gt;
      &lt;li&gt;Phương sai hậu nghiệm mới: \(P_{k\vert k} = (1 - K_k)\,P_{k\vert k-1} = 0{,}665 \times 0{,}252 \approx 0{,}168\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Kiểm chứng trực giác: kết quả \(2{,}068\) nằm gọn giữa dự đoán \(1{,}80\) và phép đo ồn \(2{,}60\) (nghiêng về phía dự đoán vì radar đang ồn), đồng thời độ bất định giảm từ \(0{,}252\) xuống \(0{,}168\) — mỗi phép đo mới, dù ồn, vẫn cung cấp thêm thông tin để làm sắc nét ước lượng!&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ giải thích được vòng lặp dự đoán–cập nhật (predict–update) cùng vai trò của hiệp phương sai nhiễu quá trình và nhiễu đo, ánh xạ bài toán SE sang mô hình không gian trạng thái, so sánh Kalman với độ lợi Wiener theo từng khung, và nhận diện mô hình triển khai thực tế: dùng Kalman/LMS/RLS làm tầng tiền xử lý cho bộ khử phần dư bằng mạng nơ-ron.&lt;/p&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Vì sao theo dõi đệ quy hiệu quả hơn việc ước lượng lại từ đầu ở mỗi khung.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Mô hình không gian trạng thái, bước dự đoán và trực giác về độ lợi Kalman (Kalman gain).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Ứng dụng trong tiếng nói và AEC: theo dõi hệ số AR hoặc đáp ứng xung đường vọng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Kiến trúc lai: AEC Kalman kết hợp hậu lọc mạng nơ-ron (các mốc tham khảo).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Các bẫy thường gặp, bài tập và cầu nối sang WebRTC APM (bài 03-04).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;nguyên-lý-kalman-tóm-gọn&quot;&gt;Nguyên lý Kalman tóm gọn&lt;/h3&gt;

&lt;p&gt;Hệ thống duy trì một ước lượng kèm độ bất định về trạng thái ẩn \(x_\ell\) (có thể là mẫu tiếng nói sạch, hệ số LPC hoặc đáp ứng xung đường vọng). Tại mỗi khung:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Dự đoán (Predict)&lt;/strong&gt; theo mô hình động học: $$x_{\ell&lt;/td&gt;
          &lt;td&gt;\ell-1}=A x_{\ell-1&lt;/td&gt;
          &lt;td&gt;\ell-1}$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cập nhật (Update)&lt;/strong&gt; với phép đo \(y_\ell=H x_\ell+v_\ell\): kéo giá trị dự đoán về phía quan sát theo tỷ lệ tương ứng với độ tin cậy của phép đo.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Độ lợi Kalman&lt;/strong&gt; \(K_\ell\) lớn khi phép đo đáng tin cậy (ưu tiên tín hiệu từ micro) và nhỏ khi phép đo nhiều nhiễu (ưu tiên dự đoán từ mô hình).&lt;/p&gt;

&lt;h3 id=&quot;mô-hình-vô-hướng-giản-lược&quot;&gt;Mô hình vô hướng giản lược&lt;/h3&gt;

\[x_\ell = x_{\ell-1}+w_\ell,\quad y_\ell=x_\ell+v_\ell,\]

\[K=\frac{p^{-}}{p^{-}+r},\quad \hat{x}=\hat{x}^{-}+K(y-\hat{x}^{-}).\]

&lt;p&gt;So với bộ lọc Wiener, \(K\) có dạng tương đồng với \(\xi/(\xi+1)\) nếu coi \(p^{-}/r\) như một dạng SNR tiên nghiệm. Nói ngắn gọn, Kalman giống như bộ lọc Wiener &lt;strong&gt;có thêm bộ nhớ&lt;/strong&gt; thông qua trạng thái và phương sai dự đoán. Trên hình minh họa, đường cam đại diện cho mức nền mà một bộ theo dõi đệ quy duy trì, còn đường cong bên phải là độ lợi được tính từ nền đó. Bước cập nhật Kalman cung cấp một cơ chế thống kê tường minh để cập nhật nền ổn định; bản thân hình vẽ vẫn minh họa khử nhiễu cổ điển chứ không phải sơ đồ khối chi tiết của bộ lọc Kalman.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/spectral-subtraction-wiener.png&quot; alt=&quot;Sàn nhiễu được theo dõi, cạnh gain theo SNR mà sàn đó dùng để tính&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Đường cam biểu diễn bộ theo dõi sàn nhiễu; đường bên phải là độ lợi suy ra từ sàn đó — phần mà bước cập nhật đệ quy kiểu Kalman giúp giữ ổn định theo thời gian.&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;vì-sao-kỹ-sư-âm-thanh-quan-tâm&quot;&gt;Vì sao kỹ sư âm thanh quan tâm&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Ứng dụng&lt;/th&gt;
      &lt;th&gt;Trạng thái ẩn \(x\)&lt;/th&gt;
      &lt;th&gt;Phép đo \(y\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Theo dõi tiếng nói sạch&lt;/td&gt;
      &lt;td&gt;Mẫu tín hiệu / biên độ phổ&lt;/td&gt;
      &lt;td&gt;Tín hiệu micro có nhiễu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mô hình LPC / formant&lt;/td&gt;
      &lt;td&gt;Các hệ số tự hồi quy (AR)&lt;/td&gt;
      &lt;td&gt;Phần dư / phổ tín hiệu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ước lượng đường vọng AEC&lt;/td&gt;
      &lt;td&gt;Đáp ứng xung \(\mathbf{h}\)&lt;/td&gt;
      &lt;td&gt;Tín hiệu micro hồi quy theo tín hiệu far-end&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mật độ phổ công suất vọng dư&lt;/td&gt;
      &lt;td&gt;Công suất vọng dư&lt;/td&gt;
      &lt;td&gt;Tín hiệu lỗi sau bộ lọc thích nghi&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Các &lt;strong&gt;bộ lọc thích nghi&lt;/strong&gt; (NLMS, RLS) trong AEC là họ hàng gần của Kalman vì cùng ước lượng đệ quy đường vọng. Kalman cung cấp lịch cập nhật độ lợi dựa trên mô hình hiệp phương sai, còn NLMS dùng bước cập nhật chuẩn hóa với chi phí thấp hơn. WebRTC APM và SpeexDSP ưu tiên các bộ lọc thích nghi thực dụng, trong khi nhiều bài báo kiến trúc lai gọi là “Kalman AEC” theo nghĩa bộ theo dõi có cập nhật hiệp phương sai.&lt;/p&gt;

&lt;h3 id=&quot;kiến-trúc-lai-cổ-điển-kết-hợp-mạng-nơ-ron&quot;&gt;Kiến trúc lai: cổ điển kết hợp mạng nơ-ron&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Bộ lọc thích nghi hoặc Kalman triệt tiêu phần tiếng vọng &lt;strong&gt;tuyến tính&lt;/strong&gt; dựa trên tín hiệu tham chiếu far-end.&lt;/li&gt;
  &lt;li&gt;Một mạng nơ-ron &lt;strong&gt;nhỏ&lt;/strong&gt; (kiểu ULCNet, GTCRN hoặc bộ hậu lọc DeepFilterNet) dọn sạch tiếng vọng dư phi tuyến và nhiễu nền mà mô hình tuyến tính không xử lý hết.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các mốc tham khảo tiêu biểu trong nghiên cứu gồm Align-ULCNet, kiến trúc lai ULCNet + bộ lọc thích nghi, và GSC + DeepFilterNet2 cho bài toán nhiễu có hướng (ego-noise).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bài học kỹ thuật:&lt;/strong&gt; Đừng ép mạng nơ-ron phải tự học hủy tiếng vọng tuyến tính thuần túy khi đã có sẵn tín hiệu tham chiếu — hãy để bộ lọc thích nghi xử lý phần tuyến tính rồi đưa tín hiệu dư sạch hơn vào mạng.&lt;/p&gt;

&lt;h2 id=&quot;danh-mục-kiểm-tra-khi-nào-nên-dùng-tư-duy-kalman&quot;&gt;Danh mục kiểm tra: khi nào nên dùng tư duy Kalman&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Khi bài toán có &lt;strong&gt;mô hình động học&lt;/strong&gt; rõ ràng (đường vọng thay đổi chậm, đường bao AR).&lt;/li&gt;
  &lt;li&gt;Khi có &lt;strong&gt;tín hiệu tham chiếu&lt;/strong&gt; (far-end cho AEC).&lt;/li&gt;
  &lt;li&gt;Khi phần dư sau bộ hủy tuyến tính vẫn cần khử phi tuyến.&lt;/li&gt;
  &lt;li&gt;Khi ngân sách CPU chặt — kết hợp bộ lọc thích nghi cổ điển với mạng NS gọn nhẹ hiệu quả hơn một mạng đầu–cuối khổng lồ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Coi Kalman là “bộ khử nhiễu vạn năng” mà không định nghĩa rõ vector trạng thái và mô hình đo.&lt;/li&gt;
  &lt;li&gt;Thiết lập sai ma trận \(A\) hoặc \(H\) dẫn tới sai lệch hệ thống.&lt;/li&gt;
  &lt;li&gt;Mất ổn định số ở ma trận hiệp phương sai (cần duy trì tính đối xứng xác định dương SPD).&lt;/li&gt;
  &lt;li&gt;Áp dụng Kalman toàn ma trận lên vector STFT chiều lớn trong khi xấp xỉ đường chéo hoặc NLMS mới khả thi ở thời gian thực.&lt;/li&gt;
  &lt;li&gt;Quên rằng tầng mạng nơ-ron hậu lọc vẫn cộng thêm độ trễ và trạng thái streaming (Chương 05–06).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Thực hiện một bước dự đoán–cập nhật vô hướng và in độ lợi Kalman trong hai trường hợp: phép đo đáng tin cậy và phép đo nhiễu mạnh.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;kalman_gain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;p_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;10.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;K&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;kalman_gain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;K&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;K&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Phương sai tiên nghiệm sau bước dự đoán bằng (1.1). Với (r=0.1), ta có (K\approx 0.917) (tin tưởng phép đo); với (r=10), ta có (K\approx 0.099) (bám sát dự đoán). Công thức có cùng dạng với độ lợi Wiener: giá trị tăng khi tỷ số (p^{-}/r) lớn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Cập nhật (p) bằng phép đo trước khi tính (K) sẽ làm sai cả hai kết quả; hoán đổi nhầm (q) và (r) sẽ khiến cảm biến nhiễu trông đáng tin hơn cảm biến sạch. Lưu ý đây chỉ là mô phỏng vô hướng minh họa cơ chế độ lợi, không phải bộ lọc Kalman đầy đủ cho tiếng nói hay bộ theo dõi PSD nhiễu.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Cài đặt vòng lặp dự đoán–cập nhật vô hướng với trạng thái \(x\) là một sóng sin biến thiên chậm và quan sát sự thay đổi của \(K\) khi điều chỉnh \(r\).&lt;/li&gt;
  &lt;li&gt;Vẽ sơ đồ một trang cho hệ thống AEC có trạng thái \(=\mathbf{h}\), đánh dấu rõ vị trí gắn bộ hậu lọc mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;Nêu ba điểm giống và khác nhau giữa bộ lọc Wiener decision-directed và bộ lọc Kalman cho mật độ phổ công suất tiếng nói.&lt;/li&gt;
  &lt;li&gt;Viết bản phác thảo thiết kế cho tình huống gọi trên trình duyệt có tiếng vọng loa theo chuỗi: WebRTC AEC → bộ khử nhiễu dư mạng nơ-ron, nêu rõ trách nhiệm của từng khối.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Giá trị (K) phải giảm khi (r) tăng, đồng thời ước lượng sẽ đáp ứng chậm hơn trước biến động nhanh của (y) khi (r) lớn.&lt;/li&gt;
  &lt;li&gt;Các mẫu trễ của far-end đóng vai trò vector hồi quy, tín hiệu micro là (y), và khối mạng nơ-ron nhận đầu vào là tín hiệu dư (e=y-\hat{h}*x) thay vì tín hiệu micro thô.&lt;/li&gt;
  &lt;li&gt;Cả hai đều có tính đệ quy và đều hạ độ lợi khi nhiễu lấn át; điểm khác là Wiener decision-directed theo dõi một tỷ số công suất, còn Kalman theo dõi tường minh cả trạng thái lẫn phương sai dựa trên mô hình động học quá trình.&lt;/li&gt;
  &lt;li&gt;AEC chịu trách nhiệm triệt tiêu tiếng vọng tuyến tính dựa trên tham chiếu far-end; tầng mạng nơ-ron xử lý phần còn lại gồm vọng dư phi tuyến và nhiễu nền mà không phải học lại (\mathbf{h}).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;R. E. Kalman, bài báo nền tảng năm 1960.&lt;/li&gt;
  &lt;li&gt;Haykin, &lt;em&gt;Adaptive Filter Theory&lt;/em&gt; (NLMS và RLS).&lt;/li&gt;
  &lt;li&gt;Tổng quan WebRTC Audio Processing Module.&lt;/li&gt;
  &lt;li&gt;Các mốc kiến trúc lai Kalman/ULCNet cho AENR (Align-ULCNet, ở mức khái niệm).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Why Use Kalman Filters?&lt;/td&gt;
          &lt;td&gt;Understanding Kalman Filters, Part 1](https://www.youtube.com/watch?v=mwn8xhgNpFY) — MATLAB, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày trực quan chu trình dự đoán rồi hiệu chỉnh — cùng tư duy hai bước với bộ theo dõi nền nhiễu nhưng tổng quát hơn.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-DiZGpAh7T4&quot;&gt;Kalman Filter - VISUALLY EXPLAINED!&lt;/a&gt; — Kapil Sachdeva, tiếng Anh. Minh họa cách độ bất định thu hẹp lại sau mỗi bước cập nhật phép đo, tạo trực giác rõ ràng cho các bộ theo dõi tiếng nói đệ quy.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-02 Bộ lọc Wiener cho tiếng nói</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter03/03_02_wiener_filtering/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter03/03_02_wiener_filtering</id>
   <content type="html">&lt;p&gt;Nếu trừ phổ xử lý theo hướng “trừ rồi kẹp sàn”, thì &lt;strong&gt;bộ lọc Wiener&lt;/strong&gt; chọn một hệ số độ lợi liên tục trên từng bin dựa trên tỷ số tín hiệu trên nhiễu ước lượng. Đường cong bên phải trong hình dưới minh họa độ lợi Wiener, đặt cạnh các cột trừ phổ mà nó thay thế.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/spectral-subtraction-wiener.png&quot; alt=&quot;Gain Wiener theo SNR tiên nghiệm, cạnh các cột spectral subtraction mà nó làm mềm&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Độ lợi Wiener đạt (1/2) ((-6\,\mathrm{dB})) khi công suất tiếng nói và nhiễu bằng nhau, biến thiên mượt mà thay vì tạo các hố phổ cứng như cột trừ phổ bên trái.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Đây là cầu nối tự nhiên giữa trừ phổ cổ điển và các mô hình tăng cường tiếng nói mạng nơ-ron dựa trên mặt nạ: họ DeepFilterNet có thể được nhìn nhận như phiên bản học sâu của độ lợi Wiener thời gian–tần số với đặc trưng giàu thông tin hơn và bộ lọc đa khung. Bài học này trình bày trực giác MMSE, phân biệt SNR tiên nghiệm và hậu nghiệm, cơ chế theo dõi decision-directed và ứng dụng lọc Wiener trong các hệ thống VoIP.&lt;/p&gt;

&lt;p&gt;Nếu trừ phổ giống như cầm chiếc kéo cắt phẳng mọi phần nhô lên khỏi mặt sàn nhiễu, thì &lt;strong&gt;bộ lọc Wiener&lt;/strong&gt; lại giống một người thợ chỉnh âm tinh tế vặn chiếc chiết áp liên tục trên từng dải tần: hễ nơi nào tiếng nói áp đảo nhiễu, chiết áp mở gần tối đa; nơi nào nhiễu lấn át tiếng nói, chiết áp hạ êm xuống gần \(0\) mà không bao giờ tạo ra vết cắt sắc lẹm. Kỳ diệu ở chỗ, công thức độ lợi mượt mà \(G = \frac{\xi}{1+\xi}\) không phải là một mẹo đặt tay cảm tính, mà là nghiệm tối ưu duy nhất của bài toán bình phương sai số trung bình cực tiểu (MMSE) trong lý thuyết xác suất.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-từ-hình-học-không-gian-hilbert-đến-bộ-lọc-wiener-thời-giantần-số&quot;&gt;Kiến thức cần nhớ: Từ hình học không gian Hilbert đến bộ lọc Wiener thời gian–tần số&lt;/h2&gt;

&lt;h3 id=&quot;1-tiêu-chí-mmse-và-nguyên-lý-trực-giao-orthogonality-principle&quot;&gt;1. Tiêu chí MMSE và nguyên lý trực giao (Orthogonality Principle)&lt;/h3&gt;
&lt;p&gt;Trong lý thuyết ước lượng thống kê, nếu muốn tìm một hệ số thực \(G\) sao cho tín hiệu ước lượng \(\hat{S} = G \cdot Y\) gần tín hiệu sạch \(S\) nhất theo nghĩa sai số bình phương trung bình \(E[\vert S - G Y \vert^2]\) nhỏ nhất, điều kiện cần và đủ là sai số \((S - G Y)\) phải &lt;em&gt;trực giao&lt;/em&gt; với dữ liệu quan sát \(Y\): \(E[(S - G Y) Y^*] = 0\). Khi \(S\) và \(N\) không tương quan, phương trình trực giao này rút gọn chỉ trong hai dòng đại số thành \(G = \frac{E[\vert S \vert^2]}{E[\vert S \vert^2] + E[\vert N \vert^2]} = \frac{\xi}{1 + \xi}\), với \(\xi = \frac{E[\vert S \vert^2]}{E[\vert N \vert^2]}\) là &lt;strong&gt;SNR tiên nghiệm (a priori SNR)&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;2-phân-biệt-rạch-ròi-snr-tiên-nghiệm-xi-và-snr-hậu-nghiệm-gamma&quot;&gt;2. Phân biệt rạch ròi SNR tiên nghiệm \(\xi\) và SNR hậu nghiệm \(\gamma\)&lt;/h3&gt;
&lt;p&gt;Trong thực tế, ta không bao giờ biết trước công suất tiếng nói sạch \(E[\vert S \vert^2]\). Thứ duy nhất đo được trực tiếp ở khung hiện tại là &lt;strong&gt;SNR hậu nghiệm (a posteriori SNR)&lt;/strong&gt;: \(\gamma(\ell, k) = \frac{\vert Y(\ell, k) \vert^2}{\hat{\lambda}_N(\ell, k)}\). Nếu vội vàng xấp xỉ \(\hat{\xi} = \max(\gamma - 1, 0)\), ước lượng sẽ nhảy loạn xạ theo từng đỉnh nhiễu ngẫu nhiên và tái sinh nhiễu nhạc y hệt trừ phổ.&lt;/p&gt;

&lt;h3 id=&quot;3-cơ-chế-decision-directed-của-ephraimmalah-và-cầu-nối-sang-deep-learning&quot;&gt;3. Cơ chế Decision-Directed của Ephraim–Malah và cầu nối sang Deep Learning&lt;/h3&gt;
&lt;p&gt;Năm 1984, Ephraim và Malah đưa ra một công thức đệ quy thiên tài gọi là &lt;strong&gt;decision-directed (DD)&lt;/strong&gt;: kết hợp \(98\%\) ước lượng mượt từ khung trước đó với chỉ \(2\%\) quan sát tức thời ở khung hiện tại:
\(\hat{\xi}(\ell, k) = \alpha\,\frac{\vert \hat{S}(\ell-1, k) \vert^2}{\hat{\lambda}_N(\ell, k)} + (1 - \alpha)\,\max(\gamma(\ell, k) - 1,\; 0), \qquad \alpha \approx 0{,}98.\)
Nhờ bộ nhớ làm mượt này, độ lợi Wiener biến thiên êm ái, gần như triệt tiêu nhiễu nhạc. Và khi bước sang Chương 4, bạn sẽ thấy mặt nạ tỷ số lý tưởng (IRM) hay độ lợi ERB của DeepFilterNet thực chất chính là một mạng nơ-ron học cách dự đoán trực tiếp đường cong \(G(\ell, k)\) thay vì tự tính \(\hat{\xi}\) bằng công thức đệ quy.&lt;/p&gt;

&lt;h3 id=&quot;giải-thích-cầm-tay-tính-độ-lợi-wiener-ở-3-mức-snr-và-kiểm-chứng-sức-mạnh-làm-mượt-của-decision-directed&quot;&gt;Giải thích: Cầm tay tính độ lợi Wiener ở 3 mức SNR và kiểm chứng sức mạnh làm mượt của Decision-Directed&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phần A — Độ lợi Wiener tại 3 mức SNR tiên nghiệm:&lt;/strong&gt; áp dụng \(G = \frac{\xi}{1+\xi}\) và đổi sang suy hao decibel \(20\log_{10} G\):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Trạng thái ô STFT&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;SNR tiên nghiệm \(\xi\)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Độ lợi Wiener \(G = \frac{\xi}{1+\xi}\)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Suy hao biên độ (dB)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Hiệu ứng nghe&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Tiếng nói mạnh (\(+10\text{ dB}\))&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(10\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(\frac{10}{11} \approx 0{,}909\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(-0{,}83\text{ dB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Gần như nguyên vẹn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Tiếng nói ngang nhiễu (\(0\text{ dB}\))&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(1\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(\frac{1}{2} = 0{,}500\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(-6{,}02\text{ dB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Hạ đều một nửa biên độ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Nhiễu áp đảo (\(-10\text{ dB}\))&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(0{,}1\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(\frac{0{,}1}{1{,}1} \approx 0{,}091\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(-20{,}83\text{ dB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Nén sâu xuống dưới nền&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Phần B — Chuyện gì xảy ra khi một gai nhiễu bất ngờ xuất hiện trong khoảng lặng?&lt;/strong&gt;
Giả sử khung trước đó đang yên lặng với \(\hat{\xi}_{\text{trước}} = 0{,}20\). Đột ngột ở khung hiện tại, nhiễu ngẫu nhiên vọt lên khiến SNR hậu nghiệm đo được là \(\gamma = 4{,}0\) (nên \(\max(\gamma - 1, 0) = 3{,}0\)):&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nếu tin hoàn toàn khung hiện tại (ML tức thời):&lt;/strong&gt;
\(\hat{\xi}_{\text{ML}} = 3{,}0 \implies G_{\text{ML}} = \frac{3{,}0}{1 + 3{,}0} = 0{,}750.\)
Bộ lọc đột ngột mở toang \(75\%\) cho gai nhiễu lọt qua — tạo ngay một tiếng “tích” nhiễu nhạc!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nếu dùng Decision-Directed với \(\alpha = 0{,}98\):&lt;/strong&gt;
\(\hat{\xi}_{\text{DD}} = 0{,}98 \times 0{,}20 + 0{,}02 \times 3{,}0 = 0{,}196 + 0{,}060 = 0{,}256 \implies G_{\text{DD}} = \frac{0{,}256}{1{,}256} \approx 0{,}204.\)
Độ lợi chỉ nhích nhẹ lên \(0{,}204\) (gần như không nghe thấy gai nhiễu). Nhưng nếu đó thực sự là một âm tiết tiếng nói bắt đầu kéo dài nhiều khung liên tiếp, \(\hat{\xi}_{\text{DD}}\) sẽ tăng dần đều trong vài chục mili-giây — đổi lấy sự êm tai bằng một chút độ trễ đáp ứng ở đầu âm tiết.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ suy ra được độ lợi Wiener miền tần số \(G = \xi/(1+\xi)\) từ tiêu chí MMSE dưới giả định Gauss, phân biệt rõ SNR tiên nghiệm \(\xi\) với SNR hậu nghiệm \(\gamma\), viết được giả mã bộ theo dõi decision-directed và liên hệ độ lợi Wiener với mặt nạ mềm (soft mask) trong mạng nơ-ron tăng cường tiếng nói.&lt;/p&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Chuyển từ trừ cứng sang độ lợi mềm; so sánh cảm nhận nghe giữa Wiener và trừ phổ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Phác thảo dẫn xuất MMSE → \(G^{\mathrm{Wiener}}=\xi/(\xi+1)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Ước lượng \(\xi\), \(\gamma\) và công thức đệ quy decision-directed (Ephraim–Malah).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Kỹ thuật thực tế cho tiếng nói: sàn độ lợi và ứng dụng trong SpeexDSP / WebRTC NS.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Các bẫy thường gặp, bài tập và dẫn sang lọc Kalman (bài 03-03).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;công-thức-độ-lợi-wiener&quot;&gt;Công thức độ lợi Wiener&lt;/h3&gt;

&lt;p&gt;Với mô hình hỗn hợp \(Y=S+N\) tại một bin STFT (giả sử \(S\) và \(N\) có phân bố Gauss, không tương quan và kỳ vọng bằng 0), bộ ước lượng tuyến tính tối ưu theo sai số bình phương trung bình tối thiểu (MMSE) của \(S\) từ \(Y\) có dạng nhân với hệ số:&lt;/p&gt;

\[G^{\mathrm{W}} = \frac{P_S}{P_S + P_N} = \frac{\xi}{\xi + 1},\]

&lt;p&gt;trong đó \(\xi = P_S/P_N\) là &lt;strong&gt;SNR tiên nghiệm (a priori SNR)&lt;/strong&gt; và phổ sau tăng cường là \(\hat{S}=G^{\mathrm{W}} Y\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cách diễn giải:&lt;/strong&gt; Khi \(\xi\to\infty\) thì \(G\to 1\) (giữ nguyên tín hiệu); khi \(\xi\to 0\) thì \(G\to 0\) (triệt tiêu nhiễu). Ở vùng trung gian, \(G\) hoạt động như một mặt nạ mềm — đúng dạng hàm mà các mạng dự đoán mặt nạ học từ dữ liệu.&lt;/p&gt;

&lt;h3 id=&quot;snr-hậu-nghiệm-a-posteriori-snr&quot;&gt;SNR hậu nghiệm (a posteriori SNR)&lt;/h3&gt;

\[\gamma = \frac{|Y|^2}{P_N}.\]

&lt;p&gt;Ta có thể đo trực tiếp \(\gamma\) ở mỗi khung nếu biết công suất nhiễu \(P_N\), nhưng không thể đo trực tiếp \(\xi\) vì \(P_S\) bị ẩn. Phần lớn công sức của khử nhiễu cổ điển tập trung vào việc ước lượng \(\xi\). Ước lượng hợp lý cực đại (ML) thô \(\hat{\xi}=\max(\gamma-1,0)\) dao động rất mạnh giữa các khung và tạo ra méo âm tương tự trừ phổ cứng.&lt;/p&gt;

&lt;h3 id=&quot;bộ-ước-lượng-decision-directed-ephraimmalah&quot;&gt;Bộ ước lượng decision-directed (Ephraim–Malah)&lt;/h3&gt;

\[\hat{\xi}(\ell) = \eta\,\frac{|G(\ell-1) Y(\ell-1)|^2}{P_N} + (1-\eta)\,\max\bigl(\gamma(\ell)-1,\,0\bigr),\]

&lt;p&gt;với hằng số làm mượt \(\eta\) thường chọn khoảng \(0.98\), sau đó tính \(G=\hat{\xi}/(\hat{\xi}+1)\). Giá trị \(\eta\) lớn giúp độ lợi mượt và giảm mạnh nhiễu nhạc nhưng dễ gây nhòe đuôi âm; ngược lại, \(\eta\) nhỏ giúp bám nhiễu không dừng nhanh hơn nhưng dễ làm độ lợi dao động giật.&lt;/p&gt;

&lt;h3 id=&quot;góc-nhìn-mặt-nạ-mềm-cầu-nối-sang-chương-04&quot;&gt;Góc nhìn mặt nạ mềm (cầu nối sang Chương 04)&lt;/h3&gt;

&lt;p&gt;Mặt nạ tỷ số lý tưởng (IRM) trên miền công suất được định nghĩa là:&lt;/p&gt;

\[M^{\mathrm{IRM}} = \frac{|S|^2}{|S|^2+|N|^2} = \frac{\xi}{\xi+1}.\]

&lt;p&gt;Biểu thức này trùng khớp hoàn toàn với độ lợi Wiener khi \(\xi\) là SNR thực. Các mạng tăng cường tiếng nói thường huấn luyện để hồi quy \(\hat{M}\) tiến tới IRM, IBM hoặc cIRM — vì thế nắm vững lọc Wiener giúp việc đọc hiểu DeepFilterNet trở nên trực quan hơn nhiều.&lt;/p&gt;

&lt;h3 id=&quot;giả-mã&quot;&gt;Giả mã&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;for each frame ell:
  Y = STFT(y_ell)
  γ = |Y|^2 / P_N
  ξ = η * |S_prev|^2 / P_N + (1-η) * max(γ - 1, 0)
  G = max(ξ / (ξ + 1), G_min)
  S_hat = G * Y
  S_prev = S_hat
  emit ISTFT_OLA(S_hat)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;bảng-tham-số-tinh-chỉnh-lọc-wiener-cho-tiếng-nói&quot;&gt;Bảng tham số tinh chỉnh lọc Wiener cho tiếng nói&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tham số&lt;/th&gt;
      &lt;th&gt;Khi tăng →&lt;/th&gt;
      &lt;th&gt;Khi giảm →&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;\(\eta\)&lt;/td&gt;
      &lt;td&gt;Mượt hơn, ít nhiễu nhạc hơn&lt;/td&gt;
      &lt;td&gt;Đáp ứng nhanh hơn nhưng dễ giật&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(G_{\min}\)&lt;/td&gt;
      &lt;td&gt;Còn nhiều nhiễu nền dư hơn&lt;/td&gt;
      &lt;td&gt;Dễ méo tiếng hoặc tạo hố phổ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tốc độ cập nhật \(P_N\)&lt;/td&gt;
      &lt;td&gt;Bám tốt hơn với nhiễu không dừng&lt;/td&gt;
      &lt;td&gt;Ổn định hơn trong lúc có tiếng nói&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Kiểm tra nhanh (sanity check):&lt;/strong&gt; Khi \(P_N\to 0\) thì \(G\to 1\) và đầu ra phải xấp xỉ đầu vào (với OLA đúng chuẩn). Nên viết bài kiểm thử đơn vị cho trường hợp biên này.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Dùng trực tiếp \(\gamma/(\gamma+1)\) và coi đó là bộ lọc Wiener chuẩn.&lt;/li&gt;
  &lt;li&gt;Đóng băng ước lượng \(P_N\) mãi mãi sau giây đầu tiên của cuộc gọi.&lt;/li&gt;
  &lt;li&gt;Không đặt sàn độ lợi \(G_{\min}\), khiến độ lợi tụt về 0 đột ngột và sinh nhiễu nhạc.&lt;/li&gt;
  &lt;li&gt;Đặt lọc Wiener phía sau khối AGC phi tuyến mà không cập nhật lại mật độ phổ công suất nhiễu.&lt;/li&gt;
  &lt;li&gt;Nhầm lẫn giữa &lt;strong&gt;tiếng vọng&lt;/strong&gt; (có tín hiệu tham chiếu) với &lt;strong&gt;nhiễu nền&lt;/strong&gt; (ước lượng mù) — lọc Wiener NS không thay thế được AEC.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Tính độ lợi Wiener tại ba mức SNR tiên nghiệm là (-10), (0) và (+10\,\mathrm{dB}).&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;snr_db&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;snr_db&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;10.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;G&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;snr_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;xi&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
          &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;G_dB&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Tại (-10\,\mathrm{dB}) → (\xi=0.1), (G\approx 0.091) ((-20.83\,\mathrm{dB})); tại (0\,\mathrm{dB}) → (\xi=1), (G=0.5) ((-6.02\,\mathrm{dB})); tại (+10\,\mathrm{dB}) → (\xi=10), (G\approx 0.909) ((-0.83\,\mathrm{dB})). Hàng giữa tương ứng đúng với điểm đánh dấu trên hình minh họa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Đưa trực tiếp giá trị dB vào công thức (\xi/(\xi+1)) (quên đổi sang tuyến tính qua (10^{\mathrm{SNR}/10})) khiến độ lợi ở (-10\,\mathrm{dB}) lớn hơn ở (+10\,\mathrm{dB}), làm đảo ngược hoàn toàn đường cong; dùng nhầm (20\log_{10}) để đổi công suất SNR sang (\xi), hoặc tính (10\log_{10} G) thay vì (20\log_{10} G), sẽ làm cột dB lệch hệ số 2; lưu ý rằng (\gamma/(\gamma+1)) là công thức thế khác và bài thực hành này không ước lượng (\gamma).&lt;/p&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chứng minh \(G=\xi/(\xi+1)=1-1/(\xi+1)\) và giải thích ý nghĩa của \(1-G\).&lt;/li&gt;
  &lt;li&gt;Tính \(G\) với \(\xi\in\{0.1,1,10\}\) theo cả thang tuyến tính và dB; giá trị \(\xi\) nào cho độ lợi đúng bằng \(-6\,\mathrm{dB}\)?&lt;/li&gt;
  &lt;li&gt;Cài đặt bộ lọc Wiener decision-directed, vẽ bản đồ độ lợi \(G(k,\ell)\) và so sánh mức nhiễu nhạc với bài 03-01.&lt;/li&gt;
  &lt;li&gt;Viết hai đoạn văn giải thích vì sao mạng nơ-ron ước lượng IRM vượt trội hơn Wiener decision-directed trên nhiễu không dừng dù vẫn giữ cùng trực giác \(\xi/(\xi+1)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Biến đổi trực tiếp cho thấy (1-G=1/(\xi+1)), đại diện cho tỷ lệ thành phần trong (Y) được quy về nhiễu.&lt;/li&gt;
  &lt;li&gt;(G=1/2) (tương ứng (-6.02\,\mathrm{dB})) đạt được tại (\xi=1); ba giá trị độ lợi tương ứng là (0.091), (0.5) và (0.909).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Hãy vẽ trực tiếp (G) thay vì (&lt;/td&gt;
          &lt;td&gt;Y&lt;/td&gt;
          &lt;td&gt;): khi (\eta) nhỏ sẽ thấy bản đồ (G) lốm đốm, trong khi trừ phổ tạo các vùng khuyết cứng.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;Mạng nơ-ron vẫn hướng tới ước lượng tỷ số công suất, nhưng nó vượt trội vì khai thác được ngữ cảnh thời gian–tần số rộng hơn nhiều so với một phép đệ quy decision-directed đơn giản, chứ không phải vì phát minh ra một công thức độ lợi hoàn toàn khác.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;N. Wiener — nền tảng lý thuyết lọc tối ưu.&lt;/li&gt;
  &lt;li&gt;Ephraim &amp;amp; Malah, &lt;em&gt;IEEE TASSP&lt;/em&gt;, 1984.&lt;/li&gt;
  &lt;li&gt;P. Scalart &amp;amp; J. V. Filho, “Speech enhancement based on a priori signal to noise estimation,” &lt;em&gt;ICASSP&lt;/em&gt;, 1996 — dạng ước lượng SNR tiên nghiệm dùng trong lọc Wiener tiếng nói.&lt;/li&gt;
  &lt;li&gt;Loizou, &lt;em&gt;Speech Enhancement: Theory and Practice&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;SpeexDSP và WebRTC APM — các hiện thực kỹ thuật thực tế.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=K_U0yeVdblU&quot;&gt;Lec 22: Causal IIR Wiener Filter&lt;/a&gt; — NPTEL IIT Guwahati, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Minh họa cách độ lợi thay đổi liên tục theo mức nhiễu của phép đo — đúng nguyên lý đằng sau độ lợi theo bin trên STFT thay cho phép trừ cứng.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=U71siegOD48&quot;&gt;Wiener Filter Demonstration&lt;/a&gt; — Greg Malysa, tiếng Anh. Đoạn minh họa ngắn về hành vi của bộ lọc Wiener giúp bạn hình dung trực quan trước khi ánh xạ lên từng bin tiếng nói.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xb--68NlxS0&quot;&gt;Spectral Subtraction In Python - Alexx Mitchell&lt;/a&gt; — The Audio Programmer, tiếng Anh. Đặt cạnh bài Wiener để thấy rõ sự khác biệt giữa quy tắc trừ kèm ngưỡng sàn với đường độ lợi liên tục theo SNR.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-01 Spectral subtraction</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter03/03_01_spectral_subtraction/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter03/03_01_spectral_subtraction</id>
   <content type="html">&lt;p&gt;Trừ phổ (spectral subtraction) là bước nhập môn kinh điển của bài toán khử nhiễu: ước lượng phổ biên độ nhiễu, trừ đi từ phổ tín hiệu quan sát rồi tái tạo lại dạng sóng. Thuật toán đủ gọn để tự cài đặt trong một buổi chiều, nhưng cũng đủ sâu để phơi bày hầu hết các dạng méo âm — đặc biệt là &lt;em&gt;nhiễu nhạc (musical noise)&lt;/em&gt; — mà các hệ thống mạng nơ-ron hiện đại vẫn phải tìm cách khắc phục. Bài học này xây dựng công thức trừ phổ trên biên độ STFT, trình bày kỹ thuật trừ dư (over-subtraction) và đặt ngưỡng sàn phổ (spectral floor) trong các bộ tiền xử lý thực tế (như SpeexDSP), đồng thời chỉ rõ khi nào trừ phổ vẫn hữu ích làm tầng tiền xử lý nhẹ trước mô hình mạng nơ-ron.&lt;/p&gt;

&lt;p&gt;Nếu bạn đứng trong một quán cà phê ồn ào và cố lắng nghe người bạn đối diện, phản xạ tự nhiên nhất của não bộ — và cũng là ý tưởng đầu tiên trong lịch sử khử nhiễu số — là: &lt;em&gt;đợi lúc bạn mình ngừng nói để “ghi nhớ” tiếng ồn nền, rồi lấy tổng âm thanh trừ bớt tiếng ồn đó đi&lt;/em&gt;. Thoạt nghe tưởng chừng quá đơn giản để có thể sai, nhưng chính phép trừ tưởng như ngây thơ ấy lại mở ra một bài học sâu sắc về thống kê ngẫu nhiên: khi trừ đi một đại lượng trung bình khỏi một tín hiệu nhiễu biến động ngẫu nhiên từng khung một, những đỉnh nhiễu sót lại sẽ kêu lách tách như những nốt nhạc rơi rời rạc — thứ mà giới kỹ sư gọi là &lt;strong&gt;nhiễu nhạc (musical noise)&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-trừ-phổ-nằm-ở-đâu-trong-xử-lý-tín-hiệu-thống-kê&quot;&gt;Kiến thức cần nhớ: Trừ phổ nằm ở đâu trong xử lý tín hiệu thống kê?&lt;/h2&gt;

&lt;h3 id=&quot;1-mô-hình-cộng-tính-và-giả-định-độc-lập-thống-kê&quot;&gt;1. Mô hình cộng tính và giả định độc lập thống kê&lt;/h3&gt;
&lt;p&gt;Trong phòng kín không vang quá nặng, sóng âm thu được tại micro là tổng tuyến tính \(y[t] = s[t] + n[t]\). Nhờ tính tuyến tính của biến đổi Fourier thời gian ngắn (STFT), quan hệ này giữ nguyên trên từng ô thời gian–tần số: \(Y(\ell, k) = S(\ell, k) + N(\ell, k)\). Khi giả định tiếng nói và nhiễu không tương quan nhau, công suất kỳ vọng cộng trực tiếp: \(E[\vert Y \vert^2] = E[\vert S \vert^2] + E[\vert N \vert^2]\). Trừ phổ thay kỳ vọng lý thuyết bằng phổ tức thời \(\vert Y(\ell, k) \vert\) và một ước lượng trung bình \(\vert \hat{N}(k) \vert\) đo được trong các khoảng lặng.&lt;/p&gt;

&lt;h3 id=&quot;2-bất-đối-xứng-giữa-biên-độ-và-pha-trong-thính-giác-người&quot;&gt;2. Bất đối xứng giữa biên độ và pha trong thính giác người&lt;/h3&gt;
&lt;p&gt;Một số phức STFT gồm biên độ \(\vert Y \vert\) và pha \(\angle Y\). Các thực nghiệm tâm âm học kinh điển (Wang &amp;amp; Lim, 1982) cho thấy ở mức SNR trung bình và cao, tai người nhạy cảm với sai số biên độ hơn nhiều so với sai số pha cục bộ. Vì thế, thuật toán trừ phổ cổ điển (Boll, 1979) chỉ sửa biên độ để lấy \(\vert \hat{S} \vert\) rồi ghép lại với chính pha nhiễu \(\angle Y\) trước khi biến đổi ngược ISTFT.&lt;/p&gt;

&lt;h3 id=&quot;3-cơ-chế-sinh-nhiễu-nhạc-và-hai-van-an-toàn-alpha-beta&quot;&gt;3. Cơ chế sinh nhiễu nhạc và hai van an toàn \(\alpha, \beta\)&lt;/h3&gt;
&lt;p&gt;Do nhiễu nền là quá trình ngẫu nhiên, biên độ thực \(\vert N(\ell, k) \vert\) dao động mạnh quanh mức trung bình \(\vert \hat{N}(k) \vert\). Nếu trừ đúng \(1\times\) mức trung bình rồi cắt về \(0\) khi âm (half-wave rectification), một nửa số bin nhiễu bị xóa sạch về \(0\), còn nửa kia trồi lên thành những gai nhọn cô lập xuất hiện rồi biến mất sau mỗi \(10\text{ ms}\). Qua ISTFT, mỗi gai cô lập trở thành một hình sin ngắn nghe như tiếng “bíp” hay tiếng nước nhỏ giọt. Giải pháp kinh điển của Berouti (1979) là trừ dư bằng hệ số \(\alpha &amp;gt; 1\) để dập các gai cô lập, đồng thời giữ lại một &lt;strong&gt;sàn phổ (spectral floor)&lt;/strong&gt; \(\beta \vert Y \vert\) (hoặc \(\beta \vert \hat{N} \vert\)) nhằm lấp các hố phổ đen kịt bằng một lớp nền dịu đều tai hơn.&lt;/p&gt;

&lt;h3 id=&quot;giải-thích-cầm-tay-tính-3-bin-stft-để-thấy-rõ-sự-khác-biệt-giữa-trừ-ngây-thơ-và-trừ-có-alpha-beta&quot;&gt;Giải thích: Cầm tay tính 3 bin STFT để thấy rõ sự khác biệt giữa trừ ngây thơ và trừ có \(\alpha, \beta\)&lt;/h3&gt;

&lt;p&gt;Giả sử bộ ước lượng nhiễu trong khoảng lặng cho \(\vert \hat{N}(k) \vert = 2{,}0\) tại cả 3 bin tần số xét cùng một khung. Quan sát biên độ đo được \(\vert Y(k) \vert\) tại 3 bin:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bin A (họa âm tiếng nói mạnh):&lt;/strong&gt; \(\vert Y_A \vert = 10{,}0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bin B (đỉnh nhiễu ngẫu nhiên trồi lên trong khoảng lặng):&lt;/strong&gt; \(\vert Y_B \vert = 3{,}0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bin C (đáy nhiễu ngẫu nhiên tụt xuống thấp):&lt;/strong&gt; \(\vert Y_C \vert = 1{,}2\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ta so sánh trực tiếp hai công thức:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trừ ngây thơ (\(\alpha = 1{,}0,\; \beta = 0\)):&lt;/strong&gt; \(\vert \hat{S} \vert = \max(\vert Y \vert - \vert \hat{N} \vert,\; 0)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trừ dư kèm sàn phổ (\(\alpha = 2{,}0,\; \beta = 0{,}1\)):&lt;/strong&gt; \(\vert \hat{S} \vert = \max(\vert Y \vert - \alpha \vert \hat{N} \vert,\; \beta \vert Y \vert)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Bin tần số&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;\(\vert Y \vert\)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Trừ ngây thơ (\(\alpha=1,\beta=0\))&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Trừ dư + sàn phổ (\(\alpha=2,\beta=0{,}1\))&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Ý nghĩa âm học&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Bin A&lt;/strong&gt; (tiếng nói)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(10{,}0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(\max(10{,}0 - 2{,}0,\; 0) = 8{,}0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(\max(10{,}0 - 4{,}0,\; 1{,}0) = 6{,}0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Giữ được họa âm chính (giảm nhẹ biên độ)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Bin B&lt;/strong&gt; (gai nhiễu)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(3{,}0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(\max(3{,}0 - 2{,}0,\; 0) = 1{,}0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(\max(3{,}0 - 4{,}0,\; 0{,}3) = 0{,}3\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Trừ ngây thơ để lọt gai \(1{,}0\) gây &lt;strong&gt;nhiễu nhạc&lt;/strong&gt;; \(\alpha=2\) dập gọn xuống \(0{,}3\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Bin C&lt;/strong&gt; (đáy nhiễu)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(1{,}2\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(\max(1{,}2 - 2{,}0,\; 0) = 0{,}0\)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;\(\max(1{,}2 - 4{,}0,\; 0{,}12) = 0{,}12\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Trừ ngây thơ tạo hố \(0{,}0\) đột ngột; sàn \(\beta\) giữ nền êm \(0{,}12\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nhìn vào cột giữa và cột phải, bạn thấy ngay cái giá phải trả: \(\alpha = 2{,}0\) dập sạch gai nhiễu ở Bin B (từ \(1{,}0\) xuống \(0{,}3\)) nhưng đồng thời làm tiếng nói ở Bin A hơi mỏng đi (từ \(8{,}0\) xuống \(6{,}0\)). Chính sự đánh đổi cố hữu giữa &lt;em&gt;khử sạch nhiễu&lt;/em&gt; và &lt;em&gt;méo giọng&lt;/em&gt; này sẽ dẫn ta sang bộ lọc Wiener mượt mà hơn ở bài 03-02.&lt;/p&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau bài học này, bạn sẽ nắm được mô hình hỗn hợp cộng tính trên miền STFT, viết được giả mã thuật toán trừ phổ biên độ kèm hệ số trừ dư và ngưỡng sàn, giải thích được vì sao các đỉnh nhiễu dư nghe giống tiếng “nhạc”, và xác định được khi nào bộ trừ phổ cổ điển nên dùng làm tầng tiền xử lý thay vì chuyển thẳng sang lọc Wiener hoặc mặt nạ mạng nơ-ron.&lt;/p&gt;

&lt;h2 id=&quot;kế-hoạch-60-phút&quot;&gt;Kế hoạch 60 phút&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 phút&lt;/strong&gt; — Mô hình \(Y = S + N\), so sánh phổ biên độ với phổ công suất và lý do thường tái sử dụng pha của khung nhiễu.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;10–25 phút&lt;/strong&gt; — Ước lượng nền nhiễu (VAD / thống kê cực tiểu) và công thức trừ cơ bản $$&lt;/td&gt;
          &lt;td&gt;\hat{S}&lt;/td&gt;
          &lt;td&gt;=&lt;/td&gt;
          &lt;td&gt;Y&lt;/td&gt;
          &lt;td&gt;- \alpha&lt;/td&gt;
          &lt;td&gt;\hat{N}&lt;/td&gt;
          &lt;td&gt;$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 phút&lt;/strong&gt; — Hệ số \(\alpha\), ngưỡng sàn \(\beta\) và ví dụ tính toán trên một vài bin.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 phút&lt;/strong&gt; — Nhiễu nhạc: cơ chế hình thành, danh mục kiểm tra nghe và bộ tiền xử lý kiểu SpeexDSP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 phút&lt;/strong&gt; — Các bẫy thường gặp, bài tập và vai trò tiền xử lý trước DeepFilterNet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;mô-hình-hỗn-hợp-và-biên-độ-stft&quot;&gt;Mô hình hỗn hợp và biên độ STFT&lt;/h3&gt;

&lt;p&gt;Xét tín hiệu quan sát đơn kênh:&lt;/p&gt;

\[y[t] = s[t] + n[t],\]

&lt;p&gt;trong đó \(s\) là tiếng nói sạch và \(n\) là nhiễu cộng tính. Sau khi áp dụng STFT có cửa sổ (Chương 02), ta ký hiệu các phổ phức tương ứng là \(Y(k,\ell)\), \(S(k,\ell)\) và \(N(k,\ell)\). Trừ phổ cổ điển tác động trên &lt;strong&gt;biên độ&lt;/strong&gt; (hoặc công suất) và tái sử dụng &lt;strong&gt;pha của tín hiệu nhiễu&lt;/strong&gt;:&lt;/p&gt;

\[\hat{S}(k,\ell) = \bigl(|Y(k,\ell)| - \widehat{|N|}(k,\ell)\bigr)_{+} \; e^{j\angle Y(k,\ell)}.\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Phép lấy phần dương \((\cdot)_{+}\) ngăn biên độ bị âm. Biến thể trên miền công suất trừ ước lượng công suất nhiễu khỏi $$&lt;/td&gt;
      &lt;td&gt;Y&lt;/td&gt;
      &lt;td&gt;^2$$ rồi lấy căn bậc hai — cùng một nguyên lý nhưng có sự đánh đổi khác nhau giữa độ chệch (bias) và phương sai (variance).&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;ước-lượng-nền-nhiễu-các-giả-định&quot;&gt;Ước lượng nền nhiễu (các giả định)&lt;/h3&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Thuật toán cần một ước lượng $$\widehat{&lt;/td&gt;
      &lt;td&gt;N&lt;/td&gt;
      &lt;td&gt;}(k)$$, thường dựa trên các giả định phổ biến sau:&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhiễu dừng trong khoảng lặng ban đầu&lt;/strong&gt; — lấy trung bình biên độ của \(L_0\) khung đầu tiên vốn được giả định chỉ chứa nhiễu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bộ phát hiện tiếng nói (VAD)&lt;/strong&gt; — chỉ cập nhật ước lượng nhiễu trên các khung không có tiếng nói.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thống kê cực tiểu (min-statistics) / cập nhật đệ quy&lt;/strong&gt; — bám theo cực tiểu đã làm mượt của phổ nhiễu (thường thấy trong bộ tiền xử lý kiểu SpeexDSP).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Công thức cập nhật đệ quy trên các khung không có tiếng nói:&lt;/p&gt;

\[\widehat{|N|}(k,\ell) = \lambda \widehat{|N|}(k,\ell-1) + (1-\lambda)\,|Y(k,\ell)|,\]

&lt;p&gt;trong đó \(\lambda\) gần bằng 1 nếu cần tốc độ thích nghi chậm và ổn định.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giả định then chốt:&lt;/strong&gt; Với nhiễu không dừng (tiếng gõ phím, người nói chuyện xung quanh, nhạc nền), ước lượng nền cập nhật chậm sẽ &lt;strong&gt;trừ thiếu&lt;/strong&gt; khi nhiễu bùng phát và &lt;strong&gt;trừ dư&lt;/strong&gt; ngay sau đó — đây là lý do trừ phổ thuần túy không đáp ứng được yêu cầu VoIP hiện đại.&lt;/p&gt;

&lt;h3 id=&quot;trừ-dư-over-subtraction-và-ngưỡng-sàn-phổ-spectral-floor&quot;&gt;Trừ dư (over-subtraction) và ngưỡng sàn phổ (spectral floor)&lt;/h3&gt;

&lt;p&gt;Các cải tiến theo hướng Berouti bổ sung hai tham số điều chỉnh:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;\(\alpha \ge 1\)&lt;/strong&gt; — trừ &lt;em&gt;nhiều hơn&lt;/em&gt; ước lượng nhiễu để triệt tiêu các đỉnh nhiễu còn sót.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;\(\beta \in (0,1)\)&lt;/strong&gt; — giữ biên độ không rơi xuống dưới $$\beta\,&lt;/td&gt;
          &lt;td&gt;Y&lt;/td&gt;
          &lt;td&gt;$$ nhằm giảm nhiễu nhạc, đánh đổi bằng việc để lại một phần nhiễu nền dư.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

\[|\hat{S}(k,\ell)| = \max\bigl(|Y(k,\ell)| - \alpha\,\widehat{|N|}(k,\ell),\; \beta\,|Y(k,\ell)|\bigr).\]

&lt;p&gt;Trong thực tế, \(\alpha\) đôi khi được chọn phụ thuộc vào SNR (tăng \(\alpha\) khi SNR tiên nghiệm thấp). Cách tiếp cận này mở đường trực tiếp sang &lt;strong&gt;bộ lọc Wiener&lt;/strong&gt; ở bài học tiếp theo.&lt;/p&gt;

&lt;h3 id=&quot;giả-mã-stft-biên-độ&quot;&gt;Giả mã (STFT biên độ)&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;for each frame ell:
  Y = STFT_frame(y_ell)
  magY = |Y|
  if is_noise_frame(ell):
      Nhat = λ * Nhat + (1-λ) * magY
  magS = max(magY - α * Nhat, β * magY)
  S_hat = magS * exp(j * angle(Y))
  emit ISTFT_OLA(S_hat)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Cần giữ kích thước hop, hàm cửa sổ và phép cộng chồng lấp nhất quán với Chương 02 để đảm bảo tái tạo hoàn hảo khi \(\alpha=0\) và \(\beta=1\).&lt;/p&gt;

&lt;h3 id=&quot;nhiễu-nhạc-musical-noise&quot;&gt;Nhiễu nhạc (musical noise)&lt;/h3&gt;

&lt;p&gt;Khi ước lượng nhiễu hơi &lt;strong&gt;thấp&lt;/strong&gt; hơn thực tế, phổ sau trừ còn sót lại các đỉnh nhọn rời rạc; khi ước lượng &lt;strong&gt;cao&lt;/strong&gt; hơn, nó khoét thành các hố phổ bằng 0. Qua các khung liên tiếp, các đỉnh cô lập này bật tắt và dịch chuyển theo tần số, tạo ra âm thanh lách tách giống tiếng hú hoặc tiếng chim hót gọi là &lt;strong&gt;nhiễu nhạc (musical noise)&lt;/strong&gt;. Đặt ngưỡng sàn và làm mượt độ lợi giúp giảm hiện tượng này, trong khi tăng mạnh \(\alpha\) mà không đặt sàn sẽ làm âm thanh tệ hơn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Danh mục kiểm tra nghe (khoảng 30 giây mỗi đoạn):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Cân bằng âm lượng (loudness) giữa đầu vào và đầu ra trước khi so sánh.&lt;/li&gt;
  &lt;li&gt;Nghe riêng đoạn chỉ có nhiễu: có xuất hiện tiếng hú hoặc ríu rít không?&lt;/li&gt;
  &lt;li&gt;Nghe riêng đoạn tiếng nói ở SNR thấp: giọng có bị rỗng hay giống robot không?&lt;/li&gt;
  &lt;li&gt;Tăng \(\beta\): nhiễu nhạc giảm xuống trong khi nhiễu nền dư tăng lên.&lt;/li&gt;
  &lt;li&gt;Tăng \(\alpha\): mức nhiễu giảm nhưng méo tiếng nói và các âm giả (tonal artifact) thường tăng.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;ví-dụ-số-trên-vài-bin-minh-họa&quot;&gt;Ví dụ số (trên vài bin minh họa)&lt;/h2&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Cho $$&lt;/td&gt;
      &lt;td&gt;Y&lt;/td&gt;
      &lt;td&gt;= [5.0,\; 2.0,\; 1.2]\(,\)\widehat{&lt;/td&gt;
      &lt;td&gt;N&lt;/td&gt;
      &lt;td&gt;} = [1.0,\; 1.5,\; 1.0]\(,\)\alpha=1.5\(và\)\beta=0.1$$.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Kết quả sau trừ và áp sàn lần lượt là: bin 0 → \(3.5\); bin 1 → chạm sàn \(0.2\); bin 2 → chạm sàn \(0.12\). Nếu không có ngưỡng sàn, bin 1 và bin 2 sẽ bị cắt thẳng về 0, tạo các hố phổ cứng sau ISTFT.&lt;/p&gt;

&lt;h2 id=&quot;khi-nào-trừ-phổ-cổ-điển-vẫn-hữu-ích-làm-tầng-tiền-xử-lý&quot;&gt;Khi nào trừ phổ cổ điển vẫn hữu ích làm tầng tiền xử lý&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Làm cổng giảm nhiễu luôn bật với chi phí rất thấp trên DSP trước tầng mạng nơ-ron nặng hơn.&lt;/li&gt;
  &lt;li&gt;Tạo ước lượng khởi tạo SNR tiên nghiệm cho bộ lọc Wiener hoặc MMSE.&lt;/li&gt;
  &lt;li&gt;Xuất hiện trong bộ tiền xử lý SpeexDSP và các chuỗi VoIP cổ điển kết hợp AGC + VAD + NS.&lt;/li&gt;
  &lt;li&gt;Kiến trúc lai (hybrid): khối cổ điển xử lý tiếng ù HVAC dừng, còn mạng nơ-ron xử lý nhiễu không dừng (Chương 04).&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Với bài toán khử nhiễu toàn băng thời gian thực như Mezon, riêng trừ phổ là chưa đủ — nhưng nắm vững cơ chế này giúp bạn hiểu rõ bản chất các mặt nạ học được của DeepFilterNet. Biểu đồ bên trái trong hình dưới minh họa quy tắc này trên miền công suất: cột xanh dương là (&lt;/td&gt;
      &lt;td&gt;Y&lt;/td&gt;
      &lt;td&gt;^2), đường cam là sàn nhiễu ước lượng, còn cột xanh lá là phần năng lượng giữ lại sau khi áp sàn. Biểu đồ bên phải không phải phép trừ mà là đường độ lợi Wiener mượt của bài kế tiếp.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/spectral-subtraction-wiener.png&quot; alt=&quot;Spectral subtraction miền công suất theo từng bin, cạnh đường gain Wiener mà bài này chưa áp&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Trừ phổ (trái) loại bỏ một nền nhiễu rồi kẹp sàn phần còn lại; đường cong mượt bên phải là độ lợi Wiener khi phép trừ cứng được thay bằng hàm theo SNR.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Trộn lẫn công thức miền công suất và miền biên độ mà không điều chỉnh lại \(\alpha, \beta\).&lt;/li&gt;
  &lt;li&gt;Vẫn cập nhật ước lượng nhiễu khi người dùng đang nói → dẫn tới &lt;strong&gt;xóa mất tiếng nói&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Đặt \(\beta=0\) với kỳ vọng nền “sạch tuyệt đối” → gây nhiễu nhạc nặng.&lt;/li&gt;
  &lt;li&gt;Quên chuẩn hóa OLA → gây hiện tượng bơm biên độ (pumping).&lt;/li&gt;
  &lt;li&gt;Kỳ vọng trừ phổ xử lý được tiếng vọng (thuộc AEC, bài 03-04) hoặc nhiễu có hướng (thuộc beamforming, bài 03-05).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Chạy thuật toán trừ phổ biên độ trên 8 bin mẫu và in danh sách các bin bị kẹp về ngưỡng sàn.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;magY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;4.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Nhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;raw&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;magY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Nhat&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;magS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;maximum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;magY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;clipped&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raw&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;magY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;raw&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;magS&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;magS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;clipped bins&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clipped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;raw&lt;/code&gt; bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[-0.8, 1.5, -1.0, 1.8, 0.2, -0.5, -0.9, 0.8]&lt;/code&gt;. Sau khi áp ngưỡng sàn, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;magS&lt;/code&gt; bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0.12, 1.5, 0.08, 1.8, 0.22, 0.11, 0.05, 0.8]&lt;/code&gt;. Các bin bị kẹp sàn là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0, 2, 4, 5, 6]&lt;/code&gt;, trong khi các bin 1, 3 và 7 đi qua nguyên vẹn.&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Áp dụng công thức công suất (&lt;/td&gt;
      &lt;td&gt;Y&lt;/td&gt;
      &lt;td&gt;^2) lên bộ số biên độ này hoặc quên nhân &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;beta * magY&lt;/code&gt; sẽ làm sai cả tập bin bị cắt lẫn giá trị sàn; kiểm tra điều kiện &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;raw &amp;lt; 0&lt;/code&gt; sẽ bỏ sót bin 4 (dù phần dư 0.2 vẫn dương nhưng thấp hơn ngưỡng sàn 0.22); đặt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alpha=1&lt;/code&gt; sẽ cắt ít bin hơn và che mất tác động trừ dư mà ví dụ muốn minh họa.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;bài-tập&quot;&gt;Bài tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Chứng minh rằng khi $$&lt;/td&gt;
          &lt;td&gt;Y&lt;/td&gt;
          &lt;td&gt;&amp;lt; \alpha\widehat{&lt;/td&gt;
          &lt;td&gt;N&lt;/td&gt;
          &lt;td&gt;}\(thì công thức có ngưỡng sàn trả về\)\beta&lt;/td&gt;
          &lt;td&gt;Y&lt;/td&gt;
          &lt;td&gt;\(, và giải thích ý nghĩa vật lý của\)\beta$$.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;Cài đặt phiên bản ngoại tuyến bằng NumPy, quét các cặp giá trị \(\alpha, \beta\) và ghi nhận sự đánh đổi giữa nhiễu nhạc và nhiễu dư.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Thay nhiễu dừng bằng tiếng gõ bàn phím và giải thích vì sao ước lượng $$\widehat{&lt;/td&gt;
          &lt;td&gt;N&lt;/td&gt;
          &lt;td&gt;}$$ cố định thất bại.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;Viết 5 gạch đầu dòng phân tích khi nào nên giữ tầng tiền xử lý kiểu SpeexDSP trước DeepFilterNet3 WASM và khi nào nên tắt hẳn.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;max&lt;/code&gt; trả về đối số thứ hai khi đối số thứ nhất nhỏ hơn (và rõ ràng khi (&lt;/td&gt;
          &lt;td&gt;Y&lt;/td&gt;
          &lt;td&gt;- \alpha\widehat{&lt;/td&gt;
          &lt;td&gt;N&lt;/td&gt;
          &lt;td&gt;} &amp;lt; 0 &amp;lt; \beta&lt;/td&gt;
          &lt;td&gt;Y&lt;/td&gt;
          &lt;td&gt;)); (\beta&lt;/td&gt;
          &lt;td&gt;Y&lt;/td&gt;
          &lt;td&gt;) chính là tỷ lệ biên độ nhiễu tối thiểu được giữ lại để tránh tạo hố phổ cứng.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;Ước lượng nền nhiễu từ đoạn đầu chỉ có nhiễu, sau đó nghe kỹ phần đuôi nhiễu khi tăng (\alpha) và giảm (\beta).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Đợt xung cao hơn sàn cố định sẽ bị trừ thiếu và lọt qua, còn các khung sau đó có thể bị trừ quá mức; cần chỉ cập nhật (\widehat{&lt;/td&gt;
          &lt;td&gt;N&lt;/td&gt;
          &lt;td&gt;}) khi VAD xác nhận không có tiếng nói.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;Có thể giữ tầng tiền xử lý dừng chi phí thấp khi nhiễu ù rất ổn định và mô hình mạng nơ-ron cần tiết kiệm tải; nên tắt nếu tầng tiền xử lý khoét hố phổ hoặc gây méo khiến mô hình 48 kHz phía sau nhận diện sai cấu trúc tiếng nói.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;S. F. Boll, bài báo kinh điển về trừ phổ, &lt;em&gt;IEEE TASSP&lt;/em&gt;, 1979.&lt;/li&gt;
  &lt;li&gt;Berouti &amp;amp; Makhoul — kỹ thuật trừ dư và ngưỡng sàn (trình bày trong Loizou, &lt;em&gt;Speech Enhancement&lt;/em&gt;).&lt;/li&gt;
  &lt;li&gt;Tài liệu bộ tiền xử lý SpeexDSP (Xiph).&lt;/li&gt;
  &lt;li&gt;Đối chiếu thêm: bộ ước lượng Ephraim–Malah / Wiener (bài 03-02) và RNNoise (bài 04-06).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xb--68NlxS0&quot;&gt;Spectral Subtraction In Python - Alexx Mitchell&lt;/a&gt; — The Audio Programmer, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày trực quan luồng thuật toán: ước lượng biên độ nhiễu, trừ rồi áp sàn; minh họa nguyên nhân phát sinh nhiễu nhạc khi xử lý bin âm một cách thô bạo.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Phần mở đầu cho thấy vì sao các sản phẩm gọi thoại sau này thay thế bộ khử cổ điển bằng mô hình học sâu.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Nên nghe sau khi nắm sơ đồ trừ phổ để cảm nhận chất lượng đích mà các thuật toán cổ điển khó đạt được.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-07 Đánh đổi độ trễ và chất lượng của pipeline</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_07_pipeline_latency_quality/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_07_pipeline_latency_quality</id>
   <content type="html">&lt;p&gt;Mỗi lựa chọn về STFT và kiến trúc mô hình đều là một sự đánh đổi giữa độ trễ, tải CPU và chất lượng âm thanh. Nguyên tắc cốt lõi để tránh quyết định triển khai sai lầm là: &lt;strong&gt;độ trễ thuật toán cho biết âm thanh bị trễ bao lâu, còn hệ số thời gian thực (RTF) cho biết CPU có xử lý kịp hay không.&lt;/strong&gt; Một mô hình chạy rất nhanh vẫn có thể gây độ trễ quá lớn cho cuộc gọi.&lt;/p&gt;

&lt;p&gt;Trong phòng thí nghiệm, bạn có thể đẩy kích thước cửa sổ lên 64 ms và cho mạng nơ-ron nhìn trước nửa giây để ghi điểm PESQ cao chót vót trên bảng xếp hạng. Nhưng khi đưa lên cuộc gọi thoại thật, kỹ sư hệ thống phải đối mặt với &lt;strong&gt;tam giác đánh đổi nghiệt ngã&lt;/strong&gt; của mọi pipeline âm thanh thời gian thực: &lt;strong&gt;Độ trễ (Latency) – Chất lượng phổ (Quality) – Chi phí tính toán (CPU/RTF)&lt;/strong&gt;. Bài học tổng kết Chương 2 này giúp bạn nhìn toàn bộ pipeline STFT → Xử lý → ISTFT như một bài toán tối ưu kỹ thuật có thể đo đạc bằng con số!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-đánh-đổi-độ-trễ--chất-lượng--cpu-trong-pipeline-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Đánh đổi Độ trễ – Chất lượng – CPU trong Pipeline đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-giải-phẫu-tổng-độ-trễ-algorithmic--buffering--compute-latency&quot;&gt;1. Giải phẫu tổng độ trễ (Algorithmic + Buffering + Compute Latency)&lt;/h3&gt;
&lt;p&gt;Độ trễ một chiều của pipeline không chỉ là thời gian chạy mô hình! Nó gồm 4 phần cộng dồn: (1) &lt;strong&gt;Độ trễ khung STFT/OLA&lt;/strong&gt; (thường bằng \(N\) hoặc \(H\) tùy cách căn đệm), (2) &lt;strong&gt;Độ trễ nhìn trước (Look-ahead)&lt;/strong&gt; nếu dùng tích chập tương lai \(L_{\text{la}}\) khung, (3) &lt;strong&gt;Độ trễ đệm đồng bộ kích thước khối&lt;/strong&gt; (ví dụ nối 128 mẫu AudioWorklet với 480 mẫu hop), và (4) &lt;strong&gt;Thời gian tính toán CPU&lt;/strong&gt; \(T_{\text{compute}}\).&lt;/p&gt;

&lt;h3 id=&quot;2-tỉ-lệ-thuận-nghịch-giữa-bước-nhảy-h-và-tải-cpu&quot;&gt;2. Tỉ lệ thuận nghịch giữa Bước nhảy \(H\) và Tải CPU&lt;/h3&gt;
&lt;p&gt;Giảm bước nhảy \(H\) đi một nửa (ví dụ từ 10 ms xuống 5 ms, tăng chồng lấp từ 50% lên 75%) giúp giảm độ trễ phản hồi và làm mượt chuyển tiếp âm thanh, nhưng lập tức &lt;strong&gt;nhân đôi số khung mỗi giây&lt;/strong&gt; (từ 100 lên 200 khung/giây) — kéo theo tải CPU của cả FFT lẫn mạng nơ-ron tăng đúng &lt;strong&gt;gấp 2 lần&lt;/strong&gt;!&lt;/p&gt;

&lt;h3 id=&quot;3-thiết-kế-điểm-ngọt-thực-chiến-sweet-spot&quot;&gt;3. Thiết kế điểm ngọt thực chiến (Sweet Spot)&lt;/h3&gt;
&lt;p&gt;Các hệ thống thoại thương mại (WebRTC APM, RNNoise, DeepFilterNet3) hội tụ về một vùng thiết kế rất hẹp: &lt;strong&gt;hop 10 ms, cửa sổ 20 ms, look-ahead 0–20 ms&lt;/strong&gt; (tổng độ trễ thuật toán 20–40 ms) và &lt;strong&gt;RTF &amp;lt; 0.25&lt;/strong&gt; trên một nhân CPU tầm trung.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-so-sánh-hai-cấu-hình-pipeline-stft-ở-48-khz&quot;&gt;Giải thích: tự tay so sánh hai cấu hình Pipeline STFT ở 48 kHz&lt;/h3&gt;

&lt;p&gt;Giả sử bạn đang chọn cấu hình STFT cho một mô hình khử nhiễu tốn cố định \(T_{\text{model}} = 2.0\text{ ms}\) cho mỗi lần suy luận khung ở \(f_s = 48\,000\text{ Hz}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cấu hình A (Ưu tiên độ trễ cực thấp):&lt;/strong&gt; \(N = 480\text{ (10 ms)},\ H = 240\text{ (5 ms)},\ \text{look-ahead} = 0\).
    &lt;ul&gt;
      &lt;li&gt;Độ phân giải tần số: \(\Delta f = \frac{48\,000}{480} = \mathbf{100\text{ Hz/bin}}\) (khá thô, khó tách hài âm giọng nam 100–130 Hz).&lt;/li&gt;
      &lt;li&gt;Số khung/giây: \(200\text{ khung/s}\); hệ số thời gian thực: \(\text{RTF}_A = \frac{2.0\text{ ms}}{5.0\text{ ms}} = \mathbf{0.40}\) (ngốn 40% nhân CPU!).&lt;/li&gt;
      &lt;li&gt;Độ trễ thuật toán: \(10 + 2.0 = \mathbf{12\text{ ms}}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cấu hình B (Điểm ngọt kiểu DeepFilterNet):&lt;/strong&gt; \(N = 960\text{ (20 ms)},\ H = 480\text{ (10 ms)},\ \text{look-ahead} = 2\text{ khung (20 ms)}\).
    &lt;ul&gt;
      &lt;li&gt;Độ phân giải tần số: \(\Delta f = \frac{48\,000}{960} = \mathbf{50\text{ Hz/bin}}\) (mịn gấp đôi, tách sạch hài âm giọng nói!).&lt;/li&gt;
      &lt;li&gt;Số khung/giây: \(100\text{ khung/s}\); hệ số thời gian thực: \(\text{RTF}_B = \frac{2.0\text{ ms}}{10.0\text{ ms}} = \mathbf{0.20}\) (giảm &lt;strong&gt;50% tải CPU&lt;/strong&gt; so với Cấu hình A!).&lt;/li&gt;
      &lt;li&gt;Độ trễ thuật toán: \(20 + 20 + 2.0 = \mathbf{42\text{ ms}}\) (vẫn nằm thoải mái trong ngân sách 150 ms của VoIP).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nhìn hai con số đặt cạnh nhau, bạn thấy ngay vì sao Cấu hình B là chuẩn vàng của công nghiệp thoại hiện đại!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Liệt kê các công đoạn trong pipeline đóng góp vào độ trễ và tải CPU.&lt;/li&gt;
  &lt;li&gt;Định lượng sự đánh đổi giữa kích thước cửa sổ, hop, kích thước FFT với chất lượng và độ trễ.&lt;/li&gt;
  &lt;li&gt;Giải thích các chế độ suy giảm chất lượng khi tối ưu độ trễ quá mức.&lt;/li&gt;
  &lt;li&gt;Lập bảng tiêu chí đạt/không đạt (scorecard) cho một cấu hình trước khi triển khai.&lt;/li&gt;
  &lt;li&gt;Liên hệ các sự đánh đổi này với mục tiêu thiết kế thời gian thực của DeepFilterNet.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Sơ đồ pipeline đầu–cuối (micro → NS → bộ mã hóa)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–28&lt;/td&gt;
      &lt;td&gt;Phân tích định lượng qua các kịch bản cấu hình có số liệu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Các chế độ hỏng về chất lượng và độ trễ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Xây dựng bảng tiêu chí triển khai cho pipeline kiểu Mezon&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;Các quantum AudioWorklet trên trục thời gian; process() đôi khi vượt một quantum: RTF là thời gian tường trên thời lượng audio, khác với độ trễ thuật toán của cửa sổ STFT&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Mỗi vạch đại diện cho một quantum render; RTF so sánh thời gian thực tế (wall-clock) của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt; với thời lượng âm thanh tương ứng — đây là đại lượng tách biệt với độ trễ thuật toán của cửa sổ STFT.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;hai-đồng-hồ-độc-lập&quot;&gt;Hai đồng hồ độc lập&lt;/h3&gt;

&lt;p&gt;Độ trễ thuật toán là thuộc tính cố hữu của đồ thị tín hiệu. Với STFT nhân quả như đã xét ở bài 02-02:&lt;/p&gt;

\[D_{\mathrm{alg}}\approx T_L=\frac{L}{f_s},\]

&lt;p&gt;cộng thêm số khung nhìn trước (look-ahead), trễ của bộ lấy mẫu lại và bộ đệm đóng gói. Ở 48 kHz, cửa sổ (L=960) luôn đóng góp khoảng &lt;strong&gt;20 ms&lt;/strong&gt; bất kể phép FFT chạy mất 0.2 ms hay 2 ms trên CPU — tín hiệu bị trễ đơn giản vì hệ thống phải chờ thu đủ số mẫu lấp đầy cửa sổ.&lt;/p&gt;

&lt;p&gt;Ngược lại, RTF là thuộc tính hiệu năng của bản cài đặt:&lt;/p&gt;

\[\mathrm{RTF}=\frac{T_{\mathrm{wall}}(D)}{D}.\]

&lt;p&gt;Trong đó (D) là thời lượng âm thanh vừa xử lý (một hop hoặc một quantum). Điều kiện (\mathrm{RTF}&amp;lt;1) chỉ đảm bảo khối hiện tại xử lý xong trước khi khối tiếp theo đến hạn, chứ không phản ánh lượng look-ahead đã đưa vào thuật toán. Cảnh báo thứ hai từ hình minh họa: ngay cả khi RTF trung bình bằng 0.4, âm thanh vẫn bị lách tách nếu phân vị p99 vượt quá thời lượng hop — do đó luôn phải ghi nhận p95 và p99.&lt;/p&gt;

&lt;p&gt;Một quantum 128 mẫu ở 48 kHz kéo dài (128/48000\approx 2.67\,\mathrm{ms}). Đây là nhịp lưới của AudioWorklet trong hình, không phải bước nhảy hop của mô hình. Một hop 10 ms trải qua gần bốn quantum; thanh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt; màu đỏ minh họa quantum nơi phép FFT và mạng nơ-ron bị vượt hạn (overrun). Lưu ý rằng thời gian khởi động lạnh (biên dịch WASM/ONNX) diễn ra trên luồng chính, không tính vào RTF ở trạng thái ổn định.&lt;/p&gt;

&lt;h3 id=&quot;các-công-đoạn-điển-hình-trong-pipeline&quot;&gt;Các công đoạn điển hình trong pipeline&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Thu âm / đệm theo quantum AudioWorklet&lt;/li&gt;
  &lt;li&gt;Lấy mẫu lại (resample) về tần số lấy mẫu của mô hình&lt;/li&gt;
  &lt;li&gt;Gộp kênh (downmix) về mono&lt;/li&gt;
  &lt;li&gt;Cắt khung STFT (áp cửa sổ và hop)&lt;/li&gt;
  &lt;li&gt;Trích xuất đặc trưng (ví dụ thang ERB)&lt;/li&gt;
  &lt;li&gt;Khử nhiễu bằng mạng nơ-ron hoặc thuật toán cổ điển&lt;/li&gt;
  &lt;li&gt;Biến đổi ngược đặc trưng, tính ISTFT và cộng chồng lấp OLA&lt;/li&gt;
  &lt;li&gt;Lấy mẫu lại về tần số của đầu ra (sink)&lt;/li&gt;
  &lt;li&gt;Chuyển sang bộ mã hóa (encoder) WebRTC&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Với từng công đoạn, hãy đo tách biệt phần độ trễ trên dạng sóng và phần đóng góp vào RTF. Một bộ lấy mẫu lại có thể tiêu tốn rất ít RTF nhưng vẫn cộng thêm trễ nhóm (group delay); ngược lại, phiên chạy ONNX có thể chiếm RTF lớn mà không cộng thêm look-ahead ngoài phần STFT.&lt;/p&gt;

&lt;h3 id=&quot;các-tham-số-điều-chỉnh-và-hệ-quả&quot;&gt;Các tham số điều chỉnh và hệ quả&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Khi tăng tham số&lt;/th&gt;
      &lt;th&gt;Độ trễ&lt;/th&gt;
      &lt;th&gt;Tải CPU&lt;/th&gt;
      &lt;th&gt;Xu hướng chất lượng&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Độ dài cửa sổ (L)&lt;/td&gt;
      &lt;td&gt;Tăng&lt;/td&gt;
      &lt;td&gt;Tăng (FFT lớn hơn)&lt;/td&gt;
      &lt;td&gt;Độ phân giải tần số tốt hơn nhưng nhòe hơn theo thời gian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bước nhảy hop (R)&lt;/td&gt;
      &lt;td&gt;Bản thân hop không quyết định toàn bộ (D_{\mathrm{alg}}); giảm (R) làm tăng hop/s&lt;/td&gt;
      &lt;td&gt;Tăng khi giảm (R)&lt;/td&gt;
      &lt;td&gt;Mặt nạ thường mượt hơn khi giảm (R)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Kích thước mô hình&lt;/td&gt;
      &lt;td&gt;Gần như không đổi nếu giữ nguyên look-ahead&lt;/td&gt;
      &lt;td&gt;Tăng&lt;/td&gt;
      &lt;td&gt;Thường cải thiện cho tới khi RTF vượt ngưỡng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Số khung look-ahead&lt;/td&gt;
      &lt;td&gt;Tăng&lt;/td&gt;
      &lt;td&gt;Tăng&lt;/td&gt;
      &lt;td&gt;Chất lượng thường cải thiện&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tần số lấy mẫu&lt;/td&gt;
      &lt;td&gt;Tăng (nếu giữ số mẫu)&lt;/td&gt;
      &lt;td&gt;Tăng&lt;/td&gt;
      &lt;td&gt;Mở rộng băng thông nếu mô hình được huấn luyện cho tần số đó&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Nguyên tắc bắt buộc phải đo đạc.&lt;/strong&gt; Giảm (R) từ 480 xuống 240 ở 48 kHz làm tăng gấp đôi số hop mỗi giây (từ 100 lên 200) và gần gấp đôi chi phí CPU của STFT, trong khi (D_{\mathrm{alg}}) vẫn xấp xỉ (L/f_s) nếu không rút ngắn cửa sổ. Ngược lại, rút ngắn cửa sổ lại làm rộng búp chính theo tần số (bài 02-03) — đó là sự đánh đổi chất lượng chứ không phải khoản tối ưu RTF miễn phí.&lt;/p&gt;

&lt;h3 id=&quot;các-con-số-mốc-cần-ghi-nhớ&quot;&gt;Các con số mốc cần ghi nhớ&lt;/h3&gt;

&lt;p&gt;Ở tần số 48 kHz:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Quantum 128 mẫu ≈ 2.67 ms&lt;/li&gt;
  &lt;li&gt;Hop 480 mẫu = 10 ms → 100 bước xử lý mỗi giây&lt;/li&gt;
  &lt;li&gt;Cửa sổ 960 mẫu = thang đệm 20 ms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ở 16 kHz, cùng &lt;em&gt;thời lượng mili giây&lt;/em&gt; sẽ chứa ít mẫu hơn (FFT nhẹ hơn) nhưng băng thông hẹp hơn; ngược lại, cùng &lt;em&gt;số lượng mẫu&lt;/em&gt; lại cho thời lượng khác hẳn ((L=512) ở 16 kHz là 32 ms chứ không phải 20 ms). Thời gian xử lý thực tế 3 ms trên hop 10 ms tương ứng (\mathrm{RTF}=0.3) (an toàn); thời gian 12 ms trên cùng hop đó cho (\mathrm{RTF}=1.2) (vượt hạn), dù 12 ms vẫn nhỏ hơn độ dài cửa sổ 20 ms. Phần Mini-lab tách riêng hai đại lượng này thành hai biến độc lập để tránh nhầm lẫn.&lt;/p&gt;

&lt;h3 id=&quot;các-chế-độ-hỏng-thường-gặp&quot;&gt;Các chế độ hỏng thường gặp&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ngân sách độ trễ quá chặt:&lt;/strong&gt; cửa sổ quá ngắn khiến các họa âm không tách biệt được và mặt nạ trở nên gắt.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ trễ quá lớn:&lt;/strong&gt; cuộc gọi có cảm giác trễ rõ rệt; nếu đặt look-ahead trước bộ khử vọng AEC, đường tiếng vọng sẽ trông như bị trôi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Biên độ dự phòng CPU quá nhỏ:&lt;/strong&gt; chỉ cần các khung ở phân vị p99 bị vượt hạn (thanh đỏ) đã đủ gây tiếng nổ lách tách dù RTF trung bình rất thấp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;phiếu-tiêu-chí-triển-khai-ví-dụ-minh-họa&quot;&gt;Phiếu tiêu chí triển khai (ví dụ minh họa)&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tiêu chí&lt;/th&gt;
      &lt;th&gt;Mục tiêu minh họa&lt;/th&gt;
      &lt;th&gt;Đạt?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Độ trễ thuật toán + look-ahead&lt;/td&gt;
      &lt;td&gt;≤ ngân sách sản phẩm (khoảng 20–40 ms)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;p95 RTF trên thiết bị đích&lt;/td&gt;
      &lt;td&gt;≤ 0.5&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Kiểm tra khứ hồi COLA&lt;/td&gt;
      &lt;td&gt;Sai số dưới ngưỡng cho phép&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DNSMOS / kiểm tra nghe&lt;/td&gt;
      &lt;td&gt;So sánh với baseline NS của WebRTC&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Không rung biên độ theo hop&lt;/td&gt;
      &lt;td&gt;Kiểm tra bằng nghe và phổ đồ&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Hãy thay các giá trị minh họa bằng cam kết SLA thực tế của sản phẩm, và tuyệt đối không coi việc đạt “RTF ≤ 0.5” là đã thỏa mãn ngân sách độ trễ thuật toán hoặc ngược lại.&lt;/p&gt;

&lt;h3 id=&quot;áp-dụng-vào-cấu-hình-deepfilternet&quot;&gt;Áp dụng vào cấu hình DeepFilterNet&lt;/h3&gt;

&lt;p&gt;Cấu hình toàn băng công bố của DeepFilterNet dùng tần số 48 kHz, STFT 960 điểm (20 ms), chồng lấp 50% (hop 10 ms) kèm vài khung look-ahead (&lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;). Hãy xem đây là các ràng buộc cứng của mô hình; không gian tối ưu nằm ở vị trí đặt trên đồ thị xử lý, khâu lấy mẫu lại và ngân sách phần cứng. Gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 vận hành trên đúng giao ước 48 kHz đó — nếu phân vị p95 của RTF không đạt, không được tự ý thay đổi bước nhảy hop.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cấu hình A:&lt;/strong&gt; 16 kHz, (L=20\,\mathrm{ms}), (R=10\,\mathrm{ms}), mô hình nhỏ, RTF 0.2, điểm MOS ổn định.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cấu hình B:&lt;/strong&gt; 48 kHz, (L=40\,\mathrm{ms}), (R=5\,\mathrm{ms}), mô hình lớn, RTF 0.9, điểm MOS ngoại tuyến cao hơn nhưng bị giật trên điện thoại → &lt;strong&gt;không triển khai B&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ở cấu hình B, riêng độ dài cửa sổ đã chiếm 40 ms và RTF trung bình 0.9 không còn đủ biên độ an toàn cho các quantum bị tăng tải đột biến.&lt;/p&gt;

&lt;p&gt;Tương tự, với ngân sách thuật toán 40 ms đã dùng hết 20 ms cho cửa sổ, hệ thống không thể tùy tiện cộng thêm nhiều khung look-ahead 10 ms; càng không thể “tiết kiệm” 20 ms đó bằng cách chỉ báo cáo 3 ms thời gian xử lý thực tế.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chỉ tối ưu RTF trung bình mà bỏ qua các phân vị đuôi.&lt;/li&gt;
  &lt;li&gt;Thay đổi (L) hoặc (R) nhưng không chạy lại toàn bộ quy trình đánh giá.&lt;/li&gt;
  &lt;li&gt;So sánh chất lượng giữa các mô hình có độ trễ khác nhau một cách thiếu công bằng.&lt;/li&gt;
  &lt;li&gt;Quên tính chi phí lấy mẫu lại (resample) vào tổng RTF.&lt;/li&gt;
  &lt;li&gt;Dùng số đo hiệu năng của bản biên dịch debug làm căn cứ triển khai thực tế.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; In tách biệt độ trễ khung thuật toán và hệ số RTF cho một hop ở 48 kHz, bao gồm cả tình huống vượt hạn (overrun), không cần thiết bị âm thanh vật lý.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;960&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;480&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;frame_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;quantum_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;algorithmic frame ms&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;frame_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hop ms&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;quantum ms&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;quantum_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rtf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wall_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;audio_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wall_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;audio_ms&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;RTF if process() takes 3 ms&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rtf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;3.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;RTF if process() takes 12 ms&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rtf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;12.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Độ trễ khung là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;20.0&lt;/code&gt; ms, hop &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10.0&lt;/code&gt; ms và quantum khoảng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2.67&lt;/code&gt; ms; RTF in ra lần lượt là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.3&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.2&lt;/code&gt;. Trường hợp sau vượt hạn hop dù 12 ms vẫn nhỏ hơn độ dài cửa sổ 20 ms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Chia thời gian xử lý thực tế cho độ dài cửa sổ thay vì cho hop sẽ cho ra RTF (12/20 = 0.6) và che giấu hoàn toàn lỗi overrun; diễn giải RTF 0.3 thành “độ trễ 3 ms” là đánh đồng hai đồng hồ độc lập, khiến bảng kiểm tra báo đạt trong khi người dùng vẫn nghe thấy độ trễ hoặc tiếng nổ. Tình huống p99 đạt 12 ms trong khi trung bình chỉ 3 ms chính là cảnh báo cốt lõi của hình minh họa: luôn phải ghi log cả hai.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Vẽ sơ đồ pipeline 9 công đoạn và đánh dấu các vị trí cần ghi mốc thời gian (timestamp).&lt;/li&gt;
  &lt;li&gt;Khi giảm hop từ 10 ms xuống 5 ms, số hop mỗi giây và tải CPU thay đổi xấp xỉ như thế nào?&lt;/li&gt;
  &lt;li&gt;Đề xuất ba chỉ số cho bảng đánh giá (scorecard) của phần mềm tổng đài chăm sóc khách hàng.&lt;/li&gt;
  &lt;li&gt;Vì sao đưa tín hiệu 48 kHz trực tiếp vào mô hình huấn luyện ở 16 kHz vẫn gây hại dù CPU dư sức xử lý?&lt;/li&gt;
  &lt;li&gt;Nêu một dạng méo chất lượng điển hình khi chọn cửa sổ phân tích quá ngắn.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Ghi mốc thời gian tại các điểm: thu mẫu, sau lấy mẫu lại, đầu vào STFT, đầu ra STFT và khi giao cho bộ mã hóa; lấy hiệu giữa các mốc để tách bạch độ trễ tín hiệu với thời gian xử lý thực tế.&lt;/li&gt;
  &lt;li&gt;Số hop mỗi giây tăng gấp đôi (từ 100 lên 200 ở 48 kHz nếu hop ban đầu là 480 mẫu), kéo theo tải CPU của phần STFT tăng gần gấp đôi; trong khi đó (D_{\mathrm{alg}}) không giảm đi một nửa trừ khi thay đổi cả (L).&lt;/li&gt;
  &lt;li&gt;Ví dụ: phân vị p95 của RTF, độ trễ thuật toán so với ngân sách cuộc gọi và điểm nghe/DNSMOS trên tập mẫu chứa tên riêng cùng chữ số.&lt;/li&gt;
  &lt;li&gt;Các bin tần số và biên dải ERB của mạng được thiết kế cố định cho 16 kHz; gán nhãn dữ liệu 48 kHz thành 16 kHz làm sai lệch toàn bộ trục phổ, đồng thời phần băng tần cao hơn có thể bị aliasing nếu thiếu lọc thông thấp.&lt;/li&gt;
  &lt;li&gt;Các họa âm không tách bạch được và mặt nạ trở nên gắt, nhấp nháy; ngược lại, chọn cửa sổ quá dài sẽ làm nhòe các âm bật (plosive).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Cấu hình định khung thời gian thực của DeepFilterNet: &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt; và &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;github.com/Rikorose/DeepFilterNet&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Tổng quan WebRTC APM: &lt;a href=&quot;https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/&quot;&gt;modules/audio_processing&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Hướng dẫn tối ưu hiệu năng AudioWorklet trên MDN — mối quan hệ giữa quantum và bước nhảy hop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Quan sát thông số độ trễ đặt cạnh kiến trúc hai tầng: độ trễ thuật toán cho biết tín hiệu đến muộn bao lâu, còn số phép tính cho biết CPU có theo kịp nhịp thời gian thực hay không.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Phần bàn về độ phức tạp thể hiện nửa còn lại của sự đánh đổi: mô hình nặng hơn có thể thắng điểm đánh giá nhưng vẫn trượt hạn hop.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, tiếng Anh. Số đo độ trễ callback thực tế xác định giới hạn ngân sách mà hop STFT bắt buộc phải tuân theo.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-06 Spectrogram: đọc tiếng nói và nhiễu</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_06_spectrograms_reading/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_06_spectrograms_reading</id>
   <content type="html">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Phổ đồ (spectrogram) là công cụ giao tiếp chung của kỹ sư xử lý tiếng nói. Bài học này hướng dẫn cách đọc cấu trúc tiếng nói, nhận diện các dạng nhiễu và phát hiện méo âm (artifact) sau khử nhiễu, đồng thời tránh bị đánh lừa bởi thang màu dB. Phổ đồ không phải là “bức ảnh tuyệt đối của âm thanh” mà là biểu diễn (&lt;/td&gt;
      &lt;td&gt;X(\ell,k)&lt;/td&gt;
      &lt;td&gt;) của một cấu hình STFT cụ thể theo thang decibel có ngưỡng sàn; chỉ cần đổi hàm cửa sổ hoặc dải màu là hình ảnh thu được sẽ kể một câu chuyện hoàn toàn khác.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Một kỹ sư âm thanh lão luyện không chỉ nghe tệp âm thanh bằng tai — họ &lt;strong&gt;“đọc” âm thanh bằng mắt&lt;/strong&gt; qua &lt;strong&gt;Spectrogram&lt;/strong&gt; (ảnh phổ thời gian–tần số hiển thị theo thang màu log-dB). Chỉ cần liếc 3 giây vào spectrogram, họ có thể chỉ ra ngay: đoạn nào là nguyên âm có thanh (các vạch ngang song song đều đặn), đoạn nào là phụ âm xát /s/, /sh/ (đám mây sáng ở vùng 4–10 kHz), tiếng gõ phím (vạch đứng sắc lẹm chạy từ đáy lên nóc), tiếng ù điện 50/100 Hz (đường kẻ ngang bất động suốt cả bài), hay dấu vết “nhiễu nhạc” do bộ khử nhiễu cắt quá tay!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-đọc-spectrogram-tiếng-nói-đứng-trên-ba-trụ-cột-âm-học-nào&quot;&gt;Kiến thức cần nhớ: Đọc Spectrogram Tiếng nói đứng trên ba trụ cột âm học nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-mô-hình-nguồn--bộ-lọc-sourcefilter-model-của-giọng-nói&quot;&gt;1. Mô hình Nguồn – Bộ lọc (Source–Filter Model) của Giọng nói&lt;/h3&gt;
&lt;p&gt;Giọng nói con người sinh ra từ hai bộ phận: &lt;strong&gt;Dây thanh (Source)&lt;/strong&gt; rung tuần hoàn với tần số cơ bản \(F_0\) (nam ~85–180 Hz, nữ ~165–255 Hz) tạo ra chuỗi &lt;strong&gt;hài âm (harmonics)&lt;/strong&gt; \(F_0, 2F_0, 3F_0, \dots\); sau đó &lt;strong&gt;Khoang miệng – mũi (Filter)&lt;/strong&gt; cộng hưởng khuếch đại một vài dải tần cố định gọi là &lt;strong&gt;Formant (\(F_1, F_2, F_3\))&lt;/strong&gt; — chính vị trí formant quyết định tai ta nghe ra chữ “a”, “i” hay “u”!&lt;/p&gt;

&lt;h3 id=&quot;2-spectrogram-dải-hẹp-narrowband-vs-dải-rộng-wideband&quot;&gt;2. Spectrogram Dải hẹp (Narrowband) vs. Dải rộng (Wideband)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dải hẹp&lt;/strong&gt; (cửa sổ dài \(20\text{–}40\text{ ms}\), \(\Delta f\) nhỏ): nhìn tách bạch từng &lt;strong&gt;vạch hài âm ngang&lt;/strong&gt; song song.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dải rộng&lt;/strong&gt; (cửa sổ ngắn \(4\text{–}8\text{ ms}\), \(\Delta f\) lớn): các vạch hài âm hòa vào nhau, làm nổi bật các dải cộng hưởng &lt;strong&gt;Formant&lt;/strong&gt; và từng nhịp rung dọc của dây thanh!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-thang-log-db-và-thang-tần-số-cảm-thụ-mel--erb&quot;&gt;3. Thang Log-dB và Thang Tần số Cảm thụ (Mel / ERB)&lt;/h3&gt;
&lt;p&gt;Vì năng lượng phụ âm cao tần yếu hơn nguyên âm trầm tới 30–50 dB, spectrogram luôn vẽ biên độ theo thang \(20\log_{10}(|X| + \epsilon)\) (dB). Đồng thời, vì tai người phân biệt tần số mịn ở vùng trầm nhưng thô dần ở vùng cao, các hệ thống hiện đại nhóm trục tần số theo thang &lt;strong&gt;Mel&lt;/strong&gt; (cho ASR) hoặc &lt;strong&gt;ERB (Equivalent Rectangular Bandwidth — dùng trong DeepFilterNet)&lt;/strong&gt;!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-đọc-tần-số-cơ-bản-f_0-và-chọn-cửa-sổ-tách-hài-âm&quot;&gt;Giải thích: tự tay đọc tần số cơ bản \(F_0\) và chọn cửa sổ tách hài âm&lt;/h3&gt;

&lt;p&gt;Giả sử bạn thu âm một giọng nam đọc nguyên âm /a/ với tần số cơ bản \(F_0 = 125\text{ Hz}\) ở \(f_s = 48\,000\text{ Hz}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Vị trí các vạch hài âm ngang trên spectrogram:&lt;/strong&gt;
\(f_1 = 125\text{ Hz},\quad f_2 = 250\text{ Hz},\quad f_3 = 375\text{ Hz},\quad f_4 = 500\text{ Hz},\ \dots,\ f_8 = 1\,000\text{ Hz}.\)
Đếm thấy đúng &lt;strong&gt;8 vạch ngang&lt;/strong&gt; trong dải \(0\text{–}1\,000\text{ Hz}\) → chia ngược \(1\,000 / 8 = \mathbf{125\text{ Hz}}\), đọc ngay ra cao độ giọng nói chỉ bằng mắt!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra điều kiện tách hài âm giữa hai cửa sổ:&lt;/strong&gt; Muốn thấy rãnh tối giữa hai vạch cách nhau \(125\text{ Hz}\), độ phân giải tần số \(\Delta f = \frac{f_s}{N}\) cần nhỏ hơn \(\frac{F_0}{2} \approx 62.5\text{ Hz}\) (với cửa sổ Hann cần thậm chí mịn hơn do búp chính rộng gấp đôi):
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Cửa sổ dài \(T = 20\text{ ms}\) (\(N = 960\)):&lt;/em&gt; \(\Delta f = \frac{48\,000}{960} = \mathbf{50\text{ Hz}} &amp;lt; 125\text{ Hz}\) → các vạch hài âm tách rời sắc nét (spectrogram &lt;strong&gt;dải hẹp&lt;/strong&gt;)!&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Cửa sổ ngắn \(T = 5\text{ ms}\) (\(N = 240\)):&lt;/em&gt; \(\Delta f = \frac{48\,000}{240} = \mathbf{200\text{ Hz}} &amp;gt; 125\text{ Hz}\) → hai hài âm liền kề dính hẳn vào nhau thành dải ngang dày (spectrogram &lt;strong&gt;dải rộng&lt;/strong&gt;), đổi lại bạn nhìn thấy rõ từng tiếng gõ phím ngắn chỉ 5 ms!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Đọc chính xác các trục của phổ đồ (thời gian, tần số và thang màu dB).&lt;/li&gt;
  &lt;li&gt;Nhận diện nguyên âm hữu thanh, formant, phụ âm xát và khoảng lặng.&lt;/li&gt;
  &lt;li&gt;Nhận diện nền nhiễu dừng, nhiễu bùng nổ (burst), babble và nhạc nền.&lt;/li&gt;
  &lt;li&gt;Phát hiện các méo âm phổ biến sau khử nhiễu (nhiễu nhạc, khử quá mức, rung biên độ theo hop).&lt;/li&gt;
  &lt;li&gt;Kết hợp phổ đồ một cách hợp lý cùng đánh giá nghe và các chỉ số định lượng.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Cấu tạo và các thành phần của một biểu đồ phổ đồ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–28&lt;/td&gt;
      &lt;td&gt;Các mẫu đặc trưng của tiếng nói (nhận diện trực quan không cần nghe)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Các mẫu nhiễu và cách đọc tín hiệu hỗn hợp&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;So sánh méo âm trước và sau khử nhiễu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/spectrogram-reading.png&quot; alt=&quot;Spectrogram tiếng nói: các vạch hài nằm ngang xếp chồng, rồi một burst nhiễu dọc phủ mọi băng&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Các họa âm hữu thanh hiện lên thành chồng vạch ngang đều đặn; một đợt nhiễu bùng nổ xuất hiện thành dải dọc phủ kín mọi băng tần cùng lúc.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;các-trục-và-thang-hiển-thị&quot;&gt;Các trục và thang hiển thị&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trục hoành (X):&lt;/strong&gt; thời gian (giây) hoặc chỉ số khung.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trục tung (Y):&lt;/strong&gt; tần số Hz (tuyến tính) hoặc thang cảm thụ (Mel/ERB).&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Màu sắc:&lt;/strong&gt; thường là (20\log_{10}&lt;/td&gt;
          &lt;td&gt;X(\ell,k)&lt;/td&gt;
          &lt;td&gt;) kèm ngưỡng sàn.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mỗi ảnh phổ đồ luôn cần ghi rõ metadata: (f_s), hàm cửa sổ, bước nhảy hop, kích thước FFT và dải dB (ví dụ −80..0 dB). Thiếu các thông số này, ảnh chụp màn hình không đủ giá trị làm bằng chứng kỹ thuật.&lt;/p&gt;

\[S(\ell,k)=20\log_{10}\bigl(\max(|X(\ell,k)|,\,\varepsilon)\bigr).\]

&lt;p&gt;Trong đó (\varepsilon) là ngưỡng sàn. Nếu thiếu (\varepsilon), một bin bằng 0 tuyệt đối (sau khi áp mặt nạ cứng) sẽ cho giá trị (-\infty), kéo giãn thang màu lệch quanh điểm lỗ đó và khiến toàn bộ câu nói biến thành một mảng màu bệt, mất tương phản. Đặt sàn quanh −80 dB so với sóng sin toàn thang (full-scale) giúp khoảng lặng hiển thị tối rõ trong khi các họa âm nguyên âm vẫn sắc nét. Hai ảnh phổ đồ chỉ có thể so sánh công bằng khi có cùng (\varepsilon), hàm cửa sổ và bước nhảy hop. Ngoài ra, trục Mel không khớp trực tiếp với lỗi theo bin tuyến tính: bin (k) tương ứng với (k f_s/N) Hz, còn dãy lọc Mel đã cộng gộp nhiều bin lại với nhau.&lt;/p&gt;

&lt;h3 id=&quot;quy-trình-đọc-phổ-đồ-chuẩn&quot;&gt;Quy trình đọc phổ đồ chuẩn&lt;/h3&gt;

&lt;p&gt;Hãy áp dụng quy trình 5 bước sau cho hình minh họa và cho mọi ảnh đính kèm trong phiếu báo lỗi (ticket):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra thông số STFT.&lt;/strong&gt; Đọc kỹ (f_s), cửa sổ, hop, (N) và dải dB trước khi diễn giải màu sắc. Trên hình minh họa, các vạch ngang nằm gần 1.2, 2.4, 3.6, 4.8, 6.0 và 7.2 kHz — tương ứng tần số cơ bản 1.2 kHz cùng các họa âm trên trục Hz tuyến tính.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Xác định khoảng lặng hoặc nền nhiễu.&lt;/strong&gt; Vùng tối trước mốc 0.2 s và sau đợt burst là nền nhiễu. Nếu nền hiển thị sáng, có thể micro đang có tiếng rít hoặc thang màu đang phóng đại 20 dB dưới cùng — không nên vội kết luận mô hình “khử chưa đủ” khi chưa kiểm tra thang màu.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm chồng họa âm.&lt;/strong&gt; Các vạch ngang cách đều nhau là dấu hiệu của âm hữu thanh (hoặc nhạc), với khoảng cách giữa hai vạch chính là tần số cơ bản (f_0). Trong hình minh họa, khoảng cách khoảng 1.2 kHz tương ứng giọng rất cao hoặc một nốt nhạc (giọng nói thông thường nằm quanh 100–200 Hz), nhưng hình học hoàn toàn tương tự.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tìm các sự kiện theo phương dọc.&lt;/strong&gt; Âm bật (plosive) hoặc đợt nhiễu bùng nổ làm sáng đồng loạt nhiều bin trong một đến hai khung. Dải cam quanh mốc 0.85–1.0 s là ví dụ điển hình: năng lượng trải khắp mọi tần số chứ không phải một họa âm mới; tiếng gõ phím hay tiếng ho có hình dạng tương tự nhưng hẹp hơn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh trước và sau khử nhiễu trên cùng một thang đo.&lt;/strong&gt; Các vạch hài bậc cao biến mất báo hiệu khử quá mức (over-suppression); các đốm sáng rời rạc trong vùng tối là nhiễu nhạc (musical noise); các sọc sáng/tối đều đặn khớp đúng nhịp hop là dấu hiệu lỗi COLA hoặc dao động độ lợi, không phải “nhiễu mới sinh”.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cần lưu ý rằng lỗi pha không xuất hiện trên (S(\ell,k)). Nếu âm thanh nghe bị méo “ướt” dù phổ đồ biên độ trông rất sạch, nguyên nhân thường là lỗi tái sử dụng pha nhiễu (bài 02-04) — bản thân phổ đồ biên độ sẽ không bộc lộ lỗi này.&lt;/p&gt;

&lt;h3 id=&quot;dấu-hiệu-đặc-trưng-của-tiếng-nói&quot;&gt;Dấu hiệu đặc trưng của tiếng nói&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Thành phần&lt;/th&gt;
      &lt;th&gt;Biểu hiện trên phổ đồ&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Nguyên âm hữu thanh&lt;/td&gt;
      &lt;td&gt;Chuỗi vạch họa âm ngang; các dải đậm (formant) nối qua các vạch&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Thay đổi cao độ&lt;/td&gt;
      &lt;td&gt;Vạch họa âm nghiêng lên/xuống, khoảng cách giữa các vạch thay đổi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Âm tắc (plosive)&lt;/td&gt;
      &lt;td&gt;Vệt bùng nổ băng rộng theo phương dọc đi kèm khoảng đóng ngắn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Phụ âm xát (fricative)&lt;/td&gt;
      &lt;td&gt;Đám mây năng lượng dạng nhiễu ở dải tần số cao&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Khoảng lặng&lt;/td&gt;
      &lt;td&gt;Gần mức sàn (chỉ còn nhiễu nền của micro)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;dấu-hiệu-đặc-trưng-của-nhiễu&quot;&gt;Dấu hiệu đặc trưng của nhiễu&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Dạng nhiễu&lt;/th&gt;
      &lt;th&gt;Biểu hiện trên phổ đồ&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;HVAC&lt;/td&gt;
      &lt;td&gt;Dải ngang liên tục ở tần số thấp&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tiếng rít quạt&lt;/td&gt;
      &lt;td&gt;Toàn bộ nền băng rộng bị nâng sáng đều&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bàn phím&lt;/td&gt;
      &lt;td&gt;Các vạch dọc rất mảnh&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Babble&lt;/td&gt;
      &lt;td&gt;Có cấu trúc hài giống tiếng nói nhưng chồng chéo lộn xộn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Nhạc nền&lt;/td&gt;
      &lt;td&gt;Chuỗi họa âm ổn định, kéo dài, không dịch chuyển formant như tiếng nói&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;méo-âm-thường-gặp-sau-khử-nhiễu&quot;&gt;Méo âm thường gặp sau khử nhiễu&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Méo âm (artifact)&lt;/th&gt;
      &lt;th&gt;Biểu hiện thị giác / thính giác&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Nhiễu nhạc (musical noise)&lt;/td&gt;
      &lt;td&gt;Các đốm bin đơn lẻ bật tắt rải rác theo thời gian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Khử quá mức (over-suppression)&lt;/td&gt;
      &lt;td&gt;Mất đám mây phụ âm xát cao tần; giọng nghe bị bí, nghẹt&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Rung biên độ theo hop (warble)&lt;/td&gt;
      &lt;td&gt;Các sọc biên độ tuần hoàn theo đúng chu kỳ hop&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Vang dư&lt;/td&gt;
      &lt;td&gt;Vệt nhòe kéo dài theo phương ngang/dọc ngay sau âm tiết&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Phổ đồ chỉ đóng vai trò &lt;strong&gt;bổ trợ&lt;/strong&gt; cho đánh giá nghe và các chỉ số như SI-SDR/DNSMOS (Chương 08), không thể thay thế chúng. Một phổ đồ trông rất sạch vẫn có thể nghe khó chịu do lỗi pha vô hình trên đồ thị biên độ.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Nhãn thông số chuẩn cho một ảnh phổ đồ: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;48 kHz, Hann 20 ms, hop 10 ms, N=1024, dB −70..0&quot;&lt;/code&gt;. Lưu ý (N=1024) ở 48 kHz tương ứng khoảng 21.3 ms nếu độ dài cửa sổ bằng FFT, &lt;em&gt;không&lt;/em&gt; phải lưới 960 điểm của DeepFilterNet — cần ghi rõ trong phiếu báo lỗi để tránh kiểm tra nhầm chỉ số bin.&lt;/p&gt;

&lt;p&gt;Tần số tâm của bin thứ (k) là (k f_s/N). Một họa âm 200 Hz ở (f_s=8\,\mathrm{kHz}) với (N=256) rơi vào vị trí:&lt;/p&gt;

\[k=\frac{200}{8000/256}=6.4,\]

&lt;p&gt;do đó năng lượng phân bố giữa bin 6 và bin 7. Họa âm bậc hai (400 Hz) và bậc ba (600 Hz) lần lượt nằm quanh 12–13 và gần 19 (Mini-lab dưới đây sẽ in trực tiếp các bin này). Một báo cáo lỗi ghi “âm đơn ở bin 200” là đang nhầm lẫn giữa tần số Hz và chỉ số bin.&lt;/p&gt;

&lt;p&gt;Một dải sáng kéo dài sát đáy tần số thấp thường là thành phần lệch DC chứ không phải “mô hình khử nhiễu thất bại”; hãy lọc thông cao trước khi vẽ nếu đang chẩn đoán NS. Với babble, cả giọng đích lẫn nền đều có cấu trúc hài nhưng giọng đích thường mạnh và gần micro hơn — phổ đồ giúp định lượng giới hạn thực tế của NS đơn kênh.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;So sánh hai phổ đồ có dải màu dB khác nhau.&lt;/li&gt;
  &lt;li&gt;Dùng phổ đồ thang Mel để gỡ lỗi chỉ số bin của STFT tuyến tính.&lt;/li&gt;
  &lt;li&gt;Vội kết luận đạt chất lượng chỉ vì nền trông tối hơn mà không kiểm tra xem tiếng nói có bị suy hao không.&lt;/li&gt;
  &lt;li&gt;Bỏ qua các méo pha vốn không hiển thị trên phổ biên độ.&lt;/li&gt;
  &lt;li&gt;Chọn cửa sổ quá dài khiến các hiện tượng biến đổi nhanh trông như “nhiễu dừng”.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Tính phổ biên độ trên một khung &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; của tín hiệu gồm ba họa âm và in danh sách các bin có năng lượng cao nhất.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;f0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;200.0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.25&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;frame&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;frame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;top&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;argsort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:][::&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;top bins&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;harmonic &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; expected k&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Các vị trí tâm lý thuyết là &lt;strong&gt;6.4, 12.8 và 19.2&lt;/strong&gt;. Sáu bin mạnh nhất nằm ở lân cận các tâm đó (thường là 6 và 7 cho 200 Hz, 12 và 13 cho 400 Hz, cùng 19 cho 600 Hz). Cặp bin sáng cạnh nhau là hệ quả tự nhiên của họa âm lệch lưới qua búp chính cửa sổ Hann, không phải nhiễu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Chỉ dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.argmax&lt;/code&gt; sẽ chỉ thấy bin 6 và bỏ sót các họa âm bậc cao; dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fft&lt;/code&gt; thay cho &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; làm nhân đôi phổ và lệch cách đọc chỉ số; bỏ qua hàm cửa sổ khiến búp phụ (bài 02-03) đẩy các bin không liên quan vào nhóm mạnh nhất; và đọc nhầm bin 6 thành 6 Hz thay vì (6\cdot8000/256=187.5\,\mathrm{Hz}) là lỗi ghi nhận rất hay gặp trong ticket.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Phác họa dạng phổ đồ giản lược của từ “hello” trong môi trường có nhiễu nền.&lt;/li&gt;
  &lt;li&gt;Lỗi COLA với bước nhảy hop 10 ms hiển thị như thế nào trên phổ đồ?&lt;/li&gt;
  &lt;li&gt;Vì sao bắt buộc phải đặt ngưỡng sàn khi chuyển biên độ sang thang logarit?&lt;/li&gt;
  &lt;li&gt;Nêu hai dấu hiệu phân biệt nhạc nền với tiếng nói hữu thanh trên phổ đồ.&lt;/li&gt;
  &lt;li&gt;Liệt kê các thông số metadata bắt buộc phải đi kèm phổ đồ khi gửi báo cáo lỗi.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Chuỗi vạch hài ở tần số thấp cho các nguyên âm, đám mây năng lượng cao tần cho phụ âm xát và vệt dọc ngắn cho âm /h/ hoặc âm bật, tất cả nằm trên một nền nhiễu tương đối đều.&lt;/li&gt;
  &lt;li&gt;Xuất hiện các sọc sáng/tối theo phương dọc lặp lại đều đặn mỗi 10 ms (khớp đúng chu kỳ hop), kể cả xuyên qua những đoạn nguyên âm ổn định.&lt;/li&gt;
  &lt;li&gt;Nếu không có sàn, giá trị 0 tuyệt đối sẽ cho (-\infty), làm sụp đổ thang màu của toàn biểu đồ.&lt;/li&gt;
  &lt;li&gt;Nhạc nền thường duy trì khoảng cách họa âm cố định và kéo dài ổn định theo thời gian, còn tiếng nói liên tục dịch chuyển dải formant và biến thiên (f_0) theo ngữ điệu.&lt;/li&gt;
  &lt;li&gt;Tần số lấy mẫu (f_s), hàm cửa sổ, bước nhảy hop, kích thước FFT và dải hiển thị dB.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer và loạt bài về phổ của Julius O. Smith — phân tích bản chất vật lý của biên độ ngắn hạn.&lt;/li&gt;
  &lt;li&gt;Chương về phổ đồ trong các giáo trình xử lý tiếng nói và DSP.&lt;/li&gt;
  &lt;li&gt;Hình minh họa của DNS Challenge và các bài báo DeepFilterNet (luôn đọc kỹ trục tần số trước khi đối chiếu với STFT tuyến tính 48 kHz).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EfWnEldTyPA&quot;&gt;The Spectrogram and the Gabor Transform&lt;/a&gt; — Steve Brunton, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Minh họa quá trình trượt cửa sổ trên biến đổi Fourier để tạo ra ảnh thời gian–tần số; luôn kiểm tra trục trước khi đọc màu.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=glnUFa2fLyE&quot;&gt;Speech Acoustics 5 - vowel formants&lt;/a&gt; — Listen Lab, tiếng Anh. Tập trung vào các dải đậm formant thay vì từng vạch hài rời rạc — đây chính là cấu trúc tiếng nói mà bộ khử nhiễu phải bảo toàn.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=08mmKNLQVHU&quot;&gt;Coding Adventure: Analyzing Audio&lt;/a&gt; — Sebastian Lague, tiếng Anh. Phần phân tích ngắn hạn minh họa cách cắt khung tiếng nói để vẽ phổ đồ và lý do một phép FFT trên cả tệp làm mất thông tin thời điểm.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-05 Lọc miền thời gian và miền tần số</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_05_filtering_time_vs_frequency/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_05_filtering_time_vs_frequency</id>
   <content type="html">&lt;p&gt;Khử nhiễu về bản chất là bài toán lọc trong điều kiện không chắc chắn. Đôi khi hệ thống dùng bộ lọc FIR/IIR ở miền thời gian, đôi khi nhân hệ số độ lợi trên từng bin STFT, và đôi khi mạng nơ-ron trực tiếp dự đoán các hệ số lọc đó. Bài học này đối chiếu hai miền xử lý để lựa chọn công cụ đúng mục đích: một đáp ứng xung cố định tương ứng với phép tích chập, còn độ lợi khử nhiễu theo bin là một hệ số thay đổi ở mỗi khung — như minh họa trong hình dưới đây.&lt;/p&gt;

&lt;p&gt;Muốn lọc bỏ tiếng ù trầm dưới 80 Hz trong một đoạn ghi âm, bạn có hai lựa chọn hoàn toàn khác nhau: hoặc cài một &lt;strong&gt;bộ lọc số FIR/IIR&lt;/strong&gt; chạy trực tiếp từng mẫu trong miền thời gian, hoặc biến đổi sang miền tần số bằng &lt;strong&gt;STFT&lt;/strong&gt;, hạ hệ số các bin dưới 80 Hz về 0 rồi biến đổi ngược lại! Hai con đường ấy có tương đương nhau không, khi nào nên lọc miền thời gian và khi nào lọc miền tần số thắng thế? Bài học này soi rõ bản chất đại số của phép lọc ở cả hai miền.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-lọc-miền-thời-gian-và-miền-tần-số-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Lọc Miền thời gian và Miền tần số đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-hệ-thống-lti-và-đáp-ứng-xung-fir-vs-iir&quot;&gt;1. Hệ thống LTI và Đáp ứng xung (FIR vs. IIR)&lt;/h3&gt;
&lt;p&gt;Trong miền thời gian, một bộ lọc tuyến tính bất biến theo thời gian (LTI) được đặc trưng bởi đáp ứng xung \(h[n]\) qua phép tích chập \(y[n] = \sum_k h[k]\,x[n-k]\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;FIR (Finite Impulse Response):&lt;/strong&gt; Chỉ dùng các mẫu đầu vào quá khứ — &lt;strong&gt;luôn ổn định&lt;/strong&gt;, dễ thiết kế &lt;strong&gt;pha tuyến tính&lt;/strong&gt; (không làm méo dạng sóng), nhưng muốn cắt dốc sắc cần bậc \(M\) lớn.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;IIR (Infinite Impulse Response — như Butterworth, Biquad):&lt;/strong&gt; Có hồi tiếp đầu ra quá khứ — cắt dốc cực sắc chỉ với bậc 2–4 (rất ít phép nhân, độ trễ gần như 0 mẫu!), nhưng có pha phi tuyến và cần kiểm tra ổn định (các cực nằm trong vòng tròn đơn vị).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-lọc-miền-tần-số-overlap-add--overlap-save-và-độ-phức-tạp-tính-toán&quot;&gt;2. Lọc Miền tần số (Overlap-Add / Overlap-Save) và Độ phức tạp tính toán&lt;/h3&gt;
&lt;p&gt;Với bộ lọc dài \(M\) (ví dụ mô phỏng tiếng vang phòng dài 2.000 mẫu), tích chập trực tiếp miền thời gian tốn \(O(M)\) phép nhân cho &lt;strong&gt;mỗi mẫu&lt;/strong&gt; (rất chậm), trong khi dùng FFT + nhân phổ + IFFT theo khối chỉ tốn \(O(\log N)\) phép nhân/mẫu!&lt;/p&gt;

&lt;h3 id=&quot;3-lọc-thời-biến-time-varying-filtering-trong-khử-nhiễu&quot;&gt;3. Lọc Thời biến (Time-Varying Filtering) trong Khử nhiễu&lt;/h3&gt;
&lt;p&gt;Tiếng nói và nhiễu thay đổi theo từng khung 10 ms, nên hệ thống khử nhiễu thực chất là &lt;strong&gt;bộ lọc thay đổi theo thời gian&lt;/strong&gt;: mặt nạ STFT \(M(m, k)\) (hoặc bộ lọc phức ngắn đa khung của DeepFilterNet) cập nhật hệ số mới ở mỗi khung \(m\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-kiểm-tra-bộ-lọc-thông-thấp-fir-3-điểm-ở-cả-hai-miền&quot;&gt;Giải thích: tự tay kiểm tra bộ lọc thông thấp FIR 3 điểm ở cả hai miền&lt;/h3&gt;

&lt;p&gt;Xét bộ lọc trung bình trượt FIR 3 điểm cực đơn giản:&lt;/p&gt;

\[y[n] = \frac{1}{3}\bigl(x[n] + x[n-1] + x[n-2]\bigr) \qquad \Bigl(h = \bigl[\tfrac{1}{3},\ \tfrac{1}{3},\ \tfrac{1}{3}\bigr]\Bigr).\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chạy trực tiếp miền thời gian trên 2 tín hiệu cực đoan (từ \(n \ge 2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tín hiệu chậm nhất — &lt;strong&gt;DC (\(\omega = 0\))&lt;/strong&gt; \(x = [1, 1, 1, 1, \dots]\):
\(y[n] = \frac{1}{3}(1 + 1 + 1) = \mathbf{1}\) (đi qua trọn vẹn \(100\%\), suy giảm \(0\text{ dB}\)).&lt;/li&gt;
      &lt;li&gt;Tín hiệu nhanh nhất — &lt;strong&gt;Nyquist (\(\omega = \pi\))&lt;/strong&gt; \(x = [1, -1, 1, -1, \dots]\):
\(y[2] = \frac{1}{3}(1 - 1 + 1) = \mathbf{+\frac{1}{3}}, \qquad y[3] = \frac{1}{3}(-1 + 1 - 1) = \mathbf{-\frac{1}{3}}\)
(biên độ bị nén còn đúng \(\frac{1}{3}\), tức giảm \(20\log_{10}(1/3) \approx \mathbf{-9.54\text{ dB}}\)!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra chéo bằng đáp ứng tần số \(H(e^{j\omega}) = \frac{1}{3}(1 + e^{-j\omega} + e^{-j2\omega})\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Tại \(\omega = 0\): $$&lt;/td&gt;
              &lt;td&gt;H(e^{j0})&lt;/td&gt;
              &lt;td&gt;= \frac{1}{3}&lt;/td&gt;
              &lt;td&gt;1 + 1 + 1&lt;/td&gt;
              &lt;td&gt;= \mathbf{1}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Tại \(\omega = \pi\): $$&lt;/td&gt;
              &lt;td&gt;H(e^{j\pi})&lt;/td&gt;
              &lt;td&gt;= \frac{1}{3}&lt;/td&gt;
              &lt;td&gt;1 - 1 + 1&lt;/td&gt;
              &lt;td&gt;= \mathbf{\frac{1}{3}}$$.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Tại \(\omega = \frac{2\pi}{3}\) (tức \(f = f_s / 3\)): \(1 + e^{-j2\pi/3} + e^{-j4\pi/3} = \mathbf{0}\) — bộ lọc &lt;strong&gt;triệt tiêu tuyệt đối 100%&lt;/strong&gt; đúng tần số \(f_s/3\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Đối chiếu lọc LTI miền thời gian với phép nhân độ lợi trong miền STFT.&lt;/li&gt;
  &lt;li&gt;Phân biệt tích chập vòng với tích chập tuyến tính và giải thích vai trò của OLA/OLS.&lt;/li&gt;
  &lt;li&gt;Liên hệ độ lợi Wiener và trừ phổ cổ điển với bài toán lọc trên miền STFT.&lt;/li&gt;
  &lt;li&gt;Xác định các tác vụ mà xử lý miền thời gian vẫn vượt trội (chặn DC, phát hiện xung click).&lt;/li&gt;
  &lt;li&gt;Tránh các thao tác lọc làm phá vỡ điều kiện COLA trong chế độ streaming.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Ôn tập tích chập LTI và đáp ứng tần số&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;Độ lợi miền STFT dưới góc nhìn bộ lọc biến thiên theo thời gian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Tích chập nhanh qua FFT và kỹ thuật OLA/OLS&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Ví dụ thực tế trong NS: lọc thông cao, độ lợi Wiener và mặt nạ mạng nơ-ron&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/spectral-subtraction-wiener.png&quot; alt=&quot;Trái: spectral subtraction từng bin, mỗi bin một gain. Phải: gain Wiener trơn theo SNR, vẫn là một hệ số mỗi bin chứ không phải một đáp ứng xung cố định&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Cả hai biểu đồ đều biểu diễn độ lợi theo từng bin chứ không phải một phép tích chập cố định: biểu đồ bên trái thay đổi theo phổ cục bộ, còn đường cong bên phải ánh xạ mỗi mức SNR sang một hệ số độ lợi tương ứng.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;lọc-lti-miền-thời-gian&quot;&gt;Lọc LTI miền thời gian&lt;/h3&gt;

\[y[n]=(h*x)[n]=\sum_k h[k]x[n-k]\]

&lt;p&gt;Khi đáp ứng xung (h) cố định, phép lọc tương đương nhân DTFT của (x) với đáp ứng tần số (H(e^{j\omega})). Cách tiếp cận này phù hợp cho bộ chặn DC, cân bằng âm sắc (EQ) nhẹ hoặc lọc thông thấp chống aliasing. Tuy nhiên, riêng nó không đủ để xử lý nhiễu không dừng vì bài toán này đòi hỏi đặc tính lọc phải thích nghi theo thời gian.&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Từ khóa then chốt ở đây là “cố định”: một đáp ứng xung (h) chỉ cho ra duy nhất một đáp ứng (H(k)) cho toàn bộ câu nói. Bộ lọc sai phân bậc một (h=[1,-1]) là bộ lọc thông cao đơn giản, trong đó (&lt;/td&gt;
      &lt;td&gt;H&lt;/td&gt;
      &lt;td&gt;) không phân biệt khung hiện tại là nguyên âm hay tiếng gõ phím. Vì vậy, nó đứng &lt;em&gt;trước&lt;/em&gt; bộ khử nhiễu để loại bỏ thành phần DC và tiếng ù tần số cực thấp chứ không thay thế bộ khử nhiễu.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;xử-lý-nhân-trong-miền-stft&quot;&gt;Xử lý nhân trong miền STFT&lt;/h3&gt;

&lt;p&gt;Ở mỗi khung, ta áp dụng (\hat{X}(\ell,k)=G(\ell,k)Y(\ell,k)). Nếu (G) biến thiên chậm, phép toán này xấp xỉ một bộ lọc biến thiên chậm theo thời gian. Ngược lại, nếu (G) nhảy đột ngột giữa các hop và các bin kề nhau, hệ thống sẽ sinh nhiễu nhạc và gây áp lực lên điều kiện COLA.&lt;/p&gt;

&lt;p&gt;Các phương pháp &lt;strong&gt;trừ phổ (spectral subtraction)&lt;/strong&gt; và &lt;strong&gt;lọc Wiener&lt;/strong&gt; cổ điển (Chương 03) cung cấp công thức giải tích cho (G), còn mô hình mạng nơ-ron học cách dự đoán (G) (hoặc dự đoán bộ lọc sâu giàu biểu diễn hơn).&lt;/p&gt;

&lt;p&gt;Trên hình minh họa, các cột xanh lá thể hiện phép trừ theo từng bin (mỗi bin nhận một hệ số riêng). Đường cong bên phải (H=\xi/(1+\xi)) đạt giá trị 0.5 (tương đương (-6\,\mathrm{dB})) khi công suất tiếng nói và công suất nhiễu bằng nhau. Không biểu đồ nào trong hai hình là FFT của một bộ lọc FIR ngắn cố định.&lt;/p&gt;

&lt;h3 id=&quot;tích-chập-qua-fft&quot;&gt;Tích chập qua FFT&lt;/h3&gt;

&lt;p&gt;Để thực hiện phép tích chập với một bộ lọc FIR dài (h) hiệu quả hơn, ta nhân phổ FFT với (H) rồi biến đổi iFFT — nhưng bắt buộc phải chia khối bằng &lt;strong&gt;overlap-add (OLA)&lt;/strong&gt; hoặc &lt;strong&gt;overlap-save (OLS)&lt;/strong&gt; để thu được tích chập &lt;em&gt;tuyến tính&lt;/em&gt;. Nhân trực tiếp phổ STFT từng khung với một (H) cố định mà thiếu bước xử lý phù hợp không tự động tương đương với bộ lọc FIR đó ở miền thời gian do tác động rò phổ của hàm cửa sổ.&lt;/p&gt;

&lt;p&gt;Xét ví dụ tích chập tuyến tính của một dãy tăng dần 8 điểm với (h=[1,-1]): kết quả tạo ra phần đuôi vượt quá 8 mẫu, trong khi tích chập vòng 8 điểm sẽ quấn phần đuôi này ngược về mẫu đầu tiên (lệch đúng 8 đơn vị trong Mini-lab). &lt;strong&gt;OLA&lt;/strong&gt; giữ phần đuôi để cộng sang khối tiếp theo, còn &lt;strong&gt;OLS&lt;/strong&gt; loại bỏ phần mép bị chồng chéo theo thời gian và chỉ giữ đoạn hợp lệ. Khi (G(\ell,k)) thay đổi theo từng hop, nó trở thành một bộ lọc biến thiên theo thời gian chứ không còn là bộ lọc FIR tĩnh.&lt;/p&gt;

&lt;h3 id=&quot;lựa-chọn-miền-xử-lý&quot;&gt;Lựa chọn miền xử lý&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Nhu cầu&lt;/th&gt;
      &lt;th&gt;Phương pháp phù hợp&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;EQ nhẹ hoặc chặn DC cố định&lt;/td&gt;
      &lt;td&gt;Bộ lọc IIR/FIR ngắn ở miền thời gian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Khử nhiễu không dừng&lt;/td&gt;
      &lt;td&gt;Miền STFT kèm (G) thích nghi hoặc mạng nơ-ron&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Cổng chặn xung click, CPU rất thấp&lt;/td&gt;
      &lt;td&gt;Bộ phát hiện xung ở miền thời gian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bộ lọc FIR dài (ví dụ mô phỏng vang)&lt;/td&gt;
      &lt;td&gt;Tích chập nhanh qua FFT bằng OLA/OLS&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;liên-hệ-với-deepfilternet&quot;&gt;Liên hệ với DeepFilterNet&lt;/h3&gt;

&lt;p&gt;Kỹ thuật deep filtering dự đoán các hệ số lọc tác động trực tiếp lên các hệ số STFT phức theo cả lân cận tần số lẫn ngữ cảnh thời gian — vẫn là “lọc miền tần số”, nhưng tổng quát hơn nhiều so với độ lợi đường chéo (G(\ell,k)). Độ lợi đường chéo không thể phục hồi một họa âm đã bị nhiễu che lấp, còn bộ lọc ngắn trải theo thời gian–tần số có thể khai thác thông tin pha từ các bin lân cận. Khóa học này bám sát pipeline kiểu DeepFilterNet trên miền STFT 48 kHz với kích thước hop và cửa sổ khớp checkpoint (bài 02-02 và 02-04).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Bộ chặn DC dạng rút gọn (y[n]=x[n]-x[n-1]) là bộ lọc thông cao có chi phí rất thấp, thường đặt trước khối khử nhiễu (dù tất nhiên không thể loại bỏ nhiễu babble quán cà phê). Đáp ứng của nó bằng 0 tại DC và đạt đỉnh tại Nyquist, với trễ nhóm (group delay) nhỏ hơn một mẫu nên không làm tiêu hao ngân sách độ trễ hội thoại như các bộ lọc FIR pha tuyến tính hàng trăm hệ số.&lt;/p&gt;

&lt;p&gt;Mô hình giản lược của độ lợi Wiener:&lt;/p&gt;

\[G(k)=\frac{P_x(k)}{P_x(k)+P_n(k)}\]

&lt;p&gt;Quy trình gồm ước lượng công suất từ biên độ STFT, nhân độ lợi rồi tính ISTFT. Phần khó nhất là ước lượng chính xác (P_n) trong môi trường nhiễu không dừng. Công thức trên tương ứng với đường cong bên phải trong hình (một hệ số cho mỗi bin ở mỗi khung); Chương 03 sẽ trình bày chi tiết chứng minh và bộ ước lượng decision-directed.&lt;/p&gt;

&lt;p&gt;Nếu triệt tiêu ngẫu nhiên các bin ở từng hop mà không làm mượt, âm thanh sẽ sinh ra nhiễu nhạc kiểu “chim hót” (birdies), tương ứng ở miền thời gian với một đáp ứng xung biến đổi hỗn loạn. Tương tự, một bộ lọc FIR pha tuyến tính có trễ nhóm 30 ms cũng không phù hợp cho thoại trực tiếp: dù đáp ứng biên độ rất đẹp, độ trễ vẫn gây khó chịu trong hội thoại.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Đánh đồng phép nhân độ lợi trên STFT với một bộ lọc FIR tuyến tính chính xác.&lt;/li&gt;
  &lt;li&gt;Chạy bộ lọc FIR rất dài trực tiếp trên audio thread mà không tăng tốc bằng FFT.&lt;/li&gt;
  &lt;li&gt;Xếp chồng bộ lọc thông cao và bộ khử nhiễu mà không đo lượng thành phần tiếng nói bị suy hao.&lt;/li&gt;
  &lt;li&gt;Dùng bộ lọc FIR pha tuyến tính có trễ nhóm lớn trên đường thoại thời gian thực.&lt;/li&gt;
  &lt;li&gt;Thiết kế bộ lọc ngoại tuyến cho chất lượng cao nhưng quên ràng buộc nhân quả của thời gian thực.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Đối chiếu đáp ứng của một bộ lọc FIR cố định với độ lợi Wiener theo từng bin, đồng thời minh họa sự sai khác giữa tích chập vòng và tích chập tuyến tính.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;H&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fixed |H|&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;10.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# SNR tiên nghiệm, năm bin
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;G&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;per-bin G&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dtype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y_lin&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;convolve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;h_pad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;h_pad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y_circ&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;irfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h_pad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;linear   &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_lin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;circular &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y_circ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;max |linear[:8] - circular|&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y_lin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_circ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fixed |H|&lt;/code&gt; bắt đầu từ 0 (triệt tại DC) và tăng dần về phía Nyquist. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;per-bin G&lt;/code&gt; cho ra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0.091, 0.231, 0.5, 0.75, 0.909]&lt;/code&gt; — một đường đáp ứng hoàn toàn khác được tính từ SNR chứ không phải từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt;. Tích chập tuyến tính kết thúc bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-8&lt;/code&gt;, còn tích chập vòng quấn giá trị đuôi này vào mẫu đầu tiên, tạo độ lệch cực đại trên 8 mẫu đầu bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;8.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Nếu độ lệch in ra bằng 0, nghĩa là bạn đã đệm số 0 cho cả &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt; lẫn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt; nên vô tình tính tích chập tuyến tính và che mất lỗi mà OLA/OLS cần xử lý; nếu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;G&lt;/code&gt; trùng với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|H|&lt;/code&gt;, vector SNR đã bị thay nhầm bằng bộ lọc FIR; và nếu bin đầu tiên của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|H|&lt;/code&gt; khác 0 thì bộ lọc không phải bộ chặn DC &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h=[1,-1]&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Nêu một bộ lọc nên đặt ở miền thời gian trước khối khử nhiễu.&lt;/li&gt;
  &lt;li&gt;Vì sao độ lợi theo từng bin không được làm mượt dễ gây tiếng lách tách hoặc nhiễu nhạc?&lt;/li&gt;
  &lt;li&gt;Phân biệt OLA và OLS trong một câu.&lt;/li&gt;
  &lt;li&gt;Một bộ lọc FIR pha tuyến tính có trễ nhóm 30 ms có phù hợp cho đường gọi thoại thời gian thực không?&lt;/li&gt;
  &lt;li&gt;Viết biểu thức tổng quát cho thấy mặt nạ mạng nơ-ron vẫn đóng vai trò một phép lọc (G(\ell,k)).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Bộ chặn DC một điểm không, hoặc bộ lọc thông thấp chống aliasing trước khi giảm mẫu từ 48 kHz xuống 16 kHz.&lt;/li&gt;
  &lt;li&gt;Phép biến đổi nghịch ở mỗi hop tương ứng với một đáp ứng xung khác nhau, gây gián đoạn tại biên cộng chồng lấp OLA.&lt;/li&gt;
  &lt;li&gt;OLA giữ lại phần đuôi tích chập để cộng sang khối tiếp theo, trong khi OLS bỏ đi đoạn mép bị chồng chéo vòng và chỉ giữ phần hợp lệ.&lt;/li&gt;
  &lt;li&gt;Không phù hợp cho gọi thoại trực tiếp: riêng 30 ms đã chiếm phần lớn ngân sách độ trễ hội thoại trước cả khi tính đến bộ mã hóa và đường truyền mạng.&lt;/li&gt;
  &lt;li&gt;(\hat{X}(\ell,k)=G(\ell,k)Y(\ell,k)), trong đó (G) được dự đoán theo từng bin (hoặc mở rộng thành bộ lọc sâu ngắn trên vùng lân cận quanh bin đó).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — thiết kế bộ lọc, tích chập qua FFT và xử lý STFT.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Spectral Audio Signal Processing&lt;/em&gt; — kỹ thuật overlap-add và overlap-save.&lt;/li&gt;
  &lt;li&gt;Khử nhiễu tiếng nói cổ điển (Wiener / trừ phổ) làm cầu nối sang Chương 03: Boll (1979) là bài báo kinh điển về trừ phổ, còn bộ lọc Wiener cho tiếng nói sẽ được trình bày ở bài kế tiếp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=KuXjwB4LzSA&quot;&gt;But what is a convolution?&lt;/a&gt; — 3Blue1Brown, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày trực quan định lý tích chập: lọc là phép trung bình có trọng số trượt ở miền thời gian và là phép nhân ở miền tần số — nền tảng cho việc chọn miền xử lý trong bài.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xb--68NlxS0&quot;&gt;Spectral Subtraction In Python - Alexx Mitchell&lt;/a&gt; — The Audio Programmer, tiếng Anh. Minh họa quy tắc chỉnh biên độ trên từng bin dựa theo ước lượng nhiễu, thể hiện rõ sự khác biệt với lọc FIR cố định.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=K_U0yeVdblU&quot;&gt;Lec 22: Causal IIR Wiener Filter&lt;/a&gt; — NPTEL IIT Guwahati, tiếng Anh. Trình bày dẫn xuất cổ điển của bộ lọc Wiener nhân quả (không riêng cho mặt nạ tiếng nói), cho thấy cách độ lợi suy giảm khi nhiễu tăng — nguyên lý trực tiếp đằng sau độ lợi theo bin trên STFT.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-04 STFT / ISTFT cho tiếng nói (nối DeepFilterNet)</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_04_stft_istft_speech/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_04_stft_istft_speech</id>
   <content type="html">&lt;p&gt;Biến đổi Fourier thời gian ngắn (STFT) là biểu diễn cốt lõi của cả khử nhiễu cổ điển lẫn họ mô hình DeepFilterNet. Trong bài học này, phép biến đổi thuận dùng cửa sổ phân tích, còn phép biến đổi nghịch chỉ rõ cửa sổ tổng hợp riêng biệt để áp dụng chính xác điều kiện COLA từ bài 02-02 mà không bị ẩn đi bước nhân cửa sổ nào.&lt;/p&gt;

&lt;p&gt;Nếu biến đổi Fourier thông thường giống như việc ép cả một bản giao hưởng dài 5 phút thành một danh sách thống kê duy nhất xem nốt Đô, Rê, Mi xuất hiện bao nhiêu lần (mất sạch thứ tự thời gian!), thì &lt;strong&gt;Biến đổi Fourier Thời gian Ngắn (STFT)&lt;/strong&gt; chính là &lt;strong&gt;bản khuông nhạc sống&lt;/strong&gt;: trục ngang ghi thời gian theo từng khung 10 ms, trục dọc ghi tần số theo từng bin 50 Hz, còn mỗi ô \((t, f)\) chứa biên độ và pha tức thời của âm thanh tại đúng khoảnh khắc đó. Hầu hết các hệ thống tăng cường tiếng nói hiện đại — từ bộ lọc Wiener cổ điển đến &lt;strong&gt;DeepFilterNet&lt;/strong&gt; — đều làm việc trực tiếp trên “bản khuông nhạc số” STFT rồi dịch ngược về sóng âm bằng &lt;strong&gt;ISTFT&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-cặp-biến-đổi-stft--istft-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Cặp biến đổi STFT / ISTFT đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-biểu-diễn-thời-gian--tần-số-phức-xm-k&quot;&gt;1. Biểu diễn Thời gian – Tần số phức \(X(m, k)\)&lt;/h3&gt;
&lt;p&gt;STFT áp dụng cửa sổ phân tích \(w_a[n]\) rồi chạy FFT trên từng khung trượt cách nhau \(H\) mẫu:&lt;/p&gt;

\[X(m, k) = \sum_{n=0}^{N-1} x[mH + n]\,w_a[n]\,e^{-j\frac{2\pi k n}{N}}.\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Ta thu được một ma trận số phức 2 chiều kích thước \((T_{\text{frames}} \times (N/2 + 1))\): độ lớn $$&lt;/td&gt;
      &lt;td&gt;X(m,k)&lt;/td&gt;
      &lt;td&gt;\(cho biết năng lượng, còn\)\angle X(m,k)$$ chứa pha — đặc biệt quan trọng trong &lt;strong&gt;Deep Filtering&lt;/strong&gt; (lọc phức đa khung trên cả phần thực và phần ảo).&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;2-tổng-hợp-wola-và-cặp-cửa-sổ-phân-tích--tổng-hợp-vorbis--sqrt-hann&quot;&gt;2. Tổng hợp WOLA và Cặp cửa sổ Phân tích – Tổng hợp (Vorbis / sqrt-Hann)&lt;/h3&gt;
&lt;p&gt;Khi khôi phục tín hiệu bằng &lt;strong&gt;ISTFT&lt;/strong&gt;, mỗi khung phổ đã lọc \(\hat{X}(m, k)\) được biến đổi IFFT về miền thời gian, nhân thêm &lt;strong&gt;cửa sổ tổng hợp \(w_s[n]\)&lt;/strong&gt; rồi cộng chồng lấp (WOLA). Để tái tạo hoàn hảo khi không lọc (\(\hat{X} = X\)), ta cần điều kiện Princen–Bradley / WOLA: \(\sum_m w_a[n - mH]\,w_s[n - mH] = 1\) — đạt được tự nhiên bằng cách chọn \(w_a[n] = w_s[n] = \sqrt{w_{\text{Hann}}[n]}\) (hoặc cửa sổ Vorbis \(w[n] = \sin\bigl(\frac{\pi}{2}\sin^2\frac{\pi(n+0.5)}{N}\bigr)\) mà DeepFilterNet sử dụng!).&lt;/p&gt;

&lt;h3 id=&quot;3-tính-không-nhất-quán-của-stft-stft-inconsistency-sau-khi-áp-mặt-nạ&quot;&gt;3. Tính không nhất quán của STFT (STFT Inconsistency) sau khi áp mặt nạ&lt;/h3&gt;
&lt;p&gt;Một tinh tế toán học rất quan trọng: không phải mọi ma trận số phức \(Y(m, k)\) bất kỳ đều là STFT hợp lệ của một tín hiệu 1 chiều nào đó (vì các khung chồng lấp chia sẻ chung mẫu thời gian!). Khi ta nhân \(X(m, k)\) với một mặt nạ khử nhiễu \(M(m, k)\) thay đổi đột ngột, \(\hat{X} = M \cdot X\) thường bị &lt;strong&gt;không nhất quán&lt;/strong&gt;; phép ISTFT WOLA thực chất thực hiện &lt;strong&gt;phép chiếu bình phương tối thiểu&lt;/strong&gt; tìm tín hiệu 1 chiều có STFT gần \(\hat{X}\) nhất!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-kiểm-tra-cửa-sổ-căn-hann-sqrt-hann-trong-wola-với-n--4-h--2&quot;&gt;Giải thích: tự tay kiểm tra cửa sổ căn Hann (sqrt-Hann) trong WOLA với \(N = 4,\ H = 2\)&lt;/h3&gt;

&lt;p&gt;Giả sử hệ thống dùng &lt;strong&gt;cùng một cửa sổ&lt;/strong&gt; \(w_a[n] = w_s[n] = \sqrt{w_{\text{Hann}}[n]}\) ở cả đầu phân tích STFT và đầu tổng hợp ISTFT (tại \(N = 4,\ H = 2\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính giá trị cửa sổ căn Hann:&lt;/strong&gt; Từ \(w_{\text{Hann}} = [0,\ 0.5,\ 1.0,\ 0.5]\), lấy căn bậc hai từng phần tử:
\(w_a = w_s = \bigl[0,\ \tfrac{1}{\sqrt{2}},\ 1,\ \tfrac{1}{\sqrt{2}}\bigr] \approx [0,\ 0.7071,\ 1.0,\ 0.7071].\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chạy qua STFT → (không đổi phổ) → ISTFT:&lt;/strong&gt; Mỗi khung đi qua STFT bị nhân \(w_a\), rồi đi qua ISTFT bị nhân thêm \(w_s\), nên trọng số tổng trên từng khung là:
\(w_a[n] \cdot w_s[n] = w_a[n]^2 = [0,\ 0.5,\ 1.0,\ 0.5] = w_{\text{Hann}}[n]!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cộng chồng lấp 50% (\(H = 2\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại mẫu chẵn: \(0 + 1.0 = \mathbf{1.0}\).&lt;/li&gt;
      &lt;li&gt;Tại mẫu lẻ: \(0.5 + 0.5 = \mathbf{1.0}\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lợi ích kép khi khử nhiễu:&lt;/strong&gt; Nếu bạn đặt mặt nạ \(M = 0\) ở khung 0 và \(M = 1\) ở khung 1 (chuyển đột ngột từ im lặng sang nói), nhờ cửa sổ tổng hợp \(w_s\) vuốt mượt từ \(0 \to 0.707 \to 1\), biên độ âm thanh tăng lên êm ái thay vì nhảy bậc gây tiếng “tách”!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Hình dung rõ cấu trúc lưới STFT (thời gian × tần số).&lt;/li&gt;
  &lt;li&gt;Phân biệt mặt nạ biên độ, mặt nạ phức và ý tưởng của deep filtering.&lt;/li&gt;
  &lt;li&gt;Nêu các điều kiện tái tạo hoàn hảo (perfect reconstruction) trong thực hành.&lt;/li&gt;
  &lt;li&gt;Ánh xạ các tham số STFT (tần số lấy mẫu, (N), hop, hàm cửa sổ) sang độ trễ và độ phân giải.&lt;/li&gt;
  &lt;li&gt;Liên hệ thiết kế STFT đã công bố của DeepFilterNet với các thông số triển khai kỹ thuật.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
      &lt;th&gt; &lt;/th&gt;
      &lt;th&gt; &lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Định nghĩa STFT; mối liên hệ giữa phổ đồ (spectrogram) và (&lt;/td&gt;
      &lt;td&gt;\mathrm{STFT}&lt;/td&gt;
      &lt;td&gt;)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;ISTFT, cộng chồng lấp OLA và bài kiểm tra tái tạo&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Xử lý biên độ so với xử lý phổ phức; trực giác về deep filtering&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Thực hành trích xuất tham số từ bài báo DeepFilterNet&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/stft-ola.png&quot; alt=&quot;Cùng bức tranh overlap-add: frame phân tích, cửa sổ Hann bước theo hop R, và tổng cửa sổ mà ISTFT dựa vào&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Mỗi khung màu tương ứng với một cột của lưới STFT; ISTFT cộng chồng các khung sau biến đổi nghịch, và tổng cửa sổ phía dưới phải là hằng số để sóng sin ban đầu được tái tạo mà không bị gợn biên độ theo nhịp hop.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;biến-đổi-stft&quot;&gt;Biến đổi STFT&lt;/h3&gt;

\[X(\ell,k)=\sum_{n=0}^{L-1}x[n+\ell R]\,w[n]\,e^{-j2\pi kn/N}\]

&lt;p&gt;Trong công thức trên, (w[n]) là cửa sổ &lt;strong&gt;phân tích&lt;/strong&gt; (w_{\mathrm{ana}}). Trên lưới thời gian–tần số, mỗi cột là một khung thời gian (\ell) và mỗi hàng là một bin tần số (k). Nhiệm vụ của tăng cường tiếng nói là ước lượng phổ sạch (\hat{X}(\ell,k)) từ phổ quan sát có nhiễu (Y(\ell,k)).&lt;/p&gt;

&lt;p&gt;(N) là độ dài FFT: có thể chọn (N &amp;gt; L) khi đệm số 0, còn nếu (N &amp;lt; L) sẽ gây chồng chéo (aliasing) theo thời gian ngay trong khung. Khoảng cách giữa các bin bằng (f_s/N), nhưng độ phân giải tần số thực vẫn do hàm cửa sổ quyết định (xem bài 02-03). Với tín hiệu thực, chỉ có (N/2+1) bin không dư thừa và bin cuối cùng là tần số Nyquist.&lt;/p&gt;

&lt;h3 id=&quot;biến-đổi-istft&quot;&gt;Biến đổi ISTFT&lt;/h3&gt;

&lt;p&gt;Quy trình tổng hợp gồm: tính FFT nghịch cho từng khung, nhân cửa sổ tổng hợp (nếu có), rồi cộng chồng lấp OLA. Mỗi khung sau biến đổi nghịch trước khi cộng chồng lấp có dạng:&lt;/p&gt;

\[y_\ell[n]=\frac{1}{N}\sum_{k=0}^{N-1}\hat{X}(\ell,k)\,e^{j2\pi kn/N},\qquad n=0,\ldots,L-1\]

&lt;p&gt;(sử dụng biến đổi FFT thực &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;irfft&lt;/code&gt; cho tín hiệu thực). Dạng sóng đầu ra được ghép theo:&lt;/p&gt;

\[\hat{x}[n]=\sum_\ell w_{\mathrm{syn}}[n-\ell R]\,y_\ell[n-\ell R].\]

&lt;p&gt;Nếu bước phân tích đã nhân (w) và chọn (w_{\mathrm{syn}}=1), điều kiện tái tạo phổ chưa sửa quy về (\sum_\ell w[n-\ell R]=C) rồi chia cho (C). Nếu có nhân thêm cửa sổ tổng hợp (w_{\mathrm{syn}}), điều kiện COLA là tổng tích đã nêu ở bài 02-02:&lt;/p&gt;

\[\sum_\ell w[n-\ell R]\,w_{\mathrm{syn}}[n-\ell R]=C.\]

&lt;p&gt;Khi phổ không bị chỉnh sửa và COLA được thỏa mãn, hệ thống sẽ tái tạo chính xác (x) (sai khác tối đa độ trễ và hằng số khuếch đại). Lưu ý rằng STFT ngoại tuyến căn giữa bị lệch khoảng (L/2) mẫu so với STFT streaming nhân quả; cả hai đều có thể thỏa COLA nhưng độ lệch thời gian đó đủ làm sụt giảm mạnh điểm SI-SDR nếu không căn chỉnh khi đánh giá.&lt;/p&gt;

&lt;h3 id=&quot;các-dạng-biểu-diễn-phổ&quot;&gt;Các dạng biểu diễn phổ&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Biểu diễn&lt;/th&gt;
      &lt;th&gt;Thành phần lưu giữ&lt;/th&gt;
      &lt;th&gt;Ứng dụng điển hình&lt;/th&gt;
      &lt;th&gt; &lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Phổ phức (X)&lt;/td&gt;
      &lt;td&gt;Phần thực/ảo hoặc biên độ/pha&lt;/td&gt;
      &lt;td&gt;Deep filtering, mặt nạ phức&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Biên độ (&lt;/td&gt;
      &lt;td&gt;X|)&lt;/td&gt;
      &lt;td&gt;Giá trị không âm&lt;/td&gt;
      &lt;td&gt;Lọc Wiener cổ điển, mặt nạ biên độ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Log-biên độ / dB&lt;/td&gt;
      &lt;td&gt;Nén dải động&lt;/td&gt;
      &lt;td&gt;Trích xuất đặc trưng, vẽ đồ thị&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dãy lọc ERB / Mel&lt;/td&gt;
      &lt;td&gt;Năng lượng theo băng tần&lt;/td&gt;
      &lt;td&gt;Tiền xử lý cảm thụ (DeepFilterNet dùng đặc trưng thang ERB)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;mặt-nạ-biên-độ-và-deep-filtering&quot;&gt;Mặt nạ biên độ và deep filtering&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Mặt nạ biên độ:&lt;/strong&gt; (\hat{X}=M\odot&lt;/td&gt;
          &lt;td&gt;Y&lt;/td&gt;
          &lt;td&gt;e^{j\arg Y}), tức giữ nguyên pha của tín hiệu nhiễu. Cách này nhẹ nhưng gây méo pha đáng kể khi SNR thấp.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mặt nạ phức và lọc sâu (deep filtering):&lt;/strong&gt; dự đoán các hệ số lọc để kết hợp nhiều bin lân cận theo cả thời gian và tần số. Trong các bài báo DeepFilterNet, &lt;strong&gt;deep filtering&lt;/strong&gt; áp bộ lọc học được trực tiếp lên phổ phức, nhờ đó khôi phục cấu trúc tín hiệu tốt hơn so với hệ số khuếch đại độc lập trên từng bin.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chi tiết kiến trúc cụ thể sẽ được học qua các bài báo DeepFilterNet / 2 / 3 ở Chương 04. Ở bài này, điều cốt lõi cần nắm là: &lt;strong&gt;mô hình đang chỉnh sửa một lưới STFT dưới ràng buộc nhân quả, sau đó biến đổi ISTFT để trả về dạng sóng.&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;thực-hành-kiểm-tra-tái-tạo-hoàn-hảo&quot;&gt;Thực hành kiểm tra tái tạo hoàn hảo&lt;/h3&gt;

&lt;p&gt;Bài kiểm thử đơn vị bắt buộc trước khi bật mô hình: cho tín hiệu đi qua chuỗi STFT → ISTFT không qua khử nhiễu và kiểm tra đầu ra phải xấp xỉ tín hiệu gốc. Nếu phép biến đổi khứ hồi này chưa đúng thì phải dừng lại sửa ngay. Phần Mini-lab dưới đây thực hiện kiểm thử này trên sóng sin: sai số ở &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt; nằm quanh (10^{-15}) tại vùng giữa, còn sai số mức (10^{-2}) báo hiệu lỗi hàm cửa sổ hoặc bước nhảy hop và sẽ nghe rõ dưới dạng rung biên độ theo nhịp hop.&lt;/p&gt;

&lt;h3 id=&quot;ánh-xạ-tham-số-từ-bài-báo-sang-hệ-thống&quot;&gt;Ánh xạ tham số từ bài báo sang hệ thống&lt;/h3&gt;

&lt;p&gt;Khi đọc tài liệu hoặc bài báo, hãy trích xuất đầy đủ: (f_s), dạng cửa sổ và độ dài (L) / kích thước FFT (N), bước nhảy hop (R), số khung nhìn trước nhân quả và giả định mono. Sau đó quy đổi sang mili giây và số hop/giây bằng các công thức của Chương 01–02 trước khi tích hợp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; hay ONNX Runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lưới STFT đã công bố của DeepFilterNet.&lt;/strong&gt; Framework hỗ trợ tần số lấy mẫu lên đến 48 kHz; cấu hình toàn băng công bố sử dụng (N_{\mathrm{FFT}}=960) (20 ms ở 48 kHz) với chồng lấp 50%, tức (R=480) (10 ms) — xem Schröter và cộng sự (&lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;) cùng cấu hình tham chiếu tại &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sr=48000&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fft_size=960&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hop_size=480&lt;/code&gt;). Hàm cửa sổ gắn liền với checkpoint đã huấn luyện nên hop và cửa sổ phải khớp tuyệt đối. Gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 cũng tuân theo giao ước toàn băng 48 kHz này. Việc tự ý đổi sang hop 16 kHz, cửa sổ Blackman hay STFT ngoại tuyến căn giữa không hề “tăng chất lượng” mà sẽ cung cấp cho dãy lọc ERB một lưới khác hẳn lưới mà trọng số đã học.&lt;/p&gt;

&lt;p&gt;Cấu hình công bố đó cũng ghi nhận độ trễ nhìn trước tích chập nhỏ ((l_{\mathrm{DNN}}=2) khung và (l_{\mathrm{DF}}=1) khung). Với hop 10 ms, các khung nhìn trước này cộng thêm vào độ trễ của cửa sổ 20 ms — hãy đối chiếu trực tiếp với cấu hình của checkpoint cụ thể.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Với 1 giây âm thanh ở 16 kHz, (R=256), (N=512) (FFT thực), lưới STFT có khoảng (16000/256\approx 62) khung (có thể lệch 1 tùy quy ước biên) và 257 bin không dư thừa. Tensor mặt nạ có thể có kích thước ([1,257,62]) hoặc hoán đổi thứ tự trục tùy định nghĩa của mô hình.&lt;/p&gt;

&lt;p&gt;Với 2 giây âm thanh ở 48 kHz, (R=480), (N=960), lưới STFT có khoảng (96000/480=200) khung và (960/2+1=481) bin thực — đây là kích thước mà tích hợp DeepFilterNet 48 kHz cần cấp phát, không phải 257 bin.&lt;/p&gt;

&lt;p&gt;Ở các bin có SNR thấp, pha của hỗn hợp gần như trở thành pha ngẫu nhiên của nhiễu. Mặt nạ biên độ có thể hạ năng lượng nhiễu nhưng phần dư thường nghe bị méo “ướt”; phương pháp xử lý phổ phức cải thiện rõ rệt tình trạng này, dù vẫn có giới hạn trước nhiễu babble.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Bật chế độ căn giữa khung (center padding) khi chạy ngoại tuyến nhưng tắt khi chạy streaming.&lt;/li&gt;
  &lt;li&gt;Dùng bước nhảy hop lúc triển khai khác với lúc huấn luyện.&lt;/li&gt;
  &lt;li&gt;Đưa đặc trưng Mel vào mô hình được thiết kế cho thang ERB hoặc STFT tuyến tính.&lt;/li&gt;
  &lt;li&gt;Tính ISTFT hàng loạt trên toàn tệp trong môi trường thời gian thực, làm tăng vọt độ trễ.&lt;/li&gt;
  &lt;li&gt;Suy diễn các hằng số STFT nội bộ chưa được công bố của Mezon chỉ dựa vào nội dung khóa học.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Cho một sóng sin 440 Hz đi qua chuỗi STFT (có cửa sổ phân tích) và ISTFT cộng chồng lấp, sau đó in sai số tuyệt đối lớn nhất ở vùng giữa.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;440&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;starts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;specs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;starts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros_like&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros_like&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;spec&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;specs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;irfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# cửa sổ phân tích đã nằm trong frame
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;slice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;max abs error&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;max abs error&lt;/code&gt; cỡ (10^{-15}) (ngưỡng sai số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;), trong đó mảng tổng COLA &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;acc&lt;/code&gt; bằng hằng số 1 trên toàn vùng giữa đúng như chứng minh ở bài 02-02.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Quên chia cho &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;acc&lt;/code&gt; sẽ làm đầu ra mất nửa biên độ hoặc bị gợn với sai số cỡ (10^{-1}); dùng Hann đối xứng hoặc nhân &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt; thêm lần nữa ở khung nghịch sẽ tạo sai số tuần hoàn theo hop nghe rất rõ; đánh giá sai số ngay trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L&lt;/code&gt; mẫu đầu tiên (nơi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;acc&lt;/code&gt; chưa ổn định) sẽ làm sai số trông lớn bất thường dù vùng ổn định đã chính xác. Nếu đoạn mã này cho sai số lớn đáng kể, nguyên nhân là backend FFT không khứ hồi đúng chứ không phải vì COLA là tùy chọn.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Ước lượng kích thước lưới STFT cho đoạn âm thanh 2 giây ở 48 kHz với (R=480) và (N=960).&lt;/li&gt;
  &lt;li&gt;Giải thích vì sao việc tái sử dụng pha nhiễu trở nên kém hiệu quả khi SNR xuống sâu.&lt;/li&gt;
  &lt;li&gt;Liệt kê bốn tham số cần sao chép từ cấu hình DeepFilterNet vào danh mục kiểm tra tích hợp.&lt;/li&gt;
  &lt;li&gt;Khi điều kiện COLA bị vi phạm, âm thanh đầu ra sau ISTFT có biểu hiện như thế nào?&lt;/li&gt;
  &lt;li&gt;So với STFT tuyến tính, nêu một lý do khiến thang ERB được ưa chuộng trong phần tiền xử lý tăng cường tiếng nói.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Khoảng 200 khung thời gian và 481 bin tần số thực.&lt;/li&gt;
  &lt;li&gt;Ở SNR thấp, pha của tín hiệu hỗn hợp bị chi phối bởi pha ngẫu nhiên của nhiễu, nên ngay cả khi khôi phục hoàn hảo biên độ, tiếng nói vẫn bị điều biến méo.&lt;/li&gt;
  &lt;li&gt;Tần số lấy mẫu (f_s), kích thước FFT, bước nhảy hop và dạng hàm cửa sổ (kèm số khung nhìn trước nếu có tài liệu hóa; cấu hình công khai cần đối chiếu là 48 kHz, 960 và 480).&lt;/li&gt;
  &lt;li&gt;Xuất hiện rung biên độ (tremolo) ở tần số (f_s/R) (ví dụ 100 Hz với hop 10 ms).&lt;/li&gt;
  &lt;li&gt;Thang ERB tập trung mật độ dải tần cao hơn ở vùng tai người (và các formant tiếng nói) nhạy cảm, thay vì chia đều tuyến tính theo Hz.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Các bài báo DeepFilterNet, DeepFilterNet2, DeepFilterNet3 về STFT, đặc trưng ERB và deep filtering: bắt đầu tại &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt; và kho mã &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;github.com/Rikorose/DeepFilterNet&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Spectral Audio Signal Processing&lt;/em&gt; — định nghĩa cặp STFT/ISTFT khớp hàm cửa sổ.&lt;/li&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — mối liên hệ giữa dãy bộ lọc (filter bank) và STFT.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-Yxj3yfvY-4&quot;&gt;Short-Time Fourier Transform Explained Easily&lt;/a&gt; — Valerio Velardo - The Sound of AI, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày khung phân tích và yêu cầu phép biến đổi nghịch phải hoàn tác chính xác bước phân tích — đúng giao ước STFT/ISTFT cho tiếng nói.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EfWnEldTyPA&quot;&gt;The Spectrogram and the Gabor Transform&lt;/a&gt; — Steve Brunton, tiếng Anh. Minh họa cửa sổ trượt trên biến đổi Fourier tạo nên phổ đồ, giúp hình dung miền biểu diễn thời gian–tần số mà phần tiền xử lý DeepFilterNet giả định.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Quan sát luồng STFT đi vào dãy ERB và ISTFT đi ra — phần kết nối trực tiếp của bài học này với DeepFilterNet trước khi bàn đến hàm mất mát.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-03 Cửa sổ và rò phổ</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_03_windowing_leakage/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_03_windowing_leakage</id>
   <content type="html">&lt;p&gt;Hàm cửa sổ cân bằng sự đánh đổi giữa hiện tượng rò phổ (spectral leakage: năng lượng của một thành phần tần số lan sang các bin khác) và độ rộng búp chính (main lobe). Trong bài toán khử nhiễu, chọn sai hàm cửa sổ — hoặc dùng cặp cửa sổ phân tích/tổng hợp không khớp nhau — sẽ sinh ra nhiễu nhạc (musical noise) và tiếng rung giật theo nhịp hop. Hai con số mốc cần nhớ theo dB là: cửa sổ chữ nhật có búp phụ (sidelobe) đầu tiên ở mức khoảng (-13\,\mathrm{dB}), trong khi cửa sổ Hann đẩy búp phụ này xuống khoảng (-31\,\mathrm{dB}).&lt;/p&gt;

&lt;p&gt;Bạn tạo một sóng sin hoàn hảo ở tần số 440 Hz trên Python, cắt lấy một đoạn dài 20 ms rồi bấm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.fft.rfft()&lt;/code&gt;. Thay vì một cột kim sắc lẹm duy nhất tại 440 Hz như kỳ vọng, đồ thị phổ lại hiện ra một “chân váy” năng lượng loang rộng khắp hàng chục bin bên cạnh! Hiện tượng khó chịu ấy gọi là &lt;strong&gt;rò phổ (spectral leakage)&lt;/strong&gt; — không phải lỗi của Python, mà là hệ quả toán học tất yếu khi bạn cắt đứt một sóng liên tục bằng &lt;strong&gt;cửa sổ chữ nhật&lt;/strong&gt; khiến hai đầu khung bị đứt gãy đột ngột khi nối tuần hoàn trong DFT.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-hàm-cửa-sổ-và-rò-phổ-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Hàm Cửa sổ và Rò phổ đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-nhân-trong-miền-thời-gian--tích-chập-trong-miền-tần-số&quot;&gt;1. Nhân trong Miền thời gian ↔ Tích chập trong Miền tần số&lt;/h3&gt;
&lt;p&gt;Cắt tín hiệu bằng hàm cửa sổ \(w[n]\) (\(x_w[n] = x[n]\cdot w[n]\)) tương đương lấy &lt;strong&gt;tích chập phổ thật \(X(f)\) với phổ cửa sổ \(W(f)\)&lt;/strong&gt;. Một sóng sin thuần đáng lẽ là mũi kim Dirac \(\delta(f - f_0)\) lập tức biến thành bản sao của chính hình dáng \(W(f - f_0)\) đặt tại \(f_0\)!&lt;/p&gt;

&lt;h3 id=&quot;2-đánh-đổi-búp-chính-main-lobe-width-vs-búp-phụ-side-lobe-level&quot;&gt;2. Đánh đổi Búp chính (Main-Lobe Width) vs. Búp phụ (Side-Lobe Level)&lt;/h3&gt;
&lt;p&gt;Mọi hàm cửa sổ đều phải chọn điểm cân bằng giữa hai thông số:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Độ rộng búp chính:&lt;/strong&gt; quyết định khả năng tách hai tần số nằm sát nhau (cửa sổ chữ nhật hẹp nhất, nhưng búp phụ cực cao tới \(-13\text{ dB}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chiều cao búp phụ (side-lobe suppression):&lt;/strong&gt; quyết định mức năng lượng rò từ một tần số mạnh làm lấp mất tần số yếu bên cạnh (Hann đạt \(-31.5\text{ dB}\), Hamming đạt \(-42.7\text{ dB}\), Blackman đạt \(-58\text{ dB}\)!).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-mất-mát-búp-scalloping-loss-và-chọn-cửa-sổ-cho-tiếng-nói&quot;&gt;3. Mất mát búp (Scalloping Loss) và Chọn cửa sổ cho Tiếng nói&lt;/h3&gt;
&lt;p&gt;Khi tần số tín hiệu rơi đúng giữa hai bin (lệch \(0.5\) bin), biên độ đo tại bin gần nhất bị tụt xuống (gọi là &lt;em&gt;scalloping loss&lt;/em&gt;: \(3.92\text{ dB}\) ở cửa sổ chữ nhật, nhưng chỉ còn \(1.42\text{ dB}\) ở cửa sổ Hann!). Trong xử lý tiếng nói và DeepFilterNet, cửa sổ &lt;strong&gt;Hann / Vorbis&lt;/strong&gt; là điểm ngọt vì vừa triệt rò phổ tốt, vừa thỏa điều kiện COLA/WOLA hoàn hảo ở chồng lấp 50%.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-so-sánh-mức-rò-phổ-của-sóng-lệch-nửa-bin-k--15-với-n--4&quot;&gt;Giải thích: tự tay so sánh mức rò phổ của sóng lệch nửa bin (\(k = 1.5\)) với \(N = 4\)&lt;/h3&gt;

&lt;p&gt;Xét một sóng sin phức có tần số rơi đúng giữa bin 1 và bin 2: \(x[n] = e^{j 2\pi (1.5) n / 4} = e^{j \frac{3\pi}{4} n}\) lấy mẫu tại \(n = 0, 1, 2, 3\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nếu dùng cửa sổ chữ nhật (\(w_{\text{rect}} = [1, 1, 1, 1]\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Năng lượng không tập trung vào một bin nào mà tràn ra &lt;strong&gt;cả 4 bin&lt;/strong&gt;: biên độ tại \(k = 1\) và \(k = 2\) là $$&lt;/td&gt;
              &lt;td&gt;X[1]&lt;/td&gt;
              &lt;td&gt;=&lt;/td&gt;
              &lt;td&gt;X[2]&lt;/td&gt;
              &lt;td&gt;= \frac{1}{\sin(\pi/8)} \approx \mathbf{2.613}\(, nhưng đáng ngại là các bin ở xa\)k = 0\(và\)k = 3\(vẫn hứng tới\)&lt;/td&gt;
              &lt;td&gt;X[0]&lt;/td&gt;
              &lt;td&gt;=&lt;/td&gt;
              &lt;td&gt;X[3]&lt;/td&gt;
              &lt;td&gt;= \frac{1}{\sin(3\pi/8)} \approx \mathbf{1.082}$$!&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;Tỉ số búp phụ trên búp chính: \(\frac{1.082}{2.613} \approx 0.414\) (chỉ suy giảm \(-7.7\text{ dB}\); ở \(N\) lớn tiến về &lt;strong&gt;\(-13.3\text{ dB}\)&lt;/strong&gt;) — hơn \(21\%\) tổng năng lượng bị rò sang các bin sai!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nếu nhân với cửa sổ Hann (\(w_{\text{Hann}} = [0, 0.5, 1.0, 0.5]\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tỉ số búp phụ ở \(N\) lớn rớt mạnh từ \(-13.3\text{ dB}\) xuống &lt;strong&gt;\(-31.5\text{ dB}\)&lt;/strong&gt; (biên độ rò giảm gần &lt;strong&gt;8.1 lần&lt;/strong&gt;, công suất rò giảm hơn &lt;strong&gt;66 lần&lt;/strong&gt;!), và tốc độ tắt búp phụ tăng nhanh từ \(6\text{ dB/quãng tám}\) lên &lt;strong&gt;\(18\text{ dB/quãng tám}\)&lt;/strong&gt; — giữ sạch nền phổ cho mạng khử nhiễu phát hiện chính xác các vạch hài âm yếu của giọng nói!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Giải thích cơ chế phát sinh rò phổ khi cắt đoạn bằng cửa sổ chữ nhật.&lt;/li&gt;
  &lt;li&gt;So sánh định tính các hàm cửa sổ thông dụng (Hann, Hamming, Blackman).&lt;/li&gt;
  &lt;li&gt;Liên hệ độ rộng búp chính với độ phân giải tần số và khả năng định vị thời gian.&lt;/li&gt;
  &lt;li&gt;Trình bày sự tương tác giữa hàm cửa sổ, điều kiện COLA và mặt nạ khử nhiễu.&lt;/li&gt;
  &lt;li&gt;Chọn hàm cửa sổ khớp chính xác với phần tiền xử lý STFT của mô hình đã huấn luyện.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Minh họa hiện tượng rò phổ của cửa sổ chữ nhật&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;Bảng so sánh cửa sổ: mức búp phụ và độ rộng búp chính&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Điều kiện COLA, lựa chọn cửa sổ và lỗi nhân cửa sổ hai lần&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Nhiễu nhạc và ngộ nhận về “các bin tần số độc lập”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/window-leakage.png&quot; alt=&quot;Cửa sổ chữ nhật so với Hann: biến đổi chữ nhật giữ đuôi sinc dài, Hann hạ sidelobe và làm rộng búp chính&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Phổ biên độ đã chuẩn hóa đỉnh của một âm đơn qua cửa sổ: cửa sổ chữ nhật để lại đuôi búp phụ suy giảm chậm, còn cửa sổ Hann đánh đổi búp chính rộng hơn để đạt nền búp phụ thấp hơn đáng kể.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;cơ-chế-rò-phổ&quot;&gt;Cơ chế rò phổ&lt;/h3&gt;

&lt;p&gt;Nhân tín hiệu với hàm cửa sổ (w[n]) ở miền thời gian tương đương với phép tích chập DTFT của tín hiệu với đáp ứng phổ (W(e^{j\omega})). Cửa sổ chữ nhật có búp phụ cao nên làm nhiễm năng lượng sang các bin ở xa. Các cửa sổ vuốt thuôn hai đầu (tapered) giúp hạ thấp búp phụ nhưng làm rộng búp chính, khiến các bin sát nhau bị nhòe vào nhau nhiều hơn.&lt;/p&gt;

&lt;p&gt;Bản thân việc cắt một khung hữu hạn đã ngầm nhân tín hiệu với cửa sổ chữ nhật, ngay cả khi bạn “không áp hàm cửa sổ nào”. DTFT của cửa sổ chữ nhật là nhân Dirichlet: búp phụ đầu tiên chỉ thấp hơn đỉnh chính khoảng &lt;strong&gt;13 dB&lt;/strong&gt; và phần đuôi tắt rất chậm. Khi một thành phần tần số rơi lệch tâm bin — điều luôn xảy ra với họa âm tiếng nói thực — năng lượng của nó lan ra hàng chục bin lân cận với mức đủ lớn để bộ theo dõi nhiễu nhận nhầm thành nhiễu nền.&lt;/p&gt;

&lt;p&gt;Cửa sổ Hann tuần hoàn ở bài 02-02:&lt;/p&gt;

\[w[n]=\frac12-\frac12\cos\frac{2\pi n}{L},\]

&lt;p&gt;giúp triệt tiêu phần đuôi tắt chậm đó: búp phụ đầu tiên hạ xuống khoảng &lt;strong&gt;−31 dB&lt;/strong&gt; (thấp hơn khoảng 18 dB), và các búp phụ xa tiếp tục suy giảm nhanh. Cái giá phải trả là độ rộng búp chính tăng lên khoảng bốn bin (tính từ điểm 0 đến điểm 0) thay vì hai bin. Lưu ý rằng kéo dài độ dài cửa sổ (L) và đổi sang cửa sổ Hann là hai tham số điều chỉnh độc lập nhau.&lt;/p&gt;

&lt;p&gt;Khi đọc biểu đồ minh họa, luôn chú ý trục tung tính theo dB tương đối so với đỉnh.&lt;/p&gt;

&lt;h3 id=&quot;so-sánh-định-tính-các-hàm-cửa-sổ&quot;&gt;So sánh định tính các hàm cửa sổ&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Cửa sổ&lt;/th&gt;
      &lt;th&gt;Búp phụ (sidelobe)&lt;/th&gt;
      &lt;th&gt;Búp chính (main lobe)&lt;/th&gt;
      &lt;th&gt;Ghi chú&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Chữ nhật&lt;/td&gt;
      &lt;td&gt;Kém (búp phụ đầu ≈ −13 dB)&lt;/td&gt;
      &lt;td&gt;Hẹp nhất (~2 bin)&lt;/td&gt;
      &lt;td&gt;Chủ yếu có giá trị phân tích lý thuyết; là cửa sổ ngầm nếu bỏ qua bước nhân cửa sổ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hann&lt;/td&gt;
      &lt;td&gt;Tốt (búp phụ đầu ≈ −31 dB)&lt;/td&gt;
      &lt;td&gt;Rộng hơn (~4 bin)&lt;/td&gt;
      &lt;td&gt;Lựa chọn phổ biến cho STFT; thỏa COLA ở chồng lấp 50% với dạng tuần hoàn&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hamming&lt;/td&gt;
      &lt;td&gt;Tương tự&lt;/td&gt;
      &lt;td&gt;Tương tự&lt;/td&gt;
      &lt;td&gt;Mức nền búp phụ xa khác; không thỏa cùng đồng nhất thức COLA như Hann&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Blackman&lt;/td&gt;
      &lt;td&gt;Thấp hơn nữa&lt;/td&gt;
      &lt;td&gt;Rộng hơn nữa&lt;/td&gt;
      &lt;td&gt;Rất mượt nhưng không được tự ý thay vào mô hình huấn luyện bằng Hann&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Các hệ số chuẩn cần tra cứu từ tài liệu DSP chứ không tự ước đoán. Vì hai đầu của cửa sổ Hamming không về 0 nên nó không thể thay thế trực tiếp cặp COLA của Hann dù hình dạng trông gần giống.&lt;/p&gt;

&lt;h3 id=&quot;đánh-đổi-về-độ-phân-giải&quot;&gt;Đánh đổi về độ phân giải&lt;/h3&gt;

&lt;p&gt;Độ phân giải tần số hiệu dụng tỷ lệ với (\sim \alpha f_s/L) (trong đó (\alpha&amp;gt;1) phụ thuộc dạng cửa sổ), còn độ phân giải định vị thời gian tỷ lệ với (\sim L/f_s). Khử nhiễu tiếng nói cần độ phân giải tần số đủ mịn để tách formant khỏi nền nhiễu, đồng thời đủ ngắn theo thời gian để bám sát phụ âm — do đó cửa sổ thường nằm trong khoảng vài chục mili giây thay vì 1 ms hay 1 giây.&lt;/p&gt;

&lt;p&gt;Ở 48 kHz với (L=960), búp chính của cửa sổ Hann rộng khoảng bốn bin, tương ứng (4\cdot48000/960=200\,\mathrm{Hz}). Độ rộng này chưa đủ tách riêng các họa âm sát nhau của giọng trầm và làm nhòe một âm bật (plosive) dài 5 ms ra toàn bộ cửa sổ 20 ms. Muốn thu hẹp búp chính theo Hz phải tăng (L) và chấp nhận tăng độ trễ; muốn giảm rò phổ sang các bin xa phải đổi hàm cửa sổ chứ không phải đệm số 0 — vì zero-padding chỉ nội suy dày thêm đường cong (W(e^{j\omega})) chứ không thu hẹp nó.&lt;/p&gt;

&lt;h3 id=&quot;tương-tác-giữa-cửa-sổ-và-mặt-nạ-khử-nhiễu&quot;&gt;Tương tác giữa cửa sổ và mặt nạ khử nhiễu&lt;/h3&gt;

&lt;p&gt;Hệ số độ lợi nhảy đột ngột giữa các bin kề nhau sẽ đi ngược lại độ mượt vốn có của hàm cửa sổ và tạo ra nhiễu nhạc khi xem các bin như hoàn toàn độc lập. Mặt nạ biến thiên mượt theo cả thời gian và tần số phù hợp với bản chất vật lý hơn. Dùng cửa sổ chữ nhật khiến giả định “bin độc lập” càng sai lệch nặng: bin (k+8) vẫn chứa năng lượng rò từ bin (k) ở mức nghe rõ, nên việc đóng cổng cứng các “bin nhiễu” sẽ cắt búp phụ của nguyên âm nhưng để sót búp chính.&lt;/p&gt;

&lt;h3 id=&quot;cửa-sổ-phân-tích-và-cửa-sổ-tổng-hợp&quot;&gt;Cửa sổ phân tích và cửa sổ tổng hợp&lt;/h3&gt;

&lt;p&gt;Một số pipeline chỉ nhân (w) ở bước phân tích và dùng cửa sổ tổng hợp tương ứng cho COLA; số khác dùng (\sqrt{\text{Hann}}) ở cả hai phía. Nguyên tắc bắt buộc là &lt;strong&gt;khớp đúng cấu hình lúc huấn luyện&lt;/strong&gt; — tự ý đổi sang Blackman sẽ phá vỡ điều kiện tái tạo. Bình phương cửa sổ Hann không thỏa COLA ở mức chồng lấp 50% vì tích (w\cdot w) dao động giữa (1/2) và (1); phép lấy căn bậc hai chia đều độ thuôn cho cả hai phía mà vẫn giữ tổng tích phẳng.&lt;/p&gt;

&lt;p&gt;Do giá trị trung bình của cửa sổ Hann là (1/2), phép phân tích chưa chuẩn hóa sẽ làm công suất băng rộng giảm khoảng 6 dB trước cả khi qua bộ khử nhiễu. Nếu tính SI-SDR so với tín hiệu tham chiếu miền thời gian mà quên chia cho hằng số COLA, kết quả sẽ xuất hiện sai lệch hệ thống.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Ở 16 kHz với (L=512), so sánh một âm đơn nằm đúng bin 32 với âm nằm giữa hai bin tại 32.5. Với cửa sổ chữ nhật, trường hợp lệch bin làm năng lượng lan rộng; với cửa sổ Hann, búp phụ hạ mạnh còn búp chính rộng ra nên cả bin 32 và 33 đều nổi rõ. Lưu ý rằng âm đơn rơi đúng bin có thể tạo phổ trông gần như lý tưởng (búp phụ nằm ở mức sai số máy) và che giấu lỗi cửa sổ — vì vậy luôn cần kiểm thử bằng âm lệch nửa bin. Trong Mini-lab dưới đây, giá trị búp phụ đo được không trùng khớp tuyệt đối với mốc −13 / −31 dB trong sách do đỉnh nằm giữa hai bin và phép đo có chừa vành bảo vệ, nhưng khoảng cách chênh lệch giữa cửa sổ chữ nhật và Hann vẫn thể hiện rõ.&lt;/p&gt;

&lt;p&gt;Trừ phổ cổ điển áp ngưỡng độc lập trên từng bin thường để lại các đỉnh cô lập gây tiếng lách tách kiểu “chim hót” (birdies / musical noise). Làm mượt sẽ giảm hiện tượng này nhưng lại làm nhòe tiếng nói — đó chính là giới hạn kinh điển thúc đẩy các phương pháp tăng cường tiếng nói bằng mạng nơ-ron.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Áp dụng hàm cửa sổ hai lần (thư viện đã tự nhân cửa sổ nhưng mã người dùng lại nhân thêm lần nữa).&lt;/li&gt;
  &lt;li&gt;Dùng cửa sổ chữ nhật vì lầm tưởng “FFT yêu cầu như vậy”.&lt;/li&gt;
  &lt;li&gt;Quên hệ số khuếch đại của cửa sổ khi kiểm tra Parseval hoặc tính SI-SDR.&lt;/li&gt;
  &lt;li&gt;Dùng cửa sổ lúc triển khai khác với cửa sổ lúc huấn luyện.&lt;/li&gt;
  &lt;li&gt;Kỳ vọng hàm cửa sổ có thể khắc phục lỗi aliasing (điều này không thể xảy ra).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Tính FFT cho một sóng sin rơi lệch bin dưới cửa sổ chữ nhật và cửa sổ Hann tuần hoàn, sau đó in mức búp phụ tính theo dB so với đỉnh.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;32.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# giữa bin 32 và 33
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hann&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sidelobe_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;guard&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;argmax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;side&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;concatenate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;guard&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:]])&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;side&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;rect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;han&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hann&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rect sidelobe dB&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sidelobe_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hann sidelobe dB&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sidelobe_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;han&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Búp phụ của cửa sổ chữ nhật xấp xỉ &lt;strong&gt;−17 dB&lt;/strong&gt;, còn cửa sổ Hann xấp xỉ &lt;strong&gt;−40 dB&lt;/strong&gt; (với vành bảo vệ 3 bin quanh đỉnh lệch bin). Cửa sổ Hann cho nền búp phụ thấp hơn rõ rệt, đổi lại búp chính rộng hơn khi vẽ cả hai phổ lên cùng đồ thị.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Chọn tần số đúng bin nguyên (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;32 * fs / N&lt;/code&gt;) sẽ đẩy búp phụ của cả hai cửa sổ xuống mức sai số số học (dưới −200 dB) và không minh họa được sự khác biệt; dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.hann&lt;/code&gt; thay cho công thức tuần hoàn chỉ làm thay đổi nhẹ giá trị của Hann chứ không thu hẹp khoảng cách; quên chia cho &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mag.max()&lt;/code&gt; sẽ in ra biên độ FFT tuyệt đối thay vì dB tương đối; và đặt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;guard=0&lt;/code&gt; sẽ tính nhầm sườn búp chính là búp phụ khiến cả hai cửa sổ đều trông kém như nhau.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Giải thích vì sao cửa sổ vuốt thuôn hai đầu (tapered) giúp giảm búp phụ.&lt;/li&gt;
  &lt;li&gt;Khi tăng gấp đôi độ dài cửa sổ (L), độ rộng búp chính thay đổi xấp xỉ như thế nào?&lt;/li&gt;
  &lt;li&gt;Bước nhảy hop nào thỏa mãn điều kiện COLA phổ biến nhất với cửa sổ Hann?&lt;/li&gt;
  &lt;li&gt;Mặt nạ cắt mạnh theo từng bin độc lập gây ra nhiễu nhạc theo cơ chế nào?&lt;/li&gt;
  &lt;li&gt;Nêu một lý do khiến cửa sổ (\sqrt{\mathrm{Hann}}) thường xuất hiện trong các kho mã STFT.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Biến đổi Fourier (W) của cửa sổ vuốt thuôn có búp phụ nhỏ hơn nhiều, mà phép nhân với (w) tương đương tích chập phổ tín hiệu với (W).&lt;/li&gt;
  &lt;li&gt;Độ rộng theo Hz tỷ lệ với (f_s/L) nên giảm đi một nửa; còn độ rộng tính theo số bin của cửa sổ Hann vẫn vào khoảng 4 bin.&lt;/li&gt;
  &lt;li&gt;(R=L/2) khi dùng cửa sổ Hann tuần hoàn (như đã chứng minh ở bài 02-02).&lt;/li&gt;
  &lt;li&gt;Các giá trị 0 đột ngột giữa các bin lân cận cắt mất phần búp phụ của một họa âm thực nhưng để sót các đỉnh cô lập, sau ISTFT chuyển thành các âm sắc ngắn nghe như tiếng chim hót.&lt;/li&gt;
  &lt;li&gt;Giúp cả bước phân tích lẫn bước tổng hợp đều được vuốt thuôn ở hai biên trong khi tích hai cửa sổ vẫn thỏa điều kiện COLA.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — hàm cửa sổ và phân tích phổ.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Spectral Audio Signal Processing&lt;/em&gt; — mức búp phụ và độ rộng búp chính của các hàm cửa sổ.&lt;/li&gt;
  &lt;li&gt;Cấu hình STFT của DeepFilterNet: &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=tCWU9C-LdJQ&quot;&gt;Lecture 13: Spectral Leakage, Windowing, with Examples of Hanning and Hamming Windows&lt;/a&gt; — Bahga Lab IIT Delhi, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; So sánh búp phụ của cửa sổ chữ nhật với Hann và Hamming, làm rõ trực tiếp sự đánh đổi giữa búp chính và rò phổ.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=MBnnXbOM5S4&quot;&gt;The more general uncertainty principle, regarding Fourier transforms&lt;/a&gt; — 3Blue1Brown, tiếng Anh. Phần nguyên lý bất định giải thích vì sao rút ngắn thời gian quan sát bắt buộc phải làm rộng búp chính theo tần số.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-Yxj3yfvY-4&quot;&gt;Short-Time Fourier Transform Explained Easily&lt;/a&gt; — Valerio Velardo - The Sound of AI, tiếng Anh. Minh họa trực tiếp bước nhân cửa sổ vuốt thuôn trên khung tiếng nói — nơi rò phổ có thể dẫn tới nhiễu nhạc ở các bước xử lý sau.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-02 Frame, hop và overlap-add</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_02_frames_hop_overlap_add/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_02_frames_hop_overlap_add</id>
   <content type="html">&lt;p&gt;Pipeline STFT chia tín hiệu âm thanh thành các khung chồng lấp, xử lý từng khung rồi ghép lại bằng kỹ thuật cộng chồng lấp (overlap-add, OLA). Cấu hình sai bước nhảy hop hoặc sai OLA sẽ tạo ra tiếng rung giật (warble) mà việc cập nhật trọng số mạng nơ-ron không thể khắc phục. Bài học này chứng minh điều kiện COLA (constant overlap-add: tổng các hàm cửa sổ chồng lấp bằng hằng số) cho cửa sổ Hann tuần hoàn, đồng thời quy đổi (L) và (R) sang mili giây — vì thông số “chồng lấp 50%” chưa cho biết độ trễ cho tới khi chia cho (f_s).&lt;/p&gt;

&lt;p&gt;Khi bạn cắt một đoạn ghi âm thành từng lát 20 ms, nhân mỗi lát với một đường cong hình chuông (như cửa sổ Hann) để hai đầu lát vuốt êm về 0, rồi biến đổi ngược lại miền thời gian — một câu hỏi quan trọng lập tức đặt ra: &lt;em&gt;làm sao ghép các lát hình chuông ấy lại với nhau để giọng nói phát ra không bị lúc to lúc nhỏ nhấp nhô theo nhịp 10 ms?&lt;/em&gt; Bí mật nằm ở thuật toán &lt;strong&gt;Overlap-Add (OLA)&lt;/strong&gt; và một điều kiện toán học đẹp như thơ mang tên &lt;strong&gt;COLA (Constant Overlap-Add)&lt;/strong&gt;!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-chia-khung-bước-nhảy-và-overlap-add-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Chia khung, Bước nhảy và Overlap-Add đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-bộ-ba-tham-số-frame-length-n-hop-size-h-và-tỉ-lệ-chồng-lấp&quot;&gt;1. Bộ ba tham số: Frame Length (\(N\)), Hop Size (\(H\)) và Tỉ lệ chồng lấp&lt;/h3&gt;
&lt;p&gt;Mỗi khung thứ \(m\) bắt đầu tại vị trí \(mH\) và lấy \(N\) mẫu: \(x_m[n] = x[mH + n]\cdot w[n]\). Tỉ lệ chồng lấp là \(1 - H/N\) (ví dụ \(N = 960,\ H = 480 \implies\) chồng lấp &lt;strong&gt;50%&lt;/strong&gt;; \(H = 240 \implies\) chồng lấp &lt;strong&gt;75%&lt;/strong&gt;). Giảm \(H\) giúp bám sát biến đổi nhanh của tiếng nói tốt hơn nhưng làm tăng tuyến tính số khung phải chạy FFT mỗi giây.&lt;/p&gt;

&lt;h3 id=&quot;2-điều-kiện-tái-tạo-hoàn-hảo-cola-constant-overlap-add&quot;&gt;2. Điều kiện Tái tạo Hoàn hảo COLA (Constant Overlap-Add)&lt;/h3&gt;
&lt;p&gt;Nếu ta chưa sửa gì trong miền tần số (bộ lọc đồng nhất), tổng các cửa sổ trượt chồng lên nhau phải bằng &lt;strong&gt;đúng một hằng số \(C &amp;gt; 0\) tại mọi mẫu \(n\)&lt;/strong&gt;:&lt;/p&gt;

\[\sum_{m=-\infty}^{\infty} w[n - mH] = C \qquad \forall n \in \mathbb{Z}.\]

&lt;p&gt;Nếu điều kiện COLA bị vi phạm (ví dụ dùng cửa sổ Hann nhưng lại chọn hop \(H = 0.6 N\)), âm thanh đầu ra sẽ bị điều biến biên độ gợn sóng liên tục!&lt;/p&gt;

&lt;h3 id=&quot;3-hai-biến-thể-thực-thi-ola-overlap-add-vs-wola-weighted-overlap-add&quot;&gt;3. Hai biến thể thực thi: OLA (Overlap-Add) vs. WOLA (Weighted Overlap-Add)&lt;/h3&gt;
&lt;p&gt;Trong &lt;strong&gt;OLA cổ điển&lt;/strong&gt;, chỉ nhân cửa sổ ở đầu phân tích (analysis) rồi cộng thẳng ở đầu tổng hợp. Trong &lt;strong&gt;WOLA&lt;/strong&gt; (dùng trong DeepFilterNet và hầu hết hệ thống khử nhiễu hiện đại), ta nhân cửa sổ ở &lt;em&gt;cả hai đầu&lt;/em&gt; phân tích (\(w_a\)) và tổng hợp (\(w_s\)) để làm mượt các bước nhảy do mặt nạ khử nhiễu gây ra — khi đó điều kiện tái tạo hoàn hảo trở thành \(\sum_m w_a[n - mH]\,w_s[n - mH] = C\)!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-kiểm-chứng-điều-kiện-cola-của-cửa-sổ-hann-với-chồng-lấp-50&quot;&gt;Giải thích: tự tay kiểm chứng điều kiện COLA của cửa sổ Hann với chồng lấp 50%&lt;/h3&gt;

&lt;p&gt;Xét cửa sổ &lt;strong&gt;Hann định kỳ (periodic Hann)&lt;/strong&gt; độ dài \(N\) với bước nhảy \(H = N/2\):&lt;/p&gt;

\[w[n] = \frac{1}{2}\Bigl(1 - \cos\frac{2\pi n}{N}\Bigr), \qquad n = 0, 1, \dots, N - 1.\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chứng minh đại số tổng quát cho mọi \(N\) chẵn:&lt;/strong&gt; Tại bất kỳ vị trí \(n \in [0, N/2 - 1]\) nào, có đúng 2 khung phủ lên nó (nửa sau của khung trước và nửa đầu của khung hiện tại):
\(w[n] + w\!\Bigl(n + \frac{N}{2}\Bigr) = \frac{1}{2}\Bigl(1 - \cos\frac{2\pi n}{N}\Bigr) + \frac{1}{2}\Bigl(1 - \cos\!\Bigl(\frac{2\pi n}{N} + \pi\Bigr)\Bigr).\)
Nhờ đồng nhất thức lượng giác \(\cos(\theta + \pi) = -\cos\theta\), hai số hạng cosin &lt;strong&gt;triệt tiêu nhau tuyệt đối&lt;/strong&gt;, để lại:
\(w[n] + w\!\Bigl(n + \frac{N}{2}\Bigr) = \frac{1}{2} + \frac{1}{2} = \mathbf{1.0}!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra bằng số cụ thể với \(N = 4,\ H = 2\):&lt;/strong&gt; Cửa sổ Hann định kỳ là \(w = [0,\ 0.5,\ 1.0,\ 0.5]\). Xếp chồng 3 khung liên tiếp lệch nhau \(H = 2\) mẫu:
    &lt;ul&gt;
      &lt;li&gt;Khung 0: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0.0, 0.5, 1.0, 0.5,  · ,  · ,  · ,  · ]&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Khung 1: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[ · ,  · , 0.0, 0.5, 1.0, 0.5,  · ,  · ]&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Khung 2: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[ · ,  · ,  · ,  · , 0.0, 0.5, 1.0, 0.5]&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Cộng từng cột (từ vùng ổn định \(n=2..5\)):&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1.0, 1.0, 1.0, 1.0]&lt;/code&gt; — phẳng lì tuyệt đối, sai số bằng \(0\)! (Lưu ý bẫy hay gặp: cửa sổ Hann &lt;em&gt;đối xứng&lt;/em&gt; dùng \(N-1\) ở mẫu số sẽ &lt;strong&gt;không&lt;/strong&gt; thỏa COLA chính xác bằng 1 mà bị gợn nhẹ tại ranh giới!)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Định nghĩa độ dài khung (L), bước nhảy hop (R) và tỷ lệ chồng lấp (overlap).&lt;/li&gt;
  &lt;li&gt;Giải thích cơ chế tái tạo OLA và điều kiện COLA.&lt;/li&gt;
  &lt;li&gt;Tính hệ quả về độ trễ thuật toán từ (L) và (R).&lt;/li&gt;
  &lt;li&gt;Lựa chọn bước nhảy hop cho khử nhiễu tiếng nói dựa trên sự đánh đổi giữa độ trễ và chất lượng.&lt;/li&gt;
  &lt;li&gt;Hình dung rõ cách vận hành của bộ đệm OLA trong chế độ streaming.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Vẽ sơ đồ khung và bước nhảy hop trên bảng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;Cơ sở toán học của OLA và chứng minh COLA cho cửa sổ Hann&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Cơ chế bộ đệm streaming và xử lý hiệu ứng biên&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Các thông số thực tế ở 16 kHz và 48 kHz cho tiếng nói&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/stft-ola.png&quot; alt=&quot;Các frame phân tích chồng nhau, cửa sổ Hann trượt với hop R, và tổng overlap-add của chúng&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Khung dài (L) trượt tiến từng bước hop (R); phép cộng chồng lấp chỉ tái tạo trung thực dạng sóng tại vùng mà tổng các cửa sổ dịch chuyển bằng hằng số.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;chia-khung-framing&quot;&gt;Chia khung (framing)&lt;/h3&gt;

&lt;p&gt;Xét cửa sổ có độ dài (L) mẫu và bước nhảy hop (R) mẫu ((1\le R\le L)). Tỷ lệ chồng lấp là:&lt;/p&gt;

\[\rho = 1-\frac{R}{L}\]

&lt;p&gt;Chồng lấp 50% ứng với (R=L/2); chồng lấp 75% ứng với (R=L/4). Bước nhảy (R) cũng chính là số mẫu mới cần gom thêm trước lần tính FFT kế tiếp:&lt;/p&gt;

\[T_R=\frac{R}{f_s},\qquad \text{hops/s}=\frac{f_s}{R},\qquad T_L=\frac{L}{f_s}.\]

&lt;p&gt;Trong đó, (T_L) là thời lượng âm thanh chứa trong một khung phân tích, còn (T_R) là chu kỳ xuất ra một khung mới. Một cửa sổ 20 ms đi kèm hop 10 ms vẫn quan sát đủ 20 ms ngữ cảnh ở mỗi lần chạy.&lt;/p&gt;

&lt;h3 id=&quot;cộng-chồng-lấp-overlap-add&quot;&gt;Cộng chồng lấp (overlap-add)&lt;/h3&gt;

&lt;p&gt;Với mỗi khung sau xử lý (y_m[n]=w_{\mathrm{syn}}[n]\cdot \mathrm{iFFT}(\hat{X}_m)), tín hiệu đầu ra được tổng hợp theo công thức:&lt;/p&gt;

\[\hat{x}[n]=\sum_m y_m[n-mR]\]

&lt;p&gt;Nếu (\hat{X}&lt;em&gt;m) là phổ STFT chưa thay đổi của (x) và cặp cửa sổ thỏa mãn điều kiện &lt;strong&gt;COLA&lt;/strong&gt;, thì (\hat{x}) sẽ tái tạo lại chính xác (x) (sai khác tối đa một độ trễ và hệ số khuếch đại hằng). Cần phân biệt rõ: bước phân tích đã nhân với (w&lt;/em&gt;{\mathrm{ana}}), còn phần nhân thêm sau iFFT là (w_{\mathrm{syn}}); viết tường minh cả hai giúp tránh lỗi nhân cửa sổ hai lần.&lt;/p&gt;

&lt;h3 id=&quot;điều-kiện-cola&quot;&gt;Điều kiện COLA&lt;/h3&gt;

&lt;p&gt;Với bước nhảy hop (R), tổng tích của cửa sổ phân tích và cửa sổ tổng hợp dịch theo hop phải bằng một hằng số:&lt;/p&gt;

\[\sum_m w_{\mathrm{ana}}[n-mR]\,w_{\mathrm{syn}}[n-mR] = C\]

&lt;p&gt;(Cụ thể cách kiểm tra phụ thuộc vào việc pipeline nhân cửa sổ một lần hay hai lần và phải khớp định nghĩa STFT đã dùng.) Cửa sổ Hann với tỷ lệ chồng lấp 50% là lựa chọn COLA kinh điển khi dùng đúng phiên bản tuần hoàn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chứng minh cho cửa sổ Hann tuần hoàn.&lt;/strong&gt; Định nghĩa:&lt;/p&gt;

\[w[n]=\frac12-\frac12\cos\frac{2\pi n}{L},\qquad n=0,\ldots,L-1.\]

&lt;p&gt;Lưu ý mẫu số là (L) chứ không phải (L-1): đây là dạng Hann &lt;em&gt;tuần hoàn&lt;/em&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sym=False&lt;/code&gt;). Phiên bản Hann đối xứng (ép (w[0]=w[L-1]=0)) &lt;strong&gt;không&lt;/strong&gt; cộng thành hằng số chính xác, và đó là nguyên nhân phổ biến khiến bài kiểm tra “Hann 50%” bị lệch vài phần nghìn.&lt;/p&gt;

&lt;p&gt;Chọn (R=L/2) và xét một mẫu trong vùng giao của hai cửa sổ kế tiếp. Đặt (\theta=2\pi n/L), ta có:&lt;/p&gt;

\[w[n]=\frac12(1-\cos\theta),\qquad
w[n+R]=\frac12(1+\cos\theta).\]

&lt;p&gt;Suy ra:&lt;/p&gt;

\[w[n]+w[n+R]=1.\]

&lt;p&gt;Như vậy, nếu (w_{\mathrm{ana}}=w) và (w_{\mathrm{syn}}=1) (không nhân cửa sổ lần thứ hai sau iFFT), tổng COLA ở vùng ổn định luôn bằng hằng số (C=1). Phần Mini-lab dưới đây sẽ kiểm chứng hằng số này.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trường hợp không bằng hằng số.&lt;/strong&gt; Nếu lấy tổng bình phương của cùng cửa sổ đó ở hop 50%, ta thu được (\tfrac12(1+\cos^2\theta)), dao động liên tục giữa (1/2) và (1). Do đó, việc nhân đầy đủ cửa sổ Hann ở cả đầu vào lẫn đầu ra sẽ khiến biên độ bị nhấp nhô theo tần số (f_s/R) Hz. Cách khắc phục chuẩn là dùng (w_{\mathrm{ana}}=w_{\mathrm{syn}}=\sqrt{w}): tích hai cửa sổ đúng bằng (w) nên tổng chồng lấp lại bằng hằng số như vừa chứng minh. Đó là lý do cửa sổ (\sqrt{\mathrm{Hann}}) thường xuyên xuất hiện trong mã nguồn STFT.&lt;/p&gt;

&lt;h3 id=&quot;độ-trễ&quot;&gt;Độ trễ&lt;/h3&gt;

&lt;p&gt;Tăng (L) giúp cải thiện độ phân giải tần số nhưng làm tăng độ trễ đệm. Giảm (R) giúp cập nhật mặt nạ dày và mượt hơn nhưng tăng tải CPU vì số hop mỗi giây lớn hơn. Các bộ khử nhiễu sản phẩm thường chọn hop trong khoảng 5–20 ms, nhưng &lt;strong&gt;luôn phải khớp với mô hình&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Với cửa sổ phân tích nhân quả, độ trễ thuật toán xấp xỉ toàn bộ chiều dài cửa sổ chứ không chỉ bằng bước nhảy hop:&lt;/p&gt;

\[D_{\mathrm{alg}}\approx T_L=\frac{L}{f_s}.\]

&lt;p&gt;Hệ thống chưa thể lập khung phân tích nếu chưa nhận đủ mẫu cuối cùng của khung đó. Giảm (R) từ (L/2) xuống (L/4) làm tăng gấp đôi số hop mỗi giây nhưng không giúp cắt giảm (D_{\mathrm{alg}}) xuống một nửa. Với STFT căn giữa (centered), hệ thống cần thêm khoảng (T_L/2) mẫu nhìn trước. Bài 02-07 sẽ tách bạch độ trễ thuật toán này khỏi hệ số thời gian thực (RTF).&lt;/p&gt;

&lt;h3 id=&quot;bộ-đệm-ola-trong-chế-độ-streaming&quot;&gt;Bộ đệm OLA trong chế độ streaming&lt;/h3&gt;

&lt;p&gt;Hệ thống cần duy trì một bộ đệm tích lũy (accumulator) có độ dài (\ge L). Ở mỗi hop, ta cộng khung vừa tổng hợp vào bộ đệm, xuất ra (R) mẫu đã hoàn tất (không còn khung tương lai nào chồng lên nữa), và giữ lại phần đuôi chồng lấp cho hop kế tiếp. (L-R) mẫu đầu tiên chưa đủ số cửa sổ chồng lấp để đạt hằng số (C), nên cần làm mờ (fade) ở đoạn khởi động. Nếu xóa bộ đệm tích lũy sau mỗi callback, tổng chồng lấp sẽ bị ngắt quãng liên tục và tạo ra hiện tượng rung biên độ (tremolo).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Với (f_s=48\,\mathrm{kHz}), (L=960) (20 ms) và (R=480) (10 ms), ta có (\rho=0.5), tốc độ 100 hop/giây và (D_{\mathrm{alg}}\approx 20\,\mathrm{ms}). Đây là lưới phân tích công bố của DeepFilterNet: (N_{\mathrm{FFT}}=960) ở 48 kHz với tỷ lệ chồng lấp 50% (&lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Với (f_s=16\,\mathrm{kHz}), (L=512) và (R=256), ta có (T_L=512/16000=32\,\mathrm{ms}), (T_R=16\,\mathrm{ms}) và tốc độ 62.5 hop/giây. Cần tránh nhầm lẫn: 512 mẫu ở 16 kHz là 32 ms chứ không phải 16 ms, còn hop 10 ms ở 16 kHz tương ứng (R=160) chứ không phải 256.&lt;/p&gt;

&lt;h3 id=&quot;triệu-chứng-khi-vi-phạm-cola&quot;&gt;Triệu chứng khi vi phạm COLA&lt;/h3&gt;

&lt;p&gt;Âm thanh xuất hiện hiện tượng rung biên độ (tremolo) ở tần số (f_s/R) Hz (ví dụ 100 Hz khi hop bằng 10 ms), thường được người nghe mô tả là tiếng “robot” hoặc “lệch pha”. Sai số độ lợi của mạng nơ-ron không cố định chính xác tại (f_s/R), nhưng lỗi COLA thì có.&lt;/p&gt;

&lt;h3 id=&quot;giai-đoạn-khởi-động&quot;&gt;Giai đoạn khởi động&lt;/h3&gt;

&lt;p&gt;(L-R) mẫu đầu tiên của tệp thường chưa đủ chồng lấp, nên cần loại bỏ hoặc làm mượt trước khi tính chỉ số SI-SDR.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Kết hợp cửa sổ phân tích Hann với cửa sổ tổng hợp chữ nhật mà không kiểm tra điều kiện COLA.&lt;/li&gt;
  &lt;li&gt;Thay đổi kích thước hop nhưng giữ nguyên hàm cửa sổ thiết kế cho hop cũ.&lt;/li&gt;
  &lt;li&gt;Xuất ra đủ (L) mẫu ở mỗi hop thay vì (R) mẫu, gây mất đồng bộ thời gian.&lt;/li&gt;
  &lt;li&gt;Xóa bộ nhớ tích lũy OLA sau mỗi lần gọi callback.&lt;/li&gt;
  &lt;li&gt;Dùng STFT ngoại tuyến (có đệm căn giữa) khi đánh giá nhưng lại dùng STFT streaming nhân quả lúc chạy thật.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Thực hiện cộng chồng lấp cửa sổ Hann tuần hoàn với bước nhảy 50% và kiểm chứng độ phẳng của tổng ở vùng giữa.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Hann tuần hoàn, không phải np.hann mặc định
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;COLA constant&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;peak deviation&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Hằng số COLA in ra là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.0&lt;/code&gt;, với độ lệch cực đại cỡ (10^{-15}).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.hann(L)&lt;/code&gt; (dạng đối xứng) sẽ đẩy độ lệch lên khoảng (10^{-2}) do cả hai đầu đều bằng 0 khiến tổng từng cặp không còn bằng 1. Nếu cộng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w**2&lt;/code&gt; thay vì &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt; ở hop 50%, tổng sẽ dao động giữa 0.5 và 1 — đây chính là gợn biên độ khi nhân cửa sổ hai lần. Với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;R = L // 4&lt;/code&gt; (chồng lấp 75%), tổng của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt; vẫn phẳng nhưng bằng hằng số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2.0&lt;/code&gt; (nếu giả định &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C = 1&lt;/code&gt; sẽ làm gấp đôi biên độ); còn nếu chọn bước nhảy không phải ước của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L&lt;/code&gt; (chẳng hạn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;R = 3 * L // 4&lt;/code&gt;), điều kiện COLA mới thực sự bị phá vỡ và tổng không còn phẳng.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Tính tỷ lệ chồng lấp khi (L=1024) và (R=256).&lt;/li&gt;
  &lt;li&gt;Tính độ dài hop (ms) ở 16 kHz khi (R=160).&lt;/li&gt;
  &lt;li&gt;Vì sao giảm kích thước hop lại làm tăng tải CPU?&lt;/li&gt;
  &lt;li&gt;Phác thảo trạng thái bộ đệm OLA sau 3 hop với (L=8) và (R=4).&lt;/li&gt;
  &lt;li&gt;Nêu một tín hiệu kiểm thử điều kiện COLA (ví dụ xung đơn vị hoặc chirp) và giải thích cách quan sát.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;(\rho=1-256/1024=0.75) (75%).&lt;/li&gt;
  &lt;li&gt;(160/16000=10\,\mathrm{ms}).&lt;/li&gt;
  &lt;li&gt;Vì số hop mỗi giây ((f_s/R)) tăng lên, kéo theo số lần gọi FFT/iFFT mỗi giây tăng tương ứng.&lt;/li&gt;
  &lt;li&gt;Sau 3 hop, bộ đệm tích lũy có một đoạn giữa dài (R) mẫu nơi hai cửa sổ chồng hoàn toàn, cộng thêm phần đuôi đang chờ dài (L-R) mẫu.&lt;/li&gt;
  &lt;li&gt;Tín hiệu xung đơn vị (hoặc hằng số) làm lộ ngay tổng COLA không phẳng dưới dạng đường bao biên độ tuần hoàn; tín hiệu chirp giúp phát hiện thêm hiện tượng nhòe theo thời gian.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — STFT, dãy bộ lọc (filterbank) và OLA.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Spectral Audio Signal Processing&lt;/em&gt; — điều kiện COLA và các đồng nhất thức của cửa sổ Hann.&lt;/li&gt;
  &lt;li&gt;Cấu hình định khung DeepFilterNet: &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;, &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;github.com/Rikorose/DeepFilterNet&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-Yxj3yfvY-4&quot;&gt;Short-Time Fourier Transform Explained Easily&lt;/a&gt; — Valerio Velardo - The Sound of AI, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Minh họa cách cắt khung, bước nhảy hop và nhân cửa sổ; overlap-add chính là bước ghép các khung đó trở lại thành dạng sóng.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=NA0TwPsECUQ&quot;&gt;Short-time Fourier Transform and the Spectogram&lt;/a&gt; — Barry Van Veen, tiếng Anh. Giải thích lý do các khung liên tiếp phải chồng lấp để phép biến đổi ngắn hạn có thể nghịch đảo chính xác.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=KuXjwB4LzSA&quot;&gt;But what is a convolution?&lt;/a&gt; — 3Blue1Brown, tiếng Anh. Xem phần FFT: tích chập miền thời gian tương đương phép nhân miền tần số, và overlap-add là cách ghép lại tín hiệu dài.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01 PCM, tốc độ mẫu và kênh</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_01_pcm_sample_rates_channels/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter02/02_01_pcm_sample_rates_channels</id>
   <content type="html">&lt;p&gt;Bộ khử nhiễu mạng nơ-ron nhận đầu vào là tensor, trong khi micro cung cấp luồng PCM. Định dạng bộ đệm, tần số lấy mẫu và cách bố trí kênh là những điểm tích hợp dễ gặp lỗi nhất ngay cả trước khi mô hình chạy. Sai (f_s) không chỉ làm âm thanh “tối” đi mà còn khiến năng lượng bị gập qua tần số Nyquist: một âm đơn 7 kHz lấy mẫu ở 8 kHz sẽ trùng khớp hoàn toàn về giá trị mẫu với âm 1 kHz, và không mặt nạ STFT nào có thể gỡ ngược phép gập đó.&lt;/p&gt;

&lt;p&gt;Trước khi bất kỳ thuật toán FFT hay mạng nơ-ron nào chạm tới giọng nói của bạn, micro và mạch chuyển đổi tương tự–số (ADC) đã phải biến sóng áp suất không khí liên tục thành một dòng các con số rời rạc gọi là &lt;strong&gt;PCM (Pulse-Code Modulation)&lt;/strong&gt;. Nếu bạn chọn sai định dạng PCM — chẳng hạn gộp sai kênh stereo, quên chuẩn hóa số nguyên 16-bit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt; về số thực &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; trong đoạn \([-1, 1]\), hoặc trộn nhầm tệp 16 kHz vào mô hình 48 kHz — toàn bộ hệ thống khử nhiễu phía sau sẽ phát ra tiếng ré chói tai hoặc giọng trầm chậm đi đúng 3 lần!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-biểu-diễn-âm-thanh-số-pcm-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Biểu diễn Âm thanh số PCM đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-rời-rạc-hóa-thời-gian-sample-rate-và-rời-rạc-hóa-biên-độ-bit-depth&quot;&gt;1. Rời rạc hóa thời gian (Sample Rate) và Rời rạc hóa biên độ (Bit Depth)&lt;/h3&gt;
&lt;p&gt;PCM thực hiện hai phép rời rạc hóa độc lập: &lt;strong&gt;lấy mẫu theo thời gian&lt;/strong&gt; ở tần số \(f_s\) (8 kHz điện thoại cổ điển, 16 kHz chuẩn ASR băng rộng, 48 kHz chuẩn WebRTC/Video) và &lt;strong&gt;lượng tử hóa biên độ&lt;/strong&gt; bằng \(B\) bit (phổ biến là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt; có \(2^{16} = 65\,536\) mức từ \(-32\,768\) đến \(+32\,767\), hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; chuẩn hóa trong \([-1.0,\ +1.0]\)).&lt;/p&gt;

&lt;h3 id=&quot;2-nhiễu-lượng-tử-hóa-và-quy-tắc-vàng-6-dbbit-sqnr&quot;&gt;2. Nhiễu lượng tử hóa và Quy tắc vàng 6 dB/bit (SQNR)&lt;/h3&gt;
&lt;p&gt;Làm tròn biên độ thực về mức lượng tử gần nhất sinh ra sai số nhỏ gọi là &lt;strong&gt;nhiễu lượng tử hóa&lt;/strong&gt;. Với mô hình sai số phân bố đều trong bước nhảy \(\Delta = 2 / 2^B\), tỉ số tín hiệu trên nhiễu lượng tử hóa cho sóng sin toàn thang đạt công thức kinh điển:&lt;/p&gt;

\[\text{SQNR}_{\text{dB}} \approx 6.02\,B + 1.76\text{ dB}.\]

&lt;p&gt;Mỗi khi tăng thêm &lt;strong&gt;1 bit&lt;/strong&gt; độ sâu, dải động sạch của bản ghi tăng thêm khoảng &lt;strong&gt;6 dB&lt;/strong&gt;!&lt;/p&gt;

&lt;h3 id=&quot;3-bố-cục-đa-kênh-mono-vs-stereo-interleavedplanar-và-clipping&quot;&gt;3. Bố cục đa kênh (Mono vs. Stereo Interleaved/Planar) và Clipping&lt;/h3&gt;
&lt;p&gt;Âm thanh đa kênh có thể lưu kiểu &lt;strong&gt;xen kẽ (interleaved: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L0, R0, L1, R1, ...&lt;/code&gt;)&lt;/strong&gt; hoặc &lt;strong&gt;tách mảng (planar: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[L0, L1, ...], [R0, R1, ...]&lt;/code&gt;)&lt;/strong&gt;. Nếu vượt biên \([-1.0, +1.0]\) trước khi xuất ra DAC, tín hiệu bị &lt;strong&gt;cắt ngọn (clipping)&lt;/strong&gt; tạo ra sóng vuông đầy hài bậc lẻ cực kỳ chói tai!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-tính-bitrate-dung-lượng-và-sqnr-của-chuẩn-pcm-48-khz--16-bit&quot;&gt;Giải thích: tự tay tính Bitrate, dung lượng và SQNR của chuẩn PCM 48 kHz / 16-bit&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính tốc độ bit (Bitrate) và dung lượng file WAV không nén&lt;/strong&gt; cho âm thanh Stereo (\(C = 2\) kênh), \(f_s = 48\,000\text{ Hz}\), độ sâu \(B = 16\text{ bit}\):
\(\text{Bitrate} = f_s \times B \times C = 48\,000 \times 16 \times 2 = 1\,536\,000\text{ bit/giây} = \mathbf{1.536\text{ Mbps}}.\)
Đổi ra byte mỗi phút: \(\frac{1\,536\,000}{8} \times 60 = 11\,520\,000\text{ byte} \approx \mathbf{11.0\text{ MiB/phút}}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh dải động SQNR giữa 8-bit và 16-bit:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;8-bit:&lt;/strong&gt; \(\text{SQNR} \approx 6.02(8) + 1.76 = \mathbf{49.9\text{ dB}}\) (nền nhiễu lượng tử nghe rất rõ trong đoạn im lặng).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;16-bit (chuẩn CD/WebRTC):&lt;/strong&gt; \(\text{SQNR} \approx 6.02(16) + 1.76 = \mathbf{98.1\text{ dB}}\) (vượt xa độ động của hầu hết micro và phòng thu thông thường!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn hóa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt; ↔ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; không lệch trục:&lt;/strong&gt; Chuyển &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt; sang &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; phải chia cho \(32\,768.0\) (\(2^{15}\)), không chia cho \(32\,767\), để giá trị nhỏ nhất \(-32\,768\) ánh xạ đúng về \(-1.0\) mà không gây tràn số!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Mô tả các định dạng mã hóa PCM phổ biến trên trình duyệt và hệ thống native (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;, bố cục planar và interleaved).&lt;/li&gt;
  &lt;li&gt;Chuyển đổi thành thạo giữa số mẫu, thời lượng (giây) và kích thước byte.&lt;/li&gt;
  &lt;li&gt;Xử lý bố cục mono/stereo đúng cách trước khi đưa vào mô hình khử nhiễu mono.&lt;/li&gt;
  &lt;li&gt;Giải thích sự sai lệch đồng hồ thiết bị và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext.sampleRate&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Đối chiếu yêu cầu định dạng với đường tích hợp WebRTC / Mezon công khai.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Đọc tệp dữ liệu thô: giải mã chuỗi byte theo định dạng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt; LE mono ở 16 kHz&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–25&lt;/td&gt;
      &lt;td&gt;Định dạng mã hóa, thứ tự byte (endian), thang chuẩn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float&lt;/code&gt; Full Scale và hiện tượng cắt đỉnh (clipping)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;25–40&lt;/td&gt;
      &lt;td&gt;Bố cục kênh (interleaved/planar) và quy tắc gộp kênh (downmix)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;40–52&lt;/td&gt;
      &lt;td&gt;Đồng hồ lấy mẫu và vị trí đặt bộ lấy mẫu lại trong đồ thị xử lý&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/sampling-nyquist.png&quot; alt=&quot;Lấy mẫu 8 kHz: sine 1 kHz là duy nhất, sine 7 kHz rơi đúng các mẫu đó và alias thành 1 kHz&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Với (f_s=8\,\mathrm{kHz}), tần số gập là 4 kHz, nên âm 7 kHz và âm 1 kHz tạo ra cùng một dãy mẫu.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;pcm&quot;&gt;PCM&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;PCM&lt;/strong&gt; (pulse-code modulation) biểu diễn tín hiệu bằng chuỗi giá trị biên độ lấy mẫu cách đều nhau theo thời gian.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Định dạng&lt;/th&gt;
      &lt;th&gt;Miền giá trị&lt;/th&gt;
      &lt;th&gt;Ghi chú&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt;)&lt;/td&gt;
      &lt;td&gt;([-32768,32767])&lt;/td&gt;
      &lt;td&gt;Phổ biến trong WebRTC, tệp WAV; cần lưu ý thứ tự byte (endian)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Thường trong ([-1,1]) FS&lt;/td&gt;
      &lt;td&gt;Chuẩn của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioBuffer&lt;/code&gt; trong Web Audio&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int32&lt;/code&gt; / 24-bit trong container&lt;/td&gt;
      &lt;td&gt;Ít dùng trên nhánh xử lý thời gian thực&lt;/td&gt;
      &lt;td&gt;Nên chuyển đổi một lần ở biên hệ thống&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

\[x_{f32} \approx \frac{x_{s16}}{32768}\]

&lt;p&gt;Một số thư viện chia cho 32767. Hãy thống nhất một quy ước ở biên đồ thị và tránh trộn lẫn hai công thức trong cùng pipeline STFT. Tín hiệu đã bị cắt đỉnh (clip) ngay từ driver không đơn thuần là “tiếng nói to”: đó là méo phi tuyến cứng tạo ra các họa âm rơi vào đúng vùng bin của phụ âm xát. Nên chừa vài dB khoảng dự trữ (headroom) trước khi đưa tín hiệu vào bộ khử nhiễu.&lt;/p&gt;

&lt;h3 id=&quot;thời-gian-số-mẫu-và-kích-thước-byte&quot;&gt;Thời gian, số mẫu và kích thước byte&lt;/h3&gt;

\[N_{\mathrm{samples}} = t\cdot f_s,\qquad
N_{\mathrm{bytes}} = N_{\mathrm{samples}}\cdot C\cdot B\]

&lt;p&gt;Trong đó (C) là số kênh và (B) là số byte trên mỗi mẫu (2 với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt;, 4 với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; Một đoạn 20 ms ở 48 kHz, stereo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt; có kích thước (0.02\cdot48000\cdot2\cdot2=3840) byte. Đoạn 20 ms mono &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; cũng có đúng 3840 byte — cùng kích thước bộ đệm nhưng khác hoàn toàn bố cục dữ liệu; nếu chỉ kiểm tra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;byteLength&lt;/code&gt;, cả hai đều vượt qua. Một quantum 128 mẫu của Web Audio kéo dài (2.67\,\mathrm{ms}) ở 48 kHz và (8\,\mathrm{ms}) ở 16 kHz, không phải “10 ms”.&lt;/p&gt;

&lt;h3 id=&quot;tần-số-nyquist-và-lý-do-16-khz-không-phải-phép-giảm-mẫu-miễn-phí&quot;&gt;Tần số Nyquist và lý do 16 kHz không phải phép giảm mẫu miễn phí&lt;/h3&gt;

&lt;p&gt;Theo định lý lấy mẫu (Oppenheim &amp;amp; Schafer), tín hiệu giới hạn băng thông với phổ triệt tiêu từ (f_s/2) trở lên mới được xác định duy nhất từ các mẫu rời rạc. Hình minh họa cho thấy trường hợp vi phạm: ở (f_s=8\,\mathrm{kHz}), ta có:&lt;/p&gt;

\[\sin(2\pi\cdot 7000\cdot n/f_s)=-\sin(2\pi\cdot 1000\cdot n/f_s).\]

&lt;p&gt;Sau khi đã lấy mẫu, cả bộ lọc Wiener, trừ phổ lẫn DeepFilterNet đều không thể tách biệt hai tần số này.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tần số lấy mẫu&lt;/th&gt;
      &lt;th&gt;Tần số Nyquist&lt;/th&gt;
      &lt;th&gt;Phạm vi thông tin giữ lại&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;8 kHz&lt;/td&gt;
      &lt;td&gt;4 kHz&lt;/td&gt;
      &lt;td&gt;Thoại băng hẹp; năng lượng phụ âm xát gần như mất hết&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;16 kHz&lt;/td&gt;
      &lt;td&gt;8 kHz&lt;/td&gt;
      &lt;td&gt;Thoại băng rộng (wideband); chuẩn cổ điển và DNS Challenge&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;48 kHz&lt;/td&gt;
      &lt;td&gt;24 kHz&lt;/td&gt;
      &lt;td&gt;Toàn băng (full-band); tần số công bố của DeepFilterNet và mặc định của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Hạ tần số từ 48 kHz xuống 16 kHz chỉ hợp lệ sau khi đã lọc thông thấp để chặn hoàn toàn phần phổ trên 8 kHz. Cách làm “lấy mỗi mẫu thứ ba” sẽ gập dải 8–24 kHz xuống 0–8 kHz; tăng mẫu lại (upsample) sau đó cũng không khôi phục được băng tần đã mất. Đường xử lý toàn băng của Mezon giữ nguyên ở 48 kHz, trừ khi bạn chủ đích chọn mô hình 16 kHz kèm bộ lọc chống aliasing.&lt;/p&gt;

&lt;h3 id=&quot;bố-cục-interleaved-và-planar&quot;&gt;Bố cục interleaved và planar&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Stereo interleaved:&lt;/strong&gt; mẫu hai kênh xen kẽ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LRLRLR...&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Planar:&lt;/strong&gt; toàn bộ kênh trái L nối tiếp bởi kênh phải R (hoặc lưu qua hai con trỏ riêng biệt)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Đưa thẳng dữ liệu stereo interleaved vào FFT mono sẽ sinh ra các tần số giả theo đúng cơ chế gập phổ ở hình minh họa, vì dãy xen kẽ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L,R,L,R&lt;/code&gt; dồn năng lượng về gần (f_s/2). Cần tách kênh hoặc gộp kênh tường minh trước khi nhân hàm cửa sổ.&lt;/p&gt;

&lt;h3 id=&quot;gộp-kênh-downmix-cho-khử-nhiễu-tiếng-nói&quot;&gt;Gộp kênh (downmix) cho khử nhiễu tiếng nói&lt;/h3&gt;

&lt;p&gt;Cần chọn một quy tắc nhất quán và ghi rõ trong tài liệu:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Trung bình cộng:&lt;/strong&gt; (m=(L+R)/2) (lưu ý trường hợp hai kênh tương quan hoặc ngược pha nhau).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chọn riêng kênh trái hoặc phải:&lt;/strong&gt; phù hợp khi biết rõ vị trí phần cứng micro của sản phẩm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Trộn theo năng lượng:&lt;/strong&gt; ít dùng trong xử lý thời gian thực.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Không nên tính trung bình sau khi đã chạy khử nhiễu độc lập trên hai kênh L và R nếu không có cơ chế xử lý không gian, vì pha giữa hai kênh sẽ bị lệch. Đặc biệt, với tín hiệu stereo ngược pha (L=-R) (thường gặp trong tín hiệu kiểm thử hoặc một số cấu hình micro mid-side), phép lấy trung bình cho kết quả bằng 0 tuyệt đối — mô hình “xử lý xong” nhưng đầu ra hoàn toàn im lặng.&lt;/p&gt;

&lt;h3 id=&quot;đồng-hồ-lấy-mẫu&quot;&gt;Đồng hồ lấy mẫu&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext.sampleRate&lt;/code&gt; trên trình duyệt có thể là 44100 Hz, 48000 Hz hoặc giá trị khác, còn track từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt; có thể đã qua bước lấy mẫu lại của trình duyệt. Hãy luôn &lt;strong&gt;đọc trực tiếp&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt; thay vì gán cứng, và đặt một bộ lấy mẫu lại chất lượng tốt ở biên khối khử nhiễu để đưa về đúng tần số lấy mẫu của mô hình.&lt;/p&gt;

&lt;p&gt;Tần số 44.1 kHz là bẫy phổ biến trên các DAC tiêu dùng. Nếu dữ liệu 44.1 kHz bị gắn nhãn nhầm là 48 kHz, toàn bộ phổ sẽ bị dịch theo tỷ lệ (44100/48000\approx 0.919), khiến các họa âm rơi sai băng ERB. Giải pháp đúng là đọc tần số lấy mẫu thực của context và lấy mẫu lại đúng một lần.&lt;/p&gt;

&lt;h3 id=&quot;kỳ-vọng-định-dạng-của-mezon--webrtc-thông-tin-công-khai&quot;&gt;Kỳ vọng định dạng của Mezon / WebRTC (thông tin công khai)&lt;/h3&gt;

&lt;p&gt;Tích hợp trên trình duyệt thường nhận luồng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Float32&lt;/code&gt; từ Web Audio, phổ biến ở 48 kHz và ở dạng mono sau khi downmix. DeepFilterNet được công bố ở cấu hình toàn băng 48 kHz (&lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;). Khi triển khai thực tế, luôn đối chiếu README hiện hành của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; thay vì đóng cứng giả định từ bài học.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Một giây âm thanh mono &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; ở 16 kHz chiếm (16000\cdot4=64000) byte. Một đoạn 10 ms mono &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt; ở 16 kHz chiếm (0.010\cdot16000\cdot2=320) byte, tương đương 160 mẫu — đây là kích thước hop cổ điển, khác với quantum 128 mẫu.&lt;/p&gt;

&lt;p&gt;Các mẫu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt; sát ngưỡng ±32767 dễ sinh họa âm méo mà bộ khử nhiễu có thể nhận nhầm là tiếng nói hoặc nhiễu; do đó nên giữ khoảng dự trữ biên độ trước khối NS.&lt;/p&gt;

&lt;p&gt;Nếu 960 khung stereo interleaved ở 48 kHz bị đọc nhầm thành 960 mẫu mono, hệ thống sẽ xử lý 10 ms dữ liệu L/R xen kẽ như thể đó là 20 ms tín hiệu mono. Lưu ý rằng 960 mẫu ở 48 kHz đúng bằng độ dài cửa sổ phân tích của DeepFilterNet — chỉ cần sai bước nhảy (stride) một lần sẽ làm lệch toàn bộ các hop kế tiếp.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Mặc định thứ tự byte luôn là little-endian (LE) khi đọc tệp thô.&lt;/li&gt;
  &lt;li&gt;Để giá trị &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float&lt;/code&gt; vượt ngoài đoạn ([-1,1]) sau xử lý, gây méo tín hiệu ở đầu ra (sink).&lt;/li&gt;
  &lt;li&gt;Gán cứng tần số lấy mẫu 48 kHz trong mã nguồn.&lt;/li&gt;
  &lt;li&gt;Đầu vào stereo bị cắt bỏ ngầm một nửa bộ đệm do tính sai kích thước.&lt;/li&gt;
  &lt;li&gt;Nhầm phần tiêu đề (header) của tệp WAV với dữ liệu PCM thô từ callback.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Kiểm chứng sóng sin 7 kHz lấy mẫu ở 8 kHz trùng khớp với sóng sin 1 kHz đảo dấu, đồng thời tính lại hai kích thước bộ đệm phổ biến.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8000&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.004&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 4 ms, cùng ý với hình
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s7&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;alias_err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s7&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;max |s7 - (-s1)|&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alias_err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nbytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channels&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bytes_per_sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channels&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bytes_per_sample&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;20 ms stereo s16 @ 48 kHz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nbytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.020&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;10 ms mono s16 @ 16 kHz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nbytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.010&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alias_err&lt;/code&gt; cỡ (10^{-14}) (xấp xỉ 0), còn hai kích thước bộ đệm lần lượt là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3840&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;320&lt;/code&gt; byte.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;linspace&lt;/code&gt; khiến điểm cuối bị lệch hoặc trùng sẽ đẩy sai số alias từ mức làm tròn số lên (O(1)); quên nhân số kênh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;channels&lt;/code&gt; hoặc dùng nhầm 4 byte cho &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt; sẽ cho ra 7680 hoặc 640 và gây lệch kích thước giữa WAV với worklet; nếu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alias_err&lt;/code&gt; ra khoảng 2, nghĩa là bạn đã so &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s7&lt;/code&gt; với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s1&lt;/code&gt; mà quên dấu trừ của phép gập pha — giá trị mẫu trùng khớp về độ lớn nhưng ngược dấu, đó chính là aliasing.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Tính số byte của đoạn âm thanh 10 ms mono &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt; ở 16 kHz.&lt;/li&gt;
  &lt;li&gt;Viết mã giả (pseudocode) gộp kênh stereo interleaved sang mono bằng trung bình cộng.&lt;/li&gt;
  &lt;li&gt;Giải thích vì sao tín hiệu stereo ngược pha ((L=-R)) gây sự cố với phép gộp kênh trung bình.&lt;/li&gt;
  &lt;li&gt;Nêu ba vị trí trên đường truyền WebRTC nơi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt; có thể khác nhau.&lt;/li&gt;
  &lt;li&gt;Chuyển đổi giá trị &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt; bằng −16000 sang chuẩn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float&lt;/code&gt; Full Scale bằng phép chia cho 32768.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Số mẫu là (0.010\times16000=160), nhân với 2 byte mỗi mẫu cho 320 byte.&lt;/li&gt;
  &lt;li&gt;Đọc từng cặp mẫu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(L, R)&lt;/code&gt; đã giải mã và xuất &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(L+R)/2&lt;/code&gt; ở kiểu số thực; không tính trung bình trực tiếp trên từng byte thô.&lt;/li&gt;
  &lt;li&gt;Trung bình của hai kênh ngược pha bằng 0 tại mọi mẫu, khiến mô hình chỉ nhận được khoảng lặng.&lt;/li&gt;
  &lt;li&gt;Thiết bị thu (micro/driver), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; của trình duyệt và tần số lấy mẫu gốc của mô hình (48 kHz, 16 kHz hoặc 44.1 kHz).&lt;/li&gt;
  &lt;li&gt;(-16000/32768\approx -0.488).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer, &lt;em&gt;Discrete-Time Signal Processing&lt;/em&gt; — lấy mẫu và tần số Nyquist.&lt;/li&gt;
  &lt;li&gt;Tài liệu Web Audio về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioBuffer&lt;/code&gt; và bộ đệm trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletProcessor&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Ràng buộc media track của WebRTC và tài liệu định dạng PCM.&lt;/li&gt;
  &lt;li&gt;Cấu hình định khung toàn băng của DeepFilterNet: &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;, &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;github.com/Rikorose/DeepFilterNet&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://xiph.org/video/vid2.shtml&quot;&gt;Xiph.Org Video Presentations: Digital Show &amp;amp; Tell&lt;/a&gt; — Xiph.Org, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video chính thức của Xiph.Org về PCM, độ sâu bit và khôi phục tín hiệu — nên xem trước khi gỡ lỗi tensor 16 kHz nhận từ callback 48 kHz.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=KuaannH5pnM&quot;&gt;Aliasing and the Sampling Theorem Simplified&lt;/a&gt; — Barry Van Veen, tiếng Anh. Cơ chế gập Nyquist minh họa rõ dạng lỗi âm thầm khi một kênh bị lấy mẫu lại sai tần số.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-07 Checklist bẫy Fourier cho kỹ sư</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_07_fourier_pitfalls_checklist/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_07_fourier_pitfalls_checklist</id>
   <content type="html">&lt;p&gt;Khi bộ khử nhiễu cho ra âm thanh lỗi, phản xạ phổ biến của nhiều kỹ sư là đem mô hình đi huấn luyện lại ngay lập tức. Bài học này cung cấp danh mục kiểm tra Fourier/STFT trước khi triển khai — bao gồm đơn vị, hàm cửa sổ, tính đối xứng, hệ số chuẩn hóa, lấy mẫu lại và DC/Nyquist — để chỉ nghi ngờ mạng nơ-ron sau khi đã loại trừ toàn bộ lỗi pipeline.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/sampling-nyquist.png&quot; alt=&quot;Các bản sao phổ khi lấy mẫu — hình đứng sau một bin Nyquist bị gán sai&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Bẫy phổ biến nhất trong bài học này là sai trục tần số: Nyquist luôn ở (f_s/2), và một bin lệch đi một chỉ số đã tương ứng với giá trị Hz khác chứ không phải sai số làm tròn.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Một trong những lỗi âm thanh khó chịu nhất khi lập trình DSP không phải là chương trình bị crash, mà là chương trình &lt;em&gt;vẫn chạy êm ru và phát ra tiếng&lt;/em&gt; — nhưng tiếng bị méo nhẹ, âm lượng sai đúng 6 dB, hoặc xuất hiện tiếng “tách tách” mơ hồ ở rìa mỗi khung! Thủ phạm hầu như luôn nằm trong một nhóm nhỏ các &lt;strong&gt;bẫy Fourier kinh điển&lt;/strong&gt;: nhầm tích chập vòng với tích chập tuyến tính, quên hệ số 2 của phổ một phía &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt;, hay quên chuẩn hóa năng lượng cửa sổ.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-ba-nhóm-bẫy-fourier-kinh-điển-mà-kỹ-sư-âm-thanh-hay-vấp-phải-là-gì&quot;&gt;Kiến thức cần nhớ: Ba nhóm bẫy Fourier kinh điển mà kỹ sư âm thanh hay vấp phải là gì?&lt;/h2&gt;

&lt;h3 id=&quot;1-tích-chập-vòng-circular-vs-tích-chập-tuyến-tính-linear-convolution&quot;&gt;1. Tích chập vòng (Circular) vs. Tích chập tuyến tính (Linear Convolution)&lt;/h3&gt;
&lt;p&gt;Định lý tích chập của DFT nói rằng nhân hai phổ cỡ \(N\) tương đương &lt;strong&gt;tích chập vòng modulo \(N\)&lt;/strong&gt; trong miền thời gian! Nếu tín hiệu dài \(L\) và bộ lọc dài \(M\), kết quả tích chập tuyến tính thực sự dài \(L + M - 1\) mẫu. Nếu bạn dùng FFT cỡ \(N &amp;lt; L + M - 1\) mà không đệm đủ số 0, phần đuôi thừa sẽ &lt;strong&gt;quấn ngược vòng lên đầu khung&lt;/strong&gt; gây chồng lấp miền thời gian (time-domain aliasing)!&lt;/p&gt;

&lt;h3 id=&quot;2-quy-ước-chuẩn-hóa-và-phổ-một-phía-rfft-vs-fft&quot;&gt;2. Quy ước chuẩn hóa và Phổ một phía (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; vs. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fft&lt;/code&gt;)&lt;/h3&gt;
&lt;p&gt;Giữa NumPy, PyTorch, SciPy và RustFFT, quy ước chia \(1/N\) có thể đặt ở IFFT, chia \(1/\sqrt{N}\) cho cả hai chiều, hoặc không chia ở đâu cả! Ngoài ra, khi dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; cho tín hiệu thực để tính phổ công suất (PSD), mỗi bin trung gian \(1 \le k &amp;lt; N/2\) đại diện cho cả tần số dương \(+f_k\) lẫn âm \(-f_k\) nên năng lượng phải nhân &lt;strong&gt;hệ số 2&lt;/strong&gt; (trừ bin DC \(k=0\) và Nyquist \(k=N/2\)).&lt;/p&gt;

&lt;h3 id=&quot;3-đứt-gãy-pha-phase-discontinuity-và-méo-ranh-giới-khung&quot;&gt;3. Đứt gãy pha (Phase Discontinuity) và Méo ranh giới khung&lt;/h3&gt;
&lt;p&gt;Thay đổi biên độ hoặc pha đột ngột giữa hai khung liên tiếp mà không dùng cửa sổ mượt và kỹ thuật chồng lấp (Overlap-Add / Overlap-Save) sẽ tạo ra bước nhảy biên độ ở ranh giới mỗi 10 ms — tai người lập tức nghe thành tiếng rè 100 Hz cực kỳ khó chịu!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-bắt-tại-trận-lỗi-tích-chập-vòng-quấn-ngược-với-dãy-3-mẫu&quot;&gt;Giải thích: tự tay bắt tại trận lỗi “Tích chập vòng quấn ngược” với dãy 3 mẫu&lt;/h3&gt;

&lt;p&gt;Xét tín hiệu \(x = [1, 1, 1]\) (độ dài \(L = 3\)) lọc qua bộ lọc \(h = [1, 1, 1]\) (độ dài \(M = 3\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Kết quả tích chập tuyến tính ĐÚNG&lt;/strong&gt; (độ dài phải là \(L + M - 1 = 3 + 3 - 1 = \mathbf{5\text{ mẫu}}\)):
\(y_{\text{linear}} = [1,\ 2,\ 3,\ 2,\ 1].\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sai lầm khi dùng FFT cỡ \(N = 4\) (quên đệm đủ lên \(N \ge 5\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Đệm thành \(x_4 = [1, 1, 1, 0]\) và \(h_4 = [1, 1, 1, 0]\), rồi tính \(\text{IFFT}_4(\text{FFT}_4(x_4) \cdot \text{FFT}_4(h_4))\).&lt;/li&gt;
      &lt;li&gt;Phần tử thứ 5 (chỉ số \(n = 4\), giá trị \(1\)) không có chỗ chứa trong mảng 4 phần tử nên bị &lt;strong&gt;quấn modulo 4&lt;/strong&gt; về chỉ số \(4 \bmod 4 = \mathbf{0}\) và cộng đè lên \(y[0] = 1\)!&lt;/li&gt;
      &lt;li&gt;Kết quả sai thu được là:
\(y_{\text{circular}, 4} = [1 + 1,\ 2,\ 3,\ 2] = [\mathbf{2},\ 2,\ 3,\ 2] \neq [1,\ 2,\ 3,\ 2,\ 1]!\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cách sửa duy nhất đúng:&lt;/strong&gt; Luôn đệm số 0 cho cả \(x\) và \(h\) tới kích thước \(N_{\text{FFT}} \ge L + M - 1\) (ở đây là \(N = 5\), hoặc lũy thừa 2 gần nhất \(N = 8\)) thì tích chập vòng mới trùng khít 100% với tích chập tuyến tính!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chẩn đoán các lỗi biến đổi Fourier và DFT phổ biến trong pipeline âm thanh.&lt;/li&gt;
  &lt;li&gt;Xác thực đơn vị tần số (Hz, chỉ số bin và tần số chuẩn hóa).&lt;/li&gt;
  &lt;li&gt;Áp dụng danh mục kiểm tra có hệ thống trước khi quy kết lỗi cho mô hình mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;Nhận diện lỗi cửa sổ/COLA và lỗi đối xứng liên hợp bằng cả thính giác lẫn kiểm thử tự động.&lt;/li&gt;
  &lt;li&gt;Áp dụng danh mục kiểm tra vào quy trình gỡ lỗi kiểu Mezon/DeepFilterNet mà không suy đoán chi tiết nội bộ.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–8&lt;/td&gt;
      &lt;td&gt;Tình huống thực tế (war story): từ triệu chứng → suy đoán sai → nguyên nhân gốc&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;8–30&lt;/td&gt;
      &lt;td&gt;Rà soát toàn bộ danh mục kiểm tra kèm thí nghiệm phân tích&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;30–45&lt;/td&gt;
      &lt;td&gt;Các bài kiểm thử đơn vị (unit test) cần duy trì trong kho mã&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;45–55&lt;/td&gt;
      &lt;td&gt;Trình tự gỡ lỗi cho Mezon/DeepFilterNet&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;55–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;danh-mục-kiểm-tra-chính&quot;&gt;Danh mục kiểm tra chính&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính chính xác của tần số lấy mẫu&lt;/strong&gt; — tần số PCM phải khớp với tần số mô hình (hoặc đi qua bộ lấy mẫu lại có tài liệu rõ ràng); bắt buộc lọc chống aliasing khi giảm mẫu; không gán cứng 48 kHz.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đơn vị trục tần số&lt;/strong&gt; — tuân thủ (f=k f_s/N); mọi bộ lọc định nghĩa theo Hz phải dùng đúng (f_s).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chuẩn hóa FFT và Parseval&lt;/strong&gt; — đối chiếu tài liệu thư viện; phép biến đổi khứ hồi STFT → ISTFT phải bảo toàn năng lượng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cửa sổ và điều kiện COLA&lt;/strong&gt; — cặp cửa sổ phân tích/tổng hợp cùng bước nhảy hop phải thỏa điều kiện COLA và khớp cấu hình huấn luyện.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đối xứng liên hợp và đóng gói phổ&lt;/strong&gt; — đầu vào của iFFT tín hiệu thực phải có tính đối xứng Hermitian; phần ảo tại DC và Nyquist xấp xỉ 0.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bố cục kênh (channel layout)&lt;/strong&gt; — phân biệt xen kẽ (interleaved) với tách mặt phẳng (planar) và xác định rõ quy tắc gộp kênh stereo → mono.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính toán bước nhảy hop và độ trễ&lt;/strong&gt; — ghi nhận rõ độ trễ look-ahead (ms), bộ đệm vòng và khoảng khởi động (warmup) nhất quán khi đo chỉ số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thành phần DC và nhiễu tần số cực thấp&lt;/strong&gt; — dùng bộ chặn DC nếu micro có độ lệch tĩnh; không kỳ vọng mô hình khử nhiễu tự xử lý phần DC này.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;Hiển thị thang dB&lt;/strong&gt; — dùng nhất quán (20\log_{10}&lt;/td&gt;
          &lt;td&gt;X&lt;/td&gt;
          &lt;td&gt;) cho biên độ và giới hạn cận dưới để tránh (\log 0).&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bộ lấy mẫu lại và miền đánh giá&lt;/strong&gt; — tính chỉ số chất lượng ở tần số lấy mẫu đã thống nhất; tránh lấy mẫu lại hai lần trong bài kiểm thử A/B.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;minh-họa-số-cho-hai-bẫy-điển-hình&quot;&gt;Minh họa số cho hai bẫy điển hình&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Bin Nyquist là một chỉ số nguyên phụ thuộc vào (f_s).&lt;/strong&gt; Với (N) chẵn, bin Nyquist nằm tại (k=N/2), tương ứng tần số (f_s/2). Xét (N=512) và (f_s=16\,\mathrm{kHz}): bin đúng là (k=256) tại (8000\,\mathrm{Hz}). Nếu lệch một chỉ số xuống (k=255), tần số tương ứng chỉ là (255\times 16000/512=7968.75\,\mathrm{Hz}); một mặt nạ đặt ngưỡng ở bin 255 sẽ bỏ sót bin Nyquist, trong khi bài test viết sơ sài (“một bin cao nào đó có thay đổi”) vẫn báo đạt. Nghiêm trọng hơn, nếu gán nhầm mảng 16 kHz sang nhãn 48 kHz thì bin 256 sẽ bị hiểu là (256\times 48000/512=24000\,\mathrm{Hz}) — bạn tưởng đang xử lý vùng gần 24 kHz trong khi tín hiệu thực chỉ chứa năng lượng đến 8 kHz. Khi đó, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt; sẽ điều chỉnh độ sâu khử trên một trục tần số sai. Hãy kiểm tra tần số lấy mẫu và bảng ánh xạ bin trước khi động vào &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tráo đổi phần thực và phần ảo.&lt;/strong&gt; Phổ DFT của một khung PCM thực luôn thỏa tính đối xứng liên hợp (X[k]=X^*[(N-k)\bmod N]), đồng thời bin DC và bin Nyquist đều là số thực thuần. Nếu vô tình tráo phần thực và phần ảo, đẳng thức đối xứng sẽ bị phá vỡ với sai số cùng bậc độ lớn của phổ. Khi tính biến đổi nghịch, kết quả xuất hiện phần ảo khác không; việc ép lấy phần thực rồi tiếp tục sẽ che giấu lỗi thành âm thanh đục và lệch pha. Phần Mini-lab dưới đây dùng câu lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assert&lt;/code&gt; để bắt cả hai lỗi này.&lt;/p&gt;

&lt;h2 id=&quot;kịch-bản-gỡ-lỗi-nhanh&quot;&gt;Kịch bản gỡ lỗi nhanh&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Tiếng rung giật (warble) chu kỳ 100 Hz → kiểm tra hop 10 ms và lỗi điều kiện COLA.&lt;/li&gt;
  &lt;li&gt;“Mô hình cắt mất phụ âm” → kiểm tra tín hiệu thực có năng lượng trên 6 kHz hay không và đối chiếu ánh xạ bin giữa 48 kHz với 16 kHz.&lt;/li&gt;
  &lt;li&gt;Chỉ số SI-SDR tốt nhưng người nghe phàn nàn → kiểm tra lỗi pha và nhiễu nhạc (Chương 08).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;các-bài-kiểm-thử-đơn-vị-nên-duy-trì&quot;&gt;Các bài kiểm thử đơn vị nên duy trì&lt;/h2&gt;

&lt;p&gt;Cần giữ sẵn các bài test tự động cho: khứ hồi xung đơn vị (impulse round-trip), đẳng thức Parseval cho hàm bọc FFT, lấy mẫu lại sóng sin không sinh thành phần alias giả, và kiểm chứng độ dài/biên độ sau bước gộp kênh mono.&lt;/p&gt;

&lt;h2 id=&quot;trình-tự-gỡ-lỗi-cho-mezon--deepfilternet-thông-tin-công-khai&quot;&gt;Trình tự gỡ lỗi cho Mezon / DeepFilterNet (thông tin công khai)&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Xác minh tần số lấy mẫu và số kênh theo README của gói hoặc model card.&lt;/li&gt;
  &lt;li&gt;Kiểm tra khâu truyền khung (callback và bộ đệm vòng) — nội dung Chương 05.&lt;/li&gt;
  &lt;li&gt;Rà soát độ chính xác của STFT theo danh mục kiểm tra của bài này.&lt;/li&gt;
  &lt;li&gt;Sau cùng mới thay đổi biến thể mô hình hoặc tùy chọn của gói npm.&lt;/li&gt;
  &lt;li&gt;Khi lập luận về thuật toán, trích dẫn các bài báo DeepFilterNet công khai; không suy đoán cấu trúc đồ thị nội bộ chưa công bố của Mezon.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Thay đổi đồng thời ba yếu tố (tần số lấy mẫu, bước nhảy hop và mô hình).&lt;/li&gt;
  &lt;li&gt;Kết luận chất lượng chỉ dựa trên một đoạn demo quán cà phê.&lt;/li&gt;
  &lt;li&gt;Vô tình đưa checkpoint không nhân quả vào wrapper streaming.&lt;/li&gt;
  &lt;li&gt;Bỏ qua phân vị đuôi p99 của thời gian xử lý mỗi hop.&lt;/li&gt;
  &lt;li&gt;Cố “khắc phục” tiếng rung giật bằng cách tăng cường độ khử nhiễu.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Viết câu lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assert&lt;/code&gt; để phát hiện phổ bị tráo phần thực/ảo và chứng minh bin Nyquist bị lệch một chỉ số sẽ không còn là 8 kHz.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hermitian_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mirror&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;conj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mirror&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;swapped&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;real&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nyquist_hz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;return &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_fft&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;//&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_fft&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;good=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;hermitian_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;swapped=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;hermitian_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;swapped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;nyquist=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nyquist_hz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;off_by_one=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;//&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hermitian_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-8&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hermitian_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;swapped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-3&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nyquist_hz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;8000.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;good=0.000e+00&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swapped=3.400&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nyquist=8000.00&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;off_by_one=7968.75&lt;/code&gt;, cả ba câu lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assert&lt;/code&gt; đều đạt. Nếu bỏ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assert&lt;/code&gt; kiểm tra phổ bị tráo, dữ liệu hỏng sẽ lọt qua; nếu đổi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nyquist_hz&lt;/code&gt; thành (N/2-1), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assert&lt;/code&gt; cuối sẽ báo lỗi ngay lập tức.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Kiểm tra tính đối xứng bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.allclose(X, np.conj(X[::-1]))&lt;/code&gt; mà quên rằng chỉ số 0 phải ánh xạ vào chính nó (công thức chuẩn dùng ((N-k)\bmod N) để bin DC khớp với DC); hoặc chấp nhận 7968.75 Hz là “đủ gần Nyquist” trong bài kiểm thử đơn vị.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chọn ba mục trong danh mục kiểm tra chính và đặt tên bài kiểm thử đơn vị tương ứng cho từng mục.&lt;/li&gt;
  &lt;li&gt;Với hop 5 ms, lỗi COLA sẽ tạo ra tiếng rung giật ở tần số xấp xỉ bao nhiêu Hz?&lt;/li&gt;
  &lt;li&gt;Vì sao dùng sai giá trị (f_s) trong công thức (f=kf_s/N) lại tạo ra triệu chứng giống như mô hình kém chất lượng?&lt;/li&gt;
  &lt;li&gt;Xây dựng mẫu báo cáo sự cố 6 bước cho lỗi “khử nhiễu nghe kém trên Chrome”.&lt;/li&gt;
  &lt;li&gt;Mục nào trong danh mục kiểm tra sẽ phát hiện lỗi đưa dữ liệu stereo xen kẽ (interleaved) trực tiếp vào FFT mono?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Đặt tên bài kiểm thử gắn trực tiếp với lỗi cần bắt: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test_cola_impulse_roundtrip&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test_parseval_scale&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test_downmix_length&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Lỗi COLA ở hop 5 ms sẽ gây điều biến biên độ ở tần số gần (1/0.005=200\,\mathrm{Hz}).&lt;/li&gt;
  &lt;li&gt;Mọi nhãn tần số của bin đều tỷ lệ thuận với (f_s); một mô hình 16 kHz khi nhận dữ liệu 48 kHz sẽ hoạt động như bộ lọc thông thấp dù trọng số mô hình không hề thay đổi.&lt;/li&gt;
  &lt;li&gt;Ghi nhận theo thứ tự: tần số lấy mẫu, số kênh, bước nhảy hop (ms), phân vị p95 của thời gian callback, kết quả kiểm tra xung COLA, rồi mới tới mã định danh mô hình; mỗi lần thử nghiệm chỉ thay đổi đúng một biến.&lt;/li&gt;
  &lt;li&gt;Mục bố cục kênh (mục 6): tín hiệu stereo xen kẽ nếu bị đọc như mono sẽ trộn mẫu kênh trái và kênh phải thành các mẫu thời gian liên tiếp.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — hàm cửa sổ, hệ số tỷ lệ và các bẫy phổ biến của DFT.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588), DeepFilterNet2 (arXiv:2205.05474), DeepFilterNet3 (arXiv:2305.08227) — cấu hình STFT và lưu ý thời gian thực; Julius O. Smith, https://ccrma.stanford.edu/~jos/mdft/, cho các tính chất đối xứng DFT được kiểm chứng bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assert&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Tài liệu đo hiệu năng (profiling) của ONNX Runtime và trình duyệt để tách riêng chi phí STFT với chi phí mạng nơ-ron.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=4ip-4ai6kN8&quot;&gt;11: Spectral Analysis Part 1 - Intro to Neural Computation&lt;/a&gt; — MIT OpenCourseWare, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Nhấn mạnh rằng gọi FFT rất dễ sai ngầm; nên xem các cảnh báo về trục tần số, hệ số chuẩn hóa và hàm cửa sổ trước khi nghĩ đến việc huấn luyện lại mô hình.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=tCWU9C-LdJQ&quot;&gt;Lecture 13: Spectral Leakage, Windowing, with Examples of Hanning and Hamming Windows&lt;/a&gt; — Bahga Lab IIT Delhi, tiếng Anh. So sánh búp phụ của cửa sổ Hann với cửa sổ chữ nhật, minh họa phần rò phổ trong danh mục kiểm tra.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://xiph.org/video/vid2.shtml&quot;&gt;Xiph.Org Video Presentations: Digital Show &amp;amp; Tell&lt;/a&gt; — Xiph.Org, tiếng Anh. Video chính thức của Xiph.Org về lấy mẫu và tái tạo tín hiệu, hữu ích khi cần phân biệt lỗi lệch trục tần số do tần số lấy mẫu với lỗi của mạng nơ-ron.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-06 FFT trong audio khung thời gian thực</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_06_fft_realtime_framing/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_06_fft_realtime_framing</id>
   <content type="html">&lt;p&gt;Giáo trình FFT thường dừng lại ở phân tích độ phức tạp, còn kỹ thuật sản phẩm bắt đầu từ audio callback. Bài học này đặt FFT vào trong vòng lặp STFT streaming: số hop mỗi giây, độ trễ thuật toán, tái sử dụng bộ đệm và tình huống thực tế theo hướng DeepFilterNet.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/stft-ola.png&quot; alt=&quot;Các khung phân tích chồng nhau, mỗi khung một FFT có cửa sổ, cộng lại phía tổng hợp&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. FFT thời gian thực vận hành theo nhịp đồng hồ: nhận một hop mới, tính biến đổi trên khung đã áp cửa sổ, rồi tổng hợp ra ngoài bằng overlap-add. Hệ cơ sở vẫn là DFT, còn lịch trình là bước nhảy hop.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Thuật toán FFT trong sách giáo khoa luôn giả định bạn có sẵn cả một mảng tín hiệu đứng yên trên bàn. Nhưng tiếng nói của con người không bao giờ đứng yên: chỉ trong 100 mili giây, miệng bạn đã kịp chuyển từ phụ âm xát cao tần /s/ sang nguyên âm trầm ấm /a/. Muốn đưa FFT vào cuộc gọi thoại thời gian thực, kỹ sư phải &lt;strong&gt;cắt dòng âm thanh liên tục thành từng lát khung (frame)&lt;/strong&gt; gối đầu lên nhau — đủ ngắn để giọng nói coi như “gần dừng” (quasi-stationary) bên trong mỗi lát, nhưng đủ dài để phân tách được các vạch tần số!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-chia-khung-fft-thời-gian-thực-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Chia khung FFT Thời gian thực đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-giả-thiết-gần-dừng-quasi-stationarity-của-tiếng-nói&quot;&gt;1. Giả thiết Gần dừng (Quasi-Stationarity) của Tiếng nói&lt;/h3&gt;
&lt;p&gt;Dây thanh và khoang miệng con người chuyển động theo quán tính cơ học, nên đặc tính phổ của tiếng nói thay đổi chậm trong cửa sổ &lt;strong&gt;10–30 ms&lt;/strong&gt;. Đó là lý do hầu hết hệ thống xử lý thoại (WebRTC, Opus, DeepFilterNet) đều chọn độ dài khung chuẩn quanh mốc &lt;strong&gt;20 ms&lt;/strong&gt; và bước nhảy (hop) &lt;strong&gt;10 ms&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;2-đánh-đổi-độ-phân-giải-thời-gian--tần-số-delta-f--f_s--n&quot;&gt;2. Đánh đổi Độ phân giải Thời gian – Tần số (\(\Delta f = f_s / N\))&lt;/h3&gt;
&lt;p&gt;Chọn kích thước FFT \(N\) quyết định trực tiếp khoảng cách giữa hai bin tần số liền kề: \(\Delta f = \frac{f_s}{N}\). Khung càng dài thì \(\Delta f\) càng mịn (nhìn rõ hài âm), nhưng độ trễ càng lớn và các tiếng nổ ngắn (như gõ bàn phím) càng bị nhòe theo thời gian.&lt;/p&gt;

&lt;h3 id=&quot;3-tính-tương-thích-phần-cứng-và-mixed-radix-fft&quot;&gt;3. Tính tương thích phần cứng và Mixed-Radix FFT&lt;/h3&gt;
&lt;p&gt;Ở tốc độ chuẩn 48 kHz, khung 20 ms tương ứng đúng \(N = 960\text{ mẫu}\) — không phải lũy thừa của 2! Thay vì ép đệm 0 lên \(1\,024\) (làm lệch lưới tần số), các thư viện hiện đại (RustFFT, PocketFFT) phân tích thừa số \(960 = 2^6 \cdot 3 \cdot 5\) để chạy &lt;strong&gt;mixed-radix FFT&lt;/strong&gt; gần nhanh ngang radix-2 thuần!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-kiểm-tra-bộ-thông-số-khung-thực-chiến-của-deepfilternet&quot;&gt;Giải thích: tự tay kiểm tra bộ thông số khung thực chiến của DeepFilterNet&lt;/h3&gt;

&lt;p&gt;Hãy kiểm chứng trọn bộ thông số cốt lõi của hệ thống khử nhiễu 48 kHz bằng những phép chia sơ cấp:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Độ dài khung &amp;amp; Bước nhảy:&lt;/strong&gt; Với \(f_s = 48\,000\text{ Hz}\), chọn khung \(N = 960\text{ mẫu}\) và bước nhảy \(H = 480\text{ mẫu}\):
    &lt;ul&gt;
      &lt;li&gt;Thời lượng khung: \(T_{\text{frame}} = \frac{960}{48\,000} = \mathbf{20\text{ ms}}\).&lt;/li&gt;
      &lt;li&gt;Bước nhảy (tốc độ cập nhật): \(T_{\text{hop}} = \frac{480}{48\,000} = \mathbf{10\text{ ms}}\) (chồng lấp \(50\%\), tức \(100\text{ khung/giây}\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lưới tần số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt;:&lt;/strong&gt; Vì tín hiệu micro là số thực, số bin phổ độc lập chỉ là:
\(K = \frac{N}{2} + 1 = \frac{960}{2} + 1 = \mathbf{481\text{ bin}} \quad (k = 0, 1, \dots, 480).\)
Khoảng cách mỗi bin đúng tròn trịa: \(\Delta f = \frac{48\,000}{960} = \mathbf{50\text{ Hz/bin}}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tra cứu nhanh tần số của bất kỳ bin nào:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Bin \(k = 0 \to 0\text{ Hz}\) (DC); Bin \(k = 1 \to 50\text{ Hz}\) (đúng tần số ù điện lưới 50 Hz!).&lt;/li&gt;
      &lt;li&gt;Bin \(k = 20 \to 20 \times 50 = \mathbf{1\,000\text{ Hz}}\); Bin \(k = 480 \to \mathbf{24\,000\text{ Hz}}\) (tần số Nyquist).&lt;/li&gt;
      &lt;li&gt;Lưu lượng dữ liệu phổ cần xử lý: \(100\text{ khung/giây} \times 481\text{ bin} = 48\,100\) số phức/giây — cực gọn cho mạng nơ-ron chạy thời gian thực!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Lập ngân sách chi phí FFT trong phạm vi một callback hoặc quantum của AudioWorklet.&lt;/li&gt;
  &lt;li&gt;Liên hệ giữa bước nhảy hop, kích thước FFT (N) điểm và độ trễ thuật toán.&lt;/li&gt;
  &lt;li&gt;Tính toán số lượng phép FFT mỗi giây cho các cấu hình thoại phổ biến.&lt;/li&gt;
  &lt;li&gt;Nhận diện tình huống chi phí FFT chiếm tỷ trọng lớn trong RTF so với mạng nơ-ron.&lt;/li&gt;
  &lt;li&gt;Nắm các nguyên tắc đảm bảo ổn định cho luồng streaming: cấp phát sẵn bộ đệm, tái sử dụng FFT plan và duy trì liên tục trạng thái OLA.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Nhìn STFT streaming như một chuỗi các phép FFT có cửa sổ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–25&lt;/td&gt;
      &lt;td&gt;Các con số cốt lõi: số hop/giây, số FFT/giây và công thức độ trễ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;25–40&lt;/td&gt;
      &lt;td&gt;Ràng buộc trên audio thread, bộ đệm vòng (ring buffer) và bất đẳng thức tránh underrun&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;40–52&lt;/td&gt;
      &lt;td&gt;Nghiên cứu tình huống: cấu hình STFT của DeepFilterNet (theo bài báo công khai)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;p&gt;Ở mỗi bước nhảy hop, pipeline thực hiện tuần tự: gom đủ (L) mẫu → nhân hàm cửa sổ → tính FFT → xử lý tăng cường tiếng nói → tính iFFT → cộng chồng lấp (OLA). Các trạng thái bắt buộc phải duy trì qua từng hop gồm bộ đệm OLA, trạng thái ẩn của RNN/DF và bộ theo dõi nền nhiễu.&lt;/p&gt;

\[T_{\mathrm{hop}}=\frac{R}{f_s},\qquad \mathrm{FFTs/s}\approx 2\cdot\frac{f_s}{R}\]

&lt;p&gt;(tính trên mỗi kênh). Trên trình duyệt, một quantum AudioWorklet thường dài 128 mẫu (khoảng 2.67 ms ở 48 kHz) — &lt;strong&gt;không&lt;/strong&gt; trùng với hop STFT 5–10 ms, do đó hệ thống bắt buộc phải có bộ đệm vòng (ring buffer).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phân tích đầy đủ một cấu hình mẫu.&lt;/strong&gt; Xét cấu hình (f_s=48\,\mathrm{kHz}) (tần số toàn băng mặc định của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0), (L=960) và (R=480). Đây là cặp tham số minh họa cho bài học, không khẳng định đồ thị nội bộ chưa công bố của Mezon sử dụng chính xác cặp giá trị này.&lt;/p&gt;

\[T_{\mathrm{hop}}=\frac{480}{48000}=10\,\mathrm{ms},\qquad
\frac{f_s}{R}=100\ \mathrm{hop/s},\qquad
T_{\mathrm{win}}=\frac{960}{48000}=20\,\mathrm{ms}.\]

&lt;p&gt;Tỷ lệ chồng lấp là ((L-R)/L=1/2). Do hệ thống nhân quả chưa thể thực hiện phép FFT phân tích đầu tiên cho đến khi gom đủ 960 mẫu, độ trễ đệm trước phép biến đổi đầu tiên là 20 ms — đây là độ trễ thuật toán của &lt;em&gt;việc lấp đầy cửa sổ phân tích&lt;/em&gt;. Việc xuất mẫu sớm hơn hoặc giữ thêm một hop nhìn trước (look-ahead) sẽ làm thay đổi hằng số độ trễ này nhưng không làm thay đổi tốc độ hop. Với hai phép biến đổi ở mỗi hop (thuận và nghịch), hệ thống thực hiện (200) phép FFT mỗi giây cho mỗi kênh, trong ngân sách thời gian thực tế (wall-clock) là 10 ms cho mỗi hop. Một quantum AudioWorklet 128 mẫu ở 48 kHz chỉ bằng (128/480=0.267) hop, nên cần (480/128=3.75) quantum để tích lũy đủ một hop (R) và (960/128=7.5) quantum để lấp đầy một cửa sổ (L). &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; cần được cấp dữ liệu đúng theo bước nhảy hop ghi trên model card; phép đếm trên giúp đối chiếu giữa thông số mô hình và nhịp callback thực tế.&lt;/p&gt;

&lt;p&gt;Để tránh vỡ tiếng, hệ thống phải duy trì (T_{\mathrm{proc}}(\ell)&amp;lt;T_{\mathrm{hop}}) gần như ở mọi khung, có chừa biên độ cho dao động (jitter). Các bài báo thuộc họ DeepFilterNet mô tả phần tiền xử lý STFT, đặc trưng thang ERB và kỹ thuật deep filtering trên phổ phức hướng tới chạy thời gian thực. Khi đọc tài liệu ở Chương 04, hãy trích xuất các thông số (f_s), kích thước cửa sổ/FFT, hop và tuyên bố về tính nhân quả rồi đối chiếu trực tiếp với các công thức trên trước khi tích hợp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;, tránh tự suy đoán các hằng số STFT chưa được công bố của Mezon.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Ở tần số 48 kHz với (R=480) (10 ms), tốc độ xử lý là 100 hop/giây, tương đương khoảng 200 lượt biến đổi/giây/kênh. Với kích thước quantum 128 mẫu ở 48 kHz, cần khoảng 3.75 quantum để gom đủ một hop 10 ms, do đó bắt buộc phải dùng bộ đệm tích lũy.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Đánh đồng quantum của AudioWorklet với bước nhảy hop của mô hình.&lt;/li&gt;
  &lt;li&gt;Chỉ đo độ trễ trên luồng chính (main thread).&lt;/li&gt;
  &lt;li&gt;Đặt lại trạng thái OLA sau mỗi lần gọi callback.&lt;/li&gt;
  &lt;li&gt;Chạy FFT cho cả hai kênh stereo trong khi mô hình chỉ nhận đầu vào mono.&lt;/li&gt;
  &lt;li&gt;Quên cộng chi phí iFFT và OLA vào ngân sách thời gian của hop.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Tính số hop mỗi giây và độ trễ lấp đầy cửa sổ phân tích cho cấu hình (L=960), (R=480) ở 48 kHz.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;960&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;480&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;win_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hops_per_s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ffts_per_s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hops_per_s&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hops_per_s=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hops_per_s&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; hop_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; win_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;win_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ffts_per_s=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ffts_per_s&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; algo_delay_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;win_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hops_per_s=100 hop_ms=10.0 win_ms=20.0&lt;/code&gt;, tiếp theo là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffts_per_s=200 algo_delay_ms=20.0&lt;/code&gt;. Giá trị độ trễ in ra là thời gian gom đủ một cửa sổ phân tích, không phải tổng độ trễ đầu–cuối của toàn bộ sản phẩm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Gán độ trễ thuật toán bằng đúng bước nhảy hop (10 ms) mà quên thời gian lấp đầy cửa sổ; chỉ đếm một phép FFT mỗi hop trong khi phép biến đổi nghịch cũng tiêu tốn thời gian; hoặc áp máy móc cặp (L, R) này lên một model card đang quy định cấu hình khác.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Với (f_s=16\,\mathrm{kHz}) và (R=256), hãy tính độ dài hop (ms) và số hop mỗi giây.&lt;/li&gt;
  &lt;li&gt;Tính ngân sách thời gian xử lý (T_{\mathrm{proc}}) để đạt RTF 0.4 với cấu hình hop ở câu 1.&lt;/li&gt;
  &lt;li&gt;Với quantum 128 mẫu ở 48 kHz, cần bao nhiêu quantum để gom đủ một hop 10 ms?&lt;/li&gt;
  &lt;li&gt;Liệt kê các trạng thái cần được bảo toàn giữa các hop liên tiếp.&lt;/li&gt;
  &lt;li&gt;Phác thảo kế hoạch đo hiệu năng (profiling) tách riêng ba công đoạn: STFT, suy luận neural và ISTFT.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Độ dài hop là (256/16000=16\,\mathrm{ms}), tương ứng (1000/16=62.5) hop/giây.&lt;/li&gt;
  &lt;li&gt;Với RTF 0.4 trên hop 16 ms, thời gian xử lý tối đa là (6.4\,\mathrm{ms}).&lt;/li&gt;
  &lt;li&gt;Một hop 10 ms ở 48 kHz gồm 480 mẫu, tương ứng (480/128=3.75) quantum. Sau khi gom 4 quantum sẽ dư ra 0.25 quantum (32 mẫu) cần được giữ lại trong bộ đệm vòng cho hop tiếp theo.&lt;/li&gt;
  &lt;li&gt;Phần đuôi bộ đệm OLA, cửa sổ phân tích, bộ đếm hop và các trạng thái ẩn hồi tiếp bên trong bộ khử nhiễu.&lt;/li&gt;
  &lt;li&gt;Đặt ba bộ đo thời gian tách biệt cho FFT phân tích, lượt suy luận mạng nơ-ron và iFFT + OLA, sau đó báo cáo phân vị p95 trên ít nhất vài nghìn hop.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588), DeepFilterNet2 (arXiv:2205.05474), DeepFilterNet3 (arXiv:2305.08227) — các mục về cấu hình STFT và vận hành thời gian thực. Kho mã tham chiếu: https://github.com/Rikorose/DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;Tài liệu MDN về &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletProcessor&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Tổng quan WebRTC APM (cơ chế xử lý theo khối khung).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-Yxj3yfvY-4&quot;&gt;Short-Time Fourier Transform Explained Easily&lt;/a&gt; — Valerio Velardo - The Sound of AI, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày bước chuyển từ một phép DFT cho toàn tệp sang tính DFT trên từng khung — đúng vị trí mà callback thời gian thực gọi FFT.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=NA0TwPsECUQ&quot;&gt;Short-time Fourier Transform and the Spectogram&lt;/a&gt; — Barry Van Veen, tiếng Anh. Bài giảng xử lý tín hiệu về STFT và phổ đồ tạo thành, giúp hình dung chuỗi FFT theo từng khung đặt trên nhịp thời gian thực.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Quan sát khối STFT ở đầu bộ khử nhiễu nhân quả: ở đây FFT là một phần ngân sách của hop chứ không chỉ là một công thức độ phức tạp trong sách giáo khoa.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-05 Thuật toán FFT và độ phức tạp</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_05_fft_radix2_complexity/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_05_fft_radix2_complexity</id>
   <content type="html">&lt;p&gt;Tính DFT trực tiếp có độ phức tạp (O(N^2)), quá nặng để chạy ở mỗi bước nhảy hop trên CPU điện thoại hay bên trong AudioWorklet cho thoại thời gian thực. Bài học này giải thích cơ chế giúp FFT đạt độ phức tạp (O(N\log N)), vai trò của radix-2 và những ràng buộc thực tế khi triển khai trên stack ORT, WASM hoặc native.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/dft-basis.png&quot; alt=&quot;Cùng các tone cơ sở DFT mà FFT vẫn tính; thuật toán chỉ đổi lịch phép tính&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Thuật toán radix-2 vẫn tính tích trong với chính các thành phần tần số cơ sở này; nó chỉ sắp xếp lại thứ tự phép tính nên kết quả khớp với DFT trực tiếp trong giới hạn sai số làm tròn.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Năm 1965, James Cooley và John Tukey công bố một bài báo dài chưa tới 5 trang giấy nhưng đã làm thay đổi vĩnh viễn lịch sử xử lý tín hiệu, viễn thông, hình ảnh y khoa và cả âm thanh thời gian thực: &lt;strong&gt;thuật toán Biến đổi Fourier Nhanh (FFT)&lt;/strong&gt;. (Thú vị thay, các nhà sử học sau này phát hiện Carl Friedrich Gauss đã tự nghĩ ra đúng thuật toán chia để trị này từ năm 1805 khi tính quỹ đạo tiểu hành tinh bằng tay!)&lt;/p&gt;

&lt;p&gt;Nếu nhân trực tiếp ma trận DFT cỡ \(N \times N\) tốn \(O(N^2)\) phép tính, thì FFT tận dụng tính đối xứng tuần hoàn của các căn đơn vị \(W_N^k = e^{-j2\pi k/N}\) để hạ độ phức tạp xuống &lt;strong&gt;\(O(N \log_2 N)\)&lt;/strong&gt;. Khác biệt đó không phải là tối ưu vài phần trăm — ở kích thước khung âm thanh tiêu chuẩn \(N = 1\,024\), nó là ranh giới giữa một thuật toán chạy mượt mà trên chiếc đồng hồ thông minh với một thuật toán chậm hơn gấp &lt;strong&gt;200 lần&lt;/strong&gt;!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-thuật-toán-fft-radix-2-hoạt-động-nhờ-ba-ý-tưởng-thuật-toán-nào&quot;&gt;Kiến thức cần nhớ: Thuật toán FFT Radix-2 hoạt động nhờ ba ý tưởng thuật toán nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-chia-để-trị-divide-and-conquer-theo-chỉ-số-chẵn--lẻ&quot;&gt;1. Chia để trị (Divide and Conquer) theo chỉ số Chẵn – Lẻ&lt;/h3&gt;
&lt;p&gt;Tách tổng DFT độ dài \(N\) thành hai nửa: nửa các mẫu ở chỉ số &lt;strong&gt;chẵn&lt;/strong&gt; \(x[2m]\) (DFT là \(E[k]\)) và nửa ở chỉ số &lt;strong&gt;lẻ&lt;/strong&gt; \(x[2m+1]\) (DFT là \(O[k]\)). Nhờ tính chất \(W_N^{2mk} = W_{N/2}^{mk}\), bài toán cỡ \(N\) lập tức tách thành &lt;strong&gt;hai bài toán DFT giống hệt nhau cỡ \(N/2\)&lt;/strong&gt;!&lt;/p&gt;

&lt;h3 id=&quot;2-phép-ghép-cánh-bướm-butterfly-và-tận-dụng-đối-xứng-w_nk--n2---w_nk&quot;&gt;2. Phép ghép Cánh bướm (Butterfly) và Tận dụng đối xứng \(W_N^{k + N/2} = -W_N^k\)&lt;/h3&gt;
&lt;p&gt;Điều kỳ diệu nằm ở khâu ghép: chỉ cần tính tích \(T_k = W_N^k O[k]\) &lt;strong&gt;đúng một lần&lt;/strong&gt;, ta thu ngay &lt;strong&gt;cả hai&lt;/strong&gt; đầu ra đối diện nhau chỉ bằng 1 phép cộng và 1 phép trừ:&lt;/p&gt;

\[X[k] = E[k] + W_N^k O[k], \qquad X[k + N/2] = E[k] - W_N^k O[k].\]

&lt;p&gt;Cấu trúc cộng–trừ đan chéo ấy trông giống đôi cánh bướm, tạo nên tên gọi &lt;strong&gt;sơ đồ cánh bướm (butterfly diagram)&lt;/strong&gt; kinh điển.&lt;/p&gt;

&lt;h3 id=&quot;3-phương-trình-đệ-quy-độ-phức-tạp-và-hiệu-năng-phần-cứng-thực-tế&quot;&gt;3. Phương trình đệ quy độ phức tạp và Hiệu năng phần cứng thực tế&lt;/h3&gt;
&lt;p&gt;Phương trình đệ quy \(T(N) = 2T(N/2) + O(N)\) có nghiệm \(T(N) = O(N \log_2 N)\) (chính xác là \(\frac{N}{2}\log_2 N\) phép nhân phức). Trong triển khai thực chiến (FFTW, RustFFT trong DeepFilterNet), tốc độ còn phụ thuộc mạnh vào kích thước không phải lũy thừa 2 (như \(N = 960 = 2^6 \cdot 3 \cdot 5\) dùng FFT hỗn hợp &lt;em&gt;mixed-radix&lt;/em&gt;), căn chỉnh bộ nhớ cache và tập lệnh vector SIMD!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-chạy-trọn-vẹn-fft-radix-2-cho-n--4-và-so-sánh-tốc-độ-tại-n--1024&quot;&gt;Giải thích: tự tay chạy trọn vẹn FFT Radix-2 cho \(N = 4\) và so sánh tốc độ tại \(N = 1\,024\)&lt;/h3&gt;

&lt;p&gt;Hãy tự tay tính FFT cho tín hiệu 4 mẫu \(x = [1,\ 2,\ 3,\ 4]\) (với \(W_4^0 = 1,\ W_4^1 = -j\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Bước 1 — Tách chẵn / lẻ và tính hai DFT độ dài 2 (chỉ cộng và trừ!):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Nhánh chẵn \(x_{\text{chẵn}} = [x[0], x[2]] = [1, 3]\):
\(E[0] = 1 + 3 = 4, \qquad E[1] = 1 - 3 = -2.\)&lt;/li&gt;
      &lt;li&gt;Nhánh lẻ \(x_{\text{lẻ}} = [x[1], x[3]] = [2, 4]\):
\(O[0] = 2 + 4 = 6, \qquad O[1] = 2 - 4 = -2.\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bước 2 — Ghép 2 cánh bướm (\(k = 0\) và \(k = 1\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Cánh bướm \(k = 0\) (hệ số \(W_4^0 = 1\)):
\(X[0] = E[0] + 1\cdot O[0] = 4 + 6 = \mathbf{10}, \qquad X[2] = E[0] - 1\cdot O[0] = 4 - 6 = \mathbf{-2}.\)&lt;/li&gt;
      &lt;li&gt;Cánh bướm \(k = 1\) (hệ số \(W_4^1 = -j\)):
\(X[1] = E[1] + (-j)O[1] = -2 + 2j, \qquad X[3] = E[1] - (-j)O[1] = -2 - 2j.\)&lt;/li&gt;
      &lt;li&gt;Kết quả: \(X = [10,\ -2+2j,\ -2,\ -2-2j]\) — khớp 100% với tính DFT trực tiếp!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;So sánh số phép nhân phức ở kích thước khung âm thanh \(N = 1\,024\) (\(2^{10}\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;DFT trực tiếp:&lt;/strong&gt; \(N^2 = 1\,024^2 = \mathbf{1\,048\,576}\) phép nhân phức.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;FFT Radix-2:&lt;/strong&gt; \(\frac{N}{2}\log_2 N = 512 \times 10 = \mathbf{5\,120}\) phép nhân phức — &lt;strong&gt;nhanh hơn đúng 204.8 lần&lt;/strong&gt;! Ở \(N = 4\,096\), khoảng cách vọt lên gần &lt;strong&gt;700 lần&lt;/strong&gt;!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;So sánh độ phức tạp (O(N\log N)) của FFT với (O(N^2)) của DFT trực tiếp.&lt;/li&gt;
  &lt;li&gt;Mô tả ý tưởng chia để trị của thuật toán Cooley–Tukey radix-2 ở mức trực quan.&lt;/li&gt;
  &lt;li&gt;Nêu các ràng buộc thực tế: kích thước lũy thừa của 2, tối ưu real-FFT và tái sử dụng kế hoạch tính (FFT plan).&lt;/li&gt;
  &lt;li&gt;Ước lượng chi phí của FFT so với phần mạng nơ-ron trong ngân sách một hop.&lt;/li&gt;
  &lt;li&gt;Phân biệt việc gọi toán tử FFT bên trong đồ thị ONNX với việc tự cài đặt trên WASM.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;So sánh số phép tính với (N=1024) giữa DFT trực tiếp và FFT&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–28&lt;/td&gt;
      &lt;td&gt;Cơ chế cánh bướm (butterfly) radix-2 và nhận diện phép đảo bit (bit-reversal)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Real-FFT và xử lý kích thước (N) không phải lũy thừa của 2 (mixed-radix / đệm 0)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Hệ sinh thái thư viện: native, WASM SIMD và toán tử FFT trong ORT&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;p&gt;Trong DFT trực tiếp, mỗi đầu ra trong số (N) đầu ra cần (N) phép nhân-cộng phức (MAC), dẫn đến độ phức tạp (\Theta(N^2)). Với (N=1024), mỗi lượt biến đổi tiêu tốn xấp xỉ (10^6) phép MAC; khi nhân thêm cả chiều thuận lẫn chiều nghịch theo số hop mỗi giây, chi phí này sẽ nhanh chóng gây quá tải trên thiết bị di động khi chạy kèm mạng nơ-ron.&lt;/p&gt;

&lt;p&gt;Thuật toán Cooley–Tukey tách dãy đầu vào thành hai nửa chỉ số chẵn và lẻ:&lt;/p&gt;

\[X[k]=E[k]+e^{-j2\pi k/N}O[k],\qquad
X[k+N/2]=E[k]-e^{-j2\pi k/N}O[k].\]

&lt;p&gt;Chi phí tính toán thỏa hệ thức truy hồi (T(N)=2T(N/2)+\Theta(N)). Khai triển qua (\log_2 N) tầng đệ quy, mỗi tầng tiêu tốn (\Theta(N)), nên tổng độ phức tạp là (T(N)=\Theta(N\log N)). Tại (N=1024), ta có (\log_2 N=10) và tỷ số hạng bậc cao nhất là (N^2/(N\log_2 N)=102.4), tương đương giảm khoảng một trăm lần số phép nhân-cộng trước cả khi tính đến tối ưu real-FFT (bỏ nửa phổ đối xứng thừa). Điều này không có nghĩa thời gian chạy thực tế (wall-clock) lúc nào cũng giảm đúng 102 lần, bởi hằng số ẩn, tập lệnh SIMD và chi phí khung gọi của Python đều làm thay đổi tỷ số đo — phần Mini-lab sẽ minh họa bậc chênh lệch này. Các thừa số xoay (twiddle factor) thực hiện phép quay pha trong cấu trúc cánh bướm (butterfly). Trong sản phẩm thực tế, FFT plan cần được khởi tạo &lt;strong&gt;một lần&lt;/strong&gt;, &lt;strong&gt;không cấp phát bộ nhớ&lt;/strong&gt; trên audio thread và ưu tiên bật SIMD (Chương 06).&lt;/p&gt;

&lt;h3 id=&quot;video-ngắn-vì-sao-fft-tính-nhanh&quot;&gt;Video ngắn: vì sao FFT tính nhanh&lt;/h3&gt;

&lt;p&gt;Đoạn video ngắn của MathDiagram đặt câu hỏi vì sao FFT có thể tính biến đổi Fourier nhanh đến vậy. Nên xem ngay sau phần tách chẵn/lẻ ở trên.&lt;/p&gt;

&lt;div class=&quot;video-embed&quot; style=&quot;text-align:center;margin:1em 0;&quot;&gt;&lt;iframe src=&quot;https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Freel%2F4039621483008687&amp;amp;show_text=false&amp;amp;width=315&amp;amp;height=560&quot; width=&quot;315&quot; height=&quot;560&quot; style=&quot;border:none;overflow:hidden;max-width:100%;&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;true&quot; allow=&quot;autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;

&lt;p&gt;Nếu video không tải được, &lt;a href=&quot;https://www.facebook.com/reel/4039621483008687&quot;&gt;xem trên Facebook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Vì tín hiệu PCM tiếng nói là số thực, real-FFT giúp giảm gần một nửa khối lượng tính toán phức nhờ tính đối xứng Hermitian của phổ. Cửa sổ 960 mẫu (20 ms ở tần số 48 kHz toàn băng của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;) phân tích được thành (960=2^6\cdot 3\cdot 5), do đó thuật toán mixed-radix xử lý trực tiếp rất hiệu quả mà không bắt buộc phải chọn lũy thừa của 2. Đệm số 0 lên 1024 vẫn khả thi nhưng sẽ làm dịch tâm các bin tần số — cần &lt;strong&gt;khớp đúng cấu hình huấn luyện&lt;/strong&gt;. Việc ép dùng plan dài 256 trên khung 48 kHz chỉ vì nghĩ “FFT phải là lũy thừa của 2” thực chất là thay đổi (N), không phải tăng tốc cùng một phép DFT.&lt;/p&gt;

&lt;p&gt;Với các bộ khử nhiễu cổ điển gọn nhẹ, FFT có thể chiếm phần lớn thời gian xử lý. Với nhóm mô hình như DeepFilterNet, phép nhân ma trận thường chiếm tỷ trọng chính, nhưng chi phí FFT vẫn đáng kể ở tần số lấy mẫu cao, hop ngắn hoặc trên các bản biên dịch không có SIMD.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Với hop 10 ms, hệ thống thực hiện 100 cặp FFT + iFFT mỗi giây trên mỗi kênh. Ở (N=512), mỗi lượt tốn vài nghìn phép MAC, tương đương xấp xỉ (10^6) MAC/giây cho riêng phần FFT — con số này khá nhỏ so với mạng tích chập–hồi tiếp nhiều lớp, nhưng sẽ tăng nhanh nếu giảm hop xuống 2.5 ms và tăng (N=1024).&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Khởi tạo lại FFT plan ở mỗi hop.&lt;/li&gt;
  &lt;li&gt;Gọi API FFT phức trên dữ liệu thực, bỏ qua lợi thế đóng gói của real-FFT.&lt;/li&gt;
  &lt;li&gt;Coi độ phức tạp (O(N\log N)) đồng nghĩa với “chi phí không đáng kể”.&lt;/li&gt;
  &lt;li&gt;Tự ý tăng (N) lên lũy thừa của 2 gần nhất mà không kiểm tra độ tương thích với mô hình.&lt;/li&gt;
  &lt;li&gt;So sánh thời gian chạy giữa bản DEBUG với bản Release hoặc bản thiếu SIMD.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; So sánh thời gian tính DFT trực tiếp bằng tích ma trận với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.fft.fft&lt;/code&gt; ở (N=256) và (N=1024). Đây là phép kiểm tra bậc độ lớn, không phải benchmark chính thức.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;naive_dft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;empty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dtype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;complex128&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;default_rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1024&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;standard_normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;perf_counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Xn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;naive_dft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t_naive&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;perf_counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t0&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;perf_counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Xf&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t_fft&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;perf_counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t0&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Xn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Xf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;naive_s=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t_naive&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fft_s=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t_fft&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;err=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Sai số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;err&lt;/code&gt; nhỏ hơn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-8&lt;/code&gt; ở cả hai kích thước (thường khoảng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-12&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-11&lt;/code&gt;). Thời gian chạy của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;naive_dft&lt;/code&gt; ở (N=1024) lớn hơn nhiều lần so với (N=256), cùng bậc với hệ số (4^2=16) của (N^2) (dù chi phí vòng lặp làm tỷ số thực tế nhỏ hơn một chút). Trong khi đó, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.fft.fft&lt;/code&gt; vẫn hoàn tất dưới 1 ms; tại (N=1024), cách tính trực tiếp chậm hơn hàng trăm lần. Giá trị giây tuyệt đối sẽ khác nhau tùy phần cứng.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Dùng một lần đo đơn lẻ làm chỉ số RTF công bố; quên rằng vòng lặp “naive” ở trên vẫn dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.dot&lt;/code&gt; đã vector hóa cho từng bin thay vì hai vòng lặp Python thuần; hoặc so sánh một lần gọi FFT đã khởi động sẵn với lần chạy trực tiếp đầu tiên rồi coi tỷ số đó là hằng số lý thuyết của Cooley–Tukey.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Tính số tầng (\log_2 1024) và so sánh sơ bộ (N\log_2 N) với (N^2).&lt;/li&gt;
  &lt;li&gt;Giải thích vì sao real-FFT giúp giảm khoảng một nửa khối lượng tính toán.&lt;/li&gt;
  &lt;li&gt;Nêu ba lưu ý kỹ thuật quan trọng khi chạy FFT trên AudioWorklet/WASM.&lt;/li&gt;
  &lt;li&gt;Nếu giảm một nửa bước nhảy hop trong khi giữ nguyên (N), tải CPU của phần FFT thay đổi như thế nào?&lt;/li&gt;
  &lt;li&gt;Nêu một lý do cần tránh đệm số 0 tùy tiện khi dùng phần tiền xử lý STFT của mô hình đã huấn luyện sẵn.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Số tầng là (\log_2 1024=10). Ta có (N\log_2 N=10240) so với (N^2=1048576), chênh lệch khoảng 102 lần ở hạng bậc cao nhất.&lt;/li&gt;
  &lt;li&gt;Phổ của tín hiệu thực có tính đối xứng liên hợp nên thuật toán đóng gói bỏ qua nửa số bin dư thừa; điều này giảm khối lượng tính toán đi gần một nửa chứ không làm thay đổi lớp độ phức tạp tiệm cận.&lt;/li&gt;
  &lt;li&gt;Không cấp phát bộ nhớ trên audio thread, tái sử dụng FFT plan và biên dịch với hỗ trợ SIMD (đồng thời tránh tính lại bảng twiddle ở mỗi hop).&lt;/li&gt;
  &lt;li&gt;Số lượng hop mỗi giây tăng gấp đôi, nên khối lượng tính toán FFT mỗi giây cũng tăng gần gấp đôi khi (N) không đổi.&lt;/li&gt;
  &lt;li&gt;Đệm số 0 làm dịch tâm các bin tần số và thay đổi cấu trúc lưới mà trọng số đã học, khiến mô hình đọc sai giá trị Hz ứng với từng chỉ số bin.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Tổng quan họ thuật toán Cooley–Tukey và mục FFT trong sách Oppenheim &amp;amp; Schafer.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Mathematics of the DFT&lt;/em&gt;, https://ccrma.stanford.edu/~jos/mdft/ — khẳng định FFT là thuật toán tính nhanh DFT chứ không phải một phép biến đổi khác.&lt;/li&gt;
  &lt;li&gt;Tài liệu toán tử STFT/DFT của ONNX khi triển khai với ONNX Runtime (ORT).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=E8HeD-MUrjY&quot;&gt;The Fast Fourier Transform (FFT)&lt;/a&gt; — Steve Brunton, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Đối chiếu phép nhân ma trận DFT dày đặc với phép phân tích thừa số của FFT, minh họa trực tiếp lập luận (O(N\log N)) trong bài.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=toj_IoCQE-4&quot;&gt;The Fast Fourier Transform Algorithm&lt;/a&gt; — Steve Brunton, tiếng Anh. Trình bày chi tiết bước tách radix-2 thành hai biến đổi nửa kích thước kèm thừa số xoay twiddle — nguồn gốc của hệ số logarit.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xw4voABxU5c&quot;&gt;Computing the DFT Matrix&lt;/a&gt; — Steve Brunton, tiếng Anh. Dùng làm mốc đối chiếu (O(N^2)) mà FFT phải giữ nguyên kết quả số học.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-04 DFT như ma trận / cơ sở trực chuẩn</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_04_dft_as_matrix_and_basis/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_04_dft_as_matrix_and_basis</id>
   <content type="html">&lt;p&gt;Gỡ lỗi các hệ thống khử nhiễu đòi hỏi nhìn nhận DFT như một phép đổi cơ sở bảo toàn năng lượng (theo định lý Parseval), thay vì chỉ là một biểu đồ màu trực quan. Bài học này kết nối tính trực giao, dạng ma trận, cách đánh chỉ số bin và hiện tượng rò phổ.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/dft-basis.png&quot; alt=&quot;Tám tone cơ sở DFT: hệ tọa độ của biến đổi dài N&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Mỗi hàng của ma trận DFT là một thành phần tần số phức như minh họa; mỗi bin phổ là tích trong giữa khung tín hiệu và hàng tương ứng.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Rất nhiều lập trình viên dùng hàm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.fft.rfft(x)&lt;/code&gt; hằng ngày như một chiếc hộp đen bí ẩn, để rồi bối rối khi thấy năng lượng tín hiệu trước và sau khi biến đổi lệch nhau đúng hệ số \(N\), hoặc không hiểu tại sao sóng sin lệch nửa bin lại bị nhòe sang cả chục bin xung quanh! Khoảnh khắc mọi sương mù tan biến là khi bạn nhìn &lt;strong&gt;DFT dưới con mắt đại số tuyến tính năm nhất&lt;/strong&gt;: DFT không có gì huyền bí — nó đơn giản là &lt;strong&gt;phép nhân một vectơ \(\mathbf{x} \in \mathbb{C}^N\) với một ma trận quay unita \(\mathbf{F}\) cỡ \(N \times N\)&lt;/strong&gt;!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-góc-nhìn-đại-số-tuyến-tính-của-dft-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Góc nhìn Đại số tuyến tính của DFT đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-ma-trận-dft-mathbff-và-hệ-cơ-sở-trực-chuẩn&quot;&gt;1. Ma trận DFT \(\mathbf{F}\) và Hệ cơ sở Trực chuẩn&lt;/h3&gt;
&lt;p&gt;Phần tử ở hàng \(k\), cột \(n\) của ma trận DFT chuẩn hóa (unitary) là \(\frac{1}{\sqrt{N}} e^{-j 2\pi k n / N}\). Mỗi hàng là một vectơ sóng đơn sắc có độ dài bằng \(1\), và &lt;strong&gt;hai hàng khác nhau bất kỳ luôn vuông góc tuyệt đối với nhau&lt;/strong&gt; (\(\langle \mathbf{f}_k, \mathbf{f}_m\rangle = \delta_{km}\)). Vì vậy, ma trận \(\mathbf{F}_{\text{unitary}}\) thỏa mãn \(\mathbf{F}^{-1} = \mathbf{F}^H\) (nghịch đảo chính là chuyển vị liên hợp!).&lt;/p&gt;

&lt;h3 id=&quot;2-định-lý-parseval--phép-bảo-toàn-năng-lượng-dùng-để-kiểm-lỗi-debug&quot;&gt;2. Định lý Parseval — Phép bảo toàn năng lượng dùng để kiểm lỗi (Debug)&lt;/h3&gt;
&lt;p&gt;Trong không gian Euclid, quay một mũi tên quanh gốc tọa độ không bao giờ làm thay đổi chiều dài của nó. Tương tự, vì DFT là phép quay trong \(\mathbb{C}^N\), tổng bình phương năng lượng được bảo toàn tuyệt đối (với quy ước phổ biến không chia \(\sqrt{N}\) của NumPy/SciPy):&lt;/p&gt;

\[\sum_{n=0}^{N-1} |x[n]|^2 \;=\; \frac{1}{N} \sum_{k=0}^{N-1} |X[k]|^2.\]

&lt;p&gt;Mọi kỹ sư âm thanh chuyên nghiệp đều viết unit test kiểm tra đẳng thức Parseval này để bắt ngay lỗi quên hệ số chuẩn hóa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1/N&lt;/code&gt; trong pipeline STFT/ISTFT!&lt;/p&gt;

&lt;h3 id=&quot;3-quy-đổi-bin--tần-số-hz-và-đối-xứng-liên-hợp-cho-tín-hiệu-thực&quot;&gt;3. Quy đổi Bin ↔ Tần số Hz và Đối xứng Liên hợp cho Tín hiệu Thực&lt;/h3&gt;
&lt;p&gt;Với tốc độ mẫu \(f_s\) và kích thước \(N\), bin thứ \(k\) ứng với tần số \(f_k = k \cdot \frac{f_s}{N}\) (ví dụ \(f_s = 48\text{ kHz},\ N = 960 \implies\) mỗi bin cách nhau đúng \(50\text{ Hz}\)). Khi đầu vào \(x[n]\) là &lt;strong&gt;số thực&lt;/strong&gt; (mọi âm thanh micro đều là số thực!), phổ DFT luôn có tính đối xứng liên hợp \(X[N - k] = \overline{X[k]}\), nên ta chỉ cần tính và lưu nửa đầu \(N/2 + 1\) bin (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt;) là đủ khôi phục 100%!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-nhân-ma-trận-dft-4times-4-và-kiểm-chứng-định-lý-parseval&quot;&gt;Giải thích: tự tay nhân ma trận DFT \(4\times 4\) và kiểm chứng Định lý Parseval&lt;/h3&gt;

&lt;p&gt;Với \(N = 4\), đặt \(W_4 = e^{-j2\pi/4} = -j\). Ma trận DFT (quy ước chuẩn NumPy chưa chia \(\sqrt{4}\)) chỉ chứa 4 số cực đơn giản \(\{1, -1, j, -j\}\):&lt;/p&gt;

\[\mathbf{F}_4 = \begin{pmatrix}
1 &amp;amp; 1 &amp;amp; 1 &amp;amp; 1 \\
1 &amp;amp; -j &amp;amp; -1 &amp;amp; j \\
1 &amp;amp; -1 &amp;amp; 1 &amp;amp; -1 \\
1 &amp;amp; j &amp;amp; -1 &amp;amp; -j
\end{pmatrix}.\]

&lt;p&gt;Hãy tự tay nhân \(\mathbf{F}_4\) với tín hiệu cosin thực \(\mathbf{x} = [1,\ 0,\ -1,\ 0]^T\) (tức \(x[n] = \cos(\frac{\pi}{2}n)\), đúng 1 chu kỳ trọn vẹn trong 4 mẫu):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhân từng hàng của \(\mathbf{F}_4\) với \(\mathbf{x}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;\(X[0] = 1(1) + 1(0) + 1(-1) + 1(0) = \mathbf{0}\) (không có thành phần DC).&lt;/li&gt;
      &lt;li&gt;\(X[1] = 1(1) + (-j)(0) + (-1)(-1) + j(0) = 1 + 1 = \mathbf{2}\) (đỉnh tần số dương \(k = 1\)!).&lt;/li&gt;
      &lt;li&gt;\(X[2] = 1(1) + (-1)(0) + 1(-1) + (-1)(0) = \mathbf{0}\) (không có thành phần Nyquist).&lt;/li&gt;
      &lt;li&gt;\(X[3] = 1(1) + j(0) + (-1)(-1) + (-j)(0) = 1 + 1 = \mathbf{2}\) (đỉnh tần số âm đối xứng \(k = 3 = N - 1\)!).
Vậy \(\mathbf{X} = [0,\ 2,\ 0,\ 2]^T\) — thấy ngay tính đối xứng liên hợp \(X[3] = \overline{X[1]} = 2\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra Định lý Parseval:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Năng lượng miền thời gian: \(E_t = 1^2 + 0^2 + (-1)^2 + 0^2 = \mathbf{2}\).&lt;/li&gt;
      &lt;li&gt;Năng lượng miền tần số (chia \(N = 4\)): \(E_f = \frac{1}{4}\bigl(0^2 + 2^2 + 0^2 + 2^2\bigr) = \frac{8}{4} = \mathbf{2}\)!
Khớp tuyệt đối \(E_t = E_f = 2\)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Hiểu DFT dưới góc nhìn phép chiếu lên hệ cơ sở hàm mũ phức.&lt;/li&gt;
  &lt;li&gt;Viết DFT ở dạng ma trận và phân biệt quy ước chuẩn hóa unitary với quy ước không chuẩn hóa.&lt;/li&gt;
  &lt;li&gt;Sử dụng phép kiểm tra năng lượng theo Parseval để xác thực pipeline STFT/ISTFT.&lt;/li&gt;
  &lt;li&gt;Chuyển đổi thành thạo giữa chỉ số bin, tần số Hz và tần số chuẩn hóa.&lt;/li&gt;
  &lt;li&gt;Dự đoán và nhận diện hiện tượng rò phổ khi tín hiệu hình sin rơi lệch bin.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Tính trực giao của hàm mũ phức và góc nhìn tích trong&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;Ma trận (\mathbf{F}), hệ số chuẩn hóa unitary và quy ước giữa các thư viện&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Quy đổi bin ↔ Hz, thành phần DC/Nyquist và tần số âm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Rò phổ khi lệch bin và thiết kế bài thực hành âm đơn + nhiễu&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập và danh mục kiểm tra&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;p&gt;Các vector cơ sở (w_k[n]=e^{j2\pi kn/N}) trực giao với nhau theo quan hệ (\langle w_k,w_\ell\rangle=N\delta_{k\ell}). Tổng cấp số nhân (\sum_{n=0}^{N-1}e^{j2\pi(k-\ell)n/N}) bằng (N) khi (k\equiv\ell\pmod N) và bằng 0 trong các trường hợp còn lại — đó chính là giá trị tích trong. Nhờ vậy, phép phân tích là (X[k]=\langle x,w_k\rangle), còn phép tổng hợp cần chia cho (N).&lt;/p&gt;

\[\mathbf{X}=\mathbf{F}\mathbf{x},\quad F_{kn}=e^{-j2\pi kn/N}\]

&lt;p&gt;Nhiều thư viện FFT áp dụng quy ước: biến đổi thuận không chia, còn biến đổi nghịch chia cho (1/N) (hoặc ngược lại) — &lt;strong&gt;lỗi hệ số tỷ lệ trong ISTFT&lt;/strong&gt; là một trong những lỗi âm thầm dễ làm hỏng chất lượng âm thanh nhất. Đặt (\mathbf{U}=\mathbf{F}/\sqrt{N}); do (\mathbf{U}) là ma trận trực chuẩn nên (|\mathbf{Ux}|=|\mathbf{x}|). Phép DFT không chuẩn hóa của NumPy thỏa (\mathbf{X}=\sqrt{N}\,\mathbf{Ux}), suy ra đẳng thức Parseval:&lt;/p&gt;

\[\sum_n|x[n]|^2=\frac{1}{N}\sum_k|X[k]|^2.\]

&lt;p&gt;Nếu bước biến đổi nghịch đã chia (N) mà khâu cộng chồng lấp OLA lại chia thêm (N) lần nữa, biên độ sóng 48 kHz toàn băng sẽ suy giảm sai lệch ở mỗi hop. Lưu ý rằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; trên &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; không kiểm tra lỗi này: tham số đó chỉ điều chỉnh mức khử nhiễu, không tự kiểm định định lý Parseval cho đoạn STFT mà bạn tự cài đặt bên ngoài.&lt;/p&gt;

\[f_k=\frac{k}{N}f_s\]

&lt;p&gt;Trong đó, (k=0) là thành phần một chiều (DC), (k=N/2) (với (N) chẵn) là tần số Nyquist, và (k&amp;gt;N/2) là vùng tần số âm của tín hiệu thực. Nếu một sóng sin không chứa đúng số nguyên chu kỳ trong khung, phép nối tuần hoàn sẽ tạo điểm gián đoạn ở biên, sinh ra các búp phụ (sidelobe) gây hiện tượng rò phổ (spectral leakage); việc áp dụng hàm cửa sổ sẽ giúp hạ búp phụ nhưng đánh đổi bằng việc nới rộng búp chính (xem Chương 02).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Ở tần số 48 kHz với (N=1024), khoảng cách giữa hai bin là (\Delta f\approx46.875\,\mathrm{Hz}). Nhiễu hệ thống HVAC quanh 100 Hz nằm gần các bin 2–3. Nếu mặt nạ chỉ triệt tiêu bin 2 mà giữ nguyên các bin 3–10 thì gần như không mang lại hiệu quả; hệ số độ lợi cần biến thiên mượt sang các bin lân cận.&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Với một đoạn nhiễu trắng phương sai đơn vị dài 256 mẫu, năng lượng miền thời gian xấp xỉ 256; tổng (\sum&lt;/td&gt;
      &lt;td&gt;X&lt;/td&gt;
      &lt;td&gt;^2\approx 65536) khi dùng DFT không chuẩn hóa, và sau khi chia cho (N=256) sẽ khớp với đẳng thức Parseval.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Xét vector (x=[1,0,-1,0]), tương ứng với (\cos(2\pi n/4)): tín hiệu hoàn thành đúng một chu kỳ trong 4 mẫu, tức rơi vào bin (k=1). Phép DFT không chuẩn hóa cho (X[1]=X[3]=2) và hai bin còn lại bằng 0. Năng lượng miền thời gian bằng 2, còn năng lượng miền tần số là ((4+4)/4=2). Bài tập 1 vẫn yêu cầu viết đầy đủ ma trận (\mathbf{F}); ví dụ này chỉ minh họa nhanh hai đỉnh phổ và định lý Parseval.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chia hệ số chuẩn hóa (1/N) hai lần liên tiếp.&lt;/li&gt;
  &lt;li&gt;Coi nửa phổ đối xứng gương như chứa thêm thông tin độc lập gấp đôi.&lt;/li&gt;
  &lt;li&gt;Chỉnh sửa một nửa phổ nhưng không cập nhật phần đối xứng liên hợp tương ứng.&lt;/li&gt;
  &lt;li&gt;So sánh trực tiếp kết quả FFT giữa các thư viện hoặc ngôn ngữ khác nhau (NumPy, FFTW…) mà không đối chiếu quy ước chuẩn hóa.&lt;/li&gt;
  &lt;li&gt;Dùng trực tiếp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|X|**2&lt;/code&gt; để ước lượng mật độ phổ công suất (PSD) mà quên chuẩn hóa theo công suất của hàm cửa sổ.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Xây dựng trực tiếp ma trận DFT dài 8 và kiểm chứng tính đối xứng liên hợp cùng đẳng thức Parseval trên một vector thực.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;F&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;outer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sym&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;conj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;energy_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;energy_freq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sym=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sym&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;time=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;energy_time&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; freq=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;energy_freq&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sym&lt;/code&gt; nhỏ hơn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-12&lt;/code&gt; (khoảng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.200e-15&lt;/code&gt;), và cả hai giá trị năng lượng đều in ra &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.462500&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Dùng dấu mũ dương (e^{+j2\pi kn/N}) rồi đem so sánh với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.fft.fft&lt;/code&gt; mà không để ý quy ước dấu (trong bài thực hành này ta không gọi FFT của NumPy; tính đối xứng và Parseval vẫn đúng với ma trận (F) đã định nghĩa); quên chia &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/ N&lt;/code&gt; trong công thức Parseval rồi “sửa chắp vá” bằng cách chia năng lượng miền thời gian; hoặc chỉnh sửa &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X[1]&lt;/code&gt; mà không cập nhật cặp liên hợp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X[7]&lt;/code&gt; rồi kỳ vọng biến đổi nghịch cho ra tín hiệu thực.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Với (N=4), hãy viết tường minh ma trận (\mathbf{F}).&lt;/li&gt;
  &lt;li&gt;Với (k=32), (f_s=16\,\mathrm{kHz}) và (N=256), bin này tương ứng với tần số bao nhiêu Hz?&lt;/li&gt;
  &lt;li&gt;Vì sao một âm đơn rơi lệch bin lại trải rộng trên nhiều bin khi dùng cửa sổ chữ nhật?&lt;/li&gt;
  &lt;li&gt;Thiết kế một bài kiểm thử đơn vị (unit test) khoảng 5 dòng dựa trên định lý Parseval cho hàm bọc FFT.&lt;/li&gt;
  &lt;li&gt;Nếu bin DC có giá trị rất lớn, triệu chứng tương ứng ở miền thời gian là gì?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Phần tử ở hàng (k), cột (n) là (e^{-j2\pi kn/4}); cụ thể hàng 0 gồm toàn số 1, hàng 2 là ([1,-1,1,-1]).&lt;/li&gt;
  &lt;li&gt;Tần số tương ứng là (f=32\times 16000/256=2000\,\mathrm{Hz}).&lt;/li&gt;
  &lt;li&gt;Khi nối tuần hoàn sẽ xuất hiện bước nhảy tại biên khối nên sóng sin không trùng với một vector cơ sở duy nhất; đáp ứng dạng hàm sinc của cửa sổ chữ nhật làm năng lượng trải rộng ra nhiều bin.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;Tạo một vector thực, so sánh (\sum&lt;/td&gt;
          &lt;td&gt;x&lt;/td&gt;
          &lt;td&gt;^2) với ((\sum&lt;/td&gt;
          &lt;td&gt;X&lt;/td&gt;
          &lt;td&gt;^2)/N), và khẳng định độ lệch tuyệt đối nhỏ hơn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-6&lt;/code&gt; theo đúng quy ước chuẩn hóa của thư viện.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;Bin DC lớn đồng nghĩa với giá trị trung bình của tín hiệu khác 0 đáng kể (dạng sóng bị dịch khỏi trục 0); cần kiểm tra bộ chặn DC (DC blocker) hoặc độ lệch tĩnh (bias) của micro trước tiên.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — các tính chất của DFT và định lý Parseval.&lt;/li&gt;
  &lt;li&gt;Tài liệu hướng dẫn các thư viện FFT (phần cờ chuẩn hóa).&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Mathematics of the DFT&lt;/em&gt;, https://ccrma.stanford.edu/~jos/mdft/ — ma trận DFT, tính trực giao và định lý Parseval.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xw4voABxU5c&quot;&gt;Computing the DFT Matrix&lt;/a&gt; — Steve Brunton, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Trình bày trực quan ma trận DFT có các hàng là thành phần tần số phức, xem mỗi bin là một tích trong đúng với góc nhìn đổi cơ sở của bài.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nl9TZanwbBk&quot;&gt;The Discrete Fourier Transform (DFT)&lt;/a&gt; — Steve Brunton, tiếng Anh. Phần mở đầu xây dựng phép nhân ma trận trước khi nói đến thuật toán tăng tốc FFT — đúng đối tượng bạn cần nắm vững khi gỡ lỗi.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=bC5umvKV8bE&quot;&gt;Chương 3.1: Biến đổi Fourier rời rạc (DFT)&lt;/a&gt; — Tín hiệu và hệ thống UEt, tiếng Việt. Bài giảng tiếng Việt về tổng DFT, thích hợp để kết hợp cùng video ma trận khi cần kiểm tra cách đánh chỉ số bin.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-03 Hệ thống quan hệ DTFT, DFS và DFT</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_03_dtft_dfs_dft_relationships/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_03_dtft_dfs_dft_relationships</id>
   <content type="html">&lt;p&gt;Mã nguồn thực tế không bao giờ tính biến đổi DTFT vô hạn mà tính DFT hữu hạn (thông qua thuật toán FFT) trên từng cửa sổ nối tiếp nhau theo bước nhảy hop. Bài học này hệ thống hóa mối quan hệ DTFT ↔ DFS ↔ DFT để các siêu tham số STFT có ý nghĩa kỹ thuật rõ ràng.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/dft-basis.png&quot; alt=&quot;Các tone cơ sở DFT: lưới rời rạc mà FFT thực sự tính&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. DFT không tính một đường cong phổ liên tục mà tính tích trong với các thành phần cơ sở phức rời rạc này, mỗi bin ứng với một tần số.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Một trong những nỗi hoang mang kinh điển nhất của sinh viên khi bước vào xử lý tín hiệu số là “rừng chữ viết tắt”: &lt;strong&gt;CFT, DTFT, DFS, rồi DFT&lt;/strong&gt; — cả bốn đều mang tên Fourier, đều có dấu tổng hoặc tích phân với \(e^{-j\omega n}\), nhưng tại sao có cái liên tục, có cái rời rạc, cái thì tuần hoàn, cái lại hữu hạn? Bí mật hóa ra cực kỳ gọn gàng: tất cả chỉ tuân theo &lt;strong&gt;một quy luật đối xứng duy nhất&lt;/strong&gt; — &lt;em&gt;rời rạc ở miền này thì tuần hoàn ở miền kia, và ngược lại&lt;/em&gt;!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-họ-biến-đổi-fourier-liên-hệ-với-nhau-qua-ba-quy-luật-nào&quot;&gt;Kiến thức cần nhớ: Bốn họ Biến đổi Fourier liên hệ với nhau qua ba quy luật nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-ma-trận-đối-xứng-rời-rạc--tuần-hoàn&quot;&gt;1. Ma trận đối xứng Rời rạc ↔ Tuần hoàn&lt;/h3&gt;
&lt;p&gt;Hãy nhớ bảng 4 ô nhỏ gọn sau:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;CFT:&lt;/strong&gt; Thời gian &lt;em&gt;liên tục, không tuần hoàn&lt;/em&gt; ↔ Tần số &lt;em&gt;liên tục, không tuần hoàn&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;DTFT:&lt;/strong&gt; Thời gian &lt;em&gt;rời rạc&lt;/em&gt; (\(n \in \mathbb{Z}\)) ↔ Tần số &lt;em&gt;liên tục nhưng tuần hoàn&lt;/em&gt; chu kỳ \(2\pi\) (\(\omega \in [-\pi, \pi)\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;DFS (Chuỗi Fourier rời rạc):&lt;/strong&gt; Thời gian &lt;em&gt;rời rạc, tuần hoàn&lt;/em&gt; chu kỳ \(N\) ↔ Tần số &lt;em&gt;rời rạc, tuần hoàn&lt;/em&gt; chu kỳ \(N\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;DFT:&lt;/strong&gt; Chỉ lấy &lt;strong&gt;đúng 1 chu kỳ&lt;/strong&gt; (\(0 \le n, k \le N-1\)) của DFS — đây là phiên bản duy nhất máy tính tính trực tiếp được trên mảng hữu hạn \(N\) phần tử!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-quan-hệ-cầu-nối-dft-chính-là-lấy-mẫu-đều-của-dtft&quot;&gt;2. Quan hệ cầu nối: DFT chính là “Lấy mẫu đều của DTFT”&lt;/h3&gt;
&lt;p&gt;Nếu bạn có một tín hiệu hữu hạn \(N\) mẫu \(x[0], \dots, x[N-1]\), thì DTFT của nó là một đường cong phổ liên tục trơn mượt \(X(e^{j\omega})\) trên vòng tròn đơn vị. Khi tính &lt;strong&gt;DFT cỡ \(N\)&lt;/strong&gt;, ta đơn giản chỉ đang &lt;strong&gt;chấm \(N\) điểm cách đều nhau&lt;/strong&gt; trên đường cong liên tục đó tại các tần số \(\omega_k = \frac{2\pi k}{N}\)!&lt;/p&gt;

&lt;h3 id=&quot;3-ý-nghĩa-của-zero-padding-đệm-số-0&quot;&gt;3. Ý nghĩa của Zero-Padding (Đệm số 0)&lt;/h3&gt;
&lt;p&gt;Đệm thêm số \(0\) vào đuôi tín hiệu (ví dụ kéo dài từ \(N = 4\) lên \(M = 16\) mẫu) &lt;strong&gt;không hề làm thay đổi đường cong DTFT gốc&lt;/strong&gt; (vì cộng thêm \(0 \cdot e^{-j\omega n} = 0\)), mà chỉ &lt;strong&gt;lấy mẫu dày hơn&lt;/strong&gt; (16 điểm thay vì 4 điểm) trên chính đường cong DTFT ấy — giúp vẽ đồ thị phổ mượt hơn nhưng &lt;em&gt;không&lt;/em&gt; tăng độ phân giải thực sự để tách hai sóng sát nhau!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-lấy-mẫu-đường-cong-dtft-để-thu-ra-đúng-dft-4-điểm&quot;&gt;Giải thích: tự tay lấy mẫu đường cong DTFT để thu ra đúng DFT 4 điểm&lt;/h3&gt;

&lt;p&gt;Xét tín hiệu cực ngắn chỉ gồm 2 mẫu khác không: \(x[0] = 1,\ x[1] = 1\) (và bằng \(0\) ở mọi chỗ khác).&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Tính đường cong DTFT liên tục \(X(e^{j\omega})\):&lt;/strong&gt;
\(X(e^{j\omega}) = \sum_{n=-\infty}^{\infty} x[n]\,e^{-j\omega n} = 1 + e^{-j\omega}.\)
Đây là một hàm liên tục theo \(\omega \in [0, 2\pi)\) với biên độ \(|X(e^{j\omega})| = 2\bigl|\cos(\omega/2)\bigr|\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đệm 2 số 0 để tính DFT cỡ \(N = 4\) (tức \(x = [1, 1, 0, 0]\)):&lt;/strong&gt; Lấy mẫu \(X(e^{j\omega})\) tại 4 điểm \(\omega_k = \frac{2\pi k}{4} = \frac{\pi k}{2}\) (\(k = 0, 1, 2, 3\)):
    &lt;ul&gt;
      &lt;li&gt;\(k = 0\ (\omega_0 = 0):\) \(X[0] = 1 + e^{0} = \mathbf{2}\).&lt;/li&gt;
      &lt;li&gt;\(k = 1\ (\omega_1 = \pi/2):\) \(X[1] = 1 + e^{-j\pi/2} = \mathbf{1 - j}\) (biên độ \(\sqrt{2} \approx 1.414\)).&lt;/li&gt;
      &lt;li&gt;\(k = 2\ (\omega_2 = \pi):\) \(X[2] = 1 + e^{-j\pi} = 1 - 1 = \mathbf{0}\).&lt;/li&gt;
      &lt;li&gt;\(k = 3\ (\omega_3 = 3\pi/2):\) \(X[3] = 1 + e^{-j3\pi/2} = \mathbf{1 + j}\) (biên độ \(\sqrt{2} \approx 1.414\)).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;strong&gt;So sánh với DFT cỡ \(N = 2\) (không đệm 0):&lt;/strong&gt; Nếu chỉ lấy \(N = 2\) điểm (\(\omega = 0, \pi\)), ta chỉ thấy \(X = [2, 0]\) — bỏ lỡ hoàn toàn giá trị \(1 \mp j\) nằm giữa! Đệm số 0 lên \(N = 4\) hay \(N = 8\) làm lộ rõ hình dáng đường cong $$2&lt;/td&gt;
          &lt;td&gt;\cos(\omega/2)&lt;/td&gt;
          &lt;td&gt;$$ của DTFT mà không thêm chút thông tin mới nào vào tín hiệu gốc!&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Phân biệt DTFT (thời gian rời rạc, tần số liên tục) với DFT (lưới tần số hữu hạn).&lt;/li&gt;
  &lt;li&gt;Giải thích mối quan hệ tuần hoàn giữa miền thời gian và miền tần số ở mức trực giác kỹ thuật.&lt;/li&gt;
  &lt;li&gt;Đọc mỗi bin DFT như một mẫu rời rạc trên phổ của đoạn tín hiệu đã qua cửa sổ.&lt;/li&gt;
  &lt;li&gt;Phân biệt tác dụng của việc đệm số 0 (zero-padding) với độ phân giải tần số thực tế.&lt;/li&gt;
  &lt;li&gt;Vận dụng tính đối xứng liên hợp và hiểu đúng khái niệm “FFT N điểm” trong các hệ thống khử nhiễu.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Phân loại các phép biến đổi và vị trí của STFT&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;DTFT và góc nhìn cửa sổ hóa như phép tích chập trên miền tần số&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Công thức DFT và thiết kế thí nghiệm kiểm chứng zero-padding&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Tính đối xứng của tín hiệu thực và lưu ý về tích chập vòng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập gắn với cách chọn kích thước (N) theo hướng DeepFilterNet&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tên&lt;/th&gt;
      &lt;th&gt;Miền thời gian&lt;/th&gt;
      &lt;th&gt;Miền tần số&lt;/th&gt;
      &lt;th&gt;Trong mã nguồn NS&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;CTFT&lt;/td&gt;
      &lt;td&gt;Liên tục&lt;/td&gt;
      &lt;td&gt;Liên tục&lt;/td&gt;
      &lt;td&gt;Lý thuyết&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DTFT&lt;/td&gt;
      &lt;td&gt;Rời rạc vô hạn&lt;/td&gt;
      &lt;td&gt;Liên tục, chu kỳ (2\pi)&lt;/td&gt;
      &lt;td&gt;Lý thuyết&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DFS&lt;/td&gt;
      &lt;td&gt;Rời rạc tuần hoàn&lt;/td&gt;
      &lt;td&gt;Rời rạc tuần hoàn&lt;/td&gt;
      &lt;td&gt;Ít gọi tên trực tiếp&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DFT/FFT&lt;/td&gt;
      &lt;td&gt;Vector dài (N)&lt;/td&gt;
      &lt;td&gt;(N) bin&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Xuất hiện mọi nơi&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;STFT&lt;/td&gt;
      &lt;td&gt;Các khung cửa sổ&lt;/td&gt;
      &lt;td&gt;DFT trên từng khung&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Xương sống của NS&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

\[X[k]=\sum_{n=0}^{N-1}x[n]e^{-j2\pi kn/N}\]

&lt;p&gt;DFT thực chất là phép lấy mẫu DTFT của một dãy hữu hạn tại các điểm tần số (\omega_k=2\pi k/N). Thay trực tiếp vào tổng DTFT, ta thu được:&lt;/p&gt;

\[X(e^{j\omega})\Big|_{\omega=2\pi k/N}
=\sum_{n=0}^{N-1}x[n]e^{-j2\pi kn/N}
=X[k].\]

&lt;p&gt;Phép lấy mẫu này không tạo thêm thông tin mới giữa các bin. Phép nhân từng phần tử giữa hai DFT tương ứng với &lt;strong&gt;tích chập vòng (circular convolution)&lt;/strong&gt; độ dài (N) trong miền thời gian — vì vậy để thực hiện tích chập tuyến tính trên tín hiệu dài, hệ thống cần các sơ đồ như OLA hoặc OLS.&lt;/p&gt;

&lt;p&gt;Cắt đoạn tín hiệu bằng cửa sổ chữ nhật dài (L) gây hiện tượng nhòe phổ (spectral smearing) với độ rộng búp chính (main lobe) tỷ lệ khoảng (1/L). Đệm số 0 (zero-padding) chỉ làm dày thêm các điểm lấy mẫu của DTFT chứ &lt;strong&gt;không&lt;/strong&gt; cải thiện độ phân giải tần số thực của đoạn quan sát.&lt;/p&gt;

&lt;p&gt;Với tín hiệu đầu vào thực, phổ thỏa mãn tính đối xứng liên hợp (X[k]=X^*[N-k]), nên phần thông tin không dư thừa chỉ nằm trong các bin (0..N/2). Việc thay đổi kích thước (N) giữa giai đoạn huấn luyện và giai đoạn suy luận trên một mô hình tạo mặt nạ mạng nơ-ron là lỗi cấu hình nghiêm trọng.&lt;/p&gt;

&lt;p&gt;Ví dụ: ở (f_s=48\,\mathrm{kHz}) với (N=960) (20 ms), khoảng cách giữa hai bin là (\Delta f=50\,\mathrm{Hz}); ở 16 kHz với (N=512), ta có (\Delta f=31.25\,\mathrm{Hz}).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Ở tần số lấy mẫu 16 kHz với (N=512), thành phần 1 kHz rơi đúng vào bin 32 vì (1000/31.25=32); tuy nhiên năng lượng vẫn có thể lan sang các bin kế cận do búp phổ của cửa sổ, nên mặt nạ khử nhiễu cần có độ mượt theo tần số. Xét 64 mẫu của âm đơn 1 kHz ở 16 kHz: tín hiệu đi hết (1000\times 64/16000=4) chu kỳ, nên DFT 64 điểm đạt đỉnh tại bin 4. Khi đệm số 0 lên 512 điểm, chính 64 mẫu đó sẽ đạt đỉnh tại bin 32. Bước nhảy tần số giữa các bin giảm từ 250 Hz xuống 31.25 Hz, nhưng độ rộng búp chính tính theo Hz vẫn bị giới hạn bởi 64 mẫu quan sát ban đầu (cỡ 250 Hz). Ở tần số mặc định 48 kHz, bẫy tương tự xảy ra khi đệm số 0 một khung 10 ms rồi cho rằng bước bin mịn hơn mang lại “độ phân giải pitch tốt hơn” trong khi thời lượng quan sát thực tế từ micro không hề tăng.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Hiểu nhầm zero-padding là kỹ thuật siêu phân giải tần số.&lt;/li&gt;
  &lt;li&gt;Quên sự khác biệt giữa tích chập vòng và tích chập tuyến tính.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;So sánh biên độ (&lt;/td&gt;
          &lt;td&gt;X[k]&lt;/td&gt;
          &lt;td&gt;) ở các kích thước (N) khác nhau mà không chuẩn hóa.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;Làm phá vỡ tính đối xứng liên hợp của phổ rồi gọi iFFT và chỉ giữ lại phần thực.&lt;/li&gt;
  &lt;li&gt;Dùng hai giá trị (N) khác nhau giữa lúc huấn luyện và lúc triển khai.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; So sánh kết quả DFT 64 điểm của âm đơn 1 kHz ở 16 kHz với chính 64 mẫu đó sau khi đệm số 0 lên 512 điểm.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_win&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_win&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;tone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;peak64&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;argmax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;peak512&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;argmax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;peak64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peak512&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_win&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4 32 250.0 31.25&lt;/code&gt;. Chỉ số đỉnh thay đổi do lưới tần số dày hơn, nhưng độ dài đoạn quan sát thực tế không đổi.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Diễn giải đỉnh tại bin 32 ở (N=512) là “tín hiệu sắc nét hơn”; so sánh trực tiếp chiều cao đỉnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|rfft|&lt;/code&gt; giữa hai kích thước mà không thống nhất chuẩn hóa; hoặc quên rằng sóng cosine đúng bin vẫn có một thành phần đối xứng ở tần số âm mà &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; không hiển thị riêng.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Tìm chỉ số bin gần 1 kHz nhất ở (f_s=16\,\mathrm{kHz}) với (N=512).&lt;/li&gt;
  &lt;li&gt;Tóm tắt trong một câu sự khác nhau giữa zero-padding và tăng độ dài cửa sổ.&lt;/li&gt;
  &lt;li&gt;Giữa một âm đơn rơi đúng bin và một âm đơn nằm giữa hai bin, trường hợp nào gây rò phổ nhiều hơn khi dùng cửa sổ chữ nhật?&lt;/li&gt;
  &lt;li&gt;Vì sao STFT cần bước nhảy hop (R&amp;lt;N) thay vì chỉ tính các khối DFT rời nhau không chồng lấp?&lt;/li&gt;
  &lt;li&gt;Nếu trọng số mô hình yêu cầu đầu vào gồm 513 bin biên độ, kích thước (N) của real-FFT là bao nhiêu?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Khoảng cách bin là (\Delta f=16000/512=31.25\,\mathrm{Hz}), nên 1 kHz rơi chính xác vào bin (32).&lt;/li&gt;
  &lt;li&gt;Zero-padding chỉ nội suy dày thêm các điểm mẫu trên cùng một DTFT, còn kéo dài cửa sổ mới thực sự thu hẹp búp chính của phổ.&lt;/li&gt;
  &lt;li&gt;Âm đơn rơi đúng bin trùng khớp với một vector cơ sở nên dưới cửa sổ chữ nhật chỉ tập trung vào một bin duy nhất; âm nằm giữa hai bin bị gián đoạn khi nối tuần hoàn nên sinh ra rò phổ.&lt;/li&gt;
  &lt;li&gt;Bước nhảy (R&amp;lt;N) tạo vùng chồng lấp giúp phép ISTFT thỏa điều kiện cộng chồng lấp không đổi (COLA); các khối DFT nối tiếp với (R=N) sẽ để lại vết gián đoạn ở biên khung.&lt;/li&gt;
  &lt;li&gt;Phép real-FFT lưu giữ (N/2+1) bin không dư thừa, do đó 513 bin tương ứng với (N=1024).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — mối quan hệ giữa DTFT, DFS và DFT.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Mathematics of the DFT&lt;/em&gt;, https://ccrma.stanford.edu/~jos/mdft/ — trình bày chi tiết về DFT, DTFT và zero-padding.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588) và kho mã nguồn https://github.com/Rikorose/DeepFilterNet cho cấu hình độ dài khung thực tế; tài liệu công khai của RNNoise là mốc đối chiếu cho cấu hình FFT ngắn hơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=bC5umvKV8bE&quot;&gt;Chương 3.1: Biến đổi Fourier rời rạc (DFT)&lt;/a&gt; — Tín hiệu và hệ thống UEt, tiếng Việt. &lt;strong&gt;Xem trước.&lt;/strong&gt; Bài giảng tiếng Việt về tổng DFT, hữu ích khi đối chiếu song song với tài liệu tiếng Anh trong khóa.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nl9TZanwbBk&quot;&gt;The Discrete Fourier Transform (DFT)&lt;/a&gt; — Steve Brunton, tiếng Anh. Trình bày DFT như chuỗi Fourier hữu hạn thay vì tích phân vô hạn, làm rõ bản đồ quan hệ DTFT–DFS–DFT trong bài.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xw4voABxU5c&quot;&gt;Computing the DFT Matrix&lt;/a&gt; — Steve Brunton, tiếng Anh. Minh họa ma trận lấy mẫu các thành phần tần số trong định nghĩa DFT, chuyển tổng hữu hạn thành phép tích trong trên từng bin.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-02 Lấy mẫu, aliasing và Nyquist</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_02_sampling_aliasing_nyquist/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_02_sampling_aliasing_nyquist</id>
   <content type="html">&lt;p&gt;Mọi track WebRTC và mọi lượt suy luận của DeepFilterNet đều giả định một tần số lấy mẫu (sample rate) cố định. Sai lệch tần số lấy mẫu sẽ tạo ra lỗi chồng phổ (aliasing) âm thầm, biểu hiện bên ngoài rất giống “suy giảm chất lượng mô hình”. Bài học này biến định lý lấy mẫu thành một công cụ kiểm tra thực tế cho kỹ sư.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/sampling-nyquist.png&quot; alt=&quot;Phổ bị sao chép theo mỗi sample rate; các bản sao chồng khi tín hiệu quá rộng&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Quá trình lấy mẫu lặp lại phổ theo chu kỳ (f_s) Hz; phần chồng lấn giữa các bản sao là aliasing mà bộ khử nhiễu mạng nơ-ron không thể khôi phục ngược lại.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bạn hẳn từng xem video quay bánh xe ô tô đang lao nhanh về phía trước nhưng trên màn hình lại thấy nan hoa quay ngược chậm rãi — đó chính là &lt;strong&gt;hiện tượng chồng phổ (aliasing)&lt;/strong&gt; trong thị giác do tốc độ khung hình máy quay quá chậm so với tốc độ quay của bánh xe! Trong âm thanh số, điều y hệt xảy ra khi ta chuyển sóng áp suất liên tục thành dãy số rời rạc: nếu tần số lấy mẫu \(f_s\) không đủ nhanh, các âm cao tần (như tiếng chũm chọe hay tiếng rít kim loại) không biến mất mà &lt;strong&gt;gấp ngược xuống thành những âm giả méo mó&lt;/strong&gt; nằm ngay giữa dải giọng nói!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-định-lý-lấy-mẫu-nyquistshannon-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Định lý Lấy mẫu Nyquist–Shannon đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-lấy-mẫu--nhân-với-lược-dirac-trong-miền-thời-gian--lặp-tuần-hoàn-phổ-trong-miền-tần-số&quot;&gt;1. Lấy mẫu = Nhân với lược Dirac trong miền thời gian ↔ Lặp tuần hoàn phổ trong miền tần số&lt;/h3&gt;
&lt;p&gt;Lấy mẫu tín hiệu liên tục \(x(t)\) mỗi chu kỳ \(T_s = 1/f_s\) tương đương nhân \(x(t)\) với chuỗi xung Dirac \(\sum \delta(t - nT_s)\). Qua biến đổi Fourier, phép nhân này biến thành &lt;strong&gt;tích chập với lược Dirac tần số&lt;/strong&gt;, tạo ra vô số bản sao của phổ gốc \(X(f)\) đặt lặp lại tại các tâm \(0, \pm f_s, \pm 2f_s, \dots\)!&lt;/p&gt;

&lt;h3 id=&quot;2-điều-kiện-nyquist-f_s--2-f_max-và-bộ-lọc-chống-chồng-phổ-anti-aliasing-filter&quot;&gt;2. Điều kiện Nyquist (\(f_s &amp;gt; 2 f_{\max}\)) và Bộ lọc chống chồng phổ (Anti-Aliasing Filter)&lt;/h3&gt;
&lt;p&gt;Để các bản sao phổ không đè lên nhau, biên trên \(f_{\max}\) của bản sao gốc phải nhỏ hơn biên dưới \(f_s - f_{\max}\) của bản sao kế tiếp — tức là &lt;strong&gt;\(f_s &amp;gt; 2 f_{\max}\)&lt;/strong&gt; (ngưỡng \(f_s/2\) gọi là &lt;strong&gt;tần số Nyquist&lt;/strong&gt;). Vì thế chuẩn đĩa CD chọn \(f_s = 44.1\text{ kHz}\) và âm thanh số/WebRTC chọn \(48\text{ kHz}\) để bao trọn ngưỡng nghe 20 kHz của tai người, kèm một bộ lọc thông thấp tương tự (anti-aliasing filter) cắt mọi thành phần trên \(f_s/2\) &lt;em&gt;trước khi&lt;/em&gt; đưa vào mạch ADC!&lt;/p&gt;

&lt;h3 id=&quot;3-công-thức-khôi-phục-whittakershannon-nội-suy-sinc&quot;&gt;3. Công thức Khôi phục Whittaker–Shannon (Nội suy Sinc)&lt;/h3&gt;
&lt;p&gt;Nếu thỏa điều kiện Nyquist, ta chỉ cần giữ lại bản sao gốc trong dải \([-f_s/2, +f_s/2]\) (nhân với cửa sổ chữ nhật tần số), tương đương nội suy trong miền thời gian bằng tổng các hàm \(\operatorname{sinc}\) — khôi phục &lt;strong&gt;chính xác 100%&lt;/strong&gt; sóng tương tự ban đầu mà không mất dù chỉ một chút thông tin!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-tính-tần-số-giả-aliasing-khi-lấy-mẫu-sai-tốc-độ&quot;&gt;Giải thích: tự tay tính tần số giả (Aliasing) khi lấy mẫu sai tốc độ&lt;/h3&gt;

&lt;p&gt;Giả sử micro thu được một tiếng rít cao tần hình sin thuần ở tần số \(f_0 = 12\,000\text{ Hz}\) (\(12\text{ kHz}\)): \(x(t) = \cos(2\pi \cdot 12\,000\,t)\). Một kỹ sư quên đặt bộ lọc chống chồng phổ và hạ tốc độ mẫu xuống \(f_s = 16\,000\text{ Hz}\) (tần số Nyquist chỉ là \(f_N = 8\,000\text{ Hz}\)). Chuyện gì xảy ra ở các mẫu số \(x[n] = x(n/f_s)\)?&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thay \(t = n / 16\,000\) vào sóng gốc:&lt;/strong&gt;
\(x[n] = \cos\!\Bigl(2\pi \cdot \frac{12\,000}{16\,000}\,n\Bigr) = \cos\!\Bigl(2\pi \cdot \frac{3}{4}\,n\Bigr).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng tính tuần hoàn \(2\pi\) và tính chẵn của hàm cosin:&lt;/strong&gt;
\(\cos\!\Bigl(2\pi \cdot \frac{3}{4}\,n\Bigr) = \cos\!\Bigl(2\pi \cdot \frac{3}{4}\,n - 2\pi n\Bigr) = \cos\!\Bigl(-2\pi \cdot \frac{1}{4}\,n\Bigr) = \cos\!\Bigl(2\pi \cdot \frac{1}{4}\,n\Bigr)!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đọc ra tần số giả \(f_{\text{alias}}\):&lt;/strong&gt; Tỉ số \(\frac{1}{4}\) nhân với \(f_s = 16\,000\text{ Hz}\) cho ra:
\(f_{\text{alias}} = |f_0 - f_s| = |12\,000 - 16\,000| = \mathbf{4\,000\text{ Hz}}!\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm chứng trực tiếp 4 mẫu đầu tiên (\(n = 0, 1, 2, 3\)):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Sóng 12 kHz lấy mẫu ở 16 kHz cho: \([1,\ 0,\ -1,\ 0]\).&lt;/li&gt;
      &lt;li&gt;Sóng 4 kHz lấy mẫu ở 16 kHz cũng cho: \([1,\ 0,\ -1,\ 0]\) — &lt;strong&gt;giống hệt nhau từng con số một!&lt;/strong&gt; Một khi đã lấy mẫu hỏng mà không lọc trước, không có thuật toán AI nào trên đời tách ngược được 12 kHz khỏi 4 kHz nữa!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Phát biểu định lý lấy mẫu, tốc độ Nyquist và tần số Nyquist.&lt;/li&gt;
  &lt;li&gt;Giải thích hiện tượng aliasing thông qua các con số âm thanh cụ thể.&lt;/li&gt;
  &lt;li&gt;Lựa chọn có chủ đích các mức tần số lấy mẫu 8 / 16 / 48 kHz cho pipeline khử nhiễu tiếng nói.&lt;/li&gt;
  &lt;li&gt;Mô tả vai trò của bộ lọc chống aliasing trước ADC và trước bước giảm mẫu (decimation).&lt;/li&gt;
  &lt;li&gt;Liệt kê các bẫy khi lấy mẫu lại (resample) nhằm đồng bộ đồng hồ trình duyệt với tần số lấy mẫu của mô hình mạng nơ-ron.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Phân tích sự cố (postmortem): vì sao chạy mô hình ONNX 16 kHz trực tiếp trên tín hiệu 48 kHz khiến chất lượng sụp đổ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–25&lt;/td&gt;
      &lt;td&gt;Lấy mẫu bằng chuỗi xung, sự lặp lại bản sao phổ và phác họa giới hạn Nyquist&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;25–40&lt;/td&gt;
      &lt;td&gt;Ví dụ số về aliasing, bảng băng thông tiếng nói và tiêu chí chọn tần số lấy mẫu cho sản phẩm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;40–52&lt;/td&gt;
      &lt;td&gt;Lọc chống aliasing, thiết kế bộ lấy mẫu lại và các lưu ý với WebAudio/WebRTC&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Các bẫy thường gặp và bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;p&gt;Lấy mẫu lý tưởng tương đương việc nhân tín hiệu liên tục (x_c(t)) với một chuỗi xung chu kỳ (T=1/f_s), khiến phổ của tín hiệu &lt;strong&gt;lặp lại&lt;/strong&gt; sau mỗi (f_s) Hz. Nếu các bản sao phổ chồng lấn lên nhau, hiện tượng &lt;strong&gt;aliasing&lt;/strong&gt; sẽ xảy ra và không một bộ lọc số nào có thể tách ngược lại một cách duy nhất.&lt;/p&gt;

&lt;p&gt;Trên lưới lấy mẫu (t=n/f_s), ta có:&lt;/p&gt;

\[\cos\!\left(2\pi\frac{f}{f_s}n\right)
=\cos\!\left(2\pi\frac{f-mf_s}{f_s}n\right)\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;vì (2\pi m n) là một số nguyên lần chu kỳ. Ta gập tần số đại diện về đoạn ([0,f_s/2]). Chẳng hạn, một sóng cosine 7 kHz lấy mẫu ở 8 kHz (chọn (m=1)) sẽ gập về (&lt;/td&gt;
      &lt;td&gt;7000-8000&lt;/td&gt;
      &lt;td&gt;=1000\,\mathrm{Hz}): hai sóng cosine này tạo ra chính xác cùng một dãy mẫu. Với hàm sine, dấu sẽ đảo ngược: (\sin(2\pi\cdot 7n/8)=-\sin(2\pi\cdot 1n/8)) do tính lẻ của hàm sine dưới phép dịch vòng. Ở đây, “trùng khớp” nghĩa là các giá trị mẫu bằng nhau hoàn toàn, không chỉ “nghe gần giống”.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Nếu tín hiệu (x_c) có băng thông giới hạn ở (B) Hz, ta phải chọn (f_s&amp;gt;2B) (&lt;strong&gt;tốc độ Nyquist&lt;/strong&gt; là (2B), còn &lt;strong&gt;tần số Nyquist&lt;/strong&gt; là (f_s/2)).&lt;/p&gt;

&lt;p&gt;Sau khi lấy mẫu, tần số góc chuẩn hóa là (\omega=2\pi f/f_s). Mốc (\omega=\pi) luôn tương ứng với tần số Nyquist trên trục số, nhưng giá trị Hz thực tế phụ thuộc vào (f_s). Do đó, cùng một tập hệ số bộ lọc FIR sẽ có tần số cắt (Hz) khác nhau khi chạy ở 16 kHz so với 48 kHz.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tần số lấy mẫu&lt;/th&gt;
      &lt;th&gt;Tần số Nyquist&lt;/th&gt;
      &lt;th&gt;Ứng dụng điển hình&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;8 kHz&lt;/td&gt;
      &lt;td&gt;4 kHz&lt;/td&gt;
      &lt;td&gt;Thoại băng hẹp (telephony)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;16 kHz&lt;/td&gt;
      &lt;td&gt;8 kHz&lt;/td&gt;
      &lt;td&gt;Mô hình ML tiếng nói băng rộng (wideband)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;48 kHz&lt;/td&gt;
      &lt;td&gt;24 kHz&lt;/td&gt;
      &lt;td&gt;Đồng hồ WebRTC/toàn băng (full-band); mặc định của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Trước bộ chuyển đổi ADC luôn cần một bộ lọc thông thấp (LPF) tương tự. Tương tự, trước khi &lt;strong&gt;giảm mẫu (decimation)&lt;/strong&gt; từ 48 kHz xuống 16 kHz (hệ số 3), bắt buộc phải lọc thông thấp gần 8 kHz &lt;em&gt;rồi mới&lt;/em&gt; giữ lại mỗi mẫu thứ ba; bỏ qua bước lọc này là một lỗi kỹ thuật nghiêm trọng.&lt;/p&gt;

&lt;p&gt;Đưa trực tiếp dữ liệu PCM 48 kHz vào STFT của một mô hình huấn luyện ở 16 kHz không giúp “tăng độ phân giải cho mạng”. Ngược lại, mọi bin tần số đều bị gán sai giá trị Hz, và nếu thiếu bộ lọc thông thấp gần 8 kHz, năng lượng vùng 8–24 kHz sẽ gập thẳng vào dải tần mà mạng nhận diện là tiếng nói. Khi lấy mẫu lại (resample), việc bỏ/lặp mẫu đơn thuần là sai, nội suy tuyến tính có chất lượng kém gần tần số Nyquist, nên môi trường sản phẩm cần dùng bộ lọc đa pha (polyphase) hoặc thư viện tương đương &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libsamplerate&lt;/code&gt;. Các mô hình khử nhiễu mạng nơ-ron rất nhạy với lỗi này vì các thành phần alias xuất hiện như một dạng “nhiễu lạ” chưa từng có trong tập huấn luyện.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Một âm đơn 5 kHz lấy mẫu ở (f_s=8\,\mathrm{kHz}) sẽ bị alias thành 3 kHz. Với khung dài 20 ms, số mẫu ở 16 kHz là (L_{16k}=320), còn ở 48 kHz là (L_{48k}=960). Chi phí tính toán xấp xỉ tỷ lệ thuận với số mẫu mỗi giây — chuyển từ 16 kHz lên 48 kHz có thể làm tăng khoảng 3 lần lưu lượng tính toán STFT nếu giữ nguyên độ dài cửa sổ theo giây.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chạy mô hình huấn luyện ở 16 kHz trực tiếp trên PCM 48 kHz với suy nghĩ “tần số lấy mẫu cao hơn thì tốt hơn”.&lt;/li&gt;
  &lt;li&gt;Cho rằng định dạng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; không bị aliasing — thực tế aliasing phụ thuộc vào tần số lấy mẫu, không phải độ sâu bit.&lt;/li&gt;
  &lt;li&gt;Trộn tín hiệu 44.1 kHz với 48 kHz mà không qua bước lấy mẫu lại.&lt;/li&gt;
  &lt;li&gt;Lấy mẫu lại bằng FFT nhưng xử lý sai biên khối, gây tiếng lách tách (click).&lt;/li&gt;
  &lt;li&gt;Nhầm lẫn giữa độ sâu bit (quyết định nhiễu lượng tử hóa) và tần số lấy mẫu (quyết định băng thông).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Lấy mẫu sóng cosine 7 kHz ở tần số 8 kHz và kiểm chứng rằng dãy mẫu thu được trùng khớp với sóng cosine 1 kHz.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8000&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;high&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;low&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;high&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;low&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;high&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; Sai số nhỏ hơn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-12&lt;/code&gt; (thường khoảng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.354e-14&lt;/code&gt;). Tám mẫu đầu tiên sau khi làm tròn là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1.0, 0.707107, -0.0, -0.707107, -1.0, -0.707107, -0.0, 0.707107]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; So sánh hàm sine nhưng quên dấu trừ; kết luận “không có aliasing” chỉ vì hai mảng đều ở kiểu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float64&lt;/code&gt;; hoặc lọc thông thấp &lt;em&gt;sau&lt;/em&gt; khi đã lấy mẫu ở 8 kHz với kỳ vọng khôi phục lại được thành phần 7 kHz.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Xác định tần số Nyquist tại 48 kHz và 16 kHz.&lt;/li&gt;
  &lt;li&gt;Tìm tần số alias của một âm đơn 10 kHz khi lấy mẫu ở (f_s=16\,\mathrm{kHz}).&lt;/li&gt;
  &lt;li&gt;Tính số mẫu trong 10 ms ở các tần số lấy mẫu 8 kHz, 16 kHz và 48 kHz.&lt;/li&gt;
  &lt;li&gt;Viết danh mục kiểm tra 4 bước để chuyển đổi an toàn tín hiệu 48 kHz mono Float32 sang đầu vào cho mô hình 16 kHz.&lt;/li&gt;
  &lt;li&gt;Giải thích vì sao cùng một mốc (\omega=\pi) lại tương ứng với các tần số Hz khác nhau khi (f_s) thay đổi.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Tần số Nyquist bằng (f_s/2): đạt 24 kHz ở 48 kHz và 8 kHz ở 16 kHz.&lt;/li&gt;
  &lt;li&gt;Âm 10 kHz tại (f_s=16\,\mathrm{kHz}) gập một lần về (16-10=6\,\mathrm{kHz}).&lt;/li&gt;
  &lt;li&gt;Khoảng thời gian 10 ms tương ứng với 80, 160 và 480 mẫu.&lt;/li&gt;
  &lt;li&gt;Xác nhận đầu vào là mono &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float&lt;/code&gt; 48 kHz; áp dụng lọc thông thấp gần 8 kHz; giảm mẫu theo hệ số 3; kiểm chứng rằng sóng sin 1 kHz vẫn giữ đúng 1 kHz và năng lượng trên 8 kHz đã được triệt tiêu.&lt;/li&gt;
  &lt;li&gt;Mốc (\omega=\pi) tương ứng với nửa chu kỳ trên mỗi mẫu, tức (f_s/2) Hz. Tần số số (\omega) đã được chuẩn hóa theo (f_s), còn tần số vật lý (Hz) thì không.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — định lý lấy mẫu và xử lý tín hiệu đa tốc độ.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Mathematics of the DFT&lt;/em&gt;, https://www.dsprelated.com/freebooks/mdft/ — quá trình lấy mẫu và trục tần số sử dụng trong FFT.&lt;/li&gt;
  &lt;li&gt;Tài liệu Web Audio &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt; và các ràng buộc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt; trong WebRTC.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=KuaannH5pnM&quot;&gt;Aliasing and the Sampling Theorem Simplified&lt;/a&gt; — Barry Van Veen, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Minh họa cách phổ liên tục gập vào khoảng (2\pi) — chính cơ chế tạo ra lỗi aliasing khi lệch tần số lấy mẫu.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://xiph.org/video/vid2.shtml&quot;&gt;Xiph.Org Video Presentations: Digital Show &amp;amp; Tell&lt;/a&gt; — Xiph.Org, tiếng Anh. Trang video chính thức của Xiph.Org giải thích về lấy mẫu, độ sâu bit và khôi phục tín hiệu, giúp phân biệt giới hạn thực của tần số lấy mẫu với hiểu nhầm về dạng sóng “bậc thang”.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-01 Trực giác biến đổi Fourier liên tục</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_01_continuous_ft_intuition/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter01/01_01_continuous_ft_intuition</id>
   <content type="html">&lt;p&gt;Các kỹ thuật tăng cường tiếng nói chủ yếu hoạt động trên miền tần số hơn là trên dạng sóng thô. Bài học này xây dựng trực giác về biến đổi Fourier thời gian liên tục (CTFT) để các tham số STFT trong mã nguồn ở những chương sau trở nên minh bạch thay vì là những con số khó hiểu.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/fourier-intuition.png&quot; alt=&quot;Một sóng được tách thành vài sinusoid; cộng lại thì ra sóng ban đầu&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Tần số là một hệ tọa độ: mỗi hình sin là một thành phần cơ sở, và phép biến đổi đo lượng đóng góp của từng thành phần đó trong tín hiệu.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Khi bạn nhìn vào dạng sóng (waveform) của một đoạn ghi âm trên màn hình, bạn chỉ thấy một đường ngoằn ngoèo lên xuống theo thời gian — rất khó nói trong đó có giọng nam trầm, tiếng còi chói tai hay tiếng ù điện 50 Hz. Thế nhưng ngay khi bạn bật &lt;strong&gt;biến đổi Fourier&lt;/strong&gt;, đám rối ngoằn ngoèo ấy bỗng tách bạch ngay lập tức thành những cột năng lượng gọn gàng trên trục tần số: tiếng ù điện đứng đúng ở vạch 50 Hz, giọng nói nằm gọn trong dải 100 Hz–4 kHz, còn tiếng rít cao tần đứng riêng một góc! Biến đổi Fourier chính là “lăng kính toán học” tách ánh sáng trắng của âm thanh thành cầu vồng các tần số đơn sắc.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-biến-đổi-fourier-liên-tục-đứng-trên-ba-trụ-cột-toán-học-nào&quot;&gt;Kiến thức cần nhớ: Biến đổi Fourier liên tục đứng trên ba trụ cột toán học nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-phép-chiếu-trực-giao-lên-họ-sóng-sin-phức-ej-2pi-f-t&quot;&gt;1. Phép chiếu trực giao lên họ sóng sin phức \(e^{j 2\pi f t}\)&lt;/h3&gt;
&lt;p&gt;Trong đại số tuyến tính, muốn biết vectơ \(\mathbf{v}\) chứa bao nhiêu thành phần theo hướng \(\mathbf{u}\), ta lấy tích vô hướng \(\langle \mathbf{v}, \mathbf{u}\rangle\). &lt;strong&gt;Biến đổi Fourier liên tục (CFT)&lt;/strong&gt; làm đúng điều đó cho hàm số \(x(t)\):&lt;/p&gt;

\[X(f) = \int_{-\infty}^{\infty} x(t)\,e^{-j 2\pi f t}\,dt.\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Tích phân này “quấn” tín hiệu \(x(t)\) quanh đường tròn đơn vị với tốc độ quay \(f\) vòng/giây rồi tìm trọng tâm: nếu \(x(t)\) thực sự chứa sóng ở tần số \(f\), các vectơ cộng hưởng cùng hướng tạo ra $$&lt;/td&gt;
      &lt;td&gt;X(f)&lt;/td&gt;
      &lt;td&gt;\(lớn; nếu không, chúng xoay đều quanh gốc và tự triệt tiêu về\)0$$!&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;2-biên-độ-magnitude-và-pha-phase&quot;&gt;2. Biên độ (Magnitude) và Pha (Phase)&lt;/h3&gt;
&lt;p&gt;Kết quả \(X(f) = |X(f)|\,e^{j\angle X(f)}\) là một &lt;strong&gt;số phức&lt;/strong&gt;: môđun \(|X(f)|\) cho biết &lt;em&gt;mạnh yếu&lt;/em&gt; của tần số \(f\), còn góc pha \(\angle X(f)\) cho biết &lt;em&gt;thời điểm dịch chuyển&lt;/em&gt; của sóng đó. Trong xử lý tiếng nói, biên độ quyết định âm sắc và cấu trúc formant, còn pha quyết định độ sắc nét của các phụ âm nổ (như /p/, /t/, /k/) và tính tự nhiên của giọng nói.&lt;/p&gt;

&lt;h3 id=&quot;3-đối-ngẫu-thời-gian--tần-số-co-giãn-và-tích-chập&quot;&gt;3. Đối ngẫu Thời gian – Tần số (Co giãn và Tích chập)&lt;/h3&gt;
&lt;p&gt;Hai tính chất của CFT điều khiển toàn bộ thiết kế bộ lọc âm thanh: (1) &lt;strong&gt;Định lý co giãn&lt;/strong&gt;: ép hẹp tín hiệu theo thời gian \(a\) lần thì phổ tần số lập tức phình rộng ra đúng \(a\) lần; (2) &lt;strong&gt;Định lý tích chập&lt;/strong&gt;: phép lọc tích chập nặng nề \(y(t) = (h * x)(t)\) trong miền thời gian biến thành phép nhân đơn giản \(Y(f) = H(f)\,X(f)\) trong miền tần số!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-tính-biến-đổi-fourier-của-một-xung-chữ-nhật-rộng-t&quot;&gt;Giải thích: tự tay tính biến đổi Fourier của một xung chữ nhật rộng \(T\)&lt;/h3&gt;

&lt;p&gt;Hãy tính tích phân Fourier của một xung chữ nhật bật trong khoảng \([-T/2,\ +T/2]\) (biên độ 1 bên trong, 0 bên ngoài — mô hình đơn giản nhất của việc “cắt một khung âm thanh dài \(T\)”):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thiết lập tích phân:&lt;/strong&gt;
\(X(f) = \int_{-T/2}^{T/2} 1 \cdot e^{-j 2\pi f t}\,dt = \left[\frac{e^{-j 2\pi f t}}{-j 2\pi f}\right]_{-T/2}^{T/2} = \frac{e^{j \pi f T} - e^{-j \pi f T}}{j 2\pi f}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dùng công thức Euler \(\sin\theta = \frac{e^{j\theta} - e^{-j\theta}}{2j}\):&lt;/strong&gt;
\(X(f) = \frac{\sin(\pi f T)}{\pi f} = T\,\frac{\sin(\pi f T)}{\pi f T} = T\,\operatorname{sinc}(f T).\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đọc ra quy luật vàng với con số cụ thể của khung tiếng nói \(T = 20\text{ ms} = 0.02\text{ s}\):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Tại \(f = 0\): \(X(0) = T = 0.02\) (đỉnh búp chính).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Không điểm đầu tiên&lt;/strong&gt; xảy ra khi \(\pi f T = \pi \iff f = \frac{1}{T} = \frac{1}{0.02} = \mathbf{50\text{ Hz}}\)!&lt;/li&gt;
      &lt;li&gt;Như vậy, chỉ riêng việc cắt đoạn âm thanh dài \(20\text{ ms}\) đã làm mỗi tần số thuần bị “nhòe” thành một búp chính rộng \(\pm 50\text{ Hz}\) (tổng \(100\text{ Hz}\)) kèm các búp phụ dao động giảm chậm theo \(1/f\)! Nếu cắt ngắn hơn nữa xuống \(T = 5\text{ ms}\), búp chính lập tức phình to gấp 4 lần lên \(\pm 200\text{ Hz}\) — đó chính là giới hạn độ phân giải thời gian–tần số mà mọi kỹ sư STFT phải sống chung!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Hiểu tần số như tốc độ dao động và như một tọa độ trong hệ cơ sở tín hiệu.&lt;/li&gt;
  &lt;li&gt;Trình bày cặp biến đổi CTFT thuận/nghịch cùng cơ chế phân tích–tổng hợp.&lt;/li&gt;
  &lt;li&gt;Vận dụng các tính chất tuyến tính và dịch thời gian trong phân tích kỹ thuật.&lt;/li&gt;
  &lt;li&gt;Liên hệ phổ biên độ và phổ pha với cảm nhận thính giác ở mức tổng quan.&lt;/li&gt;
  &lt;li&gt;Giải thích vì sao tiếng nói và nhiễu thường tách biệt rõ hơn ở miền tần số, đồng thời chỉ ra các trường hợp trực giác này không còn đúng.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–8&lt;/td&gt;
      &lt;td&gt;Dẫn nhập: so sánh cùng một dạng sóng ở miền thời gian và miền tần số; lý giải vì sao các hệ thống VoIP ưu tiên xử lý phổ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;8–20&lt;/td&gt;
      &lt;td&gt;Tín hiệu hình sin, công thức Euler và trực giác hàm riêng của hệ LTI&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;20–35&lt;/td&gt;
      &lt;td&gt;Cặp biến đổi CTFT, biên độ và pha, cùng ví dụ về tính tuyến tính và dịch thời gian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;35–48&lt;/td&gt;
      &lt;td&gt;Formant tiếng nói so với nền nhiễu, ngộ nhận về pha và định hướng sang DeepFilterNet&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;48–60&lt;/td&gt;
      &lt;td&gt;Các bẫy thường gặp, bài tập nhỏ và giới thiệu bài lấy mẫu&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;tần-số-là-một-hệ-tọa-độ&quot;&gt;Tần số là một hệ tọa độ&lt;/h3&gt;

&lt;p&gt;Tín hiệu hàm mũ phức (e^{j\Omega t}) dao động với tần số góc (\Omega) rad/s ((f=\Omega/(2\pi)) Hz). Các hàm này là &lt;strong&gt;hàm riêng của hệ tuyến tính bất biến theo thời gian (LTI)&lt;/strong&gt;: một bộ lọc LTI chỉ nhân mỗi hàm mũ phức với đáp ứng tần số (H(j\Omega)) mà không sinh ra tần số mới. Đây là lý do khử nhiễu miền tần số rất hiệu quả: dưới giả định nhiễu cộng tính và gần LTI trong thời gian ngắn, ta có thể làm suy hao các bin nhiễu và giữ lại các bin tiếng nói. Dù thực tế phức tạp hơn (nhiễu không dừng, sai số mặt nạ, lệch pha), bức tranh hàm riêng vẫn là nền tảng cho phần lớn bộ khử nhiễu cổ điển lẫn mạng nơ-ron miền STFT.&lt;/p&gt;

&lt;h3 id=&quot;biến-đổi-fourier-thời-gian-liên-tục&quot;&gt;Biến đổi Fourier thời gian liên tục&lt;/h3&gt;

\[X(j\Omega)=\int_{-\infty}^{\infty}x(t)e^{-j\Omega t}\,\mathrm{d}t\]

\[x(t)=\frac{1}{2\pi}\int_{-\infty}^{\infty}X(j\Omega)e^{j\Omega t}\,\mathrm{d}\Omega\]

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Phép &lt;strong&gt;phân tích&lt;/strong&gt; đo mức đóng góp của từng tần số, còn phép &lt;strong&gt;tổng hợp&lt;/strong&gt; tái tạo lại dạng sóng ban đầu. Viết (X=&lt;/td&gt;
      &lt;td&gt;X&lt;/td&gt;
      &lt;td&gt;e^{j\phi}), trong đó biên độ phản ánh phân bố năng lượng (formant, tiếng rít), còn pha mã hóa cấu trúc thời gian (đoạn khởi âm, cấu trúc cao độ pitch). Vì giao diện phổ đồ (spectrogram) thường chỉ hiển thị biên độ, người mới dễ hình thành thói quen sai lầm rằng “pha không quan trọng”. Khi áp dụng mặt nạ khử nhiễu mạnh, việc xử lý pha hoặc phổ phức trở thành yếu tố thiết kế then chốt — cơ chế lọc sâu (deep filtering) trên phổ phức của DeepFilterNet ra đời một phần để khắc phục giới hạn của mặt nạ biên độ đơn thuần.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;các-tính-chất-thường-dùng-trong-thực-tế&quot;&gt;Các tính chất thường dùng trong thực tế&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tuyến tính:&lt;/strong&gt; phổ của tổng tín hiệu cộng theo thang &lt;strong&gt;tuyến tính&lt;/strong&gt;, không cộng trực tiếp theo dB.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dịch thời gian:&lt;/strong&gt; một độ trễ theo thời gian tương ứng với một độ dốc tuyến tính của pha theo tần số.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Định lý Parseval:&lt;/strong&gt; việc loại bỏ một vùng phổ lớn &lt;em&gt;bắt buộc&lt;/em&gt; làm giảm năng lượng của dạng sóng tương ứng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Điều chế (modulation):&lt;/strong&gt; tương ứng với phép dịch phổ, giải thích cấu trúc các dãy hài của âm có cao độ tuần hoàn.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;tiếng-nói-và-nhiễu-mô-hình-giản-lược&quot;&gt;Tiếng nói và nhiễu (mô hình giản lược)&lt;/h3&gt;

&lt;p&gt;Tiếng nói hữu thanh có kích thích gần tuần hoàn tại tần số cơ bản (f_0), kéo theo chuỗi họa âm (kf_0) được định hình bởi các đỉnh formant. Âm vô thanh phân bố năng lượng rộng ở tần số cao — nếu cắt tần số cao quá mạnh sẽ làm giảm độ rõ. Nhiễu dừng như hệ thống HVAC tập trung ở tần số thấp hoặc phẳng như tiếng quạt. Với nhiễu babble, phổ chồng lấn trực tiếp với tiếng nói nên cần mô hình hóa ngữ cảnh theo thời gian (RNN, TCN…) như trong các hệ thống tăng cường tiếng nói hiện đại.&lt;/p&gt;

&lt;h3 id=&quot;cầu-nối-sang-phần-còn-lại-của-chương-01&quot;&gt;Cầu nối sang phần còn lại của Chương 01&lt;/h3&gt;

&lt;p&gt;Micro không cung cấp hàm liên tục mà cung cấp chuỗi mẫu rời rạc. Do đó, tích phân liên tục sẽ chuyển thành DTFT, DFT và FFT trên từng cửa sổ. Điều cốt lõi cần ghi nhớ là: &lt;strong&gt;tần số đóng vai trò hệ số trong một cơ sở tín hiệu, còn mỗi bin STFT là ước lượng cục bộ, có cửa sổ hóa của hệ số đó.&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số&quot;&gt;Ví dụ có số&lt;/h2&gt;

&lt;p&gt;Xét tín hiệu gồm hai thành phần tần số (x(t)=\cos(2\pi\cdot 440\,t)+0.3\cos(2\pi\cdot 880\,t)). Công thức Euler cho thấy rõ cấu trúc phổ của tín hiệu này:&lt;/p&gt;

\[\cos\theta=\frac{e^{j\theta}+e^{-j\theta}}{2}.\]

&lt;p&gt;Thành phần cosine 440 Hz tạo ra một cặp vạch phổ tại (\pm 440\,\mathrm{Hz}), mỗi vạch có biên độ phức (1/2); thành phần cosine 880 Hz tạo cặp vạch tại (\pm 880\,\mathrm{Hz}) với biên độ (0.15). Một bộ lọc thông thấp (LPF) cắt tại 600 Hz sẽ loại bỏ họa âm quãng tám 880 Hz và làm tối âm sắc (timbre) — các bộ khử nhiễu kiểu “lọc thông thấp để hết tiếng rít” mắc đúng lỗi này với phụ âm. Trên đường xử lý 48 kHz toàn băng (mặc định của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;), các phụ âm cao tần vẫn được bảo toàn trên 8 kHz. Một độ trễ 5 ms tại 1 kHz tạo ra độ dịch pha (-2\pi f t_0). Ngoài ra, cần tránh sai lầm khi cộng theo thang dB: không thể viết “−20 dB + −20 dB = −40 dB” cho một phép trộn tuyến tính.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Coi phổ đồ biên độ là toàn bộ thông tin của tín hiệu.&lt;/li&gt;
  &lt;li&gt;Cộng trực tiếp các giá trị dB như cộng biên độ tuyến tính.&lt;/li&gt;
  &lt;li&gt;Nhầm lẫn giữa tần số góc (\Omega) (rad/s) và tần số (f) (Hz).&lt;/li&gt;
  &lt;li&gt;Cho rằng độ phân giải tần số càng cao càng tốt mà bỏ qua cái giá phải trả về độ trễ.&lt;/li&gt;
  &lt;li&gt;Kỳ vọng công thức tích phân CTFT xuất hiện nguyên dạng trong mã nguồn thực tế.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Tổng hợp tín hiệu dài 1 giây gồm ba sóng sin 200 Hz, 600 Hz và 1000 Hz ở tần số lấy mẫu 8 kHz, sau đó đọc chỉ số các bin đỉnh từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt;. Khi chọn (N=f_s), chỉ số bin trùng khớp trực tiếp với tần số tính bằng Hz.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8000&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;600&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;argsort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:])&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[200, 600, 1000]&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[4000.0, 4000.0, 4000.0]&lt;/code&gt;. Mỗi sóng sin có biên độ 1 và chứa đúng một số nguyên chu kỳ trong cửa sổ nên năng lượng tập trung vào đúng một bin dương với biên độ (N/2=4000).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.fft.fft&lt;/code&gt; rồi báo cáo thêm chỉ số tần số âm như một đỉnh riêng biệt; chọn (N) không chứa số nguyên chu kỳ khiến đỉnh bị nhòe sang các bin xung quanh; hoặc nhầm lẫn giá trị 4000 với hệ số (1/2) của cosine trong ví dụ liên tục (tỷ lệ quy đổi của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; cho sóng sin là (N/2)).&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Biểu diễn (\sin(\Omega t)) bằng hàm mũ phức theo công thức Euler.&lt;/li&gt;
  &lt;li&gt;Với độ trễ 2 ms, hãy tính độ dịch pha tại 500 Hz và 2 kHz (trước khi gập pha về ([-\pi, \pi])).&lt;/li&gt;
  &lt;li&gt;Phác họa dạng phổ giản lược cho bốn loại tín hiệu: nguyên âm hữu thanh, nhiễu trắng, tiếng gõ bàn phím và nhiễu babble.&lt;/li&gt;
  &lt;li&gt;Viết một đoạn ngắn giải thích vì sao hàm mũ phức đặc biệt thuận tiện khi phân tích hệ LTI.&lt;/li&gt;
  &lt;li&gt;Nêu một tình huống mà xử lý ở miền thời gian có thể hiệu quả hơn trừ phổ cơ bản (gợi ý: xung click).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;(\sin\theta=(e^{j\theta}-e^{-j\theta})/(2j)): gồm hai vạch phổ trái dấu với hệ số (1/(2j)).&lt;/li&gt;
  &lt;li&gt;Áp dụng (\Delta\phi=-2\pi f t_0): tại 500 Hz và 2 ms, độ dịch pha là (-2\pi) rad (đúng một vòng); tại 2 kHz là (-8\pi) rad (bốn vòng), trong khi biên độ không đổi.&lt;/li&gt;
  &lt;li&gt;Nguyên âm hữu thanh có chuỗi hài xếp theo đường bao formant; nhiễu trắng có phổ phẳng; xung click trải rộng trên toàn băng tần; babble giống như một chuỗi hài thứ hai chồng lấn phức tạp.&lt;/li&gt;
  &lt;li&gt;Bộ lọc LTI chỉ nhân (e^{j\Omega t}) với một hằng số phức (H(j\Omega)) và không sinh ra tần số mới; mọi sóng cosine đều có thể tách thành tổng của hai hàm riêng như vậy.&lt;/li&gt;
  &lt;li&gt;Một xung click kéo dài một mẫu sẽ trải năng lượng đều trên mọi bin tần số. Một cổng triệt xung ngắn ở miền thời gian có thể phát hiện và chặn nó ngay lập tức, trong khi bộ theo dõi nền nhiễu cập nhật chậm ở miền tần số sẽ bỏ lọt.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer, &lt;em&gt;Discrete-Time Signal Processing&lt;/em&gt; — các chương tổng quan về biến đổi Fourier.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Mathematics of the DFT&lt;/em&gt;, https://ccrma.stanford.edu/~jos/mdft/ — góc nhìn xem sóng sin là hệ cơ sở trước khi đi vào STFT.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588) — khử nhiễu trên miền STFT kết hợp deep filtering (bài này cung cấp nền tảng động lực cho phương pháp đó).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=spUNpyF58BY&quot;&gt;But what is the Fourier Transform?  A visual introduction.&lt;/a&gt; — 3Blue1Brown, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Minh họa trực quan phép quấn tín hiệu trước khi đi vào tích phân: mỗi tần số là một tọa độ, đúng với trực giác của bài học này.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=MBnnXbOM5S4&quot;&gt;The more general uncertainty principle, regarding Fourier transforms&lt;/a&gt; — 3Blue1Brown, tiếng Anh. Phần phân tích sóng âm minh họa sự đánh đổi giữa thời gian và tần số trước khi chọn độ dài cửa sổ.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>00-04 Lộ trình khóa học và ngữ cảnh sản phẩm Mezon</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter00/00_04_course_map_mezon/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter00/00_04_course_map_mezon</id>
   <content type="html">&lt;p&gt;Bài học này đóng vai trò như bản đồ và cam kết học tập cho toàn khóa: các chương được sắp xếp từ nền tảng biến đổi Fourier đến bài tập tổng kết (capstone) gắn với Mezon, chỉ rõ bề mặt công khai của sản phẩm là gì và định hướng cách học để tránh nhầm lẫn giữa “biết gọi wrapper” với “nắm vững kỹ thuật”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;TrackProcessor của LiveKit, chỗ công khai để gắn bộ lọc nhiễu lên một media track&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Sơ đồ chỉ minh họa điểm tích hợp công khai: gắn một TrackProcessor lên media track, không tiết lộ cấu trúc nội bộ chưa công bố của Mezon.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Học lý thuyết xử lý tín hiệu mà không gắn với một đường ống (pipeline) sản phẩm thật rất dễ rơi vào cảnh “thuộc công thức Fourier nhưng không biết ghép vào trình duyệt thế nào”. Khóa học này được thiết kế xoay quanh một bài toán kỹ thuật sống động: làm thế nào đưa một mạng khử nhiễu hiện đại (&lt;strong&gt;DeepFilterNet3&lt;/strong&gt;, đóng gói trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; của Mezon) chạy mượt mà ngay trong trình duyệt web qua &lt;strong&gt;WebAssembly (WASM)&lt;/strong&gt; và &lt;strong&gt;Web Audio API (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt;)&lt;/strong&gt; ở tốc độ 48 kHz!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-đường-ống-khử-nhiễu-trên-trình-duyệt-kết-nối-ba-tầng-kiến-thức-nào&quot;&gt;Kiến thức cần nhớ: Đường ống Khử nhiễu trên Trình duyệt kết nối ba tầng kiến thức nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-tầng-toán-học--tín-hiệu-chương-1--2&quot;&gt;1. Tầng Toán học – Tín hiệu (Chương 1 &amp;amp; 2)&lt;/h3&gt;
&lt;p&gt;Biến đổi Fourier (DFT/FFT), lấy mẫu Nyquist, chia khung (framing), cửa sổ Hann và cặp biến đổi &lt;strong&gt;STFT / ISTFT&lt;/strong&gt; biến luồng mẫu PCM 1 chiều thành bản đồ thời gian–tần số 2 chiều mà các bộ lọc và mạng nơ-ron có thể thao tác.&lt;/p&gt;

&lt;h3 id=&quot;2-tầng-thuật-toán-cổ-điển--học-sâu-chương-3--4&quot;&gt;2. Tầng Thuật toán Cổ điển &amp;amp; Học sâu (Chương 3 &amp;amp; 4)&lt;/h3&gt;
&lt;p&gt;Đi từ các nguyên lý nền tảng — &lt;strong&gt;Spectral Subtraction&lt;/strong&gt;, &lt;strong&gt;bộ lọc Wiener&lt;/strong&gt;, &lt;strong&gt;Kalman&lt;/strong&gt;, &lt;strong&gt;AEC/Beamforming&lt;/strong&gt; — lên kiến trúc hai tầng thông minh của &lt;strong&gt;DeepFilterNet&lt;/strong&gt; (tầng 1 khử nhiễu thô bằng thang tần số ERB cảm thụ sinh học, tầng 2 lọc sâu đa khung phức để phục hồi cấu trúc hài âm).&lt;/p&gt;

&lt;h3 id=&quot;3-tầng-triển-khai-thời-gian-thực-trên-web-webrtc--audioworklet--wasm&quot;&gt;3. Tầng Triển khai Thời gian thực trên Web (WebRTC + AudioWorklet + WASM)&lt;/h3&gt;
&lt;p&gt;Trình duyệt cấp dữ liệu âm thanh theo các khối cứng &lt;strong&gt;128 mẫu&lt;/strong&gt; (render quantum) trên luồng ưu tiên cao &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt;, trong khi DeepFilterNet3 xử lý theo khung hop &lt;strong&gt;480 mẫu (10 ms ở 48 kHz)&lt;/strong&gt;. Việc bắc cầu giữa hai kích thước khung khác nhau đó đòi hỏi kỹ thuật bộ đệm vòng (ring buffer) chính xác đến từng mẫu!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-tính-bộ-đệm-vòng-ring-buffer-nối-audioworklet-128-mẫu-với-deepfilternet3-480-mẫu&quot;&gt;Giải thích: tự tay tính bộ đệm vòng (Ring Buffer) nối &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; (128 mẫu) với DeepFilterNet3 (480 mẫu)&lt;/h3&gt;

&lt;p&gt;Tại sao không thể gọi trực tiếp DeepFilterNet3 trong mỗi lần &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet.process()&lt;/code&gt;? Hãy tính bằng số nguyên sơ cấp ở \(f_s = 48\,000\text{ Hz}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Nhịp vào của trình duyệt:&lt;/strong&gt; Mỗi lần gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt;, Web Audio API cung cấp đúng &lt;strong&gt;128 mẫu&lt;/strong&gt; (\(\frac{128}{48\,000} \approx \mathbf{2.67\text{ ms}}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhịp xử lý của DeepFilterNet3:&lt;/strong&gt; Mô hình đòi hỏi đúng &lt;strong&gt;480 mẫu&lt;/strong&gt; (\(\mathbf{10\text{ ms}}\)) cho mỗi bước nhảy hop.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Theo dõi bộ đệm vòng qua 4 lần gọi liên tiếp:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Gọi lần 1: đệm có \(128\) mẫu (\(&amp;lt; 480\) → chưa đủ, phát khung cũ từ bộ đệm ra).&lt;/li&gt;
      &lt;li&gt;Gọi lần 2: đệm có \(256\) mẫu (\(&amp;lt; 480\)).&lt;/li&gt;
      &lt;li&gt;Gọi lần 3: đệm có \(384\) mẫu (\(&amp;lt; 480\)).&lt;/li&gt;
      &lt;li&gt;Gọi lần 4: đệm có \(512\) mẫu (\(\ge 480\) → &lt;strong&gt;rút đúng 480 mẫu&lt;/strong&gt; chạy DeepFilterNet3, còn dư \(512 - 480 = \mathbf{32\text{ mẫu}}\) giữ lại cho chu kỳ kế tiếp!).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chu kỳ lặp chính xác:&lt;/strong&gt; Tìm bội chung nhỏ nhất \(\operatorname{lcm}(128, 480) = \mathbf{1\,920\text{ mẫu}}\) (đúng \(40\text{ ms}\)): cứ sau đúng &lt;strong&gt;15 lần gọi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt;&lt;/strong&gt; (\(15 \times 128 = 1\,920\)), mô hình chạy chẵn &lt;strong&gt;4 khung DeepFilterNet3&lt;/strong&gt; (\(4 \times 480 = 1\,920\)) và số dư bộ đệm quay tròn về đúng \(0\)!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Nắm được lộ trình xuyên suốt các chương: từ DSP → khử nhiễu cổ điển → DeepFilterNet → thời gian thực và suy luận trên thiết bị → tích hợp sản phẩm → đánh giá → bài tập tổng kết.&lt;/li&gt;
  &lt;li&gt;Mô tả kiến trúc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezon-noise-suppression&lt;/code&gt; ở &lt;strong&gt;mức tổng quan&lt;/strong&gt; chỉ dựa trên thông tin công khai.&lt;/li&gt;
  &lt;li&gt;Nêu rõ nguyên tắc sư phạm của khóa học: giảng dạy nền tảng kỹ thuật; gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; là &lt;em&gt;bề mặt ứng dụng&lt;/em&gt;, không phải toàn bộ giáo trình.&lt;/li&gt;
  &lt;li&gt;Xây dựng lộ trình học phù hợp (đầy đủ hoặc rút gọn) tùy theo nền tảng cá nhân.&lt;/li&gt;
  &lt;li&gt;Biết nơi tra cứu đề cương khóa học và quy tắc đóng góp.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–15&lt;/td&gt;
      &lt;td&gt;Rà soát bảng chương trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COURSE_OUTLINE.md&lt;/code&gt; và đánh dấu các kiến thức tiên quyết&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;15–30&lt;/td&gt;
      &lt;td&gt;Ngữ cảnh sản phẩm: GitHub, gói npm và đường dẫn nội bộ của giảng viên; những điều nên và không nên làm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;30–45&lt;/td&gt;
      &lt;td&gt;Giới thiệu sơ bộ bài tập tổng kết (Chương 09) và tư duy đánh giá (Chương 08)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;45–55&lt;/td&gt;
      &lt;td&gt;Lập phiếu lộ trình học tập cá nhân&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;55–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;bản-đồ-chương-0010&quot;&gt;Bản đồ chương (00–10)&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Ch&lt;/th&gt;
      &lt;th&gt;Chủ đề&lt;/th&gt;
      &lt;th&gt;Mục đích&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;00&lt;/td&gt;
      &lt;td&gt;Định khung bài toán&lt;/td&gt;
      &lt;td&gt;Thống nhất thuật ngữ và ngữ cảnh Mezon&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;01&lt;/td&gt;
      &lt;td&gt;Fourier &amp;amp; biến đổi rời rạc (&lt;strong&gt;chuyên sâu&lt;/strong&gt;)&lt;/td&gt;
      &lt;td&gt;Đọc và phân tích STFT/FFT dưới góc nhìn kỹ sư&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;02&lt;/td&gt;
      &lt;td&gt;Pipeline xử lý âm thanh&lt;/td&gt;
      &lt;td&gt;Chuỗi PCM → định khung → STFT → đánh đổi độ trễ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;03&lt;/td&gt;
      &lt;td&gt;NS / AEC / beamforming cổ điển&lt;/td&gt;
      &lt;td&gt;Các giả định nền tảng mà DeepFilterNet vẫn kế thừa&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;04&lt;/td&gt;
      &lt;td&gt;Tăng cường tiếng nói bằng mạng nơ-ron &amp;amp; họ DeepFilterNet&lt;/td&gt;
      &lt;td&gt;Ý tưởng cốt lõi của mô hình và khảo sát các nhánh kế thừa&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;05&lt;/td&gt;
      &lt;td&gt;Ràng buộc thời gian thực&lt;/td&gt;
      &lt;td&gt;RTF, AudioWorklet, bộ đệm vòng (ring buffer) và quản lý trạng thái&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;06&lt;/td&gt;
      &lt;td&gt;Suy luận trên thiết bị (on-device)&lt;/td&gt;
      &lt;td&gt;ONNX/tract, lượng tử hóa và WASM/SIMD&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;07&lt;/td&gt;
      &lt;td&gt;Tích hợp sản phẩm&lt;/td&gt;
      &lt;td&gt;WebRTC, LiveKit, CDN và đóng gói npm&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;08&lt;/td&gt;
      &lt;td&gt;Đánh giá&lt;/td&gt;
      &lt;td&gt;SI-SDR, DNSMOS, kiểm tra nghe và bộ chỉ số DNS&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;09&lt;/td&gt;
      &lt;td&gt;Capstone: Mezon NS&lt;/td&gt;
      &lt;td&gt;Triển khai kỹ thuật đầu–cuối&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;10&lt;/td&gt;
      &lt;td&gt;Tài liệu &amp;amp; hướng đi tiếp&lt;/td&gt;
      &lt;td&gt;Danh mục nguồn tham khảo chọn lọc&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Chương &lt;strong&gt;01&lt;/strong&gt; và &lt;strong&gt;02&lt;/strong&gt; là hai học phần trọng tâm (mỗi chương gồm bảy bài), không phải phần phụ lục DSP lướt qua.&lt;/p&gt;

&lt;h3 id=&quot;lộ-trình-gợi-ý&quot;&gt;Lộ trình gợi ý&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Lộ trình đầy đủ&lt;/strong&gt; (mới tiếp cận DSP): 00 → 01 → 02 → 03 → 04 → 05 → 06 → 07 → 08 → 09.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lộ trình rút gọn&lt;/strong&gt; (đã vững DSP, mới tiếp cận neural SE): 00 → danh mục kiểm tra 01–02 → 04 → 05–07 → 08 → 09.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hướng tích hợp sản phẩm:&lt;/strong&gt; 00, 02-07, 05, 06, 07, 08, 09 — vẫn cần đọc bài 01-07 về các bẫy thường gặp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;ngữ-cảnh-mezon-thông-tin-công-khai&quot;&gt;Ngữ cảnh Mezon (thông tin công khai)&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Kho mã nguồn: https://github.com/mezonai/mezon-noise-suppression&lt;/li&gt;
  &lt;li&gt;Gói npm: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Các lớp công khai trên bề mặt API: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Tham số điều khiển công khai: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Tần số lấy mẫu mặc định: &lt;strong&gt;48 kHz toàn băng (full-band)&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Đường dẫn trên máy giảng viên (không bắt buộc với học viên): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Quy tắc thực hành:&lt;/strong&gt; không chỉnh sửa trực tiếp kho mã sản phẩm từ bài học; không suy diễn kiến trúc nội bộ chưa công bố; bài tập tổng kết chứng minh năng lực hiểu về định khung, độ trễ và đánh giá; phần Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; là nội dung mở rộng ở Chương 09.&lt;/p&gt;

&lt;h3 id=&quot;dạy-kỹ-thuật-không-chỉ-gọi-wrapper&quot;&gt;“Dạy kỹ thuật, không chỉ gọi wrapper”&lt;/h3&gt;

&lt;p&gt;Biết cách gọi API từ gói npm là hữu ích nhưng chưa đủ. Kỹ sư cần trả lời được các câu hỏi nền tảng: mô hình giả định kích thước hop, cửa sổ và tần số lấy mẫu nào; độ trễ thuật toán phát sinh từ đâu; tín hiệu stereo được xử lý theo quy tắc gì; và chất lượng được đo lường ra sao — lời giải nằm trải dài từ Chương 01–02 đến Chương 04–08.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; trông chỉ như một lời gọi hàm đơn giản, nhưng để hiểu đúng bản chất, ta phải lần theo bản đồ kiến thức: giá trị số nguyên đó chọn điểm làm việc cho độ lợi hoặc mặt nạ đã huấn luyện (Chương 03–04), mặc định 48 kHz quyết định tần số Nyquist và phép tính hop (Chương 01–02), còn bộ xử lý vẫn phải hoàn tất trong ngân sách thời gian của callback (Chương 05). Sơ đồ LiveKit ở trên chỉ minh họa trước vị trí gắn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; lên track âm thanh (Chương 07), chứ không phải cơ sở để suy đoán các bộ đệm chưa công bố trong mã nguồn nội bộ của giảng viên.&lt;/p&gt;

&lt;h3 id=&quot;ví-dụ-ánh-xạ-triệu-chứng-lỗi--chương-tương-ứng&quot;&gt;Ví dụ ánh xạ triệu chứng lỗi → chương tương ứng&lt;/h3&gt;

&lt;p&gt;Triệu chứng: “Âm thanh sau khử nhiễu có tiếng rung giật (warble) kiểu robot lặp lại mỗi 10 ms.”&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chương 02&lt;/strong&gt; — kiểm tra lệch kích thước hop, cửa sổ hoặc cộng chồng lấp OLA.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chương 01&lt;/strong&gt; — kiểm tra sai lệch chỉ số bin FFT sau khi lấy mẫu lại (resample).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chương 05&lt;/strong&gt; — kiểm tra hiện tượng underrun gây lặp khung.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chương 04&lt;/strong&gt; — kiểm tra khả năng mặt nạ tuần hoàn quá mạnh — &lt;em&gt;bước cuối cùng&lt;/em&gt;, chỉ xét sau khi đã loại trừ lỗi pipeline.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hiện tượng rung giật chu kỳ 10 ms tương ứng tần số điều biến (100\,\mathrm{Hz}) vì (1/0.010=100). Con số này gợi ý mạnh tới điều biến biên độ theo nhịp hop (Chương 02) trước khi nghi ngờ checkpoint mô hình bị lỗi (Chương 04). Phần Mini-lab dưới đây chuyển phép tính này thành điều kiện kiểm tra đạt/không đạt theo thời gian xử lý p95.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Nhảy thẳng vào trọng số mô hình ở Chương 04 trước khi đảm bảo đúng tần số lấy mẫu và quy tắc gộp kênh mono.&lt;/li&gt;
  &lt;li&gt;Coi tên gói npm là bằng chứng về cấu trúc đồ thị mô hình nội bộ chưa công bố.&lt;/li&gt;
  &lt;li&gt;Chỉ theo dõi một phiên bản ngôn ngữ (EN hoặc VI) mà bỏ sót các bản cập nhật ở ngôn ngữ còn lại.&lt;/li&gt;
  &lt;li&gt;Bỏ qua Chương 08 và vội kết luận hiệu quả chỉ dựa trên một đoạn nghe thử tại quán cà phê.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Liên hệ triệu chứng “rung giật mỗi 10 ms” với bước nhảy hop ở tần số lấy mẫu mặc định 48 kHz, sau đó kiểm tra ngưỡng đạt/không đạt bằng thời gian xử lý p95.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;480&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;warble_hz&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hop_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; warble_if_cola_fails_hz=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warble_hz&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p95_ms&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;6.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;12.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p95_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p95_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hop_ms=10.0 warble_if_cola_fails_hz=100&lt;/code&gt;, tiếp theo là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.0 True&lt;/code&gt;, rồi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;12.0 False&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Đổ lỗi cho &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; trước khi kiểm tra kích thước hop; chấp nhận mức p95 bằng 12 ms chỉ vì thời gian trung bình là 4 ms; hoặc diễn giải sơ đồ LiveKit như đặc tả kiến trúc nội bộ.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Ghi lại nền tảng hiện tại của bạn (DSP: chưa biết / cơ bản / vững; WebAudio: chưa biết / đã dùng) và chọn lộ trình đầy đủ hay rút gọn.&lt;/li&gt;
  &lt;li&gt;Từ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COURSE_OUTLINE.md&lt;/code&gt;, liệt kê bảy tiêu đề bài học tiếng Anh của Chương 01.&lt;/li&gt;
  &lt;li&gt;Nêu ba nguồn công khai hợp lệ được phép trích dẫn khi mô tả hành vi của DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;Viết một tiêu chí nghiệm thu &lt;em&gt;đo lường được&lt;/em&gt; cho bài tập tổng kết (ví dụ: “p95 RTF ≤ 0.5 trên máy X ở 48 kHz mono”).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Nếu chưa có nền tảng DSP và WebAudio, nên đi theo lộ trình đầy đủ. Nếu đã vững DSP nhưng mới làm quen với neural SE, có thể đi theo lộ trình rút gọn nhưng vẫn nên đọc danh mục kiểm tra 01-07 thay vì bỏ hẳn.&lt;/li&gt;
  &lt;li&gt;Bảy tiêu đề tương ứng với trường &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;title:&lt;/code&gt; trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;contents/en/chapter01/_posts/&lt;/code&gt;, theo thứ tự từ 1 đến 7 (từ trực giác Fourier liên tục đến danh mục các bẫy thường gặp).&lt;/li&gt;
  &lt;li&gt;Ba bài báo arXiv:2110.05588, arXiv:2205.05474, arXiv:2305.08227, cùng tệp README tại https://github.com/mezonai/mezon-noise-suppression. Kho mã tham chiếu: https://github.com/Rikorose/DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;Tiêu chí cần ghi rõ cấu hình máy thử nghiệm, tần số lấy mẫu (48 kHz toàn băng nếu bám cấu hình mặc định của sản phẩm), chế độ mono hoặc quy tắc downmix, và một chỉ số phân vị đuôi như p95 RTF. Nhận xét cảm tính như “nghe sạch hơn” không phải là tiêu chí nghiệm thu.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Các tệp &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COURSE_OUTLINE.md&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AGENTS.md&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;README.md&lt;/code&gt; trong kho tài liệu này.&lt;/li&gt;
  &lt;li&gt;Tệp README GitHub công khai: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Trang gói npm: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588), DeepFilterNet2 (arXiv:2205.05474), DeepFilterNet3 (arXiv:2305.08227) cho ngữ cảnh thuật toán, không dùng để suy diễn chi tiết riêng của Mezon.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=spUNpyF58BY&quot;&gt;But what is the Fourier Transform?  A visual introduction.&lt;/a&gt; — 3Blue1Brown, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Giúp hình dung trực quan miền tần số trước khi các chương đầu của lộ trình đi vào định nghĩa toán học và bài toán khử nhiễu.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Đây là đích đến ở phần mạng nơ-ron của lộ trình: đầu vào STFT và đầu ra khử nhiễu toàn băng theo thời gian thực.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Minh họa con đường từ tập dữ liệu mở đến tính năng gọi thoại thực tế; các chương sau sẽ bám sát vòng lặp đánh giá đó.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>00-03 Khử nhiễu thời gian thực và offline</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter00/00_03_realtime_vs_offline/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter00/00_03_realtime_vs_offline</id>
   <content type="html">&lt;p&gt;Việc triển khai thành công một bộ khử nhiễu (NS) vào sản phẩm phụ thuộc ít hơn vào điểm MOS cao nhất trên bảng xếp hạng và phụ thuộc nhiều hơn vào khả năng vận hành ổn định trên luồng âm thanh (audio thread). Bài học này định nghĩa chặt chẽ độ trễ và hệ số thời gian thực (RTF), phân tích các ràng buộc của luồng xử lý streaming, đồng thời liệt kê những chế độ lỗi thường gặp khi gỡ lỗi trong các tích hợp kiểu Mezon.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/realtime-vs-offline.png&quot; alt=&quot;Cùng một bộ khử nhiễu, vẽ một lần là batch offline và một lần là khối streaming nhân quả&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Độ trễ nhìn trước (look-ahead) ở chế độ ngoại tuyến và bước nhảy hop ở chế độ thời gian thực là hai khoản trễ khác nhau; sơ đồ dùng để lập ngân sách độ trễ, không đại diện cho hai thuật toán riêng biệt.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Nếu bạn tải một tập podcast lên phần mềm xử lý âm thanh để làm sạch trước khi đăng YouTube, phần mềm có thể đọc trọn cả 60 phút ghi âm, phân tích trước những đoạn im lặng ở phút thứ 40 để đoán chính xác tiếng ồn nền của căn phòng, rồi chạy một mạng Transformer khổng lồ mất 5 phút mới xong. Nhưng trong một &lt;strong&gt;cuộc gọi thoại trực tiếp&lt;/strong&gt;, bạn không có đặc quyền biết trước người kia sẽ nói gì sau 1 giây nữa! Ranh giới giữa &lt;strong&gt;xử lý thời gian thực (real-time / streaming)&lt;/strong&gt; và &lt;strong&gt;xử lý ngoại tuyến (offline / batch)&lt;/strong&gt; không chỉ là chuyện tốc độ chạy nhanh hay chậm — nó thay đổi hoàn toàn kiến trúc toán học của thuật toán.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bốn-ràng-buộc-kỹ-thuật-tách-biệt-thời-gian-thực-với-ngoại-tuyến-là-gì&quot;&gt;Kiến thức cần nhớ: Bốn ràng buộc kỹ thuật tách biệt Thời gian thực với Ngoại tuyến là gì?&lt;/h2&gt;

&lt;h3 id=&quot;1-tính-nhân-quả-causality-và-cửa-sổ-nhìn-trước-look-ahead&quot;&gt;1. Tính nhân quả (Causality) và Cửa sổ nhìn trước (Look-Ahead)&lt;/h3&gt;
&lt;p&gt;Bộ lọc ngoại tuyến dùng &lt;strong&gt;tích chập hai phía&lt;/strong&gt; và mạng hai chiều (Bi-LSTM / Transformer toàn cục) nhìn thấy cả quá khứ lẫn tương lai. Bộ lọc thời gian thực phải dùng &lt;strong&gt;tích chập nhân quả&lt;/strong&gt; và mạng một chiều (GRU / Uni-LSTM / Causal Conv) với bộ đệm trạng thái ẩn (hidden state) truyền từ khung \(t-1\) sang khung \(t\), chỉ được nhìn trước tối đa 1–2 khung (10–20 ms).&lt;/p&gt;

&lt;h3 id=&quot;2-ngân-sách-độ-trễ-đầucuối-end-to-end-latency-budget&quot;&gt;2. Ngân sách độ trễ đầu–cuối (End-to-End Latency Budget)&lt;/h3&gt;
&lt;p&gt;Theo khuyến nghị &lt;strong&gt;ITU-T G.114&lt;/strong&gt; cho thoại tương tác hai chiều, tổng độ trễ một chiều (từ miệng người nói đến tai người nghe) nên giữ &lt;strong&gt;dưới 150 ms&lt;/strong&gt; để hai người không nói đè lên nhau. Trong 150 ms đó, mạng internet, bộ đệm chống rung (jitter buffer), codec (Opus) và phần cứng loa/micro đã ngốn phần lớn — bộ khử nhiễu thường chỉ được cấp &lt;strong&gt;20–40 ms&lt;/strong&gt;!&lt;/p&gt;

&lt;h3 id=&quot;3-bố-trí-bộ-nhớ-và-quản-lý-trạng-thái-streaming-state&quot;&gt;3. Bố trí bộ nhớ và Quản lý trạng thái (Streaming State)&lt;/h3&gt;
&lt;p&gt;Trong chế độ streaming, thuật toán không được cấp phát bộ nhớ động tùy tiện trên luồng âm thanh (tránh giật do Garbage Collection trên trình duyệt/WASM), mà phải dùng &lt;strong&gt;bộ đệm vòng (ring buffer)&lt;/strong&gt; cố định và lưu giữ chính xác trạng thái chồng lấp (overlap-add buffer) giữa các khung liên tiếp.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-lập-bảng-ngân-sách-độ-trễ-cho-một-cuộc-gọi-webrtc-150-ms&quot;&gt;Giải thích: tự tay lập bảng ngân sách độ trễ cho một cuộc gọi WebRTC 150 ms&lt;/h3&gt;

&lt;p&gt;Hãy cộng từng thành phần độ trễ trên một đường truyền thoại thực tế (một chiều) để thấy tại sao từng khung 10 ms lại quý giá đến thế:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thu âm phần cứng + hệ điều hành (Capture &amp;amp; AudioWorklet):&lt;/strong&gt; \(\approx 15\text{ ms}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Khối khử nhiễu thời gian thực (khung hop 10 ms + look-ahead 20 ms + suy luận 2 ms):&lt;/strong&gt; \(10 + 20 + 2 = \mathbf{32\text{ ms}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nén &amp;amp; giải nén Codec Opus:&lt;/strong&gt; \(\approx 22.5\text{ ms}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Truyền mạng Internet (một chiều) + Jitter Buffer:&lt;/strong&gt; \(40 + 25 = 65\text{ ms}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Phát ra loa (Playout):&lt;/strong&gt; \(\approx 10\text{ ms}\).
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Tổng độ trễ một chiều:&lt;/strong&gt; \(15 + 32 + 22.5 + 65 + 10 = \mathbf{144.5\text{ ms}} &amp;lt; 150\text{ ms}\) (đạt chuẩn trò chuyện tự nhiên!).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Nếu thay bằng một mô hình bán-offline có look-ahead 300 ms:&lt;/strong&gt; tổng độ trễ vọt lên &lt;strong&gt;\(424.5\text{ ms}\)&lt;/strong&gt; (khứ hồi gần 1 giây!) — dù chất lượng âm thanh sạch hơn vài phần trăm, cuộc gọi lập tức trở nên khó chịu vì hai đầu liên tục ngắt lời nhau!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Định nghĩa chính xác độ trễ thuật toán, độ trễ đệm và hệ số thời gian thực (RTF).&lt;/li&gt;
  &lt;li&gt;Giải thích các ràng buộc nhân quả / streaming so với khả năng nhìn trước (look-ahead) của xử lý ngoại tuyến.&lt;/li&gt;
  &lt;li&gt;Liên hệ kích thước khung, bước nhảy hop và ngân sách độ trễ đầu–cuối trong một cuộc gọi.&lt;/li&gt;
  &lt;li&gt;Liệt kê các chế độ lỗi phổ biến: underrun, âm thanh bị cắt khúc, trôi đồng hồ (clock drift) và gián đoạn trạng thái (state discontinuity).&lt;/li&gt;
  &lt;li&gt;Áp dụng tư duy đánh giá “RTF ở trường hợp xấu nhất trên thiết bị đích” khi lựa chọn mô hình.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Định nghĩa độ trễ và RTF kèm ví dụ tính toán&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;Pipeline STFT nhân quả; lý giải vì sao các mô hình SOTA ngoại tuyến thất bại trên WebRTC/LiveKit&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Quản lý trạng thái streaming: bộ đệm OLA và trạng thái ẩn của RNN/DF&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Các chế độ lỗi thực tế và danh mục kiểm tra SLA&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;ba-thành-phần-độ-trễ&quot;&gt;Ba thành phần độ trễ&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Độ trễ đệm (buffering latency)&lt;/strong&gt; — thời gian chờ gom đủ mẫu trước khi có thể xử lý một khung.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ trễ thuật toán (algorithmic latency)&lt;/strong&gt; — gồm khoảng nhìn trước (look-ahead), trễ nhóm của bộ lọc (group delay) và độ trễ từ phép cộng chồng lấp (OLA).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Độ trễ hệ thống (system latency)&lt;/strong&gt; — kích thước quantum của hệ điều hành/callback, cầu nối JS/Wasm và độ rung mạng (network jitter).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;hệ-số-thời-gian-thực-rtf&quot;&gt;Hệ số thời gian thực (RTF)&lt;/h3&gt;

\[\mathrm{RTF} = \frac{T_{\mathrm{proc}}}{T_{\mathrm{audio}}}\]

&lt;p&gt;Hệ thống streaming luôn cần &lt;strong&gt;biên độ an toàn&lt;/strong&gt;: một mô hình có RTF trung bình 0.9 vẫn sẽ gặp lỗi khi trình thu gom rác (GC) hoặc giảm xung do quá nhiệt đẩy thời gian xử lý của một khung lên RTF 2.0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ví dụ:&lt;/strong&gt; Với bước nhảy hop (R=480) mẫu ở tần số (48\,\mathrm{kHz}), mỗi hop tương ứng (10\,\mathrm{ms}). Để giữ ngân sách RTF (\le 0.5), thời gian xử lý (T_{\mathrm{proc}}) cho toàn bộ chuỗi STFT + mô hình + ISTFT (tính khấu hao theo hop) phải thỏa mãn (\le 5\,\mathrm{ms}).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giá trị trung bình đẹp vẫn có thể gây méo tiếng (glitch).&lt;/strong&gt; Giả sử trong 100 hop dài 10 ms, có 99 hop hoàn thành trong 3 ms nhưng 1 hop mất 15 ms. Thời gian xử lý trung bình là ((99\times 3+15)/100=3.12\,\mathrm{ms}), tương ứng RTF trung bình (0.312). Tuy vậy, riêng hop bị chậm có RTF bằng (1.5) và sẽ trượt hạn callback. Do đó, đánh giá hiệu năng bắt buộc phải đo kèm các phân vị đuôi như p95 hoặc p99; nếu chỉ nhìn giá trị trung bình, hiện tượng underrun sẽ bị che khuất.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quantum không đồng nhất với hop.&lt;/strong&gt; Một quantum 128 mẫu ở 48 kHz kéo dài (128/48000\approx 2.67\,\mathrm{ms}), trong khi hop 480 mẫu tương đương (480/128=3.75) quantum. Vì vậy, bộ xử lý phải gom các quantum lẻ vào bộ đệm vòng (ring buffer). DeepFilterNet3 (arXiv:2305.08227) được thiết kế cho chế độ thời gian thực trong họ mô hình này; một checkpoint ngoại tuyến có độ trễ nhìn trước vài trăm ms sẽ không tự động trở thành nhân quả chỉ nhờ được bọc bên trong &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;nhân-quả-và-ngoại-tuyến&quot;&gt;Nhân quả và ngoại tuyến&lt;/h3&gt;

&lt;p&gt;DeepFilterNet2 và DeepFilterNet3 nhấn mạnh thiết kế &lt;strong&gt;thời gian thực / nhân quả&lt;/strong&gt; — đây là lý do khóa học chọn họ mô hình này làm trọng tâm thay vì các mô hình khuếch tán (diffusion) ngoại tuyến.&lt;/p&gt;

&lt;h3 id=&quot;khung-hop-và-độ-trễ&quot;&gt;Khung, hop và độ trễ&lt;/h3&gt;

\[T_{\mathrm{hop}}=\frac{R}{f_s},\qquad T_{\mathrm{win}}=\frac{L}{f_s}\]

&lt;p&gt;Giảm độ dài cửa sổ (L) giúp hạ độ trễ nhưng đánh đổi bằng độ phân giải tần số — nội dung này sẽ được phân tích kỹ ở Chương 02.&lt;/p&gt;

&lt;h3 id=&quot;trạng-thái-streaming&quot;&gt;Trạng thái streaming&lt;/h3&gt;

&lt;p&gt;Một hệ thống streaming phải duy trì liên tục các trạng thái như bộ đệm OLA, bộ ước lượng nhiễu/VAD và trạng thái ẩn hồi tiếp của mạng nơ-ron. Khởi tạo lại từ đầu (cold-start) ở mỗi callback sẽ gây tiếng lách tách (click), còn thay đổi tần số lấy mẫu mà không đặt lại trạng thái sẽ khiến âm thanh bị đục và méo.&lt;/p&gt;

&lt;h3 id=&quot;các-chế-độ-lỗi-thường-gặp&quot;&gt;Các chế độ lỗi thường gặp&lt;/h3&gt;

&lt;p&gt;Các lỗi điển hình bao gồm: hụt đệm/vỡ tiếng (underrun/glitch); tiếng nói bị cắt cụt hoặc méo “ướt”; trôi con trỏ bộ đệm vòng (ring buffer drift); nhiễu đuôi (tail artifacts); và sụt giảm hiệu năng đột ngột do quá nhiệt (thermal throttling).&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ--mô-hình-này-có-triển-khai-được-không&quot;&gt;Ví dụ — mô hình này có triển khai được không?&lt;/h2&gt;

&lt;p&gt;Xét một mô hình ngoại tuyến có độ trễ nhìn trước 300 ms, đạt RTF 0.15 trên GPU nhưng RTF 1.2 trên CPU laptop ở 48 kHz mono. Nếu ngân sách cuộc gọi yêu cầu độ trễ nhìn trước (\le 40\,\mathrm{ms}), mô hình này &lt;strong&gt;không đạt&lt;/strong&gt;. Với RTF 1.2 trên CPU đích, mô hình cũng &lt;strong&gt;không đạt&lt;/strong&gt; trừ khi giảm tần số lấy mẫu, lượng tử hóa hoặc thu gọn kiến trúc.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Trích dẫn số liệu RTF từ bài báo vốn được đo ở chế độ ngoại tuyến với kích thước batch lớn.&lt;/li&gt;
  &lt;li&gt;Bỏ qua độ trễ đuôi (p95/p99).&lt;/li&gt;
  &lt;li&gt;Dùng checkpoint không nhân quả “tạm cho bản demo”.&lt;/li&gt;
  &lt;li&gt;Đo độ trễ bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Date.now()&lt;/code&gt; xuyên qua nhiều tầng đệm ẩn mà không tách rõ từng công đoạn.&lt;/li&gt;
  &lt;li&gt;Nhầm lẫn quantum của AudioWorklet (ví dụ 128 mẫu ≈ 2.67 ms ở 48 kHz) với bước nhảy hop của STFT.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; In ngân sách xử lý cho hop 10 ms ở 48 kHz, đồng thời minh họa tình huống một hop tăng đột biến khiến callback trượt hạn dù RTF trung bình vẫn trông rất an toàn.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;480&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t_audio_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t_proc_max_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t_audio_ms&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mean_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;99&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;quantum_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;t_audio_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t_audio_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; t_proc_max_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t_proc_max_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;mean_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mean_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; mean_rtf=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mean_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t_audio_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;spike_rtf=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t_audio_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;quantum_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;quantum_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; quanta_per_hop=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t_audio_ms=10.0 t_proc_max_ms=5.0&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mean_ms=3.12 mean_rtf=0.312&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;spike_rtf=1.50&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;quantum_ms=2.67 quanta_per_hop=3.75&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Chỉ lấy RTF trung bình mà bỏ qua các điểm tăng đột biến (spike); đồng nhất 128 mẫu với hop 10 ms; hoặc tính ngược công thức RTF khiến máy chậm lại cho ra con số nhỏ hơn.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Với hop 256 mẫu ở tần số 16 kHz, hãy tính độ dài hop (ms) và thời gian xử lý tối đa (T_{\mathrm{proc}}) để đạt RTF 0.25.&lt;/li&gt;
  &lt;li&gt;Liệt kê ba bộ đệm trạng thái mà một hệ thống STFT-NS phải duy trì xuyên suốt giữa các hop.&lt;/li&gt;
  &lt;li&gt;Vì sao một mô hình có RTF trung bình 0.4 vẫn có thể gây vỡ tiếng trên Chrome khi hệ thống chịu tải cao?&lt;/li&gt;
  &lt;li&gt;Đề xuất danh mục kiểm tra go/no-go gồm 5 phép đo trước khi bật mặc định tính năng khử nhiễu.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Độ dài hop là (256/16000=16\,\mathrm{ms}). Với RTF (0.25), thời gian xử lý tối đa cho phép là (4\,\mathrm{ms}).&lt;/li&gt;
  &lt;li&gt;Bộ đệm cộng chồng lấp OLA, bộ đệm cửa sổ phân tích và trạng thái ẩn hồi tiếp của mạng nơ-ron (hoặc bộ theo dõi nền nhiễu); ngoài ra cần theo dõi cấu hình tần số lấy mẫu và số kênh.&lt;/li&gt;
  &lt;li&gt;Giá trị trung bình che lấp các khoảng dừng của GC, hiện tượng quá nhiệt hoặc những hop đơn lẻ vượt quá 16 ms — trong khi audio callback chịu ảnh hưởng trực tiếp bởi độ trễ đuôi (p99).&lt;/li&gt;
  &lt;li&gt;Năm phép đo thiết thực: độ trễ nhìn trước nhân quả (ms), phân vị p95 của RTF trên CPU đích, số lần underrun trong cuộc gọi kéo dài 10 phút, quy tắc gộp kênh stereo và một phiên nghe kiểm tra ở đúng tần số lấy mẫu của sản phẩm.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DeepFilterNet2 (arXiv:2205.05474) và DeepFilterNet3 (arXiv:2305.08227) — các mục về thiết kế thời gian thực / nhân quả. Mã nguồn: https://github.com/Rikorose/DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;Tài liệu tổng quan đồ thị xử lý của WebRTC APM.&lt;/li&gt;
  &lt;li&gt;Tài liệu MDN về AudioWorklet (ràng buộc thời gian của callback).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Quan sát các thông số độ trễ và hệ số thời gian thực đặt cạnh sơ đồ hai tầng; đây chính là phép thử khả năng triển khai mà bài học này định nghĩa.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. Phần phân tích đánh đổi giữa độ phức tạp và chất lượng cho thấy điểm số ngoại tuyến không đại diện cho ngân sách streaming.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, tiếng Anh. Các số đo độ trễ callback minh họa nửa còn lại ở tầng thiết bị: độ trễ nhìn trước của thuật toán và nhịp đồng hồ của audio thread là hai bài toán khác nhau.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>00-02 Các loại nhiễu và mô hình hỗn hợp tiếng nói</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter00/00_02_noise_types/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter00/00_02_noise_types</id>
   <content type="html">&lt;p&gt;Trước khi lựa chọn trừ phổ (spectral subtraction), lọc Wiener hay DeepFilterNet, ta cần một hệ thống thuật ngữ thống nhất về &lt;em&gt;những yếu tố&lt;/em&gt; đang làm suy giảm tín hiệu tiếng nói. Bài học này phân loại các dạng nhiễu và trình bày mô hình hỗn hợp nền tảng mà cả phương pháp cổ điển lẫn mạng nơ-ron đều dựa vào.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/noise-mixture.png&quot; alt=&quot;Tiếng nói sạch, nhiễu cộng, và hỗn hợp trên cùng một trục thời gian&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Mô hình quan sát mặc định của bài toán khử nhiễu (NS) là một phép cộng: micro thu được tổng của tiếng nói và nhiễu, còn bộ khử nhiễu có nhiệm vụ ước lượng lại phần tiếng nói.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Tại sao một bộ khử nhiễu hoạt động hoàn hảo trước tiếng ồn quạt điều hòa đều đều lại bỗng nhiên “bó tay” khi ai đó gõ bàn phím cơ lách cách, hoặc khi bạn đứng trong một căn phòng trống nhiều tiếng vang? Bởi vì dưới con mắt toán học của xử lý tín hiệu, &lt;strong&gt;“nhiễu” không phải là một khái niệm đơn nhất&lt;/strong&gt;: nhiễu dừng (stationary) có phổ gần như đứng yên theo thời gian, nhiễu xung (transient) nổ bùng trong vài mili giây trên mọi tần số, còn tiếng vang phòng (reverberation) lại không phải phép &lt;em&gt;cộng&lt;/em&gt; đơn thuần mà là phép &lt;strong&gt;tích chập&lt;/strong&gt; làm nhòe chính giọng nói của bạn!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-mô-hình-toán-học-của-tiếng-nói-và-nhiễu-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Mô hình toán học của Tiếng nói và Nhiễu đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-mô-hình-hỗn-hợp-cộng-và-tích-chập-phòng-additive-vs-convolutive&quot;&gt;1. Mô hình hỗn hợp cộng và Tích chập phòng (Additive vs. Convolutive)&lt;/h3&gt;
&lt;p&gt;Ở bài toán đơn kênh cơ bản, tín hiệu micro thu được \(y[n]\) được mô hình hóa thành:&lt;/p&gt;

\[y[n] = (h * s)[n] + v[n],\]

&lt;p&gt;trong đó \(s[n]\) là tiếng nói sạch, \(h[n]\) là &lt;strong&gt;đáp ứng xung phòng (Room Impulse Response — RIR)&lt;/strong&gt; gây tiếng vang, và \(v[n]\) là tổng các nguồn nhiễu cộng bên ngoài. Trong trường hợp gần micro ít vang (\(h[n] \approx \delta[n]\)), mô hình rút gọn về dạng cộng cổ điển \(y[n] = s[n] + v[n]\).&lt;/p&gt;

&lt;h3 id=&quot;2-tính-dừng-stationarity-trong-quá-trình-ngẫu-nhiên&quot;&gt;2. Tính dừng (Stationarity) trong Quá trình ngẫu nhiên&lt;/h3&gt;
&lt;p&gt;Một quá trình nhiễu được gọi là &lt;strong&gt;dừng&lt;/strong&gt; (như tiếng quạt, tiếng mưa đều) nếu mật độ phổ công suất của nó thay đổi rất chậm — các bộ lọc cổ điển dễ dàng ước lượng phổ nhiễu ở những khoảng lặng rồi trừ đi. Ngược lại, nhiễu &lt;strong&gt;không dừng&lt;/strong&gt; (tiếng gõ phím, còi xe, giọng người nói nền &lt;em&gt;babble noise&lt;/em&gt;) biến đổi nhanh ngang hoặc nhanh hơn tiếng nói, đòi hỏi mạng học sâu (như DeepFilterNet) phân biệt cấu trúc hài âm của giọng người.&lt;/p&gt;

&lt;h3 id=&quot;3-tỉ-số-tín-hiệu-trên-nhiễu-snr-theo-thang-decibel-db&quot;&gt;3. Tỉ số Tín hiệu trên Nhiễu (SNR) theo thang Decibel (dB)&lt;/h3&gt;
&lt;p&gt;Vì tai người cảm nhận độ lớn âm thanh theo thang logarit, kỹ sư âm thanh đo độ “sạch” hay “bẩn” của tín hiệu bằng &lt;strong&gt;SNR (Signal-to-Noise Ratio)&lt;/strong&gt; tính theo dB: \(\text{SNR}_{\text{dB}} = 10\log_{10}\!\left(\frac{P_s}{P_n}\right)\). Mỗi khi SNR tăng thêm &lt;strong&gt;+3 dB&lt;/strong&gt;, công suất tiếng nói sạch gấp đôi so với nhiễu; còn khi SNR âm (\(&amp;lt; 0\text{ dB}\)), năng lượng nhiễu đã áp đảo cả giọng nói!&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-tính-snr-db-và-nhận-diện-độ-khó-của-3-môi-trường-thực-tế&quot;&gt;Giải thích: tự tay tính SNR (dB) và nhận diện độ khó của 3 môi trường thực tế&lt;/h3&gt;

&lt;p&gt;Giả sử một đoạn giọng nói sạch dài 1 giây có công suất trung bình \(P_s = \frac{1}{N}\sum s[n]^2 = 0.04\) (tương ứng biên độ RMS \(\sqrt{0.04} = 0.20\)). Hãy tính SNR trong ba môi trường thu âm:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Phòng làm việc có điều hòa nhẹ (\(P_n = 0.0004\)):&lt;/strong&gt;
\(\text{SNR} = 10\log_{10}\!\Bigl(\frac{0.04}{0.0004}\Bigr) = 10\log_{10}(100) = \mathbf{+20\text{ dB}}.\)
Công suất giọng nói lớn gấp 100 lần nhiễu — cả lọc cổ điển lẫn mạng nơ-ron đều làm sạch dễ dàng.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Văn phòng mở (\(P_n = 0.01\)):&lt;/strong&gt;
\(\text{SNR} = 10\log_{10}\!\Bigl(\frac{0.04}{0.01}\Bigr) = 10\log_{10}(4) \approx \mathbf{+6.02\text{ dB}}.\)
Giọng nói chỉ mạnh gấp 4 lần nhiễu; nếu nhiễu có tiếng người nền (babble), lọc trừ phổ cổ điển bắt đầu sinh &lt;em&gt;nhiễu nhạc (musical noise)&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quán cà phê rất ồn hoặc ngoài đường phố (\(P_n = 0.16\)):&lt;/strong&gt;
\(\text{SNR} = 10\log_{10}\!\Bigl(\frac{0.04}{0.16}\Bigr) = 10\log_{10}(0.25) \approx \mathbf{-6.02\text{ dB}}!\)
Công suất nhiễu lớn gấp &lt;strong&gt;4 lần&lt;/strong&gt; giọng nói — mắt thường nhìn dạng sóng thời gian gần như không thấy giọng người đâu nữa, và chỉ có phân tích thời gian–tần số (STFT) kết hợp mô hình học sâu mới tách được các vạch hài âm của tiếng nói ra khỏi biển nhiễu!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Phân loại suy giảm cộng tính, suy giảm tích chập và nhiễu không dừng kèm ví dụ kỹ thuật cụ thể.&lt;/li&gt;
  &lt;li&gt;Liên hệ tỷ số tín hiệu trên nhiễu (SNR và segmental SNR) với độ khó cảm thụ và độ nhạy của các chỉ số đánh giá.&lt;/li&gt;
  &lt;li&gt;Phác thảo mô hình sinh dữ liệu đơn kênh theo hướng pipeline DNS.&lt;/li&gt;
  &lt;li&gt;Giải thích khi nào bài toán khử vang phòng (dereverberation) nên được tách khỏi khử nhiễu (NS).&lt;/li&gt;
  &lt;li&gt;Đối chiếu bài toán quan sát đơn kênh và đa kênh ở cấp độ sản phẩm.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Phân loại nhiễu: dừng, không dừng, babble, xung và nhạc nền&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–25&lt;/td&gt;
      &lt;td&gt;Phương trình hỗn hợp, định nghĩa SNR và ví dụ tính toán ở 16 kHz&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;25–40&lt;/td&gt;
      &lt;td&gt;Vang phòng so với nhiễu; đơn kênh so với đa kênh; trực giác về bộ dữ liệu DNS&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;40–50&lt;/td&gt;
      &lt;td&gt;Các bẫy thường gặp: lệch phân bố huấn luyện–kiểm thử, gain riding, và “nhiễu” thực chất là tiếng nói&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;50–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;nhiễu-cộng-tính-giả-định-mặc-định-của-ns&quot;&gt;Nhiễu cộng tính (giả định mặc định của NS)&lt;/h3&gt;

\[y[n] = x[n] + n[n]\]

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nhiễu dừng (stationary)&lt;/strong&gt;: đặc tính thống kê biến đổi chậm theo thời gian (ví dụ hệ thống HVAC).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhiễu không dừng (non-stationary)&lt;/strong&gt;: thay đổi mạnh trong khoảng vài chục mili giây (tiếng va chạm bát đĩa, gõ bàn phím).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Babble&lt;/strong&gt;: tổng hợp giọng nói của nhiều người xung quanh — nếu áp mặt nạ (mask) quá mạnh, bộ lọc rất dễ cắt mất phụ âm của người nói chính.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nhạc / âm thanh media&lt;/strong&gt;: có cấu trúc hài rõ rệt, dễ đánh lừa bộ phát hiện tiếng nói (VAD).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;suy-giảm-tích-chập-vang-phòng&quot;&gt;Suy giảm tích chập (vang phòng)&lt;/h3&gt;

\[y[n] = (x * h)[n] + n[n]\]

&lt;p&gt;Khử vang (dereverberation) có liên hệ gần với khử nhiễu nhưng không đồng nhất với NS. Một mô hình chỉ được huấn luyện trên nhiễu cộng tính sẽ hoạt động kém trong không gian có độ vang lớn (chẳng hạn sảnh rộng hoặc nhà thờ lớn).&lt;/p&gt;

&lt;h3 id=&quot;tỷ-số-tín-hiệu-trên-nhiễu-snr&quot;&gt;Tỷ số tín hiệu trên nhiễu (SNR)&lt;/h3&gt;

\[\mathrm{SNR}_{\mathrm{dB}} = 10\log_{10}\frac{\sum_n x[n]^2}{\sum_n n[n]^2}\]

&lt;p&gt;Segmental SNR lấy trung bình SNR trên từng khung ngắn nên phản ánh sát hơn chất lượng cục bộ theo thời gian, nhưng cả hai chỉ số này đều không thể thay thế đánh giá nghe trực tiếp (listening test). Các mô hình thuộc họ DeepFilterNet vì vậy thường báo cáo SI-SDR và DNSMOS thay vì chỉ báo cáo mức tăng SNR thuần túy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trực giác về con số.&lt;/strong&gt; Nếu tiếng nói có biên độ RMS bằng (0.1) (thang tuyến tính full-scale) và SNR bằng (0\,\mathrm{dB}), thì nhiễu cũng có RMS bằng (0.1), bởi (0\,\mathrm{dB}) tương ứng với &lt;em&gt;công suất&lt;/em&gt; bằng nhau, mà công suất tỷ lệ với bình phương RMS. Khi SNR bằng (-5\,\mathrm{dB}), công suất nhiễu lớn gấp (10^{0.5}\approx 3.16) lần công suất tiếng nói, tức RMS của nhiễu gấp khoảng (1.78) lần RMS tiếng nói — ở mức này, việc nghe hội thoại đã rất khó khăn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SNR từng đoạn không trùng khớp với một con số toàn cục.&lt;/strong&gt; Xét hai khung có cùng độ dài và cùng mức năng lượng tiếng nói bằng 1: khung A có năng lượng nhiễu (0.01) (SNR (20\,\mathrm{dB})), còn khung B có năng lượng nhiễu (\approx 3.16) (SNR (-5\,\mathrm{dB})). Trung bình SNR theo từng khung là (7.5\,\mathrm{dB}). Tuy nhiên, SNR toàn cục tính trên tổng năng lượng lại cho kết quả:&lt;/p&gt;

\[10\log_{10}\frac{2}{3.17}\approx -2.0\,\mathrm{dB}.\]

&lt;p&gt;Nếu bảng kiểm thử QA chỉ ghi giá trị toàn cục, tệp âm thanh này sẽ bị xếp vào nhóm “dưới 0 dB”; ngược lại, bảng ghi trung bình từng đoạn lại đánh giá là “dương khá”. Do cả hai đều không thay thế được bài kiểm tra nghe, họ DeepFilterNet thường báo cáo đồng thời SI-SDR và các điểm dạng DNSMOS, và kết quả vẫn cần được đọc kèm điều kiện trộn nhiễu thực tế khi triển khai.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanh trượt không làm thay đổi bản chất vật lý của hỗn hợp.&lt;/strong&gt; Gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 cung cấp tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt;. Giá trị này chỉ điều chỉnh mức độ tác động của mô hình đã huấn luyện chứ không làm thay đổi phương trình hỗn hợp (y=x+n); nhiễu babble ở (-5\,\mathrm{dB}) vẫn giữ nguyên độ khó ở mọi mức cài đặt. Tần số lấy mẫu mặc định của sản phẩm là 48 kHz toàn băng (tần số Nyquist là 24 kHz), nên dải phổ nhiễu cần xem xét kéo dài vượt xa vùng formant của nguyên âm.&lt;/p&gt;

&lt;h3 id=&quot;mô-hình-sinh-dữ-liệu-huấn-luyện-kiểu-dns&quot;&gt;Mô hình sinh dữ liệu huấn luyện (kiểu DNS)&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Lấy mẫu tiếng nói sạch (x).&lt;/li&gt;
  &lt;li&gt;Chọn đoạn nhiễu (n) (và tùy chọn tích chập với đáp ứng xung phòng RIR (h)).&lt;/li&gt;
  &lt;li&gt;Điều chỉnh hệ số khuếch đại của (n) để đạt mức SNR mục tiêu, tạo hỗn hợp (y = x*h + n) hoặc (y=x+n).&lt;/li&gt;
  &lt;li&gt;Huấn luyện mô hình dự đoán (x), mặt nạ phổ hoặc hệ số bộ lọc từ (y) (thường trên miền STFT/ERB).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tính đa dạng của dữ liệu&lt;/strong&gt; thường quan trọng hơn việc tinh chỉnh hàm mất mát phức tạp khi môi trường triển khai khác biệt với tập huấn luyện (ví dụ micro trong mũ bảo hiểm rất khác với nhiễu văn phòng trong bộ DNS).&lt;/p&gt;

&lt;h3 id=&quot;đơn-kênh-và-đa-kênh&quot;&gt;Đơn kênh và đa kênh&lt;/h3&gt;

&lt;p&gt;Stack công khai của Mezon theo hướng gói npm tập trung vào &lt;strong&gt;khử nhiễu đơn kênh thời gian thực&lt;/strong&gt; trong trình duyệt và WebRTC. Xử lý đa kênh chỉ được đề cập ở mức ngữ cảnh phần tiền xử lý (front-end) trong Chương 03.&lt;/p&gt;

&lt;h2 id=&quot;ví-dụ-có-số--trộn-tín-hiệu-theo-snr-mục-tiêu&quot;&gt;Ví dụ có số — trộn tín hiệu theo SNR mục tiêu&lt;/h2&gt;

&lt;p&gt;Xuất phát từ định nghĩa SNR (lưu ý hệ số bình phương trên năng lượng):&lt;/p&gt;

\[10\log_{10}\frac{E_x}{\alpha^2 E_n} = S
\quad\Rightarrow\quad
\alpha = \sqrt{\frac{E_x}{E_n}\cdot 10^{-S/10}}.\]

&lt;p&gt;Khi (E_x=E_n), công thức rút gọn thành (\alpha=10^{-S/20}). Với (S=5\,\mathrm{dB}), ta có (\alpha\approx 0.562), tương ứng công suất nhiễu còn khoảng (0.316) lần công suất tiếng nói, sau đó trộn (y=x+\alpha n). Luôn đảm bảo đồng nhất tần số lấy mẫu trước khi trộn. Mini-lab dưới đây kiểm tra cả trường hợp rút gọn (năng lượng bằng nhau) lẫn trường hợp sinh nhiễu ngẫu nhiên có hạt giống cố định (hai năng lượng khác nhau).&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Quy mọi vấn đề âm thanh về “nhiễu”, bao gồm cả tiếng vọng (thuộc phạm vi AEC) và méo do bộ mã hóa (codec).&lt;/li&gt;
  &lt;li&gt;Báo cáo mức cải thiện SNR rất lớn trên các tệp gần như chỉ có khoảng lặng.&lt;/li&gt;
  &lt;li&gt;Huấn luyện trên nhiễu dừng nhưng đem kiểm thử trên nhiễu babble.&lt;/li&gt;
  &lt;li&gt;Sự sai lệch độ lợi (gain) micro giữa môi trường huấn luyện và môi trường thực tế làm lệch phân bố SNR hiệu dụng.&lt;/li&gt;
  &lt;li&gt;Kỳ vọng bộ khử nhiễu đơn kênh có thể tách bạch hai người nói có mức năng lượng ngang nhau.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Trộn một sóng sin (đóng vai trò tiếng nói) với nhiễu Gauss sinh theo hạt giống cố định để đạt SNR mục tiêu 5 dB, sau đó in hệ số (\alpha) vừa áp dụng.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;default_rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16_000&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;220&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;en&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s_db&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;5.0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sqrt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;en&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s_db&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;measured&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;snr_db=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;measured&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;alpha_equal_energy=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s_db&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alpha=0.039870&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;snr_db=5.00&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alpha_equal_energy=0.562341&lt;/code&gt;. Giá trị SNR đo lại khớp chính xác mục tiêu vì (\alpha) được giải trực tiếp từ năng lượng thực của hai tín hiệu; dòng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alpha_equal_energy&lt;/code&gt; chỉ là công thức rút gọn (10^{-S/20}) khi hai năng lượng bằng nhau, không phải hệ số cho lần sinh mẫu này.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Nhân nhiễu với (10^{-S/10}) mà quên lấy căn bậc hai (gây lệch 10 dB khi yêu cầu 5 dB); trộn tín hiệu 48 kHz với nhiễu 16 kHz mà không lấy mẫu lại (resample); hoặc tính SNR từ biên độ RMS nhưng quên bình phương.&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Phân loại các nguồn sau vào nhóm cộng tính, tích chập hoặc cả hai: tiếng gõ bàn phím, tiếng HVAC, tiếng TV phát nền dưới lời nói, và tiếng vang trong ga tàu điện.&lt;/li&gt;
  &lt;li&gt;Tính (\alpha) khi (E_x=E_n) và SNR mục tiêu (S = 5\,\mathrm{dB}).&lt;/li&gt;
  &lt;li&gt;Vì sao SI-SDR có thể tăng nhưng người nghe vẫn cảm thấy khó chịu? Nêu một dạng méo âm (artifact) minh họa.&lt;/li&gt;
  &lt;li&gt;Mô tả cách một đợt nhiễu bùng nổ không dừng làm sai lệch bộ theo dõi nền nhiễu cập nhật chậm.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Tiếng gõ bàn phím là nhiễu cộng dạng xung; HVAC là nhiễu cộng biến đổi chậm; tiếng thoại từ TV là nhiễu cộng dạng babble; vang trong ga tàu điện là suy giảm tích chập, thường đi kèm nhiễu cộng.&lt;/li&gt;
  &lt;li&gt;Khi năng lượng hai tín hiệu bằng nhau và (S=5), ta có (\alpha=10^{-5/20}\approx 0.562).&lt;/li&gt;
  &lt;li&gt;Nhiễu nhạc (musical noise): một số bin tần số bật tắt rời rạc theo thời gian. SI-SDR vẫn có thể cải thiện trong khi âm thanh tạo ra rất khó chịu với tai người.&lt;/li&gt;
  &lt;li&gt;Bộ làm mượt có hằng số thời gian dài giữ lại ước lượng nền cũ nên nhận nhầm đợt nhiễu bùng nổ là tiếng nói và cho lọt qua; sau khi đợt nhiễu kết thúc, mức nền ước lượng vẫn còn cao và làm suy hao các nguyên âm kế tiếp.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Tài liệu mô tả bộ dữ liệu nhiễu/tiếng nói DNS Challenge và tổng quan các hạng mục.&lt;/li&gt;
  &lt;li&gt;Ghi chú thiết kế của SpeexDSP / WebRTC NS (các giả định tiên nghiệm cổ điển).&lt;/li&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588), DeepFilterNet2 (arXiv:2205.05474), DeepFilterNet3 (arXiv:2305.08227) — phần trình bày mô hình hỗn hợp cộng trên miền STFT. Mã nguồn: https://github.com/Rikorose/DeepFilterNet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Chú ý phần dữ liệu: cách nhiễu dừng, các sự kiện thoáng qua và tiếng nói cạnh tranh được trộn có chủ đích, tương ứng trực tiếp với hệ thống phân loại nhiễu trong bài.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xb--68NlxS0&quot;&gt;Spectral Subtraction In Python - Alexx Mitchell&lt;/a&gt; — The Audio Programmer, tiếng Anh. Minh họa nhiễu trắng và sơ đồ trừ phổ biên độ dựa trên đúng giả định hỗn hợp cộng tính đã nêu.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Dùng đoạn nghe thử này để cảm nhận trực tiếp nhiễu không dừng — dạng suy giảm mà một con số nền nhiễu tĩnh không thể mô tả đầy đủ.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01 Vì sao khử nhiễu thời gian thực quan trọng</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/vi/chapter00/00_01_problem_and_motivation/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/vi/chapter00/00_01_problem_and_motivation</id>
   <content type="html">&lt;p&gt;Khử nhiễu thời gian thực (real-time noise suppression, NS) là ràng buộc sản phẩm quyết định liệu một cuộc gọi có thể sử dụng ổn định trong văn phòng mở, ngoài đường phố hay bên cạnh bàn phím cơ hay không. Bài học này định khung &lt;em&gt;bài toán&lt;/em&gt; trước khi đi sâu vào thuật toán: ai quan tâm đến bài toán này, tiêu chí “tốt” được hiểu như thế nào, và khóa học gắn với bề mặt công khai của sản phẩm Mezon ra sao.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/realtime-vs-offline.png&quot; alt=&quot;Xử lý offline cả file đặt cạnh đường thoại nhân quả, không nhìn được tương lai&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hình. Bộ khử nhiễu thời gian thực chỉ được sử dụng các mẫu tính đến thời điểm hiện tại, cộng thêm một ngân sách nhìn trước (look-ahead) nhỏ; trong khi đó, bộ xử lý ngoại tuyến (offline) có thể quan sát toàn bộ tệp âm thanh.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bạn đang họp trực tuyến quan trọng từ một quán cà phê đông đúc: tiếng máy pha espresso rít lên, tiếng gõ bàn phím cơ lách cách ngay sát micro, và tiếng quạt điều hòa ù nền đều đều. Nếu đầu dây bên kia vẫn nghe giọng bạn trong trẻo, tự nhiên mà không bị trễ nửa giây, đó là nhờ một &lt;strong&gt;bộ khử nhiễu thời gian thực (Real-Time Noise Suppression)&lt;/strong&gt; đang âm thầm xử lý 48.000 mẫu âm thanh mỗi giây ngay trên thiết bị của bạn — chỉ với vài mili giây ngân sách tính toán cho mỗi khung âm thanh!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;kiến-thức-cần-nhớ-bài-toán-khử-nhiễu-thời-gian-thực-đứng-trên-ba-trụ-cột-nào&quot;&gt;Kiến thức cần nhớ: Bài toán Khử nhiễu Thời gian thực đứng trên ba trụ cột nào?&lt;/h2&gt;

&lt;h3 id=&quot;1-xử-lý-tín-hiệu-số-dsp-nhân-quả&quot;&gt;1. Xử lý tín hiệu số (DSP) nhân quả&lt;/h3&gt;
&lt;p&gt;Một hệ thống &lt;strong&gt;nhân quả (causal)&lt;/strong&gt; tại thời điểm \(t\) chỉ được phép nhìn dữ liệu từ quá khứ đến hiện tại (\(x[\tau]\) với \(\tau \le t\)), cộng thêm tối đa một cửa sổ nhìn trước (look-ahead) rất nhỏ (10–20 ms). Khác với xử lý ngoại tuyến (offline) được đọc trước cả tệp âm thanh, bài toán thời gian thực là cuộc đánh đổi khắt khe giữa chất lượng âm thanh và độ trễ.&lt;/p&gt;

&lt;h3 id=&quot;2-tâm-âm-học-psychoacoustics-và-ba-mục-tiêu-đánh-giá&quot;&gt;2. Tâm âm học (Psychoacoustics) và Ba mục tiêu đánh giá&lt;/h3&gt;
&lt;p&gt;Một bộ lọc xóa sạch nhiễu nhưng làm giọng người méo mó như robot là một bộ lọc thất bại. Ngành xử lý tiếng nói tách rạch ròi ba tiêu chí: &lt;strong&gt;Độ rõ (Intelligibility — đo bằng STOI)&lt;/strong&gt; để nghe ra từng âm tiết, &lt;strong&gt;Chất lượng cảm thụ (Perceptual Quality — đo bằng PESQ / DNSMOS)&lt;/strong&gt; để nghe tự nhiên dễ chịu, và &lt;strong&gt;Độ thân thiện với ASR (WER)&lt;/strong&gt; để máy nhận dạng giọng nói không bị nhầm từ.&lt;/p&gt;

&lt;h3 id=&quot;3-kỹ-thuật-hệ-thống-thời-gian-thực-và-hệ-số-rtf&quot;&gt;3. Kỹ thuật hệ thống thời gian thực và Hệ số RTF&lt;/h3&gt;
&lt;p&gt;Trong sản phẩm thật (như WebRTC hay gói &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; của Mezon), một mô hình dù đạt điểm chuẩn cao đến đâu cũng vô dụng nếu &lt;strong&gt;Hệ số thời gian thực (Real-Time Factor — RTF)&lt;/strong&gt; vượt ngưỡng: \(\text{RTF} = \frac{T_{\text{xử lý}}}{T_{\text{khung}}} &amp;lt; 1\) (trong thực tế thường đòi hỏi \(\text{RTF} \le 0.25\) để chừa CPU cho video, mạng và hệ điều hành).&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;giải-thích-tự-tay-tính-ngân-sách-độ-trễ-và-rtf-cho-một-khung-thoại-10-ms&quot;&gt;Giải thích: tự tay tính ngân sách độ trễ và RTF cho một khung thoại 10 ms&lt;/h3&gt;

&lt;p&gt;Giả sử bạn triển khai bộ khử nhiễu ở tần số lấy mẫu chuẩn băng rộng đầy đủ \(f_s = 48\,000\text{ Hz}\) với bước nhảy (hop) \(H = 480\text{ mẫu}\):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thời lượng một khung âm thanh:&lt;/strong&gt;
\(T_{\text{khung}} = \frac{480}{48\,000} = 0.010\text{ giây} = \mathbf{10\text{ ms}}.\)
Nghĩa là cứ đúng mỗi 10 ms, hệ thống âm thanh lại ném vào bộ lọc một gói 480 mẫu mới.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kiểm tra hệ số thời gian thực (RTF):&lt;/strong&gt; Nếu mô hình mạng nơ-ron trên CPU mất \(T_{\text{xử lý}} = 1.8\text{ ms}\) để lọc xong 1 khung:
\(\text{RTF} = \frac{1.8\text{ ms}}{10\text{ ms}} = \mathbf{0.18} \ll 1 \quad (\text{chạy mượt mà, chiếm } 18\% \text{ một nhân CPU}).\)
Nếu mô hình nặng hơn tốn \(12\text{ ms/khung}\), \(\text{RTF} = 1.2 &amp;gt; 1\): hàng đợi âm thanh sẽ ứ đọng dần rồi &lt;strong&gt;rớt gói, rè tiếng&lt;/strong&gt; ngay lập tức!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tính tổng độ trễ thuật toán:&lt;/strong&gt; Nếu bộ lọc dùng cửa sổ FFT \(20\text{ ms}\) (chồng lấp 50%) và nhìn trước 2 khung (\(20\text{ ms}\)), thì độ trễ tối thiểu của riêng khối khử nhiễu là:
\(L_{\text{NS}} = T_{\text{khung}} + T_{\text{look-ahead}} + T_{\text{xử lý}} = 10 + 20 + 1.8 = \mathbf{31.8\text{ ms}},\)
nằm gọn trong ngân sách cuộc gọi hai chiều mượt mà!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mục-tiêu-học-tập&quot;&gt;Mục tiêu học tập&lt;/h2&gt;

&lt;p&gt;Sau khoảng 60 phút, bạn cần nắm được các nội dung sau:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Giải thích vì sao khử nhiễu (NS) đơn kênh là yêu cầu cốt lõi trong VoIP, họp trực tuyến và các giao diện thoại nhúng.&lt;/li&gt;
  &lt;li&gt;Phân biệt ba mục tiêu tăng cường tiếng nói: &lt;strong&gt;độ rõ (intelligibility)&lt;/strong&gt;, &lt;strong&gt;chất lượng cảm thụ (perceptual quality)&lt;/strong&gt; và đầu vào &lt;strong&gt;thân thiện với ASR&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Phân biệt khử nhiễu thời gian thực / nhân quả với xử lý ngoại tuyến theo ngôn ngữ sản phẩm (độ trễ và hệ số thời gian thực RTF).&lt;/li&gt;
  &lt;li&gt;Đặt khóa học trong ngữ cảnh công khai của Mezon (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt;, gói npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;) mà không suy đoán các chi tiết nội bộ chưa công bố.&lt;/li&gt;
  &lt;li&gt;Nêu rõ những phần &lt;em&gt;không&lt;/em&gt; nằm trong trọng tâm của khóa học (chẳng hạn toàn bộ stack AEC/AGC).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;kế-hoạch-giảng-60-phút&quot;&gt;Kế hoạch giảng 60 phút&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Phút&lt;/th&gt;
      &lt;th&gt;Hoạt động&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–8&lt;/td&gt;
      &lt;td&gt;Khởi động: phân tích ba bối cảnh thực tế (hệ thống điều hòa văn phòng, đường phố, bàn phím cơ) để thấy yếu tố nào làm hỏng cuộc gọi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;8–20&lt;/td&gt;
      &lt;td&gt;Mục tiêu sản phẩm: độ rõ, chất lượng cảm thụ và đầu vào ASR; ánh xạ sang các chế độ lỗi tương ứng&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;20–35&lt;/td&gt;
      &lt;td&gt;Ràng buộc thời gian thực: độ trễ khung, RTF; lý giải vì sao các mô hình SOTA ngoại tuyến thường không thể triển khai trực tiếp&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;35–48&lt;/td&gt;
      &lt;td&gt;Ngữ cảnh Mezon và DeepFilterNet (chỉ xét bề mặt công khai) cùng phạm vi khóa học&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;48–60&lt;/td&gt;
      &lt;td&gt;Bài tập nhỏ và thảo luận các bẫy thường gặp&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;giải-thích-cốt-lõi&quot;&gt;Giải thích cốt lõi&lt;/h2&gt;

&lt;h3 id=&quot;nhiễu-như-một-ràng-buộc-sản-phẩm&quot;&gt;Nhiễu như một ràng buộc sản phẩm&lt;/h3&gt;

&lt;p&gt;Trong sản phẩm thoại, nhiễu không chỉ là thành phần (n(t)) trên giấy mà là &lt;strong&gt;mức cam kết chất lượng (SLA) mà người dùng trực tiếp cảm nhận&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Văn phòng / hệ thống HVAC&lt;/strong&gt;: nhiễu gần dừng (quasi-stationary) ở tần số thấp; các bộ ước lượng cổ điển xử lý tương đối tốt, nhưng nếu bỏ qua sẽ gây cảm giác khó chịu kéo dài.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đường phố / quán cà phê&lt;/strong&gt;: các đợt nhiễu bùng nổ không dừng; bộ theo dõi nền nhiễu cổ điển thường đáp ứng chậm, nên mô hình mạng nơ-ron (neural) mới thực sự phát huy giá trị.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bàn phím / chuột&lt;/strong&gt;: xung băng rộng, xuyên thẳng qua vùng formant của tiếng nói.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Babble (nhiều người nói xung quanh)&lt;/strong&gt;: trường hợp khó nhất đối với xử lý đơn kênh vì “nhiễu” có cùng cấu trúc thời gian–tần số với tín hiệu đích.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Một khối NS dùng được trong sản phẩm phải giảm được các thành phần nhiễu trên mà không biến giọng nói thành âm thanh bị méo “ướt”, không cộng thêm hàng chục mili giây làm gián đoạn nhịp hội thoại, và không tiêu tốn CPU quá mức khiến callback của AudioWorklet bị hụt dữ liệu (underrun).&lt;/p&gt;

&lt;h3 id=&quot;ba-mục-tiêu-tăng-cường-không-nên-đánh-đồng&quot;&gt;Ba mục tiêu tăng cường (không nên đánh đồng)&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Độ rõ (intelligibility)&lt;/strong&gt; — người nghe (hoặc hệ thống nhận dạng tiếng nói ASR) có nhận diện đúng từng từ hay không. Méo phổ làm cắt mất phụ âm có thể khiến phổ đồ (spectrogram) &lt;em&gt;trông&lt;/em&gt; sạch hơn nhưng lại làm giảm độ rõ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Chất lượng cảm thụ&lt;/strong&gt; — được đo qua các thang như MOS hoặc DNSMOS: ít tiếng rít, ít nhiễu nhạc (musical noise) và giữ được âm sắc (timbre) tự nhiên.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Đầu vào cho ASR&lt;/strong&gt; — một số pipeline tối ưu trực tiếp tỷ lệ lỗi từ (WER); việc khử nhiễu quá mạnh dù dễ nghe với người dùng đôi khi lại &lt;em&gt;gây hại&lt;/em&gt; cho ASR vì làm mất các đặc trưng mà bộ nhận dạng cần.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Các chỉ số đo lường cổ điển (như SI-SDR) và chỉ số cảm thụ (như DNSMOS) thường không đồng thuận với nhau, do đó đội ngũ sản phẩm cần xác định rõ mục tiêu ưu tiên. Khóa học này tập trung vào &lt;strong&gt;chất lượng hội thoại thời gian thực&lt;/strong&gt; theo định hướng Mezon / WebRTC, đồng thời trang bị công cụ đánh giá ở Chương 08.&lt;/p&gt;

&lt;h3 id=&quot;thời-gian-thực-và-ngoại-tuyến-xem-chi-tiết-ở-bài-00-03&quot;&gt;Thời gian thực và ngoại tuyến (xem chi tiết ở bài 00-03)&lt;/h3&gt;

&lt;p&gt;Xử lý ngoại tuyến (offline) có thể sử dụng toàn bộ câu nói, ngữ cảnh hai chiều và các mô hình lớn. Ngược lại, xử lý thời gian thực bắt buộc phải &lt;strong&gt;nhân quả (causal)&lt;/strong&gt;: tại thời điểm (t), hệ thống chỉ được sử dụng dữ liệu âm thanh tính đến (t) (cộng thêm một khoảng nhìn trước look-ahead nhỏ được thiết kế có chủ đích).&lt;/p&gt;

&lt;p&gt;Hai đại lượng chính chi phối các buổi đánh giá thiết kế là:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Độ trễ thuật toán và bộ đệm (ms)&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hệ số thời gian thực (Real-Time Factor, RTF)&lt;/strong&gt;: tỷ số giữa thời gian xử lý thực tế (wall-clock) và thời lượng đoạn âm thanh. Với luồng thời gian thực (streaming), cần đảm bảo RTF ở trường hợp xấu nhất (\ll 1) trên &lt;em&gt;đúng thiết bị đích&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;mô-hình-hỗn-hợp-phương-trình-nền-tảng&quot;&gt;Mô hình hỗn hợp (phương trình nền tảng)&lt;/h3&gt;

\[y(t) = x(t) + n(t)\]

&lt;p&gt;Sau khi áp dụng biến đổi STFT:&lt;/p&gt;

\[Y(\ell,k) = X(\ell,k) + N(\ell,k)\]

&lt;p&gt;Phần lớn các phương pháp khử nhiễu cổ điển lẫn mạng nơ-ron đều là chiến lược ước lượng (X) (hoặc ước lượng mặt nạ / hệ số bộ lọc) từ (Y) dưới ràng buộc thời gian thực. Hiện tượng vang phòng (reverb) là một bài toán &lt;em&gt;liên quan nhưng tách biệt&lt;/em&gt;:&lt;/p&gt;

\[y(t) = (x * h)(t) + n(t)\]

&lt;h3 id=&quot;ngữ-cảnh-sản-phẩm-mezon-chỉ-dựa-trên-thông-tin-công-khai&quot;&gt;Ngữ cảnh sản phẩm Mezon (chỉ dựa trên thông tin công khai)&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Kho mã nguồn GitHub: &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Gói npm: &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Đường dẫn nội bộ trên máy giảng viên (không bắt buộc với học viên): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Khóa học này &lt;strong&gt;dạy nguyên lý kỹ thuật&lt;/strong&gt;, không dừng lại ở việc “gọi một gói bọc (wrapper) npm”. Bài tập tổng kết (Capstone) ở Chương 09 yêu cầu học viên nắm vững toàn bộ pipeline xử lý, không phải dịch ngược (reverse-engineer) các phần nội bộ chưa công bố.&lt;/p&gt;

&lt;h3 id=&quot;phạm-vi-khóa-học&quot;&gt;Phạm vi khóa học&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Trong phạm vi&lt;/th&gt;
      &lt;th&gt;Ngoài trọng tâm&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Định khung, STFT, khử nhiễu cổ điển, DeepFilterNet, RTF, ORT/WASM, tích hợp WebRTC/LiveKit, chỉ số đánh giá&lt;/td&gt;
      &lt;td&gt;Thiết kế AEC đầy đủ, beamforming phần cứng, các chi tiết nội bộ chưa công bố của Mezon&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;AEC/AGC/WebRTC APM ở mức &lt;em&gt;ngữ cảnh&lt;/em&gt; (Chương 03)&lt;/td&gt;
      &lt;td&gt;Thay thế toàn bộ WebRTC APM&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;ví-dụ-có-số--phác-thảo-ngân-sách-độ-trễ&quot;&gt;Ví dụ có số — phác thảo ngân sách độ trễ&lt;/h2&gt;

&lt;p&gt;Giả sử một sản phẩm họp trực tuyến yêu cầu độ trễ đệm thuật toán (\le 40\,\mathrm{ms}) tính từ callback micro cho đến khi có dữ liệu PCM sạch đưa vào bộ mã hóa (encoder).&lt;/p&gt;

&lt;p&gt;Xét cấu hình (f_s = 48\,\mathrm{kHz}), cửa sổ (L = 480) mẫu (10 ms), bước nhảy hop (R = 240) mẫu (5 ms), và mô hình cần thêm một khung nhìn trước (look-ahead).&lt;/p&gt;

&lt;p&gt;Tại tần số lấy mẫu 48 kHz, mỗi 1 ms tương ứng 48 mẫu, do đó ngân sách 40 ms tương đương (40\times 48=1920) mẫu. Riêng việc chờ gom đủ cửa sổ 480 mẫu đã chiếm 10 ms; cộng thêm một hop nhìn trước 5 ms, phần còn lại của phác thảo này chỉ còn 25 ms. Xét một tình huống khác: nếu thời gian suy luận (forward) mất 8 ms trên một hop dài 20 ms thì RTF bằng (8/20=0.40). Nếu cùng khối xử lý đó mất 22 ms thì RTF tăng lên (1.1), dẫn đến underrun, trừ khi ta kéo dài hop hoặc thu gọn mô hình. Phần Mini-lab dưới đây kiểm tra lại nhóm tham số đầu tiên.&lt;/p&gt;

&lt;h2 id=&quot;bẫy-thường-gặp&quot;&gt;Bẫy thường gặp&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Tối ưu SI-SDR ngoại tuyến rồi đưa cùng checkpoint đó vào luồng thời gian thực mà không đo độ trễ nhân quả và RTF trên thiết bị đích.&lt;/li&gt;
  &lt;li&gt;Sử dụng “% giảm nhiễu” làm chỉ số kiểm thử (QA) dù khái niệm này không được định nghĩa chặt chẽ.&lt;/li&gt;
  &lt;li&gt;Giả định bộ khử nhiễu đơn kênh (mono) có thể chạy trực tiếp trên tín hiệu stereo mà không có chính sách gộp kênh (downmix).&lt;/li&gt;
  &lt;li&gt;Đổ lỗi cho mô hình mạng nơ-ron trong khi lỗi thực sự nằm ở lệch tần số lấy mẫu (sample rate), sai kích thước hop hoặc lệch cửa sổ cộng chồng lấp (OLA).&lt;/li&gt;
  &lt;li&gt;Suy diễn “bí mật nội bộ của Mezon” từ nội dung khóa học — cần bám sát thông tin công khai và các bài báo khoa học về DeepFilterNet.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mục tiêu.&lt;/strong&gt; Tính lại phác thảo ngân sách ở 48 kHz bằng mã lệnh để tác động của việc đổi hop được thể hiện minh bạch thay vì ẩn trong bảng tính.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;budget_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;240&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;480&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;40.0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;window_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;window&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hop_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; window_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;window_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;samples_per_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; budget_samples=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;budget_ms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;remaining_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;budget_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;window_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; rtf=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kết quả kỳ vọng.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hop_ms=5.0 window_ms=10.0&lt;/code&gt;, tiếp theo là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;samples_per_ms=48 budget_samples=1920&lt;/code&gt;, và cuối cùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;remaining_ms=25.0 rtf=0.40&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lỗi thường gặp.&lt;/strong&gt; Đảo nhầm giữa kích thước hop và độ dài cửa sổ, đếm số mẫu theo 16 kHz trong ngân sách 48 kHz, hoặc định nghĩa ngược RTF (lấy thời lượng âm thanh chia cho thời gian xử lý).&lt;/p&gt;

&lt;h2 id=&quot;bài-tập-nhỏ&quot;&gt;Bài tập nhỏ&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Chọn một đoạn bối cảnh dài 10 giây (ví dụ quán cà phê), liệt kê ba sự kiện nhiễu và phân loại chúng theo nhóm dừng / không dừng / giống tiếng nói.&lt;/li&gt;
  &lt;li&gt;Viết mỗi câu một mục tiêu tương ứng với độ rõ, chất lượng cảm thụ và đầu vào ASR cho phần mềm tổng đài chăm sóc khách hàng (softphone).&lt;/li&gt;
  &lt;li&gt;Với (f_s=16\,\mathrm{kHz}) và bước nhảy hop (R=160), hãy tính độ dài hop (ms) và thời gian xử lý trung bình tối đa để đạt RTF (=0.5).&lt;/li&gt;
  &lt;li&gt;Đọc tệp README công khai của &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt; (khi trực tuyến) và liệt kê ba tính năng &lt;em&gt;đã được tài liệu hóa&lt;/em&gt;, không suy diễn thêm.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gợi-ý-đáp-án&quot;&gt;Gợi ý đáp án&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Tiếng hệ thống HVAC biến đổi chậm (nhiễu dừng); tiếng đóng cửa thay đổi đột ngột (không dừng); người nói chuyện gần micro là nhiễu babble, có đặc trưng tương đồng với tiếng nói.&lt;/li&gt;
  &lt;li&gt;Độ rõ hướng tới việc nhận diện đúng từng từ; chất lượng cảm thụ hướng tới trải nghiệm nghe dễ chịu; đầu vào ASR hướng tới giảm tỷ lệ lỗi từ — mục tiêu thứ ba đôi khi xung đột với hai mục tiêu đầu.&lt;/li&gt;
  &lt;li&gt;Độ dài hop là (160/16000=10\,\mathrm{ms}). Với RTF (=0.5), thời gian xử lý trung bình tối đa cho mỗi hop là (5\,\mathrm{ms}).&lt;/li&gt;
  &lt;li&gt;Chỉ trích dẫn các gạch đầu dòng có trong README (tên gói, runtime, tần số lấy mẫu), không suy đoán cấu trúc đồ thị mô hình chưa công bố.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;đọc-thêm&quot;&gt;Đọc thêm&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Tài liệu WebRTC Audio Processing Module (APM) — mục noise suppression.&lt;/li&gt;
  &lt;li&gt;Schröter và cộng sự, DeepFilterNet (arXiv:2110.05588), DeepFilterNet2 (arXiv:2205.05474), DeepFilterNet3 (arXiv:2305.08227) — phần mở đầu giải thích vì sao khử nhiễu nhân quả là một bài toán sản phẩm. Kho mã nguồn: https://github.com/Rikorose/DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;Trang tổng quan DNS Challenge (bộ dữ liệu và các hạng mục đánh giá).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, tiếng Anh. &lt;strong&gt;Xem trước.&lt;/strong&gt; Video trình bày cách một sản phẩm gọi thoại nhìn nhận nhiễu nền từ phản hồi người dùng trước khi lựa chọn bộ lọc, đúng với khung bài toán của bài học này.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Tác giả giới thiệu bộ khử nhiễu toàn băng (full-band) nhân quả với độ trễ vài mili giây, minh họa trực tiếp ràng buộc thời gian thực đối lập với khử nhiễu ngoại tuyến.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, tiếng Anh. Đoạn nghe thử trước và sau xử lý giúp bạn hình dung trực quan hiệu quả trên nhiễu văn phòng và nhiễu không dừng thay vì chỉ nhìn bảng chỉ số.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>10-03 Maintaining this course</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter10/10_03_course_changelog/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter10/10_03_course_changelog</id>
   <content type="html">&lt;p&gt;This course is a full set of English and Vietnamese articles across Chapters 00–10. APIs still move. The npm package, the CDN &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; layout, DeepFilterNet weights, and LiveKit’s TrackProcessor hook will drift, and a lesson that quotes them will drift with them. Maintainers keep the pair of languages in one change, regenerate figures instead of editing PNGs by hand, and treat the shared product repository as upstream reading, not as the homework tree.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/fourier-intuition.png&quot; alt=&quot;Fourier intuition figure used as the maintainer example&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. A sum of tones in time becomes lines in frequency. Maintainers regenerate this PNG, and every other course figure, with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 scripts/generate_course_figures.py&lt;/code&gt;. Output lands in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/generated/&lt;/code&gt;. Lessons embed it as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/img/generated/fourier-intuition.png&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Technical courses rot fast. Within eighteen months, an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnxruntime-web&lt;/code&gt; import path changes, a browser tightens its &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; security policy, a PyTorch ONNX opset deprecates an old flag, or a new open-source denoiser beats the old baseline by 2 dB at half the compute. What separates a living engineering course from an abandoned blog post is &lt;strong&gt;disciplined maintenance&lt;/strong&gt;: pinned versions, automated smoke tests, and a transparent changelog!&lt;/p&gt;

&lt;p&gt;This closing note documents how to maintain, audit, and evolve &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audio-processing-self-learning&lt;/code&gt; cleanly over time—treating course materials with the exact same engineering rigor as production software.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-four-pillars-of-living-technical-course-maintenance&quot;&gt;Key ideas: Four Pillars of Living Technical Course Maintenance&lt;/h2&gt;

&lt;p&gt;Keeping a systems-and-ML course accurate across years relies on four software-engineering habits:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Pinned Toolchains &amp;amp; Reproducible Environments:&lt;/strong&gt; Recording exact tested versions of Python, PyTorch, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnxruntime-web&lt;/code&gt;, Rust (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rustc&lt;/code&gt;), and browser engines prevents silent drift when upstream APIs change.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Automated Verification Over Manual Hopes:&lt;/strong&gt; Code snippets, STFT/SI-SDR unit tests, and MathJax/Markdown link checks should run automatically in CI on every pull request so broken examples never silently reach learners.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Backward-Compatible Changelog Discipline:&lt;/strong&gt; When swapping a benchmark model or updating an ONNX opset, log &lt;em&gt;what&lt;/em&gt; changed, &lt;em&gt;why&lt;/em&gt; (measured metric/latency delta), and &lt;em&gt;which&lt;/em&gt; lesson exercises are affected.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Separating Timeless Fundamentals From Fast-Moving Tooling:&lt;/strong&gt; Fourier analysis, causal latency math, ring buffers, and SI-SDR projection geometry stay valid for decades; isolate volatile npm/WASM version glue in dedicated integration chapters so updates stay surgical.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to patch a lesson when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; or the CDN layout changes, update the Vietnamese twin in the same pull request, add a figure without breaking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;baseurl&lt;/code&gt;, and file a maintenance note that lists both language files. You should also build the site locally and name the failure if &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle exec jekyll build&lt;/code&gt; warns.&lt;/p&gt;

&lt;h2 id=&quot;what-to-watch&quot;&gt;What to watch&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Upstream&lt;/th&gt;
      &lt;th&gt;What breaks&lt;/th&gt;
      &lt;th&gt;What you edit&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; above 1.3.0&lt;/td&gt;
      &lt;td&gt;Public names or the automatic &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; prefix&lt;/td&gt;
      &lt;td&gt;Chapters 07 and 09, both languages&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;CDN layout leaving &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;URLs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;07-03 and 09-01&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;LiveKit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;The publish path in 09-01&lt;/td&gt;
      &lt;td&gt;Re-read &lt;a href=&quot;https://docs.livekit.io/&quot;&gt;docs.livekit.io&lt;/a&gt; and quote the version&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;A new ONNX archive name&lt;/td&gt;
      &lt;td&gt;Asset sentences in 09 and 10&lt;/td&gt;
      &lt;td&gt;The filename only, after you see it&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DNSMOS checkpoint&lt;/td&gt;
      &lt;td&gt;Chapter 08 tables&lt;/td&gt;
      &lt;td&gt;Pin the new name; do not compare old scores as one series&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Public names to preserve until the README itself changes: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;. Do not document private classes in order to sound precise.&lt;/p&gt;

&lt;h2 id=&quot;changelog-discipline&quot;&gt;Changelog discipline&lt;/h2&gt;

&lt;p&gt;When you change an English lesson, update the Vietnamese twin in the same pull request. Same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chapter&lt;/code&gt;, same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;order&lt;/code&gt;, same filename stem, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lang: en&lt;/code&gt; on one side and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lang: vi&lt;/code&gt; on the other. Code blocks, URLs, and the printed lab floats (13.80 and −10.67, the mixer list &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1.237, -0.237, -0.763, 0.263]&lt;/code&gt;) stay identical. Prose is natural Vietnamese. Keep the English terms SI-SDR, DNSMOS, RTF, and TrackProcessor.&lt;/p&gt;

&lt;p&gt;When you add a figure, put the PNG in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/generated/&lt;/code&gt; and reference it with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/img&lt;/code&gt;. Do not paste a one-off screenshot under a new folder. The generator is:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 scripts/generate_course_figures.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That command rewrites the PNGs in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/generated/&lt;/code&gt;, including &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fourier-intuition.png&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eval-metric-map.png&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;livekit-trackprocessor.png&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet-erb.png&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnx-wasm-path.png&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf-audioworklet.png&lt;/code&gt;. Commit the regenerated PNG with the lesson that embeds it. If you only change a caption, you do not need to regenerate.&lt;/p&gt;

&lt;p&gt;A dated line belongs in the PR body, not only in chat:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;2026-09-23 — Chapters 08–10 EN and VI: figures, mini-labs, answer hints.
             VI twins updated in the same change. No product-repo edits.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;site-build&quot;&gt;Site build&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_config.yml&lt;/code&gt; sets &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;baseurl: /audio-processing-self-learning&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;imgurl: /audio-processing-self-learning/img&lt;/code&gt;. Local preview:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle &lt;span class=&quot;nb&quot;&gt;install
&lt;/span&gt;bundle &lt;span class=&quot;nb&quot;&gt;exec &lt;/span&gt;jekyll serve
&lt;span class=&quot;c&quot;&gt;# http://127.0.0.1:4000/audio-processing-self-learning/&lt;/span&gt;
bundle &lt;span class=&quot;nb&quot;&gt;exec &lt;/span&gt;jekyll build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The published site is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://nglelinh.github.io/audio-processing-self-learning/&lt;/code&gt;. A figure that uses a relative path without &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;site.imgurl&lt;/code&gt; will work on one of those hosts and 404 on the other. After a build, open one Chapter 08 page and one Chapter 10 page and confirm the image request URL contains &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/audio-processing-self-learning/img/generated/&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;advisor-loop-and-the-product-boundary&quot;&gt;Advisor loop and the product boundary&lt;/h2&gt;

&lt;p&gt;Record syllabus requests in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COURSE_OUTLINE.md&lt;/code&gt;. Citation rules live in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AGENTS.md&lt;/code&gt;: DeepFilterNet and DeepFilterNet2/3, the DNS Challenge, WebRTC APM, SpeexDSP, RNNoise, SI-SDR, DNSMOS, ONNX Runtime, and tract. Survey names stay names. Course tasks read &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt;. They do not require &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt;, and they do not take patches there. Students experiment in a personal fork or in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;maintenance-issue-template&quot;&gt;Maintenance issue template&lt;/h2&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Title: [course] Update Ch09 CDN paths for package x.y.z
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Upstream version:
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Broken lesson paths:
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; EN files:
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; VI files:
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Figure touched (img/generated name) or none:
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; jekyll build: pass/fail
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Verified image URL contains site imgurl: yes/no
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;File the issue only when both language files are listed. A fix that lands in English alone is incomplete.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;From the repository root, confirm the generator exists and that every English lesson in Chapters 08–10 still embeds a figure through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;site.imgurl&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; scripts/generate_course_figures.py &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;script_ok
python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
from pathlib import Path
bad = []
paths = list(Path(&quot;contents/en&quot;).glob(&quot;chapter0[89]/_posts/*.md&quot;))
paths += list(Path(&quot;contents/en&quot;).glob(&quot;chapter10/_posts/*.md&quot;))
for p in paths:
    if &quot;site.imgurl&quot; not in p.read_text():
        bad.append(p.name)
print(&quot;bad&quot;, bad or &quot;none&quot;)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;script_ok
bad none
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Failure modes: editing a PNG in an image editor and skipping the script, so the next regeneration wipes the tweak; changing English lab floats and leaving the Vietnamese twin on the old number; a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;baseurl&lt;/code&gt; copied from a different repository name so every image 404s; a pull request that “fixes” a lesson by editing the product repo.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-a-quantitative-maintenance-audit-before-bumping-a-course-dependency&quot;&gt;Worked Numerical Example: A Quantitative Maintenance Audit Before Bumping a Course Dependency&lt;/h3&gt;

&lt;p&gt;Suppose a maintainer wants to upgrade &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnxruntime-web&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v1.17&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v1.20&lt;/code&gt; across Chapters 6–9. Run a crisp 4-point quantitative regression audit before merging:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Audit Check&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Before (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v1.17&lt;/code&gt;)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;After (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v1.20&lt;/code&gt;)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Pass Rule&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Status&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Streaming Parity (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;max |Δ|&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3.2	imes 10^{-6}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2.8	imes 10^{-6}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(&amp;lt; 10^{-5}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Pass&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;WASM SIMD Bundle (Brotli)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1.45	ext{ MB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1.52	ext{ MB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\le +10\%\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Pass (+4.8%)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(\mathrm{RTF}_{p99}\) (48 kHz 10 ms hop)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.38\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.34\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\le 0.40\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Pass (-10.5% faster!)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;All Lab &amp;amp; Exercise Scripts&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;26 / 26 passing&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;26 / 26 passing&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;100% pass&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Pass&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Only when all four objective checks pass does the upgrade land in the changelog with a dated entry—turning course maintenance into a clean, verifiable engineering workflow!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-maintaining-any-technical-learning-repo&quot;&gt;Explanation: Four Rules for Maintaining Any Technical Learning Repo&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test every code snippet against real synthetic audio:&lt;/strong&gt; Even a 0.5-second generated sine wave + white noise fixture in CI catches 95% of broken library imports, shape mismatches, and deprecated kwargs.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Never delete historical context when updating a recommendation:&lt;/strong&gt; Keep a short changelog note explaining &lt;em&gt;why&lt;/em&gt; an older API (like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ScriptProcessorNode&lt;/code&gt;) was replaced by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt;—learners will still encounter legacy code in the wild.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Audit MathJax and formatting automatically:&lt;/strong&gt; Unbalanced double-dollar MathJax delimiters or raw &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|&lt;/code&gt; pipes inside Markdown tables silently break rendering on static Jekyll/GitHub Pages sites unless caught by an automated linter.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Review external links and reference papers annually:&lt;/strong&gt; Prefer archival links (arXiv, DOI, official W3C/MDN specs) over ephemeral blog posts that disappear after two years.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; In the dependency upgrade audit table above, why do we check &lt;strong&gt;both&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;max |Δ| &amp;lt; 1e-5&lt;/code&gt; (numerical parity) and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WASM Brotli size&lt;/code&gt; rather than checking only &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTF&lt;/code&gt;?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Diff the npm README against lesson 09-01 and list one drift risk.&lt;/li&gt;
  &lt;li&gt;Introduce a one-word English typo in a local branch, fix it, and mirror the fix in the Vietnamese file in the same commit. Do not push unless you are the maintainer on duty.&lt;/li&gt;
  &lt;li&gt;Run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle exec jekyll build&lt;/code&gt; and copy any warning that mentions chapters 08–10.&lt;/li&gt;
  &lt;li&gt;Fill the issue template for a fictional 1.4.0 that removes the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; prefix. Mark both EN and VI files.&lt;/li&gt;
  &lt;li&gt;Name the generator command and the two path rules for a new figure.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Likely drift: extra public methods, or a CDN prefix change. Quote the README line you saw.&lt;/li&gt;
  &lt;li&gt;One PR, two files. Front matter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lang&lt;/code&gt; stays put.&lt;/li&gt;
  &lt;li&gt;If the build is not installed, say “jekyll not run” rather than inventing a clean log.&lt;/li&gt;
  &lt;li&gt;EN and VI paths both listed. Figure line “none” unless the diagram changes.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 scripts/generate_course_figures.py&lt;/code&gt; writes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img/generated/&amp;lt;name&amp;gt;.png&lt;/code&gt;. Lessons use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/img/generated/&amp;lt;name&amp;gt;.png&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Runtime and packaging details move. Watch the client-inference path this course cites, and treat a version pin in a lesson as something the changelog has to revisit.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d2N0d6CKrbk&quot;&gt;Group calling architectures in WebRTC: MCU, SFU &amp;amp; P2P&lt;/a&gt; — Tsahi Levent-Levi, English. SFU, MCU, and mesh vocabulary is the WebRTC half of the integration lessons. When a client SDK renames a hook, this architecture is what the prose still has to describe correctly.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=rIAIzf6utOc&quot;&gt;What is a CDN (Content Delivery Network) and How does a CDN Work?&lt;/a&gt; — Cloudflare, English. Cache and origin behavior is the asset half of the changelog: a model URL that used to be fresh can be a stale edge copy.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>10-02 Further learning paths</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter10/10_02_further_paths/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter10/10_02_further_paths</id>
   <content type="html">&lt;p&gt;After the capstone, pick one path and a thirty-day practice that produces files, not a reading list you will not open. The three paths below reuse the evaluation map: intrusive SI-SDR where a clean reference exists, DNSMOS or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; on real audio, a listening note, and RTF when the work is realtime. Adjacent topics are named so you can choose a weekend experiment. They are not a second course you must finish.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Evaluation map used to choose a follow-on project&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Whatever path you pick, the map still applies. A classical filter, a paper reproduction, and a LiveKit policy are all graded by which column they actually move.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Real-time noise suppression is only the front door into modern audio AI. Once you can frame 48 kHz audio cleanly, manage causal streaming state, quantize models to INT8, and evaluate perceptual quality honestly, you already possess &lt;strong&gt;80% of the systems toolkit&lt;/strong&gt; needed for every adjacent frontier in speech and audio—from &lt;strong&gt;streaming Automatic Speech Recognition (ASR)&lt;/strong&gt; and &lt;strong&gt;low-latency Text-to-Speech (TTS)&lt;/strong&gt; to &lt;strong&gt;neural audio codecs&lt;/strong&gt; and &lt;strong&gt;multimodal voice agents&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;This roadmap maps four high-impact next paths and shows exactly which skills transfer directly and what new mathematical tools each frontier adds.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-four-adjacent-frontiers-beyond-noise-suppression&quot;&gt;Key ideas: Four Adjacent Frontiers Beyond Noise Suppression&lt;/h2&gt;

&lt;p&gt;Every major area of modern audio AI builds straight on the streaming DSP + ML foundation you now hold:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Streaming ASR (CTC, RNN-T, Chunked Conformer / Whisper):&lt;/strong&gt; Maps log-Mel spectrograms to text tokens in real time. Adds sequence-alignment losses (CTC / Transducer), beam search, and chunked attention caching (typical latency 160–640 ms).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Neural Audio Codecs (EnCodec, SoundStream, DAC, Mimi):&lt;/strong&gt; Compresses 24–48 kHz audio down to &lt;strong&gt;1.5–6 kbps&lt;/strong&gt; using &lt;strong&gt;Residual Vector Quantization (RVQ)&lt;/strong&gt;—turning continuous audio waveforms into discrete tokens that multimodal LLMs can read and generate natively!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Streaming TTS &amp;amp; Voice Conversion (VITS, Flow Matching, Codec LMs):&lt;/strong&gt; Generates natural speech from text with sub-200 ms time-to-first-audio (TTFA), combining semantic tokens, acoustic flow matching, and streaming neural vocoders.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Full-Duplex Spatial Audio &amp;amp; AEC (Neural Acoustic Echo Cancellation, Beamforming):&lt;/strong&gt; Extends single-mic NS to multi-microphone arrays (spatial filtering / MVDR beamforming) and joint AEC + NS + dereverberation for smart speakers and AR/VR headsets.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to choose classical DSP, neural speech enhancement, or productization, write a thirty-day calendar with a file you will commit each week, and name one adjacent topic with a concrete weekend command or measurement. You should also turn the capstone &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/&lt;/code&gt; tree into a portfolio piece that does not depend on the shared product repo.&lt;/p&gt;

&lt;h2 id=&quot;path-a--classical-depth&quot;&gt;Path A — classical depth&lt;/h2&gt;

&lt;p&gt;Re-implement overlap-add until a sine reconstructs within a tolerance you print. Read SpeexDSP (&lt;a href=&quot;https://github.com/xiph/speexdsp&quot;&gt;https://github.com/xiph/speexdsp&lt;/a&gt;) or WebRTC APM (&lt;a href=&quot;https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/&quot;&gt;https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/&lt;/a&gt;) far enough to say what the noise suppressor block is responsible for, as distinct from AEC. On a stereo file you recorded, describe one beamforming failure (a talker off to the side, a noisy reference mic) without claiming a new algorithm.&lt;/p&gt;

&lt;p&gt;Exit ticket: a note, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-a/when-classical.md&lt;/code&gt;, that shows one clip where a simple spectral gate or Wiener-style gain beats a heavy model on RTF and does not embarrass the listening note. Include SI-SDR only if you still have the clean reference.&lt;/p&gt;

&lt;h2 id=&quot;path-b--neural-speech-enhancement&quot;&gt;Path B — neural speech enhancement&lt;/h2&gt;

&lt;p&gt;Read one primary paper a week from lesson 10-01, starting with arXiv:2110.05588, arXiv:2205.05474, and arXiv:2305.08227. Reproduce one ONNX Runtime or tract timing on a laptop CPU and write RTF as wall time over audio duration, plus the CPU name. If you compare DeepFilterNet3 to an ultra-light name (FastEnhancer, μNet, Fast-ULCNet, GTCRN), keep the comparison on &lt;strong&gt;your&lt;/strong&gt; clips and do not invent a paper URL. Successors DPDFNet, DeepFilterGAN, and HDF-Net are the same kind of pointer: names until you have a real citation in front of you.&lt;/p&gt;

&lt;p&gt;Exit ticket: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-b/table.md&lt;/code&gt; with the six columns from lesson 08-04 and a limits paragraph. No leaderboard language.&lt;/p&gt;

&lt;h2 id=&quot;path-c--productization&quot;&gt;Path C — productization&lt;/h2&gt;

&lt;p&gt;Stay on the public LiveKit path: mic, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, publish. Measure cold-start time of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt; (the prefix 1.3.0 adds for ≥ 1.2.0) on a network you actually have, and repeat with the CDN blocked. Optional Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; remains a stretch alternative to the WASM box. If the backend is passthrough, the portfolio README says so.&lt;/p&gt;

&lt;p&gt;Exit ticket: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-c/design.md&lt;/code&gt; with init time, RTF p95 or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, and the failure log from the blocked CDN.&lt;/p&gt;

&lt;h2 id=&quot;adjacent-weekends&quot;&gt;Adjacent weekends&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Topic&lt;/th&gt;
      &lt;th&gt;Weekend artifact&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;AEC&lt;/td&gt;
      &lt;td&gt;A recording where echo dominates noise, plus a note that NS will not remove it&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Multi-mic&lt;/td&gt;
      &lt;td&gt;One stereo file and a paragraph on which channel you would trust&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Target speaker&lt;/td&gt;
      &lt;td&gt;A babble clip where DNSMOS and your ear disagree&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Codec&lt;/td&gt;
      &lt;td&gt;The same utterance through a low-rate Opus encode before and after NS&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Captions&lt;/td&gt;
      &lt;td&gt;WER or a manual error count on ten sentences, not a MOS claim&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;thirty-day-calendar&quot;&gt;Thirty-day calendar&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Days&lt;/th&gt;
      &lt;th&gt;File you add&lt;/th&gt;
      &lt;th&gt;Done when&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1–3&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;notes/si_sdr.py&lt;/code&gt; re-run of the 13.80 / −10.67 lab&lt;/td&gt;
      &lt;td&gt;Both floats match lesson 08-01&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4–7&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audio/CLIPS.txt&lt;/code&gt; with 20 filenames&lt;/td&gt;
      &lt;td&gt;No scores in the file yet&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;8–14&lt;/td&gt;
      &lt;td&gt;Path MVP (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-a&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-b&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path-c&lt;/code&gt;)&lt;/td&gt;
      &lt;td&gt;A command in the README&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;15–21&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;metrics/suite.md&lt;/code&gt; and one peer listening note&lt;/td&gt;
      &lt;td&gt;Checker from 08-04 prints 6 data rows, or you document fewer and why&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;22–26&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DEMO.md&lt;/code&gt; under five minutes&lt;/td&gt;
      &lt;td&gt;Backup audio named&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;27–30&lt;/td&gt;
      &lt;td&gt;A doc patch in &lt;strong&gt;your&lt;/strong&gt; fork, or an ADR at work&lt;/td&gt;
      &lt;td&gt;No commit to the shared Mezon product repo unless that is your job outside this course&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;portfolio-contents&quot;&gt;Portfolio contents&lt;/h2&gt;

&lt;p&gt;Ship the architecture sketch, the metrics table, the AB protocol in English and Vietnamese, a demo recording at or under three minutes, and the reading cards from 10-01. Strip local absolute paths. The optional instructor checkout is not part of the public portfolio.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Create &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path_plan.md&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;path: A
week1_file: notes/si_sdr.py
weekend: aec
command: python3 notes/si_sdr.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C&lt;/code&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;weekend&lt;/code&gt; must be one of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;aec&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;multimic&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;target&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;codec&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;captions&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;path_plan.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;path_ok&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;path: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;abc&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;weekend_ok&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;aec&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;multimic&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;codec&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;captions&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path_ok&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fix&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;weekend&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;weekend_ok&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fix&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;command:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fix&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;path ok
weekend ok
command ok
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Failure modes: three paths in one month; a weekend topic with no artifact; an RTF goal with no device; a plan that starts by forking nothing and editing the shared product tree.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-computing-the-exact-bitrate-of-a-neural-audio-codec-rvq&quot;&gt;Worked Numerical Example: Computing the Exact Bitrate of a Neural Audio Codec (RVQ)&lt;/h3&gt;

&lt;p&gt;One of the hottest technologies in 2024–2026 audio AI is &lt;strong&gt;Residual Vector Quantization (RVQ)&lt;/strong&gt; inside neural codecs (like EnCodec, DAC, or Moshi’s Mimi). Compute its exact bitrate by hand!&lt;/p&gt;

&lt;p&gt;Suppose a neural encoder downsamples 24 kHz audio by a stride of \(320\) samples per frame:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Token frame rate:&lt;/strong&gt;
\(f_{	ext{tok}} = rac{24{,}000}{320} = 75	ext{ frames/second}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bits per codebook:&lt;/strong&gt; Each RVQ codebook has \(V = 1{,}024 = 2^{10}\) entries \(\implies \log_2(1{,}024) = \mathbf{10	ext{ bits}}\) per token.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Total bitrate across \(Q\) residual codebooks:&lt;/strong&gt;
\(ext{Bitrate} = Q 	imes 10	ext{ bits} 	imes 75	ext{ Hz} = 750\,Q	ext{ bits/s}.\)&lt;/li&gt;
&lt;/ol&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Codebooks \(Q\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Bitrate (kbps)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Compression Ratio vs. 24 kHz 16-bit PCM (384 kbps)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Typical Use Case&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(Q = 2\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1.5	ext{ kbps}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(256	imes\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Ultra-low-bitrate speech / voice LLM&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(Q = 4\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3.0	ext{ kbps}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(128	imes\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Clean conversational voice&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(Q = 8\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(6.0	ext{ kbps}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(64	imes\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High-fidelity speech &amp;amp; music&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Compare that with raw uncompressed 24 kHz 16-bit PCM (\(24{,}000 	imes 16 = 384	ext{ kbps}\)): &lt;strong&gt;64× to 256× compression&lt;/strong&gt; into discrete tokens ready for a Transformer!&lt;/p&gt;

&lt;h3 id=&quot;explanation-how-to-pick-your-next-audio-specialization-strategically&quot;&gt;Explanation: How to Pick Your Next Audio Specialization Strategically&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;If you loved Chapters 5–7 (WASM, Rust, WebRTC, low latency):&lt;/strong&gt; Go deeper into &lt;strong&gt;Native Rust DSP, Neural AEC, or Multi-Mic Beamforming&lt;/strong&gt;—the industry has a massive shortage of engineers who understand both PyTorch and lock-free real-time C++/Rust.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;If you loved Chapters 3–4 (Spectrograms, Neural Nets, Deep Filtering):&lt;/strong&gt; Explore &lt;strong&gt;Neural Audio Codecs (RVQ)&lt;/strong&gt; and &lt;strong&gt;Flow-Matching Speech Restoration&lt;/strong&gt;—the bridge between classic DSP and multimodal voice LLMs.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;If you loved Chapter 8 (Evaluation, Metrics, Listening Tests):&lt;/strong&gt; Specialize in &lt;strong&gt;Voice AI Evaluation &amp;amp; Speech Quality Modeling&lt;/strong&gt;—building automated benchmarks for full-duplex voice agents.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always build one small runnable artifact per new frontier:&lt;/strong&gt; Reading 10 papers on streaming ASR teaches less than wiring one working microphone-to-transcript demo and measuring its real p99 latency.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; Using the RVQ formula above (75 frames/s, 10 bits per codebook), what bitrate in kbps do you get if you use \(Q = 16\) codebooks—and what is the compression ratio relative to 384 kbps PCM?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Fill &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path_plan.md&lt;/code&gt; for the path you will actually do. Run the checker.&lt;/li&gt;
  &lt;li&gt;Write the week-by-week filenames into the same file under the four-line header.&lt;/li&gt;
  &lt;li&gt;Name one upstream doc gap (LiveKit processor page, npm README, or DeepFilterNet README) you could fix with a paragraph, and the paragraph’s claim.&lt;/li&gt;
  &lt;li&gt;Draft the portfolio README section that links the five artifacts. Include the passthrough rule if Rust appears.&lt;/li&gt;
  &lt;li&gt;State which evaluation-map column your path will leave as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; and why.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;One letter. Switching paths on day 20 is a new plan, not a bonus.&lt;/li&gt;
  &lt;li&gt;Filenames must be creatable on your machine. Do not point at the instructor’s home directory.&lt;/li&gt;
  &lt;li&gt;A real gap: the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; prefix, or the difference between &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt; and a failed asset load.&lt;/li&gt;
  &lt;li&gt;Link files, not private repos you cannot share.&lt;/li&gt;
  &lt;li&gt;Real audio leaves SI-SDR as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. A pure DSP reconstruction lab can leave DNSMOS as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=E8HeD-MUrjY&quot;&gt;The Fast Fourier Transform (FFT)&lt;/a&gt; — Steve Brunton, English. &lt;strong&gt;xem trước.&lt;/strong&gt; The classical path starts here: DFT cost, then the FFT you can implement.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. The neural path is this architecture plus the papers, not a new survey of unnamed models.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. The product path is datasets, listening tests, and a complexity budget on a real call.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>10-01 Curated reading list</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter10/10_01_curated_reading/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter10/10_01_curated_reading</id>
   <content type="html">&lt;p&gt;Read three primary sources carefully rather than bookmarking twenty abstracts. Every link below is a real paper, repository, or doc set used in this course. Survey names at the bottom are names only: DPDFNet, DeepFilterGAN, HDF-Net, FastEnhancer, μNet, Fast-ULCNet, GTCRN. Do not invent their titles or URLs. If a reading card needs a fact you have not opened, write “not read” instead of a plausible sentence.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;DeepFilterNet ERB path and deep filter&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The picture you should be able to redraw after reading Schröter et al.: STFT in, ERB gains and a deep filter, ISTFT and overlap-add out. The card template below is how you prove you read it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The speech-enhancement and audio-ML literature publishes hundreds of papers every year at ICASSP, INTERSPEECH, and NeurIPS—and trying to read them chronologically or randomly is a fast track to burnout. The secret to reading audio research like a senior engineer is &lt;strong&gt;triangulation&lt;/strong&gt;: anchor yourself on a small canon of landmark papers that each unlocked a genuinely new architectural paradigm (classical Wiener/MMSE \(o\) RNNoise hybrid \(o\) Conv-TasNet time-domain \(o\) DeepFilterNet complex deep filtering \(o\) modern neural codecs and generative diffusion).&lt;/p&gt;

&lt;p&gt;This curated reading map organizes the essential papers, textbooks, and open-source repositories by &lt;em&gt;what exact engineering bottleneck each one solved&lt;/em&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-five-paradigms-across-the-speech-enhancement-canon&quot;&gt;Key ideas: Five Paradigms Across the Speech-Enhancement Canon&lt;/h2&gt;

&lt;p&gt;Every paper on the reading list sits cleanly inside one of five intellectual lineages:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Classical Statistical DSP (Ephraim–Malah, Boll, Loizou):&lt;/strong&gt; Wiener filtering, spectral subtraction, and MMSE-STSA—teaching you noise-floor tracking, musical noise, and why phase matters.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Psychoacoustic Hybrids (RNNoise, PercepNet, DeepFilterNet):&lt;/strong&gt; Combining ERB/Bark critical bands and pitch/deep filtering with tiny GRUs to achieve sub-millisecond CPU inference at 48 kHz.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;End-to-End Time-Domain Separation (Conv-TasNet, Demucs):&lt;/strong&gt; Replacing fixed STFTs with learned filterbanks and dilated TCNs/U-Nets—great for source separation, revealing the latency-vs-compute trade-offs of raw waveforms.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Perceptual Evaluation &amp;amp; Challenges (DNS Challenge, DNSMOS, SI-SDR / Le Roux et al.):&lt;/strong&gt; Defining how the field measures progress honestly without metric gaming.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Generative Speech Restoration (Score/Diffusion &amp;amp; Flow Matching, Neural Audio Codecs):&lt;/strong&gt; Moving beyond masking (which cannot regenerate destroyed harmonics) to synthesizing clean speech from severely degraded inputs.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to pick three links from the list, fill a four-bullet card for each, and match one filled example closely enough that a grader can see the shape. You should also keep SI-SDR, DNSMOS, RTF, and TrackProcessor as the English terms in your notes even when you write the surrounding prose in Vietnamese.&lt;/p&gt;

&lt;h2 id=&quot;links-you-may-cite&quot;&gt;Links you may cite&lt;/h2&gt;

&lt;p&gt;DeepFilterNet family:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter, Escalante-B., Rosenkranz, Maier. “DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio based on Deep Filtering.” ICASSP 2022. &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;https://arxiv.org/abs/2110.05588&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Schröter et al. “DeepFilterNet2: Towards Real-Time Speech Enhancement on Embedded Devices for Full-Band Audio.” &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;https://arxiv.org/abs/2205.05474&lt;/a&gt; (the later Interspeech 2023 write-up cites this paper as IWAENC 2022).&lt;/li&gt;
  &lt;li&gt;Schröter, Escalante-B., Rosenkranz, Maier. “DeepFilterNet: Perceptually Motivated Real-Time Speech Enhancement.” Interspeech 2023. &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;https://arxiv.org/abs/2305.08227&lt;/a&gt; — this is the DeepFilterNet3 model citation used by the upstream README. The results table in that paper names DeepFilterNet3; the paper title itself does not add a “3.”&lt;/li&gt;
  &lt;li&gt;Code and model archive instructions: &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;https://github.com/Rikorose/DeepFilterNet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Teaching bridges and runtimes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;RNNoise: &lt;a href=&quot;https://github.com/xiph/rnnoise&quot;&gt;https://github.com/xiph/rnnoise&lt;/a&gt; and Valin, “A Hybrid DSP/Deep Learning Approach to Real-Time Full-Band Speech Enhancement,” &lt;a href=&quot;https://arxiv.org/abs/1709.08243&quot;&gt;https://arxiv.org/abs/1709.08243&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;WebRTC APM: &lt;a href=&quot;https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/&quot;&gt;https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SpeexDSP: &lt;a href=&quot;https://github.com/xiph/speexdsp&quot;&gt;https://github.com/xiph/speexdsp&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;ONNX Runtime docs: &lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;https://onnxruntime.ai/docs/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;tract: &lt;a href=&quot;https://github.com/sonos/tract&quot;&gt;https://github.com/sonos/tract&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Evaluation and product:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Le Roux, Wisdom, Erdogan, Hershey. “SDR – Half-baked or Well Done?” ICASSP 2019. Use it for SI-SDR, not as a listening test.&lt;/li&gt;
  &lt;li&gt;DNS Challenge data and baselines: &lt;a href=&quot;https://github.com/microsoft/DNS-Challenge&quot;&gt;https://github.com/microsoft/DNS-Challenge&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;DNSMOS / DNSMOS P.835: Reddy, Gopal, Cutler, Interspeech 2021 and ICASSP 2022. Non-intrusive. No official score threshold lives in this course.&lt;/li&gt;
  &lt;li&gt;LiveKit docs: &lt;a href=&quot;https://docs.livekit.io/&quot;&gt;https://docs.livekit.io/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0: &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;https://www.npmjs.com/package/deepfilternet3-noise-filter&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Product repo (read, do not submit course patches here): &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;https://github.com/mezonai/mezon-noise-suppression&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;card-template&quot;&gt;Card template&lt;/h2&gt;

&lt;p&gt;Four bullets, no more. This is the shape the mini-lab expects.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Source: &amp;lt;url&amp;gt;
- Claim: one sentence from the abstract or README, not a guess.
- Streaming / latency: causal or not, hop or look-ahead if the source states it, else &quot;not stated&quot;.
- What it measures or ships: metrics, a library, or an API. Use SI-SDR, DNSMOS, RTF, TrackProcessor only when the source actually discusses them.
- What I will reuse: one action in your harness or capstone.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Filled example (do not submit this URL as one of your three unless you also write two others):&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Source: https://arxiv.org/abs/2110.05588
- Claim: DeepFilterNet enhances full-band speech with an ERB gain stage plus deep filtering, at low complexity.
- Streaming / latency: The framework targets real-time full-band enhancement; check the paper for the stated window, hop, and any look-ahead before you quote a millisecond figure.
- What it measures or ships: The paper reports intrusive enhancement metrics on its test sets and describes the two-stage filter. It is not a LiveKit TrackProcessor.
- What I will reuse: I will redraw the ERB-plus-deep-filter block in my capstone sketch and I will not describe the npm wrapper as the algorithm.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The example refuses a fake latency number. That refusal is part of the shape. If you open the PDF and find the hop, you may replace “check the paper” with the figure you read, and you should say you read it.&lt;/p&gt;

&lt;h2 id=&quot;how-to-read-one-of-these-in-an-hour&quot;&gt;How to read one of these in an hour&lt;/h2&gt;

&lt;p&gt;Start with the figure, not the related-work section. For a DeepFilterNet paper, find the ERB path and the deep-filter sum. For DNSMOS, confirm it is non-intrusive and write down the listening protocol it was trained to track. For the npm README, copy the public names only: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;, and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; prefix behavior on ≥ 1.2.0. For WebRTC APM or SpeexDSP, note that they are classical baselines, not drop-in weights for the Mezon CDN.&lt;/p&gt;

&lt;p&gt;Survey names, listed so you can recognize them in a talk and then stop: DPDFNet, DeepFilterGAN, HDF-Net, FastEnhancer, μNet, Fast-ULCNet, GTCRN. A card that invents an arXiv id for one of these fails the assignment.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Choose &lt;strong&gt;three&lt;/strong&gt; URLs from the list above. Write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reading_cards.md&lt;/code&gt; with three cards in the four-bullet shape. Then run:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;reading_cards.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sources&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Source:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;bullets&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;- &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sources&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sources&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bullets&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bullets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;has_url&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;https://&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sources 3
bullets 12
has_url True
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Twelve bullets is three cards times four bullets. Failure modes: a card whose claim contradicts the title you did not open; a fabricated URL for GTCRN or DeepFilterGAN; using the filled example as all three cards; translating SI-SDR or DNSMOS into a different acronym.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-comparing-four-landmark-architectures-side-by-side&quot;&gt;Worked Numerical Example: Comparing Four Landmark Architectures Side by Side&lt;/h3&gt;

&lt;p&gt;Use this concrete scale table to orient yourself whenever you open a new speech-enhancement paper:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Landmark Architecture&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Domain / Front-End&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Approx. Params&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Typical Latency&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Core Engineering Breakthrough&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;RNNoise (2017)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;22 Bark bands + pitch&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\sim 88	ext{ K}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(20	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Ultra-tiny hybrid DSP + GRU in pure C&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;DeepFilterNet (2022–23)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;32 ERB + 96 complex DF bins&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\sim 1.8	ext{ M}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(20	ext{–}40	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Two-stage ERB gain + complex deep filtering&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Conv-TasNet (2019)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Learned 1D encoder (raw wave)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\sim 5.1	ext{ M}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2	ext{ ms}\) (causal)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;End-to-end time-domain TCN separation&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;DNS-Demucs (2020)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Waveform U-Net + LSTM&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\sim 18	ext{ M}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(40	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;High-capacity real-time waveform denoising&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Look at the ratio across the table: &lt;strong&gt;DeepFilterNet&lt;/strong&gt; uses &lt;strong&gt;20× more parameters than RNNoise&lt;/strong&gt; to add complex harmonic restoration, yet still stays &lt;strong&gt;10× smaller than Demucs&lt;/strong&gt;—illustrating the exact Pareto frontier between model size, latency, and perceptual quality!&lt;/p&gt;

&lt;h3 id=&quot;explanation-how-to-read-an-audio-paper-in-20-minutes-without-getting-lost&quot;&gt;Explanation: How to Read an Audio Paper in 20 Minutes Without Getting Lost&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Check four numbers on Page 1–3 before reading a single equation:&lt;/strong&gt; Sample rate (16 kHz vs 48 kHz), causal vs. non-causal (algorithmic latency!), MACs/s or RTF on CPU, and parameter count.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always listen to the authors’ audio demo page:&lt;/strong&gt; A paper with +0.8 dB higher SI-SDR can still sound metallic or over-smoothed on real speech; 30 seconds of listening tells you more than three tables.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Spot the &lt;em&gt;delta&lt;/em&gt; from its predecessor:&lt;/strong&gt; Ask &lt;em&gt;“what single bottleneck did the previous paper hit, and what exact mechanism here fixes it?”&lt;/em&gt; (e.g., RNNoise’s real band gains \(o\) DeepFilterNet’s complex deep filter).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reproduce one tiny piece in code:&lt;/strong&gt; Even implementing just the paper’s STFT framing or loss function in 40 lines of Python/Rust cements the idea permanently.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; When comparing two speech-enhancement papers, why is it misleading to compare Paper A’s &lt;strong&gt;16 kHz non-causal&lt;/strong&gt; SI-SDR directly against Paper B’s &lt;strong&gt;48 kHz causal (20 ms latency)&lt;/strong&gt; SI-SDR?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Produce the three cards. Include at least one DeepFilterNet URL and one non-paper URL (repo or docs).&lt;/li&gt;
  &lt;li&gt;After you actually open arXiv:2110.05588, add a fifth private note (not part of the four bullets) with the hop or look-ahead you found, or “I did not find it.”&lt;/li&gt;
  &lt;li&gt;Open the DNS Challenge repo long enough to name one directory or script that is really there. Put that name in the “ships” bullet.&lt;/li&gt;
  &lt;li&gt;Write one sentence on why DNSMOS has no official cutoff in your card.&lt;/li&gt;
  &lt;li&gt;List the survey names you will &lt;strong&gt;not&lt;/strong&gt; cite with a URL.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Paper plus repo is the minimum mix. The npm page and LiveKit docs count as non-papers.&lt;/li&gt;
  &lt;li&gt;Keep the four-bullet contract intact. Extra notes go underneath.&lt;/li&gt;
  &lt;li&gt;Do not describe a file you have not seen. “not stated” is allowed.&lt;/li&gt;
  &lt;li&gt;Reddy, Gopal, and Cutler give a predictor, not a Mezon ship line. Domain shift is the failure mode.&lt;/li&gt;
  &lt;li&gt;DPDFNet, DeepFilterGAN, HDF-Net, FastEnhancer, μNet, Fast-ULCNet, GTCRN.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch this beside the DeepFilterNet paper on the reading list. The talk follows the paper’s block diagram; it does not replace the PDF.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. The DNS Challenge and DNSMOS portions match the dataset and metric readings in the same list.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=spUNpyF58BY&quot;&gt;But what is the Fourier Transform?  A visual introduction.&lt;/a&gt; — 3Blue1Brown, English. Use the visual transform as the intuition under the DSP readings, then return to the formulas.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-05 Capstone checklist & demo day</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter09/09_05_capstone_checklist/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter09/09_05_capstone_checklist</id>
   <content type="html">&lt;p&gt;Demo day is a five-minute proof that the publish path, the metrics, and the limits all exist. A polished title slide with no RTF number and no backup recording is a miss. This checklist is the day-before runbook: commands, files, and the failures you will inject on purpose.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;RTF against the AudioWorklet render quantum&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. RTF is wall time of a quantum divided by the quantum’s duration. A mean below 1 can still overrun if p95 or p99 spills the callback. Log p95, and keep cold-start asset download out of that number.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Demo day has a cruel habit of exposing every shortcut you took at 2 a.m.: the demo laptop isn’t connected to the office Wi-Fi, the projector’s HDMI audio device forces 44.1 kHz, or a browser tab runs without &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COOP&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COEP&lt;/code&gt; headers and silently fails to allocate &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt;. Great audio engineers don’t pray on demo day—they run a &lt;strong&gt;ruthless, quantified pre-flight checklist&lt;/strong&gt; 24 hours in advance.&lt;/p&gt;

&lt;p&gt;This lecture turns your capstone from “works on my machine” into a rock-solid live demonstration, covering soak testing, latency verification, blind A/B listening setup, fallback drills, and crisp technical storytelling.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-four-verification-gates-before-demo-day&quot;&gt;Key ideas: Four Verification Gates Before Demo Day&lt;/h2&gt;

&lt;p&gt;Before putting headphones on a reviewer or stakeholder, verify four independent gates:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Functional &amp;amp; Parity Gate:&lt;/strong&gt; Offline-vs-streaming equivalence passes (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt; 1e-5&lt;/code&gt;), bypass toggle is click-free, and clean speech stays transparent.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Soak &amp;amp; Stability Gate:&lt;/strong&gt; A continuous &lt;strong&gt;5-minute soak test&lt;/strong&gt; (30,000 frames at 10 ms hop) completes with 0 underruns, flat RAM usage (no memory leak across device restarts), and \(\mathrm{RTF}_{p99} \le 0.50\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Failure-Mode &amp;amp; Fallback Gate:&lt;/strong&gt; Explicitly simulate a 404 model URL, a missing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SIMD128&lt;/code&gt; flag, and a mid-call microphone unplug—confirming the app degrades gracefully without crashing or muting the user.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Perceptual &amp;amp; Presentation Gate:&lt;/strong&gt; Loudness-normalized (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-24 LUFS&lt;/code&gt;) before/after clips ready locally (zero dependency on live venue Wi-Fi!), backed by a clear 1-page metric scorecard.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to walk the audio path, the asset path, and the metric files, rehearse a five-minute script, and inject a CDN failure without ending the call. You should also show one listening example with the condition name visible.&lt;/p&gt;

&lt;h2 id=&quot;technical-checklist&quot;&gt;Technical checklist&lt;/h2&gt;

&lt;p&gt;Copy this into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/demo_checklist.md&lt;/code&gt; and tick it. A blank box is a fail until you write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; and why.&lt;/p&gt;

&lt;p&gt;Audio path:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Microphone permission works on the machine you will demo.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(true)&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt; both leave a published track. If your UI must rejoin, write that limitation down.&lt;/li&gt;
  &lt;li&gt;Browser &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt; is recorded as on or off so you do not credit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; for the browser’s own suppressor.&lt;/li&gt;
  &lt;li&gt;Leaving the room does not leak an extra audio context you can hear on the next join.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Model load:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Cold start fetches &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt; for package ≥ 1.2.0, including 1.3.0. Confirm in the network panel that you did &lt;strong&gt;not&lt;/strong&gt; also put &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;A second join uses cache or you document that it does not.&lt;/li&gt;
  &lt;li&gt;With the CDN blocked, the call still publishes unprocessed audio and the UI shows an error. Screenshot or a one-line log goes in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Metrics, from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/metrics/suite.md&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Six columns: clip id, condition, SI-SDR or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, DNSMOS or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, listening note, RTF p95.&lt;/li&gt;
  &lt;li&gt;At least one real row with SI-SDR &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;RTF p95 names the device. If you only dogfooded, the cell is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, not a guessed 0.2.&lt;/li&gt;
  &lt;li&gt;Versions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; version, model archive name, DNSMOS build or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not run&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Demo hygiene:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A backup recording plays if the live mic fails.&lt;/li&gt;
  &lt;li&gt;Headphones are on the table.&lt;/li&gt;
  &lt;li&gt;One café or babble clip, one keyboard clip, one quiet clip.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rust, if you touched it: the first spoken sentence matches &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_core_status.md&lt;/code&gt;. Passthrough means you say “noise suppression is not running.”&lt;/p&gt;

&lt;h2 id=&quot;five-minute-script&quot;&gt;Five-minute script&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Time&lt;/th&gt;
      &lt;th&gt;Say this&lt;/th&gt;
      &lt;th&gt;File you can open&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;0:00–0:40&lt;/td&gt;
      &lt;td&gt;Uplink noise, on-device, LiveKit publish&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;design/sketch.md&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;0:40–1:20&lt;/td&gt;
      &lt;td&gt;Eight public steps, no private classes&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publish-path.md&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;1:20–2:30&lt;/td&gt;
      &lt;td&gt;Play raw versus processed, name the condition&lt;/td&gt;
      &lt;td&gt;backup wav&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2:30–3:30&lt;/td&gt;
      &lt;td&gt;One row of the suite that improved, one that did not&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;metrics/suite.md&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3:30–4:20&lt;/td&gt;
      &lt;td&gt;Hypothesis result, including a fail if that is the truth&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;design/hypothesis.md&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4:20–5:00&lt;/td&gt;
      &lt;td&gt;Limits: language, device, DNSMOS version, Rust status&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;notes/limits.md&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;If the rehearsal exceeds five minutes, cut the architecture slide before you cut the counterexample row. The row that did not improve is the evidence you understand the map.&lt;/p&gt;

&lt;h2 id=&quot;failure-injection&quot;&gt;Failure injection&lt;/h2&gt;

&lt;p&gt;Block the CDN host (DevTools offline, or a bad &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;) and join. Expected: the room still has audio; the processor does not pretend the model ran; your notes say whether &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; was reachable. Restore the network and reload. Expected: WASM and the tar.gz load from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; paths. If either injection does something else, that behavior is a limit, not a surprise you hide.&lt;/p&gt;

&lt;p&gt;RTF injection, if you have a log: scroll to the worst quantum, not the mean. The figure’s overrun bar is the failure mode. A p95 you never computed stays &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Run the checklist file through a checker after you have copied the headings.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;capstone/notes/demo_checklist.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setenabled&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;noisesuppression&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;df_bg.wasm&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;deepfilternet3_onnx.tar.gz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;si-sdr&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;dnsmos&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rtf p95&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;backup&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;passthrough&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;missing none
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Use the token &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt; even if your line is “Rust: not attempted, so not a passthrough claim.” The checker only requires the word so the demo script cannot forget the stretch rule. Failure modes: ticking RTF with no device; a backup recording that is a different sentence than the live clip; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; typed into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; and also added by the package, so the request 404s; calling a passthrough Rust build “NS works.”&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-pre-flight-soak--demo-readiness-audit&quot;&gt;Worked Numerical Example: Pre-Flight Soak &amp;amp; Demo Readiness Audit&lt;/h3&gt;

&lt;p&gt;Calculate the exact numbers behind a 5-minute pre-flight soak test at \(f_s = 48{,}000	ext{ Hz}\), hop \(H = 480\) (10 ms):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Pre-Flight Check&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Exact Test Quantity&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Pass Criteria&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Actual Demo-Ready Target&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Total Frames Processed&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(300	ext{ s} 	imes 100 = \mathbf{30{,}000	ext{ frames}}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0 crashes, 0 NaNs&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;30,000 / 30,000 clean&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Underrun Tolerance&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(ext{underruns} / 30{,}000\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.000\%\) (0 clicks)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0 underruns&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Memory Leak Check (5 restarts)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\mathrm{RAM}_{	ext{after }5} - \mathrm{RAM}_{	ext{after }1}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\le +0.5	ext{ MB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.0	ext{ MB}\) drift&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Blind A/B Demo Clips&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5 diverse clips (fan, café, typing, clean, echo)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;All normalized to \(-24	ext{ LUFS}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Local &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wav&lt;/code&gt; backup ready&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;explanation-four-rules-for-an-unforgettable-audio-engineering-demo&quot;&gt;Explanation: Four Rules for an Unforgettable Audio Engineering Demo&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always play loudness-matched before/after audio within the first 60 seconds:&lt;/strong&gt; Nothing convinces an audience faster than hearing noisy café chatter vanish into crystal-clear speech—just make sure both clips are matched to the exact same LUFS!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Show your live telemetry overlay during the demo:&lt;/strong&gt; Displaying real-time &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTF&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p99 ms&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;underruns: 0&lt;/code&gt;, and a live bypass toggle proves your system is genuinely running in real time, not playing a pre-baked file.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lead with one honest failure mode you discovered and fixed:&lt;/strong&gt; Explaining how you caught a 44.1 kHz resampling bug or a 1-frame streaming state mismatch shows genuine engineering maturity.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Have an offline local server (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;localhost&lt;/code&gt;) ready:&lt;/strong&gt; Venue Wi-Fi fails constantly; serving your WASM/ONNX assets locally guarantees your demo runs smoothly even in airplane mode.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; During a 5-minute soak test at 10 ms hop (30,000 frames), if your telemetry records &lt;strong&gt;30 underruns&lt;/strong&gt;, what is your underrun rate percentage—and roughly how often (every how many seconds) would a listener hear a glitch?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Time a rehearsal. Write the wall time in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/rehearsal.txt&lt;/code&gt;. Cut until you are at or under 5:00.&lt;/li&gt;
  &lt;li&gt;Perform the CDN block. Paste the observed publish behavior under the checklist.&lt;/li&gt;
  &lt;li&gt;Exchange limitation sections with a peer. Each of you must find one overclaim.&lt;/li&gt;
  &lt;li&gt;List the files from 09-04 that you will zip or push from your fork. Exclude the product repo.&lt;/li&gt;
  &lt;li&gt;Point at the overrun bar in the RTF figure and say what you will report if your log only has a mean.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Cut architecture before the bad metric row.&lt;/li&gt;
  &lt;li&gt;Expected honest line: “audio published, model not loaded, UI showed an error” or whatever you truly saw.&lt;/li&gt;
  &lt;li&gt;Typical overclaim: SI-SDR language on a real clip, or DNSMOS without a version.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/design&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audio&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;metrics&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;notes&lt;/code&gt;. No path under the shared Mezon tree.&lt;/li&gt;
  &lt;li&gt;Report the mean and set RTF p95 to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. Do not invent a percentile.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; The metric and integration sections are the checklist: a number, a listening note, and the stack you actually joined.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, English. Glitches and callback overruns are the failure you inject on purpose. Watch how they are measured, then do the smaller version in the lab.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, English. Keep a backup recording in the spirit of this demo: demo day needs sound if the live callback fails.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-04 Capstone project brief</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter09/09_04_capstone_project_brief/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter09/09_04_capstone_project_brief</id>
   <content type="html">&lt;p&gt;The capstone is a written design, a measured demo on a small clip set, and a public-API story you can defend. It is not a patch to the shared product repository &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt;. Work in a personal fork or in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/&lt;/code&gt; tree this lab creates. The instructor path &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt; is optional local context, not a required checkout and not a place to invent files.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Evaluation map for the capstone report&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The report uses the evaluation map: SI-SDR only with a clean reference, DNSMOS or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, a listening note, and a systems line for RTF. The ship box is a decision, not a slogan.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Real audio engineering is never just a Jupyter notebook with a pretty spectrogram—it is shipping a &lt;strong&gt;working, measured, glitch-free system&lt;/strong&gt; that survives real microphones, real background noise, and real CPU budgets. This &lt;strong&gt;Capstone Project Brief&lt;/strong&gt; challenges you to synthesize every chapter of the course into one end-to-end deliverable: a real-time streaming noise-suppression prototype (browser &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; + WASM/ONNX, or native Rust/Python streaming) backed by an honest quantitative evaluation report.&lt;/p&gt;

&lt;p&gt;Think of this brief as an industry RFC (Request for Comments): clear scope, hard numerical acceptance criteria, and zero hand-waving.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-the-four-pillars-of-an-industry-grade-audio-capstone&quot;&gt;Key ideas: The Four Pillars of an Industry-Grade Audio Capstone&lt;/h2&gt;

&lt;p&gt;A portfolio-worthy audio engineering capstone demonstrates mastery across four integrated dimensions:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Signal &amp;amp; Model Architecture:&lt;/strong&gt; Clean causal STFT/iSTFT framing, explicit streaming state management, and verified offline-vs-streaming numerical equivalence (\(\max\lvert\Delta
vert &amp;lt; 10^{-5}\)).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Real-Time Systems Engineering:&lt;/strong&gt; Glitch-free streaming under a fixed latency and compute budget (zero allocations in the audio callback, ring-buffer underrun instrumentation, and click-free bypass toggle).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quantitative &amp;amp; Perceptual Evaluation:&lt;/strong&gt; Multi-metric benchmarking combining intrusive &lt;strong&gt;SI-SDRi&lt;/strong&gt; (by SNR bucket), non-intrusive &lt;strong&gt;DNSMOS (SIG/BAK/OVRL)&lt;/strong&gt; on real field clips, clean-speech transparency, and &lt;strong&gt;\(\mathrm{RTF}_{	ext{mean}} / \mathrm{RTF}_{p99}\)&lt;/strong&gt; histograms.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reproducible Engineering Craft:&lt;/strong&gt; One-command setup, pinned dependencies, automated unit + streaming-equivalence tests, and a concise technical write-up honestly analyzing both wins and failure modes.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to create the capstone directories, mix a four-sample signal at a known SNR, pick one primary track, and list the artifacts a grader will open. You should also state the failure mode of each milestone so a slip does not become a silent skip.&lt;/p&gt;

&lt;h2 id=&quot;tracks&quot;&gt;Tracks&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A. Eval and policy (recommended).&lt;/strong&gt; Freeze clips, fill the six-column sheet from lesson 08-04, and justify one &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; choice with an AB note.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B. Integration.&lt;/strong&gt; Exercise &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt; (Mezon example &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/code&gt;), the automatic &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; prefix on package ≥ 1.2.0 including 1.3.0, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;, and a blocked-CDN drill that still publishes audio.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C. Rust stretch.&lt;/strong&gt; Optional &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; from lesson 09-03. A passthrough backend must be labeled passthrough. Partial credit is real if the label is honest. No credit for “NS works” on a copy loop.&lt;/p&gt;

&lt;p&gt;Pick one primary track. The others may appear only as a named non-goal.&lt;/p&gt;

&lt;h2 id=&quot;milestones-and-how-they-fail&quot;&gt;Milestones and how they fail&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;ID&lt;/th&gt;
      &lt;th&gt;Output&lt;/th&gt;
      &lt;th&gt;Failure mode&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;M0&lt;/td&gt;
      &lt;td&gt;Architecture sketch (09-01) and hypothesis (09-02)&lt;/td&gt;
      &lt;td&gt;Private class names, or no fail rule&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;M1&lt;/td&gt;
      &lt;td&gt;Baseline on a frozen clip list&lt;/td&gt;
      &lt;td&gt;Tuning the list after you see the score&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;M2&lt;/td&gt;
      &lt;td&gt;Change lives in your fork or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/&lt;/code&gt;, not the shared tree&lt;/td&gt;
      &lt;td&gt;A commit on the product repo “just to try”&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;M3&lt;/td&gt;
      &lt;td&gt;Six-column table, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; where required&lt;/td&gt;
      &lt;td&gt;Invented SI-SDR on a real mic file&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;M4&lt;/td&gt;
      &lt;td&gt;Demo checklist (09-05)&lt;/td&gt;
      &lt;td&gt;Live CDN as the only path, no backup recording&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;There is no week count hiding in the IDs. Finish M0 before you collect M3, or you will fit the hypothesis to the number.&lt;/p&gt;

&lt;h2 id=&quot;artifacts-the-grader-opens&quot;&gt;Artifacts the grader opens&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/design/sketch.md&lt;/code&gt; — goal, public data path, asset URLs, non-goals.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/design/hypothesis.md&lt;/code&gt; — hypothesis, experiment, success, fail.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/audio/&lt;/code&gt; — small wavs or the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.npy&lt;/code&gt; from the mixer, plus a README of filenames.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/metrics/suite.md&lt;/code&gt; — clip id, condition, SI-SDR or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, DNSMOS or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, listening note, RTF p95.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/reading.md&lt;/code&gt; — at least five bullets that tie Chapters 02–08 to a public API or a paper URL from lesson 10-01.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/limits.md&lt;/code&gt; — languages, devices, and the Rust status (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not attempted&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passthrough&lt;/code&gt; or a real backend).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A slide deck is optional. An unreproducible screenshot of a score is not a metric.&lt;/p&gt;

&lt;h2 id=&quot;grading-emphasis&quot;&gt;Grading emphasis&lt;/h2&gt;

&lt;p&gt;High weight: the technique is real and the table is honest, including &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. High weight: someone else can re-run the mixer or the checker. Medium weight: a demo path that survives headphones and a blocked CDN. Low weight: visual polish. Zero: unapproved edits to the shared product repo, and any report that calls passthrough “noise suppression.”&lt;/p&gt;

&lt;p&gt;Non-goals, stated so they do not creep: training a new state-of-the-art model, bit-exact Rust parity as a graduation requirement, and uploading customer audio to a cloud model without a privacy design you do not have.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;From an empty working directory that is &lt;strong&gt;not&lt;/strong&gt; the product repo:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; capstone/&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;design,audio,metrics,notes&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
find capstone &lt;span class=&quot;nt&quot;&gt;-type&lt;/span&gt; d | &lt;span class=&quot;nb&quot;&gt;sort
&lt;/span&gt;python3 &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;import numpy as np; s=np.array([1.,0,-1,.5]); n=np.array([.2,-.2,.2,-.2]); g=np.linalg.norm(s)/(10**(10/20)*np.linalg.norm(n)); y=s+g*n; np.save(&quot;capstone/audio/mix.npy&quot;, y); print(np.round(y,3).tolist())&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;capstone
capstone/audio
capstone/design
capstone/metrics
capstone/notes
[1.237, -0.237, -0.763, 0.263]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The mixer builds a 10 dB mixture of the lesson 08-01 reference &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s&lt;/code&gt; with a four-point noise vector. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; scales the noise so that \(10\log_{10}(\|s\|^2/\|gn\|^2) = 10\). The printed samples are \(s + gn\) rounded to three decimals. Confirm with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;find capstone -type f | sort&lt;/code&gt; that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/audio/mix.npy&lt;/code&gt; exists.&lt;/p&gt;

&lt;p&gt;Failure modes: running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mkdir&lt;/code&gt; inside the shared product clone; a different SNR because the formula used amplitude ratios twice; forgetting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.save&lt;/code&gt; and then claiming the directory listing is the whole lab; treating &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1.237, -0.237, -0.763, 0.263]&lt;/code&gt; as a DeepFilterNet output. It is the noisy mixture.&lt;/p&gt;

&lt;p&gt;After the commands, add a milestone checklist to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/design/sketch.md&lt;/code&gt; with M0–M4 marked &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;todo&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;done&lt;/code&gt;. A grader should see the directories even if every milestone is still &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;todo&lt;/code&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-a-concrete-capstone-acceptance-scorecard-target-spec&quot;&gt;Worked Numerical Example: A Concrete Capstone Acceptance Scorecard (Target Spec)&lt;/h3&gt;

&lt;p&gt;Before writing code, lock your capstone’s quantitative engineering targets into a single verifiable table:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Acceptance Criterion&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Target Threshold&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;How You Measure &amp;amp; Prove It&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Algorithmic + Buffer Latency&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\le 40	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(T_{	ext{win}} + L\cdot T_{	ext{hop}} + T_{	ext{prefill}}\) + impulse-response test&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Streaming Parity&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;$$\max\lvert y_{	ext{stream}} - y_{	ext{offline}}&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;vert &amp;lt; 10^{-5}$$&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Automated unit test on 5 s random/speech audio&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Real-Time Headroom (\(\mathrm{RTF}_{p99}\))&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\le 0.50\) (on target laptop/browser)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Histogram over 5-minute soak (30,000 frames)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Audio Glitches (Underruns)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0\) over 5 minutes&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Atomic underrun counter in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; / callback&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Enhancement Quality (5 dB SNR)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\mathrm{SI	ext{-}SDRi} \ge +8.0	ext{ dB}\), \(\mathrm{SIG} \ge 3.4\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Frozen synthetic + real café test set&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Clean-Speech Transparency&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\Delta\mathrm{SIG} \ge -0.10\) vs. clean input&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Run denoiser on studio clean speech clips&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Notice why locking these six numbers &lt;em&gt;before&lt;/em&gt; coding transforms your project: every architectural trade-off (INT8 vs FP32, hop 10 ms vs 20 ms, lookahead 0 vs 1) immediately becomes an objective engineering decision!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-traps-that-derail-audio-capstones&quot;&gt;Explanation: Four Traps That Derail Audio Capstones&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Building a giant custom model before wiring the end-to-end streaming pipe:&lt;/strong&gt; Always get a trivial &lt;strong&gt;passthrough or gain-only&lt;/strong&gt; streaming pipeline working end-to-end on Day 1, then drop in a pre-trained RNNoise/DeepFilterNet/ONNX model, and &lt;em&gt;only then&lt;/em&gt; iterate on custom models.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Forgetting impulse-response latency measurement:&lt;/strong&gt; Don’t just guess your pipeline latency on paper—feed a 1-sample unit impulse &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.0&lt;/code&gt; into the input and measure the exact sample index where the peak exits!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cherry-picking one flattering demo clip:&lt;/strong&gt; Record at least one brutally hard clip (loud café babble + keyboard clatter + soft speech) and show both where your system shines and where it struggles.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Skipping the clean-speech check:&lt;/strong&gt; Reviewers immediately test a denoiser on quiet speech—if it muffles a clean voice, the project loses credibility regardless of how well it kills fan noise.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; If your streaming pipeline processes 48 kHz audio and a unit impulse injected at input sample &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t = 0&lt;/code&gt; emerges at output sample &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t = 1920&lt;/code&gt;, what is the exact measured end-to-end pipeline latency in milliseconds?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Choose track A, B, or C and write the M0 hypothesis under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/design/&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Freeze ten clip filenames in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/audio/CLIPS.txt&lt;/code&gt; before you score anything.&lt;/li&gt;
  &lt;li&gt;Start &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;capstone/notes/reading.md&lt;/code&gt; with five bullets and real URLs you will actually open.&lt;/li&gt;
  &lt;li&gt;Name the single failure mode most likely to hit you, from the table above, and the file that will show it.&lt;/li&gt;
  &lt;li&gt;Re-run the one-line mixer at 0 dB (replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10/20&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0/20&lt;/code&gt;) and explain why the samples change.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Track C still needs the passthrough label if you have no model.&lt;/li&gt;
  &lt;li&gt;Filenames only. No scores yet, so you cannot steer the set.&lt;/li&gt;
  &lt;li&gt;Use the URLs in lesson 10-01. Do not invent a successor paper.&lt;/li&gt;
  &lt;li&gt;The common miss is M2 on the shared repo, or M3 with a fake SI-SDR.&lt;/li&gt;
  &lt;li&gt;At 0 dB, \(\|gn\| = \|s\|\), so &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; is larger and the noise is more visible in the printout.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch what a measured noise-suppression result contains: data, a listening check, and a complexity number. The capstone is that shape on a small clip set.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, English. The before-and-after is the listening half of the demo day artifact.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. Use the system diagram as the design you have to defend, including latency, not only the sound.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-03 Optional Rust native (df-core) path</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter09/09_03_optional_rust_df_core/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter09/09_03_optional_rust_df_core</id>
   <content type="html">&lt;p&gt;The supported Mezon path is the WASM box in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;: ONNX weights, a SIMD WASM build, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; CDN layout the package adds for ≥ 1.2.0 (including 1.3.0), and an AudioWorklet. A Rust crate you might call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; is a &lt;strong&gt;stretch alternative to that box&lt;/strong&gt;, for a desktop CLI or a native embed you build in your own workspace. It is not a second product, it is not required to pass, and it is not a folder you are entitled to find under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt;. If your first backend only copies samples from input to output, label it &lt;strong&gt;passthrough&lt;/strong&gt;. Never write “NS works” on a passthrough build.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;On-device WASM path for deepfilternet3-noise-filter&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The shipping path is PyTorch to ONNX to WASM to the package or CDN &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; assets, then AudioWorklet. Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; is a stretch alternative to this WASM box, not a second product beside it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Running a neural speech denoiser inside browser WASM is already impressive—but what if you are building a native desktop client (Electron/Tauri), a mobile iOS/Android app, or a server-side audio mixer where you can unleash &lt;strong&gt;native Rust (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt;)&lt;/strong&gt; directly on the CPU? Dropping the browser sandbox unlocks &lt;strong&gt;256-bit AVX2 / ARM NEON&lt;/strong&gt; hardware intrinsics, true OS threads, zero JS-to-WASM marshaling overhead, and &lt;strong&gt;3–5× lower CPU usage&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;This optional lecture explores the &lt;strong&gt;native Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; path&lt;/strong&gt;: how one portable Rust DSP+ML crate serves both &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wasm32&lt;/code&gt; and native x86_64/ARM64 targets, how zero-copy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;[f32]&lt;/code&gt; slices cross C-ABI / FFI boundaries safely, and how native profiling reveals cache and SIMD bottlenecks.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-native-rust-audio-engines-and-safe-ffi-boundaries&quot;&gt;Key ideas: Native Rust Audio Engines and Safe FFI Boundaries&lt;/h2&gt;

&lt;p&gt;Four systems concepts govern a native Rust audio core like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Wider Hardware SIMD (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AVX2&lt;/code&gt; 256-bit / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NEON&lt;/code&gt; 128-bit FMA):&lt;/strong&gt; Native Rust compiled for the host CPU leverages 8-lane &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32x8&lt;/code&gt; fused multiply-add instructions (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AVX2&lt;/code&gt;), cutting per-frame inference time by 3–4× compared to 4-lane browser WASM &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Zero-Allocation Real-Time Rust (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#[no_std]&lt;/code&gt; / Pre-Allocated Structs):&lt;/strong&gt; Rust’s ownership model makes real-time audio safety verifiable: allocate all STFT scratch buffers, state tensors, and ring buffers once inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DfEngine::new()&lt;/code&gt;, then pass &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;mut [f32]&lt;/code&gt; into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process_frame(&amp;amp;mut self, frame: &amp;amp;mut [f32])&lt;/code&gt; with zero &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;malloc&lt;/code&gt; calls.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Safe FFI / C-ABI Surface (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;extern &quot;C&quot;&lt;/code&gt;):&lt;/strong&gt; To call Rust from Swift (iOS), Kotlin/JNI (Android), C++ (WebRTC), or Node/Electron (N-API), expose a minimal opaque handle (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*mut DfEngine&lt;/code&gt;) and raw float pointer + length (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*mut f32, usize&lt;/code&gt;), converting to a safe Rust slice &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;mut [f32]&lt;/code&gt; inside a tiny audited &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unsafe&lt;/code&gt; wrapper.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Single Codebase, Dual Targets:&lt;/strong&gt; Using Cargo feature flags (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--features wasm&lt;/code&gt; vs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--features native&lt;/code&gt;), the exact same DSP math, state machines, and streaming unit tests run identically on native servers and inside browsers.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to say what the WASM path loads (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;), what a personal Rust experiment would have to match (frame hop, sample rate, a real model), and how you will prove parity without claiming bit-exactness you have not measured. You should also refuse to treat a passthrough backend as enhancement.&lt;/p&gt;

&lt;h2 id=&quot;the-box-you-are-not-replacing-by-default&quot;&gt;The box you are not replacing by default&lt;/h2&gt;

&lt;p&gt;Package 1.3.0, like every release ≥ 1.2.0, requests &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;. The client adds &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;. Do not put it in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;. The example base is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/code&gt;. The public controls remain &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;. A Rust experiment does not get new public names in the npm package. If you want a CLI, you build it beside the course, in a personal repository.&lt;/p&gt;

&lt;p&gt;The DeepFilterNet papers describe why a native reimplementation is picky: 48 kHz full-band audio, an STFT with a hop on the order of 10 ms, an ERB gain stage, and a deep filter that may use a short look-ahead. That look-ahead is algorithmic latency. Matching RTF is not the same as matching the waveform. Lesson 08-01 showed that a one-sample slip turns 13.80 dB into −10.67 dB. A Rust port that is “a little late” will look terrible on SI-SDR even when it sounds similar.&lt;/p&gt;

&lt;h2 id=&quot;a-personal-workspace-if-you-opt-in&quot;&gt;A personal workspace, if you opt in&lt;/h2&gt;

&lt;p&gt;Create this only in your fork or a new repo. Do not add it to the shared product tree as the homework.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;my-df-stretch/
  df-core/     # your frame API
  df-cli/      # offline wav in, wav out
  README.md    # says passthrough or real backend, in the first paragraph
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Suggested milestones, in order:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Passthrough backend.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; returns the input samples. The README title says passthrough. Tests check length and a copy, not a noise floor.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Asset errors.&lt;/strong&gt; A missing tar or ONNX path fails with a clear error. It does not silently pass audio and print “enhanced.”&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Load a real runtime.&lt;/strong&gt; &lt;a href=&quot;https://github.com/sonos/tract&quot;&gt;tract&lt;/a&gt; or ONNX Runtime (&lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;onnxruntime.ai/docs&lt;/a&gt;) runs the same DeepFilterNet3 archive the CDN serves. Upstream &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;libDF&lt;/a&gt; is the other honest option. Pick one and pin the version.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Framing.&lt;/strong&gt; Document hop, window, and sample rate next to the WASM path. Do not invent a private Mezon API to do it.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Golden files.&lt;/strong&gt; One noisy wav through the public WASM path, one through your CLI. Compare with SI-SDR &lt;strong&gt;between the two estimates&lt;/strong&gt;, after alignment, and report the float. Also listen. High SI-SDR between them means they match each other, not that either matches clean speech.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stop conditions.&lt;/strong&gt; If you only finished step 1, the demo script says “passthrough, noise suppression is not running.”&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Licensing follows the upstream DeepFilterNet project (Apache-2.0 OR MIT, as the npm package does). Do not commit the tar.gz. Point at the CDN layout or the upstream &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;models/&lt;/code&gt; instructions.&lt;/p&gt;

&lt;h2 id=&quot;parity-without-fiction&quot;&gt;Parity without fiction&lt;/h2&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;align hop delay
enh_wasm.wav  from the published processor or an offline WASM run you script
enh_rust.wav  from your CLI
print SI-SDR(enh_wasm, enh_rust) after alignment
write the float in the report
if the backend is passthrough, skip this comparison and say why
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Until step 3 exists, the golden test is &lt;strong&gt;pending&lt;/strong&gt;. A passthrough file compared to a real enhancer will score badly. That bad score is the point. Do not loosen the tolerance until the number looks kind.&lt;/p&gt;

&lt;p&gt;tract versus a hand-written binding to upstream libDF is a tradeoff you should write in a paragraph: tract and ONNX Runtime consume the ONNX artifact the CDN already ships; libDF is the engine the WASM build is derived from and may track streaming state more faithfully. Either way you still measure. Chapter 06 is the background. This lesson does not add a private symbol table.&lt;/p&gt;

&lt;h2 id=&quot;what-done-means-for-a-stretch&quot;&gt;What “done” means for a stretch&lt;/h2&gt;

&lt;p&gt;Done for the optional path is a README a stranger can build, a passthrough label if that is all you have, or a CLI plus one SI-SDR float against the WASM output if you loaded a model. Done is not a slide that says the native client is production Mezon. The shipping client remains the npm package on the LiveKit path in 09-01.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_core_status.md&lt;/code&gt; with two lines a checker can see:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;backend: passthrough
claim: noise suppression is not running
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you truly load a model, you may instead write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;backend: tract&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;backend: onnxruntime&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;backend: libdf&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;claim: compared to wasm SI-SDR &amp;lt;float&amp;gt;&lt;/code&gt;. The passthrough wording must not appear next to a claim that NS works.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;df_core_status.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ok_pass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;passthrough&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;not running&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ok_real&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;tract&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;onnxruntime&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;libdf&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;si-sdr&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;bad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ns works&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;noise suppression works&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ok_pass&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ok_real&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bad&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fix&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output for the default stretch lab (no model yet):&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;status ok
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Failure modes: “NS works” on a copy loop; committing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;; requiring the instructor’s machine path; describing Rust as the product and WASM as the demo; a parity float with no alignment note.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-comparing-native-rust-df-core-vs-browser-wasm-simd-on-a-10-ms-frame&quot;&gt;Worked Numerical Example: Comparing Native Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; vs. Browser WASM SIMD on a 10 ms Frame&lt;/h3&gt;

&lt;p&gt;Benchmark the exact same 48 kHz streaming DeepFilterNet-style model (10 ms hop = 480 samples, 150 MMAC/s) across three deployment targets on the same laptop CPU:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Deployment Target&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Vector Width&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Mean Frame Time&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;p99 Frame Time&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;\(\mathrm{RTF}_{p99}\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Battery / CPU Headroom&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Browser WASM (Scalar)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1 × &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(7.8	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(12.5	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1.25\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Fails real-time!&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Browser WASM (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;4 × &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2.2	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3.8	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.38\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Comfortable for browser&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Native Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AVX2&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;8 × &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; + FMA&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(0.6	ext{ ms}\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(1.1	ext{ ms}\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(0.11\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;3.5× faster than WASM!&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;At \(0.6	ext{ ms}\) per 10 ms frame, a single native CPU core can even denoise &lt;strong&gt;8–10 concurrent audio streams&lt;/strong&gt; on a media server—or run on a laptop all day with virtually zero battery impact!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-building-a-native-rust-audio-core&quot;&gt;Explanation: Four Rules for Building a Native Rust Audio Core&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Never let a Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;panic!&lt;/code&gt; unwind across an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;extern &quot;C&quot;&lt;/code&gt; FFI boundary:&lt;/strong&gt; Unwinding into C/C++/Swift is immediate undefined behavior! Wrap FFI entry points with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std::panic::catch_unwind&lt;/code&gt; or return explicit integer error codes (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0 = OK&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-1 = InvalidLen&lt;/code&gt;).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Audit real-time heap allocations with a custom test allocator:&lt;/strong&gt; In integration tests, wrap the global allocator with an allocation counter and assert &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;allocations == 0&lt;/code&gt; across 1,000 calls to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process_frame()&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Keep FFI calls coarse-grained (one hop per call):&lt;/strong&gt; Crossing FFI once every 480 samples (100 times/sec) has negligible overhead; crossing once per sample (48,000 times/sec) wastes cycles on boundary transitions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Share bit-exact golden test vectors between Python, Rust Native, and WASM:&lt;/strong&gt; Running the exact same 5-second &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wav&lt;/code&gt; fixture through all three targets and asserting \(\max\lvert\Delta
vert &amp;lt; 10^{-5}\) guarantees zero drift across platforms.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; Why does passing a raw pointer + length &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(*mut f32, usize)&lt;/code&gt; across an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;extern &quot;C&quot;&lt;/code&gt; FFI boundary require checking for null pointers and verifying &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;len == 480&lt;/code&gt; &lt;em&gt;before&lt;/em&gt; constructing a Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;mut [f32]&lt;/code&gt; slice?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Write five milestones you can finish without a GPU, marking which ones are passthrough.&lt;/li&gt;
  &lt;li&gt;List tests that do not need weights: frame length, identity copy, and a missing-file error.&lt;/li&gt;
  &lt;li&gt;In one paragraph, compare tract (or ONNX Runtime) with upstream libDF as the stretch backend.&lt;/li&gt;
  &lt;li&gt;Decide go or no-go for Rust in your capstone. Name the WASM work you will do if you say no-go.&lt;/li&gt;
  &lt;li&gt;State the SI-SDR comparison direction: estimate versus estimate, not estimate versus a slogan.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Steps 1–2 are passthrough-legal. Step 3 is the first time the word enhancement is allowed.&lt;/li&gt;
  &lt;li&gt;Identity: output samples equal input samples. Missing file: non-zero exit status and no “enhanced” wav.&lt;/li&gt;
  &lt;li&gt;ONNX runtimes consume the tar/ONNX the CDN already has. libDF is the upstream engine. Both need a golden.&lt;/li&gt;
  &lt;li&gt;No-go is a complete capstone if 09-01 and 09-04 are real. Say so.&lt;/li&gt;
  &lt;li&gt;SI-SDR(wasm, rust) after delay compensation. The 13.80 lab is the method, not the expected product score.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nhTxJBgTywc&quot;&gt;Zoom on Web: getting connected with advanced web technology&lt;/a&gt; — Chrome for Developers, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the Rust simd128 note and the Emscripten flag. A native df-core stretch still has to meet this WASM baseline or explain why it replaced it.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, English. ONNX Runtime is the engine the lesson’s WASM box is already using. A Rust engine has to load the same kind of graph.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, English. The callback does not care that the code moved to Rust. Watch the deadline the native core still has to hit.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-02 Techniques beyond the npm wrapper</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter09/09_02_techniques_not_wrapper/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter09/09_02_techniques_not_wrapper</id>
   <content type="html">&lt;p&gt;Capstone credit is for a technique you can measure: framing and overlap, a suppression-level policy, an eval harness, a CDN failure path, or an RTF budget. It is not for renaming &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; or for a drive-by refactor inside the shared product repo. The wrapper is the vehicle. DeepFilterNet’s ERB stage and deep filter are the reason the vehicle exists. This lesson forces one hypothesis, one baseline, and one table a maintainer can re-run.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;DeepFilterNet block: ERB path plus multi-frame deep filter&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The technique under the wrapper: 48 kHz PCM, STFT, an ERB gain path, a deep filter on the complex spectrum, then ISTFT and overlap-add. Your capstone should name which of these you are studying.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It takes ten minutes to install an npm package and copy-paste five lines of initialization code. It takes &lt;strong&gt;deep signal-processing and systems judgment&lt;/strong&gt; to debug why Bluetooth headset users sound like chipmunks, why Safari silently drops audio after 30 seconds, or why toggling noise suppression mid-sentence produces a harsh pop. Frameworks and npm wrappers change every two years; the &lt;strong&gt;underlying techniques&lt;/strong&gt;—sample-rate adaptation, click-free crossfading, state resets, and real-time memory discipline—last your entire career!&lt;/p&gt;

&lt;p&gt;This lecture strips away the npm wrapper to spotlight the portable engineering techniques that transfer across WebRTC, desktop apps, mobile SDKs, and embedded DSP.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-four-transferable-techniques-beyond-any-sdk-wrapper&quot;&gt;Key ideas: Four Transferable Techniques Beyond Any SDK Wrapper&lt;/h2&gt;

&lt;p&gt;Mastering these four techniques lets you build or debug &lt;em&gt;any&lt;/em&gt; real-time audio pipeline from scratch:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Sample-Rate Adaptation (Resampling):&lt;/strong&gt; Hardware microphones run at 16 kHz (Bluetooth HFP), 44.1 kHz (legacy USB/macOS), or 48 kHz (standard WebRTC). Feeding 44.1 kHz audio directly into a 48 kHz STFT model shifts every frequency bin by \(48/44.1 pprox +8.84\%\)—warping vocal formants and breaking harmonic filters!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Click-Free Bypass &amp;amp; Gain Crossfading:&lt;/strong&gt; Switching abruptly from denoised audio to raw audio creates a step discontinuity (audible &lt;em&gt;click&lt;/em&gt;). Applying a short 5–10 ms linear or raised-cosine crossfade eliminates the transient completely.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;DC-Offset &amp;amp; Denormal Protection:&lt;/strong&gt; Cheap microphones often introduce a constant DC bias; a simple 1st-order high-pass filter (\(f_c pprox 60	ext{–}80	ext{ Hz}\)) removes rumble and DC offset before STFT analysis, while flushing subnormal floats prevents sudden 10× CPU slowdowns in IIR/GRU loops.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Deterministic State &amp;amp; Failure Recovery:&lt;/strong&gt; Sanitizing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NaN&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Inf&lt;/code&gt; outputs before they reach the speakers (protecting users’ ears!) and resetting model states on discontinuity.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to propose one change grounded in Chapters 02–08, write the success and fail rules before you collect the second number, and keep the work in a personal fork or an external harness. You should also say which public control you will touch (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;) and which metrics will stay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;a-menu-that-maps-to-chapters&quot;&gt;A menu that maps to chapters&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Idea&lt;/th&gt;
      &lt;th&gt;Fuel&lt;/th&gt;
      &lt;th&gt;Artifact you can grade&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Eval harness with the six-column sheet from 08-04&lt;/td&gt;
      &lt;td&gt;Ch. 08&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suite.md&lt;/code&gt; plus the checker&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Default level chosen by an AB test&lt;/td&gt;
      &lt;td&gt;08-03&lt;/td&gt;
      &lt;td&gt;Protocol, N, per-condition wins&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;RTF p95 log and a written downgrade rule&lt;/td&gt;
      &lt;td&gt;05, 07&lt;/td&gt;
      &lt;td&gt;Device, p95, what you disable&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Document browser NS versus this processor&lt;/td&gt;
      &lt;td&gt;03, 07&lt;/td&gt;
      &lt;td&gt;Constraint checklist&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;CDN base and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; prefix, with a failure drill&lt;/td&gt;
      &lt;td&gt;07&lt;/td&gt;
      &lt;td&gt;Log of blocked versus cached load&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Offline synthetic mixer and SI-SDR&lt;/td&gt;
      &lt;td&gt;02, 08-01&lt;/td&gt;
      &lt;td&gt;The 13.80 / −10.67 lab, then your own wavs&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;09-03&lt;/td&gt;
      &lt;td&gt;Optional stretch, passthrough labeled as such&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Reject CSS-only edits, dependency bumps without a table, and two unrelated hypotheses in one report. If you cannot name the baseline number you will collect first, you do not have an experiment.&lt;/p&gt;

&lt;h2 id=&quot;hypothesis-experiment-measure&quot;&gt;Hypothesis, experiment, measure&lt;/h2&gt;

&lt;p&gt;Write this before you change a knob:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Hypothesis: Moving setSuppressionLevel from 80 to 60 reduces muffled
            consonants on keyboard clips without a café collapse.

Experiment: The same 12 clips. Levels 80 and 60. AB with at least 6 raters.
            SI-SDR only on synthetic twins. DNSMOS only if one checkpoint
            is pinned; otherwise n/a. RTF p95 on one named laptop.

Success:    Keyboard listening does not prefer 80 for naturalness, café is
            tie or better than bypass, quiet-speech control is mostly ties,
            RTF p95 stays inside the budget you wrote down.

Fail:       Café listeners clearly prefer 80, or quiet speech loses, or
            p95 misses the AudioWorklet quantum. Then you do not change
            the default.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The numbers in that box are a template, not a result. Your report replaces them with measurements. There is still no official DNSMOS threshold to hide behind.&lt;/p&gt;

&lt;h2 id=&quot;metrics-you-must-name&quot;&gt;Metrics you must name&lt;/h2&gt;

&lt;p&gt;Quality is SI-SDR on aligned synthetic pairs, DNSMOS or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; on real files, and a listening note. Systems is RTF p95 or an honest statement that you only have a mean, plus whether init failed when the CDN was blocked. UX is whether &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt; returns the raw mic and whether a missing asset still lets the call publish. If you skip a column, write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; and the reason. Do not copy 13.80 from the SI-SDR lab into a product table and call it DeepFilterNet.&lt;/p&gt;

&lt;h2 id=&quot;a-note-maintainers-can-keep&quot;&gt;A note maintainers can keep&lt;/h2&gt;

&lt;p&gt;Use a short decision record:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Context: which public API and which chapter.&lt;/li&gt;
  &lt;li&gt;Decision: the level, the flag, or the harness layout.&lt;/li&gt;
  &lt;li&gt;Metrics: the six-column sheet or a pointer to it.&lt;/li&gt;
  &lt;li&gt;Alternatives you rejected, including “edit the shared repo.”&lt;/li&gt;
  &lt;li&gt;Follow-ups: what you did not measure (languages, phones, ASR).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The DeepFilterNet figure is the technical content of that note. If your change is only a CDN policy, say that you did not retune the ERB gains or the deep-filter taps. If your change is a level knob, say that the knob is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt; and that you did not retrain the network.&lt;/p&gt;

&lt;h2 id=&quot;scope-cuts&quot;&gt;Scope cuts&lt;/h2&gt;

&lt;p&gt;An MVP for this course is a frozen clip list, a baseline column, one change, and a report. A stretch is a second device, a DNSMOS checkpoint you actually run, or the Rust path in 09-03. Training a new enhancement network is out of scope. So is cloud inference of customer audio. So is any patch that lands only on the shared product repository.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hypothesis.md&lt;/code&gt; with the four labels &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hypothesis:&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Experiment:&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Success:&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Fail:&lt;/code&gt;. Name one public API and one metric that will be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. Run:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hypothesis.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Hypothesis:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Experiment:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Success:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Fail:&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;n/a&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Allow either suppression level or another public control if you edit the checker.
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;splitlines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If your hypothesis uses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, change the last required token to that name and say so in the file. Expected output for the level study:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;missing none
lines &amp;lt;your count, at least 8&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Failure modes: a hypothesis with no fail rule; success defined only as “SI-SDR goes up”; editing files under the shared product repo as the implementation step; claiming the ERB diagram means you must retrain the filter.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-quantifying-sample-rate-mismatch--click-free-crossfade-length&quot;&gt;Worked Numerical Example: Quantifying Sample-Rate Mismatch &amp;amp; Click-Free Crossfade Length&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Sample-rate mismatch distortion:&lt;/strong&gt; Suppose a model trained strictly at \(f_s = 48{,}000	ext{ Hz}\) receives a 1 kHz sine wave recorded at \(44{,}100	ext{ Hz}\) &lt;em&gt;without&lt;/em&gt; resampling. The model interprets those samples as if they arrived at 48 kHz, shifting the perceived frequency to:
\(f_{	ext{perceived}} = 1{,}000 	imes rac{48{,}000}{44{,}100} pprox \mathbf{1{,}088.4	ext{ Hz}}\)
—nearly &lt;strong&gt;1.5 musical semitones sharp&lt;/strong&gt;, shifting every Bark/ERB band off its trained calibration!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Crossfade sample count for a smooth 5 ms toggle:&lt;/strong&gt; At \(f_s = 48{,}000	ext{ Hz}\), a 5 ms raised-cosine fade takes:
\(N_{	ext{fade}} = 0.005 	imes 48{,}000 = 240	ext{ samples}\)
(just under two 128-sample Web Audio quanta). At sample \(n \in [0, 239]\), blending \(y[n] = (1 - lpha_n)\,x_{	ext{raw}}[n] + lpha_n\,x_{	ext{ns}}[n]\) with \(lpha_n = rac{1}{2}\!\left(1 - \cosrac{\pi n}{239}
ight)\) transitions smoothly from \(0 	o 1\) with zero first-derivative kink!&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;explanation-four-habits-that-separate-audio-engineers-from-wrapper-users&quot;&gt;Explanation: Four Habits That Separate Audio Engineers From Wrapper Users&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always inspect the actual hardware &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt; at runtime:&lt;/strong&gt; Never assume 48 kHz; either resample cleanly with a low-latency polyphase/sinc resampler or load a matching 16 kHz model variant.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Put a hard safety limiter / NaN guard at the very output:&lt;/strong&gt; One unguarded &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NaN&lt;/code&gt; inside a recursive filter or GRU latches forever; clamping output to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[-1.0, 1.0]&lt;/code&gt; and replacing non-finite samples with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.0&lt;/code&gt; protects both users’ ears and WebRTC encoders.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Align raw vs. denoised delay before crossfading:&lt;/strong&gt; If your NS path has 30 ms of latency and your raw bypass path has 0 ms, crossfading them directly creates a brief comb-filter echo unless you delay the raw path by 30 ms during the transition.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test the ugly edge cases explicitly:&lt;/strong&gt; Pure digital silence (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.0&lt;/code&gt;), full-scale clipping (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;±1.0&lt;/code&gt;), 1-second mic unplug, and rapid enable/disable clicks reveal 90% of wrapper bugs in 5 minutes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; If a user’s Bluetooth headset operates at \(16{,}000	ext{ Hz}\) and you want a 5 ms click-free crossfade, how many samples long is \(N_{	ext{fade}}\)?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Write the one-sentence hypothesis you will actually grade. Ask whether a stranger could falsify it.&lt;/li&gt;
  &lt;li&gt;List the baseline numbers you will collect before the change, including at least one &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Split the idea into MVP and stretch in five lines.&lt;/li&gt;
  &lt;li&gt;Draft the decision-record headings empty, then fill Context and Alternatives.&lt;/li&gt;
  &lt;li&gt;Point at one block in the ERB figure and say whether your capstone touches it.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Include the knob, the condition (keyboard, café, quiet), and the metric. “Make it better” is not falsifiable.&lt;/li&gt;
  &lt;li&gt;Baseline is level 80 or bypass on the same files. Real clips have SI-SDR &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; until a clean reference exists.&lt;/li&gt;
  &lt;li&gt;MVP is the table and the AB. Stretch is a second device or Rust. Training is neither.&lt;/li&gt;
  &lt;li&gt;Alternatives should include “do nothing” and “patch the shared repo” (rejected).&lt;/li&gt;
  &lt;li&gt;A level policy does not retune ERB gains. An eval harness does not either. Say that plainly.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-Yxj3yfvY-4&quot;&gt;Short-Time Fourier Transform Explained Easily&lt;/a&gt; — Valerio Velardo - The Sound of AI, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Framing and the hop are a technique you can measure. Watch them before renaming a package counts as a capstone.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. The evaluation loop (data, listening, complexity) is the experiment the lesson asks you to write down.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. The model itself is one technique on the menu: ERB gains plus a deep filter, with a latency you can cite.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>09-01 Mezon NS architecture tour</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter09/09_01_mezon_architecture/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter09/09_01_mezon_architecture</id>
   <content type="html">&lt;p&gt;Mezon noise suppression is a product case study, not a second syllabus. The public path is a browser microphone, a LiveKit local track, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; from the npm package &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; (version 1.3.0 in this course). Inference stays on device. The package loads a WASM build and the DeepFilterNet3 ONNX archive from a CDN base you pass as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;. Package ≥ 1.2.0, including 1.3.0, adds &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; itself, so the files fetched are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;. The example base is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/code&gt;. You study that path. The weights are the Rikorose DeepFilterNet3 archive. You do not edit the shared repository &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt; as the assignment. A personal fork or an external harness is the workspace. The instructor tree at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt; is optional and not required to finish the lab.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;LiveKit publish path with DeepFilterNoiseFilterProcessor&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Public publish path only: mic, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, encoded audio, LiveKit. CDN assets feed the processor. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; are runtime controls. On asset failure, publish unprocessed audio.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Up to this point in the course, you have mastered each component in isolation—STFT frames, causal neural networks, lock-free ring buffers, WASM SIMD128, WebRTC constraints, and perceptual metrics. Now it is time to zoom out and see how every single gear locks together inside a real production system: the &lt;strong&gt;Mezon Noise Suppression (NS) architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This architecture tour walks end-to-end from the user’s microphone hardware through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt;, lock-free SPSC ring buffers, Rust/WASM DSP + neural inference, and out into a LiveKit WebRTC &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrack&lt;/code&gt;—tracing every byte, every thread boundary, and every millisecond of latency.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-four-architectural-planes-of-a-production-voice-ns-system&quot;&gt;Key ideas: Four Architectural Planes of a Production Voice-NS System&lt;/h2&gt;

&lt;p&gt;A real-world browser/desktop NS pipeline separates cleanly into four planes:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Control Plane (Main JS/TS Thread):&lt;/strong&gt; Handles UI toggles, device selection, capability probing, CDN asset fetching, and LiveKit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; lifecycle (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;)—never touching raw audio samples.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Real-Time Audio Plane (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; Thread):&lt;/strong&gt; Wakes up every 128 samples (2.67 ms @ 48 kHz), copies samples to/from lock-free SPSC ring buffers with zero heap allocation, and performs smooth bypass crossfading.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute Plane (WASM SIMD128 / Native Rust Core):&lt;/strong&gt; Runs STFT analysis, ERB/Bark feature extraction, causal neural inference (DeepFilterNet/RNNoise/ONNX), and iSTFT overlap-add on fixed 480-sample (10 ms) hops.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Observability &amp;amp; Fallback Plane:&lt;/strong&gt; Collects atomic telemetry (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtfP99&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;underrunCount&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;activeTier&lt;/code&gt;) and triggers automatic fallback to native WebRTC NS if loading fails or sustained underruns occur.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to trace eight public steps from the microphone to a published track, name only the API this course treats as public, and map each box to an earlier chapter. You should also write an architecture sketch an advisor can grade without opening private source.&lt;/p&gt;

&lt;h2 id=&quot;public-names-you-may-use&quot;&gt;Public names you may use&lt;/h2&gt;

&lt;p&gt;Stay on this surface:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Role&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;LiveKit processor that owns the on-device graph&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Lower-level core for a WebAudio graph that is not LiveKit&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Attaches the processor to the local track before publish&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Runtime aggressiveness&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Bypass without pretending the model ran&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;CDN &lt;strong&gt;base&lt;/strong&gt;. Do not append &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; yourself&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;LiveKit’s own docs are the signaling reference: &lt;a href=&quot;https://docs.livekit.io/&quot;&gt;docs.livekit.io&lt;/a&gt;. The processor does not own tokens, the room, or the SFU. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; is the escape hatch when you are not inside a LiveKit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt;. It is still the same product package, not a private class you invent.&lt;/p&gt;

&lt;h2 id=&quot;eight-step-publish-path&quot;&gt;Eight-step publish path&lt;/h2&gt;

&lt;p&gt;Read this once, then close it and rewrite it in the mini-lab.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The page requests the microphone and receives a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStream&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;You wrap that stream in a LiveKit local audio track. The track is the object that can accept a processor.&lt;/li&gt;
  &lt;li&gt;You construct &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; (or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilter(options)&lt;/code&gt;, which returns that processor) and pass &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt; as the CDN base, with no &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; suffix.&lt;/li&gt;
  &lt;li&gt;Package ≥ 1.2.0, including 1.3.0, requests &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;You call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; with that processor so samples are enhanced before encode.&lt;/li&gt;
  &lt;li&gt;You publish the track to the room. The SFU receives encoded audio, not your CDN credentials.&lt;/li&gt;
  &lt;li&gt;Later, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; between 0 and 100 changes aggressiveness without a new publish.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt; bypasses the model. If WASM or the archive fails to load, you still publish the unprocessed microphone and you surface the error. A dead join button is not a noise-suppression feature.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That is the whole public story. Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; is not on this diagram. It is an optional stretch in lesson 09-03, not a second product you must draw to pass.&lt;/p&gt;

&lt;h2 id=&quot;what-each-layer-is-for&quot;&gt;What each layer is for&lt;/h2&gt;

&lt;p&gt;The application layer is the LiveKit room: join, mute, leave. Chapter 07 owns that boundary. The processor layer is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; together with the audio callback that must finish inside the render quantum (Chapter 05). The asset layer is the WASM module and the ONNX tar on the CDN (Chapters 06 and 07). The model those assets run is the DeepFilterNet3 line from &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt;: an ERB gain stage plus a deep filter on the STFT, which is why Chapters 02 and 04 are prerequisites. Controls are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. Evaluation is Chapter 08: SI-SDR when you have a clean reference, DNSMOS when you do not, a listening note, and RTF p95.&lt;/p&gt;

&lt;p&gt;Browser noise suppression and echo control still exist beside this processor. If both run, you will not know which one ate the consonants. Document the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt; constraint you set. That interaction is a checklist item, not a private class.&lt;/p&gt;

&lt;h2 id=&quot;advisor-sketch&quot;&gt;Advisor sketch&lt;/h2&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gu&quot;&gt;## Mezon NS — architecture sketch&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Goal: on-device uplink noise suppression for a LiveKit meeting
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Data path: mic → setProcessor(DeepFilterNoiseFilterProcessor) → publish
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Assets for ≥ 1.2.0 including 1.3.0: {cdnUrl}/v2/pkg/df_bg.wasm and {cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Controls: setEnabled, setSuppressionLevel(0–100)
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Eval: SI-SDR on synthetic pairs, DNSMOS or n/a on real clips, AB note, RTF p95
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Non-goals: uploading raw audio for cloud inference; editing the shared product repo
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; Stretch (optional): a personal Rust df-core harness, labeled passthrough until a real backend exists
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Chapter&lt;/th&gt;
      &lt;th&gt;Question the sketch must answer&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;02&lt;/td&gt;
      &lt;td&gt;Sample rate and frame/hop, without inventing a hidden buffer API&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;03&lt;/td&gt;
      &lt;td&gt;Whether browser AEC/NS is on at the same time&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;04&lt;/td&gt;
      &lt;td&gt;Why this model is DeepFilterNet3 and what the level knob trades&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;05&lt;/td&gt;
      &lt;td&gt;What happens when the callback misses its quantum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;06&lt;/td&gt;
      &lt;td&gt;WASM and the ONNX archive; the package adds &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; for ≥ 1.2.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;07&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;08&lt;/td&gt;
      &lt;td&gt;Which metric is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; on a real recording&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publish-path.md&lt;/code&gt; with exactly eight numbered steps from the microphone to publish. Use only public names. Then run:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;re&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;publish-path.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;findall&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;(?m)^\s*(\d+)\.\s+\S&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setEnabled&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;cdnUrl&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;df_bg.wasm&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;steps 8
missing none
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Failure modes: a ninth step that names a private class; putting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; itself; stopping the call when assets fail; describing Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; as required; pointing the lab at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt; as if that tree were part of the assignment.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-end-to-end-resource--latency-audit-of-the-mezon-ns-pipeline&quot;&gt;Worked Numerical Example: End-to-End Resource &amp;amp; Latency Audit of the Mezon NS Pipeline&lt;/h3&gt;

&lt;p&gt;Audit the exact memory and timing budget of one active 48 kHz mono voice track running through the Mezon NS pipeline:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Subsystem&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Unit / Shape&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Latency Contribution&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Memory Footprint&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Input/Output SPSC Ring Buffers&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2 	imes 2048\) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; samples&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(10.0	ext{ ms}\) (1-hop prefill)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(16	ext{ KB}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;STFT / iSTFT OLA Buffers&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(N=960, H=480\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(20.0	ext{ ms}\) (window)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(12	ext{ KB}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Neural Lookahead + Streaming State&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(L=1\) frame + conv/GRU caches&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(10.0	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(64	ext{ KB}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Quantized Weights + WASM Runtime&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;INT8 ONNX + SIMD128 engine&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0	ext{ ms}\) (per-frame \(2.4	ext{ ms}\))&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(8.5	ext{ MB}\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Total Active Track Budget&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;—&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(40.0	ext{ ms}\) total NS delay&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(&amp;lt; 9	ext{ MB}\) RAM&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Notice how cleanly every constraint holds: \(40	ext{ ms}\) NS delay leaves \(110	ext{ ms}\) for AEC + Opus + network + jitter buffer (staying under 150 ms!), while \(2.4	ext{ ms}\) compute per 10 ms hop yields \(\mathrm{RTF} = 0.24\) with 7.6 ms of headroom!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-architectural-invariants-that-keep-voice-calls-stable&quot;&gt;Explanation: Four Architectural Invariants That Keep Voice Calls Stable&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Strict thread isolation:&lt;/strong&gt; Main-thread React re-renders can take 50 ms; isolating audio I/O inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; guarantees UI lag never creates audio pops.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Single source of truth for frame geometry:&lt;/strong&gt; Derive ring-buffer thresholds, STFT window sizes, and latency compensation from one shared constant config so JS and Rust/WASM can never disagree on hop size.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Design for graceful degradation from day one:&lt;/strong&gt; If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt; is unavailable or p99 RTF exceeds 0.85 for 3 consecutive seconds, auto-downgrade cleanly rather than letting the user suffer robotic stuttering.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Keep the DSP/ML core platform-independent:&lt;/strong&gt; Writing the core engine in portable Rust lets the exact same tested code compile to browser WASM, Electron native addons, iOS, and Android!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; In the Mezon NS budget table above, if a developer switches the neural network from \(L = 1\) frame lookahead to \(L = 0\) (strictly causal), what does the total NS delay drop to?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Fill the advisor sketch in your own words, one page, with the asset URLs written out.&lt;/li&gt;
  &lt;li&gt;Draw the failure branch for a blocked CDN. The success branch still publishes audio. Say which audio.&lt;/li&gt;
  &lt;li&gt;List three telemetry events that do not upload PCM (for example asset HTTP status, init milliseconds, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; flips).&lt;/li&gt;
  &lt;li&gt;State where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; is allowed in your design, and where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; is required.&lt;/li&gt;
  &lt;li&gt;Explain why a personal fork is the workspace and the shared GitHub repo is not.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Include both &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; files and say the prefix is the package’s, not yours.&lt;/li&gt;
  &lt;li&gt;On failure, publish the unprocessed mic and show an error. Do not block the room.&lt;/li&gt;
  &lt;li&gt;Counters and timings only. No samples, no transcripts of the room.&lt;/li&gt;
  &lt;li&gt;LiveKit publish path uses the processor and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;. A custom WebAudio page may use the core. Do not invent further methods.&lt;/li&gt;
  &lt;li&gt;Course tasks read the public README and API. Experiments go in your fork or harness.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the on-device STFT and the real-time factor. The public Mezon path is this enhancer in the browser, not a second private diagram.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d2N0d6CKrbk&quot;&gt;Group calling architectures in WebRTC: MCU, SFU &amp;amp; P2P&lt;/a&gt; — Tsahi Levent-Levi, English. The SFU forwards the published track. That is the server half of the architecture tour.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. A shipped calling stack is the comparison for what ‘on device, before encode’ has to survive.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-04 DNS Challenge-style metric suites</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter08/08_04_dns_challenge_metrics/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter08/08_04_dns_challenge_metrics</id>
   <content type="html">&lt;p&gt;A single SI-SDR mean is how enhancement papers get quoted and how products get surprised. The Microsoft DNS Challenge (&lt;a href=&quot;https://github.com/microsoft/DNS-Challenge&quot;&gt;microsoft/DNS-Challenge&lt;/a&gt;) is the public pattern this course copies in miniature: synthetic pairs where intrusive metrics are legal, real recordings where they are not, a listening slice, and a systems column so realtime software cannot hide behind a quality table. Challenge editions change their metric menus. Pin the year or the paper you follow. Do not claim you “beat the DNS Challenge” unless you ran that year’s blind set with that year’s protocol.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Evaluation map: intrusive SI-SDR, non-intrusive DNSMOS, and listening tests&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. A suite is the whole map, not one box. SI-SDR, DNSMOS, listening, and RTF answer different questions. Empty cells are written &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, not imputed.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One metric is a blindfold. In the Microsoft DNS Challenge and production voice platforms, teams learned the hard way that optimizing a single number always triggers &lt;strong&gt;metric gaming&lt;/strong&gt;: chase SI-SDR alone and you get phase-obsessed models with lingering background hiss; chase BAK alone and you chop off soft consonants, causing downstream speech-to-text (ASR) Word Error Rate (WER) to spike!&lt;/p&gt;

&lt;p&gt;This lecture integrates everything in Chapter 8 into a unified &lt;strong&gt;DNS Challenge-style evaluation suite&lt;/strong&gt;: combining intrusive fidelity (SI-SDRi), perceptual MOS (SIG/BAK/OVRL), intelligibility / downstream ASR (&lt;strong&gt;WER&lt;/strong&gt;), clean-speech transparency, and real-time systems health (\(\mathrm{RTF}_{p99}\)) into a disciplined release gate.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-multi-objective-evaluation-and-release-gates&quot;&gt;Key ideas: Multi-Objective Evaluation and Release Gates&lt;/h2&gt;

&lt;p&gt;Four evaluation dimensions prevent any single blind spot from slipping into production:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Acoustic Fidelity (SI-SDRi / PESQ / STOI):&lt;/strong&gt; Tracks clean-reference signal reconstruction on synthetic mixtures across SNR buckets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Perceptual Naturalness (DNSMOS SIG / BAK / OVRL + Blind A/B):&lt;/strong&gt; Measures human-aligned listening quality on real-world blind test sets with no clean reference.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Downstream Intelligibility (ASR Word Error Rate — WER):&lt;/strong&gt; A denoiser that sounds “smooth” to a casual listener can still smear subtle fricatives (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/s/&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/f/&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/th/&lt;/code&gt;) and wreck live captions or voice-assistant recognition! Running a frozen Whisper/Conformer ASR model over enhanced clips catches intelligibility regressions automatically.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Systems &amp;amp; Edge Health (\(\mathrm{RTF}_{p99}\), Latency, Bundle Size, Clean-Speech Passthrough):&lt;/strong&gt; Ensures quality wins don’t blow the 10 ms frame budget or degrade already-clean microphones.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to lay out a six-column score sheet with one row per clip, run a checker that rejects a missing column, and explain which cells must be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. You should also separate a lab regression epsilon from any number that appears in a paper.&lt;/p&gt;

&lt;h2 id=&quot;tracks-worth-keeping&quot;&gt;Tracks worth keeping&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Track&lt;/th&gt;
      &lt;th&gt;Material&lt;/th&gt;
      &lt;th&gt;Legal metrics&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Synthetic&lt;/td&gt;
      &lt;td&gt;Noisy/clean pairs you generated&lt;/td&gt;
      &lt;td&gt;SI-SDR, optional PESQ/STOI, delta versus bypass&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Real&lt;/td&gt;
      &lt;td&gt;Meeting-like recordings, no clean file&lt;/td&gt;
      &lt;td&gt;DNSMOS if the checkpoint is pinned, else &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Listening&lt;/td&gt;
      &lt;td&gt;The same conditions, short clips&lt;/td&gt;
      &lt;td&gt;AB note: win, loss, or tie&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Systems&lt;/td&gt;
      &lt;td&gt;The machine that will demo&lt;/td&gt;
      &lt;td&gt;RTF p95, plus init or fallback if you measured it&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Optional downstream&lt;/td&gt;
      &lt;td&gt;Fixed ASR build&lt;/td&gt;
      &lt;td&gt;WER or CER delta, never as a MOS substitute&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Synthetic data gives you SNR knobs and a reference. It also lies when the noise bank is cleaner than a real room. Real data is the product and refuses SI-SDR. The rule is to tune on neither column alone. Freeze a final listening subset that you do not open while you are still changing levels.&lt;/p&gt;

&lt;h2 id=&quot;harness-layout&quot;&gt;Harness layout&lt;/h2&gt;

&lt;p&gt;Keep the harness in your own directory or fork. Do not put it inside the shared product tree &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt;, and do not require the instructor checkout at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;eval/
  datasets/synthetic/   # clean/, noisy/, meta.csv
  datasets/real/
  systems/bypass/
  systems/level60/
  systems/level80/
  scripts/compute_si_sdr.py
  reports/YYYY-MM-DD.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;meta.csv&lt;/code&gt; needs at least &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clip_id,condition,snr_db,clean_path,noisy_path&lt;/code&gt;. Real rows leave &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clean_path&lt;/code&gt; empty. Reproducibility is a header on the report: package version (npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 if that is what you ran), model archive name &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;, DNSMOS checkpoint name or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not run&lt;/code&gt;, OS, and the device you used for RTF. If enhancement is deterministic, say so. If it is not, record the seed.&lt;/p&gt;

&lt;p&gt;There is no official SI-SDR or DNSMOS cutoff to copy into CI. You may choose a lab epsilon after you have a baseline on this exact set, and you must label it as local. A paper’s table is not that epsilon.&lt;/p&gt;

&lt;p&gt;Optional ASR: pick one engine version, transcribe noisy and enhanced with the same settings, and report the delta. Enhancement that helps DNSMOS and hurts WER is a product fact, not a contradiction to hide.&lt;/p&gt;

&lt;h2 id=&quot;report-skeleton&quot;&gt;Report skeleton&lt;/h2&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gu&quot;&gt;## NS eval — &amp;lt;date&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; System: deepfilternet3-noise-filter &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;, setSuppressionLevel &lt;span class=&quot;nt&quot;&gt;&amp;lt;n&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; RTF p95: &lt;span class=&quot;nt&quot;&gt;&amp;lt;number&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;device&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt; or n/a

&lt;span class=&quot;gu&quot;&gt;### Per clip&lt;/span&gt;
(the six-column table from the mini-lab)

&lt;span class=&quot;gu&quot;&gt;### Decision&lt;/span&gt;
Ship, no-ship, or ship behind a flag — and which column forced it.

&lt;span class=&quot;gu&quot;&gt;### Limits&lt;/span&gt;
Languages, devices, and metrics you did not run.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Overfitting shows up as a suite that only contains your own voice, one café, and a mean with no per-condition rows. Re-run after a WASM or SIMD change. Sample equality rarely survives a runtime swap, so the metrics must move with the binary.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Create &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suite.md&lt;/code&gt; with a markdown table of &lt;strong&gt;six data rows&lt;/strong&gt;. The header must contain these columns: clip id, condition, SI-SDR or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, DNSMOS or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, listening note, RTF p95. Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; when the metric is illegal or not run. At least one row must be a real clip (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; SI-SDR) and at least one row must be synthetic. Listening notes are short (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;old&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tie&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not listened&lt;/code&gt;). RTF p95 is a number you measured or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; if you did not.&lt;/p&gt;

&lt;p&gt;Checker &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;check_suite.py&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;suite.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;splitlines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;tables&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;startswith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;header&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tables&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;clip id&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;condition&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;si-sdr&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;dnsmos&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;listening note&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rtf p95&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tables&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ln&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;data_rows&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;missing none
data_rows 6
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Shape example (your six rows must be your own clips; this single row only shows the cells):&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;| clip id | condition | SI-SDR or n/a | DNSMOS or n/a | listening note | RTF p95 |
| --- | --- | --- | --- | --- | --- |
| syn_fan_01 | synthetic fan, 10 dB | 13.80 | n/a | tie | 0.35 |
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The 13.80 here is the lesson 08-01 lab float, pasted so the column type is obvious. It is not a measurement of DeepFilterNet. Failure modes: a header that says “quality” instead of the six names; five rows; a real recording with a made-up SI-SDR; one RTF number copied onto every row without saying it is a session-level figure; an official-looking threshold such as “DNSMOS must exceed 3.5.”&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-a-multi-metric-release-gate-catching-a-hidden-regression&quot;&gt;Worked Numerical Example: A Multi-Metric Release Gate Catching a Hidden Regression&lt;/h3&gt;

&lt;p&gt;Compare Candidate v2.1 against Production v2.0 on a balanced DNS-style release scorecard:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Metric&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Production v2.0&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Candidate v2.1&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Gate Rule&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Pass?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;SI-SDRi (synthetic 0–10 dB)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+11.4	ext{ dB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(+12.6	ext{ dB}\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\ge +11.4	ext{ dB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Pass (\(+1.2	ext{ dB}\)!)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;DNSMOS BAK (real noisy)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3.72\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(4.10\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\ge 3.70\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Pass (\(+0.38\)!)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;DNSMOS SIG (real noisy)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3.55\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3.34\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\ge 3.50\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;FAIL (\(-0.21\))&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Downstream ASR WER&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(4.5\%\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(6.8\%\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\le 4.8\%\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;FAIL (\(+51\%\) relative WER!)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(\mathrm{RTF}_{p99}\) (WASM SIMD)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.38\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.42\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\le 0.50\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Pass&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Look at what this scorecard just saved you from: Candidate v2.1 looked like a slam dunk on SI-SDRi (\(+1.2	ext{ dB}\)) and BAK (\(+0.38\)), yet its over-aggressive masking damaged consonants enough to push ASR WER from \(4.5\%\) to \(6.8\%\) (a &lt;strong&gt;51% relative increase in transcription errors&lt;/strong&gt;)! The multi-metric gate blocks the regression cleanly.&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-building-a-dns-style-evaluation-suite&quot;&gt;Explanation: Four Rules for Building a DNS-Style Evaluation Suite&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Freeze your test sets and never train or tune hyperparameters on them:&lt;/strong&gt; Keep a locked blind test set (synthetic + real + clean) that is touched &lt;em&gt;only&lt;/em&gt; for release decisions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Track both aggregate averages and worst-5% tail clips:&lt;/strong&gt; A model that raises mean OVRL by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+0.15&lt;/code&gt; while completely muting 2% of soft-spoken female or child voices is a release blocker!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Include a clean-speech “do no harm” test:&lt;/strong&gt; Verify that on quiet studio speech, the denoiser preserves SIG, WER, and natural timbre without pumping or gating artifacts.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Automate the full scorecard in one reproducible command:&lt;/strong&gt; Making &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eval_suite.py&lt;/code&gt; emit one JSON + Markdown table per checkpoint turns release reviews from subjective debates into clear engineering decisions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; In the release scorecard above, why did Candidate v2.1 achieve a &lt;em&gt;higher&lt;/em&gt; SI-SDRi and BAK while simultaneously making downstream ASR WER &lt;em&gt;worse&lt;/em&gt;?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Fill all six rows for a mix of synthetic and real conditions. Run the checker until it prints &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;data_rows 6&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Write the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;meta.csv&lt;/code&gt; header and one synthetic row and one real row.&lt;/li&gt;
  &lt;li&gt;Propose a CI fail rule that does not pretend to be an official DNSMOS threshold.&lt;/li&gt;
  &lt;li&gt;Name two ways a suite overfits Mezon meeting audio, and the holdout that blocks each.&lt;/li&gt;
  &lt;li&gt;Add an ASR column as optional. State why it must not replace the listening note.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Real rows: SI-SDR is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. Rows without a DNSMOS run: DNSMOS is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Real row: empty clean path. Do not invent a reference file.&lt;/li&gt;
  &lt;li&gt;Example policy: “on this 12-clip golden set, fail if the per-condition DNSMOS mean drops by more than the epsilon written in the report.” The epsilon is yours.&lt;/li&gt;
  &lt;li&gt;Only the author’s voice; only café. Hold out other talkers and a keyboard or fan condition you do not tune on.&lt;/li&gt;
  &lt;li&gt;WER can rise when the suppressor damages consonants the metric likes. Keep the listening note.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the challenge section: synthetic pairs, a listening test, and an objective predictor reported together. A single SI-SDR mean is what this talk refuses to stop at.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. The training-data mention is a model sitting on DNS material. Use the talk as one row in the suite, not as the suite itself.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-03 Listening tests</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter08/08_03_listening_tests/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter08/08_03_listening_tests</id>
   <content type="html">&lt;p&gt;SI-SDR can stay high while the voice turns metallic, and DNSMOS can miss a domain your users actually occupy. A listening test is the column that catches both, if you control loudness, order, and the clip grid. You do not need an ITU-certified lab to learn the discipline. You do need a written protocol, blinded labels, and a table that can lose. This lesson is a small AB (or MUSHRA-like) design for an engineering team deciding whether to change &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Evaluation map: intrusive SI-SDR, non-intrusive DNSMOS, and listening tests&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Listening tests are the slow, high-value column. They arbitrate when SI-SDR and DNSMOS disagree, which is a normal outcome on real microphones.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Every audio team eventually learns a humbling lesson: you listen to your brand-new model on your own desk, convinced it sounds “way cleaner” than production—only to run a &lt;strong&gt;blind randomized A/B test&lt;/strong&gt; where listeners can’t see which clip is which, and discover your new model actually lost 60–40! Confirmation bias in human hearing is astonishingly powerful; the moment you know which clip is “Model B,” your brain hears what it &lt;em&gt;wants&lt;/em&gt; to hear.&lt;/p&gt;

&lt;p&gt;This lecture teaches how to run rigorous, lightweight &lt;strong&gt;subjective listening tests&lt;/strong&gt; (blind A/B preference, &lt;strong&gt;CCR&lt;/strong&gt;, &lt;strong&gt;ACR / P.835&lt;/strong&gt;, and &lt;strong&gt;MUSHRA&lt;/strong&gt;) and how to compute exact sample-size confidence intervals so you never mistake 10 noisy votes for a real perceptual win.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-psychophysics-and-statistical-rigor-in-listening-tests&quot;&gt;Key ideas: Psychophysics and Statistical Rigor in Listening Tests&lt;/h2&gt;

&lt;p&gt;Four experimental principles separate trustworthy listening tests from wishful thinking:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Double-Blind Randomization &amp;amp; Loudness Normalization:&lt;/strong&gt; Listeners must never see system labels, clip order must be randomized per trial, and all systems must be loudness-matched (e.g., \(-24	ext{ LUFS}\))—because human ears reflexively rate a 1.5 dB louder clip as “better”!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choosing the Right Protocol:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Blind A/B (or ABX):&lt;/strong&gt; Fastest for comparing 2 candidate models (e.g., current prod vs. new candidate).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;P.835 (SIG/BAK/OVRL):&lt;/strong&gt; Separates speech distortion from background suppression on 1–5 scales.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;MUSHRA (0–100):&lt;/strong&gt; Gold standard for subtle differences among 3–6 systems, calibrated with a hidden reference (100) and a low-quality anchor (e.g., 3.5 kHz low-pass).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Anchor Traps &amp;amp; Listener Screening:&lt;/strong&gt; Including hidden reference and degraded anchor clips immediately detects distracted raters clicking randomly.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Binomial Confidence Intervals &amp;amp; Statistical Power:&lt;/strong&gt; With only \(N = 10\) votes, a 7–3 split (70%) is still completely compatible with a 50/50 coin flip; you need enough independent clips and listeners to separate signal from sampling variance.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to pick AB versus a light MUSHRA-like scale, loudness-normalize the stimuli, randomize order, write rater instructions in English and Vietnamese, and report wins, losses, and ties per condition. You should also know when a day of dogfooding is enough and when it is not.&lt;/p&gt;

&lt;h2 id=&quot;pick-a-protocol-that-matches-the-decision&quot;&gt;Pick a protocol that matches the decision&lt;/h2&gt;

&lt;p&gt;Informal dogfooding — using noise suppression in a real meeting — catches crashes, CPU spikes, and “I hate this” moments. It does not estimate a preference rate. AB asks each rater to prefer A, prefer B, or tie, on one pair. That is the right tool for level 80 versus level 60, or for the processor enabled versus bypassed with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt;. An ABC task adds a raw microphone anchor. A MUSHRA-like scale, inspired by ITU-R BS.1534, rates several systems against an anchor and needs more rater training. ITU-T P.808 describes crowdsourced conversational-speech tests; read it as a standard to respect, then run a lightweight variant and say so in the report. Do not label a five-person hallway test as P.808.&lt;/p&gt;

&lt;h2 id=&quot;controls-that-keep-the-result-about-noise-suppression&quot;&gt;Controls that keep the result about noise suppression&lt;/h2&gt;

&lt;p&gt;Loudness is the classic confound. If the suppressed file is quieter, raters who were told to judge “comfort” will pick it even when fricatives died. Normalize integrated loudness toward a common target and say which tool you used. Randomize which system is A on each clip. Never park the new level on the right. Show “System 1” and “System 2,” not “DF3-80.” Use the same headphones when you can, and record the device when you cannot. Prefer 5–10 seconds that contain the hard noise and a consonant, not a full minute that exhausts the rater. Keep the playback path identical: same browser, same sample rate, no extra limiter on one side.&lt;/p&gt;

&lt;p&gt;Include a clean-speech control. A suppressor that only helps on café babble and wounds a quiet sentence is not a default you can ship. Include at least one impulsive noise (keyboard) and one babble noise. A single favorite café clip is how suites overfit.&lt;/p&gt;

&lt;h2 id=&quot;a-grid-not-a-dump&quot;&gt;A grid, not a dump&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Noise&lt;/th&gt;
      &lt;th&gt;Difficulty&lt;/th&gt;
      &lt;th&gt;Device&lt;/th&gt;
      &lt;th&gt;Why it is here&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Café babble&lt;/td&gt;
      &lt;td&gt;Hard&lt;/td&gt;
      &lt;td&gt;Laptop mic&lt;/td&gt;
      &lt;td&gt;Overlapping speech-like noise&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Keyboard&lt;/td&gt;
      &lt;td&gt;Medium&lt;/td&gt;
      &lt;td&gt;Laptop&lt;/td&gt;
      &lt;td&gt;Impulsive; easy to over-cut&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Fan or AC&lt;/td&gt;
      &lt;td&gt;Easier&lt;/td&gt;
      &lt;td&gt;Phone&lt;/td&gt;
      &lt;td&gt;Stationary; bandwidth differs&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Traffic&lt;/td&gt;
      &lt;td&gt;Hard&lt;/td&gt;
      &lt;td&gt;Phone&lt;/td&gt;
      &lt;td&gt;Low-frequency rumble&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Quiet room&lt;/td&gt;
      &lt;td&gt;Control&lt;/td&gt;
      &lt;td&gt;Laptop&lt;/td&gt;
      &lt;td&gt;Over-suppression detector&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Eight to fifteen clips and five to ten raters is a small team test. Write \(N\) in the table. Repeat two clips with the labels flipped as an attention check. If a rater contradicts themselves on both, set their sheet aside and say so. Translate the instruction sheet into Vietnamese when the raters work in Vietnamese. The decision criterion must stay the same language-to-language: clear consonants, a natural voice, low distraction, and a penalty for muffling, robotic timbre, or chopped words. Tell raters to ignore leftover loudness differences.&lt;/p&gt;

&lt;h2 id=&quot;what-you-report&quot;&gt;What you report&lt;/h2&gt;

&lt;p&gt;For AB, report wins for the candidate, wins for the baseline, and ties, overall and per condition. A keyboard win plus a café loss is a split decision: you might ship the lower suppression level as default and document the residual café noise, or you might refuse to change the default. You do not average those rows into a single triumphant percentage. Attach one example you have rights to play on demo day (lesson 09-05), with the condition named.&lt;/p&gt;

&lt;p&gt;Stakeholder table shape:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Condition&lt;/th&gt;
      &lt;th&gt;New wins&lt;/th&gt;
      &lt;th&gt;Old wins&lt;/th&gt;
      &lt;th&gt;Ties&lt;/th&gt;
      &lt;th&gt;N&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Keyboard&lt;/td&gt;
      &lt;td&gt;7&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;10&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Café&lt;/td&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;10&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Quiet&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;10&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The quiet row full of ties is a success if the candidate was not supposed to touch clean speech. A quiet row where “old” wins means the new level is eating the voice.&lt;/p&gt;

&lt;h2 id=&quot;when-dogfooding-is-the-whole-test&quot;&gt;When dogfooding is the whole test&lt;/h2&gt;

&lt;p&gt;Use dogfooding alone for a change that must be bit-identical in the waveform: a CDN fallback, a logging line, a cache header. Use it for an internal flag that does not change the default listeners hear. Require the structured test when you change the default suppression level, ship a new WASM or model archive, or respond to “the voice sounds weird.” RTF work can skip listening only when the output samples match a golden wav within a tolerance you wrote down. A faster build that is not sample-close is a new system.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ab_protocol.md&lt;/code&gt; for a suppression-level change (for example 80 versus 60 on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;). Then run the checker. The lab passes when the protocol names loudness, blinding, a clean control, and both languages.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ab_protocol.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;loudness&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;blind&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;tie&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;quiet&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;keyboard&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;cafe&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;vietnamese&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setsuppressionlevel&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;chars&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;missing none
chars &amp;lt;some integer above 400&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The character count will be your own. The checker’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;missing none&lt;/code&gt; line is the pass signal. Failure modes: unblinded filenames in the rater UI; no tie option, which forces a preference when the clips match; no quiet control; instructions only in English for a Vietnamese-speaking panel; judging a level change on one talker’s voice.&lt;/p&gt;

&lt;p&gt;A minimal protocol body that satisfies the checker will state the task in both languages, name &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, and list the three conditions. Expand it with the rater paragraph from this lesson rather than keyword-stuffing.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-how-many-votes-do-you-need-for-a-confident-blind-ab-win&quot;&gt;Worked Numerical Example: How Many Votes Do You Need for a Confident Blind A/B Win?&lt;/h3&gt;

&lt;p&gt;Suppose you run a blind A/B preference test comparing New Model B against Prod Model A (excluding ties), and &lt;strong&gt;70%&lt;/strong&gt; of ratings prefer Model B (\(\hat{p} = 0.70\)). Compute the 95% Wald confidence interval \(\hat{p} \pm 1.96\sqrt{rac{\hat{p}(1-\hat{p})}{N}}\) for two test sizes:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Test Size \(N\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Votes for B&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Observed \(\hat{p}\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Standard Error \(\mathrm{SE}\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;95% Confidence Interval&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Statistically Significant (excludes 0.50)?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(N = 10\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;7 / 10&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.70\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\sqrt{rac{0.21}{10}} = 0.145\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\([0.416,\; 0.984]\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;NO&lt;/strong&gt; (contains 0.50—could be luck!)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(N = 40\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;28 / 40&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.70\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\sqrt{rac{0.21}{40}} = 0.0725\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\([0.558,\; 0.842]\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;YES&lt;/strong&gt; (cleanly above 0.50!)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(N = 100\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;70 / 100&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.70\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(\sqrt{rac{0.21}{100}} = 0.0458\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\([0.610,\; 0.790]\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;YES&lt;/strong&gt; (tight estimate!)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;That simple calculation explains why “I asked 5 teammates to listen to 2 clips” is never enough—even a 70% win rate needs roughly &lt;strong&gt;35–40 independent ratings&lt;/strong&gt; (e.g., 8 listeners × 5 diverse clips, or 10 listeners × 4 clips) to clear 95% confidence!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-running-fast-honest-listening-tests&quot;&gt;Explanation: Four Rules for Running Fast, Honest Listening Tests&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Loudness-normalize every clip before anyone presses play:&lt;/strong&gt; A 2 dB louder output wins blind A/B tests almost automatically—normalize all systems to the same active speech LUFS first.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stratify your test playlist across failure modes:&lt;/strong&gt; Include (a) steady fan/AC noise, (b) babble/café voices, (c) sudden keyboard clicks, (d) double-talk/echo, and (e) &lt;strong&gt;clean quiet speech&lt;/strong&gt; to catch clean-speech degradation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Require headphones and keep sessions under 15 minutes:&lt;/strong&gt; Listener fatigue sets in fast; 15–20 short 6-second clips yield far sharper judgments than 60 clips in one sitting.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always inspect the clips where your new model &lt;em&gt;lost&lt;/em&gt;:&lt;/strong&gt; Aggregate win rate tells you &lt;em&gt;whether&lt;/em&gt; to ship; the 3 clips where your model lost tell you &lt;em&gt;what to fix next&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; Why does a MUSHRA listening test include both a &lt;strong&gt;hidden clean reference&lt;/strong&gt; and a &lt;strong&gt;hidden low-quality anchor&lt;/strong&gt; alongside the candidate denoisers?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Write the rater paragraph in English and a natural Vietnamese equivalent. Keep the same penalties.&lt;/li&gt;
  &lt;li&gt;List nine filenames for a 3×3 grid (babble, keyboard, quiet × laptop, phone, headset).&lt;/li&gt;
  &lt;li&gt;Keyboard: new wins 7–2–1. Café: new wins 4–5–1. Quiet: 3–2–5. What do you ship as the default level, and what do you retest?&lt;/li&gt;
  &lt;li&gt;Define an attention-check rule for one duplicated clip.&lt;/li&gt;
  &lt;li&gt;Name two product changes that do not need this protocol, and one that does.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Penalize muffling, robotic timbre, and chopped words. Ignore small loudness gaps. Vietnamese should sound like an instruction to a colleague, not a word-for-word gloss.&lt;/li&gt;
  &lt;li&gt;Encode condition and device in the stem, for example &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;babble__laptop__01.wav&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Do not ship on the keyboard row alone. The café loss and the quiet ties mean you either keep the old default or retest a middle level. Say which.&lt;/li&gt;
  &lt;li&gt;Flip A/B on the duplicate. A rater who flips their own preference fails the check.&lt;/li&gt;
  &lt;li&gt;CDN fallback with unchanged samples can be dogfood. A new default for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; cannot.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the crowdsourced P.808 section: references, anchors, and screening. That is the listening discipline in the lesson, even when your grid is smaller than a full ITU lab.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-02 DNSMOS and non-intrusive MOS predictors</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter08/08_02_dnsmos/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter08/08_02_dnsmos</id>
   <content type="html">&lt;p&gt;Customer calls do not ship with a clean reference, so SI-SDR is undefined on the audio you most need to judge. DNSMOS is the non-intrusive predictor associated with Microsoft’s Deep Noise Suppression Challenge: a network that estimates a mean-opinion score from the enhanced signal alone. Reddy, Gopal, and Cutler published DNSMOS at Interspeech 2021 and DNSMOS P.835 at ICASSP 2022. Both are tools for ranking clips inside a frozen domain. Neither is an official pass/fail threshold, and a move of a few hundredths is not a ship decision by itself. This lesson shows how to pin a version, how domain shift breaks the score, and how to file the number next to listening notes.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Evaluation map: intrusive SI-SDR, non-intrusive DNSMOS, and listening tests&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. DNSMOS occupies the non-intrusive column. It does not need \(s\). It still does not replace a listening test when the noise or the language leaves the training domain.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When a user records a real voice call from a noisy Bangkok café, you do &lt;strong&gt;not&lt;/strong&gt; have a clean studio twin of their voice—so SI-SDR, PESQ, and STOI are completely unusable! How do Microsoft’s DNS Challenge and modern audio teams score thousands of real-world field recordings automatically? They train a neural network (&lt;strong&gt;DNSMOS&lt;/strong&gt;) directly on tens of thousands of human &lt;strong&gt;ITU-T P.835&lt;/strong&gt; listening-test ratings so it predicts perceptual quality &lt;strong&gt;non-intrusively&lt;/strong&gt; from the enhanced audio alone.&lt;/p&gt;

&lt;p&gt;This lecture explains how DNSMOS splits perceived speech quality into three indispensable axes—&lt;strong&gt;SIG&lt;/strong&gt; (speech naturalness), &lt;strong&gt;BAK&lt;/strong&gt; (background cleanliness), and &lt;strong&gt;OVRL&lt;/strong&gt; (overall quality)—and why chasing a higher BAK score while ignoring SIG is the fastest way to ship a robotic-sounding denoiser.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-non-intrusive-perceptual-quality-prediction&quot;&gt;Key ideas: Non-Intrusive Perceptual Quality Prediction&lt;/h2&gt;

&lt;p&gt;Four concepts ground DNSMOS and modern MOS predictors (NISQA, UTMOS):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Non-Intrusive (Reference-Free) Evaluation:&lt;/strong&gt; Takes &lt;em&gt;only&lt;/em&gt; the output waveform \(\hat{\mathbf{s}}\) (resampled to 16 kHz) and predicts the Mean Opinion Score (MOS, 1.0–5.0) a panel of human listeners would give—making field telemetry and real-world test sets scorable at scale.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The ITU-T P.835 Triad (SIG / BAK / OVRL):&lt;/strong&gt; Human perception of denoised speech has a built-in tension: aggressively suppressing noise boosts &lt;strong&gt;BAK&lt;/strong&gt; (quiet background) but risks chewing up consonants and hurting &lt;strong&gt;SIG&lt;/strong&gt; (speech distortion). &lt;strong&gt;OVRL&lt;/strong&gt; captures the joint trade-off.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Domain Shift &amp;amp; Calibration Limits:&lt;/strong&gt; Because DNSMOS is itself a neural network trained on DNS Challenge crowdsourced ratings, it can be slightly miscalibrated on singing, non-English tonal languages, extreme codec artifacts, or brand-new generative vocoders.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Never Train Directly to Hack DNSMOS:&lt;/strong&gt; Using a fixed MOS predictor as a direct training loss invites &lt;em&gt;Goodhart’s Law&lt;/em&gt;—models learn subtle adversarial spectral quirks that fool DNSMOS into predicting 4.5 while sounding awful to real humans!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to say when DNSMOS is the right column (no clean \(s\)), name the two papers without inventing a cutoff, and design a small golden set whose &lt;strong&gt;deltas&lt;/strong&gt; you can re-run after a suppression-level change. You should also list the domain shifts that make a higher score the wrong product call.&lt;/p&gt;

&lt;h2 id=&quot;where-it-sits-in-the-stack&quot;&gt;Where it sits in the stack&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Setting&lt;/th&gt;
      &lt;th&gt;Clean reference?&lt;/th&gt;
      &lt;th&gt;What you can compute&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Synthetic DNS-style mixture&lt;/td&gt;
      &lt;td&gt;Yes&lt;/td&gt;
      &lt;td&gt;SI-SDR, and PESQ or STOI if you choose to install them&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Real laptop or phone recording&lt;/td&gt;
      &lt;td&gt;No&lt;/td&gt;
      &lt;td&gt;DNSMOS (version pinned) and a listening note&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ship review&lt;/td&gt;
      &lt;td&gt;Sometimes a tiny labeled subset&lt;/td&gt;
      &lt;td&gt;Predictor deltas &lt;strong&gt;and&lt;/strong&gt; humans, plus RTF&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The challenge data, baselines, and blind sets live in &lt;a href=&quot;https://github.com/microsoft/DNS-Challenge&quot;&gt;microsoft/DNS-Challenge&lt;/a&gt;. Challenge years do not share one metric list. When you write “DNSMOS” in a table, write the predictor build you ran (P.808-style DNSMOS versus DNSMOS P.835) and the checkpoint filename. Scores from two checkpoints are not one time series.&lt;/p&gt;

&lt;h2 id=&quot;what-the-predictor-returns&quot;&gt;What the predictor returns&lt;/h2&gt;

&lt;p&gt;DNSMOS reads one waveform and returns a scalar, or a small tuple of scalars in the P.835 variant (signal quality, background noise, and overall). It does not see the clean studio take, so it cannot punish a time shift the way SI-SDR does, and it cannot tell you ΔSI-SDR. It is happy to score a file that is mostly silence if you let that file dominate the mean. It is an offline batch tool. It is not a substitute for the realtime telemetry in Chapters 05–07: init time, fallback when the CDN misses, and RTF inside the audio callback.&lt;/p&gt;

&lt;p&gt;P.835 separates speech quality from background noise. That split matters when the noise floor is quiet and the voice is thin. Report the components you actually have. This course does not publish an official DNSMOS pass line. If your team picks an internal epsilon, label it as a lab policy on a named golden set, not as a property of the paper.&lt;/p&gt;

&lt;h2 id=&quot;domain-shift-is-the-failure-mode&quot;&gt;Domain shift is the failure mode&lt;/h2&gt;

&lt;p&gt;The networks were trained to track listening labels from challenge-like speech and noise. A Mezon meeting is a different generator. Treat these as breaks:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Language and accent. A model that tracked English challenge listeners can move for the wrong reason on Vietnamese speech, regional tone, or code-switching.&lt;/li&gt;
  &lt;li&gt;Codec. Opus at a low bitrate already sounds rough. The predictor may charge that roughness to your noise suppressor.&lt;/li&gt;
  &lt;li&gt;Non-speech. Music, notification chirps, and screen-share audio are outside the speech-enhancement domain the challenge optimized.&lt;/li&gt;
  &lt;li&gt;Aggressive suppression. Some predictors reward a quieter residual even when consonants are gone. Users do not.&lt;/li&gt;
  &lt;li&gt;Bandwidth. A 16 kHz file and a 48 kHz file are different inputs. Resample with a written rule, or score each rate in its own column.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Freeze a golden set: café babble, keyboard, fan, a quiet room, and one clip with residual echo if the product still has any. Store the wavs, the DNSMOS version, and the enhancement command. Track the &lt;strong&gt;change&lt;/strong&gt; against the pinned package (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 or the version you actually run), per condition, with the clip count visible. A mean that moves because one silent file was added is not a model win.&lt;/p&gt;

&lt;h2 id=&quot;how-to-combine-columns&quot;&gt;How to combine columns&lt;/h2&gt;

&lt;p&gt;Use SI-SDR on synthetic twins when you have them (08-01). Use DNSMOS on the real golden set. Use a blinded AB or a small MUSHRA-like pass (08-03) on the same conditions before you change the default of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. Keep RTF p95 next to the quality numbers so a “better” MOS that misses the AudioWorklet deadline is visible. Ship when the real-set delta and the listening note agree and the realtime budget still holds. A peak on synthetic SI-SDR alone is a research note, not a release.&lt;/p&gt;

&lt;p&gt;A CI sketch, still conceptual until you own the machines:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;on a change that can alter audio:
  use the pinned golden wavs (git-lfs or a versioned archive)
  enhance offline with the same level and sample rate
  run the pinned DNSMOS checkpoint
  upload the CSV
  fail only on a lab epsilon you wrote down for this set
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Do not let CI download an unbounded noise corpus. Do not fail the build because a paper abstract once showed a score near 3. Something. That number is not your epsilon.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Create &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dnsmos_plan.md&lt;/code&gt; for a no-reference folder. You are not required to run the DNSMOS weights in this lab (they are a separate download and a version pin). You are required to show that every real clip has an explicit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; plan for SI-SDR and a named DNSMOS variant.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;golden/
  cafe__laptop.wav
  keyboard__laptop.wav
  fan__phone.wav
  quiet__laptop.wav
dnsmos_plan.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Put this table in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dnsmos_plan.md&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;| clip id | condition | SI-SDR | DNSMOS variant | why this clip can fool the predictor |
| cafe__laptop | babble, no clean ref | n/a | P.835 or the build you will pin | overlapping talkers |
| keyboard__laptop | key clicks | n/a | same build | impulsive noise, not the challenge average |
| fan__phone | stationary hum | n/a | same build | phone bandwidth |
| quiet__laptop | clean-speech control | n/a | same build | over-suppression on an already quiet file |
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 check_dnsmos_plan.py&lt;/code&gt; after you save the file:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;dnsmos_plan.md&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read_text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;n/a&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;p.835&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;cafe__laptop&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;keyboard__laptop&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fan__phone&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;quiet__laptop&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;need&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;missing none
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Failure modes: writing a numeric SI-SDR for a real file that has no clean reference; mixing P.835 and the 2021 DNSMOS scalar in one mean; dropping the quiet control so over-suppression cannot be seen; treating any absolute score as an official Microsoft cutoff.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-diagnosing-over-suppression-with-the-sig--bak--ovrl-triad&quot;&gt;Worked Numerical Example: Diagnosing Over-Suppression with the SIG / BAK / OVRL Triad&lt;/h3&gt;

&lt;p&gt;Suppose two candidate models are evaluated on 200 real-world noisy café recordings using DNSMOS P.835 (1–5 scale, higher is better):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;System&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;strong&gt;SIG&lt;/strong&gt; (Speech Quality)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;strong&gt;BAK&lt;/strong&gt; (Background Cleanliness)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;strong&gt;OVRL&lt;/strong&gt; (Overall MOS)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Listening Diagnosis&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Noisy Input&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3.25\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1.85\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2.15\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Loud café chatter, voice intact&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Model A (Balanced)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(3.58\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3.75\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(3.22\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Natural voice, gentle residual hum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Model B (Aggressive)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2.88\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(4.25\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2.74\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Dead-silent background, choppy/robotic speech!&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Look closely at &lt;strong&gt;Model B&lt;/strong&gt;: it wins BAK by a huge &lt;strong&gt;\(+0.50\) MOS&lt;/strong&gt; over Model A, yet its &lt;strong&gt;SIG drops below the noisy input&lt;/strong&gt; (\(2.88 &amp;lt; 3.25\)) and its &lt;strong&gt;OVRL loses by \(-0.48\) MOS&lt;/strong&gt;! Without separating SIG from BAK, an engineer looking only at background silence would ship the worse model.&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-using-dnsmos-in-model-development&quot;&gt;Explanation: Four Rules for Using DNSMOS in Model Development&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always inspect all three numbers (SIG, BAK, OVRL) together:&lt;/strong&gt; Set a hard floor on SIG (never allow SIG to degrade below baseline) even when celebrating a BAK jump.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Respect the 16 kHz input expectation of DNSMOS:&lt;/strong&gt; If your denoiser runs at 48 kHz, DNSMOS downsamples to 16 kHz—meaning it is completely &lt;strong&gt;blind&lt;/strong&gt; to high-frequency artifacts between 8 kHz and 24 kHz! Pair it with full-band listening checks.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate on diverse real-world noise + clean speech:&lt;/strong&gt; Always run DNSMOS on &lt;em&gt;clean&lt;/em&gt; studio speech too—a good denoiser must leave clean speech untouched (SIG \(pprox\) clean input), not degrade it!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Use DNSMOS to narrow 20 experiments down to 2, then use human ears:&lt;/strong&gt; Automated MOS predictors are phenomenal screening filters, never a replacement for a blind listening test before a major release.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; If a 48 kHz denoiser introduces a harsh metallic ringing artifact at \(12	ext{ kHz}\), why will standard 16 kHz DNSMOS fail to catch it?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;In four sentences, state the policy “when this team runs DNSMOS,” including version pin, golden-set path, and the ban on an official threshold.&lt;/li&gt;
  &lt;li&gt;Give three domain shifts that matter for a Vietnamese meeting app using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, and one clip filename for each.&lt;/li&gt;
  &lt;li&gt;A golden-set mean rises by 0.05 after you change &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. What extra table would you demand before calling it an improvement?&lt;/li&gt;
  &lt;li&gt;Explain why DNSMOS on a stereo mix, or on a file that is half silence, can look strong while the call sounds worse.&lt;/li&gt;
  &lt;li&gt;Name the column you will leave as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; on these four files, and the column you will leave as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt; on a synthetic pair when the DNSMOS weights are not installed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Run one named build (DNSMOS or DNSMOS P.835). Store deltas on a frozen set. Any epsilon is local policy. Reddy, Gopal, and Cutler did not hand you a ship line.&lt;/li&gt;
  &lt;li&gt;Plausible shifts: tonal Vietnamese speech, Opus artifacts, fan-plus-keyboard rooms, Zalo/Meet-style device mics. Filenames should encode noise and device.&lt;/li&gt;
  &lt;li&gt;Per-condition means and clip counts, not one average. Then a blinded listen on the condition that moved.&lt;/li&gt;
  &lt;li&gt;The predictor scores what it sees. A downmix can hide a bad channel. Silence inflates a mean if you do not gate it.&lt;/li&gt;
  &lt;li&gt;Real files: SI-SDR is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. Synthetic files without the checkpoint: DNSMOS is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. Do not backfill either cell.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the DNSMOS section: a non-intrusive predictor trained to track human scores when the clean reference does not exist.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>08-01 SI-SDR and related intrusive metrics</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter08/08_01_si_sdr/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter08/08_01_si_sdr</id>
   <content type="html">&lt;p&gt;An intrusive metric scores an enhanced waveform against a clean reference of the same utterance. Scale-invariant signal-to-distortion ratio (SI-SDR), introduced by Le Roux, Wisdom, Erdogan, and Hershey in “SDR – Half-baked or Well Done?” (ICASSP 2019), is the number most speech-enhancement labs print first. It answers a narrow question: after the best global gain is removed, how much of the estimate is still not the reference? It does not answer whether the result sounds metallic, whether consonants survived, or whether a meeting client can run the model on time. This lesson builds the formula, a NumPy lab with printed floats, and the alignment failures that make the number lie.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/eval-metric-map.png&quot; alt=&quot;Evaluation map: intrusive SI-SDR, non-intrusive DNSMOS, and listening tests&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. SI-SDR sits in the intrusive column. It needs a time-aligned clean reference. A ship decision for Mezon noise suppression still needs DNSMOS or listening notes, plus RTF.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Suppose your new speech denoiser produces audio that is &lt;strong&gt;100% identical&lt;/strong&gt; to the clean studio recording—except it is 3 dB quieter (multiplied by \(0.707\)). Your ears can barely tell the difference (you just nudge the volume slider), yet a naive Mean Squared Error (MSE) or classic SDR metric penalizes it brutally as if it were full of distortion! That exact flaw motivated &lt;strong&gt;SI-SDR (Scale-Invariant Signal-to-Distortion Ratio)&lt;/strong&gt;—the workhorse intrusive metric of modern speech enhancement and source separation.&lt;/p&gt;

&lt;p&gt;This lecture derives SI-SDR from pure vector projection geometry, walks through a complete hand-verifiable numerical example, and explains why SI-SDR is indispensable for training and ablation—yet must &lt;em&gt;never&lt;/em&gt; be your sole release metric.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-vector-projection-geometry-behind-intrusive-audio-metrics&quot;&gt;Key ideas: Vector Projection Geometry Behind Intrusive Audio Metrics&lt;/h2&gt;

&lt;p&gt;Four signal-processing concepts frame intrusive (reference-based) evaluation:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Intrusive = Requires Clean Ground Truth \(\mathbf{s}\):&lt;/strong&gt; Metrics like SI-SDR, PESQ, and STOI compare the enhanced waveform \(\hat{\mathbf{s}}\) directly against the exact clean reference \(\mathbf{s}\)—which exists in synthetic mixtures, &lt;em&gt;not&lt;/em&gt; in real recorded calls!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Orthogonal Projection Eliminates Gain Sensitivity:&lt;/strong&gt; SI-SDR projects \(\hat{\mathbf{s}}\) orthogonally onto the clean signal direction \(\mathbf{s}\) via optimal scalar \(lpha = rac{\langle \hat{\mathbf{s}}, \mathbf{s}
angle}{\|\mathbf{s}\|^2}\). The component \(\mathbf{s}_{	ext{target}} = lpha\mathbf{s}\) is true signal; the perpendicular residual \(\mathbf{e}_{	ext{noise}} = \hat{\mathbf{s}} - lpha\mathbf{s}\) is pure distortion!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SI-SDR Improvement (SI-SDRi):&lt;/strong&gt; Raw SI-SDR depends heavily on how noisy the input was; &lt;strong&gt;SI-SDRi&lt;/strong&gt; \(= \mathrm{SI	ext{-}SDR}(\hat{\mathbf{s}}, \mathbf{s}) - \mathrm{SI	ext{-}SDR}(\mathbf{x}, \mathbf{s})\) measures the net decibel gain added by your denoiser.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Waveform Fidelity vs. Human Perception:&lt;/strong&gt; Because SI-SDR is a time-domain inner product, tiny sample-level phase shifts or 1-sample timing offsets can crater SI-SDR even when the audio sounds completely transparent to human ears!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-you-should-be-able-to-do&quot;&gt;What you should be able to do&lt;/h2&gt;

&lt;p&gt;You should be able to compute SI-SDR from the projection formula, explain why a pure gain leaves the score perfect, and explain why a one-sample delay can collapse it. You should report SI-SDR only on pairs you have aligned, and you should refuse to treat a high score as permission to skip a listening check.&lt;/p&gt;

&lt;h2 id=&quot;intrusive-setup&quot;&gt;Intrusive setup&lt;/h2&gt;

&lt;p&gt;Keep three signals distinct. The clean reference is \(s\). The microphone mixture is \(x = s + n\), useful for input SNR and for ΔSI-SDR, but it is not the reference. The enhancer output is \(\hat{s}\). SI-SDR compares \(s\) and \(\hat{s}\) at the same sample rate, the same length, and the same time origin. If the enhancer is DeepFilterNet-style, algorithmic latency from the STFT hop and any look-ahead must be removed before the inner product. A positive delay of even one hop dumps reference energy into the residual and the score falls off a cliff.&lt;/p&gt;

&lt;h2 id=&quot;from-sdr-to-si-sdr&quot;&gt;From SDR to SI-SDR&lt;/h2&gt;

&lt;p&gt;Classical SDR treats every gain error as distortion:&lt;/p&gt;

\[\mathrm{SDR} = 10 \log_{10} \frac{\| s \|^2}{\| \hat{s} - s \|^2}\]

&lt;p&gt;If \(\hat{s} = 2s\), the residual is as large as the reference and SDR is 0 dB, even though a listener hears the same waveform louder. Scale-invariant SDR first projects the estimate onto the reference, which is the optimal scalar gain in the least-squares sense:&lt;/p&gt;

\[s_{\mathrm{target}} = \frac{\langle \hat{s}, s \rangle}{\| s \|^2}\, s\]

\[e_{\mathrm{noise}} = \hat{s} - s_{\mathrm{target}}\]

\[\mathrm{SI\text{-}SDR} = 10 \log_{10} \frac{\| s_{\mathrm{target}} \|^2}{\| e_{\mathrm{noise}} \|^2}\]

&lt;p&gt;The target is the part of \(\hat{s}\) that is a scaled copy of \(s\). Everything orthogonal to \(s\) is distortion. A pure gain makes \(e_{\mathrm{noise}} = 0\) and the ratio goes to \(+\infty\). Some library ports of Le Roux et al. also subtract the mean of each vector before the projection. This lesson’s lab does &lt;strong&gt;not&lt;/strong&gt; remove the mean, so your printout must match the floats below. If a helper function zero-means, it will not print 13.80 on this pair.&lt;/p&gt;

&lt;h2 id=&quot;a-numeric-pair-you-can-recompute&quot;&gt;A numeric pair you can recompute&lt;/h2&gt;

&lt;p&gt;Take \(s = [1, 0, -1, 0.5]\) and \(\hat{s} = [0.8, 0.1, -0.7, 0.6]\). The projection coefficient is \(\langle \hat{s}, s \rangle / \|s\|^2\). The residual is small but not zero, and SI-SDR prints &lt;strong&gt;13.80 dB&lt;/strong&gt;. Shift the estimate by one sample, \(\hat{s}_{\mathrm{delay}} = [0, 0.8, 0.1, -0.7]\), and the same function prints &lt;strong&gt;−10.67 dB&lt;/strong&gt;. Nothing about the spectrum changed in a deep way; the time origin did. That is why every batch script in this course aligns before it averages.&lt;/p&gt;

&lt;p&gt;When a mixture \(x\) is available, also report improvement:&lt;/p&gt;

\[\Delta\mathrm{SI\text{-}SDR} = \mathrm{SI\text{-}SDR}(\hat{s}, s) - \mathrm{SI\text{-}SDR}(x, s)\]

&lt;p&gt;A model that scores 12 dB on an already-clean file can have a negative delta. Input SNR of the mixture is a different quantity: it compares \(s\) to \(n\), not \(\hat{s}\) to \(s\).&lt;/p&gt;

&lt;h2 id=&quot;alignment-checklist&quot;&gt;Alignment checklist&lt;/h2&gt;

&lt;p&gt;Prefer generating the reference at the model rate (48 kHz in the DeepFilterNet papers) and document any resample. Trim both sides to the same length and write down which tail you cut. Compensate a known hop delay, or estimate it once on a calibration clip and freeze that shift. Compare mono to mono. Global gain is free under SI-SDR. A compressor that pumps inside the utterance is not, and neither is residual echo the reference never contained.&lt;/p&gt;

&lt;h2 id=&quot;why-a-high-score-can-still-sound-metallic&quot;&gt;Why a high score can still sound metallic&lt;/h2&gt;

&lt;p&gt;SI-SDR is an energy ratio after one scalar. It does not care whether the residual sits in a consonant or in a musical tone between harmonics. Over-suppression can delete noise and fricatives together and still look fine on a loud vowel. A reverberant estimate against a dry reference is punished even when dereverberation was never the product goal. Clipping, a stereo mixup, or a later switch to mean removal all move the number without a matching change in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. The figure is the rule: SI-SDR is one column. DNSMOS (08-02) and a listening note (08-03) are the others. RTF is a separate gate. Pin a DNS Challenge year from &lt;a href=&quot;https://github.com/microsoft/DNS-Challenge&quot;&gt;microsoft/DNS-Challenge&lt;/a&gt; when you copy a public protocol.&lt;/p&gt;

&lt;p&gt;PESQ and STOI show up in DNS reports and in the DeepFilterNet papers. Both still need a time-aligned reference. Neither replaces a human check when the voice sounds underwater.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Hard-code the two vectors. Do not download a dataset. Run this file as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 si_sdr_lab.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;si_sdr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;estimate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;asarray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dtype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;estimate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;asarray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;estimate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dtype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;estimate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;estimate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s_hat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s_hat_delayed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;si_sdr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s_hat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;si_sdr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s_hat_delayed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected output:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;13.80
-10.67
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Failure modes you should hit on purpose once:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Drop the delay line and you will think every model scores about 14 dB. The second print is the alignment alarm.&lt;/li&gt;
  &lt;li&gt;Pass vectors of different lengths and NumPy raises on the dot product. Trim explicitly.&lt;/li&gt;
  &lt;li&gt;Feed \(x\) instead of \(s\) as the reference and the function still returns a float. The float is not SI-SDR of the enhancement.&lt;/li&gt;
  &lt;li&gt;Set &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;estimate = 2 * reference&lt;/code&gt;. The noise energy is zero and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log10&lt;/code&gt; warns or returns &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inf&lt;/code&gt;. That is a perfect scale match, not a bug in the formula. Do not add an epsilon and then claim 80 dB.&lt;/li&gt;
  &lt;li&gt;Import a library SI-SDR that subtracts the mean. It will not print 13.80. Either match this projection or label the variant.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-computing-si-sdr-by-hand-and-verifying-scale-invariance&quot;&gt;Worked Numerical Example: Computing SI-SDR by Hand (and Verifying Scale Invariance!)&lt;/h3&gt;

&lt;p&gt;Let our tiny 2-sample clean speech vector be \(\mathbf{s} = [3,\; 4]\) (energy \(\|\mathbf{s}\|^2 = 3^2 + 4^2 = 25\)), and suppose our denoiser outputs a louder, slightly noisy estimate \(\hat{\mathbf{s}} = [7,\; 7]\) (energy \(7^2 + 7^2 = 98\)):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the optimal scaling factor \(lpha\):&lt;/strong&gt;
\(lpha = rac{\langle \hat{\mathbf{s}}, \mathbf{s}
angle}{\|\mathbf{s}\|^2} = rac{7(3) + 7(4)}{25} = rac{49}{25} = 1.96.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Decompose \(\hat{\mathbf{s}}\) into orthogonal target and distortion vectors:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Target projection: \(\mathbf{s}_{	ext{target}} = 1.96\,[3,\; 4] = [5.88,\; 7.84]\), with energy \(\|\mathbf{s}_{	ext{target}}\|^2 = 1.96^2 	imes 25 = 96.04\).&lt;/li&gt;
      &lt;li&gt;Residual distortion: \(\mathbf{e}_{	ext{noise}} = \hat{\mathbf{s}} - \mathbf{s}_{	ext{target}} = [7 - 5.88,\; 7 - 7.84] = [1.12,\; -0.84]\), with energy \(1.12^2 + (-0.84)^2 = 1.2544 + 0.7056 = 1.96\).&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;(Pythagorean sanity check: \(96.04 + 1.96 = 98.00 = \|\hat{\mathbf{s}}\|^2\)—exact orthogonality!)&lt;/em&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute SI-SDR in decibels:&lt;/strong&gt;
\(\mathrm{SI	ext{-}SDR} = 10\log_{10}\!\left(rac{\|\mathbf{s}_{	ext{target}}\|^2}{\|\mathbf{e}_{	ext{noise}}\|^2}
ight) = 10\log_{10}\!\left(rac{96.04}{1.96}
ight) = 10\log_{10}(49) pprox \mathbf{16.90	ext{ dB}}!\)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now test &lt;strong&gt;scale invariance&lt;/strong&gt;: multiply \(\hat{\mathbf{s}}\) by 2 to get \([14, 14]\). Both \(\|\mathbf{s}_{	ext{target}}\|^2\) and \(\|\mathbf{e}_{	ext{noise}}\|^2\) multiply by \(4\), so their ratio stays &lt;strong&gt;49&lt;/strong&gt; and SI-SDR stays &lt;strong&gt;\(16.90	ext{ dB}\)&lt;/strong&gt;—whereas naive unscaled SDR would drop dramatically because of the volume change!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-using-si-sdr-responsibly&quot;&gt;Explanation: Four Rules for Using SI-SDR Responsibly&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always align latency before computing SI-SDR:&lt;/strong&gt; A streaming denoiser with a 10 ms (480-sample) delay looks like pure noise to SI-SDR unless you shift \(\hat{\mathbf{s}}\) back by the exact algorithmic delay first!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Report SI-SDRi stratified by input SNR bucket:&lt;/strong&gt; Averaging over easy \(+20	ext{ dB}\) clips hides failure on harsh \(0	ext{ dB}\) cafe noise; always break down SI-SDRi across &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[-5, 0, 5, 10, 20] dB&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Never optimize SI-SDR alone without a perceptual guard:&lt;/strong&gt; Generative or phase-reconstructing models can sound cleaner to humans while scoring &lt;em&gt;lower&lt;/em&gt; SI-SDR because their reconstructed phase differs slightly from the reference.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Watch out for silent clips (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;||s|| = 0&lt;/code&gt;):&lt;/strong&gt; Add a small \(arepsilon\) guard or exclude pure-silence segments from SI-SDR aggregation so division by zero doesn’t poison batch averages.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; If a denoiser outputs the &lt;em&gt;exact&lt;/em&gt; clean signal scaled down by half (\(\hat{\mathbf{s}} = 0.5\,\mathbf{s}\)), what is the residual energy \(\|\mathbf{e}_{	ext{noise}}\|^2\), and what happens to SI-SDR?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Recompute the projection coefficient for the first pair by hand and confirm the printed 13.80 dB is \(10\log_{10}(\|s_{\mathrm{target}}\|^2 / \|e\|^2)\).&lt;/li&gt;
  &lt;li&gt;Replace the one-sample shift with a two-sample shift of the same estimate, keeping length 4 by padding zeros on the left and dropping the tail. Report the new SI-SDR and say whether the cliff got worse.&lt;/li&gt;
  &lt;li&gt;Build \(x = s + 0.3\,[0.2, -0.2, 0.2, -0.2]\) and report SI-SDR of \(x\) against \(s\), SI-SDR of \(\hat{s}\) against \(s\), and the delta. State which number is “improvement.”&lt;/li&gt;
  &lt;li&gt;Write four sentences for a capstone README: when you will publish SI-SDR, when you will print &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;, and why a metallic clip can still score well.&lt;/li&gt;
  &lt;li&gt;Name the sample-rate and delay checks you will run before averaging a 48 kHz DeepFilterNet hop of 10 ms.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(\langle \hat{s}, s \rangle = 0.8\cdot 1 + 0 + (-0.7)\cdot(-1) + 0.6\cdot 0.5 = 1.8\), \(\|s\|^2 = 1 + 0 + 1 + 0.25 = 2.25\), so the scale is \(1.8/2.25 = 0.8\). Finish the norms in NumPy if the arithmetic gets messy; the print is 13.80.&lt;/li&gt;
  &lt;li&gt;A larger shift usually lowers the score further on this short vowel-like vector, because less of the estimate lands on \(s\). Report the float you compute; do not copy −10.67.&lt;/li&gt;
  &lt;li&gt;Delta is output SI-SDR minus input SI-SDR. The input term uses \(x\), not \(\hat{s}\).&lt;/li&gt;
  &lt;li&gt;Publish SI-SDR only for synthetic pairs with a stored clean file and a documented shift. Real calls get &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n/a&lt;/code&gt;. Metallic timbre is residual structure SI-SDR does not classify.&lt;/li&gt;
  &lt;li&gt;Same rate (48 kHz), same length, delay at least on the order of the hop (10 ms is 480 samples) plus any look-ahead the paper states, mono only.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; There is no verified public lecture that derives SI-SDR. Watch the objective-metric section instead: a number that ignores how the call sounds is the failure mode the lesson warns about after the scale-invariant formula.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-04 Mezon npm surface (techniques, not only wrapper)</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter07/07_04_mezon_npm_surface/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter07/07_04_mezon_npm_surface</id>
   <content type="html">&lt;p&gt;The npm package &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; is a vehicle for DeepFilterNet3 in LiveKit and Web Audio apps. It is not the syllabus. This lesson maps the public methods onto frames, gains, WASM, the CDN, and LiveKit’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt;, so a capstone changes a technique you can measure. Course tasks do not modify the product repository. An optional instructor checkout is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;Public processor API in front of a LiveKit TrackProcessor publish path&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The npm surface is a TrackProcessor plus a Web Audio core, not a second noise-suppression algorithm.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Anyone can publish an npm package that wraps a 30-line &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; snippet and calls it a noise-suppression SDK. Yet the difference between a classroom wrapper and a production package like the &lt;strong&gt;Mezon NS npm surface&lt;/strong&gt; lies in everything &lt;em&gt;around&lt;/em&gt; the model: capability probing, clean TypeScript contracts, zero-glitch runtime toggling, structured telemetry (RTF, underrun counts, active tier), and automatic graceful degradation when a user joins from an older browser or low-end device.&lt;/p&gt;

&lt;p&gt;This lecture dissects how to design a clean, resilient &lt;strong&gt;public npm SDK surface&lt;/strong&gt;—separating the reusable DSP/ML engineering techniques inside from the thin integration glue facing application developers.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-designing-a-production-audio-sdk-surface&quot;&gt;Key ideas: Designing a Production Audio SDK Surface&lt;/h2&gt;

&lt;p&gt;Four software-architecture principles turn a working prototype into a dependable npm package:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Thin Public Facade, Swappable Internal Backends:&lt;/strong&gt; Application code should import one clean interface (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createNoiseSuppressor(config)&lt;/code&gt;) without caring whether the internal engine runs WASM SIMD128, scalar WASM fallback, or native browser NS.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Runtime Capability Probing:&lt;/strong&gt; At startup, probe &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.SIMD&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;crossOriginIsolated&lt;/code&gt;), and hardware concurrency—automatically selecting the fastest safe tier instead of crashing on unsupported browsers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;First-Class Observability (Telemetry Hooks):&lt;/strong&gt; Real-time audio failures are invisible in HTTP server logs. Exposing a lightweight periodic stats callback (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtfMean&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtfP99&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;underruns&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;activeModel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bypassed&lt;/code&gt;) lets product teams spot device regressions across millions of sessions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Strict Asset Path &amp;amp; Bundler Compatibility:&lt;/strong&gt; Modern web apps use Vite, Webpack, Next.js, and Electron—all of which handle &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new URL(&apos;./worklet.js&apos;, import.meta.url)&lt;/code&gt; differently. Allowing explicit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetBaseUrl&lt;/code&gt; configuration avoids painful bundler breakage.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will map each public call onto a course idea, choose configure versus fork with a maintenance argument, and name extension work that needs zero edits inside the product tree.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Core, TrackProcessor, assets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — API table against Chapters 02–06.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Knobs: level, bypass, CDN, SIMD.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Configure, wrap, or fork.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab and capstone constraints.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;public-surface&quot;&gt;Public surface&lt;/h2&gt;

&lt;p&gt;Install with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install deepfilternet3-noise-filter&lt;/code&gt;. Peer dependency: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;livekit-client&lt;/code&gt; ^2. The README’s bundler note still holds: worklet code is inlined as blob URLs, so a copy plugin is not required.&lt;/p&gt;

&lt;h3 id=&quot;deepfilternoisefilterprocessor&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;LiveKit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; implementation. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;name&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Constructor options: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enabled&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;static isSupported()&lt;/code&gt; — &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly&lt;/code&gt; exist.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; — build or rebuild the 48 kHz graph on a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrack&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(level)&lt;/code&gt; — forwards 0–100 to the core.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await setEnabled(boolean)&lt;/code&gt; — bypass or resume suppression; returns the enabled flag.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suspend&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt; — &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; power states.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; — tear down the graph and the core.&lt;/li&gt;
  &lt;li&gt;Attach with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await audioTrack.setProcessor(filter)&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilter(options)&lt;/code&gt; is a small factory that returns a processor. Prefer the class in course snippets so the lifecycle stays visible.&lt;/p&gt;

&lt;h3 id=&quot;deepfilternet3core&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;Web Audio core used by the processor and usable alone:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DeepFilterNet3Core&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DeepFilterNoiseFilter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;deepfilternet3-noise-filter&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// LiveKit: new DeepFilterNoiseFilterProcessor(opts) or DeepFilterNoiseFilter(opts)&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DeepFilterNet3Core&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;sampleRate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;noiseReductionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;node&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;createAudioWorkletNode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 0–100&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setNoiseSuppressionEnabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;proc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;destroy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize&lt;/code&gt; fetches and compiles. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt; throws if you skipped it. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled(false)&lt;/code&gt; is the core’s bypass; the processor’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; calls it. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; drops the worklet and the compiled assets.&lt;/p&gt;

&lt;h3 id=&quot;assets&quot;&gt;Assets&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; is the WASM build described in the README (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wasm-pack&lt;/code&gt;, SIMD flags for ≥ 1.2.0). &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; is the upstream archive. The 1.3.0 changelog records a tract &lt;strong&gt;0.23.3&lt;/strong&gt; bump for that WASM path. CDN layout is lesson 07-03. Repository: &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;api-to-course-idea&quot;&gt;API to course idea&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;API or artifact&lt;/th&gt;
      &lt;th&gt;Course idea&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;48 kHz &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Chapter 02 PCM and full-band speech&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;AudioWorklet node&lt;/td&gt;
      &lt;td&gt;Chapter 05 realtime callback&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Frame inside WASM&lt;/td&gt;
      &lt;td&gt;Chapter 02 hop; DeepFilter ERB and deep filter, Chapter 04&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel&lt;/code&gt; 0–100&lt;/td&gt;
      &lt;td&gt;Gain aggressiveness, not a promise about SI-SDR&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;CDN &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Chapter 06 packaging and lesson 07-03&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SIMD WASM ≥ 1.2.0&lt;/td&gt;
      &lt;td&gt;Chapter 06; README’s 20–30% claim&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Lesson 07-01 insertion point A&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await setEnabled(false)&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Bypass without a second publish&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;INT8 weights, if you quantize offline&lt;/td&gt;
      &lt;td&gt;Lesson 06-02, done before upload&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;There is no public method that sets an ONNX input name, an opset, or a private server route. If a capstone needs a new graph, that is a fork or a separate runtime, not a hidden option.&lt;/p&gt;

&lt;p&gt;Optional native mirror, stretch only: a Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; frame API in the Rust sibling, Chapter 09. Do not block the browser capstone on it.&lt;/p&gt;

&lt;h2 id=&quot;knobs&quot;&gt;Knobs&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Knob&lt;/th&gt;
      &lt;th&gt;Turn up&lt;/th&gt;
      &lt;th&gt;Risk&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Suppression level&lt;/td&gt;
      &lt;td&gt;Lower noise floor&lt;/td&gt;
      &lt;td&gt;Thin voice, musical noise near zero gains&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Enabled&lt;/td&gt;
      &lt;td&gt;Suppression on&lt;/td&gt;
      &lt;td&gt;CPU, thermals, delay&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;CDN versus bundled bytes&lt;/td&gt;
      &lt;td&gt;Shared cache, smaller npm install&lt;/td&gt;
      &lt;td&gt;First-join network dependency&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SIMD build&lt;/td&gt;
      &lt;td&gt;Lower real-time factor where it instantiates&lt;/td&gt;
      &lt;td&gt;Safari before 16.4 fails closed&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Pair every knob change with Chapter 08 (SI-SDR on synthetic mixes, DNSMOS or a short listening test on real clips) and a real-time factor on a named device. A dependency bump with no table is not a result.&lt;/p&gt;

&lt;h2 id=&quot;extension-without-editing-the-product&quot;&gt;Extension without editing the product&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;An evaluation harness: WAV in, WAV out, SI-SDR and DNSMOS.&lt;/li&gt;
  &lt;li&gt;UX policy: disable suppression for music mode or when real-time factor stays high.&lt;/li&gt;
  &lt;li&gt;Your own CDN layout and cache headers.&lt;/li&gt;
  &lt;li&gt;Telemetry of init time and fallback reason, no audio upload.&lt;/li&gt;
  &lt;li&gt;A written fork plan if the loader cannot host a different archive.&lt;/li&gt;
  &lt;li&gt;Stretch: frame-API parity in Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;configure-versus-fork&quot;&gt;Configure versus fork&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Situation&lt;/th&gt;
      &lt;th&gt;Prefer&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;CDN base, default level, enable UX&lt;/td&gt;
      &lt;td&gt;Configure &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig&lt;/code&gt; and the constructor&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lifecycle bug or LiveKit version skew&lt;/td&gt;
      &lt;td&gt;Report upstream, or a thin wrapper in your app&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;New model architecture&lt;/td&gt;
      &lt;td&gt;Fork or a new package; keep Apache-2.0 OR MIT, matching upstream&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Course homework&lt;/td&gt;
      &lt;td&gt;Your repo, your notes, or the Rust sibling. Not the instructor product tree&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;annotated-join-path&quot;&gt;Annotated join path&lt;/h2&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// 07-01 insertion A, local pre-encode&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 07-03 CDN; &amp;gt;= 1.2.0 including 1.3.0 auto-prefixes v2/&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 05 AudioWorklet inside init&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 04 DeepFilterNet3 weights in the tar.gz&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;sampleRate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;noiseReductionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;assetConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;cdnUrl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;audioTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;room&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;localParticipant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;publishTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;audioTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 api_map.py&lt;/code&gt;. It binds each call to the type that owns it in 1.3.0.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;calls&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;createAudioWorkletNode&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNet3Core&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;LiveKit LocalAudioTrack&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setEnabled&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setNoiseSuppressionEnabled&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNet3Core&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;isSupported&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sorted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;calls&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;calls&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;createAudioWorkletNode -&amp;gt; DeepFilterNet3Core
isSupported -&amp;gt; DeepFilterNoiseFilterProcessor
setEnabled -&amp;gt; DeepFilterNoiseFilterProcessor
setNoiseSuppressionEnabled -&amp;gt; DeepFilterNet3Core
setProcessor -&amp;gt; LiveKit LocalAudioTrack
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; on the core. The core method is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled&lt;/code&gt; on the processor. The processor method is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;, and it should be awaited.&lt;/li&gt;
  &lt;li&gt;Treating &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; as a method of the npm class. It is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack.setProcessor&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Editing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt; as part of the exercise.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;A capstone that only bumps the dependency.&lt;/li&gt;
  &lt;li&gt;Blaming the model for a double-prefix CDN 404.&lt;/li&gt;
  &lt;li&gt;Redistributing weights without reading the upstream license.&lt;/li&gt;
  &lt;li&gt;Course commits inside the product tree.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-capability-tier-decision-matrix-for-an-npm-audio-sdk&quot;&gt;Worked Numerical Example: Capability-Tier Decision Matrix for an npm Audio SDK&lt;/h3&gt;

&lt;p&gt;Trace how a well-designed SDK automatically selects the right execution tier at call join based on 3 runtime probes:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Browser Environment&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt;?&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WASM SIMD128&lt;/code&gt;?&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;crossOriginIsolated&lt;/code&gt;?&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Selected Execution Tier&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Expected \(\mathrm{RTF}_{p99}\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Modern Chrome / Edge (COOP+COEP)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Tier 1:&lt;/strong&gt; Worker + SAB + SIMD128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.22\) (Best!)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Modern Safari / Standard Page&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Tier 2:&lt;/strong&gt; Inline Worklet + SIMD128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.35\) (Fast, 0 SAB needed)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Legacy Browser (No SIMD)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Tier 3:&lt;/strong&gt; Ultra-light RNNoise scalar&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.48\) (Safe fallback)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Restricted WebView / Error&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;—&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;—&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Tier 4:&lt;/strong&gt; Native WebRTC NS passthrough&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.00\) (Zero-crash fallback)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Notice the product engineering math: if 85% of users hit Tier 1–2, 12% hit Tier 3, and 3% hit Tier 4, &lt;strong&gt;100.0% of users join the call with working audio&lt;/strong&gt;—zero broken microphones!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-shipping-a-clean-audio-npm-package&quot;&gt;Explanation: Four Rules for Shipping a Clean Audio npm Package&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Never hardcode relative asset paths without an override:&lt;/strong&gt; Expose &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;baseUrl&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;modelUrl&lt;/code&gt; options so consumers hosting assets on their own CDN or Electron &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;file://&lt;/code&gt; bundle never get 404s.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Keep the main entry bundle tiny (&amp;lt; 20 KB gzipped):&lt;/strong&gt; Lazy-load &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt; binaries on demand so apps that only occasionally start voice calls don’t pay a startup tax on every page load.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Version your TypeScript types and error codes semantically:&lt;/strong&gt; Return typed error enums (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ModelLoadTimeout&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsupportedBrowser&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContextSuspended&lt;/code&gt;) instead of raw opaque strings so UI layers can show helpful banners.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Include a built-in self-test / synthetic sine-wave smoke test:&lt;/strong&gt; Letting integrators verify worklet registration and non-silent output in CI catches broken bundler configs before users ever see them.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; Why should an audio npm SDK expose an explicit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;baseUrl&lt;/code&gt; option for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt; files rather than relying solely on bundler-inlined relative paths?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Extend the mini-lab table with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Propose one capstone improvement that needs zero package source changes, and name the metric.&lt;/li&gt;
  &lt;li&gt;Propose one improvement that needs a fork, and justify why configuration cannot do it.&lt;/li&gt;
  &lt;li&gt;Compare suppression levels 40 and 80 on one noisy clip. What do you listen for near quiet bins?&lt;/li&gt;
  &lt;li&gt;Why does &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported()&lt;/code&gt; returning true not authorize you to skip the Safari 16.4 check?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; are on the processor (LiveKit calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;). &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; exists on both; the processor forwards to the core.&lt;/li&gt;
  &lt;li&gt;A CDN mirror, a bypass policy, or an SI-SDR harness around WAV files. Metric: SI-SDR delta, DNSMOS, or real-time factor p95.&lt;/li&gt;
  &lt;li&gt;A new operator set or a different archive layout the loader cannot express. Configuration only sets sample rate, level, enabled, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Level 80 should cut more noise and may thin fricatives or musical-noise the floor. Level 40 leaves more residual. Use the same clip.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported()&lt;/code&gt; checks &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly&lt;/code&gt; only. SIMD is lesson 06-03; Safari before 16.4 fails the ≥ 1.2.0 module at compile time.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;npm &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;deepfilternet3-noise-filter&lt;/a&gt; and &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;GitHub&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Upstream &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;DeepFilterNet&lt;/a&gt;, including Schröter et al., ICASSP 2022, arXiv:2110.05588.&lt;/li&gt;
  &lt;li&gt;LiveKit &lt;a href=&quot;https://docs.livekit.io/transport/media/publish/&quot;&gt;TrackProcessor / setProcessor on LocalAudioTrack&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/sonos/tract&quot;&gt;tract&lt;/a&gt; and &lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;ONNX Runtime&lt;/a&gt; for the runtime side of Chapter 06.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Listen to the suppressor the package is a vehicle for. The lesson maps public methods onto this behavior, not onto a private API tour.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d2N0d6CKrbk&quot;&gt;Group calling architectures in WebRTC: MCU, SFU &amp;amp; P2P&lt;/a&gt; — Tsahi Levent-Levi, English. Track forwarding is the LiveKit side of the public surface. The video explains the SFU; it does not document the npm types.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=g1L4O1smMC0&quot;&gt;AudioWorklet :: What, Why, and How - Hongchan Choi&lt;/a&gt; — WebAudio PDX, English. The audio callback is where the package’s processor has to return in time.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-03 CDN model loading</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter07/07_03_cdn_model_loading/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter07/07_03_cdn_model_loading</id>
   <content type="html">&lt;p&gt;DeepFilterNet3 in the browser needs a &lt;strong&gt;WASM&lt;/strong&gt; module and a model archive, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;. Shipping both only inside the npm tarball bloats install and couples asset updates to application deploys. Production pages load them from a &lt;strong&gt;CDN&lt;/strong&gt; (content delivery network): a cache in front of those two files. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; resolves the URLs from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;. This lesson makes the four URLs for 1.1.2 and 1.3.0 self-checking, and keeps a failed fetch from taking down the call.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;CDN fetch of WASM and the ONNX archive before AudioWorklet compile&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The client turns cdnUrl into a WASM URL and a model URL, then compiles WASM.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Picture a team of 50 engineers clicking “Join Daily Standup” at 9:00 AM sharp. If your web app fetches a 3 MB &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt; model from your origin API server with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control: no-cache&lt;/code&gt;, you just triggered 50 redundant origin downloads, delayed everyone’s audio by 3 seconds, and burned unnecessary egress bills. Put that same content-hashed model behind a global &lt;strong&gt;CDN edge&lt;/strong&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;immutable&lt;/code&gt; caching and browser &lt;strong&gt;Cache API / IndexedDB&lt;/strong&gt; persistence, and 49 of those 50 calls load the model locally in &lt;strong&gt;under 20 milliseconds&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;This lecture engineers the complete &lt;strong&gt;CDN model loading pipeline&lt;/strong&gt;: immutable content-hashed URLs, proper CORS/CORP headers for cross-origin isolated pages, browser Cache API / IndexedDB caching, and resilient timeout + fallback logic.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-edge-delivery-browser-caching-and-cross-origin-security&quot;&gt;Key ideas: Edge Delivery, Browser Caching, and Cross-Origin Security&lt;/h2&gt;

&lt;p&gt;Four web-infrastructure pillars turn heavy ML assets into instant-loading web features:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Immutable Content-Hashed URLs:&lt;/strong&gt; Serving &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dfnet-v2.9f3a8c.onnx&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control: public, max-age=31536000, immutable&lt;/code&gt; tells both CDN edge PoPs and the browser never to revalidate—zero conditional &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;304 Not Modified&lt;/code&gt; round trips!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;CORS + CORP Under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COOP&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COEP&lt;/code&gt;:&lt;/strong&gt; When your app enables &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt; via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cross-Origin-Embedder-Policy: require-corp&lt;/code&gt;, &lt;em&gt;every&lt;/em&gt; CDN asset (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt;, worklet &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.js&lt;/code&gt;) must return &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cross-Origin-Resource-Policy: cross-origin&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Access-Control-Allow-Origin&lt;/code&gt;—otherwise the browser silently blocks the fetch!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cache API vs. IndexedDB Persistence:&lt;/strong&gt; Storing fetched &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArrayBuffer&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Response&lt;/code&gt; objects in the browser’s Cache API survives page reloads and works inside Workers without hitting the network again.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bounded Timeouts &amp;amp; Non-Blocking Call Join:&lt;/strong&gt; Never block joining a voice call waiting for a 10-second CDN timeout! Start the call immediately (with native browser NS active), load the neural model asynchronously with an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AbortController&lt;/code&gt; timeout, and hot-swap it in once ready.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will write the resolved URLs for package ≤ 1.1.2 and for the 1.3.0 README rule, keep &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; out of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;, set cache headers that survive a version bump, and bypass suppression when the fetch fails.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Which two bodies move, and when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; fetches them.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; and the version prefix.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Cache, MIME, CORS.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Readiness without blocking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab: four URLs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;assets&quot;&gt;Assets&lt;/h2&gt;

&lt;p&gt;From the package README:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Asset&lt;/th&gt;
      &lt;th&gt;Role&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pkg/df_bg.wasm&lt;/code&gt; under the base or under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;SIMD WASM glue for versions that enable it&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Upstream DeepFilterNet3 archive&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Upstream pointer: &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet/blob/main/models/DeepFilterNet3_onnx.tar.gz&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/a&gt;. The CDN serves &lt;strong&gt;weights and code&lt;/strong&gt;, not user audio. Inference stays on device. Do not add an upload of PCM “for debugging” on a production client.&lt;/p&gt;

&lt;h2 id=&quot;configuring-the-base&quot;&gt;Configuring the base&lt;/h2&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;sampleRate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;noiseReductionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;assetConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;cdnUrl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you omit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;, the package default is that same Mezon base. A private mirror replaces the origin and the path prefix only.&lt;/p&gt;

&lt;h3 id=&quot;version-specific-paths&quot;&gt;Version-specific paths&lt;/h3&gt;

&lt;p&gt;The README states:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Package&lt;/th&gt;
      &lt;th&gt;Resolved paths&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;≤ 1.1.2&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/pkg/df_bg.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;≥ 1.2.0, including 1.3.0&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The package adds &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;. You do not. The README also says the SIMD build is about 20–30% faster for ≥ 1.2.0; cite that as the README’s number. Browsers for that build, again from the README: Chrome 91+, Firefox 89+, Safari 16.4+.&lt;/p&gt;

&lt;p&gt;Package ≥ 1.2.0, including 1.3.0, adds &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; itself. You do not. Never put &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;. The public example base is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/code&gt;. The 1.3.0 changelog also records a tract 0.23.3 bump for the WASM build; that pin does not change the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; paths.&lt;/p&gt;

&lt;h2 id=&quot;progressive-readiness&quot;&gt;Progressive readiness&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; fetches both bodies with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Promise.all&lt;/code&gt; and compiles WASM on the main thread. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; awaits &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, which awaits that work. Room signaling must not.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;connect() ──► room is up, mic muted or NS bypassed
                ├─► fetch pair ──► ok ──► setProcessor, then publish, then setEnabled(true)
                └─► fetch pair ──► err ──► telemetry, stay bypassed or APM-only
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A practical policy is still the README order once assets are hot: construct, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt;. The failure to avoid is awaiting the cold CDN &lt;strong&gt;inside&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt; before the user is in the room. Show “enhancing audio” from byte progress if you measure it. Toast once on failure.&lt;/p&gt;

&lt;h2 id=&quot;http-caching&quot;&gt;HTTP caching&lt;/h2&gt;

&lt;p&gt;An immutable version directory can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control: public, max-age=31536000, immutable&lt;/code&gt;. When bytes change, publish a new directory and let the package prefix point at it. Do not mutate bytes at a URL you marked immutable. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?t=Date.now()&lt;/code&gt; on every join destroys the hit rate. If you also use the Cache API, key by the full versioned URL, cap storage, and offer a support action that clears the noise-suppression cache.&lt;/p&gt;

&lt;p&gt;Serve &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Content-Type: application/wasm&lt;/code&gt;. A missing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Access-Control-Allow-Origin&lt;/code&gt; looks like a generic network error; log status and response type. WASM and the archive are one atomic pair. A 1.3.0 SIMD module beside a 1.1.2-era archive is not a mixed configuration you should “try.”&lt;/p&gt;

&lt;p&gt;Regional latency matters on mobile networks. Mirror into a customer VPC when the public host is blocked. CORS and TLS still apply. There is no unpublished authentication header in this public API: the client issues a normal &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;partial-failure&quot;&gt;Partial failure&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Failure&lt;/th&gt;
      &lt;th&gt;What the user sees&lt;/th&gt;
      &lt;th&gt;Action&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;404 on WASM or model&lt;/td&gt;
      &lt;td&gt;Suppression unavailable&lt;/td&gt;
      &lt;td&gt;Fix the path; publish raw audio&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;CORS error&lt;/td&gt;
      &lt;td&gt;Same&lt;/td&gt;
      &lt;td&gt;Fix CDN headers&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Truncated body&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize&lt;/code&gt; throws&lt;/td&gt;
      &lt;td&gt;Retry once, then bypass&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Offline after a good cache&lt;/td&gt;
      &lt;td&gt;May still work&lt;/td&gt;
      &lt;td&gt;Confirm disk cache or Cache API&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mismatched pair&lt;/td&gt;
      &lt;td&gt;Bad audio or a compile error&lt;/td&gt;
      &lt;td&gt;Lock both files to one directory&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Wrong MIME&lt;/td&gt;
      &lt;td&gt;Streaming loaders fail&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;application/wasm&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;worked-mirror&quot;&gt;Worked mirror&lt;/h2&gt;

&lt;p&gt;Download the upstream &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; that matches your package generation. For a client that follows the README’s ≥ 1.2.0 rule, upload to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://assets.example.com/ns/df3/v2/pkg/&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.../v2/models/&lt;/code&gt;, and set &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://assets.example.com/ns/df3&lt;/code&gt;. Smoke-test a cold profile with the cache disabled, then again with the cache enabled.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Given &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl = https://example.com/df3&lt;/code&gt;, compute the paths for ≤ 1.1.2 and for ≥ 1.2.0 including 1.3.0. Run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 cdn_urls.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;cdn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;https://example.com/df3&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pairs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;1.1.2&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;pkg/df_bg.wasm&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;models/DeepFilterNet3_onnx.tar.gz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;1.3.0&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;v2/pkg/df_bg.wasm&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;v2/models/DeepFilterNet3_onnx.tar.gz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ver&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wasm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pairs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ver&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cdn&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wasm&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cdn&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1.1.2
https://example.com/df3/pkg/df_bg.wasm
https://example.com/df3/models/DeepFilterNet3_onnx.tar.gz
1.3.0
https://example.com/df3/v2/pkg/df_bg.wasm
https://example.com/df3/v2/models/DeepFilterNet3_onnx.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Embedding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;, which yields &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://example.com/df3/v2/v2/pkg/df_bg.wasm&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Using a filename that is not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Blocking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt; until all four hypothetical URLs respond. Only the two URLs for the installed version are fetched, and not as a gate on signaling.&lt;/li&gt;
  &lt;li&gt;Treating 1.3.0 as a no-prefix layout. From 1.2.0 onward, including 1.3.0, the client adds &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Double prefix.&lt;/li&gt;
  &lt;li&gt;Join UI gated on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Uploading raw audio from production.&lt;/li&gt;
  &lt;li&gt;One folder shared blindly by ≤ 1.1.2 and ≥ 1.2.0 clients.&lt;/li&gt;
  &lt;li&gt;Wrong WASM MIME type.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-first-visit-vs-repeat-visit-startup-latency-budget&quot;&gt;Worked Numerical Example: First-Visit vs. Repeat-Visit Startup Latency Budget&lt;/h3&gt;

&lt;p&gt;Compare loading a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.3 MB&lt;/code&gt; compressed bundle (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.85 MB&lt;/code&gt; INT8 model + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.45 MB&lt;/code&gt; WASM runtime) under three caching strategies:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Scenario&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;DNS + TLS + RTT&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Transfer Time (@ 10 Mbps)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;WASM Compile + Session Init&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Total Time to Neural NS Ready&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Origin Server (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;no-cache&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(180	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1{,}040	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(110	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(1{,}330	ext{ ms}\)&lt;/strong&gt; (every call!)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;CDN Edge Cold Visit (immutable)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(45	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1{,}040	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(110	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(1{,}195	ext{ ms}\)&lt;/strong&gt; (1st visit only)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Browser Cache API Hit (repeat visit)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(12	ext{ ms}\) (local SSD read)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(110	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(122	ext{ ms}\)&lt;/strong&gt; (&lt;strong&gt;10.9× faster!&lt;/strong&gt;)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Even better: if you store the pre-compiled &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.Module&lt;/code&gt; (where supported) or warm the cache on app idle before the user clicks “Join Call,” neural noise suppression activates in &lt;strong&gt;under 50 ms&lt;/strong&gt;!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-reliable-cdn-model-loading&quot;&gt;Explanation: Four Rules for Reliable CDN Model Loading&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always set explicit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Content-Type: application/wasm&lt;/code&gt; on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt; files:&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.instantiateStreaming&lt;/code&gt; refuses to stream-compile if the CDN serves &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt; as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;application/octet-stream&lt;/code&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test your CDN headers with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl -I&lt;/code&gt; before every release:&lt;/strong&gt; Confirm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content-encoding: br&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cache-control: ... immutable&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;access-control-allow-origin&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cross-origin-resource-policy: cross-origin&lt;/code&gt; are all present.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Never block &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;joinRoom()&lt;/code&gt; on model download:&lt;/strong&gt; Joining with native browser NS and upgrading seamlessly 1 second later feels instant to users and survives flaky airport Wi-Fi.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify SHA-256 on download, not just HTTP 200:&lt;/strong&gt; Captive hotel Wi-Fi portals sometimes return HTTP 200 with an HTML login page instead of your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt; binary—hash verification catches it immediately and falls back cleanly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; If a browser tab enables &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cross-Origin-Embedder-Policy: require-corp&lt;/code&gt; to unlock &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt;, what happens when it fetches &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.example.com/model.onnx&lt;/code&gt; if the CDN omits the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cross-Origin-Resource-Policy&lt;/code&gt; header?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Repeat the four URLs from memory, then diff against the expected block.&lt;/li&gt;
  &lt;li&gt;List UI states &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;idle&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;downloading&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ready&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;error&lt;/code&gt; and which processor method runs on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ready&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control&lt;/code&gt; for an immutable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; tree and the rule for publishing a new tree.&lt;/li&gt;
  &lt;li&gt;Ten lines of policy for a failed asset load that still leaves the room usable.&lt;/li&gt;
  &lt;li&gt;Why are the WASM file and the tar.gz required to share a directory generation?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Two files times two generations. Prefix only on ≥ 1.2.0 / 1.3.0 README. Base stays &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://example.com/df3&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ready&lt;/code&gt; is when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; has resolved. Then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; (if you have not already) and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await setEnabled(true)&lt;/code&gt; if the user wanted suppression.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public, max-age=31536000, immutable&lt;/code&gt; on the versioned tree. New bytes get a new directory, not an overwrite.&lt;/li&gt;
  &lt;li&gt;Catch the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize&lt;/code&gt; rejection, publish the raw track, emit one telemetry reason, do not retry forever.&lt;/li&gt;
  &lt;li&gt;SIMD WASM and the archive are a matched pair. Split generations across folders and you will compile a module against the wrong weights.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Package README, Custom CDN: &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;deepfilternet3-noise-filter&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;MDN &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching&quot;&gt;HTTP caching&lt;/a&gt; and &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS&quot;&gt;CORS&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Upstream &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet/blob/main/models/DeepFilterNet3_onnx.tar.gz&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Chapter 06 for quantization, SIMD, and packaging of the same pair.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=rIAIzf6utOc&quot;&gt;What is a CDN (Content Delivery Network) and How does a CDN Work?&lt;/a&gt; — Cloudflare, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch caching at the edge versus going back to the origin. A WASM file and a model archive are the assets this lesson refuses to ship only inside the npm tarball.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, English. The client-inference section is why those files exist: the runtime needs a graph and a engine, and both have to be loaded before the first hop.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=0VdNflU08yA&quot;&gt;Quantization explained with PyTorch - Post-Training Quantization, Quantization-Aware Training&lt;/a&gt; — Umar Jamil, English. Smaller weights change the first-load story. Watch the accuracy trade before treating quantization as a free CDN win.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-02 LiveKit TrackProcessor patterns</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter07/07_02_livekit_trackprocessor/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter07/07_02_livekit_trackprocessor</id>
   <content type="html">&lt;p&gt;LiveKit’s client SDK exposes a &lt;strong&gt;TrackProcessor&lt;/strong&gt; so a local audio track can be transformed before it is encoded and published. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; is that hook for DeepFilterNet3. The class also implements &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suspend&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;, and a static &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported()&lt;/code&gt;. This lesson is the lifecycle, the order of join calls, and the failures that keep a call up when the CDN or the worklet misbehaves.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;TrackProcessor lifecycle from construction through publish on a LiveKit local audio track&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. TrackProcessor sits on the local audio track: init builds the worklet graph, publish sends processedTrack.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In a real video-conferencing app like LiveKit or Mezon, users don’t just join a call once and sit still: they plug in AirPods mid-sentence, switch from laptop mic to USB Yeti, toggle noise suppression on and off, and bounce between voice channels. If your audio processor doesn’t implement a rock-solid &lt;strong&gt;TrackProcessor lifecycle (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;)&lt;/strong&gt;, every microphone switch leaks megabytes of WASM linear memory and leaves zombie &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; nodes burning CPU in the background!&lt;/p&gt;

&lt;p&gt;This lecture breaks down the &lt;strong&gt;LiveKit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; pattern&lt;/strong&gt;: how LiveKit hands your processor a raw &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrack&lt;/code&gt; and expects a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processedTrack&lt;/code&gt; back, how to cleanly reset streaming state on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart()&lt;/code&gt;, and how to guarantee deterministic teardown on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy()&lt;/code&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-track-lifecycle-resource-ownership-and-zero-leak-teardown&quot;&gt;Key ideas: Track Lifecycle, Resource Ownership, and Zero-Leak Teardown&lt;/h2&gt;

&lt;p&gt;Building a production-grade &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; rests on four lifecycle guarantees:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; Interface Contract:&lt;/strong&gt; LiveKit calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init(opts)&lt;/code&gt; when attaching to a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart(opts)&lt;/code&gt; when the underlying hardware microphone or constraints change, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy()&lt;/code&gt; when the track unpublishes or the user leaves the room.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Deterministic Resource Ownership (No Zombie AudioContexts):&lt;/strong&gt; Each &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletNode&lt;/code&gt;, Web Worker, and WASM instance holds native OS threads and heap buffers that JavaScript’s garbage collector will &lt;em&gt;not&lt;/em&gt; reclaim until explicitly &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.disconnect()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.terminate()&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.close()&lt;/code&gt;d!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;State Reset vs. Engine Reuse on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart()&lt;/code&gt;:&lt;/strong&gt; Switching from a 48 kHz built-in mic to a 16 kHz Bluetooth headset changes the source track—you should keep the compiled WASM module cached, reconnect the new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamAudioSourceNode&lt;/code&gt;, and zero out all GRU/conv streaming states so old audio doesn’t bleed into the new mic.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Seamless Bypass Without Re-Negotiating WebRTC:&lt;/strong&gt; Toggling NS off/on should route audio around the denoiser &lt;em&gt;inside&lt;/em&gt; the same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processedTrack&lt;/code&gt; rather than replacing the WebRTC sender track (avoiding SDP renegotiation hiccups).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will order &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new DeepFilterNoiseFilterProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, name the processor methods LiveKit calls for you, and keep &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt; independent of the model download.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — What the processor owns versus what the Room owns.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Lifecycle and the public 1.3.0 snippet.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Enable, bypass, suppression level, backpressure.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Mobile, telemetry, dispose.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab on call order.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;responsibilities&quot;&gt;Responsibilities&lt;/h2&gt;

&lt;p&gt;A processor should accept a source track through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack.setProcessor&lt;/code&gt;, produce &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processedTrack&lt;/code&gt;, load WASM and the model archive asynchronously, expose runtime controls that do not require a republish, and dispose workers, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;, and WASM memory. It should not own room tokens, and it should not upload microphone PCM. The default Mezon path is on-device. It also should not freeze the join button for tens of seconds with no progress.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor.isSupported()&lt;/code&gt; returns true when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly&lt;/code&gt; exist. That is a floor, not a SIMD check (lesson 06-03).&lt;/p&gt;

&lt;h2 id=&quot;reference-integration&quot;&gt;Reference integration&lt;/h2&gt;

&lt;p&gt;Peer dependency: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;livekit-client&lt;/code&gt; ^2. The public constructor and the call order:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DeepFilterNoiseFilter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;deepfilternet3-noise-filter&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// DeepFilterNoiseFilter(options) returns a DeepFilterNoiseFilterProcessor.&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;sampleRate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;noiseReductionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;assetConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;cdnUrl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;audioTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;room&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;localParticipant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;publishTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;audioTrack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setEnabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// bypass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate: 48000&lt;/code&gt; matches the full-band graph this package builds (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new AudioContext({ sampleRate: 48000 })&lt;/code&gt;). &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; are a 0–100 product knob, not an SNR target. The level is clamped and forwarded to the worklet port. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; is asynchronous. The README sample sometimes omits &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt;; the method returns a promise and updates &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core.setNoiseSuppressionEnabled&lt;/code&gt;, which posts a bypass flag. Await it. Bypass leaves the graph in place, so the publish slot does not change.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; is what your code calls. LiveKit then calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init({ track })&lt;/code&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; stores the original track and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ensureGraph&lt;/code&gt;: resume the context, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; the core (parallel fetch of WASM and model, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt;), create the AudioWorklet node once, connect source → worklet → destination, and assign &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processedTrack&lt;/code&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; is the same graph rebuild when the microphone track identity changes. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suspend&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt; map onto the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; disconnects nodes, closes the context, and calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processor.destroy()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The non-LiveKit twin is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;. Use it when you own the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; yourself.&lt;/p&gt;

&lt;h2 id=&quot;state-machine&quot;&gt;State machine&lt;/h2&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Created
  → LoadingAssets   (inside init / initialize)
  → Ready
  → Active          (enabled, frames flowing)
  → Bypassed        (await setEnabled(false))
  → Failed          (asset or compile error)
  → Disposed        (destroy)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On failure, publish unprocessed or APM-only audio and show a non-blocking toast. Do not reject &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt; solely because the archive 404s. Gate “suppression ready” separately from “room connected.”&lt;/p&gt;

&lt;h3 id=&quot;backpressure&quot;&gt;Backpressure&lt;/h3&gt;

&lt;p&gt;Honor AudioWorklet timing. A frame that misses its quantum should passthrough or drop, not append to an unbounded PCM queue. Sustained high real-time factor is a reason to lower the suppression level or bypass, not to buffer five seconds of audio.&lt;/p&gt;

&lt;h3 id=&quot;per-track-versus-room-settings&quot;&gt;Per-track versus room settings&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Scope&lt;/th&gt;
      &lt;th&gt;Example&lt;/th&gt;
      &lt;th&gt;Use when&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Per track&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; on the mic&lt;/td&gt;
      &lt;td&gt;Default&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Room / UX&lt;/td&gt;
      &lt;td&gt;“NS on” in settings&lt;/td&gt;
      &lt;td&gt;Persist in localStorage; apply at publish&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Remote participant&lt;/td&gt;
      &lt;td&gt;Process subscribed tracks&lt;/td&gt;
      &lt;td&gt;Rare; bots and recording&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Persist the preference at the UX layer. Apply it by constructing the processor when you create the local track.&lt;/p&gt;

&lt;h2 id=&quot;join-order-and-the-cdn&quot;&gt;Join order and the CDN&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await audioTrack.setProcessor(filter)&lt;/code&gt; waits for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; waits for the CDN. That is correct &lt;strong&gt;before publish&lt;/strong&gt;. It is the wrong thing to put in front of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;room.connect()&lt;/code&gt;. Connect the signaling path, publish when you are ready, and if assets are still in flight keep the mic muted or bypassed. Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; only after &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt;, and then never &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; when the underlying track is replaced, leaves LiveKit sending the original mic. The safe order is construct, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. A later device change goes through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;, not through a second forgotten &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;mobile-and-telemetry&quot;&gt;Mobile and telemetry&lt;/h2&gt;

&lt;p&gt;Background tabs throttle timers. Audio callbacks are more privileged and still not free. iOS Safari resumes an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; from a user gesture; initialize after tap-to-join. Camera plus this model plus Opus can thermal-throttle a mid-range phone. Bluetooth SCO rates may not be 48 kHz; stay on the documented 48 kHz context when you can.&lt;/p&gt;

&lt;p&gt;Telemetry without raw audio: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ns_init_ms&lt;/code&gt;, asset bytes, cache hit, enabled flag, level, real-time factor percentiles, fallback reason. That is reliability data. MOS stays in Chapter 08.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Read the snippet above and fill the order. Check yourself with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 join_order.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;new DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;publishTrack&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setSuppressionLevel&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;. &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;step&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. new DeepFilterNoiseFilterProcessor
2. setProcessor
3. publishTrack
4. setSuppressionLevel
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; after &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;publishTrack&lt;/code&gt; without &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; when the mic track is replaced. The room keeps the unprocessed track.&lt;/li&gt;
  &lt;li&gt;Blocking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect()&lt;/code&gt; on the CDN. Asset fetch belongs to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;, not to the signaling handshake.&lt;/li&gt;
  &lt;li&gt;Forgetting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt; and reading &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isEnabled()&lt;/code&gt; before the bypass post completes.&lt;/li&gt;
  &lt;li&gt;Double &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; while the first &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; is still fetching.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; before the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack&lt;/code&gt; exists.&lt;/li&gt;
  &lt;li&gt;Navigation without &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;, leaving a zombie worklet.&lt;/li&gt;
  &lt;li&gt;Treating the README fragment as the whole API. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suspend&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported&lt;/code&gt; are real.&lt;/li&gt;
  &lt;li&gt;Using the obsolete class name that is not the 1.3.0 export. Construct &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-quantifying-memory--cpu-leaks-across-5-device-switches&quot;&gt;Worked Numerical Example: Quantifying Memory &amp;amp; CPU Leaks Across 5 Device Switches&lt;/h3&gt;

&lt;p&gt;Suppose one instance of your WASM denoiser + Worker + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; allocates:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;WASM linear memory + model weights: &lt;strong&gt;8.0 MB&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Worker thread + ring buffers: &lt;strong&gt;2.5 MB&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Idle audio callback overhead: &lt;strong&gt;1.5% CPU&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compare a buggy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart()&lt;/code&gt; (that forgets to close old nodes/workers) against a disciplined lifecycle across 5 mic switches during a long meeting:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Lifecycle Metric&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Buggy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart()&lt;/code&gt; (No Cleanup)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Clean &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart()&lt;/code&gt; (Reuse Engine + Reset State)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Live WASM/Worker Memory&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(6 	imes 10.5 = \mathbf{63.0	ext{ MB}}\) (leaked!)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(10.5	ext{ MB}\)&lt;/strong&gt; (constant \(O(1)\))&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Active &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;s&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;6 (hits browser limit of ~6!)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Background CPU Overhead&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(6 	imes 1.5\% = 9.0\%\) wasted&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(1.5\%\)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Switch Glitch Duration&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;400–800 ms (re-downloading/compiling)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;&amp;lt; 20 ms&lt;/strong&gt; (instant state reset)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Notice that Chrome enforces a hard cap on simultaneous active &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; instances per tab—forgetting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.close()&lt;/code&gt; on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy()&lt;/code&gt; doesn’t just leak RAM; after 6 channel switches it literally &lt;strong&gt;throws an exception and kills the user’s mic&lt;/strong&gt;!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-rock-solid-livekit-trackprocessors&quot;&gt;Explanation: Four Rules for Rock-Solid LiveKit TrackProcessors&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Make &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy()&lt;/code&gt; idempotent:&lt;/strong&gt; LiveKit or React strict-mode hooks may invoke &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy()&lt;/code&gt; twice; guarding with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if (this.destroyed) return;&lt;/code&gt; prevents double-free errors on WASM pointers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Disconnect audio graph nodes in strict reverse order:&lt;/strong&gt; Disconnect source \(o\) worklet \(o\) destination, notify the Worker to free its WASM heap, call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;worker.terminate()&lt;/code&gt;, and finally &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await audioCtx.close()&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Zero streaming state on every &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart()&lt;/code&gt; and unmute:&lt;/strong&gt; Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wasm.reset_state()&lt;/code&gt; clears stale STFT overlap-add tails and GRU hidden states so the first word on the new mic is never clipped.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Expose an instant runtime &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(bool)&lt;/code&gt; toggle:&lt;/strong&gt; Switching between denoised and raw audio inside the worklet (with a 5 ms crossfade) gives users zero-click A/B toggling during a call.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; When a user switches microphones mid-call and LiveKit triggers &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart(opts)&lt;/code&gt;, why is it better to call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reset_state()&lt;/code&gt; and rewire the audio graph than to re-fetch and re-compile the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt; module from scratch?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Mark on the state machine where the UI shows a spinner versus a toggle.&lt;/li&gt;
  &lt;li&gt;Sketch &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connectWithNS()&lt;/code&gt; that still joins when the CDN fails.&lt;/li&gt;
  &lt;li&gt;List LiveKit events that should call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; in your app.&lt;/li&gt;
  &lt;li&gt;When do you pick &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; versus &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;?&lt;/li&gt;
  &lt;li&gt;A user toggles bypass during &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LoadingAssets&lt;/code&gt;. What do you store, and which method applies it after &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Spinner during &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LoadingAssets&lt;/code&gt;. Toggle only in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Active&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Bypassed&lt;/code&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Failed&lt;/code&gt; shows the toast, not a spinner that never ends.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await room.connect(url, token)&lt;/code&gt; with no &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await filter&lt;/code&gt; in front of it. Publish raw or APM audio in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;catch&lt;/code&gt; of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Disconnected, and your own route unmount. Device changes call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; rather than a full leave.&lt;/li&gt;
  &lt;li&gt;Processor when a LiveKit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalAudioTrack&lt;/code&gt; is published. Core when you build the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; graph yourself.&lt;/li&gt;
  &lt;li&gt;Store the desired boolean. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ensureGraph&lt;/code&gt; already ends in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(this.enabled)&lt;/code&gt;. Do not call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; a second time.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;LiveKit: &lt;a href=&quot;https://docs.livekit.io/transport/media/publish/&quot;&gt;TrackProcessor / setProcessor on LocalAudioTrack&lt;/a&gt;, and the docs home &lt;a href=&quot;https://docs.livekit.io/&quot;&gt;https://docs.livekit.io/&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt; and the &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;npm package&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Chapter 05 for the worklet quantum and Chapter 06 for SIMD compile failures during &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d2N0d6CKrbk&quot;&gt;Group calling architectures in WebRTC: MCU, SFU &amp;amp; P2P&lt;/a&gt; — Tsahi Levent-Levi, English. &lt;strong&gt;xem trước.&lt;/strong&gt; LiveKit is an SFU: it forwards tracks without mixing them. This talk is that architecture. It is not a TrackProcessor tutorial; no accurate LiveKit-specific public tutorial survived verification.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Revamping Audio Quality for RTC Part 1: Beryl Echo Cancellation&lt;/td&gt;
          &lt;td&gt;Sriram Srinivasan and Hoang Do](https://www.youtube.com/watch?v=lapq9zvUd-k) — @Scale, English. Local enhancement before encode is the moment a TrackProcessor has to finish. Watch that slot in a production chain.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=g1L4O1smMC0&quot;&gt;AudioWorklet :: What, Why, and How - Hongchan Choi&lt;/a&gt; — WebAudio PDX, English. The processor callback is the thread a LiveKit audio processor still has to obey.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>07-01 WebRTC insertion points</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter07/07_01_webrtc_integration/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter07/07_01_webrtc_integration</id>
   <content type="html">&lt;p&gt;Where you insert noise suppression in a WebRTC call decides latency, echo, and whether the SFU ever forwards clean speech. This lesson maps insertion points against &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt;, the browser Audio Processing Module, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTCPeerConnection&lt;/code&gt;, then shows how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; occupies the local pre-encode slot through LiveKit’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;LiveKit local track passing through a noise-suppression processor before publish&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Insertion point A is a TrackProcessor on the local mic track, before the sender encodes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You finally have a fast, crystal-clear WASM noise suppressor—so you drop it into a live WebRTC call, put on your headphones, and something sounds eerily thin and underwater! What happened? You forgot to turn off the browser’s &lt;em&gt;built-in&lt;/em&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression: true&lt;/code&gt; constraint, so your speech is being aggressively denoised &lt;strong&gt;twice in a row&lt;/strong&gt;—and even worse, if you placed your denoiser &lt;em&gt;before&lt;/em&gt; Acoustic Echo Cancellation (AEC), your nonlinear neural mask just destroyed the linear echo path that AEC depends on!&lt;/p&gt;

&lt;p&gt;This lecture maps the exact &lt;strong&gt;WebRTC audio pipeline insertion points&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt; constraints (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;echoCancellation&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoGainControl&lt;/code&gt;), Web Audio &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; vs. Insertable Streams / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrackProcessor&lt;/code&gt;, and how to budget end-to-end conversational latency.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-the-webrtc-audio-processing-chain&quot;&gt;Key ideas: The WebRTC Audio Processing Chain&lt;/h2&gt;

&lt;p&gt;Inserting custom ML audio processing into WebRTC requires respecting four strict signal-chain realities:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;AEC Must Run &lt;em&gt;Before&lt;/em&gt; Nonlinear Neural Denoising:&lt;/strong&gt; Acoustic Echo Cancellation models the room’s speaker-to-mic transfer function as a &lt;em&gt;linear&lt;/em&gt; adaptive filter. Running a nonlinear neural denoiser ahead of AEC warps the echo waveform and causes loud howling or double-talk echo leakage!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preventing Double Noise Suppression:&lt;/strong&gt; Always request &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia({ audio: { echoCancellation: true, autoGainControl: true, noiseSuppression: false } })&lt;/code&gt; when activating your own neural denoiser so the browser’s native NS does not stack on top of yours.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Web Audio Graph vs. Track Processing (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrackProcessor&lt;/code&gt;):&lt;/strong&gt; Routing a mic track through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; \(o\) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletNode&lt;/code&gt; \(o\) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamAudioDestinationNode&lt;/code&gt; works universally across browsers; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrackProcessor&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Generator&lt;/code&gt; (Breakout Box) offers a stream-based alternative where supported.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;End-to-End Mouth-to-Ear Latency Budget:&lt;/strong&gt; ITU-T G.114 recommends keeping one-way interactive voice latency under &lt;strong&gt;150 ms&lt;/strong&gt;. Every extra 10 ms buffer you add in WebRTC directly eats into conversational turn-taking comfort.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will place neural noise suppression on the uplink before encode, keep browser echo cancellation while turning browser noise suppression off, and describe what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; changes in the published &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrack&lt;/code&gt; without moving inference off the device.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Mic, processing, encode, SFU, decode, render.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Insertion points A, B, and C.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Browser APM versus the 1.3.0 processor.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Device switch, mute, and the worklet graph.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, pitfalls, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;the-conferencing-audio-graph&quot;&gt;The conferencing audio graph&lt;/h2&gt;

&lt;p&gt;A local send path:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Microphone
  → getUserMedia MediaStreamTrack
  → [optional: AudioContext / AudioWorklet NS]
  → [optional: browser APM: AEC / NS / AGC]
  → RTCPeerConnection sender (encode Opus)
  → SFU / peers
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A receive path:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Remote RTP
  → receiver decode
  → MediaStreamTrack
  → audio element or AudioContext
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run &lt;strong&gt;your&lt;/strong&gt; uplink noise suppression on the local send path, before encode. Post-decode suppression on a remote track cleans other people’s noise for your ears. It does not reduce what you upload, and it is the wrong place to chase your own echo.&lt;/p&gt;

&lt;h2 id=&quot;insertion-points-a-b-and-c&quot;&gt;Insertion points A, B, and C&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A — pre-encode local.&lt;/strong&gt; Process the mic and publish the processed track. The SFU and remote peers receive the enhanced speech. You pay algorithmic delay on the critical path, and you must not disturb the echo canceller’s timing. This is the Mezon package’s target. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; implements LiveKit’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt;. You construct it, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await audioTrack.setProcessor(filter)&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await room.localParticipant.publishTrack(audioTrack)&lt;/code&gt;. LiveKit calls the processor’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, which builds the graph. You do not upload PCM to a private enhancement server in this design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B — browser APM only.&lt;/strong&gt; Constraints such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;echoCancellation&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoGainControl&lt;/code&gt; ask Chromium’s Audio Processing Module to do the work. Cost is low. Control is mostly a boolean, and non-stationary noise is often weaker than a DeepFilterNet3 model. There is no suppression slider from 0 to 100.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C — SFU or cloud.&lt;/strong&gt; The client CPU stays idle and quality is uniform, at the cost of privacy, money, and extra delay. Echo cancellation also gets harder because the server does not hold each client’s loudspeaker reference. That is a different product from this npm package.&lt;/p&gt;

&lt;h2 id=&quot;browser-apm-beside-the-neural-path&quot;&gt;Browser APM beside the neural path&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aspect&lt;/th&gt;
      &lt;th&gt;APM noise suppression&lt;/th&gt;
      &lt;th&gt;DeepFilterNoiseFilterProcessor&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Control&lt;/td&gt;
      &lt;td&gt;Boolean / browser default&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseReductionLevel&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; (0–100), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Latency&lt;/td&gt;
      &lt;td&gt;Usually small&lt;/td&gt;
      &lt;td&gt;Hop plus model; must meet the real-time factor budget&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Echo&lt;/td&gt;
      &lt;td&gt;AEC inside the APM&lt;/td&gt;
      &lt;td&gt;You keep the AEC reference timing intact&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Delivery&lt;/td&gt;
      &lt;td&gt;Built in&lt;/td&gt;
      &lt;td&gt;WASM plus CDN model (lessons 06-03, 07-03)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Many products keep &lt;strong&gt;echo cancellation and auto gain&lt;/strong&gt; and set &lt;strong&gt;browser noise suppression to false&lt;/strong&gt; while the neural processor is active. Two suppressors in series dull the voice. The constraint sketch:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;stream&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;navigator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mediaDevices&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getUserMedia&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;audio&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;echoCancellation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;noiseSuppression&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;autoGainControl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;channelCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Log &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;track.getSettings()&lt;/code&gt; on the target browser. Chrome and Safari do not honor every constraint you request.&lt;/p&gt;

&lt;h2 id=&quot;what-the-processor-inserts&quot;&gt;What the processor inserts&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; is the public LiveKit adapter. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; is the Web Audio adapter underneath it. On &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; the processor ensures a 48 kHz &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;, calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; (WASM compile and model fetch), and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt;. The graph is source → worklet → &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamDestination&lt;/code&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processedTrack&lt;/code&gt; is the destination’s audio track, and that is what LiveKit should publish. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; clamps to an integer from 0 to 100 and posts it to the worklet. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await filter.setEnabled(false)&lt;/code&gt; bypasses suppression without tearing the graph down. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; closes the context and calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;proc.destroy()&lt;/code&gt; on the core.&lt;/p&gt;

&lt;p&gt;A raw WebRTC page that does not use LiveKit can build the same graph with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; and then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sender.replaceTrack(processedTrack)&lt;/code&gt;. The peer dependency of the package is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;livekit-client&lt;/code&gt; ^2; the core class itself is still the right tool when you are not in a Room.&lt;/p&gt;

&lt;h3 id=&quot;device-switch-and-mute&quot;&gt;Device switch and mute&lt;/h3&gt;

&lt;p&gt;On a device switch, tear the old graph down with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt;, or let LiveKit call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; with the new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrack&lt;/code&gt;. Then publish the new processed track. Mute by disabling the track or by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setEnabled(false)&lt;/code&gt;, and keep the UX honest. Do not leave a stalled worklet with no on-screen state. Re-prompt for permission only when the browser requires it.&lt;/p&gt;

&lt;h2 id=&quot;echo-hop-and-the-sfu&quot;&gt;Echo, hop, and the SFU&lt;/h2&gt;

&lt;p&gt;The canceller needs a reference aligned with the microphone. A noise suppressor that adds an unaccounted delay, or that runs in an order the browser AEC did not expect, leaves residual echo or cuts speech. Prefer the stack’s documented AEC, keep the DeepFilter hop near 10 ms at 48 kHz (480 samples) when that is the model’s frame, and do not add a second AEC in JavaScript without a measurement.&lt;/p&gt;

&lt;p&gt;The SFU forwards Opus. It does not share a loudspeaker reference for every client. Noise-suppression CPU is per publishing participant, not per subscriber. If only some clients enable it, say so in the support notes.&lt;/p&gt;

&lt;h2 id=&quot;worked-choice&quot;&gt;Worked choice&lt;/h2&gt;

&lt;p&gt;For a browser meeting on a LiveKit SFU: insertion &lt;strong&gt;A&lt;/strong&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;echoCancellation: true&lt;/code&gt;, browser &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression: false&lt;/code&gt;, assets from a CDN you control (lesson 07-03) so an air-gapped network is a packaging decision rather than a fork.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 insertion_check.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;getUserMedia&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;new DeepFilterNoiseFilterProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;setProcessor&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;publishTrack&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;constraints&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;echoCancellation&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;noiseSuppression&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;autoGainControl&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;order=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;browser_ns=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;constraints&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;noiseSuppression&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;order=getUserMedia &amp;gt; new DeepFilterNoiseFilterProcessor &amp;gt; setProcessor &amp;gt; publishTrack
browser_ns=False
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression: true&lt;/code&gt; together with the neural processor (double suppression).&lt;/li&gt;
  &lt;li&gt;Running the processor on a &lt;strong&gt;remote&lt;/strong&gt; track and calling that uplink cleanup.&lt;/li&gt;
  &lt;li&gt;Blocking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;room.connect()&lt;/code&gt; on the CDN fetch. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setProcessor&lt;/code&gt; waits for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt;, so start the room connection on its own timeline (lesson 07-02).&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;replaceTrack&lt;/code&gt; with the raw mic after a device switch, dropping the processed track on the floor.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Double noise suppression dulls speech.&lt;/li&gt;
  &lt;li&gt;Processing remote tracks by default spends CPU on the wrong product story.&lt;/li&gt;
  &lt;li&gt;A surprise resample away from 48 kHz before this model.&lt;/li&gt;
  &lt;li&gt;Leaking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;s on leave, which holds the microphone and the battery.&lt;/li&gt;
  &lt;li&gt;Assuming constraints were honored because you requested them.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-end-to-end-webrtc-mouth-to-ear-latency-budget&quot;&gt;Worked Numerical Example: End-to-End WebRTC Mouth-to-Ear Latency Budget&lt;/h3&gt;

&lt;p&gt;Trace every millisecond from the speaker’s mouth to the listener’s ear on a real-time WebRTC call with a custom 48 kHz streaming denoiser:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Pipeline Stage&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Typical Delay (ms)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Notes&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;OS Mic Capture + Browser AEC&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(15	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Linear AEC runs first!&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Custom NS Algorithmic Latency&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(30	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;20 ms STFT window + 10 ms lookahead&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;AudioWorklet \(\leftrightarrow\) Worker Ring Buffer&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(10	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1-hop prefill absorbing bursty compute&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Opus Encoder Frame + Packetization&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(20	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Standard WebRTC 20 ms Opus packet&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Network One-Way Transit (RTT / 2)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(40	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Regional fiber/4G link&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Receiver Jitter Buffer + Playback&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(30	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;NetEQ adaptive playout buffer&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Total Mouth-to-Ear Latency&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(145	ext{ ms}\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Under 150 ms ITU-T G.114 target!&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Look how tight that margin is: just &lt;strong&gt;5 ms of headroom&lt;/strong&gt;! If an engineer carelessly adds a 40 ms ring buffer or 3 extra frames of lookahead (30 ms), total latency jumps to \(175	ext{–}185	ext{ ms}\)—right where callers start accidentally talking over each other!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-clean-webrtc-ns-integration&quot;&gt;Explanation: Four Rules for Clean WebRTC NS Integration&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Disable browser &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt; whenever your custom NS is enabled—and re-enable it on fallback:&lt;/strong&gt; If your WASM denoiser fails to load, flip native &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression: true&lt;/code&gt; via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;track.applyConstraints(...)&lt;/code&gt; so the user is never left unprotected.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Never leak &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaStreamTrack&lt;/code&gt; handles on mute/unmute:&lt;/strong&gt; Stopping a call without calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;track.stop()&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audioCtx.close()&lt;/code&gt; leaves the browser’s red microphone recording indicator stuck on!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preserve stereo/mono channel counts explicitly:&lt;/strong&gt; Most speech denoisers expect mono (1 channel); explicitly configure &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;channelCount: 1&lt;/code&gt; or downmix cleanly so stereo USB mics don’t feed silence into channel 0.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test on real Bluetooth headsets (HFP 16 kHz):&lt;/strong&gt; Bluetooth hands-free mode drops sample rates to 16 kHz and introduces high hardware latency—verify your resampling or native 16 kHz path handles it gracefully.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; Why does placing a nonlinear neural noise suppressor &lt;em&gt;before&lt;/em&gt; WebRTC’s Acoustic Echo Canceller (AEC) degrade echo cancellation performance?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Draw your app’s send and receive graph and mark the one insertion point you will ship.&lt;/li&gt;
  &lt;li&gt;On Chrome, capture &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getSettings()&lt;/code&gt; with browser noise suppression requested on and off.&lt;/li&gt;
  &lt;li&gt;List three device-switch cases (Bluetooth headset, USB mic, background tab) and name &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; for each.&lt;/li&gt;
  &lt;li&gt;In five sentences, explain why SFU-side suppression is a different product from this package.&lt;/li&gt;
  &lt;li&gt;Where does &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await filter.setEnabled(false)&lt;/code&gt; sit relative to encode, and what still flows to the SFU?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Ship point A on the local mic. Point B is a fallback, not a second stage.&lt;/li&gt;
  &lt;li&gt;Record the effective &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noiseSuppression&lt;/code&gt; value, not only the constraint you passed.&lt;/li&gt;
  &lt;li&gt;Bluetooth and USB both need &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;restart&lt;/code&gt; or a new processor with the new track. A background tab may &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;suspend&lt;/code&gt; the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resume&lt;/code&gt; after the user gesture. Always &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy&lt;/code&gt; on leave.&lt;/li&gt;
  &lt;li&gt;Cloud suppression sees encoded or server-side audio, costs bandwidth and trust, and lacks the client loudspeaker reference. The npm processor stays in the browser.&lt;/li&gt;
  &lt;li&gt;Bypass is still insertion A. The SFU receives the mic path with suppression disabled, not a different publish slot.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://webrtc.github.io/samples/&quot;&gt;WebRTC samples&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack&quot;&gt;MDN: MediaStreamTrack&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;LiveKit docs on publish: &lt;a href=&quot;https://docs.livekit.io/transport/media/publish/&quot;&gt;TrackProcessor / setProcessor on LocalAudioTrack&lt;/a&gt;. Docs home: &lt;a href=&quot;https://docs.livekit.io/&quot;&gt;https://docs.livekit.io/&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Chapter 03 for AEC and Chapter 05 for the AudioWorklet budget.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Revamping Audio Quality for RTC Part 1: Beryl Echo Cancellation&lt;/td&gt;
          &lt;td&gt;Sriram Srinivasan and Hoang Do](https://www.youtube.com/watch?v=lapq9zvUd-k) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the mouth-to-ear chain: capture, enhancement, encode, network, decode, render. The lesson’s insertion points are positions on this chain.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d2N0d6CKrbk&quot;&gt;Group calling architectures in WebRTC: MCU, SFU &amp;amp; P2P&lt;/a&gt; — Tsahi Levent-Levi, English. Mesh, MCU, and SFU decide whether the server ever sees decoded audio. Inserting suppression before encode only helps if the forwarded track is the one you cleaned.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. The integration section is a shipped suppressor meeting a real calling stack, including echo and loss beside the noise model.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-04 Packaging models for products</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter06/06_04_model_packaging/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter06/06_04_model_packaging</id>
   <content type="html">&lt;p&gt;A correct ONNX graph still fails in a product when &lt;strong&gt;packaging&lt;/strong&gt; is wrong: a huge first load, an uncached URL, a WASM file and a model archive from different generations, or a license you cannot hand to a customer. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; splits that problem. The npm package ships the JavaScript glue, the inlined AudioWorklet, and the loader. The heavy bytes, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;, are fetched from a CDN base you pass as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assetConfig.cdnUrl&lt;/code&gt;. This lesson designs the layout, the version prefix rule, integrity, and the rollback path. Lesson 07-03 computes the full URLs.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;Packaged WASM and ONNX archive on the CDN side of the browser path&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Packaging decides which bytes the WASM compile in the browser is allowed to see.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A model file named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;final_v3_fixed.onnx&lt;/code&gt; sitting in a Slack thread is not a product artifact—it is an incident waiting to happen. The moment you ship real-time speech enhancement to millions of browser tabs or mobile installs, &lt;strong&gt;packaging&lt;/strong&gt; becomes as important as model architecture: How fast does the bundle download on 4G? How do you guarantee the client loaded the exact weights matching the DSP front-end’s hop size and FFT window? And how do you roll back a bad release in 60 seconds without breaking cached clients?&lt;/p&gt;

&lt;p&gt;This lecture turns raw &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt; binaries into disciplined, versioned product artifacts with explicit &lt;strong&gt;manifests&lt;/strong&gt;, &lt;strong&gt;SHA-256 integrity checks&lt;/strong&gt;, &lt;strong&gt;compression&lt;/strong&gt;, and &lt;strong&gt;rollback safety&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-four-engineering-pillars-of-ml-artifact-packaging&quot;&gt;Key ideas: Four Engineering Pillars of ML Artifact Packaging&lt;/h2&gt;

&lt;p&gt;Shipping ML weights reliably to edge devices requires four software-supply-chain practices:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Co-Versioning Model + DSP Contract:&lt;/strong&gt; A speech model’s weights are meaningless without its exact preprocessing parameters (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sample_rate&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n_fft&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hop_size&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;window_type&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;norm_stats&lt;/code&gt;). Bundling a JSON manifest alongside the weights prevents silent train/serve skew.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Transport Compression (Brotli / Gzip) vs. Quantization:&lt;/strong&gt; Random-looking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FP32&lt;/code&gt; mantissa bits barely compress under Gzip, whereas &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INT8&lt;/code&gt; weights compress well—pairing INT8 quantization with Brotli cuts transfer size by &lt;strong&gt;5–6×&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Content-Addressed Integrity (SHA-256):&lt;/strong&gt; Naming artifacts by content hash (e.g., &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ns-v2.1-9f3a8c.onnx&lt;/code&gt;) eliminates stale-cache mismatches and lets clients verify integrity before instantiating the inference session.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lazy Loading &amp;amp; Feature-Tiered Bundles:&lt;/strong&gt; Ship a tiny JS/TS bootstrap (~15 KB) in the main app bundle, and fetch the heavy WASM + model weights asynchronously only when the user actually joins an audio call.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will separate the npm tarball from the CDN artifacts, apply the path rule for package ≤ 1.1.2 versus ≥ 1.2.0 (including 1.3.0, which still auto-prefixes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt;), refuse a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; that already contains &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt;, and list the license and cache checks that belong in a ship gate.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — A first-run download that blocks the call, and why npm size is the wrong number.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Artifact pair, suggested config, semver.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Prefix rule, compression, immutable cache.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Integrity, licenses, staged rollout.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, pitfalls, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;two-packages-one-product&quot;&gt;Two packages, one product&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install deepfilternet3-noise-filter&lt;/code&gt; installs a library whose peer dependency is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;livekit-client&lt;/code&gt; ^2. The README states that worker and worklet sources are inlined as blob URLs, so Webpack, Vite, Rollup, esbuild, and Parcel do not need a copy plugin. That is the small, versioned JavaScript surface. It is not the model. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core.initialize()&lt;/code&gt; fetches two bodies in parallel: the WASM module and the model archive. Those bodies dominate cold-start time. Quantization (lesson 06-02) and the SIMD build (lesson 06-03) change their size and their speed, but only after you publish the pair to a URL the client will actually request.&lt;/p&gt;

&lt;h3 id=&quot;suggested-sidecar-not-a-private-api&quot;&gt;Suggested sidecar, not a private API&lt;/h3&gt;

&lt;p&gt;A product mirror should carry enough metadata that a wrapper cannot drift silently. A teaching layout, which you own, looks like this:&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;models/df3-mono-48k/
  df_bg.wasm
  DeepFilterNet3_onnx.tar.gz
  config.json             # hop, sample_rate, state shapes
  LICENSE_WEIGHTS.txt
  SHA256SUMS
  CHANGELOG.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.json&lt;/code&gt; is your manifest: sample rate (48000 for this package), hop, input names, and state shapes. The npm public API does not require you to upload a file with that name. The client requests exactly two paths under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;. Keep the manifest beside them for humans and for CI.&lt;/p&gt;

&lt;h3 id=&quot;readme-path-rule&quot;&gt;README path rule&lt;/h3&gt;

&lt;p&gt;The package README specifies:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Package&lt;/th&gt;
      &lt;th&gt;WASM&lt;/th&gt;
      &lt;th&gt;Model archive&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;≤ 1.1.2&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/pkg/df_bg.wasm&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;≥ 1.2.0, including 1.3.0&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/pkg/df_bg.wasm&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{cdnUrl}/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The client adds &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/&lt;/code&gt; itself for ≥ 1.2.0. Do not put &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt;. A base that already ends in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/v2&lt;/code&gt; becomes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.../v2/v2/...&lt;/code&gt; and 404s. The example base in the package README is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.mezon.ai/AI/models/datas/noise_suppression/deepfilternet3&lt;/code&gt;. The archive name is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;, from the upstream Rikorose DeepFilterNet repository. The WASM file name is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;cache-compression-integrity&quot;&gt;Cache, compression, integrity&lt;/h3&gt;

&lt;p&gt;Serve the pair with Brotli or gzip. ONNX archives often compress well; WASM less so, but it still benefits. Prefer immutable, content-addressed names or an immutable version directory, with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cache-Control: public, max-age=31536000, immutable&lt;/code&gt;. Publish SHA-256 sums and verify after download in CI. Refuse to start a canary if the WASM hash and the model hash are not from the same release. A new SIMD module with last month’s archive is a packaging bug, not a model-quality bug.&lt;/p&gt;

&lt;p&gt;Overwrite-in-place of a URL you told caches to keep for a year is how you poison clients. Roll forward by publishing a new directory. Keep the previous directory up so you can point &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; back, or ship a package downgrade, without rebuilding the world. The JavaScript package version and the asset directory version move together in your compatibility matrix: opset, tract or ORT build, SIMD feature set, browser floor.&lt;/p&gt;

&lt;h3 id=&quot;size-is-a-channel-decision&quot;&gt;Size is a channel decision&lt;/h3&gt;

&lt;p&gt;Teaching budgets, not measurements of this archive: a mobile web first load wants a small compressed pair, desktop can lazy-load a larger one, and a native app has store limits of its own. INT8 weights and ultra-light models (lesson 04-05) are how you hit the mobile number. They are chosen before the CDN upload, which is why the figure puts quantization on the left of the WASM compile.&lt;/p&gt;

&lt;h3 id=&quot;legal-packaging&quot;&gt;Legal packaging&lt;/h3&gt;

&lt;p&gt;The npm package is dual-licensed Apache-2.0 OR MIT, following upstream DeepFilterNet. Weights you redistribute need the same reading of the upstream license, plus third-party notices for the runtime. Do not put customer audio in the artifact. A model file is not a recording, but telemetry that stores voice metrics can be personal data. The optional instructor tree &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt; is a local checkout for the teacher. Course work does not modify it.&lt;/p&gt;

&lt;h3 id=&quot;staged-rollout&quot;&gt;Staged rollout&lt;/h3&gt;

&lt;p&gt;Canary a small desktop cohort, watch underruns and init failures, then expand. Cold-start failures are packaging failures: 404, CORS, wrong MIME, double prefix. Steady-state underruns are real-time factor failures. Log them separately.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 prefix_check.py&lt;/code&gt;. The function encodes the README rule: a 1.3.0 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; must not already end with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/v2&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;prefix_ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rstrip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/v2&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;double-prefix risk&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;base-ok&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;prefix_ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;https://example.com/df3&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;prefix_ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;https://example.com/df3/v2&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;base-ok
double-prefix risk
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Putting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; because the README table shows &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; in the resolved path. The prefix is the client’s job.&lt;/li&gt;
  &lt;li&gt;Uploading only &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2/pkg/&lt;/code&gt; and leaving the tar.gz at the 1.1.2 path. The pair must match the package generation.&lt;/li&gt;
  &lt;li&gt;Putting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; and also letting ≥ 1.2.0 add it, so the request 404s on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.../v2/v2/...&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Hashing the files on a laptop and publishing different bytes to the CDN.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Judging the product by the npm install size.&lt;/li&gt;
  &lt;li&gt;No manifest, so a hop change ships “successfully” and breaks overlap-add.&lt;/li&gt;
  &lt;li&gt;Shipping a debug WASM.&lt;/li&gt;
  &lt;li&gt;Query-string cache busters on every page load (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?t=Date.now()&lt;/code&gt;), which defeat the CDN.&lt;/li&gt;
  &lt;li&gt;Mixing ≤ 1.1.2 clients and ≥ 1.2.0 clients in one folder without both layouts present.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-calculating-cold-start-download-time-on-a-10-mbps-mobile-link&quot;&gt;Worked Numerical Example: Calculating Cold-Start Download Time on a 10 Mbps Mobile Link&lt;/h3&gt;

&lt;p&gt;Suppose a 1.2M-parameter streaming denoiser is packaged three ways and downloaded over a realistic &lt;strong&gt;10 Mbps&lt;/strong&gt; (\(1.25	ext{ MB/s}\)) mobile connection:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Artifact Variant&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Raw Size&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Brotli Wire Size&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Download Time @ 10 Mbps&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Fits Call-Join Budget (&amp;lt; 1 s)?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;FP32 ONNX (uncompressed)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(4.80	ext{ MB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(4.35	ext{ MB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3.48	ext{ s}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;No&lt;/strong&gt; (delays call join!)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;FP16 ONNX + Brotli&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2.40	ext{ MB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2.05	ext{ MB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1.64	ext{ s}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Marginal&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;INT8 ONNX + Brotli&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1.20	ext{ MB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.85	ext{ MB}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;\(0.68	ext{ s}\)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Yes!&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Add a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.45 MB&lt;/code&gt; Brotli-compressed WASM SIMD runtime, and the entire INT8 package downloads in \((0.85 + 0.45) / 1.25 = \mathbf{1.04	ext{ s}}\) on first visit—and &lt;strong&gt;0 ms network wait&lt;/strong&gt; on every subsequent call once cached!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-bulletproof-model-packaging&quot;&gt;Explanation: Four Rules for Bulletproof Model Packaging&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Never overwrite a live model URL in place:&lt;/strong&gt; Always publish immutable versioned URLs (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2.1.0/...&lt;/code&gt;) so an in-flight call never downloads half of v2.0 and half of v2.1.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Validate the manifest schema before calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;InferenceSession.create&lt;/code&gt;:&lt;/strong&gt; Verify &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sample_rate&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hop_size&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sha256&lt;/code&gt; at load time so corrupted downloads fall back cleanly to passthrough audio instead of crashing the call.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Separate runtime upgrades from weight upgrades:&lt;/strong&gt; Keeping the WASM engine and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt; weight blob independently versioned lets ML engineers ship improved weights without rebuilding the C++/Rust runtime.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Budget for both download &lt;em&gt;and&lt;/em&gt; WASM compilation/warmup:&lt;/strong&gt; Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.instantiateStreaming&lt;/code&gt; overlaps network download with compilation, shaving hundreds of milliseconds off startup.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; Why do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FP32&lt;/code&gt; neural network weight files compress poorly under Gzip/Brotli compared to text or JSON, and why does &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INT8&lt;/code&gt; quantization shrink the wire transfer so dramatically?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Write the fields your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.json&lt;/code&gt; must contain so a 48 kHz DeepFilter hop cannot drift.&lt;/li&gt;
  &lt;li&gt;Propose compressed-size budgets for mobile web and desktop, and state which knob (INT8, ultra-light model, lazy load) hits each budget.&lt;/li&gt;
  &lt;li&gt;Document a rollback that restores the previous artifact pair without editing the product repository.&lt;/li&gt;
  &lt;li&gt;List the license questions you must answer before redistributing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt; commercially.&lt;/li&gt;
  &lt;li&gt;A teammate sets &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.example.com/df3/v2&lt;/code&gt;. What URLs will a ≥ 1.2.0 client request if it follows the README and prefixes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v2&lt;/code&gt; again?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Sample rate, hop, window, model input names, state shapes, and the package version the shapes were checked against.&lt;/li&gt;
  &lt;li&gt;Mobile: quantize or swap in a smaller model and keep the pair on the CDN, not inside npm. Desktop: lazy-load is acceptable if join is not blocked (lesson 07-02).&lt;/li&gt;
  &lt;li&gt;Keep the previous directory. Point &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdnUrl&lt;/code&gt; at the base that resolves to it, or pin the older package. Do not overwrite immutable URLs.&lt;/li&gt;
  &lt;li&gt;Upstream license, the package’s Apache-2.0 OR MIT dual license, trademark, and whether your mirror may rehost the archive. Read the upstream model card. Do not guess “non-commercial” without the text.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://cdn.example.com/df3/v2/v2/pkg/df_bg.wasm&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.../v2/v2/models/DeepFilterNet3_onnx.tar.gz&lt;/code&gt;. That is the double-prefix failure.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Package README, Custom CDN Configuration: &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;deepfilternet3-noise-filter&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;ONNX Runtime documentation&lt;/a&gt; on optimized model artifacts.&lt;/li&gt;
  &lt;li&gt;Upstream archive &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet/blob/main/models/DeepFilterNet3_onnx.tar.gz&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Chapter 07 for LiveKit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TrackProcessor&lt;/code&gt; loading and CDN failure policy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the path from a trained graph to a smaller file a client can load. Packaging in the lesson is this file plus the WASM and the cache, not a new network.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=rIAIzf6utOc&quot;&gt;What is a CDN (Content Delivery Network) and How does a CDN Work?&lt;/a&gt; — Cloudflare, English. A CDN caches that file near the user. Watch cache versus origin; a model archive is just a large static asset.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=0VdNflU08yA&quot;&gt;Quantization explained with PyTorch - Post-Training Quantization, Quantization-Aware Training&lt;/a&gt; — Umar Jamil, English. Quantization is the size lever inside the package. Watch the accuracy cost before you celebrate the smaller download.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-03 SIMD and WASM deployment</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter06/06_03_simd_wasm/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter06/06_03_simd_wasm</id>
   <content type="html">&lt;p&gt;Web deployment of neural noise suppression stands or falls on &lt;strong&gt;WebAssembly&lt;/strong&gt; throughput. &lt;strong&gt;SIMD&lt;/strong&gt; (single instruction, multiple data), the 128-bit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; feature, threads where the page is allowed to use them, and the MIME type of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wasm&lt;/code&gt; response often matter as much as the choice of model. Package &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;≥ 1.2.0&lt;/strong&gt;, including &lt;strong&gt;1.3.0&lt;/strong&gt;, ships a WASM build with SIMD enabled. The package README attributes about &lt;strong&gt;20–30%&lt;/strong&gt; higher speed to that build. That figure is the README’s claim, not a measurement from this course. This lesson shows how to detect the feature, how Safari 16.4 bounds it, and how an AudioWorklet stays inside its budget when SIMD is missing.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;WASM SIMD build on the path from the ONNX archive to the browser&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The ≥ 1.2.0 package loads a SIMD WASM module from the CDN layout in lesson 07-03.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;Real-time factor of an AudioWorklet hop with and without SIMD headroom&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Real-time factor compares processing time with the audio duration of one hop. SIMD changes whether that ratio stays under 1.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For years, running real-time neural audio inside a web browser meant fighting JavaScript’s single-threaded, scalar execution model—leaving 75% of the user’s CPU arithmetic units sitting completely idle. &lt;strong&gt;WebAssembly (WASM)&lt;/strong&gt; with &lt;strong&gt;128-bit SIMD (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;)&lt;/strong&gt; changed the game: a single CPU instruction now multiplies and accumulates &lt;strong&gt;four 32-bit floats at once&lt;/strong&gt; inside a portable browser sandbox, delivering near-native C/Rust speed with zero plugin installation!&lt;/p&gt;

&lt;p&gt;This lecture opens the hood on &lt;strong&gt;SIMD vectorization and WASM deployment&lt;/strong&gt;: how 128-bit vector lanes accelerate dot products and FFT butterflies, why memory alignment and loop unrolling matter, and how browser security headers (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COOP&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COEP&lt;/code&gt;) unlock multi-threaded &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt; audio pipelines.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-data-level-parallelism-and-the-browser-sandbox&quot;&gt;Key ideas: Data-Level Parallelism and the Browser Sandbox&lt;/h2&gt;

&lt;p&gt;Four hardware and browser-platform concepts control real-time WASM audio speed:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;SIMD (Single Instruction, Multiple Data):&lt;/strong&gt; Instead of fetching, decoding, and executing one &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; multiply-add per cycle, a 128-bit vector register (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v128&lt;/code&gt; in WASM, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSE&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NEON&lt;/code&gt; on native CPUs) holds &lt;strong&gt;4 × &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;&lt;/strong&gt; (or &lt;strong&gt;16 × &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i8&lt;/code&gt;&lt;/strong&gt;) side by side and executes the same arithmetic across all lanes in a single instruction.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Auto-Vectorization vs. Explicit Intrinsics:&lt;/strong&gt; Rust/LLVM can auto-vectorize simple contiguous loops compiled with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-C target-feature=+simd128&lt;/code&gt;, provided there is no pointer aliasing or loop-carried dependency; hot kernels (GEMM, FFT) often use hand-tuned intrinsics.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;WASM Linear Memory &amp;amp; Zero-Copy Views:&lt;/strong&gt; WASM operates inside one contiguous byte array (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.Memory&lt;/code&gt;). Passing audio between JS and WASM without extra copies means reading/writing directly via a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Float32Array&lt;/code&gt; view over WASM’s linear memory buffer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Threads &amp;amp; Cross-Origin Isolation (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COOP&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COEP&lt;/code&gt;):&lt;/strong&gt; Browser &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt; (required for lock-free AudioWorklet \(\leftrightarrow\) Worker ring buffers and WASM pthreads) is gated behind HTTP response headers &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cross-Origin-Opener-Policy: same-origin&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cross-Origin-Embedder-Policy: require-corp&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will explain why &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; changes real-time factor for a GEMM-heavy enhancer, detect the feature without a compiler, apply the README’s browser floor (Chrome 91+, Firefox 89+, Safari 16.4+), and plan a fallback when SIMD or the WASM MIME type is wrong.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Same model, different real-time factor, README’s 20–30% claim.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;, feature detection, Safari 16.4.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Threads, COOP/COEP, and why the default budget is single-threaded.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — AudioWorklet instantiation and the three failure strings.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, pitfalls, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;what-simd-changes-in-the-hop&quot;&gt;What SIMD changes in the hop&lt;/h3&gt;

&lt;p&gt;Matrix multiplies and convolutions dominate a DeepFilter-class hop. SIMD loads 128 bits, four &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; lanes or eight &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i16&lt;/code&gt; lanes, and raises arithmetic throughput. The real-time factor of a hop of duration (H) is&lt;/p&gt;

\[\mathrm{RTF} = \frac{T_{\mathrm{wall}}}{H}.\]

&lt;p&gt;(\mathrm{RTF} &amp;lt; 1) is required on that device and still not sufficient: the AudioWorklet also spends time on the STFT, copies, and the encoder. The package README says the SIMD build is about 20–30% faster for versions ≥ 1.2.0. Illustratively, a hop at RTF (0.90) would land near (0.63)–(0.72) if that claim holds on your laptop. Confirm with your own percentiles. Do not quote 20–30% as a lab result.&lt;/p&gt;

&lt;p&gt;The public WASM recipe in the repository README enables this at build time: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wasm-opt&lt;/code&gt; flags include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--enable-simd&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--enable-bulk-memory&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--enable-nontrapping-float-to-int&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RUSTFLAGS&lt;/code&gt; adds &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+simd128&lt;/code&gt;. Versions ≤ 1.1.2 were built without that feature set. You do not need a compiler for this lesson. You do need to know that a module compiled with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; &lt;strong&gt;fails to instantiate&lt;/strong&gt; on an engine that lacks the feature. It does not silently run slower.&lt;/p&gt;

&lt;h3 id=&quot;browser-floor-especially-safari-164&quot;&gt;Browser floor, especially Safari 16.4&lt;/h3&gt;

&lt;p&gt;The same README states the SIMD build needs &lt;strong&gt;Chrome 91+&lt;/strong&gt;, &lt;strong&gt;Firefox 89+&lt;/strong&gt;, and &lt;strong&gt;Safari 16.4+&lt;/strong&gt;. Safari 16.4 is a hard boundary, not a tuneable flag. Safari 16.3 and earlier, including iOS versions that ship that engine, reject the SIMD module at compile or instantiate time. There is no “partial SIMD” mode that runs the 1.3.0 module slowly. Product policy is explicit: detect, then fall back to a non-SIMD artifact (the ≤ 1.1.2 style build, or browser APM noise suppression, or bypass). &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor.isSupported()&lt;/code&gt; only checks that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly&lt;/code&gt; exist. It does &lt;strong&gt;not&lt;/strong&gt; prove &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;. A page can pass &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported()&lt;/code&gt; and still fail inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt; rejects the module.&lt;/p&gt;

&lt;p&gt;A maintained probe, which validates on engines with SIMD, is:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;simd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;WebAssembly&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Uint8Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;97&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;115&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;109&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;96&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;123&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;65&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;253&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;253&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;98&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Prefer this style of probe, or the helper your runtime documents, over a hand-written opcode list you have not validated.&lt;/p&gt;

&lt;h3 id=&quot;threads-are-a-separate-privilege&quot;&gt;Threads are a separate privilege&lt;/h3&gt;

&lt;p&gt;Multi-threaded WASM needs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt;, which modern browsers expose only on a cross-origin-isolated page (COOP and COEP headers). Many product origins cannot set those headers. Design the real-time budget for &lt;strong&gt;one&lt;/strong&gt; WASM thread first. Threads are an optimization after isolation is real, not part of the README’s SIMD percentage.&lt;/p&gt;

&lt;h3 id=&quot;audioworklet-meets-the-module&quot;&gt;AudioWorklet meets the module&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core.initialize()&lt;/code&gt; compiles WASM on the main thread. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt; then constructs an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletNode&lt;/code&gt; named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilter-audio-processor&lt;/code&gt;. Do that before audio is flowing. The worklet must not compile a multi-megabyte module inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt;. Keep the heap stable: per-quantum allocations across the JS/WASM boundary blow the budget you just won with SIMD. STFT and windowing outside the graph need the same discipline. Profile them separately from inference.&lt;/p&gt;

&lt;h3 id=&quot;three-strings-two-failures&quot;&gt;Three strings, two failures&lt;/h3&gt;

&lt;p&gt;The mini-lab classifies three deployment strings. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; is the feature the ≥ 1.2.0 module requires, so on a browser inside the README floor it is not a failure. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;missing simd&lt;/code&gt; fails closed: the module does not instantiate. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wrong wasm mime&lt;/code&gt; fails when a loader uses streaming compilation and the response is not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;application/wasm&lt;/code&gt;. The 1.3.0 core compiles an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArrayBuffer&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt;, which is less sensitive to MIME than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;instantiateStreaming&lt;/code&gt;, but a CDN must still serve &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df_bg.wasm&lt;/code&gt; as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;application/wasm&lt;/code&gt;. Proxies that sniff a wrong type, and any future streaming path, will break the pair of files from lesson 07-03.&lt;/p&gt;

&lt;h3 id=&quot;graceful-degradation&quot;&gt;Graceful degradation&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if missing simd or wrong wasm mime or RTF p95 over budget:
    fallback = non-SIMD build OR browser APM NS OR bypass
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Never leave a crackling worklet as the success path. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setNoiseSuppressionEnabled(false)&lt;/code&gt; on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await filter.setEnabled(false)&lt;/code&gt; on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, is the bypass once the node exists. If compile itself throws, do not publish a half-built processor. Publish the unprocessed track and surface one non-blocking error (lesson 07-02).&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;No compiler. Run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 simd_fail.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;checks&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;simd128&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;pass&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;missing simd&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fail&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;wrong wasm mime&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fail&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;failed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;checks&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fail&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sorted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;failed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Sorting makes the set printable and stable. The set itself is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{&quot;missing simd&quot;, &quot;wrong wasm mime&quot;}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[&apos;missing simd&apos;, &apos;wrong wasm mime&apos;]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Printing the set without sorting. Hash randomization can reorder the line; the expected check uses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sorted&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Treating Safari 16.3 as “SIMD but slower.” The README boundary is 16.4; earlier Safari fails the module.&lt;/li&gt;
  &lt;li&gt;Assuming &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isSupported()&lt;/code&gt; covers &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;. It does not.&lt;/li&gt;
  &lt;li&gt;Serving the WASM file as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text/plain&lt;/code&gt; and debugging the model archive instead.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Testing only desktop Chrome, which has had SIMD for years.&lt;/li&gt;
  &lt;li&gt;Forgetting that iOS Safari follows the 16.4 line.&lt;/li&gt;
  &lt;li&gt;Shipping an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-O0&lt;/code&gt; or debug WASM to production.&lt;/li&gt;
  &lt;li&gt;Turning on threads without COOP/COEP and calling the hang a model bug.&lt;/li&gt;
  &lt;li&gt;Quoting the README’s 20–30% as if this course measured it.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-counting-instructions-for-a-256-element-dot-product-scalar-vs-wasm-simd128&quot;&gt;Worked Numerical Example: Counting Instructions for a 256-Element Dot Product (Scalar vs. WASM SIMD128)&lt;/h3&gt;

&lt;p&gt;Every layer of a speech denoiser boils down to dot products \(\sum_{i=0}^{255} a_i b_i\). Compare scalar execution against WASM &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; (4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; lanes per &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v128&lt;/code&gt; register) on \(N = 256\) floats:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Execution Mode&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Floats per Register&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Multiply-Add Loop Iterations&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Horizontal Reduction at End&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Theoretical Speedup&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Scalar WASM (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(256\) iterations&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1.0	imes\) (baseline)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;WASM &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32x4&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;4&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(256 / 4 = 64\) iterations&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2 shuffles + 2 adds (4 lanes \(o\) 1)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Up to \(3.5	ext{–}4.0	imes\)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;WASM &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i8x16&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;16 (quantized!)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(256 / 16 = 16\) vector loads&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Widening pairwise dot-adds&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Up to \(6	ext{–}8	imes\)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Notice what happens if the vector length is awkward—say \(N = 257\) (like a 512-point STFT!). The first 256 elements run in 64 fast SIMD iterations, and the remaining &lt;strong&gt;1 tail element&lt;/strong&gt; runs in a tiny scalar epilogue (or you pad the buffer to 260 floats so every loop stays 100% vector-aligned!).&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-practical-rules-for-fast-wasm-audio-deployment&quot;&gt;Explanation: Four Practical Rules for Fast WASM Audio Deployment&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always verify &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+simd128&lt;/code&gt; is actually enabled in your build flags:&lt;/strong&gt; Compiling Rust to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wasm32-unknown-unknown&lt;/code&gt; without &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RUSTFLAGS=&quot;-C target-feature=+simd128&quot;&lt;/code&gt; silently emits scalar instructions and throws away 3–4× speed!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Provide a graceful fallback or feature-detect SIMD:&lt;/strong&gt; Modern Chrome, Firefox, Safari, and Edge all support WASM SIMD128, but checking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.validate(...)&lt;/code&gt; at startup protects legacy enterprise browsers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minimize JS \(\leftrightarrow\) WASM boundary crossings:&lt;/strong&gt; Never call into WASM once per sample (48,000 calls/sec); pass an entire 128-sample quantum or 480-sample hop in one call via shared linear memory.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Plan &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COOP&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COEP&lt;/code&gt; headers early with your web infra team:&lt;/strong&gt; Adding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require-corp&lt;/code&gt; can break third-party analytics scripts or un-CORS’d images on the same page if discovered right before launch!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; For a 480-sample audio frame (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;), is 480 evenly divisible by 4 (the number of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; lanes in WASM &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;simd128&lt;/code&gt;), and how many &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32x4&lt;/code&gt; vector iterations does a simple elementwise gain multiply take?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Run the SIMD &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;validate&lt;/code&gt; probe in two browsers and record pass or fail beside the version string.&lt;/li&gt;
  &lt;li&gt;If a scalar build sits at RTF p95 (1.1) and a SIMD build at (0.45), what do you ship to Safari 16.3?&lt;/li&gt;
  &lt;li&gt;Explain COOP/COEP in a short note to a web lead who cannot change the origin headers this week.&lt;/li&gt;
  &lt;li&gt;Propose how to time STFT and inference separately inside the worklet.&lt;/li&gt;
  &lt;li&gt;Why does a wrong MIME type belong in the failure set even though &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt; on an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArrayBuffer&lt;/code&gt; does not check &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Content-Type&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Chrome 91+ and Firefox 89+ should pass. Safari passes at 16.4 and fails before that.&lt;/li&gt;
  &lt;li&gt;Do not ship the SIMD module there. Bypass, APM noise suppression, or a non-SIMD artifact. The 0.45 number is unreachable if instantiate fails.&lt;/li&gt;
  &lt;li&gt;Threads need cross-origin isolation. Until headers exist, budget a single thread.&lt;/li&gt;
  &lt;li&gt;Post timestamps from the worklet for the STFT section and the inference section. Aggregate p95 on the main thread. Do not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; every quantum.&lt;/li&gt;
  &lt;li&gt;Streaming instantiation and intermediaries require &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;application/wasm&lt;/code&gt;. The lab fails that string so the CDN contract stays explicit.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;MDN WebAssembly SIMD and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.validate&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;ONNX Runtime&lt;/a&gt; Web notes on SIMD and threads, for products that call ORT from the page directly.&lt;/li&gt;
  &lt;li&gt;Package README browser matrix and SIMD percentage: &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;deepfilternet3-noise-filter&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;MDN &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;AudioWorklet&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nhTxJBgTywc&quot;&gt;Zoom on Web: getting connected with advanced web technology&lt;/a&gt; — Chrome for Developers, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the simd128 loop and the note that Rust can target it. That is the WebAssembly throughput this lesson is about.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, English. The audio half shows WASM inside the real-time callback, which is where a noise suppressor actually spends the SIMD.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, English. The runtime talk is why a SIMD WASM file and an ONNX graph still have to be a matched pair.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-02 Quantization for speech models</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter06/06_02_quantization/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter06/06_02_quantization</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;Quantization&lt;/strong&gt; shrinks weights and often speeds speech-enhancement inference. That matters for WASM download size and for CPU real-time factor. It can also damage speech or destabilize recurrent state. The dangerous errors are not the large weights. They are the gains near zero, because those gains are applied directly to frequency bins. This lesson covers INT8 at an engineering level, calibration on speech rather than on images, and a numeric lab you can self-check.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;Quantized weights packed into the model archive before the browser loads WASM&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Quantization happens before the WASM the browser loads.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A full-precision &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FP32&lt;/code&gt; speech denoiser takes 4 bytes for every single weight. Shrink those weights down to 8-bit integers (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INT8&lt;/code&gt;), and two magical things happen simultaneously: your model download shrinks by &lt;strong&gt;4×&lt;/strong&gt; (so it loads in a blink over mobile networks and fits inside CPU L2 cache), and modern SIMD instructions (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VNNI&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NEON dotprod&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WASM SIMD&lt;/code&gt;) can crunch &lt;strong&gt;2–4× more multiply-adds per clock cycle&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Yet naive quantization can wreck a speech model—turning soft background silence into audible buzzing or crushing quiet consonants because audio features span a huge dynamic range in decibels. This lecture walks through the exact math of &lt;strong&gt;symmetric &amp;amp; affine INT8 quantization&lt;/strong&gt;, compares &lt;strong&gt;PTQ (Post-Training Quantization)&lt;/strong&gt; vs. &lt;strong&gt;QAT (Quantization-Aware Training)&lt;/strong&gt;, and shows which sensitive layers (like final gain heads) are best left in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FP32&lt;/code&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-fixed-point-arithmetic-and-quantization-noise-in-audio&quot;&gt;Key ideas: Fixed-Point Arithmetic and Quantization Noise in Audio&lt;/h2&gt;

&lt;p&gt;Four mathematical concepts explain when quantization shines and when it breaks speech quality:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Affine &amp;amp; Symmetric Mapping:&lt;/strong&gt; Quantization maps a real value \(x \in [x_{\min}, x_{\max}]\) to an integer \(q \in [-127, 127]\) via \(q = \operatorname{round}(x / s) + z\) and reconstructs \(\hat{x} = s(q - z)\). &lt;strong&gt;Symmetric quantization&lt;/strong&gt; sets zero-point \(z = 0\) (ideal for zero-centered weights, eliminating cross-terms in integer matrix multiplication).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quantization Noise &amp;amp; SQNR:&lt;/strong&gt; Rounding introduces uniform error \(e = \hat{x} - x \in [-s/2, +s/2]\) with variance \(s^2/12\). For 8-bit uniform quantization, peak Signal-to-Quantization-Noise Ratio (SQNR) is roughly \(6.02 	imes 8 pprox 48	ext{ dB}\)—plenty for intermediate weights, but tight if an extreme outlier stretches \(s\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Per-Channel vs. Per-Tensor Scaling:&lt;/strong&gt; Giving each output channel its own scale \(s_c\) prevents one large-magnitude channel from blowing up the quantization step size for 63 quiet channels.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;PTQ vs. QAT &amp;amp; Mixed Precision:&lt;/strong&gt; Dynamic/static &lt;strong&gt;PTQ&lt;/strong&gt; requires no retraining; &lt;strong&gt;QAT&lt;/strong&gt; inserts fake-quantization nodes during fine-tuning so weights adapt to rounding noise. Keeping input/output gain heads in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FP32&lt;/code&gt; while quantizing heavy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Conv&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GRU&lt;/code&gt; bodies often yields 95% of the speedup with zero audible degradation.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will distinguish dynamic and static INT8 quantization, compute a symmetric scale and the maximum absolute error on a gain vector, explain why bins whose gain is near zero dominate audible damage, and design an A/B listening plus SI-SDR gate before shipping quantized weights.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Size and real-time factor for a DeepFilter-class WASM download.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Symmetric INT8, per-tensor versus per-channel scales.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Calibration audio, and why ImageNet statistics do not transfer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Gains near zero, residual noise, state drift.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, pitfalls, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;the-scale-you-will-actually-code&quot;&gt;The scale you will actually code&lt;/h3&gt;

&lt;p&gt;A float value (g) maps to an integer code (q) with scale (s) and optional zero-point (z):&lt;/p&gt;

\[g \approx s\,(q - z).\]

&lt;p&gt;For a symmetric gain vector with no zero-point, take&lt;/p&gt;

\[s = \frac{\max_i |g_i|}{127}, \qquad q_i = \mathrm{clip}\big(\mathrm{round}(g_i / s), -128, 127\big), \qquad \hat g_i = s\, q_i.\]

&lt;p&gt;The reconstruction error on each element is at most about half a step, (s/2), when rounding behaves. GEMM kernels multiply the integers and rescale. &lt;strong&gt;Per-channel&lt;/strong&gt; scales on convolutions usually beat one coarse per-tensor scale, because a single outlier channel would otherwise inflate (s) for every channel.&lt;/p&gt;

&lt;h3 id=&quot;where-the-error-becomes-audible&quot;&gt;Where the error becomes audible&lt;/h3&gt;

&lt;p&gt;Suppose the peak gain is (1). Then (s = 1/127 \approx 0.00787), and the absolute error is only a few thousandths. Relative to a full-scale bin that is nothing. Relative to a bin whose true gain is (0.004), one code is the entire signal. The mini-lab’s vector ([1.0,\ 0.5,\ 0.02,\ 0.004,\ 0.0]) quantizes to codes ([127,\ 64,\ 3,\ 1,\ 0]). The (0.004) bin moves to (1/127 \approx 0.00787). That is almost a doubling of a weak bin, and the maximum absolute error on the vector is about (0.00394), coming from the half-step on (0.5), not from the speech-like full-scale bin.&lt;/p&gt;

&lt;p&gt;In noise suppression those small gains are the noise-dominated bins and the weak harmonics. Collapse a harmonic to code (0) and the vowel thins. Round a near-silent bin up to one quantum and you leak a steady tonal floor, the usual source of musical noise. Weight error inside a convolution is filtered by later layers. Gain error is multiplied onto the STFT bin and summed by overlap-add. Calibrate and listen to the gain head even when you leave it in float32.&lt;/p&gt;

&lt;h3 id=&quot;approaches&quot;&gt;Approaches&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Mode&lt;/th&gt;
      &lt;th&gt;Idea&lt;/th&gt;
      &lt;th&gt;Pros&lt;/th&gt;
      &lt;th&gt;Cons&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Dynamic quant&lt;/td&gt;
      &lt;td&gt;Activations quantized at runtime&lt;/td&gt;
      &lt;td&gt;Easy to try&lt;/td&gt;
      &lt;td&gt;Overhead; variable latency&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Static PTQ&lt;/td&gt;
      &lt;td&gt;Calibrate ranges offline&lt;/td&gt;
      &lt;td&gt;Fast inference&lt;/td&gt;
      &lt;td&gt;Needs representative audio&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;QAT&lt;/td&gt;
      &lt;td&gt;Train with quant noise&lt;/td&gt;
      &lt;td&gt;Best quality when it converges&lt;/td&gt;
      &lt;td&gt;Costly&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Weight-only&lt;/td&gt;
      &lt;td&gt;INT8 or INT4 weights, float activations&lt;/td&gt;
      &lt;td&gt;Simple size win&lt;/td&gt;
      &lt;td&gt;Smaller speed win&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;For streaming enhancement, static post-training quantization in the ONNX Runtime toolchain is the usual first experiment. Move to quantization-aware training when SI-SDR or listening regresses. Quantization is a &lt;strong&gt;packaging&lt;/strong&gt; step: it runs before you compress the archive and before the browser compiles WASM (lesson 06-04, lesson 07-03). Do not quantize a graph whose STFT still disagrees with production.&lt;/p&gt;

&lt;h3 id=&quot;calibration-is-speech-not-imagenet&quot;&gt;Calibration is speech, not ImageNet&lt;/h3&gt;

&lt;p&gt;A calibration set that is only white noise produces scales that misfit café babble and near-end speech. Include silence, noise-only, loud near-end speech, low-SNR mixes, and residual-echo-like clips if echo is in scope. A minute of diverse DNS-style mixes is a teaching minimum. Products use a broader set and freeze it. Otherwise you get pumping or a harsh residual that objective scores on clean speech will miss.&lt;/p&gt;

&lt;h3 id=&quot;what-often-stays-float32&quot;&gt;What often stays float32&lt;/h3&gt;

&lt;p&gt;Sensitive elementwise gates, the final gain head, and very small layers where INT8 overhead exceeds the benefit often stay in float. First and last layers are a common heuristic, not a theorem. Verify. Recurrent state is a special case: an overflow that would be a one-bin click in a feed-forward net can ring for the rest of the call. Watch state ranges on a 30-minute stream (lesson 05-04).&lt;/p&gt;

&lt;h3 id=&quot;validation-gate&quot;&gt;Validation gate&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;SI-SDR and DNSMOS delta against the float model on a frozen set (Chapter 08).&lt;/li&gt;
  &lt;li&gt;Ten or more paired clips, forced choice, including gains that were near zero.&lt;/li&gt;
  &lt;li&gt;A long stream for state drift.&lt;/li&gt;
  &lt;li&gt;Real-time factor on the target device, not a smaller file size alone.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Survey notes on FastEnhancer and faster-enhancer.c show that fused INT8 kernels can move real-time factor a lot. ORT post-training quantization often moves it less. Measure. The package README’s 20–30% SIMD claim (lesson 06-03) is a separate speedup and is not a quantization result.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 quant_gain.py&lt;/code&gt; with this script. It uses Python’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;round&lt;/code&gt; (half to even), which matches the codes below.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.004&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;scale&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;127.0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;127&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))))&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scale&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;qi&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;qi&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;q=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;max_abs_error=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;scale=0.00787402
q=[127, 64, 3, 1, 0]
max_abs_error=0.00393701
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Using (128) as the divisor. Signed INT8’s positive end is (127), so the full-scale code is (127), not (128).&lt;/li&gt;
  &lt;li&gt;Reporting relative error only on the (1.0) bin and declaring the quantizer harmless. The (0.004) bin is the speech-NS case.&lt;/li&gt;
  &lt;li&gt;Quantizing before STFT parity. A one-bin frequency shift then gets baked into the scales.&lt;/li&gt;
  &lt;li&gt;Assuming this toy uses the same zero-point as a production ORT static quantizer. Production tools may use an affine zero-point; the lab is symmetric on purpose.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Calibrating on white noise only.&lt;/li&gt;
  &lt;li&gt;Shipping INT8 with no written quality delta for support.&lt;/li&gt;
  &lt;li&gt;Ignoring overflow in state tensors.&lt;/li&gt;
  &lt;li&gt;Treating a smaller &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tar.gz&lt;/code&gt; as proof the AudioWorklet meets its budget.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-hand-quantizing-a-4-weight-vector-to-symmetric-int8&quot;&gt;Worked Numerical Example: Hand-Quantizing a 4-Weight Vector to Symmetric INT8&lt;/h3&gt;

&lt;p&gt;Take a tiny weight vector from a speech denoiser layer:&lt;/p&gt;

\[\mathbf{w} = [-0.80,\; -0.15,\; 0.42,\; 0.95].\]

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the symmetric INT8 scale factor \(s\)&lt;/strong&gt; (mapping \(\max\lvert w_i
vert = 0.95\) to \(127\)):
\(s = rac{0.95}{127} pprox 0.0074803.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quantize each weight&lt;/strong&gt; \(q_i = \operatorname{round}(w_i / s)\) and &lt;strong&gt;dequantize&lt;/strong&gt; \(\hat{w}_i = s \cdot q_i\):&lt;/li&gt;
&lt;/ol&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Original \(w_i\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;\(w_i / s\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Quantized \(q_i\) (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i8&lt;/code&gt;)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Dequantized \(\hat{w}_i = s q_i\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Error \(e_i = \hat{w}_i - w_i\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(-0.80\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(-106.95\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(-107\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(-0.8004\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(-0.0004\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(-0.15\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(-20.05\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(-20\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(-0.1496\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+0.0004\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+0.42\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+56.15\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+56\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+0.4189\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(-0.0011\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+0.95\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+127.00\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+127\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(+0.9500\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.0000\)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Compute the exact SQNR in decibels:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Signal energy: \(\sum w_i^2 = 0.64 + 0.0225 + 0.1764 + 0.9025 = 1.7414\).&lt;/li&gt;
      &lt;li&gt;Quantization error energy: \(\sum e_i^2 pprox 1.6	imes 10^{-7} + 1.6	imes 10^{-7} + 1.21	imes 10^{-6} + 0 = 1.53	imes 10^{-6}\).&lt;/li&gt;
      &lt;li&gt;\(\mathrm{SQNR} = 10\log_{10}\!\left(rac{1.7414}{1.53	imes 10^{-6}}
ight) pprox \mathbf{60.6	ext{ dB}}\) — virtually indistinguishable from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FP32&lt;/code&gt;, while cutting storage by &lt;strong&gt;4×&lt;/strong&gt; (from 16 bytes to 4 bytes + 1 scale float)!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;explanation-four-rules-for-quantizing-speech-models-safely&quot;&gt;Explanation: Four Rules for Quantizing Speech Models Safely&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always use &lt;em&gt;per-channel&lt;/em&gt; quantization for Conv/Linear weights:&lt;/strong&gt; A single outlier filter in a convolutional layer can degrade SQNR by 15+ dB under per-tensor scaling.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Calibrate activations on realistic noisy + quiet audio:&lt;/strong&gt; If you calibrate static PTQ only on loud clean speech, quiet silence frames and sudden loud transient claps will clip or buzz in production.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Protect the final sigmoid/mask head in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FP32&lt;/code&gt;:&lt;/strong&gt; The final output layer costs less than 2% of total MACs, yet small rounding errors in gains near \(0.01\) (\(-40	ext{ dB}\)) create audible “musical noise” during speech pauses.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify quantization with both SI-SDR/DNSMOS &lt;em&gt;and&lt;/em&gt; real headphone listening:&lt;/strong&gt; Numbers can stay flat while subtle high-frequency hiss creeps into silence—always listen to quiet-tail segments!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; In our 4-weight vector above, suppose one extra outlier weight \(w_5 = 9.50\) (10× larger!) were added to the same tensor under &lt;em&gt;per-tensor&lt;/em&gt; symmetric INT8 quantization. How would the scale factor \(s\) change, and what would happen to the precision of the small weight \(-0.15\)?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Recompute the symmetric scale for weights confined to ([-0.8,\ 0.8]). What is (s), and what code does (0.8) receive?&lt;/li&gt;
  &lt;li&gt;List eight clip types for a Mezon-style post-training calibration set.&lt;/li&gt;
  &lt;li&gt;Design a blind sheet for float versus INT8 that includes at least two near-zero-gain conditions (soft speech, noise floor).&lt;/li&gt;
  &lt;li&gt;Name the ONNX Runtime quantization entry points you would call, from the official docs, without running them yet.&lt;/li&gt;
  &lt;li&gt;Explain, with the lab’s (0.004) bin, why a gain head is a poor candidate for aggressive INT8 even when the convolutions are not.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;(s = 0.8 / 127). The value (0.8) maps to code (127) if it is the max-abs. Do not use (255) unless you switched to an unsigned affine scheme and said so.&lt;/li&gt;
  &lt;li&gt;Include silence, noise-only, loud speech, whisper, low-SNR babble, non-stationary keyboard, a tone, and a residual-echo-like clip.&lt;/li&gt;
  &lt;li&gt;Forced choice, same gain, hidden labels, plus a “musical noise / thin voice” checkbox.&lt;/li&gt;
  &lt;li&gt;Start from the ONNX Runtime quantization documentation: static post-training quantization with a calibration reader. Exact class names change by API version; cite the page you opened.&lt;/li&gt;
  &lt;li&gt;(0.004) moved to about (0.00787). That relative jump is applied straight to a bin. Later layers do not smooth a mask the way they smooth a weight error.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;ONNX Runtime documentation&lt;/a&gt; quantization guides.&lt;/li&gt;
  &lt;li&gt;Jacob et al., quantization for integer-arithmetic-only inference, the standard mobile reference.&lt;/li&gt;
  &lt;li&gt;FastEnhancer / faster-enhancer.c notes on INT8 enhancement runtimes (survey pointers only).&lt;/li&gt;
  &lt;li&gt;DeepFilterNet model-size and real-time discussion in the upstream repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=0VdNflU08yA&quot;&gt;Quantization explained with PyTorch - Post-Training Quantization, Quantization-Aware Training&lt;/a&gt; — Umar Jamil, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch post-training quantization and quantization-aware training, including why a min-max range punishes every small gain when one outlier is huge.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, English. The INT8 section is quantization landing in ONNX Runtime, which is the path a speech model takes after the PyTorch explanation.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=phmFvMOHt4I&quot;&gt;Enable Model Quantization for ONNX and TensorRT!&lt;/a&gt; — Nicolai Nielsen Tech, English. Watch a quantized ONNX graph actually load. Treat TensorRT as optional; the lesson’s risk is the speech model, not the GPU vendor.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>06-01 ONNX, tract, and ORT</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter06/06_01_onnx_tract_ort/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter06/06_01_onnx_tract_ort</id>
   <content type="html">&lt;p&gt;On-device noise suppression almost always &lt;strong&gt;exports&lt;/strong&gt; a trained graph to an inference runtime. &lt;strong&gt;ONNX&lt;/strong&gt; is the interchange format; &lt;strong&gt;ONNX Runtime (ORT)&lt;/strong&gt; is the dominant cross-platform engine, including Web builds; &lt;strong&gt;tract&lt;/strong&gt; is the Rust-native crate used when you want a pure-Rust path. Package &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt; does not ship PyTorch to the browser. Its public release notes say the WASM path was rebuilt against &lt;strong&gt;tract 0.23.3&lt;/strong&gt;. The browser then receives a compiled WASM module plus the upstream archive &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3_onnx.tar.gz&lt;/code&gt;, not a Python session. This lesson fixes the selection criteria, the streaming I/O contract, and the shape mistakes that make a graph load in a notebook and fail inside an AudioWorklet.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/onnx-wasm-path.png&quot; alt=&quot;ONNX graph exported to a WASM module the browser loads beside the model archive&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. ONNX is the interchange file; tract or ORT executes it; the browser ultimately instantiates WASM.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Training a speech model in PyTorch is only half the journey—you cannot ship a 2-gigabyte PyTorch + Python installation inside a browser tab or a 5 MB mobile SDK! To cross from research notebook to production device, you export the computational graph to &lt;strong&gt;ONNX (Open Neural Network Exchange)&lt;/strong&gt; and execute it with a dedicated inference engine—most commonly &lt;strong&gt;ONNX Runtime (ORT)&lt;/strong&gt; in C++/WASM or &lt;strong&gt;tract&lt;/strong&gt; in pure Rust.&lt;/p&gt;

&lt;p&gt;This lecture compares ONNX, ORT, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; through a systems-engineering lens: how static shapes unlock zero-allocation execution plans, why operator coverage (especially GRUs, FFTs, and custom ops) decides which runtime you can pick, and how binary size trades off against peak SIMD throughput.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-graph-irs-static-execution-plans-and-runtime-trade-offs&quot;&gt;Key ideas: Graph IRs, Static Execution Plans, and Runtime Trade-Offs&lt;/h2&gt;

&lt;p&gt;Four systems principles guide your choice of inference runtime for real-time audio:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;ONNX as a Portable Static Graph IR:&lt;/strong&gt; Exporting with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.onnx.export&lt;/code&gt; freezes Python control flow into a typed DAG of standard operators (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Conv&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GRU&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MatMul&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Add&lt;/code&gt;) plus serialized constant weights.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Static Shapes Enable Pre-Allocated Memory Arenas:&lt;/strong&gt; For streaming audio, every frame has the &lt;em&gt;exact same shape&lt;/em&gt; (e.g., &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 1, 257]&lt;/code&gt;). Declaring fixed static shapes lets both ORT and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; compute an entire memory plan once at startup—achieving near-zero heap allocations inside the audio loop.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ONNX Runtime (ORT) vs. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; (Pure Rust):&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;ORT:&lt;/strong&gt; Battle-tested C++ engine with rich hardware Execution Providers (CoreML, DirectML, NNAPI, WASM SIMD), wider op coverage, larger binary footprint (several MB).&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt;:&lt;/strong&gt; Pure Rust, tiny self-contained binary (ideal for Rust native apps and lean WASM bundles), deterministic static planning (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;into_optimized().into_runnable()&lt;/code&gt;), slightly narrower op set.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Graph Fusion &amp;amp; Constant Folding:&lt;/strong&gt; Both runtimes fuse adjacent &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Conv + BatchNorm + ReLU&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MatMul + Add&lt;/code&gt; nodes at load time, eliminating intermediate tensor writes to RAM.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will explain ONNX as a speech-enhancement interchange format, compare ORT and tract for a browser product versus a Rust binary, list export pitfalls that show up only on a one-hop stream, and check whether a tensor shape is an image-style NCHW blob or a DeepFilter-style frame &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, T, F]&lt;/code&gt; before anyone calls a session.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Why an AudioWorklet cannot host a training framework.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Graph, initializers, opset, and who owns the STFT.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — ORT versus tract, including the 1.3.0 tract pin.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Dynamic axes, state tensors, and the shape cartoon.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, pitfalls, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;what-the-file-actually-contains&quot;&gt;What the file actually contains&lt;/h3&gt;

&lt;p&gt;An ONNX file is a computation graph: named tensors in and out, operators such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Conv&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GRU&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MatMul&lt;/code&gt;, and weights stored as initializers. The training framework writes the file. A runtime optimizes and executes it. For speech enhancement the graph either contains the feature transform or assumes you run the STFT outside the session. DeepFilter-class models are usually the second kind: the runtime consumes a spectral frame, and your overlap-add lives beside it. If those two sides disagree on hop, window, or frequency count, the session can still return tensors while the audio sounds wrong.&lt;/p&gt;

&lt;h3 id=&quot;opset-and-runtime-pin&quot;&gt;Opset and runtime pin&lt;/h3&gt;

&lt;p&gt;Operators are versioned by &lt;strong&gt;opset&lt;/strong&gt;. An export at opset 17 may refuse to load on an older ORT build. Pin three things together: the export opset, the ORT or tract version in the product, and a CI job that loads the exact &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.onnx&lt;/code&gt; on the runtime you ship. The 1.3.0 release notes of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; name tract &lt;strong&gt;0.23.3&lt;/strong&gt; for the WASM build. That pin is a product fact from the changelog, not a reason to skip an operator check. Tract and ORT do not implement every op the same way. A graph that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnxruntime&lt;/code&gt; imports in Python can still fail in tract if a custom deep-filter layer was not fused into supported ops.&lt;/p&gt;

&lt;h3 id=&quot;ort-versus-tract&quot;&gt;ORT versus tract&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Criterion&lt;/th&gt;
      &lt;th&gt;ONNX Runtime&lt;/th&gt;
      &lt;th&gt;tract&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Languages&lt;/td&gt;
      &lt;td&gt;C/C++, Python, Java, C#, JS/WASM&lt;/td&gt;
      &lt;td&gt;Rust-first&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Web story&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnxruntime-web&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Not the primary browser path&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Optimizations&lt;/td&gt;
      &lt;td&gt;Graph opts, execution providers&lt;/td&gt;
      &lt;td&gt;Rust graphs, streaming-friendly&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Product fit&lt;/td&gt;
      &lt;td&gt;Wide platform parity&lt;/td&gt;
      &lt;td&gt;The Rust path behind the 1.3.0 WASM notes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ops coverage&lt;/td&gt;
      &lt;td&gt;Broad default&lt;/td&gt;
      &lt;td&gt;Verify on a real DeepFilter export&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Choose ORT when you need one ONNX file checked from Python and a documented Web backend. Choose tract when the shipping binary is Rust and you have verified the operators. The Mezon package’s browser path is WASM built from the DeepFilter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libDF&lt;/code&gt; stack, with tract called out in the 1.3.0 notes. Chapter 09’s optional &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt; experiment is the place to link tract yourself. Do not treat the npm wrapper as a second model.&lt;/p&gt;

&lt;h3 id=&quot;streaming-axes&quot;&gt;Streaming axes&lt;/h3&gt;

&lt;p&gt;A streaming model should declare a frame whose time axis is one hop, plus recurrent state in and out. A typical teaching contract is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;features&lt;/code&gt; with shape &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, T, F]&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T = 1&lt;/code&gt; in the callback, together with fixed-size &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state_in&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state_out&lt;/code&gt;. Dynamic batch is useful for offline parallelism and almost always 1 inside the audio callback. Export those axes explicitly. Some exports bake &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T = 100&lt;/code&gt; from an offline validation script. That graph loads, then rejects every real-time hop.&lt;/p&gt;

&lt;p&gt;NCHW layouts such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 3, 224, 224]&lt;/code&gt; are image conventions. A rank-4 tensor is the wrong shape for a DeepFilter frame even when the numbers look “batched.” Rank 3 with a leading 1 is the cartoon this lesson accepts. The real next step, after the cartoon, is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ort.InferenceSession&lt;/code&gt; and a check that the &lt;strong&gt;input name&lt;/strong&gt; matches the graph, not only the rank.&lt;/p&gt;

&lt;h3 id=&quot;export-pitfalls&quot;&gt;Export pitfalls&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Unsupported ops&lt;/strong&gt; in custom deep-filter layers. Fuse them to ONNX-friendly ops or register a custom runtime op. Do not invent a private op name and hope CI is kind.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Control-flow and in-place&lt;/strong&gt; tracing mismatches between the training step and the exported graph.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Missing state I/O&lt;/strong&gt; on GRUs, so the model looks stateless and pumps from hop to hop.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Float64 leftovers.&lt;/strong&gt; Force float32 before you quantize or compile WASM.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Preprocessing drift.&lt;/strong&gt; A NumPy STFT in training versus the WASM STFT in the product.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;why-the-browser-path-standardizes-on-a-compiled-module&quot;&gt;Why the browser path standardizes on a compiled module&lt;/h3&gt;

&lt;p&gt;The package does not ask the page to construct an ORT session by hand. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core.initialize()&lt;/code&gt; fetches the WASM bytes and the model archive, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WebAssembly.compile&lt;/code&gt;s the module on the main thread. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt; runs only after that compile. Heavy work stays off the audio callback (Chapter 05). ORT remains the right tool for Python parity checks and for products that ship &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnxruntime-web&lt;/code&gt; directly. Measure real-time factor on the WASM build you ship. A Python ORT timing is a different machine.&lt;/p&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;Optional, if ONNX Runtime is installed: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 -c &quot;import onnxruntime&quot;&lt;/code&gt;. The required lab is the shape cartoon. Save it as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shape_check.py&lt;/code&gt; and run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 shape_check.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;verdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rank&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rank&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;NCHW rejected-by-df-frame&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rank&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DF frame [1, T, F] accepted&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rejected&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;224&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;224&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;96&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;96&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,)]:&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;verdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[1, 3, 224, 224] -&amp;gt; NCHW rejected-by-df-frame
[1, 1, 96] -&amp;gt; DF frame [1, T, F] accepted
[96] -&amp;gt; rejected
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Treating “accepted” here as proof the real graph will run. The cartoon only checks rank and a leading batch of 1.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ort.InferenceSession&lt;/code&gt; is the real next step. &lt;strong&gt;Session input name mismatch&lt;/strong&gt; is the usual failure: the shape is right and the input is still named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input&lt;/code&gt; in your code while the graph says &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feat_erb&lt;/code&gt; or similar. Read &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session.get_inputs()&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;A dynamic axis left at export-time &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T = 100&lt;/code&gt; passes a loose rank check and still rejects a hop of length 1.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Shipping a different ONNX file per operating system without a load test.&lt;/li&gt;
  &lt;li&gt;Enabling a CUDA execution provider in a product that must run on CPU-only laptops.&lt;/li&gt;
  &lt;li&gt;Assuming tract supports every model ORT accepts.&lt;/li&gt;
  &lt;li&gt;Copying Python ORT real-time factor numbers onto the WASM build.&lt;/li&gt;
  &lt;li&gt;Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;createAudioWorkletNode&lt;/code&gt; before &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;initialize()&lt;/code&gt; has compiled the module. The core throws if you do.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-counting-tensor-io-overhead-vs-compute-on-a-10-ms-frame&quot;&gt;Worked Numerical Example: Counting Tensor I/O Overhead vs. Compute on a 10 ms Frame&lt;/h3&gt;

&lt;p&gt;Suppose a streaming denoiser processes 10 ms frames (100 frames/s) with input &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 1, 257]&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;), output &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 1, 257]&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;), and state &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 128]&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Raw I/O payload per frame:&lt;/strong&gt;
\((257 + 257 + 128 + 128)	ext{ floats} 	imes 4	ext{ bytes} = 770 	imes 4 = 3{,}080	ext{ bytes} pprox 3.0	ext{ KB/frame}.\)
At 100 frames/s, that is only \(308	ext{ KB/s}\) of tensor data—tiny!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Runtime comparison for a 1.2 MB streaming model:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Dimension&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;ONNX Runtime (WASM / Native)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tract&lt;/code&gt; (Pure Rust)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;WASM / Binary Overhead&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;~3–8 MB (gzipped ~1–2.5 MB)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;~0.5–1.5 MB (lean Rust crate)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Startup Plan Optimization&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Session graph optimization + arena alloc&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;with_input_fact&lt;/code&gt; \(o\) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;into_optimized()&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Per-Frame Allocation Risk&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Low with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IOBinding&lt;/code&gt; / reused buffers&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Zero-alloc possible with reusable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TVec&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Best Fit&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Broad ops, GPU/NPU EPs, JS/TS teams&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Pure Rust SDKs, tight WASM size budgets&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Notice the trap: even though the tensor payload is only 3 KB, if a JS wrapper allocates &lt;em&gt;new&lt;/em&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ort.Tensor&lt;/code&gt; objects and copies buffers on every 10 ms frame, you trigger 100 heap allocations/sec—causing GC micro-stutters!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-painless-onnx-export-and-deployment&quot;&gt;Explanation: Four Rules for Painless ONNX Export and Deployment&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fix opset version and freeze static frame shapes:&lt;/strong&gt; Avoid dynamic sequence axes (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;seq_len = &quot;T&quot;&lt;/code&gt;) for streaming inference; locking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;seq_len = 1&lt;/code&gt; unlocks stronger operator fusion and simpler memory planning.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Keep STFT/iSTFT outside the ONNX graph:&lt;/strong&gt; Complex FFT operators have uneven support across ORT/tract/WASM backends; run STFT/iSTFT in clean Rust/C++/WASM DSP code and pass real-valued magnitude/complex pairs into ONNX.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify numerical parity immediately after export:&lt;/strong&gt; Compare PyTorch output vs. ORT/tract output on the same frame and assert \(\max\lvert y_{	ext{onnx}} - y_{	ext{torch}}
vert &amp;lt; 10^{-5}\) before integrating into audio callbacks.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Measure cold-start load time as well as per-frame RTF:&lt;/strong&gt; Downloading a 10 MB WASM runtime + compiling it on a slow mobile connection can delay call join by seconds.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; Why does exporting a streaming denoiser with static input shape &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 1, 257]&lt;/code&gt; generally run faster and allocate less memory than exporting with dynamic shape &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[batch, time, 257]&lt;/code&gt;?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Write a tensor table for a toy GRU hop: names, ranks, and which tensors are state.&lt;/li&gt;
  &lt;li&gt;Given an ORT version, look up its supported opset in the &lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;ONNX Runtime docs&lt;/a&gt; and pick an export opset.&lt;/li&gt;
  &lt;li&gt;In about 150 words, choose ORT or tract for a Chrome extension and again for a Rust CLI enhancer.&lt;/li&gt;
  &lt;li&gt;Design a CI step that fails when ONNX and a PyTorch reference differ by more than a stated SI-SDR threshold on one golden clip.&lt;/li&gt;
  &lt;li&gt;Explain why &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 3, 224, 224]&lt;/code&gt; must not be fed to a frame model even if batch size is 1.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frame&lt;/code&gt; shaped &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 1, F]&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state_in&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state_out&lt;/code&gt; with equal hidden sizes. Mark the STFT as outside the session if the graph has no FFT op.&lt;/li&gt;
  &lt;li&gt;The export opset must be one the shipping runtime documents, not the newest opset your trainer offers.&lt;/li&gt;
  &lt;li&gt;Extension: a WASM runtime with a known browser matrix. CLI: tract if the ops check passes, because you avoid a second native library. Either answer needs the operator check.&lt;/li&gt;
  &lt;li&gt;Fix the clip, the hop, and the threshold in the job. Fail on missing state outputs as well as on SI-SDR.&lt;/li&gt;
  &lt;li&gt;Rank 4 is NCHW. The frame contract in the mini-lab is rank 3.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://onnxruntime.ai/docs/&quot;&gt;ONNX Runtime documentation&lt;/a&gt;, including quantization and Web topics used in the next lessons.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/sonos/tract&quot;&gt;tract&lt;/a&gt;, the Rust inference library named in the package’s 1.3.0 notes.&lt;/li&gt;
  &lt;li&gt;npm &lt;a href=&quot;https://www.npmjs.com/package/deepfilternet3-noise-filter&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;&lt;/a&gt; and the &lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;repository&lt;/a&gt;. Optional instructor checkout, not a course edit target: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet export discussions. Verify any community ONNX file before you depend on it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=WDww8ce12Mc&quot;&gt;Faster and Lighter Model Inference with ONNX Runtime from Cloud to Client&lt;/a&gt; — Microsoft Developer, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch ONNX as the interchange file and ONNX Runtime as the engine that runs it on CPU, GPU, and the edge. Tract is the Rust engine in the lesson; this talk is the format and the dominant runtime.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Wp5PaRpudlk&quot;&gt;Introduction to ONNX Runtime&lt;/a&gt; — NVIDIA Developer, English. A second official introduction to the same runtime, useful for the execution-provider picture the lesson needs before any WASM build.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>05-04 Streaming model state</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter05/05_04_streaming_state/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter05/05_04_streaming_state</id>
   <content type="html">&lt;p&gt;A streaming enhancer is a function of the current hop and of state that survived the previous hop: the STFT overlap tail, the GRU vector, the deep-filter history, and the unread samples in the ring. Reset that bundle mid-call and the next hop does not match the tail. You hear a click or a one-hop noise burst.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/ring-buffer.png&quot; alt=&quot;Ring buffer whose unread samples are state that must survive the next hop&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The unread arc of the ring is state: it has to be the same memory on the next callback. The same rule applies to the GRU vector and to the four past STFT frames a 5-tap deep filter still needs. Wiping any of those at a hop boundary is an impulse. Listeners hear it as a click or a short noise burst.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You train a causal speech enhancement model in PyTorch, export it to ONNX, run it on a 5-second test clip offline, and it sounds crystal clear. Then you wire it into a live streaming pipeline—feeding one 10 ms frame at a time—and the output turns into a robotic, choppy mess! Almost every time, the culprit is the exact same bug: &lt;strong&gt;forgotten or misaligned streaming state&lt;/strong&gt; (GRU hidden states reset to zero, or causal convolution history buffers truncated by one frame).&lt;/p&gt;

&lt;p&gt;This lecture makes &lt;strong&gt;streaming model state&lt;/strong&gt; completely explicit: how to convert every stateful layer (causal Conv1d, dilated convolutions, GRUs, overlap-add synthesis buffers) into explicit input/output state tensors—and how to write a &lt;strong&gt;bit-equivalence unit test&lt;/strong&gt; proving that frame-by-frame streaming matches full-utterance inference to \(10^{-5}\)!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-turning-time-domain-networks-into-pure-state-machines&quot;&gt;Key ideas: Turning Time-Domain Networks Into Pure State Machines&lt;/h2&gt;

&lt;p&gt;A streaming neural network is mathematically a finite-state machine \((y_t, s_t) = f(x_t, s_{t-1})\). Four state components must be tracked with exact precision:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Causal Convolution Ring Buffers:&lt;/strong&gt; A causal 1D convolution with kernel size \(K\) and dilation \(d\) depends on the current frame plus the previous \((K - 1) \cdot d\) frames. Streaming inference shifts those \((K-1)\cdot d\) historical frames through an explicit state tensor &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[B, C, (K-1)*d]&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recurrent Hidden States (GRU / LSTM):&lt;/strong&gt; Each recurrent layer carries its previous hidden state \(h_{t-1}\) (and cell state \(c_{t-1}\) for LSTM) across frame boundaries, with shape &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[num_layers, B, H]&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;DSP Analysis &amp;amp; Synthesis State:&lt;/strong&gt; Don’t forget non-neural state! The STFT input needs the previous \(N - H\) samples of raw audio, and the inverse STFT overlap-add (OLA) needs an accumulator buffer of \(N - H\) samples to stitch frames smoothly without clicks.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reset &amp;amp; Silence Handling:&lt;/strong&gt; When a microphone mutes, a call switches audio devices, or a NaN slips in, the runtime must cleanly zero every state tensor so stale noise history does not bleed into the next utterance.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will list the state a DeepFilterNet-class hop feeds back, compute the overlap tail at the published 20 ms / 10 ms framing, and crossfade on mute instead of zeroing that tail.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — A click on enable, traced to a zeroed overlap tail.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Inventory: ring, STFT, GRU, 5 taps, SNR gate.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Mute, device change, underrun: three different resets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Long calls and drift, without inventing a paper.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;what-has-to-be-the-same-object-next-hop&quot;&gt;What has to be the same object next hop&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;State&lt;/th&gt;
      &lt;th&gt;Size at 48 kHz&lt;/th&gt;
      &lt;th&gt;If you zero it mid-call&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Input ring&lt;/td&gt;
      &lt;td&gt;0–479 samples waiting for a 480-sample hop&lt;/td&gt;
      &lt;td&gt;A hole, or a repeated quantum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;OLA tail&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;480 samples = 10 ms&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;A 10 ms step. That is the click&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;GRU&lt;/td&gt;
      &lt;td&gt;256 in the DeepFilterNet2 setup&lt;/td&gt;
      &lt;td&gt;Gains jump from the initial state: often a noise burst&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Deep-filter history&lt;/td&gt;
      &lt;td&gt;4 past frames, 96 low bins in the 2023 demo&lt;/td&gt;
      &lt;td&gt;Harmonics drop for up to 4 hops (40 ms)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Level normalizer&lt;/td&gt;
      &lt;td&gt;Exponential mean, 1 s decay (ICASSP features)&lt;/td&gt;
      &lt;td&gt;A level jump for about a second&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SNR gate&lt;/td&gt;
      &lt;td&gt;Running \(\xi\) (04-03)&lt;/td&gt;
      &lt;td&gt;Silence if you force \(\xi&amp;lt;-10\) dB&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Smoothed gains&lt;/td&gt;
      &lt;td&gt;One value per band (\(\lambda=0.6\) in RNNoise)&lt;/td&gt;
      &lt;td&gt;A one-frame gain spike&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;ONNX Runtime keeps this bundle only if the graph exposes it and you copy outputs back to the next inputs. A stateless call still returns a tensor; it is the wrong enhancer. A new session every hop also destroys RTF (05-01). One state vector, one call. Two tabs that share it will each eat the other’s update and both will click.&lt;/p&gt;

&lt;h3 id=&quot;what-a-reset-sounds-like&quot;&gt;What a reset sounds like&lt;/h3&gt;

&lt;p&gt;A 960-point window and a 480-point hop store &lt;strong&gt;480 samples (10 ms)&lt;/strong&gt; that the next frame must add. If hop \(n\) ends near amplitude 0.3 and you zero that tail, the output steps by ~0.3. That step is a click: you removed the overlap the window needed.&lt;/p&gt;

&lt;p&gt;A GRU reset is often a burst. From zeros, the first SNR and gain estimates are whatever the initial activations emit, frequently “no speech” or “full gain,” for one or two 10 ms hops. Full gain on a noisy bin is a noise burst; a forced \(\xi&amp;lt;-10\) dB gate (04-03) is a hole. Both line up with the button the user just pressed.&lt;/p&gt;

&lt;p&gt;Hard-zeroing is the wrong mute. Crossfade wet to dry over one hop (480 samples, about 3.75 quanta of 128). Fade the samples in the ring, not the hidden units, if the GRU was already warm.&lt;/p&gt;

&lt;h3 id=&quot;policies&quot;&gt;Policies&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cold start.&lt;/strong&gt; Zeros are correct before the first audible hop. Run a few silent hops before the call so the 1 s normalizer leaves exact zero.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enable.&lt;/strong&gt; Do not clear a tail that already holds dry audio. Crossfade dry to wet over 10–20 ms. Keep the GRU that warmed during bypass.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Disable.&lt;/strong&gt; Crossfade wet to dry and freeze the GRU. Zeroing it makes the next enable a burst.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;New device or sample rate.&lt;/strong&gt; Full reset and a new hop length. A 44.1 kHz quantum into a 48 kHz STFT will not fade into correctness.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Underrun.&lt;/strong&gt; Bypass (05-03) until the output ring holds a hop, then fade. Zeroing the tail without a fade clicks at the moment you were hiding a click.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;long-calls&quot;&gt;Long calls&lt;/h3&gt;

&lt;p&gt;A 45-minute call at a 10 ms hop is \(45\times 60\times 100=270\,000\) GRU updates. Drift is a slow walk of that vector (dullness or pumping), distinct from a one-hop click. Lesson 04-05 names Fast-ULCNet only as a shortlist entry for long-stream discussion; no paper is cited here. Blend state toward zero over a few hundred milliseconds of silence. An instant blend is a reset. Compare a calibration clip at minute 1 and minute 40.&lt;/p&gt;

&lt;h3 id=&quot;feedback-loop&quot;&gt;Feedback loop&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;state = initial   # zeros only before audio starts
for hop in stream:
    y, state = model(hop, state)
    emit y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Check shapes once: GRU in and out (256 in the DF2 setup), four past complex frames below the deep-filter cutoff, one 480-float tail. A mismatched binding reads the next tensor and sounds like a bad model.&lt;/p&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;A new inference session per hop (state gone, RTF gone).&lt;/li&gt;
  &lt;li&gt;One state object shared by two tabs.&lt;/li&gt;
  &lt;li&gt;Seeking an offline file without a reset, so file two inherits file one’s GRU.&lt;/li&gt;
  &lt;li&gt;Assuming a reloaded worklet kept its WASM state. A new module is a cold start.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Hear the reset in a number. Build a two-hop overlap tail of 4 samples (a toy stand-in for the 480-sample tail), emit the sum, then zero the tail and emit again.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
import numpy as np

def ola(prev_tail, frame):
    # frame layout: [overlap_with_previous | new_tail]
    mixed = prev_tail + frame[: len(prev_tail)]
    new_tail = frame[len(prev_tail) :].copy()
    return mixed, new_tail

frame0 = np.array([0.2, 0.2, 0.4, 0.4])  # tail that hop 1 will need
frame1 = np.array([0.4, 0.4, 0.1, 0.1])
mixed, tail = ola(frame0[2:], frame1)
print(&quot;continuous&quot;, mixed.tolist(), &quot;tail&quot;, tail.tolist())
mixed_reset, tail_reset = ola(np.zeros(2), frame1)
print(&quot;after_zero_tail&quot;, mixed_reset.tolist())
print(&quot;step&quot;, float(mixed[0] - mixed_reset[0]))
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;continuous [0.8, 0.8] tail [0.1, 0.1]&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;after_zero_tail [0.4, 0.4]&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;step 0.4&lt;/code&gt;. The continuous path adds the previous tail (0.4, 0.4) onto the next frame’s overlap. Zeroing the tail drops that contribution and the output steps by 0.4 on those samples. Scale 0.4 up to a real 480-sample hop and the step is a click. A GRU reset is the same experiment with a vector you cannot plot as easily: the first hop after the zero is an untrained transient, which comes out as a click or a noise burst.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;. Zeroing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tail&lt;/code&gt; “to be safe” on every hop and shipping a click on every hop. Resetting on mute without the crossfade. Sharing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tail&lt;/code&gt; across two streams so each hop adds the other stream’s overlap. Treating the 0.4 step as an RTF problem — the CPU was on time; the state was wrong.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-exact-state-tensor-budget-for-a-streaming-denoiser&quot;&gt;Worked Numerical Example: Exact State Tensor Budget for a Streaming Denoiser&lt;/h3&gt;

&lt;p&gt;Consider a lightweight streaming model with:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;STFT front-end: window \(N = 960\), hop \(H = 480\) (overlap \(N - H = 480\) samples).&lt;/li&gt;
  &lt;li&gt;Causal Conv1d Layer 1: \(C = 32\) channels, kernel \(K = 3\), dilation \(d = 1\).&lt;/li&gt;
  &lt;li&gt;Causal Conv1d Layer 2: \(C = 32\) channels, kernel \(K = 5\), dilation \(d = 2\).&lt;/li&gt;
  &lt;li&gt;GRU Layer: hidden width \(H_{	ext{gru}} = 64\) (1 layer).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compute the exact number of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; floats carried between frames:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;State Component&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;History Length Formula&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Tensor Shape&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Floats (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Memory (Bytes)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;STFT input overlap&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(N - H = 960 - 480\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[480]&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;480&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1,920 B&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;iSTFT OLA tail&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(N - H = 480\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[480]&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;480&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1,920 B&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Conv1d #1 cache&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\((K-1)\cdot d = (3-1)\cdot 1 = 2\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 32, 2]&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;64&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;256 B&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Conv1d #2 cache&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\((K-1)\cdot d = (5-1)\cdot 2 = 8\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 32, 8]&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;256&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1,024 B&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;GRU hidden state&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1 step&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1, 64]&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;64&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;256 B&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Total Streaming State&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;—&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;—&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;1,344 floats&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;5,376 B (~5.25 KB)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Just &lt;strong&gt;5.25 KB of explicit state&lt;/strong&gt;—small enough to sit permanently inside the CPU’s L1 data cache! And notice the golden verification test: run offline forward pass \(Y_{	ext{offline}} = F(X_{0..T-1})\), then loop \(t = 0\dots T-1\) passing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(x_t, state)&lt;/code&gt; explicitly, and assert \(\max \lvert Y_{	ext{stream}} - Y_{	ext{offline}} 
vert &amp;lt; 10^{-5}\)!&lt;/p&gt;

&lt;h3 id=&quot;explanation-four-rules-for-bug-free-streaming-state&quot;&gt;Explanation: Four Rules for Bug-Free Streaming State&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Make every state tensor an explicit ONNX input and output:&lt;/strong&gt; Never rely on hidden mutable globals inside a runtime; explicit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(x_t, s_in) -&amp;gt; (y_t, s_out)&lt;/code&gt; makes your model pure, testable, and safe for multiple concurrent audio tracks.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Check causality &lt;em&gt;before&lt;/em&gt; exporting:&lt;/strong&gt; A single non-causal &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BatchNorm&lt;/code&gt; running across the time axis or symmetric padding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;padding = (K-1)//2&lt;/code&gt; silently leaks future frames and breaks offline-vs-streaming equivalence!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Never zero-pad inside the streaming conv if you already prepended the cache:&lt;/strong&gt; Concatenating &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[state_cache, x_t]&lt;/code&gt; along time and running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;padding = 0&lt;/code&gt; reproduces exact causal convolution with zero off-by-one shift.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Automate the streaming-equivalence test in CI:&lt;/strong&gt; Every architecture edit should automatically assert \(\max\lvert Y_{	ext{stream}} - Y_{	ext{offline}}
vert &amp;lt; 10^{-5}\) on a 50-frame random signal.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; If we add a third causal dilated Conv1d layer with \(C = 32\) channels, kernel size \(K = 3\), and dilation \(d = 4\), how many historical frames must its cache store, and how many &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt; bytes does that add to our state?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Inventory.&lt;/strong&gt; For a DF3-style hop, list five state objects and the owner (worklet field, ONNX input, ring).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Click length.&lt;/strong&gt; Window 960, hop 480, sample rate 48 kHz. How many milliseconds of tail did a hard reset delete?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Policy.&lt;/strong&gt; Write the mute, unmute, and switch-mic actions in one sentence each. Which one is allowed to zero the GRU?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Drift versus reset.&lt;/strong&gt; A user reports a click at the moment NS is enabled, and a different user reports dull audio after 40 minutes. Which bug is state reset, and which is drift?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Input-ring occupancy, 480-float OLA tail, GRU (256 in the DF2 setup; confirm on the ONNX I/O), four frames of deep-filter history, and the ERB running mean. The worklet owns the rings; the graph I/O owns the GRU if it is an input.&lt;/li&gt;
  &lt;li&gt;\(480/48000=10\) ms of audio. That is the click’s length, not an RTF.&lt;/li&gt;
  &lt;li&gt;Mute and unmute: crossfade 10–20 ms and freeze the GRU. Switch-mic or sample-rate change: zero off-air, warm up on silence, then open the mic. Only that third case zeros the GRU.&lt;/li&gt;
  &lt;li&gt;A click at enable is a reset. Dull audio after 40 minutes is drift (\(240\,000\) hops) or thermal RTF. Zeroing mid-sentence does not fix drift.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Lessons 04-02 and 04-03 for the 5-tap history, the 256-wide GRU in DeepFilterNet2, and the SNR gate in &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Lesson 05-03 for the ring that holds the tail between 128-sample quanta.&lt;/li&gt;
  &lt;li&gt;ONNX Runtime I/O binding docs, for feeding state tensors back without rebuilding the session.&lt;/li&gt;
  &lt;li&gt;MDN, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;AudioWorklet&lt;/a&gt;, for processor lifetime: a new worklet is a new state, and the first hop is a cold start.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Gated Recurrent Unit&lt;/td&gt;
          &lt;td&gt;GRU&lt;/td&gt;
          &lt;td&gt;Explained in detail](https://www.youtube.com/watch?v=IBs8D8PWMc8) — Learn With Jay, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the update gate that keeps state across steps. A streaming enhancer’s GRU vector is that state between hops.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. The encoder GRU is the recurrent state the lesson says you must not reset mid-call.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nsscrYdrGRE&quot;&gt;RNNoise, Neural Speech Enhancement, and the Browser&lt;/a&gt; — W3C, English. A small GRU emitting gains per frame is the same streaming-state idea at teaching scale.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>05-03 Ring buffers and underruns</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter05/05_03_ring_buffers_underruns/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter05/05_03_ring_buffers_underruns</id>
   <content type="html">&lt;p&gt;A DeepFilterNet hop is 480 samples. An AudioWorklet quantum is often 128. Those two clocks meet in a &lt;strong&gt;ring buffer&lt;/strong&gt;: a fixed array plus a read index and a write index. When the reader catches the writer you get an &lt;strong&gt;underrun&lt;/strong&gt; (a click or a hole). When the writer laps the reader you get an &lt;strong&gt;overrun&lt;/strong&gt; (latency that grows until you drop or bypass). This lesson sizes the ring and implements both policies on an 8-sample toy.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/ring-buffer.png&quot; alt=&quot;Circular buffer with a write index ahead of a read index&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. One fixed array. The writer advances &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;write_pos&lt;/code&gt; as quanta arrive; the reader advances &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read_pos&lt;/code&gt; when a full hop is ready. Occupancy is the distance between them. The grey region is the only state that must survive the next callback. Capacity does not grow.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;How do two threads—a hyper-punctual 128-sample &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; callback and a bursty 480-sample ML inference Worker—hand audio samples back and forth thousands of times per second &lt;strong&gt;without ever locking a mutex&lt;/strong&gt;? The answer is one of the oldest, cleanest data structures in systems programming: the &lt;strong&gt;lock-free Single-Producer Single-Consumer (SPSC) ring buffer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This lecture traces the exact pointer arithmetic of a power-of-two ring buffer, explains why &lt;strong&gt;underruns&lt;/strong&gt; (empty output buffer \(o\) audible clicks) and &lt;strong&gt;overruns&lt;/strong&gt; (full input buffer \(o\) dropped audio) happen, and derives the exact minimum prefill latency needed to keep real-time streaming rock-solid.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-lock-free-spsc-queues-and-jitter-absorption&quot;&gt;Key ideas: Lock-Free SPSC Queues and Jitter Absorption&lt;/h2&gt;

&lt;p&gt;Four systems principles govern audio ring buffers:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Power-of-Two Wrap-Around Arithmetic:&lt;/strong&gt; Sizing a ring buffer to \(C = 2^k\) samples (e.g., 2048 or 4096) replaces expensive modulo division &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;% C&lt;/code&gt; with a single bitwise AND mask &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;idx &amp;amp; (C - 1)&lt;/code&gt;, and using monotonically incrementing unsigned &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;write_idx&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read_idx&lt;/code&gt; avoids the classic “full vs. empty” ambiguity!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Lock-Free SPSC Memory Ordering:&lt;/strong&gt; With exactly one writer updating &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;write_idx&lt;/code&gt; (with &lt;em&gt;release&lt;/em&gt; semantics) and one reader updating &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read_idx&lt;/code&gt; (with &lt;em&gt;acquire&lt;/em&gt; semantics via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Atomics.store&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Atomics.load&lt;/code&gt; in JS or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std::sync::atomic&lt;/code&gt; in Rust), neither thread ever blocks the other.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Underrun vs. Overrun Mechanics:&lt;/strong&gt; An &lt;strong&gt;underrun&lt;/strong&gt; happens when the audio callback asks for 128 output samples and fewer than 128 are ready—forcing zeros (a sharp discontinuity / click). An &lt;strong&gt;overrun&lt;/strong&gt; happens when the producer writes faster than the consumer drains, overwriting unconsumed audio.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Prefill Latency vs. Safety Margin:&lt;/strong&gt; Pre-filling the output ring buffer with one hop of silence (e.g., 480 samples = 10 ms) absorbs the bursty compute time of the Worker thread at the cost of a fixed, predictable latency.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will compute occupancy and free space after a 6-sample write and a 4-sample read; implement an overrun policy that drops the oldest sample rather than allocating; and choose a power-of-two capacity for a 480-sample hop, a 128-sample quantum, and a small jitter budget without hiding an extra 100 ms of delay in the ring.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — What a click, a dropout, and a growing delay sound like.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Indices, mask, occupancy. The toy of 6 then 4.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Two rings around one 10 ms hop. Capacity arithmetic.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Drop versus bypass when the writer is ahead.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;mechanics&quot;&gt;Mechanics&lt;/h3&gt;

&lt;p&gt;Store PCM in an array of length \(C\), preferably \(C=2^m\), so wrapping is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index &amp;amp; (C-1)&lt;/code&gt; with no division on the audio thread. A single producer and a single consumer (SPSC) need only the two indices. Occupancy and free space:&lt;/p&gt;

\[\mathrm{available}=(\mathrm{write\_pos}-\mathrm{read\_pos})\bmod C,\qquad \mathrm{free}=C-\mathrm{available}.\]

&lt;p&gt;If you keep an explicit count, as the lab does, you do not recompute the modulo on every sample; you still have to wrap the indices when you store. The producer may write \(n\) samples only when \(\mathrm{free}\ge n\). The consumer may read \(n\) only when \(\mathrm{available}\ge n\). Doing either anyway is the bug: writing past free space corrupts samples the consumer has not played, and reading past available replays stale PCM or zeros.&lt;/p&gt;

&lt;p&gt;The figure’s grey arc is occupancy. It is streaming state. Clearing the array on every enable toggle throws away that arc and the listener hears a gap (lesson 05-04).&lt;/p&gt;

&lt;h3 id=&quot;where-the-rings-sit&quot;&gt;Where the rings sit&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mic quanta (128) → ring A → gather 480 → NS hop → ring B → out quanta (128)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ring A converts “3.75 quanta per hop” into an integer hop. \(480/128=3.75\), so after three callbacks ring A holds 384 samples and the hop does not run; after four it holds 512, the hop consumes 480, and 32 remain. Ring B holds the 480-sample overlap-add burst and releases it 128 samples at a time. One ring cannot serve both clocks unless you are careful about who produces: the microphone and the model are two producers if you naively share a buffer. Give them one ring each.&lt;/p&gt;

&lt;h3 id=&quot;capacity&quot;&gt;Capacity&lt;/h3&gt;

&lt;p&gt;Let hop length be \(H\) samples, quantum \(Q\), and \(J\) extra hops of jitter you are willing to absorb.&lt;/p&gt;

\[C \gtrsim H + J\cdot H + Q.\]

&lt;p&gt;For \(H=480\), \(Q=128\), \(J=2\): \(480+960+128=1568\), next power of two &lt;strong&gt;2048&lt;/strong&gt; samples, \(2048/48000\approx 42.7\) ms in that stage. \(J=3\) lands on 2048 exactly, so the next safe power of two is &lt;strong&gt;4096&lt;/strong&gt; (85 ms). Two stages plus the model’s 40 ms look-ahead are already a long conversation delay. Every extra factor of two is delay the user attributes to the suppressor.&lt;/p&gt;

&lt;h3 id=&quot;underrun-overrun-and-the-two-policies&quot;&gt;Underrun, overrun, and the two policies&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Event&lt;/th&gt;
      &lt;th&gt;Condition&lt;/th&gt;
      &lt;th&gt;What to do&lt;/th&gt;
      &lt;th&gt;What the user hears if you guess&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Output underrun&lt;/td&gt;
      &lt;td&gt;ring B has fewer than \(Q\) samples&lt;/td&gt;
      &lt;td&gt;Copy the dry quantum (bypass) or emit a short fade to zero&lt;/td&gt;
      &lt;td&gt;A click, or a hole of silence&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Input overrun&lt;/td&gt;
      &lt;td&gt;ring A &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free &amp;lt; n&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Drop the oldest unread samples, then write&lt;/td&gt;
      &lt;td&gt;A skip forward. Latency stays bounded&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Model late&lt;/td&gt;
      &lt;td&gt;hop wall time \(&amp;gt; 10\) ms (RTF p95 \(&amp;gt; 1\))&lt;/td&gt;
      &lt;td&gt;Leave the already-queued output; bypass new quanta until the hop catches up&lt;/td&gt;
      &lt;td&gt;Crackles if you instead block &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Blocking the audio thread to “let inference finish” turns an overrun into a priority inversion. The 2.67 ms quantum will expire while you hold the lock. Bypass and drop are both non-blocking. Bypass preserves timing and lets noise through. Drop preserves the suppressor and discards audio. Pick drop on the capture ring (old mic samples are the ones you would have played late) and bypass on the output ring (the speaker cannot be handed silence without a fade, but it also cannot wait).&lt;/p&gt;

&lt;h3 id=&quot;what-to-log&quot;&gt;What to log&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;underrun_count&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;overrun_count&lt;/code&gt;, high-water occupancy, low-water occupancy. Correlate overruns with the p95 RTF from lesson 05-01. A ring that sits at 95% full is extra latency you can cut. A ring that touches zero is a click you already shipped.&lt;/p&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Two producers, one ring, no second synchronization story.&lt;/li&gt;
  &lt;li&gt;Interleaved stereo written into a planar ring, or the reverse. Channel layout is part of the capacity math (two rings, or \(2C\)).&lt;/li&gt;
  &lt;li&gt;Growing \(C\) until the call sounds like a satellite hop. 4096 samples is already 85 ms.&lt;/li&gt;
  &lt;li&gt;Zeroing the ring on mute and un-mute. Drain it, or crossfade (lesson 05-04).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; On a capacity-8 ring, write 6 samples, read 4, print occupancy, then write 7 more samples under a drop-oldest overrun policy and show what survived.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
import numpy as np

class Ring:
    def __init__(self, cap):
        self.buf = np.zeros(cap, dtype=np.float64)
        self.cap = cap
        self.w = 0
        self.r = 0
        self.n = 0
    def free(self):
        return self.cap - self.n
    def write(self, samples):
        if len(samples) &amp;gt; self.free():
            raise RuntimeError(&quot;overrun&quot;)
        for v in samples:
            self.buf[self.w] = v
            self.w = (self.w + 1) % self.cap
            self.n += 1
    def read(self, k):
        if k &amp;gt; self.n:
            raise RuntimeError(&quot;underrun&quot;)
        out = np.empty(k, dtype=np.float64)
        for i in range(k):
            out[i] = self.buf[self.r]
            self.r = (self.r + 1) % self.cap
            self.n -= 1
        return out
    def write_drop_oldest(self, samples):
        dropped = 0
        for v in samples:
            if self.free() == 0:
                self.r = (self.r + 1) % self.cap
                self.n -= 1
                dropped += 1
            self.buf[self.w] = v
            self.w = (self.w + 1) % self.cap
            self.n += 1
        return dropped

rb = Ring(8)
rb.write([1, 2, 3, 4, 5, 6])
print(&quot;after_write6&quot;, rb.n, rb.free())
got = rb.read(4)
print(&quot;read4&quot;, got.tolist(), &quot;occ&quot;, rb.n)
dropped = rb.write_drop_oldest([10, 11, 12, 13, 14, 15, 16])
print(&quot;dropped&quot;, dropped, &quot;occ&quot;, rb.n)
print(&quot;next4&quot;, rb.read(4).tolist())
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;after_write6 6 2&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read4 [1.0, 2.0, 3.0, 4.0] occ 2&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dropped 1 occ 8&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;next4 [6.0, 10.0, 11.0, 12.0]&lt;/code&gt;. After the read, the ring held 5 and 6. Seven new samples needed one extra slot, so the oldest remaining sample (5) was dropped. 6 survived, then 10, 11, and 12.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;. Raising the capacity instead of dropping (latency grows without a log line). Blocking when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free &amp;lt; n&lt;/code&gt;. Using the bypass policy but still reporting the dropped-sample numbers above — bypass would have refused the write and left occupancy at 2. Forgetting to wrap &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt; with modulo 8, so sample 16 lands past the array.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-tracing-a-capacity-8-power-of-two-ring-buffer-by-hand&quot;&gt;Worked Numerical Example: Tracing a Capacity-8 Power-of-Two Ring Buffer by Hand&lt;/h3&gt;

&lt;p&gt;Let \(C = 8\) (mask &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C - 1 = 7&lt;/code&gt;), starting with monotonic counters &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w = 0, r = 0&lt;/code&gt;. Remember:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Samples available to read: \(ext{avail} = w - r\).&lt;/li&gt;
  &lt;li&gt;Free slots to write: \(ext{free} = C - (w - r)\).&lt;/li&gt;
  &lt;li&gt;Physical array slot: \(ext{slot} = 	ext{idx} \ \&amp;amp;\ 7\).&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Step&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Operation&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Physical Slots Written/Read&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;avail = w - r&lt;/code&gt;&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free = 8 - avail&lt;/code&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Init&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;—&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0 (Empty!)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;8&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Push 5 samples&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;slots &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0, 1, 2, 3, 4&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Pop 3 samples&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;slots &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0, 1, 2&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;6&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Push 4 samples&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;9&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;slots &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5, 6, 7, 0&lt;/code&gt; (wrapped!)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;6&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;4&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Try Push 3&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;—&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;—&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Only &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free = 2 &amp;lt; 3&lt;/code&gt; \(\implies\) &lt;strong&gt;OVERRUN!&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;6&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Pop 6 samples&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;9&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;9&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;slots &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3, 4, 5, 6, 7, 0&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0 (Empty!)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;8&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Now scale up to our &lt;strong&gt;48 kHz AudioWorklet + 480-sample Worker&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Input ring buffer collects 128-sample chunks until &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;avail &amp;gt;= 480&lt;/code&gt; (takes up to 4 callbacks = 512 samples).&lt;/li&gt;
  &lt;li&gt;Output ring buffer should be pre-filled with at least &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;480&lt;/code&gt; samples (10 ms) so that while the Worker takes up to 10 ms to denoise the frame, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; never sees &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;avail &amp;lt; 128&lt;/code&gt;! Choosing buffer capacity \(C = 2048\) samples (42.7 ms) leaves generous room against transient OS jitter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;explanation-four-rules-for-bulletproof-audio-ring-buffers&quot;&gt;Explanation: Four Rules for Bulletproof Audio Ring Buffers&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always check &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;avail&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free&lt;/code&gt; &lt;em&gt;before&lt;/em&gt; touching memory:&lt;/strong&gt; Never partially overwrite or read uninitialized slots; either push/pop the whole chunk or record an explicit overrun/underrun counter for telemetry.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Atomics.store&lt;/code&gt; AFTER writing samples, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Atomics.load&lt;/code&gt; BEFORE reading samples:&lt;/strong&gt; This acquire–release pair guarantees the consumer never reads half-written float samples due to CPU instruction reordering.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Never let underrun glitches stay silent in metrics:&lt;/strong&gt; Increment an atomic &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;underrun_count&lt;/code&gt; and fade to/from zero over a few milliseconds during recovery to turn harsh clicks into soft dips.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Right-size your prefill:&lt;/strong&gt; Too little prefill causes constant clicks; too much prefill (e.g., 200 ms) ruins live conversation. Start at \(1	ext{ hop} + 1	ext{ quantum}\) and tune from real p99 telemetry.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; In our capacity-8 ring buffer above, if &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w = 14&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r = 6&lt;/code&gt;, how many samples are available (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;avail&lt;/code&gt;), how many slots are free (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free&lt;/code&gt;), and which physical index (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;idx &amp;amp; 7&lt;/code&gt;) will the &lt;em&gt;next&lt;/em&gt; pop read from?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Identity.&lt;/strong&gt; After &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;write 6&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read 4&lt;/code&gt; on a fresh capacity-8 ring, what is occupancy, and which samples are still stored?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Power of two.&lt;/strong&gt; \(H=480\), \(Q=128\), \(J=3\). Compute \(H+JH+Q\) and the next power of two. How many milliseconds is that power of two at 48 kHz?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Policy.&lt;/strong&gt; Capture ring free space is 100 samples and the callback delivers 128. Do you drop 28 oldest samples or bypass the model? What does each choice do to latency?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Two rings.&lt;/strong&gt; Why can the model not write its 480-sample output into ring A?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Occupancy 2. Samples 5 and 6 remain. 1 through 4 have been consumed.&lt;/li&gt;
  &lt;li&gt;\(480+3\times 480+128=2048\) exactly, so a capacity of 2048 has zero spare sample. Use 4096 if you need strict \(\ge\). \(4096/48000\approx 85.3\) ms per stage.&lt;/li&gt;
  &lt;li&gt;Drop 28 oldest on the capture ring: latency stays capped, 28 samples (\(28/48000\approx 0.58\) ms) are skipped. Bypass: the model does not run this quantum, latency does not grow, noise is passed through. Blocking is not a third option.&lt;/li&gt;
  &lt;li&gt;Ring A’s producer is the microphone. A second writer races the quantum callback. Ring B is the model’s output queue.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Lesson 05-01 for the p95 that predicts the overrun, and lesson 05-02 for the 128-sample producer.&lt;/li&gt;
  &lt;li&gt;MDN, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;AudioWorklet&lt;/a&gt;, for the thread that must not block when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free&lt;/code&gt; is zero.&lt;/li&gt;
  &lt;li&gt;JACK or PipeWire buffer-size notes, as a second vocabulary for “period versus ring depth,” not as an API you must call.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the hardware callback size against the work you wish you could do in bigger blocks. The ring buffer in the lesson is the seam between those two sizes; this talk is the clocks, not a line-by-line buffer.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=g1L4O1smMC0&quot;&gt;AudioWorklet :: What, Why, and How - Hongchan Choi&lt;/a&gt; — WebAudio PDX, English. The process callback is the reader that must not block. An empty read is the underrun the lesson names.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>05-02 AudioWorklet and audio callbacks</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter05/05_02_audioworklet_callbacks/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter05/05_02_audioworklet_callbacks</id>
   <content type="html">&lt;p&gt;Browser audio is rendered on a real-time thread. &lt;strong&gt;AudioWorklet&lt;/strong&gt; is the API that puts your code on that thread: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audioWorklet.addModule&lt;/code&gt;, then an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletNode&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process(inputs, outputs, parameters)&lt;/code&gt; once per render quantum. The quantum is often &lt;strong&gt;128 samples&lt;/strong&gt;. At 48 kHz that is \(128/48000\approx 2.67\) ms. Inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; you may not allocate, take a lock, or touch the network. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; does all three kinds of harm and is not how you debug a dropout.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;AudioWorklet quantum as a wall-time budget next to RTF&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Each callback owns a short block — commonly 128 samples, about 2.67 ms at 48 kHz — and must return before the next one. RTF is measured on whatever block you chose to time (one quantum, or one 10 ms model hop gathered from several quanta). The picture is the deadline, not a license to run a DeepFilterNet forward pass inside a single &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; call.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you try to run real-time audio processing on JavaScript’s main UI thread, every time the user scrolls a page or opens a dropdown menu, the audio stutters horribly. The Web Audio API solved this with &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletProcessor&lt;/code&gt;&lt;/strong&gt;: a dedicated, high-priority real-time audio thread that wakes up like clockwork every &lt;strong&gt;128 audio samples&lt;/strong&gt; and demands your next buffer of clean audio—no excuses, no waiting for network requests, and no garbage-collection pauses!&lt;/p&gt;

&lt;p&gt;This lecture demystifies the real-time audio callback contract in browsers (and its native cousins CoreAudio, ALSA, and WASAPI): why 128 samples equals just &lt;strong&gt;2.67 milliseconds&lt;/strong&gt; at 48 kHz, why allocating memory or taking locks inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt; is forbidden, and how to bridge a 128-sample callback with a 480-sample neural network hop.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-real-time-audio-thread-contracts&quot;&gt;Key ideas: Real-Time Audio Thread Contracts&lt;/h2&gt;

&lt;p&gt;Audio callbacks obey the strictest execution rules in application software:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fixed Render Quantum (128 Samples):&lt;/strong&gt; Web Audio invokes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process(inputs, outputs)&lt;/code&gt; with exactly 128 samples per channel. At 48 kHz, the hard deadline is \(128 / 48{,}000 = 2.667	ext{ ms}\); at 44.1 kHz, it is \(2.902	ext{ ms}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Real-Time Safety (No Allocation, No Locks, No I/O):&lt;/strong&gt; Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new Float32Array(...)&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;malloc()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log()&lt;/code&gt;, or acquiring a mutex inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt; can block the audio thread unpredictably, causing instant audible pops. Pre-allocate every buffer once in the constructor!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quantum-to-Hop Rate Adaptation:&lt;/strong&gt; Neural speech models typically prefer 10 ms hops (480 samples at 48 kHz), which is &lt;em&gt;not&lt;/em&gt; an integer multiple of 128. You must buffer incoming 128-sample chunks in a pre-allocated ring buffer and trigger inference whenever \(\ge 480\) samples accumulate.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Heavy Inference Offloading (Optional Worker):&lt;/strong&gt; If a single ML forward pass takes 4 ms (longer than the 2.67 ms quantum!), running it directly inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt; will miss deadlines even if its average RTF is 0.40—requiring either a faster model or offloading inference to a dedicated Worker via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SharedArrayBuffer&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will trace the AudioWorklet lifecycle, write a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; that copies input to output when a bypass flag is set, explain why &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; is illegal on that thread, and place a 480-sample DeepFilterNet hop across several 128-sample quanta without assuming the counts divide.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Why the main thread cannot own the microphone callback.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Lifecycle, the 128-sample quantum, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return true&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Bypass copy, and the ban on allocate / lock / network.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Where a DF3 ONNX graph is allowed to run.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab (pseudocode is enough), exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;lifecycle&quot;&gt;Lifecycle&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;On the main thread, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;audioContext.audioWorklet.addModule(&apos;ns-processor.js&apos;)&lt;/code&gt; loads the processor script. This is where compilation belongs. It is not inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new AudioWorkletNode(audioContext, &apos;ns-processor&apos;, options)&lt;/code&gt; constructs the node. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;options.processorOptions&lt;/code&gt; can pass hop size and channel count once.&lt;/li&gt;
  &lt;li&gt;Connect &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source → nsNode → destination&lt;/code&gt;, or into the WebRTC track path (Chapter 07).&lt;/li&gt;
  &lt;li&gt;The browser calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; on the &lt;strong&gt;audio rendering thread&lt;/strong&gt;, once per quantum, for the life of the node. MDN’s AudioWorklet page is the spec-facing reference: &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;registerProcessor(&apos;ns-processor&apos;, NsProcessor)&lt;/code&gt; runs when the module loads, on the audio thread’s setup, not per buffer. Returning &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; keeps the node alive. Returning &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt; allows the browser to collect it, which sounds like the suppressor vanished mid-call.&lt;/p&gt;

&lt;h3 id=&quot;the-bypass-contract&quot;&gt;The bypass contract&lt;/h3&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;NsProcessor&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;AudioWorkletProcessor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bypass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// model not ready: copy, do not block&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onmessage&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// Control messages are delivered between callbacks, not during them.&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;setBypass&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bypass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nf&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;outputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;outputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;outputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bypass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// output already exists. set() copies bytes; it does not allocate the buffer.&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Enhancement would use only preallocated scratch and a ready model.&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;registerProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ns-processor&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;NsProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bypass&lt;/code&gt; is set, the listener hears the microphone, delayed by the graph, with no suppressor. That is the correct behavior while WASM is compiling or while the previous hop missed its deadline (lesson 05-03). &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;output.set(input)&lt;/code&gt; requires equal lengths. A quantum of 128 into a leftover buffer of a different size throws, and an exception inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; kills the node. Check &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input.length&lt;/code&gt; before the copy.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; uses the same shape: ONNX/WASM in an AudioWorklet, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, suppression 0–100 via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. It is not bit-exact with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepFilter&lt;/code&gt; CLI, and the bypass above is teaching code, not that package.&lt;/p&gt;

&lt;h3 id=&quot;why-consolelog-is-illegal-in-process&quot;&gt;Why &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; is illegal in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;The rendering thread has a hard deadline of about 2.67 ms for a 128-sample quantum at 48 kHz. Three rules follow, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; breaks them:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;No allocation.&lt;/strong&gt; Formatting a log line builds a string. A string is a heap allocation. Allocation can trigger garbage collection, and a GC pause of a few milliseconds is already larger than the quantum.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;No lock.&lt;/strong&gt; Delivering the line to the console or to DevTools crosses to another thread and can wait on a mutex. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Atomics.wait&lt;/code&gt; and any synchronous IPC are the same class of bug.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;No network.&lt;/strong&gt; A log sink that posts to a remote debugger or a telemetry endpoint waits on I/O. The audio device does not.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The same ban covers &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fetch&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSON.parse&lt;/code&gt; of a weight file, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new Float32Array&lt;/code&gt; every callback, compiling WASM, and blocking on a mutex held by the main thread. Control changes (bypass, suppression, a “model ready” bit) arrive as small messages on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MessagePort&lt;/code&gt;, applied between quanta. Weights load on the main thread or a worker before the node leaves bypass.&lt;/p&gt;

&lt;p&gt;A Node.js script that imports &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wrtc&lt;/code&gt; or a WASM build is optional practice. It is not required to pass this lab. The pass condition is the pseudocode and the explanation above.&lt;/p&gt;

&lt;h3 id=&quot;quantum-versus-hop&quot;&gt;Quantum versus hop&lt;/h3&gt;

&lt;p&gt;The published hop is 10 ms, &lt;strong&gt;480 samples&lt;/strong&gt; at 48 kHz (04-02, 04-03). \(480/128=3.75\). Three callbacks hold 384 samples, four hold 512. Append into a ring (05-03) until 480 are present, run one hop, and slice the overlap-add output back into 128-sample quanta. Assuming &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input.length === 480&lt;/code&gt; drops or repeats audio.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt; is in scope in the worklet. Read it. At 44.1 kHz the same 128 samples last \(128/44100\approx 2.90\) ms, and a 480-sample hop is the wrong length for a 48 kHz model. CoreAudio, WASAPI, and AAudio use the same rule under other names: finish before the next period, and bypass when the model is late.&lt;/p&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Debugging dropouts with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;console.log&lt;/code&gt; and making them worse.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new Float32Array(128)&lt;/code&gt; inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Hard-coding 48000 instead of reading &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Structured-cloning a full PCM buffer to the main thread every quantum. Use a SharedArrayBuffer ring if you must leave the thread, and measure the copies.&lt;/li&gt;
  &lt;li&gt;Running ScriptProcessorNode, which pulls audio back onto the main thread.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Implement the bypass copy as plain pseudocode in Python so the lab has no browser and no Node dependency. The AudioWorklet version is the block in the lesson; a Node harness is optional and is not required to pass.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
def process(frame, bypass, output):
    &quot;&quot;&quot;Copy input to the caller-provided output when bypass is set.
    console.log is illegal: it allocates a string, can lock against
    the console thread, and may touch the network. Do none of that here.
    &quot;&quot;&quot;
    if bypass:
        for i, sample in enumerate(frame):
            output[i] = sample
        return True
    for i, sample in enumerate(frame):
        output[i] = sample  # enhancement would write here, still no allocation
    return True

frame = [0.1, -0.2, 0.3, -0.4]
out = [0.0] * 4
alive = process(frame, bypass=True, output=out)
print(alive, out)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;True [0.1, -0.2, 0.3, -0.4]&lt;/code&gt;. The output buffer object is the one the caller allocated. Nothing in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; constructs a list, prints, or waits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;. Allocating &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;out = frame.copy()&lt;/code&gt; inside the function and calling it real-time safe. Inserting a print “just for the lab” and leaving it in the worklet. Requiring &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install&lt;/code&gt; or a running browser for a pass. Treating a successful copy as evidence that the DF3 graph meets the 2.67 ms budget — the copy is a few loads and stores, the graph is not.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-reconciling-a-128-sample-audioworklet-with-a-480-sample-ml-hop&quot;&gt;Worked Numerical Example: Reconciling a 128-Sample AudioWorklet with a 480-Sample ML Hop&lt;/h3&gt;

&lt;p&gt;At \(f_s = 48{,}000	ext{ Hz}\), trace how samples accumulate across consecutive &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; callbacks (128 samples = \(2.667	ext{ ms}\) each) feeding a 480-sample (10 ms) denoiser:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Callback #&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Elapsed Time&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Samples Pushed&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Buffered Samples Before ML&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;ML Hop Triggered (480)?&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Remaining Samples&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(2.67	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;+128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;128&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(5.33	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;+128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;256&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;256&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;3&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(8.00	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;+128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;384&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;384&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;4&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(10.67	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;+128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;512&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;YES (-480)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;32&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;5&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(13.33	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;+128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;160&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;160&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;6&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(16.00	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;+128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;288&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;288&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;7&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(18.67	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;+128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;416&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;416&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;8&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(21.33	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;+128&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;544&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;YES (-480)&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;64&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Look at the crucial systems insight revealed by this table:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Because \(128 
mid 480\), inference fires on callbacks #4, #8, #12, #15 (since \(\mathrm{lcm}(128, 480) = 1920\) samples = 15 callbacks = 4 ML hops = 40 ms!).&lt;/li&gt;
  &lt;li&gt;On callback #4, if inference runs &lt;strong&gt;inline&lt;/strong&gt; inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt;, it must finish in &lt;strong&gt;under 2.67 ms&lt;/strong&gt; (not 10 ms!), otherwise callback #4 overruns! That is why offloading to a Worker + ring buffer smooths the bursty 10 ms compute across all 4 callbacks!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;explanation-four-rules-for-glitch-free-audioworklet-engineering&quot;&gt;Explanation: Four Rules for Glitch-Free AudioWorklet Engineering&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Zero allocations inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt;:&lt;/strong&gt; Create all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Float32Array&lt;/code&gt; scratch buffers, FFT workspaces, and ring buffers once during initialization so JavaScript’s garbage collector stays asleep during calls.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Never confuse hop deadline (10 ms) with callback deadline (2.67 ms):&lt;/strong&gt; Running a 3.5 ms ML inference synchronously inside a 2.67 ms &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorklet&lt;/code&gt; callback guarantees underruns even though \(\mathrm{RTF} = 0.35\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Handle silence and bypass cleanly:&lt;/strong&gt; Always return &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt; while the node is active, and implement a zero-glitch bypass toggle that preserves latency alignment or crossfades smoothly.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Watch sample-rate mismatches:&lt;/strong&gt; Always read the runtime &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt; global inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletGlobalScope&lt;/code&gt; (some Bluetooth headsets force 16 kHz or 44.1 kHz instead of 48 kHz!).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; At \(44{,}100	ext{ Hz}\), how many milliseconds long is a 128-sample Web Audio render quantum?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Deadline.&lt;/strong&gt; 256-sample quantum, 48 kHz. How many milliseconds do you have? At 44.1 kHz?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gather.&lt;/strong&gt; You need 480 samples and each &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; gives 128. After how many callbacks do you first hold a full hop, and how many samples are left over?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Suppression message.&lt;/strong&gt; Draft the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;postMessage&lt;/code&gt; payload that sets suppression to 40 on a processor that exposes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; in the range 0–100. What happens if you apply it halfway through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;output.set&lt;/code&gt;?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Failure.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt; occasionally takes 15 ms while the quantum is 2.67 ms. What does the user hear, and what should the next callback do?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(256/48000\approx 5.33\) ms. \(256/44100\approx 5.80\) ms. Both are still too small for a cold ONNX session, and 5.33 ms is half of a 10 ms hop, so one quantum is still not a hop.&lt;/li&gt;
  &lt;li&gt;Four callbacks hold \(4\times 128=512\) samples. The hop consumes 480 and &lt;strong&gt;32&lt;/strong&gt; remain in the input ring. Three callbacks hold only 384.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{type: &quot;setSuppressionLevel&quot;, value: 40}&lt;/code&gt; handled in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onmessage&lt;/code&gt;, stored in a field, applied on the next hop boundary. Applying it mid-copy makes the two halves of one quantum use different gains and clicks.&lt;/li&gt;
  &lt;li&gt;The device underruns: a click, a repeat, or a short silence, depending on the browser. The recovery callback should take the bypass path (copy) or play the samples already in the output ring, not block until inference catches up.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;MDN, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;AudioWorklet&lt;/a&gt; and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletProcessor.process&lt;/code&gt; reference.&lt;/li&gt;
  &lt;li&gt;Lesson 05-01 for RTF and the 10 ms hop budget; lesson 05-03 for the ring that absorbs the 3.75 quanta.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt; for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; as a product surface, not as this lesson’s code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=g1L4O1smMC0&quot;&gt;AudioWorklet :: What, Why, and How - Hongchan Choi&lt;/a&gt; — WebAudio PDX, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Hongchan Choi on why the audio thread cannot wait on the main thread. Watch addModule, the processor, and the callback.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, English. The Chrome half shows AudioWorklet plus WebAssembly on the same callback, with measured round-trip latency.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>05-01 RTF and device budgets</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter05/05_01_rtf_budgets/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter05/05_01_rtf_budgets</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;Real-time factor (RTF)&lt;/strong&gt; is wall-clock time divided by the duration of the audio you just processed. If a 10 ms hop takes 12 ms, the callback misses and the listener hears a click, whatever the model’s PESQ was. This lesson defines RTF, shows why the mean hides the miss, and puts published DeepFilterNet laptop numbers next to an AudioWorklet quantum so they stop being used as phone budgets.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;RTF as wall time over audio time, drawn against a short AudioWorklet callback&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. RTF \(= T_{\mathrm{wall}}/T_{\mathrm{audio}}\). The picture’s short block is the render quantum, often 128 samples. At 48 kHz that block lasts \(128/48000\approx 2.67\) ms. A DeepFilterNet hop is 10 ms of audio and does not have to finish inside one quantum, but the p95 of hop time must stay under 10 ms or the output ring underruns (lesson 05-03).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A rookie real-time audio engineer benchmarks a new denoiser on 60 seconds of recorded audio, watches it finish in 42 seconds, and celebrates: &lt;em&gt;“RTF is 0.70—it’s faster than real time, ship it!”&lt;/em&gt; Two hours later, live users report ugly clicks and metallic dropouts every few seconds. What went wrong? &lt;strong&gt;Average RTF hides tail latency!&lt;/strong&gt; A laptop running a browser video call has garbage-collection pauses, OS scheduler hiccups, and thermal throttling—if even 1% of 10 ms audio frames take 11.2 ms to compute, the audio buffer starves and glitches audibly.&lt;/p&gt;

&lt;p&gt;This lecture makes &lt;strong&gt;Real-Time Factor (RTF)&lt;/strong&gt; and &lt;strong&gt;device compute budgets&lt;/strong&gt; mathematically concrete: how to measure mean vs. p95/p99 frame latency, why real-time audio demands massive headroom, and how to budget CPU across the entire call pipeline.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-hard-real-time-deadlines-vs-average-throughput&quot;&gt;Key ideas: Hard Real-Time Deadlines vs. Average Throughput&lt;/h2&gt;

&lt;p&gt;Real-time audio obeys strict deadlines that behave completely differently from batch ML throughput:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Real-Time Factor (RTF):&lt;/strong&gt; Defined as \(\mathrm{RTF} = rac{T_{	ext{compute}}}{T_{	ext{audio}}}\). Mathematically, \(\mathrm{RTF} &amp;lt; 1.0\) is necessary to keep up &lt;em&gt;on average&lt;/em&gt;, but in interactive systems you need \(\mathrm{RTF}_{	ext{mean}} \le 0.25\) and &lt;strong&gt;\(\mathrm{RTF}_{p99} \le 0.50\)&lt;/strong&gt; to survive OS jitter and background workloads.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tail Latency (p95 / p99 / p99.9):&lt;/strong&gt; At 100 frames per second (10 ms hop), a 10-minute call processes &lt;strong&gt;60,000 frames&lt;/strong&gt;. Even a 0.1% deadline miss rate produces &lt;strong&gt;60 audible clicks&lt;/strong&gt; during one meeting!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thermal Throttling &amp;amp; Asymmetric Cores:&lt;/strong&gt; Mobile phones and thin laptops drop CPU clock speeds by 30–50% after 2–3 minutes of sustained load, and may schedule background audio workers onto low-power efficiency cores.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;End-to-End Call Budget:&lt;/strong&gt; Noise suppression does &lt;em&gt;not&lt;/em&gt; own the CPU alone—it shares the machine with video encoding (VP9/AV1), acoustic echo cancellation (AEC), Opus encoding, and the browser UI.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will compute RTF from a list of per-frame times, including the exact mean and p95 for the list in the mini-lab; separate that number from algorithmic latency; and set a budget that distinguishes a notebook Core i5, a browser audio thread, and a phone you have not measured.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — A mean RTF of 0.43 that still misses the deadline.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Definition, warm-up, percentiles.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — 2.67 ms quantum, 10 ms hop, published 0.04 and 0.19.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Cold start versus steady state.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;definition&quot;&gt;Definition&lt;/h3&gt;

\[\mathrm{RTF}=\frac{T_{\mathrm{wall}}(\text{process }D\text{ seconds of audio})}{D}.\]

&lt;p&gt;\(\mathrm{RTF}&amp;lt;1\) is necessary on &lt;strong&gt;that&lt;/strong&gt; machine, &lt;strong&gt;that&lt;/strong&gt; build, &lt;strong&gt;that&lt;/strong&gt; thread count. It is not sufficient: the operating system can preempt you, a shared core can steal the tail, and the audio device will not wait. For a hop of \(H\) seconds the audio thread’s budget for everything — STFT, network, copy — is about \(H\), not “\(H\) for the net plus free time for the rest.” If the net alone takes \(0.7H\), 30% remains for the FFT and the ring-buffer copies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algorithmic latency is not RTF.&lt;/strong&gt; DeepFilterNet2 and the 2023 demo state &lt;strong&gt;40 ms&lt;/strong&gt; of delay for a 20 ms window, a 10 ms hop, and two frames of look-ahead (arXiv:2205.05474, arXiv:2305.08227). That delay is still there when RTF is 0.04. Users wait 40 ms because the filter looked ahead, not because the CPU was slow.&lt;/p&gt;

&lt;h3 id=&quot;percentiles-because-the-ear-hears-the-tail&quot;&gt;Percentiles, because the ear hears the tail&lt;/h3&gt;

&lt;p&gt;Take ten hop times in milliseconds,&lt;/p&gt;

\[[2.0,\;3.0,\;2.5,\;4.0,\;2.2,\;8.0,\;3.1,\;2.8,\;3.4,\;12.0],\]

&lt;p&gt;and a hop of 10 ms. The mean is \(43.0/10=4.3\) ms, so mean RTF is \(4.3/10=0.43\). Sorted, the list is \([2.0, 2.2, 2.5, 2.8, 3.0, 3.1, 3.4, 4.0, 8.0, 12.0]\). NumPy’s linear percentile at 95 lands at index \(9\times 0.95=8.55\), which interpolates between 8.0 and 12.0:&lt;/p&gt;

\[8.0+0.55\times(12.0-8.0)=10.2\text{ ms}.\]

&lt;p&gt;p95 RTF is \(10.2/10=1.02\). One interpretation a manager likes (0.43, “lots of headroom”) and one the device hears (a hop that does not finish before the next 10 ms of audio is due). Report p50, p95, and the maximum in a sliding window. A mean of 0.35 with a p99 above 1 clicks about once per hundred hops — every second, at a 10 ms hop.&lt;/p&gt;

&lt;p&gt;Measure like this:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Warm up. Run on the order of 50 hops before you append a sample, so JIT, the ONNX Runtime arena, and the cache are hot. The first hop is often an allocator spike; report it as cold start, not as RTF.&lt;/li&gt;
  &lt;li&gt;Pin threads. One thread for any WASM comparison. If native ONNX Runtime uses intra-op threads, write the number down; those threads steal the core the audio callback needs.&lt;/li&gt;
  &lt;li&gt;Time only &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process&lt;/code&gt;. Do not include the disk read of the wav, and do not include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session&lt;/code&gt; creation.&lt;/li&gt;
  &lt;li&gt;Match the chassis. A phone under thermal throttle is not a cold laptop. DeepFilterNet2’s &lt;strong&gt;RTF 0.04&lt;/strong&gt; and the earlier row’s &lt;strong&gt;RTF 0.11&lt;/strong&gt; are notebook Core i5-8250U numbers at about 0.35 GMAC. The 2023 demo’s tract loop reports &lt;strong&gt;RTF 0.19&lt;/strong&gt; on one thread of an i5-8250U. None of those three figures is a phone RTF.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;browser-versus-native-in-milliseconds&quot;&gt;Browser versus native, in milliseconds&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Target&lt;/th&gt;
      &lt;th&gt;Deadline you can compute&lt;/th&gt;
      &lt;th&gt;What “good” means&lt;/th&gt;
      &lt;th&gt;Trap&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;AudioWorklet render quantum&lt;/td&gt;
      &lt;td&gt;128 samples at 48 kHz: \(128/48000=2.\overline{6}\) ms, about &lt;strong&gt;2.67 ms&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Do almost no work here; gather quanta into a hop&lt;/td&gt;
      &lt;td&gt;Running the 10 ms DF hop inside one quantum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DF-style hop&lt;/td&gt;
      &lt;td&gt;480 samples, &lt;strong&gt;10 ms&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;p95 wall time \(\ll 10\) ms on the target&lt;/td&gt;
      &lt;td&gt;Quoting mean RTF&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Native 10 ms callback&lt;/td&gt;
      &lt;td&gt;10 ms, shared with AEC&lt;/td&gt;
      &lt;td&gt;p95 RTF under about 0.5 if AEC still has to run&lt;/td&gt;
      &lt;td&gt;Giving the whole 10 ms to NS&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ultra-light DSP&lt;/td&gt;
      &lt;td&gt;1–4 ms class&lt;/td&gt;
      &lt;td&gt;A small GRU / band model (04-05, 04-06)&lt;/td&gt;
      &lt;td&gt;Loading DF3 weights&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The quantum length is browser-dependent. Measure &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inputs[0][0].length&lt;/code&gt; (lesson 05-02). The 128-sample figure is the common case, not a spec guarantee.&lt;/p&gt;

&lt;h3 id=&quot;cold-start-is-a-different-timer&quot;&gt;Cold start is a different timer&lt;/h3&gt;

&lt;p&gt;Weight download, WASM compile, and ONNX Runtime session creation can take seconds. Do them before the call is audible. The first steady-state hop may still allocate. Exclude it from the percentile or report it on its own line. Field logs that help: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frames_total&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frames_late&lt;/code&gt; (wall time \(&amp;gt; H\)), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf_p95&lt;/code&gt; over a 1 s window, device model, and a thermal flag if the platform has one. Alert when &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frames_late / frames_total&lt;/code&gt; leaves the noise floor. Do not upload raw audio to make that graph.&lt;/p&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Timing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read()&lt;/code&gt; of the wav inside the hop loop.&lt;/li&gt;
  &lt;li&gt;Letting a multi-threaded runtime share the audio core, then blaming the model.&lt;/li&gt;
  &lt;li&gt;Publishing a GPU RTF for a CPU ship vehicle.&lt;/li&gt;
  &lt;li&gt;Ignoring battery-saver clocks and thermal throttling after twenty minutes.&lt;/li&gt;
  &lt;li&gt;Writing “latency 40 ms, so RTF is 0.04.” Those numbers came from different measurements and different questions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; From the hard-coded hop times above, print mean RTF and p95 RTF. The expected values are exact for NumPy’s linear percentile.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
import numpy as np
times_ms = np.array([2.0, 3.0, 2.5, 4.0, 2.2, 8.0, 3.1, 2.8, 3.4, 12.0])
hop_ms = 10.0
mean_ms = float(times_ms.mean())
p95_ms = float(np.percentile(times_ms, 95))  # linear, index (n-1)*0.95
print(f&quot;mean_ms={mean_ms:.1f}&quot;)
print(f&quot;p95_ms={p95_ms:.1f}&quot;)
print(f&quot;rtf_mean={mean_ms/hop_ms:.2f}&quot;)
print(f&quot;rtf_p95={p95_ms/hop_ms:.2f}&quot;)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mean_ms=4.3&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p95_ms=10.2&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf_mean=0.43&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf_p95=1.02&lt;/code&gt;. The mean says the hop is fine. The p95 says it is not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;. Using a percentile implementation that picks 12.0 or 8.0 without interpolating, then “failing” a correct 10.2. Dividing by the 20 ms window instead of the 10 ms hop (both RTFs halve). Dropping the 12 ms sample as an outlier you cannot hear. Comparing this toy list with DeepFilterNet2’s published 0.04.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-why-mathrmrtf_-extmean--035-can-still-glitch-a-10-minute-call&quot;&gt;Worked Numerical Example: Why \(\mathrm{RTF}_{	ext{mean}} = 0.35\) Can Still Glitch a 10-Minute Call&lt;/h3&gt;

&lt;p&gt;Suppose our streaming denoiser runs on a \(T_{	ext{hop}} = 10.0	ext{ ms}\) hop (100 frames/s). Benchmark 10,000 consecutive frames on a mid-range laptop during a video call:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Percentile&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Frame Compute Time \(T_{	ext{compute}}\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Instantaneous \(\mathrm{RTF} = T_{	ext{compute}} / 10	ext{ ms}\)&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Meets 10 ms Deadline?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Mean&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(3.5	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.35\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Yes (looks safe!)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;p95&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(6.8	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(0.68\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Yes (getting tight)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;p99&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(11.2	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1.12\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;MISS! (+1.2 ms late \(o\) underrun!)&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;p99.9&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(18.5	ext{ ms}\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;\(1.85\)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Severe dropout!&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Calculate the real-world impact on a &lt;strong&gt;10-minute call&lt;/strong&gt; (\(600	ext{ s} 	imes 100	ext{ frames/s} = 60{,}000\) frames):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Missing the deadline on 1% of frames (p99 &amp;gt; 10 ms) means up to &lt;strong&gt;600 late frames&lt;/strong&gt;—an audible glitch every single second unless absorbed by extra buffering (which adds painful latency)!&lt;/li&gt;
  &lt;li&gt;If we optimize/quantize the model by 2.5× so p99 drops from \(11.2	ext{ ms}\) to \(4.5	ext{ ms}\) (\(\mathrm{RTF}_{p99} = 0.45\)), we recover &lt;strong&gt;5.5 ms of safety margin&lt;/strong&gt; per frame!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;explanation-four-rules-for-honest-real-time-audio-benchmarking&quot;&gt;Explanation: Four Rules for Honest Real-Time Audio Benchmarking&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always benchmark per-frame histograms, never just total file runtime:&lt;/strong&gt; Total runtime divides out spikes; p99 and max frame time reveal the glitches users actually hear.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warm up and soak-test for 5+ minutes:&lt;/strong&gt; Cold runs miss JIT/WASM warmup, while 10-second runs miss CPU thermal throttling.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Measure under realistic contention:&lt;/strong&gt; Run your denoiser while a 720p WebRTC video call is active—an idle laptop gives wildly optimistic RTF numbers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Budget for the worst target device, not your M-series workstation:&lt;/strong&gt; A model at \(\mathrm{RTF}=0.08\) on a flagship desktop can easily hit \(\mathrm{RTF}=0.95\) on a 5-year-old Chromebook.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; A denoiser uses a 20 ms hop (50 frames/s). On your target device, the p99 frame compute time is \(8.0	ext{ ms}\). What is \(\mathrm{RTF}_{p99}\), and how many milliseconds of headroom remain before a deadline miss?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Headroom.&lt;/strong&gt; Hop 10 ms, p95 process time 6 ms. What are p95 RTF and the remaining fraction of the hop?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quantum.&lt;/strong&gt; How many 128-sample quanta fit in a 480-sample hop at 48 kHz? Why is the answer not an integer a scheduler can rely on?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Which number.&lt;/strong&gt; A colleague pastes “RTF 0.04” into a phone test plan. Which paper, which CPU, and what do you ask them to remeasure?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Incident.&lt;/strong&gt; Crackles start after 20 minutes on a laptop that idled at RTF 0.3. List four mechanisms that move p95 without changing the ONNX graph.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;RTF \(=6/10=0.60\). Remaining fraction \(=(10-6)/10=0.40\) (4 ms for FFT, copies, and the OS).&lt;/li&gt;
  &lt;li&gt;\(480/128=3.75\). Three quanta are 384 samples, four are 512. You gather with a ring buffer; you do not assume four callbacks per hop.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet2, arXiv:2205.05474, notebook Core i5-8250U, the simplified-model row. Remeasure p95 on the phone, one thread, warm, for at least a few thousand hops. The 0.19 figure (arXiv:2305.08227, tract, same CPU family) is a different binary.&lt;/li&gt;
  &lt;li&gt;Thermal clock drop, a second thread (AEC, GC, a log flush), cache eviction after other tabs allocate, and a state path that gets slower when a buffer grows. The graph file did not change; \(T_{\mathrm{wall}}\) did.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter et al., &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt;, Table of RTF 0.11 versus 0.04 on a Core i5-8250U.&lt;/li&gt;
  &lt;li&gt;Schröter et al., &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt;, single-thread RTF 0.19 for the published real-time loop.&lt;/li&gt;
  &lt;li&gt;MDN, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet&quot;&gt;AudioWorklet&lt;/a&gt;, for the rendering thread the quantum runs on.&lt;/li&gt;
  &lt;li&gt;ONNX Runtime performance notes on threading and session creation, as a method, not as a promised RTF.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch model cost against call quality. Real-time factor is that cost divided by the audio duration, and the mean is the number that hides a miss.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. The stated real-time factor on a notebook CPU is a single point on the budget this lesson wants on the target device.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, English. Callback deadlines on Android and Chrome are the wall-clock side of an RTF budget.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-06 RNNoise as a teaching bridge</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_06_rnnoise_bridge/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_06_rnnoise_bridge</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;RNNoise&lt;/strong&gt; (Jean-Marc Valin, arXiv:1709.08243; &lt;a href=&quot;https://github.com/xiph/rnnoise&quot;&gt;xiph/rnnoise&lt;/a&gt;) is a Bark-band front-end, a pitch comb, and a small GRU that emits 22 gains. It does not match the DeepFilterNet3 Voicebank+Demand row (PESQ 3.17 in arXiv:2305.08227). It teaches the same shape — coarse bands plus a harmonic stage — with numbers you can check by hand.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;DeepFilterNet ERB path, used here as the contrast to RNNoise’s 22 Bark bands and GRU gains&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. DeepFilterNet’s picture: 32 ERB gains, then a 5-tap complex filter on the low STFT bins. RNNoise is the contrast, not a redraw of this figure: 22 Bark-scale bands, a GRU that predicts those band gains, and a pitch comb between harmonics. Both are hybrid. The bands, the second stage, and the net size differ.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In 2017, Jean-Marc Valin—co-creator of the Opus audio codec—published &lt;strong&gt;RNNoise&lt;/strong&gt;, a tiny C library that stunned the speech community: in under &lt;strong&gt;100 kilobytes of weights&lt;/strong&gt; and running effortlessly on a Raspberry Pi, it stripped away fan hum, street traffic, and keyboard clatter in real time. RNNoise didn’t win by throwing billions of parameters at raw audio; it won by pairing &lt;strong&gt;classical psychoacoustics (Bark/Opus critical bands + pitch comb filtering)&lt;/strong&gt; with &lt;strong&gt;three compact GRU layers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This lecture uses RNNoise as a conceptual bridge between traditional signal processing and modern neural speech enhancement (such as DeepFilterNet), showing &lt;em&gt;exactly&lt;/em&gt; why domain-informed feature compression unlocks extreme efficiency—and where band-level gain masks hit their ceiling.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-the-hybrid-dsp--neural-philosophy-of-rnnoise&quot;&gt;Key ideas: The Hybrid DSP + Neural Philosophy of RNNoise&lt;/h2&gt;

&lt;p&gt;Four classical DSP and ML ideas fuse together inside RNNoise:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Perceptual Critical Bands (Bark / Opus Scale):&lt;/strong&gt; Human hearing resolves fine frequency differences below 1 kHz but groups high frequencies into wide logarithmic bands. Collapsing 481 linear STFT bins (at 48 kHz) into &lt;strong&gt;22 Bark bands&lt;/strong&gt; slashes input/output dimensionality by over &lt;strong&gt;21×&lt;/strong&gt;!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pitch Comb Filtering for Voiced Speech:&lt;/strong&gt; Band-level gains cannot suppress noise &lt;em&gt;between&lt;/em&gt; the harmonic peaks of a vowel. RNNoise computes a classical pitch correlation and applies a lightweight comb filter to preserve harmonic structure while attenuating inter-harmonic noise.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Recurrent Gain Estimation (3 GRUs):&lt;/strong&gt; Three small GRU layers track temporal continuity (distinguishing steady air-conditioner noise from transient consonants) and output 22 band gains \(g_b \in [0, 1]\) plus a Voice Activity Detection (VAD) probability.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bridge to Modern Deep Filtering (DeepFilterNet):&lt;/strong&gt; Where RNNoise stops at real-valued band gains (leaving phase noisy at low SNR), modern successors keep the exact same hybrid ERB-band idea for the coarse envelope and add a lightweight complex &lt;strong&gt;deep filter&lt;/strong&gt; only on the lower frequency bins where speech harmonics live!&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will compute RNNoise’s band gain from the ideal ratio mask, list the 42 features and the 215-unit GRU stack from the paper, contrast that pipeline with DeepFilterNet’s 32 ERB bands and 5 complex taps, and name the systems lessons (frame API, smoothing, cache-sized weights) that transfer to an AudioWorklet even when the product ships DF3.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Listen to the contrast: band gains versus a complex multi-tap filter.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — 22 bands, the gain formula, the pitch comb.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — 42 features, GRU, loss exponent \(\gamma=1/2\), complexity.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — What to copy into a WASM port, and what not to expect on PESQ.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;frame-and-bands&quot;&gt;Frame and bands&lt;/h3&gt;

&lt;p&gt;RNNoise runs at 48 kHz on &lt;strong&gt;20 ms&lt;/strong&gt; windows with &lt;strong&gt;50% overlap&lt;/strong&gt; (hop 10 ms, 480 samples), the same framing DeepFilterNet uses. Analysis and synthesis use the Vorbis window&lt;/p&gt;

\[w(n)=\sin\left(\frac{\pi}{2}\sin^{2}\left(\frac{\pi n}{N}\right)\right),\]

&lt;p&gt;which satisfies the Princen–Bradley criterion, so constant-overlap-add of this window reconstructs a constant input. The spectrum is grouped into &lt;strong&gt;22 bands&lt;/strong&gt;: the Opus codec’s Bark approximation (Bark spacing at high frequency, and at least four DFT bins per band at low frequency), with triangular weights \(w_b(k)\) that sum to 1 across bands. Band energy is&lt;/p&gt;

\[E(b)=\sum_k w_b(k)\,|X(k)|^{2}.\]

&lt;p&gt;The network does not emit 481 bin masks. It emits one gain per band. The training target is the square root of the ideal ratio mask,&lt;/p&gt;

\[g_b=\sqrt{\frac{E_s(b)}{E_x(b)}},\]

&lt;p&gt;applied to bins by interpolating with the same triangles, \(r(k)=\sum_b w_b(k)\,\hat{g}_b\). Gains live in \([0,1]\). That bound is the reason a tiny net is stable: a mapping network that predicts raw magnitudes has no such box.&lt;/p&gt;

&lt;p&gt;DeepFilterNet’s envelope stage is the descendant of this idea with a different scale: &lt;strong&gt;32 ERB bands&lt;/strong&gt; and a real gain, not 22 Bark bands. The second stage is the break. RNNoise does not predict complex STFT taps. It runs a &lt;strong&gt;pitch comb&lt;/strong&gt;. If \(P(k)\) is the DFT of the signal delayed by the pitch period \(T\), the filter forms \(X(k)+\alpha_b P(k)\) and renormalizes each band’s energy. The coefficient is a heuristic of the pitch correlation \(p_b\) and the gain,&lt;/p&gt;

\[\alpha_b=\min\left(\sqrt{\frac{p_b^{2}(1-g_b^{2})}{(1-p_b^{2})g_b^{2}}},\,1\right),\]

&lt;p&gt;with the boundary rules \(\alpha_b=1\) when \(p_b\ge g_b\), and \(\alpha_b=0\) when \(g_b=1\) or \(p_b=0\). DeepFilterNet’s 5-tap complex sum can build a similar harmonic reinforcement inside the net, at a much higher MAC cost, and only up to about 5 kHz. RNNoise’s comb is DSP, cheap, and only as good as the pitch estimate.&lt;/p&gt;

&lt;h3 id=&quot;features-and-the-gru&quot;&gt;Features and the GRU&lt;/h3&gt;

&lt;p&gt;The 42 inputs are fixed by the paper: 22 Bark cepstral coefficients, first and second derivatives of the first 6 (12 more), 6 DCT coefficients of the pitch correlation, the pitch period, and one non-stationarity feature. \(22+12+6+1+1=42.\) There is no cepstral mean normalization, so absolute level is visible. Mic response is trained in with a random second-order filter whose coefficients lie in \([-3/8,3/8]\).&lt;/p&gt;

&lt;p&gt;The net has &lt;strong&gt;215 units&lt;/strong&gt; and &lt;strong&gt;four hidden layers&lt;/strong&gt;, the largest with 96 units. Valin reports that a GRU slightly beats an LSTM here and is simpler. A voice-activity output adds 24 weights and gives one GRU a speech-versus-noise job during training. The gain loss is&lt;/p&gt;

\[L(g_b,\hat{g}_b)=\left(g_b^{\gamma}-\hat{g}_b^{\gamma}\right)^{2},\qquad \gamma=\tfrac{1}{2},\]

&lt;p&gt;not binary cross-entropy. \(\gamma\to 0\) would approach a log-energy error and over-suppress; \(\gamma=1/2\) is the paper’s operating point. Bands with no speech and no noise are marked undefined and dropped from the loss, which is how silence and low-passed audio avoid teaching the net to output 0.&lt;/p&gt;

&lt;p&gt;Gain smoothing limits how fast a band may decay,&lt;/p&gt;

\[\tilde{g}_b=\max\left(\lambda \tilde{g}_b^{(\mathrm{prev})},\,\hat{g}_b\right),\qquad \lambda=0.6,\]

&lt;p&gt;and the paper equates \(\lambda=0.6\) at a 10 ms hop with a reverberation time of about &lt;strong&gt;135 ms&lt;/strong&gt;. A smaller \(\lambda\) sounds dry; \(\lambda=1\) never releases. This one-pole floor is the anti-musical-noise trick Chapter 03 obtained from a spectral floor.&lt;/p&gt;

&lt;h3 id=&quot;complexity-you-can-put-next-to-deepfilternet&quot;&gt;Complexity you can put next to DeepFilterNet&lt;/h3&gt;

&lt;p&gt;The net has &lt;strong&gt;87,503&lt;/strong&gt; weights. At 8 bits they fit an L2 cache; the paper reports no quality loss from that quantization. A multiply-add counted as two flops is about 175,000 flops per frame, &lt;strong&gt;17.5 Mflop/s&lt;/strong&gt; at 100 frames per second. FFTs add about 7.5 Mflop/s and the 12 kHz pitch search about 10, near &lt;strong&gt;40 Mflop/s&lt;/strong&gt; total. The non-vectorized C code used about &lt;strong&gt;1.3%&lt;/strong&gt; of one Haswell i7-4800MQ core and about &lt;strong&gt;14%&lt;/strong&gt; of a 1.2 GHz Cortex-A53. DeepFilterNet’s published budget is ~0.35 GMAC/s, far above 40 Mflop/s. In the DF2 table, RNNoise is PESQ &lt;strong&gt;2.33&lt;/strong&gt;, RTF &lt;strong&gt;0.027&lt;/strong&gt;, against simplified DF2 at PESQ &lt;strong&gt;3.08&lt;/strong&gt;, RTF &lt;strong&gt;0.04&lt;/strong&gt;: similar laptop RTF, lower PESQ on that set.&lt;/p&gt;

&lt;p&gt;Training data is about 6 hours of speech and 4 hours of noise, expanded to 140 hours, resampled between 40 and 54 kHz. The ICASSP DeepFilterNet setup uses more than 750 hours of speech. A click or a language outside those 6 hours is a fair miss.&lt;/p&gt;

&lt;h3 id=&quot;what-transfers-to-the-product-path&quot;&gt;What transfers to the product path&lt;/h3&gt;

&lt;p&gt;The product path is still the DF3-oriented AudioWorklet (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;), not an RNNoise port. Copy the habits: one hop per call (480 samples; a 128-sample quantum still needs the ring in 05-03); precompute the window and the band weights; smooth gains (\(\lambda=0.6\) is RNNoise’s constant, not an untested DF3 default); quantize so weights stay in cache; keep the pitch comb if the net is this small. A GRU without the comb is a different algorithm.&lt;/p&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Dismissing the C code because PESQ is 2.33 on someone else’s table.&lt;/li&gt;
  &lt;li&gt;Expecting the default RNNoise model to match PESQ 3.17.&lt;/li&gt;
  &lt;li&gt;Porting the GRU and deleting the pitch filter.&lt;/li&gt;
  &lt;li&gt;Using only RNNoise as the baseline for a 48 kHz DF3 regression. Keep it as a floor (“we still beat this”), not as the target.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Check the feature count, the flop budget, and one smoothed-gain step with the paper’s constants. No audio file and no network.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
bfcc, deriv, pitch_dct, pitch_period, nonstat = 22, 12, 6, 1, 1
features = bfcc + deriv + pitch_dct + pitch_period + nonstat
weights = 87503
flops_per_frame = weights * 2  # multiply-add counted as two flops
mflops = flops_per_frame * 100 / 1e6  # 10 ms hop
g_hat, g_prev, lam = 0.3, 0.9, 0.6
g_smooth = max(lam * g_prev, g_hat)
print(features, flops_per_frame, round(mflops, 1), round(g_smooth, 2))
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;42 175006 17.5 0.54&lt;/code&gt;. The smoothed gain stays at \(0.6\times 0.9=0.54\) because the new estimate 0.3 would have dropped the band too fast. The paper’s “175,000” is the same quantity rounded (\(2\times 87503=175006\)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;. Forgetting the derivatives and reporting 22 features. Using a 20 ms hop and getting 8.8 Mflop/s. Setting \(\lambda=0\) and calling the result “smoothed.” Cloning RNNoise into the product and claiming DF3 parity.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-quantifying-rnnoises-21-dimensionality-compression&quot;&gt;Worked Numerical Example: Quantifying RNNoise’s 21× Dimensionality Compression&lt;/h3&gt;

&lt;p&gt;Compare a naive full-band 48 kHz STFT mask network against RNNoise’s Bark-band front-end (frame size \(N = 960\), hop \(H = 480 = 10	ext{ ms}\)):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Full-band linear STFT:&lt;/strong&gt; Number of unique frequency bins is \(rac{N}{2} + 1 = rac{960}{2} + 1 = 481\) bins. A single dense projection from 481 bins to a hidden layer of width 128 requires:
\(481 	imes 128 = 61{,}568	ext{ weights/MACs per frame}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;RNNoise Bark-band front-end:&lt;/strong&gt; Compresses 481 bins into &lt;strong&gt;22 Bark band energies&lt;/strong&gt; (plus pitch features \(\implies\) 42 total features). Projecting 42 features to a hidden layer of width 24–96 requires only:
\(42 	imes 96 = 4{,}032	ext{ weights/MACs per frame}\)
—a &lt;strong&gt;15.3× reduction&lt;/strong&gt; in the very first layer alone, and a &lt;strong&gt;\(481 / 22 pprox 21.9	imes\)&lt;/strong&gt; compression of the output gain head!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Look at how a Bark band gain works on one band (say Band 5 covering bins \(k=12\dots 16\)): if the GRU predicts gain \(g_5 = 0.25\) (\(-12.0	ext{ dB}\)), all 5 complex STFT bins in that band are scaled by \(0.25\), suppressing noise energy by \(g_5^2 = 0.0625\) (16× power reduction) while preserving original phase.&lt;/p&gt;

&lt;h3 id=&quot;explanation-what-rnnoise-teachesand-where-it-stops&quot;&gt;Explanation: What RNNoise Teaches—and Where It Stops&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Let physics handle what physics already solved:&lt;/strong&gt; FFTs, perceptual frequency warping, and pitch tracking are exact, zero-parameter operations; offloading them to DSP frees the neural network’s tiny capacity to focus purely on separating speech from non-stationary noise.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Real-valued band gains cannot fix phase distortion:&lt;/strong&gt; At high SNR (\(&amp;gt; 10	ext{ dB}\)), noisy phase barely matters. At low SNR (\(0	ext{ dB}\) or below), keeping noisy phase introduces audible roughness—motivating complex-valued masks and deep filtering.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Multi-task VAD stabilizes noise estimation:&lt;/strong&gt; Training the network to jointly predict speech presence (VAD) and band gains prevents the denoiser from aggressively chopping off quiet word endings.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Use RNNoise as your engineering baseline:&lt;/strong&gt; Before shipping a 5 MB model, measure whether a 100 KB RNNoise-style hybrid already meets your product’s quality bar on your target hardware.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; If RNNoise predicts a band gain of \(g_b = 0.10\) for a noise-only band, by how many decibels (\(20\log_{10} g_b\)) is the noise amplitude attenuated in that band?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Chain.&lt;/strong&gt; Draw PCM → 960-point window → 22 bands → 42 features → GRU → 22 gains → pitch comb → synthesis. Mark the 10 ms hop.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Alpha.&lt;/strong&gt; \(g_b=1\). What is \(\alpha_b\), and what does the comb do to a clean frame?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Smoothing.&lt;/strong&gt; Previous smoothed gain 0.8, new estimate 0.2, \(\lambda=0.6\). What is the output gain? How many hops of a sustained 0.2 estimate does it take to fall under 0.3?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;API.&lt;/strong&gt; Sketch &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process_frame(state, in[480], out[480])&lt;/code&gt; and list three fields inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state&lt;/code&gt; that must survive the call.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Hop 480 samples at 48 kHz. The GRU sees 42 inputs and emits 22 gains plus a VAD. The comb uses pitch period \(T\) and per-band \(\alpha_b\), then band energies are renormalized.&lt;/li&gt;
  &lt;li&gt;The formula is guarded: when \(g_b=1\), \(\alpha_b=0\). The comb is bypassed so clean speech is not pitch-filtered.&lt;/li&gt;
  &lt;li&gt;\(\max(0.6\times 0.8,\,0.2)=\max(0.48,\,0.2)=0.48\). Next hop \(\max(0.6\times 0.48,\,0.2)=0.288\), which is under 0.3. Two hops.&lt;/li&gt;
  &lt;li&gt;At least: GRU hidden state, the previous smoothed gains \(\tilde{g}_b\), and the OLA / pitch history. Zeroing any of them mid-stream clicks or opens a short noise burst (lesson 05-04).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Valin, “A Hybrid DSP/Deep Learning Approach to Real-Time Full-Band Speech Enhancement,” &lt;a href=&quot;https://arxiv.org/abs/1709.08243&quot;&gt;arXiv:1709.08243&lt;/a&gt;. Published as the 2018 IEEE MMSP paper cited by DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;Source and the 8-bit weights: &lt;a href=&quot;https://github.com/xiph/rnnoise&quot;&gt;github.com/xiph/rnnoise&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;SpeexDSP’s MMSE suppressor, the classical baseline in that paper.&lt;/li&gt;
  &lt;li&gt;Schröter et al., &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt;, for the 32-band ERB contrast and the PESQ 2.33 versus 3.08 table.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nsscrYdrGRE&quot;&gt;RNNoise, Neural Speech Enhancement, and the Browser&lt;/a&gt; — W3C, English. &lt;strong&gt;xem trước.&lt;/strong&gt; This is the teaching bridge: DSP features, a small GRU, and gains, running in a browser with almost no look-ahead.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. Watch the larger ERB-plus-filter model this lesson says RNNoise does not match on published scores.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. Use the product results as the scale RNNoise is not claiming to replace.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-05 Ultra-light streaming models</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_05_ultralight_streaming/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_05_ultralight_streaming</id>
   <content type="html">&lt;p&gt;Some products cannot spend DeepFilterNet2’s notebook budget. The names &lt;strong&gt;GTCRN&lt;/strong&gt;, &lt;strong&gt;FastEnhancer&lt;/strong&gt;, &lt;strong&gt;μNet&lt;/strong&gt;, and &lt;strong&gt;Fast-ULCNet&lt;/strong&gt; are a shortlist vocabulary for ultra-light streaming enhancers. This lesson does &lt;strong&gt;not&lt;/strong&gt; attach paper titles, years, or URLs to them. It teaches the measurement that decides the shortlist: MAC tables and wall-clock RTF come apart, and a GRU state that runs for an hour is a different bug from a slow hop.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;Real-time factor against an AudioWorklet quantum: wall time per audio block, not a MAC table&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. RTF is wall time divided by audio time. A 128-sample AudioWorklet quantum at 48 kHz lasts about 2.67 ms. An ultra-light model is one whose p95 wall time fits the hop you actually run, on the CPU you actually ship. GTCRN, FastEnhancer, μNet, and Fast-ULCNet are names only on this figure — no paper, year, or URL.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A noise-suppression model that scores a dazzling 21 dB SI-SDR on an offline benchmark can be completely unusable on a live Zoom or Mezon call. Why? Because offline models peek 500 milliseconds into the future and burn 40 GFLOPs per second on a desktop GPU—whereas a live call inside a laptop browser tab gives you roughly &lt;strong&gt;20–40 milliseconds of total algorithmic latency&lt;/strong&gt; and a tiny slice of a single CPU core!&lt;/p&gt;

&lt;p&gt;This lecture introduces the engineering art of &lt;strong&gt;ultra-light streaming speech enhancement models&lt;/strong&gt;: how strict causality, compact STFT front-ends, depthwise-separable convolutions, and small recurrent bottlenecks squeeze high-quality denoising into a few hundred thousand parameters running smoothly in real time.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-four-pillars-of-ultra-light-streaming-audio-models&quot;&gt;Key ideas: Four Pillars of Ultra-Light Streaming Audio Models&lt;/h2&gt;

&lt;p&gt;Designing a neural audio model that runs live on CPU/WASM rests on four interlocking constraints:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Strict Causality &amp;amp; Algorithmic Latency:&lt;/strong&gt; A streaming model cannot see future audio beyond a tiny budgeted lookahead \(L\). Total algorithmic latency equals the STFT synthesis window (or frame + overlap-add delay) plus any neural lookahead—typically capped below 30–40 ms so human conversation stays natural.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute Complexity (MACs/sec) vs. Parameter Count:&lt;/strong&gt; Parameter count governs &lt;em&gt;download size&lt;/em&gt; and &lt;em&gt;RAM&lt;/em&gt;, while &lt;strong&gt;multiply-accumulate operations per second (MACs/s)&lt;/strong&gt; govern CPU time. A small 1D convolution run 100 times per second can cost fewer MACs than a tiny dense layer applied to every frequency bin.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hybrid DSP + Neural Decomposition:&lt;/strong&gt; Instead of forcing a neural network to learn Fourier physics from raw waveforms, ultra-light architectures operate on STFT magnitudes or perceptually spaced filterbanks (ERB/Bark), letting the network predict smooth gain masks or small complex residuals.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Depthwise-Separable &amp;amp; Grouped Recurrence:&lt;/strong&gt; Replacing full 2D convolutions with depthwise + pointwise layers and using grouped GRUs cuts MACs by 5–10× with minimal loss in speech intelligibility.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will explain, with the DeepFilterNet2 table as the worked example, why GMAC and RTF can move in opposite directions; place the four ultra-light names on a selection checklist without inventing their results; and design a long-stream state check that does not depend on any of those papers.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Hearable DSP versus a laptop tab: two budgets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — The DF2 numbers as a MAC-versus-RTF proof.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — The four names, one line each, and what you still must measure.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — State drift over tens of minutes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, checklist, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;two-budgets-that-are-not-the-df2-table&quot;&gt;Two budgets that are not the DF2 table&lt;/h3&gt;

&lt;p&gt;DeepFilterNet2 (arXiv:2205.05474) reports RTF &lt;strong&gt;0.04&lt;/strong&gt; at &lt;strong&gt;0.356 GMAC&lt;/strong&gt; on a notebook Core i5-8250U, against the ICASSP row at 0.348 GMAC and RTF &lt;strong&gt;0.11&lt;/strong&gt;. The 2023 tract loop reports RTF &lt;strong&gt;0.19&lt;/strong&gt; on an i5-8250U. RNNoise, on that DF2 table, is about 0.06 M parameters, RTF 0.027, PESQ 2.33, against DF2’s PESQ 3.08. Those are the only compute numbers treated as printed here. A hearable or a phone is a different machine: laptop RTF is not phone RTF. Ultra-light graphs aim at much smaller memory and one short hop, and they usually land nearer PESQ 2.33 than 3.17. That is acceptable when the alternative is an underrun.&lt;/p&gt;

&lt;h3 id=&quot;why-a-mac-table-lies&quot;&gt;Why a MAC table lies&lt;/h3&gt;

&lt;p&gt;A multiply-accumulate count assumes every MAC has the same wall time. It does not.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Grouped or sub-band gathers jump around memory. The ALU waits on the cache. FastEnhancer is the name people cite when they make this argument; this page does not quote that paper.&lt;/li&gt;
  &lt;li&gt;A slightly larger dense GEMM, fused by the runtime, can finish sooner than a clever grouped conv the ONNX Runtime kernel does not vectorize.&lt;/li&gt;
  &lt;li&gt;Temporal kernels store a ring of past activations. DF2 cut kernels from \(2\times 3\) to \(1\times 3\) (input layer excepted) and the RTF fell from 0.11 to 0.04 with GMAC flat. That is the mechanism to copy into your own reading of any ultra-light graph: count bytes moved per hop, not only MACs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Measurement rule (Chapter 05).&lt;/strong&gt; Single thread, warm-up discarded, p50 and p95 of per-hop wall time, divided by the hop duration. Run it on the target device under the audio callback’s pacing. A paper MAC column is a hypothesis.&lt;/p&gt;

&lt;h3 id=&quot;the-four-names-and-only-the-names&quot;&gt;The four names, and only the names&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Role on this course’s shortlist&lt;/th&gt;
      &lt;th&gt;What this lesson will not say&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;GTCRN&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;A widely mentioned ultra-light grouped convolutional recurrent net&lt;/td&gt;
      &lt;td&gt;No title, year, URL, MAC, or MOS&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;FastEnhancer&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;A name attached to “speed on device,” including ONNX Runtime timing&lt;/td&gt;
      &lt;td&gt;No result numbers&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;μNet&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;A name attached to extreme low memory (DSP, hearable)&lt;/td&gt;
      &lt;td&gt;No result numbers&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Fast-ULCNet&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;A name attached to the ULCNet line and to long-stream RNN state&lt;/td&gt;
      &lt;td&gt;No result numbers&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Related strings you will see in the same cluster — ULCNet, UL-UNAS, AdaptCRN, CoFi-Lite, FSPEN — are optional vocabulary. They are not exam content and they are not given citations here.&lt;/p&gt;

&lt;h3 id=&quot;state-that-runs-longer-than-the-demo-clip&quot;&gt;State that runs longer than the demo clip&lt;/h3&gt;

&lt;p&gt;A 3-second clip hides GRU drift. At a 10 ms hop, 45 minutes is \(45\times 60\times 100=270\,000\) updates. Quantization, an unstable gate, or unseen silence walks the state off the training region. You hear a slow rise in musical noise or a slow ducking, not a click at \(t=0\). Fast-ULCNet is only the shortlist name associated with that discussion; this page states no cure from a paper. Tests you can run without a citation:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;During detected silence, blend the GRU state toward zero over a few hundred milliseconds, not in one hop. A hard zero is the click or noise burst of lesson 05-04.&lt;/li&gt;
  &lt;li&gt;Bound the state norm if the architecture allows a scale that does not change the gain.&lt;/li&gt;
  &lt;li&gt;Log gain histograms at minute 1 and minute 40. A shift at the same input level is drift.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;when-the-df3-path-still-wins&quot;&gt;When the DF3 path still wins&lt;/h3&gt;

&lt;p&gt;Prefer the DeepFilterNet3-associated model on a laptop browser when WASM SIMD holds the hop and a few megabytes of weights are acceptable. Prefer an ultra-light name on a DSP or a tiny CPU, where residual noise is allowed. A split is coherent: classical AEC plus a tiny residual suppressor on the device, DF3 in the browser. A 16 kHz weight file in a 48 kHz graph is not a light DF3; resample on purpose.&lt;/p&gt;

&lt;h2 id=&quot;shortlist-checklist&quot;&gt;Shortlist checklist&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Causal, and how many look-ahead frames?&lt;/li&gt;
  &lt;li&gt;16 kHz or 48 kHz, and where is the resampler?&lt;/li&gt;
  &lt;li&gt;p95 RTF on &lt;strong&gt;your&lt;/strong&gt; device, one thread, warm cache, callback pacing.&lt;/li&gt;
  &lt;li&gt;Weight bytes and cold-start time, separate from RTF.&lt;/li&gt;
  &lt;li&gt;A run of at least 30 minutes with a silence stretch.&lt;/li&gt;
  &lt;li&gt;License of the weights.&lt;/li&gt;
  &lt;li&gt;Every operator present in your ONNX Runtime or tract build.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Picking the winner from a MAC column.&lt;/li&gt;
  &lt;li&gt;Porting grouped convolutions the WASM runtime executes as scalar loops.&lt;/li&gt;
  &lt;li&gt;Skipping the 30-minute run.&lt;/li&gt;
  &lt;li&gt;Feeding 48 kHz PCM to a model whose STFT was trained at 16 kHz.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Reproduce the DF2 “GMAC flat, RTF not flat” comparison from published numbers, then apply the same ratio test to a fake ultra-light pair so you see what a decision looks like before any unnamed paper is involved.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
# Numbers from the DeepFilterNet2 paper&apos;s Voicebank table (notebook i5).
rows = [
    (&quot;DF ICASSP row&quot;, 0.348, 0.11),
    (&quot;DF2 simplified&quot;, 0.356, 0.04),
]
for name, gmac, rtf in rows:
    print(f&quot;{name}: gmac={gmac:.3f} rtf={rtf:.2f} rtf_per_gmac={rtf/gmac:.3f}&quot;)
# Hypothetical shortlist. These MACs are lab fiction, not paper results.
fake = [(&quot;modelA&quot;, 0.05, 0.30), (&quot;modelB&quot;, 0.08, 0.12)]
best = min(fake, key=lambda r: r[2])
print(&quot;lower_p95_rtf&quot;, best[0])
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DF ICASSP row: gmac=0.348 rtf=0.11 rtf_per_gmac=0.316&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DF2 simplified: gmac=0.356 rtf=0.04 rtf_per_gmac=0.112&lt;/code&gt;. Then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lower_p95_rtf modelB&lt;/code&gt;. Model B has more MACs and a lower RTF, which is the selection rule.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;. Treating the fake pair as GTCRN or FastEnhancer results. Quoting 0.04 as a phone RTF. Ranking on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf_per_gmac&lt;/code&gt; alone when one model’s p95, not its mean, misses the hop.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;worked-numerical-example-budgeting-latency-and-macssec-for-a-48-khz-streaming-denoiser&quot;&gt;Worked Numerical Example: Budgeting Latency and MACs/sec for a 48 kHz Streaming Denoiser&lt;/h3&gt;

&lt;p&gt;Suppose we design a causal STFT denoiser at sample rate \(f_s = 48{,}000	ext{ Hz}\) with window length \(N = 960\) samples, hop size \(H = 480\) samples (50% overlap), and \(L = 1\) frame of lookahead in the neural network:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Frame duration &amp;amp; frame rate:&lt;/strong&gt;
\(T_{	ext{win}} = rac{960}{48{,}000} = 20	ext{ ms}, \qquad T_{	ext{hop}} = rac{480}{48{,}000} = 10	ext{ ms} \implies 100	ext{ frames/s}.\)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Total algorithmic latency:&lt;/strong&gt;
\(T_{	ext{alg}} = T_{	ext{win}} + L \cdot T_{	ext{hop}} = 20	ext{ ms} + 1 	imes 10	ext{ ms} = 30	ext{ ms}\)
&lt;em&gt;(still well below the ~150 ms ITU-T G.114 one-way conversational comfort threshold, leaving room for network + jitter buffer!)&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compute rate:&lt;/strong&gt; Suppose each forward pass on one STFT frame costs \(1.5	ext{ MMACs}\) (1.5 million multiply-adds). At 100 frames/s:
\(ext{Compute rate} = 100 	imes 1.5	ext{ MMAC} = 150	ext{ MMAC/s} pprox 300	ext{ MFLOP/s}.\)
On a single browser WASM core sustaining ~3 GFLOP/s, the model consumes roughly \(300 / 3000 = 10\%\) of the frame budget (\(\mathrm{RTF} pprox 0.10\))!&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;explanation-four-rules-for-designing-real-time-streaming-models&quot;&gt;Explanation: Four Rules for Designing Real-Time Streaming Models&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Always separate &lt;em&gt;algorithmic&lt;/em&gt; latency from &lt;em&gt;compute&lt;/em&gt; latency:&lt;/strong&gt; Even on an infinitely fast CPU, a 20 ms STFT window plus 2 frames of lookahead (20 ms) still introduces 40 ms of unavoidable delay.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Halving the hop size doubles your CPU bill:&lt;/strong&gt; Dropping \(H\) from 10 ms to 5 ms cuts latency by 5 ms, but doubles the neural network frame rate from 100 to 200 calls per second!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Inspect activation memory, not just weight size:&lt;/strong&gt; A model with only 200 KB of weights can still stall CPU caches if intermediate feature maps explode across frequency bins.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Profile end-to-end (STFT + neural net + iSTFT):&lt;/strong&gt; On ultra-light models, FFTs, windowing, and data marshaling can easily account for 20–30% of total wall-clock time.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick check.&lt;/strong&gt; If we double the neural lookahead from \(L = 1\) frame to \(L = 3\) frames (keeping \(T_{	ext{win}} = 20	ext{ ms}\) and \(T_{	ext{hop}} = 10	ext{ ms}\)), what is the new algorithmic latency—and does the MACs/sec compute cost change?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Scenario.&lt;/strong&gt; For an on-ear DSP, a mid-range laptop in Chrome, and a Raspberry Pi class speakerphone, choose DF3 or “an ultra-light name” and give the budget reason in one sentence each.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Harness sketch.&lt;/strong&gt; Warm-up count, hop duration, and the percentile you will gate on. Why is the mean not the gate?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Drift.&lt;/strong&gt; 10 ms hop, 40 minutes. How many GRU updates is that? What do you compare at the start and at the end?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Names.&lt;/strong&gt; Write one sentence each for GTCRN, FastEnhancer, μNet, and Fast-ULCNet that contains no digit and no year.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;DSP: ultra-light, because the DF2 0.04 RTF was measured on a Core i5. Laptop Chrome: DF3, if WASM SIMD holds p95 inside the hop and the download size is acceptable. Pi-class board: the DF2 paper claims real-time on a Pi 4 for &lt;strong&gt;that&lt;/strong&gt; model; an ultra-light name is the fallback if your build’s p95 does not.&lt;/li&gt;
  &lt;li&gt;Drop the first 50 hops, hop = 10 ms = 0.01 s, gate on p95 (and watch p99). The mean hides the late frame that underruns. Chapter 05 computes this exactly.&lt;/li&gt;
  &lt;li&gt;\(40\times 60\times 100=240\,000\) updates. Compare band-gain histograms or the state norm on a repeated calibration clip, not the raw waveform of the whole call.&lt;/li&gt;
  &lt;li&gt;Use only the one-line roles in the table above. A digit means you invented a result.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter et al., DeepFilterNet2, &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt;, for the 0.11 versus 0.04 RTF rows. That is the MAC-versus-RTF example.&lt;/li&gt;
  &lt;li&gt;Schröter et al., Interspeech 2023, &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt;, for the RTF 0.19 tract-loop figure.&lt;/li&gt;
  &lt;li&gt;Valin, &lt;a href=&quot;https://arxiv.org/abs/1709.08243&quot;&gt;arXiv:1709.08243&lt;/a&gt;, as the tiny hybrid baseline (lesson 04-06).&lt;/li&gt;
  &lt;li&gt;Primary sources you open yourself for GTCRN, FastEnhancer, μNet, and Fast-ULCNet. None are linked here.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nsscrYdrGRE&quot;&gt;RNNoise, Neural Speech Enhancement, and the Browser&lt;/a&gt; — W3C, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch a suppressor small enough for a browser and a Raspberry Pi. That budget is the ultra-light streaming problem, without attaching papers to the shortlist names.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. The complexity-versus-quality plot is what an ultra-light model has to survive before the name on the shortlist matters.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nhTxJBgTywc&quot;&gt;Zoom on Web: getting connected with advanced web technology&lt;/a&gt; — Chrome for Developers, English. The SIMD section shows why a tiny model still needs a vectorized runtime if the hop is a few milliseconds.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-04 Successors survey: DPDFNet, DeepFilterGAN, HDF-Net</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_04_successors_survey/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_04_successors_survey</id>
   <content type="html">&lt;p&gt;DPDFNet, DeepFilterGAN, and HDF-Net are &lt;strong&gt;survey pointers only&lt;/strong&gt;. This lesson gives them no paper title, year, venue, or URL. If you have not opened the PDF, you do not have a bibliographic line. The hour is how to set a successor next to the ERB-plus-deep-filter skeleton, then decide whether a DF3 deployment should change.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;ERB-plus-deep-filter skeleton that successor names still have to beat on RTF and listening&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. DPDFNet, DeepFilterGAN, and HDF-Net are survey pointers only: names on a reading list, not checkpoints you can load from this page. Any of them still has to preserve a causal STFT hop, a bounded state, and an RTF under 1 on the target CPU. This lesson states no paper title, year, or URL for those three names.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will attach one sentence each to DPDFNet, DeepFilterGAN, and HDF-Net; refuse a title or year you did not copy from a PDF; and decide ship, watch, or ignore from RTF, ONNX coverage, and a listening failure you can reproduce.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Why a name is not a migration plan.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — The four-field card, filled only with what you can point at.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — What “dual-path,” “GAN stage,” and “hierarchical filter” would cost in an AudioWorklet.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Over-attenuation as a product bug, independent of any one paper.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab and citation hygiene.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;what-a-survey-lesson-is-allowed-to-claim&quot;&gt;What a survey lesson is allowed to claim&lt;/h3&gt;

&lt;p&gt;Lessons 04-02 and 04-03 quoted tables because those tables are in arXiv:2110.05588, arXiv:2205.05474, and arXiv:2305.08227. This lesson does not have that license. The course reading map uses three names:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;DPDFNet&lt;/strong&gt; — a successor people look up when long-context modeling and over-attenuation, on a DeepFilterNet2-style backbone, are the complaint.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;DeepFilterGAN&lt;/strong&gt; — a successor people look up when a predictive DeepFilterNet-style stage is followed by a generative stage that tries to put back speech the predictor removed.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;HDF-Net&lt;/strong&gt; — a successor people look up when deep filtering is split hierarchically across time and frequency instead of one filter head.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those sentences are the map, not abstracts. They do not authorize a parameter count, a PESQ delta, a figure, or a link. Optional nearby names, also without citations here, are pDeepFilterNet2 (speaker conditioning) and DFingerNet (noise-fingerprint conditioning). Personalization is out of scope unless the capstone says otherwise.&lt;/p&gt;

&lt;h3 id=&quot;the-four-field-card&quot;&gt;The four-field card&lt;/h3&gt;

&lt;p&gt;For each PDF you actually open, write four fields and nothing else:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Problem&lt;/strong&gt; the authors measured (over-attenuation, a missing harmonic, a latency number).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mechanism&lt;/strong&gt; with the block names printed in that PDF, not synonyms you prefer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Deployability:&lt;/strong&gt; parameter count if the PDF prints one, whether the graph is causal, whether ONNX or a real-time factor appears.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Action:&lt;/strong&gt; ignore, watch, or prototype. A prototype needs a hop size, a device, and a listening clip.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If field 3 is empty because the PDF never mentions streaming, the action is not “ship.” A leaderboard model with a bidirectional layer will not run inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;what-each-idea-would-cost-without-pretending-you-read-the-pdf&quot;&gt;What each idea would cost, without pretending you read the PDF&lt;/h3&gt;

&lt;p&gt;Keep this section in the conditional. It is an engineering translation of the &lt;strong&gt;names&lt;/strong&gt;, so you can budget a spike. It is not a summary of results.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;dual-path&lt;/strong&gt; block, the pattern the DPDFNet name points at, runs one sequence in time and one in frequency. On a 10 ms hop the time path is either a fixed GRU state or a wait for future hops. Four future hops are another 40 ms on top of DeepFilterNet2’s published 40 ms, so 80 ms of delay. That sum is not an RTF. Two GRUs can also double p95. Over-attenuation itself needs no paper: soft fricatives disappear. A loss that floors the gain is a hypothesis, not a quoted result.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;GAN regenerator&lt;/strong&gt;, the pattern the DeepFilterGAN name points at, is a second network on top of a predictive stage. Two ONNX sessions, or one fused graph, add MACs and a stage that is awkward to keep deterministic in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt;. Suppression on the npm surface is already an integer 0–100 via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. Turn it down before you add a GAN.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;hierarchical deep filter&lt;/strong&gt;, the pattern the HDF-Net name points at, still computes&lt;/p&gt;

\[\hat{S}(t,f)=\sum_{i} W_i(t,f)\,X(t-i+\ell,f),\]

&lt;p&gt;with more than one head. Five taps on 96 bins are already 480 complex multiplies per frame (04-02). A frequency-axis head can see neighboring bins; whether a given PDF’s head is causal is a question for that figure, not for this page.&lt;/p&gt;

&lt;h3 id=&quot;product-triage-against-the-df3-row-you-can-actually-cite&quot;&gt;Product triage against the DF3 row you can actually cite&lt;/h3&gt;

&lt;p&gt;The only DeepFilterNet3 metric row you may quote is Voicebank+Demand in arXiv:2305.08227: PESQ 3.17, CSIG 4.34, CBAK 3.61, COVL 3.77, STOI 0.944, next to DF2 at PESQ 3.08. RTFs you may quote are 0.04 (DF2, notebook i5) and 0.19 (the 2023 tract loop on an i5-8250U). A successor earns a spike only if your clips show a failure those checkpoints miss, and a causal graph can live in a 10 ms hop (a single 2.67 ms quantum is the wrong budget).&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Idea you may repeat&lt;/th&gt;
      &lt;th&gt;Ship from this lesson?&lt;/th&gt;
      &lt;th&gt;Why&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;DPDFNet&lt;/td&gt;
      &lt;td&gt;Dual-path context; over-attenuation is the theme to look up&lt;/td&gt;
      &lt;td&gt;No&lt;/td&gt;
      &lt;td&gt;No title, year, or URL here&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DeepFilterGAN&lt;/td&gt;
      &lt;td&gt;Predictive stage plus a generative stage&lt;/td&gt;
      &lt;td&gt;No&lt;/td&gt;
      &lt;td&gt;Second network, RTF and determinism unknown until you read&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;HDF-Net&lt;/td&gt;
      &lt;td&gt;Hierarchical deep filter&lt;/td&gt;
      &lt;td&gt;No&lt;/td&gt;
      &lt;td&gt;Same&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DeepFilterNet3 baseline&lt;/td&gt;
      &lt;td&gt;32 ERB + 5-tap filter, README-associated 2023 citation&lt;/td&gt;
      &lt;td&gt;Yes, as the course baseline&lt;/td&gt;
      &lt;td&gt;Numbers live in 04-03&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Spatial front-ends from Chapter 03 (GSC into a mono enhancer, IVA into a mono enhancer) are a different kind of “successor”: they change the microphone count. They are still survey-level hybrids, not a reason to drop DF3.&lt;/p&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Rewriting the ONNX graph after an abstract.&lt;/li&gt;
  &lt;li&gt;Typing a title, year, or arXiv id from memory for DPDFNet, DeepFilterGAN, or HDF-Net.&lt;/li&gt;
  &lt;li&gt;Assuming a GAN stage fits the same p95 as the predictor.&lt;/li&gt;
  &lt;li&gt;Importing a custom filter op that tract or ONNX Runtime WASM does not implement, then discovering it on the audio thread.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Build the four-field card with the fields you are &lt;strong&gt;not&lt;/strong&gt; allowed to invent left blank, and check that a string scan of your notes does not contain a made-up citation.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
names = [&quot;DPDFNet&quot;, &quot;DeepFilterGAN&quot;, &quot;HDF-Net&quot;]
# Fill only from a PDF you opened. Leave unknown fields as None.
cards = {
    name: {&quot;problem&quot;: None, &quot;mechanism&quot;: None, &quot;params&quot;: None,
           &quot;causal&quot;: None, &quot;url&quot;: None, &quot;year&quot;: None, &quot;title&quot;: None}
    for name in names
}
for name, card in cards.items():
    missing = [k for k, v in card.items() if v is None]
    print(f&quot;{name}: missing={missing}&quot;)
print(&quot;survey_pointers_only=True&quot;)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;. Each name prints &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;missing=[&apos;problem&apos;, &apos;mechanism&apos;, &apos;params&apos;, &apos;causal&apos;, &apos;url&apos;, &apos;year&apos;, &apos;title&apos;]&lt;/code&gt; until you replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;None&lt;/code&gt; from a PDF. The last line is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;survey_pointers_only=True&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;. Pasting a title or year from a search snippet you did not open. Filling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;params&lt;/code&gt; with a number that is not in the PDF. Treating a blank &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;causal&lt;/code&gt; field as “causal enough.” Linking a URL this lesson does not provide.&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Cards.&lt;/strong&gt; After you open each PDF yourself, fill the four fields. If you cannot open it, leave the card blank and say so.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Over-attenuation, no paper required.&lt;/strong&gt; Record ten seconds with soft fricatives (“see”, “fish”) at a comfortable level and at a low level, through a DF3 path at suppression 30 and at suppression 90. Write the listening difference in two sentences.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Delay budget.&lt;/strong&gt; A dual-path chunk waits 4 hops of 10 ms, and DeepFilterNet2’s published delay is already 40 ms. What is the sum, and is that sum an RTF?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Memo.&lt;/strong&gt; In 150 words, tell a tech lead to stay on the DF3 baseline or to schedule a reading spike. You may cite only arXiv:2110.05588, arXiv:2205.05474, and arXiv:2305.08227.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;A blank card scores higher than a fabricated title. Mechanism text must use the PDF’s nouns.&lt;/li&gt;
  &lt;li&gt;You are listening for deleted consonants and a “dry” or pumping tail, not for a MOS number. Suppression is 0–100 via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;, not a dB from the paper.&lt;/li&gt;
  &lt;li&gt;\(40+4\times 10=80\) ms algorithmic delay if the chunk is extra look-ahead. RTF is wall time over audio time and can be 0.2 or 1.4 independently of those 80 ms.&lt;/li&gt;
  &lt;li&gt;The defendable baseline is the 2023 citation’s DF3 row and the published 40 ms / RTF figures. A spike is a reading assignment plus one causal ONNX smoke test, not a rewrite.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Lessons 04-02 and 04-03, which cite &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt;, and &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;The PDFs you obtain yourself for DPDFNet, DeepFilterGAN, and HDF-Net. This page intentionally has no link for them.&lt;/li&gt;
  &lt;li&gt;Chapter 05 for the RTF and AudioWorklet constraints any successor still has to meet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the ERB-plus-deep-filter skeleton. The lesson sets successors next to this picture and does not treat the video as a source for their papers.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. The dataset, listening, and complexity sections are the comparison method. No named successor in the lesson has its own verified talk here.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-03 DeepFilterNet2 and DeepFilterNet3</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_03_deepfilternet2_3/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_03_deepfilternet2_3</id>
   <content type="html">&lt;p&gt;DeepFilterNet2 and DeepFilterNet3 keep the ERB-plus-deep-filter split and change the training loss, the amount of temporal buffering, a post-filter, and an SNR gate. This lesson only uses numbers printed in arXiv:2205.05474 and arXiv:2305.08227. It does not invent block names, and it does not claim the npm package matches those checkpoints bit for bit.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;Same ERB-plus-deep-filter skeleton across DeepFilterNet generations&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The skeleton stays: 32 ERB gains for the envelope, then a 5-tap complex filter on the low bins. Across versions the published changes are the loss and the data (multi-resolution STFT, DNS4, a post-filter), fewer temporal buffers inside the net, and an SNR gate that can skip a stage. Module names you have not read in the paper are not part of this caption.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will state what DeepFilterNet2 changed relative to the ICASSP 2022 model (runtime buffers, multi-resolution loss, post-filter, reported RTF), what the Interspeech 2023 paper adds as a local-SNR gate and a DeepFilterNet3 row on Voicebank+Demand, and how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; relates to that family without being a second source of truth for the weights.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Recap: 32 ERB bands, 5 taps, 20 ms / 10 ms, 40 ms delay.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — DF2: where the 0.04 RTF comes from, and where it does not.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — The 2023 gate and the DF3 row on the metric table.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — RIR mismatch, ONNX export, the npm surface.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;same-dna-different-checkpoints&quot;&gt;Same DNA, different checkpoints&lt;/h3&gt;

&lt;p&gt;All three generations target 48 kHz, a 20 ms window, 50% overlap, 32 ERB bands, and a 5-tap filter up to about 5 kHz, with two frames of look-ahead quoted as &lt;strong&gt;40 ms&lt;/strong&gt; of delay. Pin a weight file, not the word “DeepFilterNet.” A DF2 checkpoint in a DF3 config is a shape error or a timbre error.&lt;/p&gt;

&lt;h3 id=&quot;deepfilternet2--arxiv220505474&quot;&gt;DeepFilterNet2 — arXiv:2205.05474&lt;/h3&gt;

&lt;p&gt;DeepFilterNet2, “Towards Real-Time Speech Enhancement on Embedded Devices for Full-Band Audio” (IWAENC 2022, arXiv:2205.05474), keeps that STFT. The changes that move quality and speed are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Loss.&lt;/strong&gt; Warmup of 3 epochs, then cosine decay, updated every step. A multi-resolution spectral loss after the inverse STFT uses windows of 5, 10, 20, and 40 ms with compression \(c=0.3\). The ICASSP \(\alpha\) loss is dropped; a 5-tap filter can idle by setting the current real tap to 1 and the others to 0.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Data.&lt;/strong&gt; English DNS4, plus a distortion path: the target keeps less reverberation than the mixture, and clipped speech is reconstructed. That is a meeting-room mechanism, not a guarantee on your rooms.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fewer temporal buffers.&lt;/strong&gt; Time kernels shrink from \(2\times 3\) to \(1\times 3\) except a causal \(3\times 3\) at the input. The GRU hidden size is 256. Grouped linears become one matmul. Extra context is a ring of activations; on a small CPU that traffic dominates the MAC count.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Post-filter.&lt;/strong&gt; A sine warp on the ERB gains, \(G \leftarrow G\sin(\pi G/2)\), over-attenuates noisy bands. A second step mixes a strength \(\beta\). Do not invent a default \(\beta\); &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--pf&lt;/code&gt; enables the published post-filter.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Same CPU, different RTF.&lt;/strong&gt; On Voicebank+Demand, Core i5-8250U: the ICASSP row is 1.778 M parameters, 0.348 GMAC, RTF 0.11, PESQ 2.81. The simplified DF2 row is 2.306 M, 0.356 GMAC, &lt;strong&gt;RTF 0.04&lt;/strong&gt;, PESQ 3.08 (CSIG 4.30, CBAK 3.40, COVL 3.699, STOI 0.9429). GMAC is flat; RTF drops because the kernels and the GRU changed. The post-filter row stays at RTF 0.04 and PESQ &lt;strong&gt;3.03&lt;/strong&gt;. PESQ fell. Watching only PESQ will revert a change that was made for perception.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The abstract also calls this fast enough for a Raspberry Pi 4. That is still not a phone thermal result.&lt;/p&gt;

&lt;h3 id=&quot;the-2023-paper-and-deepfilternet3--arxiv230508227&quot;&gt;The 2023 paper and DeepFilterNet3 — arXiv:2305.08227&lt;/h3&gt;

&lt;p&gt;“DeepFilterNet: Perceptually Motivated Real-Time Speech Enhancement” (Interspeech 2023, arXiv:2305.08227) restates the framework and is the citation the project README associates with the &lt;strong&gt;DeepFilterNet3&lt;/strong&gt; model. Use that association. Do not invent a second DF3 title.&lt;/p&gt;

&lt;p&gt;The demo’s processing rules, which you can implement without new module names:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;48 kHz, 20 ms window, 10 ms hop, look-ahead of 2 frames, &lt;strong&gt;40 ms&lt;/strong&gt; algorithmic latency.&lt;/li&gt;
  &lt;li&gt;32 ERB gains for the envelope.&lt;/li&gt;
  &lt;li&gt;An \(N=5\) complex filter on the lowest &lt;strong&gt;96 bins&lt;/strong&gt; (4.8 kHz). Higher bins keep the ERB gain.&lt;/li&gt;
  &lt;li&gt;The encoder also predicts a local SNR \(\xi\in[-15,35]\) dB. If \(\xi&amp;lt;-10\) dB, both decoders are disabled and the frame is silent. If \(\xi&amp;gt;20\) dB, the deep-filter decoder is disabled. Otherwise both stages run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Speech just under −10 dB becomes digital silence. Speech above 20 dB never gets the harmonic stage, so a hum can remain between partials. The tract loop in that paper reports &lt;strong&gt;RTF 0.19&lt;/strong&gt; on one i5-8250U thread. DF2’s &lt;strong&gt;0.04&lt;/strong&gt; is a different binary. Do not average them, and do not call either a phone RTF.&lt;/p&gt;

&lt;p&gt;The Voicebank+Demand row labeled DeepFilterNet3 is PESQ 3.17, CSIG 4.34, CBAK 3.61, COVL 3.77, STOI 0.944, against DF2 at PESQ 3.08 and the original at 2.81. One test set.&lt;/p&gt;

&lt;h3 id=&quot;wrapper-onnx-rooms&quot;&gt;Wrapper, ONNX, rooms&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 (&lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt;) runs ONNX/WASM in an AudioWorklet: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, suppression 0–100 via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt;. Do not claim bit-exact agreement with the CLI or the paper table. A wrapper that changes hop, look-ahead, or sample rate is a different system.&lt;/p&gt;

&lt;p&gt;Export is PyTorch → ONNX → ONNX Runtime, WASM, or tract → AudioWorklet or a native callback. The GRU state must be a graph input and output. A dynamic axis that eats the whole file is an offline model. The first paper’s simulated RT60 stops at 1 s. Over-suppression in a real room is often that data gap. Listen (Chapter 08) before you grow the net.&lt;/p&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Loading DF2 weights with the DF3 gate thresholds, or the reverse.&lt;/li&gt;
  &lt;li&gt;Quoting PESQ 3.17 as “the product MOS.”&lt;/li&gt;
  &lt;li&gt;Treating RTF 0.04 or 0.19 on an i5 as the budget for a fanless laptop or a phone.&lt;/li&gt;
  &lt;li&gt;Enabling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--pf&lt;/code&gt;, watching PESQ drop from 3.08 to 3.03, and reverting a perceptual change you never listened to.&lt;/li&gt;
  &lt;li&gt;Assuming &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(100)&lt;/code&gt; reproduces the paper’s full attenuation. It is a product control, range 0–100, not a dB value from the paper.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Run the CLI twice if weights are available, once with the post-filter flag, and always compute the unitless sine warp on four gains so the lab works offline.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;deepFilter &lt;span class=&quot;nt&quot;&gt;--output-dir&lt;/span&gt; out/noisy/ noisy.wav
deepFilter &lt;span class=&quot;nt&quot;&gt;--pf&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--output-dir&lt;/span&gt; out/pf/ noisy.wav
python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
import numpy as np
G = np.array([0.0, 0.2, 0.5, 1.0])
Gp = G * np.sin(0.5 * np.pi * G)
np.set_printoptions(precision=6, suppress=True)
print(Gp)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;. With weights and a 48 kHz input: two enhanced wavs, and a log that includes timing or RTF. Do not expect the two wavs to match. NumPy always prints &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0. 0.061803 0.353553 1.]&lt;/code&gt;. A gain of 0.2 is pulled down harder than a gain of 1, which is the over-attenuation the post-filter is for. The second, \(\beta\)-weighted, step is intentionally not in this script.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;. No network to download weights: keep the NumPy result and write down the CLI error. A non-48 kHz file into the Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deep-filter&lt;/code&gt; binary. Comparing laptop log RTF with a phone. Claiming the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--pf&lt;/code&gt; wav matches &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; in the npm package.&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Three rows.&lt;/strong&gt; For the ICASSP 2022 model, DeepFilterNet2, and the DeepFilterNet3 row, list venue, arXiv id, one mechanism change, and one number you are willing to defend.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Gate.&lt;/strong&gt; Local SNR is −12 dB, then +25 dB, then +5 dB. Which stages run?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;RTF reading.&lt;/strong&gt; DF2’s table says GMAC 0.356 and RTF 0.04; the earlier row says GMAC 0.348 and RTF 0.11. Why can the slower-looking MAC row be faster?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Package.&lt;/strong&gt; Name two symbols an app author sees on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;, and two facts about hops and state the package does not excuse you from knowing.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;ICASSP 2022, 2110.05588: two-stage ERB + deep filter; PESQ 2.81 / 1.778 M. IWAENC 2022, 2205.05474: fewer temporal kernels, multi-resolution loss, post-filter; RTF 0.04 and PESQ 3.08 on that i5 table. Interspeech 2023, 2305.08227, README ties this citation to DF3: SNR gate and a table row at PESQ 3.17. All PESQ figures are Voicebank+Demand, not your product set.&lt;/li&gt;
  &lt;li&gt;−12 dB: both decoders off, silent frame. +25 dB: ERB stage only. +5 dB: both stages.&lt;/li&gt;
  &lt;li&gt;MAC tables ignore memory traffic. DF2’s smaller temporal kernels touch fewer buffered activations per hop, which is why RTF moved from 0.11 to 0.04 while GMAC stayed near 0.35.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; (0–100) are the surface. You still own the 10 ms hop versus the 128-sample quantum, and the GRU/STFT state across callbacks. No bit-exact claim with the CLI.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter et al., DeepFilterNet2, IWAENC 2022, &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Schröter et al., Interspeech 2023, &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt;, the README’s DeepFilterNet3 citation.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt; for checkpoints and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepFilter&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt; for the AudioWorklet packaging only.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. &lt;strong&gt;xem trước.&lt;/strong&gt; This is the framework DeepFilterNet2 and DeepFilterNet3 keep. Watch the STFT, ERB gains, and deep filter before the lesson’s loss and post-filter changes.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, English. The author’s noise-suppression demo. Judge it by ear; the DF2 and DF3 numbers in the lesson stay in the papers, not in this soundtrack.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. Watch how a later model is accepted: same task, a complexity budget, and a listening test. That is the comparison the lesson wants for DF2 and DF3.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-02 DeepFilterNet: deep filtering idea</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_02_deepfilternet_core/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_02_deepfilternet_core</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;DeepFilterNet&lt;/strong&gt; (Schröter et al., ICASSP 2022, arXiv:2110.05588) is a full-band speech enhancer that spends most of its capacity on a coarse auditory envelope and a short complex filter, not on a dense net over all 481 bins. This lesson derives that split, writes the filter sum, and runs it on a two-tap toy spectrum even if the pretrained weights never download.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;DeepFilterNet two-stage diagram: ERB gains on the envelope, deep filter on low-frequency harmonics&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Stage 1 predicts real gains on 32 ERB bands and applies them to the full STFT. Stage 2 predicts a 5-tap complex filter and applies it only on the low frequencies, where most periodic speech energy sits. High bins keep the ERB gain.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will compute an ERB gain application and a multi-frame deep-filter sum on complex bins; explain why a 5-tap filter up to about 5 kHz is cheaper than a complex mask on every bin at 48 kHz; state the published STFT (20 ms window, 10 ms hop) and the 40 ms algorithmic delay that includes two frames of look-ahead; and run either the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepFilter&lt;/code&gt; CLI or the NumPy fallback below.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Why 481 bins at 48 kHz should not all get the same MAC budget.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — ERB stage: 32 real gains, pointwise multiply.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Deep-filter sum versus a one-tap Wiener or CRM gain.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Look-ahead, causality, and the official repository.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab (CLI or NumPy), exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;two-stages-with-the-published-sizes&quot;&gt;Two stages, with the published sizes&lt;/h3&gt;

&lt;p&gt;Hearing resolves frequency more finely at low frequency than at high frequency. DeepFilterNet uses that fact twice.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Envelope stage.&lt;/strong&gt; A rectangular ERB bank compresses log-power to \(N_{\mathrm{ERB}}=32\) bands. The net predicts 32 real gains, the inverse bank spreads them onto STFT bins, and they multiply the noisy spectrum. Features use an exponential mean normalization with a 1 s decay, so a microphone-gain jump does not look like a new noise.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Periodicity stage.&lt;/strong&gt; Five complex taps run only up to \(f_{\mathrm{DF}}=5\) kHz (ICASSP and DeepFilterNet2). The 2023 demo (arXiv:2305.08227) says the lowest 96 bins: a 960-point FFT at 48 kHz has 50 Hz bins, and \(96\times 50\,\mathrm{Hz}=4.8\) kHz. Above the cutoff the ERB gain is the output.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Comparisons use 48 kHz, \(N_{\mathrm{FFT}}=960\) (20 ms), 50% overlap (hop 480 samples = 10 ms). DeepFilterNet2 and the 2023 demo use a two-frame look-ahead and state &lt;strong&gt;40 ms&lt;/strong&gt; algorithmic latency. The ICASSP latency formula is window delay plus \(\max(l_{\mathrm{DNN}}, l_{\mathrm{DF}})\); the training setup uses \(l_{\mathrm{DNN}}=2\) and \(l_{\mathrm{DF}}=1\). Those future frames are delay, counted before anyone says “real time.”&lt;/p&gt;

&lt;p&gt;On the VCTK/DEMAND table in the ICASSP paper the full model has 1.778 million parameters and 0.348 GMAC/s, WB-PESQ 2.81, SI-SDR 16.63 dB. Stripping stage 2 leaves 0.885 million parameters, 0.251 GMAC/s, PESQ 2.57, SI-SDR 13.81 dB. Stage 2 is about half the parameters and most of the harmonic restoration.&lt;/p&gt;

&lt;h3 id=&quot;the-filter-is-not-a-mask&quot;&gt;The filter is not a mask&lt;/h3&gt;

&lt;p&gt;A one-tap mask, including the Wiener gain under a Gaussian model, is&lt;/p&gt;

\[\hat{S}(k,\ell)=M(k,\ell)\,Y(k,\ell).\]

&lt;p&gt;Deep filtering (Mack and Habets, and the CLC line of work the ICASSP paper builds on) predicts taps \(W_i\) and sums a short history. For a 5-tap filter and an optional look-ahead \(\ell\),&lt;/p&gt;

\[\hat{S}(t,f)=\sum_{i=0}^{4} W_i(t,f)\,X(t-i+\ell,f).\]

&lt;p&gt;The ICASSP write-up indexes a filter of order \(N=5\) as a sum \(\sum_{i=0}^{N}\); the 2023 demo writes an \(N=5\) tap vector \(W_0,\ldots,W_{N-1}\). Teach the five-coefficient sum. Either reading is a per-bin FIR across time, not a per-bin multiply. The lab below uses two taps so the arithmetic fits on one line; the missing three taps are the same pattern.&lt;/p&gt;

&lt;p&gt;Complex taps can rotate a bin using a past frame, which a magnitude mask cannot do. Many tap vectors realize one output, so the paper trains them with the compressed spectral loss from 04-01 (\(c=0.6\)), not with a closed-form ideal filter. The ICASSP model also learns a blend \(\alpha(k)\) between deep-filter output and ERB output. The 2023 demo uses an SNR gate instead (04-03). Do not merge those two mechanisms into one block.&lt;/p&gt;

&lt;h3 id=&quot;why-the-mac-count-falls&quot;&gt;Why the MAC count falls&lt;/h3&gt;

&lt;p&gt;The envelope decoder emits 32 gains, not 481 (\(32/481\approx 0.067\)). The fine stage is 5 complex taps on 96 bins, not a CRM on every bin. The ICASSP net also splits linear and GRU layers into \(P=8\) groups of hidden size \(512/8=64\). Layer names move between versions; this budget does not.&lt;/p&gt;

&lt;h3 id=&quot;causality-and-the-repository&quot;&gt;Causality and the repository&lt;/h3&gt;

&lt;p&gt;Taps may only touch frames inside the declared look-ahead. GRU state, the 1 s normalizer, and the past spectra are streaming state (05-04). Zeroing them mid-call is a click or a short noise burst.&lt;/p&gt;

&lt;p&gt;Configs and weights: &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt;. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet&lt;/code&gt; package’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepFilter&lt;/code&gt; CLI defaults to DeepFilterNet3 weights. The Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deep-filter&lt;/code&gt; binary expects 48 kHz wav. The npm package &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; (&lt;a href=&quot;https://github.com/mezonai/mezon-noise-suppression&quot;&gt;mezonai/mezon-noise-suppression&lt;/a&gt;) runs ONNX/WASM in an AudioWorklet (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;) and is not bit-exact with the CLI.&lt;/p&gt;

&lt;h2 id=&quot;checklist-before-you-call-it-deepfilternet&quot;&gt;Checklist before you call it DeepFilterNet&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;48 kHz full-band STFT, not a 16 kHz offline net.&lt;/li&gt;
  &lt;li&gt;32 ERB gains for the envelope.&lt;/li&gt;
  &lt;li&gt;A multi-tap complex filter on the low bins only.&lt;/li&gt;
  &lt;li&gt;Look-ahead counted in the 40 ms class of delay, separately from RTF.&lt;/li&gt;
  &lt;li&gt;Causal state carried across hops.&lt;/li&gt;
  &lt;li&gt;Weights pinned by filename or commit, then exported (Chapter 06).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Calling every mask network “DeepFilterNet.”&lt;/li&gt;
  &lt;li&gt;Applying the 5-tap filter to all 481 bins and then wondering where the GMAC budget went.&lt;/li&gt;
  &lt;li&gt;Scoring 16 kHz PESQ and claiming the 48 kHz table.&lt;/li&gt;
  &lt;li&gt;Forgetting the 20 ms window inside the “10 ms frame” story.&lt;/li&gt;
  &lt;li&gt;Swapping DF, DF2, and DF3 checkpoints in one config (next lesson).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Enhance one file with the official CLI. If weights cannot download, still compute one deep-filter sum in NumPy and compare it to a one-tap mask.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;deepfilternet
deepFilter &lt;span class=&quot;nt&quot;&gt;--output-dir&lt;/span&gt; out/ noisy.wav
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Documented flags you may need: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--model-base-dir&lt;/code&gt; (local weights), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--pf&lt;/code&gt; (post-filter, lesson 04-03), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--output-dir&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--compensate-delay&lt;/code&gt;. Input for the Rust &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deep-filter&lt;/code&gt; binary is 48 kHz wav.&lt;/p&gt;

&lt;p&gt;Offline fallback, two taps of the sum above:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
import numpy as np
Y_now = np.complex64(1.0 + 0.5j)
Y_prev = np.complex64(0.2 - 0.1j)
H0 = np.complex64(0.8 + 0.0j)
H1 = np.complex64(0.1 - 0.2j)
deep = H0 * Y_now + H1 * Y_prev
mask = np.complex64(0.8) * Y_now
print(deep)
print(mask)
print(round(abs(deep), 6), round(abs(mask), 6))
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;. CLI: an enhanced wav under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;out/&lt;/code&gt; and a log line that reports timing or RTF. NumPy, always: deep-filter result &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(0.8+0.35j)&lt;/code&gt;, one-tap mask &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(0.8+0.4j)&lt;/code&gt;, magnitudes about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.873212&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.894427&lt;/code&gt;. The imaginary part moved because \(H_1\) used \(Y_{\mathrm{prev}}\); a mask cannot do that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;. No network, so the CLI cannot fetch weights — run the NumPy path and record the error, do not invent an output wav. Input that is not 48 kHz into the Rust binary. Reading a laptop RTF off the log and calling it a phone RTF. Forgetting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--output-dir&lt;/code&gt; and then hunting the wav in the wrong folder.&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Side by side.&lt;/strong&gt; Write the Wiener one-tap gain and the 5-tap sum. Circle learned quantities versus quantities a noise tracker would estimate.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bins.&lt;/strong&gt; At 48 kHz with a 960-point FFT, which bin index is the last one included by a 4.8 kHz cutoff? How many complex taps per frame is that, at 5 taps?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;MAC sketch.&lt;/strong&gt; The envelope head emits 32 numbers instead of 481. Give the ratio. Why is that not the whole GMAC story?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Delay audit.&lt;/strong&gt; Hop 10 ms, look-ahead 2 frames, window 20 ms. What algorithmic latency do you quote, and which CLI flag shifts output alignment rather than that latency?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Wiener: \(M=\xi/(\xi+1)\), one real (or complex) multiply, \(\xi\) from a noise tracker. Deep filter: five complex \(W_i\) from the net, dotted with five frames of \(X\). Learned: \(W_i\) and the ERB gains. Estimated in a classical system: \(\xi\) or the noise PSD.&lt;/li&gt;
  &lt;li&gt;Bin width 50 Hz, so index 96 lands on 4.8 kHz and is the count the 2023 demo uses (“lowest 96 bins”). \(96\times 5=480\) complex taps per frame, before the high bins, which only receive a real gain.&lt;/li&gt;
  &lt;li&gt;\(32/481\approx 0.0665\). The STFT, the inverse ERB spread, and the 5-tap multiply on 96 bins are extra. DF2’s lesson is that grouping and kernel shape move wall-clock RTF even when GMAC barely changes.&lt;/li&gt;
  &lt;li&gt;40 ms. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--compensate-delay&lt;/code&gt; realigns the file for offline scoring; it does not remove the look-ahead from a live call.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter et al., ICASSP 2022, &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;. ERB gains, deep filtering, the 1.778 M / 0.348 GMAC table.&lt;/li&gt;
  &lt;li&gt;Mack and Habets, “Deep Filtering,” IEEE Signal Processing Letters, 2020, as cited by that paper: the complex multi-frame filter DeepFilterNet adopts.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt; README for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepFilter&lt;/code&gt; CLI and the model card.&lt;/li&gt;
  &lt;li&gt;Next lesson: what DeepFilterNet2 and the DeepFilterNet3-associated 2023 citation change, at the same high level.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the ERB envelope stage and the complex deep filter on the lower bins. That split is the idea the lesson derives.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, English. Listen after the diagram so the two stages are a sound, not only a block count.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nsscrYdrGRE&quot;&gt;RNNoise, Neural Speech Enhancement, and the Browser&lt;/a&gt; — W3C, English. Contrast a handful of band gains with the complex filter the lesson is defining.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>04-01 Neural speech enhancement overview</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_01_neural_se_overview/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter04/04_01_neural_se_overview</id>
   <content type="html">&lt;p&gt;Neural speech enhancement (SE) replaces a hand-tuned gain with a model trained on noisy–clean mixtures. This lesson maps masking, mapping, and generative SE, waveform versus short-time Fourier transform (STFT) models, and the losses those models actually optimize, so DeepFilterNet (04-02 onward) and RNNoise (04-06) sit on a map you can defend. The architecture this course unpacks is the two-stage graph below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/deepfilternet-erb.png&quot; alt=&quot;Two-stage DeepFilterNet graph: ERB envelope gains and a complex deep filter on the STFT&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The graph this course unpacks: a coarse equivalent-rectangular-bandwidth (ERB) stage estimates a spectral envelope, then a short complex deep filter restores harmonics. Later lessons open each block; this lesson only fixes the map.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will contrast masking, mapping, and generative SE; separate the compressed spectral loss DeepFilterNet trains from the SI-SDR it only reports; and separate algorithmic latency from real-time factor (RTF).&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — From the Wiener ideal ratio mask (IRM) to a learned mask: what paired data buys.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Masking vs mapping vs generative; time domain vs STFT.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — DNS-style mixtures and the losses in the DeepFilterNet papers.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Streaming constraints; 40 ms algorithmic delay is not an RTF.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Mini-lab, pitfalls, exercises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;what-the-network-outputs&quot;&gt;What the network outputs&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Masking.&lt;/strong&gt; Predict a mask \(M(k,\ell)\) and form \(\hat{S}=M\odot Y\). A real mask keeps the noisy phase. A complex ratio mask (CRM) multiplies real and imaginary parts and can rotate phase per bin, but it is still a single tap: one coefficient times one bin. The ideal ratio mask echoes the Wiener gain \(\xi/(\xi+1)\) from Chapter 03. The ICASSP 2022 DeepFilterNet paper (arXiv:2110.05588) treats a CRM as the special case of deep filtering with filter order \(N=1\) and look-ahead \(\ell=0\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Mapping.&lt;/strong&gt; Predict clean magnitudes or the complex spectrum directly, \(\hat{S}=f_\theta(Y)\). Nothing forces the output to stay near \(Y\), so a weak loss over-smooths harmonics into a blurry envelope.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Generative SE.&lt;/strong&gt; A GAN or diffusion model draws speech from a posterior. A second network still has to finish inside the hop. DeepFilterGAN (04-04) is a survey name only: no paper title or URL in this course.&lt;/p&gt;

&lt;h3 id=&quot;time-domain-versus-spectrogram-models&quot;&gt;Time domain versus spectrogram models&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Family&lt;/th&gt;
      &lt;th&gt;Input&lt;/th&gt;
      &lt;th&gt;What you pay&lt;/th&gt;
      &lt;th&gt;What you get&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Waveform (Conv-TasNet-like)&lt;/td&gt;
      &lt;td&gt;PCM frames&lt;/td&gt;
      &lt;td&gt;A learned encoder on every sample&lt;/td&gt;
      &lt;td&gt;Phase is implicit; full-band 48 kHz is expensive&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;STFT mask&lt;/td&gt;
      &lt;td&gt;Complex spectrogram&lt;/td&gt;
      &lt;td&gt;One window of latency&lt;/td&gt;
      &lt;td&gt;Interpretable gains; CRM cannot rebuild a harmonic the window smeared&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;ERB gain + deep filter&lt;/td&gt;
      &lt;td&gt;32 ERB bands, then a few complex taps&lt;/td&gt;
      &lt;td&gt;Implementation of two stages&lt;/td&gt;
      &lt;td&gt;DeepFilterNet’s operating point&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;At 48 kHz a 20 ms window (960 samples) has bin spacing \(48000/960=50\) Hz. A pointwise mask cannot pull noise out from between harmonics finer than a bin, which is why stage 2 exists. These models are spectrogram systems for a full-band CPU budget.&lt;/p&gt;

&lt;h3 id=&quot;a-dns-style-training-mixture-with-the-numbers-from-the-paper&quot;&gt;A DNS-style training mixture, with the numbers from the paper&lt;/h3&gt;

&lt;p&gt;The ICASSP 2022 framework trains on Deep Noise Suppression (DNS) challenge material: more than 750 hours of full-band clean speech and 180 hours of noise, VCTK and PTDB oversampled by 10, up to five noises at SNRs in \(\{-5,0,5,10,20,40\}\) dB, random second-order filters, gains in \(\{-6,0,6\}\) dB, and room impulse responses. Another 10,000 image-source RIRs are simulated at 48 kHz with RT60 from 0.05 s to 1.00 s. A café outside that RT60 range, or a noise those 180 hours never contained, was never supervised. DNSMOS (Chapter 08) scores the result; a leaderboard rank is not a product requirement.&lt;/p&gt;

&lt;h3 id=&quot;loss-families-and-the-one-deepfilternet-trains&quot;&gt;Loss families, and the one DeepFilterNet trains&lt;/h3&gt;

&lt;p&gt;Families you will see elsewhere: magnitude MSE, complex spectral error, time-domain SI-SDR, multi-resolution STFT, and adversarial critics. The ICASSP 2022 recipe does &lt;strong&gt;not&lt;/strong&gt; train on SI-SDR. It uses a compressed spectral loss with exponent \(c=0.6\),&lt;/p&gt;

\[\mathcal{L}_{\mathrm{spec}}=\sum_{k,f}\left\||Y|^{c}-|S|^{c}\right\|^{2}+\sum_{k,f}\left\||Y|^{c}e^{j\varphi_Y}-|S|^{c}e^{j\varphi_S}\right\|^{2},\]

&lt;p&gt;plus a small auxiliary term (weight \(0.05\)) that pushes the deep-filter blend weight toward zero when the local SNR below the deep-filter cutoff is under \(-10\) dB, and toward one when that SNR is above \(-5\) dB. SI-SDR is an &lt;strong&gt;evaluation&lt;/strong&gt; number in that paper: 16.63 dB for the full model on the VCTK/DEMAND test set, against 13.81 dB when stage 2 is removed. Wideband PESQ on the same table is 2.81 versus 2.57 without stage 2. Quote those only as that table’s numbers, on that set, for that checkpoint.&lt;/p&gt;

&lt;h3 id=&quot;streaming-is-a-different-graph-not-a-smaller-offline-net&quot;&gt;Streaming is a different graph, not a smaller offline net&lt;/h3&gt;

&lt;p&gt;An offline Transformer may attend over the whole utterance. A VoIP hop cannot. The 2023 demo (arXiv:2305.08227) uses 20 ms windows, a 10 ms hop, and two frames of look-ahead: &lt;strong&gt;40 ms of algorithmic latency&lt;/strong&gt;. That delay is not RTF.&lt;/p&gt;

\[\mathrm{RTF}=\frac{T_{\mathrm{wall}}}{T_{\mathrm{audio}}}.\]

&lt;p&gt;A 10 ms hop that burns 4 ms of CPU has RTF 0.4 while the user still waits 40 ms. Causal convolutions and a fixed-size GRU (gated recurrent unit) replace a growing attention cache. Chapter 05 times the tail of \(T_{\mathrm{wall}}\): a mean RTF of 0.4 with p95 above 1 still clicks.&lt;/p&gt;

&lt;h3 id=&quot;where-the-named-systems-sit&quot;&gt;Where the named systems sit&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; low complexity                         higher quality on the published full-band tests
     │                                              │
  RNNoise ── ultra-light names (04-05) ── DeepFilterNet / 2 / 3 ── survey names (04-04)
  22 Bark bands + GRU                   32 ERB bands + 5-tap complex filter
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;RNNoise (Valin, arXiv:1709.08243) predicts 22 band gains with a small GRU and a pitch comb. DeepFilterNet predicts 32 ERB gains and five complex taps on the low bins. The npm package &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; runs a DF3-oriented ONNX/WASM graph in an AudioWorklet; it is not a bit-exact claim against the paper checkpoint, and it is not the RNNoise branch (04-06).&lt;/p&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Ranking an offline PESQ against a streaming RTF.&lt;/li&gt;
  &lt;li&gt;Debugging a −15 dB subway clip as a model bug when the mix grid stopped at −5 dB.&lt;/li&gt;
  &lt;li&gt;Reusing noisy phase and skipping the listening pass.&lt;/li&gt;
  &lt;li&gt;Treating the npm wrapper as the algorithm. The algorithm is the STFT, the ERB gains, the taps, and the state across hops.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Compute algorithmic latency and RTF for the published 20 ms / 10 ms / two-frame look-ahead setup, and show they are different quantities.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 - &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
window_ms, hop_ms, lookahead_frames = 20.0, 10.0, 2
# Published overall delay for this configuration: window plus two hops.
algo_ms = window_ms + lookahead_frames * hop_ms
wall_ms = 4.0  # one hop of steady compute on a laptop you just timed
rtf = wall_ms / hop_ms
print(f&quot;algorithmic_latency_ms={algo_ms:.1f}&quot;)
print(f&quot;rtf={rtf:.2f}&quot;)
print(&quot;latency_is_rtf&quot;, algo_ms == wall_ms)
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected&lt;/strong&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;algorithmic_latency_ms=40.0&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rtf=0.40&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;latency_is_rtf False&lt;/code&gt;. The 40 ms figure is the delay stated for this window and look-ahead in the DeepFilterNet2 paper and in the 2023 demo write-up. The 4 ms wall time is a lab assumption, not a phone measurement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes&lt;/strong&gt;. Using hop as the latency (you report 10 ms and ignore the 20 ms window and the two future frames). Dividing wall time by the window instead of the hop (RTF looks half as large). Pasting a laptop RTF into a phone budget.&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Taxonomy.&lt;/strong&gt; Place RNNoise, a magnitude-IRM U-Net, Conv-TasNet, and DeepFilterNet into masking / mapping / generative and waveform / STFT. Say what each one multiplies or filters.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Latency.&lt;/strong&gt; Window 20 ms, hop 10 ms, look-ahead 2 frames. State the algorithmic latency before any neural timing. What extra delay appears if the synthesis ring holds one extra hop?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Loss.&lt;/strong&gt; The training loss uses \(c=0.6\) on magnitudes and a phase-aware term. SI-SDR on the paper’s table is 16.63 dB. Which number would you monitor during training, and which only on a fixed test set?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Data.&lt;/strong&gt; Give one user-audible failure for each of: SNRs only down to −5 dB, RT60 only up to 1 s, and noise drawn from 180 hours that lack keyboard clicks.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;RNNoise: real band gains (masking) on an STFT/Bark grid, plus a DSP pitch comb. IRM U-Net: masking, STFT. Conv-TasNet: learned waveform basis, closer to mapping. DeepFilterNet: real ERB mask plus a multi-tap complex filter on the STFT, not a generative model.&lt;/li&gt;
  &lt;li&gt;\(20+2\times 10=40\) ms. One extra hop in the ring adds another 10 ms of buffering delay and does not change RTF.&lt;/li&gt;
  &lt;li&gt;Monitor \(\mathcal{L}_{\mathrm{spec}}\) (and the auxiliary gate term) during training. Report SI-SDR only on the pinned test set; it is not the training objective in that paper.&lt;/li&gt;
  &lt;li&gt;−15 dB is outside the mix grid. A 1.5 s room was never in the 0.05–1.00 s RT60 set. Short clicks are unlike the long noises in those 180 hours.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Schröter et al., ICASSP 2022, &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Schröter et al., DeepFilterNet2, IWAENC 2022, &lt;a href=&quot;https://arxiv.org/abs/2205.05474&quot;&gt;arXiv:2205.05474&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Schröter et al., Interspeech 2023, &lt;a href=&quot;https://arxiv.org/abs/2305.08227&quot;&gt;arXiv:2305.08227&lt;/a&gt;; the README associates this citation with DeepFilterNet3. Code: &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Valin, &lt;a href=&quot;https://arxiv.org/abs/1709.08243&quot;&gt;arXiv:1709.08243&lt;/a&gt;, &lt;a href=&quot;https://github.com/xiph/rnnoise&quot;&gt;xiph/rnnoise&lt;/a&gt;. DNS Challenge overviews for the mixture protocol.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the move from a DSP suppressor to a trained model, including the losses and tests that decide whether the model actually helped.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nsscrYdrGRE&quot;&gt;RNNoise, Neural Speech Enhancement, and the Browser&lt;/a&gt; — W3C, English. A hybrid of DSP features and a small recurrent net. Use it as the small end of the masking-versus-mapping map.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. Real-valued envelope gains plus a complex filter are two of the neural SE families this lesson names.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-05 Beamforming / GSC / IVA as front-ends</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter03/03_05_beamforming_frontends/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter03/03_05_beamforming_frontends</id>
   <content type="html">&lt;p&gt;With a single microphone, two people talking at equal loudness in a café are nearly impossible to tell apart—their voices overlap in the exact same frequency bands. Add a &lt;strong&gt;second microphone&lt;/strong&gt; just 2 centimeters away, and physics hands you a brand-new dimension: &lt;strong&gt;space&lt;/strong&gt;. A sound coming from \(45^\circ\) off-axis hits one mic \(41.2\,\mu\mathrm{s}\) (nearly 2 samples at 48 kHz) later than the other!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beamforming&lt;/strong&gt;, the &lt;strong&gt;Generalized Sidelobe Canceller (GSC)&lt;/strong&gt;, and &lt;strong&gt;Independent Vector Analysis (IVA)&lt;/strong&gt; turn those tiny inter-mic time delays into a directional acoustic spotlight—suppressing off-axis interferers &lt;em&gt;before&lt;/em&gt; handing a cleaner mono stream to a neural enhancer like DeepFilterNet. This lesson closes Chapter 03 by mapping multi-mic spatial front-ends and showing exactly where they plug into a mono product pipeline.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;LiveKit publish path through a single-channel DeepFilterNoiseFilterProcessor, the stage a beamformer would have to feed&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. This is the mono publish path; a beamformer is not drawn, and would sit in front of DeepFilterNoiseFilterProcessor so the processor still sees one channel.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (steering vectors &amp;amp; time-of-arrival geometry, fixed vs. adaptive beamforming, blind separation via IVA) → Delay-and-sum, MVDR, GSC, and IVA architectures → Hybrid spatial + mono neural patterns → Worked example: computing the exact \(41.2\,\mu\mathrm{s}\) (1.98-sample) inter-mic delay and phase shift for a 2 cm dual-mic array at 48 kHz → Explanation: 3 steps from delay-and-sum to MVDR/GSC and hybrid neural postfiltering → Decision checklist, Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-multi-microphone-spatial-audio-processing&quot;&gt;Key ideas: Multi-Microphone Spatial Audio Processing&lt;/h2&gt;

&lt;h3 id=&quot;1-steering-vectors--encoding-direction-as-phase-shifts&quot;&gt;1. Steering Vectors — Encoding Direction as Phase Shifts&lt;/h3&gt;
&lt;p&gt;When a plane wave from angle \(\theta\) crosses a microphone array with spacing \(d\), the arrival delay \(\tau = (d\sin\theta)/c\) turns into a frequency-dependent phase shift \(e^{-j2\pi f\tau}\) in the STFT domain. Stacking those phase factors across all \(M\) mics produces the &lt;strong&gt;steering vector&lt;/strong&gt; \(\mathbf{a}(\theta, f)\).&lt;/p&gt;

&lt;h3 id=&quot;2-fixed-vs-adaptive-beamforming-delay-and-sum-mvdr-gsc&quot;&gt;2. Fixed vs. Adaptive Beamforming (Delay-and-Sum, MVDR, GSC)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Delay-and-sum&lt;/strong&gt; aligns the target’s phases and averages—boosting target SNR against diffuse noise by up to \(M\times\) in power.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;MVDR / GSC&lt;/strong&gt; goes further by steering sharp &lt;strong&gt;spatial nulls&lt;/strong&gt; straight at loud directional interferers while constraining the target direction to unity gain (\(\mathbf{w}^H\mathbf{a} = 1\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-blind-separation-iva-and-hybrid-spatial--neural-front-ends&quot;&gt;3. Blind Separation (IVA) and Hybrid Spatial + Neural Front-Ends&lt;/h3&gt;
&lt;p&gt;When you do &lt;em&gt;not&lt;/em&gt; know the array geometry or talker angle, &lt;strong&gt;Independent Vector Analysis (IVA)&lt;/strong&gt; separates sources purely via statistical independence across microphones. In production, a spatial front-end collapses \(M\) mics down to &lt;strong&gt;1 cleaner mono channel&lt;/strong&gt;, letting you reuse an unmodified mono DeepFilterNet3 model downstream!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will explain delay-and-sum and MVDR goals in plain language, sketch a GSC (fixed beamformer + blocking matrix + adaptive canceler), summarize IVA as a blind multi-channel separator, and decide when a spatial front-end plus mono DeepFilterNet-class model beats mono-only NS.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Two-mic laptop demo narrative: target talker vs interferer direction.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Steering vectors, delay-and-sum, MVDR objective sketch.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — GSC structure; what the adaptive branch cancels.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — IVA / BSS pointer; hybrid front-end + neural refine.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Pitfalls, exercises, product reality check (most Mezon paths are still mono).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;spatial-model-far-field-sketch&quot;&gt;Spatial model (far-field sketch)&lt;/h3&gt;

&lt;p&gt;For microphone \(m=1\ldots M\), a plane-wave target from direction \(\theta\) at frequency \(f\) has relative phase shifts encoded in a &lt;strong&gt;steering vector&lt;/strong&gt; \(\mathbf{a}(\theta,f)\). The stacked spectrum is&lt;/p&gt;

\[\mathbf{y}(f,\ell) = \mathbf{a}(\theta,f)\,S(f,\ell) + \mathbf{v}(f,\ell),\]

&lt;p&gt;with \(\mathbf{v}\) containing noise and interferers. A beamformer applies weights \(\mathbf{w}(f)\):&lt;/p&gt;

\[Z(f,\ell) = \mathbf{w}^H(f)\,\mathbf{y}(f,\ell).\]

&lt;h3 id=&quot;delay-and-sum&quot;&gt;Delay-and-sum&lt;/h3&gt;

&lt;p&gt;Choose delays (phases) so the target aligns coherently across mics, then average. Gain against &lt;strong&gt;incoherent&lt;/strong&gt; noise scales with \(M\), but &lt;strong&gt;coherent interferers&lt;/strong&gt; from other directions are only partially attenuated. It is the simplest teaching beamformer and a fine baseline.&lt;/p&gt;

&lt;h3 id=&quot;mvdr-cartoon-minimum-variance-distortionless-response&quot;&gt;MVDR cartoon (minimum variance distortionless response)&lt;/h3&gt;

&lt;p&gt;Solve: minimize output power subject to unity gain toward the target,&lt;/p&gt;

\[\min_{\mathbf{w}} \mathbf{w}^H \mathbf{R}_{yy}\mathbf{w} \quad \text{s.t.} \quad \mathbf{w}^H\mathbf{a}=1.\]

&lt;p&gt;The closed form \(\mathbf{w}\propto \mathbf{R}_{yy}^{-1}\mathbf{a}\) (normalized) steers a null toward interferers while keeping the target. Estimating \(\mathbf{R}_{yy}\) (or a noise-only \(\mathbf{R}_{nn}\)) robustly is the hard engineering part—steering error and RTF mismatch cause target cancellation (self-nulling).&lt;/p&gt;

&lt;h3 id=&quot;gsc--generalized-sidelobe-canceller&quot;&gt;GSC — generalized sidelobe canceller&lt;/h3&gt;

&lt;p&gt;GSC reparameterizes beamforming into:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fixed beamformer (FBF)&lt;/strong&gt; — looks at the target (delay-and-sum / MVDR fixed weights).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Blocking matrix (BM)&lt;/strong&gt; — projects away the target so outputs are “target-free” noise references.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Adaptive noise canceler&lt;/strong&gt; — NLMS/RLS filters subtract interference estimated from BM channels from the FBF output.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; mics → Fixed beamformer ───────────────────────────→ + → out
     └→ Blocking matrix → Adaptive filters → (−)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Why engineers like GSC:&lt;/strong&gt; unconstrained adaptive filtering on the noise references; easy to add voice-activity control so the adaptive path freezes during target speech.&lt;/p&gt;

&lt;h3 id=&quot;iva--blind-spatial-separation-pointer&quot;&gt;IVA / blind spatial separation (pointer)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Independent vector analysis (IVA)&lt;/strong&gt; and related BSS methods separate sources from multi-mic mixtures without an explicit steering vector, using statistical independence across frequency-grouped vectors. Teaching level:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Treat IVA as a &lt;strong&gt;blind spatial front-end&lt;/strong&gt; that yields a coarse target estimate + interferer estimate.&lt;/li&gt;
  &lt;li&gt;A lightweight neural model (e.g. GTCRN-class) can refine the IVA output—hybrid papers on dual-channel low-SNR SE follow this pattern.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You do not need to derive IVA contrast functions here; you need to know it exists as a classical multi-channel tool and that hybrids use it when DOA is unknown.&lt;/p&gt;

&lt;h3 id=&quot;hybrid-front-end--neural-mono-enhancer&quot;&gt;Hybrid front-end + neural mono enhancer&lt;/h3&gt;

&lt;p&gt;Pattern A — &lt;strong&gt;GSC → DeepFilterNet2&lt;/strong&gt;: spatial cancel of strong directional ego-noise (drone rotors, fan), then DF2 cleans residual diffuse noise.&lt;br /&gt;
Pattern B — &lt;strong&gt;IVA → GTCRN&lt;/strong&gt;: blind separation then tiny CRN refine.&lt;br /&gt;
Pattern C — &lt;strong&gt;mono DF3 only&lt;/strong&gt;: correct default when \(M=1\) (most browser tabs).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mezon product note:&lt;/strong&gt; current npm / WASM paths are typically &lt;strong&gt;mono&lt;/strong&gt;. Multi-mic is a stretch goal—learn the front-ends so you can design a future native pipeline without rewriting the neural core. A beamformer would be a spatial pre-filter in front of that mono processor: several microphones in, one channel out, and only then the per-bin gain of a single-channel suppressor. The figure above is the single-channel product path. It does not contain a beamformer; the honest reading is where a beamformer would have to sit, which is upstream of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-how-two-microphones-2-cm-apart-steer-a-spatial-null&quot;&gt;Explanation: How Two Microphones 2 cm Apart Steer a Spatial Null&lt;/h3&gt;

&lt;h4 id=&quot;step-1-compute-the-physical-delay-tau-and-phase-shift-by-hand&quot;&gt;Step 1: Compute the physical delay \(\tau\) and phase shift by hand&lt;/h4&gt;
&lt;p&gt;Place two mics \(d = 0.02\,\mathrm{m}\) apart (speed of sound \(c = 343\,\mathrm{m/s}\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Broadside target (\(\theta = 0^\circ\), straight ahead):&lt;/strong&gt; \(\tau = 0\,\mu\mathrm{s}\) (0 samples). Both mics hear the target identically: \(\mathbf{a}(0^\circ, f) = [1, 1]^T\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Off-axis interferer (\(\theta = 45^\circ\)):&lt;/strong&gt; \(\tau = \frac{0.02 \sin 45^\circ}{343} \approx 41.2\,\mu\mathrm{s}\), which is \(41.2\times 10^{-6} \times 48000 \approx 1.98\) samples at 48 kHz! At \(f = 2\,\mathrm{kHz}\), that delay creates a phase difference of \(2\pi f\tau \approx 0.52\,\mathrm{rad}\) (\(\approx 30^\circ\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;step-2-watch-the-gsc-blocking-matrix-turn-the-target-into-zero&quot;&gt;Step 2: Watch the GSC Blocking Matrix turn the target into zero&lt;/h4&gt;
&lt;p&gt;For a broadside target (\(y_1 = s + v_1,\; y_2 = s + v_2\)), the &lt;strong&gt;Fixed Beamformer&lt;/strong&gt; sums \(\frac{1}{2}(y_1 + y_2) = s + \frac{1}{2}(v_1 + v_2)\) while the &lt;strong&gt;Blocking Matrix&lt;/strong&gt; subtracts \(y_1 - y_2 = v_1 - v_2\)—canceling \(s\) completely and producing a pure noise reference for the adaptive filter!&lt;/p&gt;

&lt;h4 id=&quot;step-3-hand-the-single-spatially-cleaned-stream-to-a-mono-neural-enhancer&quot;&gt;Step 3: Hand the single spatially cleaned stream to a mono neural enhancer&lt;/h4&gt;
&lt;p&gt;Because beamforming cannot easily cancel diffuse reverberant noise (arriving from &lt;em&gt;all&lt;/em&gt; angles at once), pairing &lt;strong&gt;GSC/MVDR → Mono DeepFilterNet&lt;/strong&gt; gives you the best of both worlds: geometry kills directional babble, and the neural postfilter erases remaining diffuse hiss!&lt;/p&gt;

&lt;p&gt;Summary of the multi-mic hybrid pipeline:&lt;/p&gt;

\[\mathbf{y}_M\ (M \ge 2\text{ mics})
\;\xrightarrow{\text{Delay-and-sum / GSC / IVA}}\;
z_{\text{mono}}
\;\xrightarrow{\text{Mono Neural NS (DF3)}}\;
\hat{s}_{\text{clean}}.\]

&lt;h2 id=&quot;decision-checklist&quot;&gt;Decision checklist&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;\(M=1\) → classical / neural mono NS (Ch. 03–04); skip beamforming.&lt;/li&gt;
  &lt;li&gt;\(M\ge 2\), known target direction, strong directional noise → GSC / MVDR front-end.&lt;/li&gt;
  &lt;li&gt;\(M\ge 2\), unknown geometry / moving talkers → IVA / robust adaptive BF, then neural.&lt;/li&gt;
  &lt;li&gt;CPU budget tiny → prefer simple delay-and-sum + ultra-light NS over full IVA.&lt;/li&gt;
  &lt;li&gt;Browser getUserMedia often exposes mono after OS processing—verify actual channel count.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Steering vector mismatch → &lt;strong&gt;target cancellation&lt;/strong&gt; (sounds like NS over-suppressing speech).&lt;/li&gt;
  &lt;li&gt;Adapting GSC during target activity without a VAD → speech leakage into BM path.&lt;/li&gt;
  &lt;li&gt;Assuming stereo laptop mics have calibrated geometry (they often do not).&lt;/li&gt;
  &lt;li&gt;Running multi-channel STFT with inconsistent channel delays (USB clocking).&lt;/li&gt;
  &lt;li&gt;Expecting beamforming to fix &lt;strong&gt;echo&lt;/strong&gt; without a far-end reference—still need AEC.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Far-field delay between two microphones 2 cm apart, at broadside and at 45°.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;343.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# meters, m/s, Hz
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;deg&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;tau&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;deg2rad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;deg&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tau&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;us&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tau&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;samples&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; Broadside: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.0 µs&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.0&lt;/code&gt; samples. At 45°: about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;41.2 µs&lt;/code&gt;, about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.98&lt;/code&gt; samples at 48 kHz. Delay-and-sum at 48 kHz is a fractional-sample shift, not a multi-tap “room” filter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Using degrees in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.sin&lt;/code&gt; without converting to radians gives a nonsense delay (the 45° case will not be ~2 samples). Forgetting \(\sin\theta\) and using \(d/c\) for every angle makes broadside look like endfire. A 16 kHz print of “samples” is about 0.66 at 45°, so a hardcoded 48 kHz assumption has to be visible in the script.&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Delay-and-sum.&lt;/strong&gt; For 2 mics spaced \(d=2\,\mathrm{cm}\), \(f=2\,\mathrm{kHz}\), speed of sound \(343\,\mathrm{m/s}\), compute the inter-mic delay for broadside vs 45° incidence (far-field).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;GSC sketch.&lt;/strong&gt; Label FBF, BM, adaptive filters on a diagram; mark where a neural postfilter would attach.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Product brief.&lt;/strong&gt; One page: propose a dual-mic native mode for Mezon that reuses the existing mono DF3 ONNX and adds a delay-and-sum front-end only.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reading map.&lt;/strong&gt; Skim one hybrid abstract (GSC+DeepFilterNet2 or IVA+GTCRN); write three bullets on what the classical stage contributes vs the neural stage.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Broadside delay is 0. At 45°, \(\tau=d\sin\theta/c\) is about 41 µs, roughly two samples at 48 kHz.&lt;/li&gt;
  &lt;li&gt;Neural postfilter attaches to the GSC output, after the adaptive subtraction, on a single channel.&lt;/li&gt;
  &lt;li&gt;Delay-and-sum emits one waveform; the existing mono ONNX does not grow a second input.&lt;/li&gt;
  &lt;li&gt;The classical stage uses the extra microphone (nulls or independence). The neural stage is still a single-channel enhancer on whatever that spatial stage passed through.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Van Trees, &lt;em&gt;Optimum Array Processing&lt;/em&gt; — MVDR / beamforming foundations.&lt;/li&gt;
  &lt;li&gt;Griffiths &amp;amp; Jim — generalized sidelobe canceller (classic GSC).&lt;/li&gt;
  &lt;li&gt;WebRTC / mobile multi-mic AEC+BF engineering notes (platform docs).&lt;/li&gt;
  &lt;li&gt;Survey hybrids: GSC–DeepFilterNet2 (drone ego-noise), IVA+GTCRN dual-channel SE (name-level pointers).&lt;/li&gt;
  &lt;li&gt;DeepFilterNet2 paper — mono neural stage often used &lt;em&gt;after&lt;/em&gt; classical spatial cleaning.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=A1n5Hhwtz78&quot;&gt;What is Beamforming? (“the best explanation I’ve ever heard”)&lt;/a&gt; — Iain Explains Signals, Systems, and Digital Comms, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the delay that lines up one direction before the sum. Delay-and-sum is the front-end geometry this lesson starts from; GSC and IVA are what you reach for when that sum is not enough.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-04 AEC context and WebRTC APM</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter03/03_04_aec_and_webrtc_apm/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter03/03_04_aec_and_webrtc_apm</id>
   <content type="html">&lt;p&gt;Nothing destroys a video call faster than hearing your own voice bounce back out of a teammate’s laptop speakers half a second late. Yet when users file a bug saying “the noise suppressor is broken—I hear echo!”, they are blaming the wrong block. &lt;strong&gt;Acoustic Echo Cancellation (AEC)&lt;/strong&gt; is the sibling of noise suppression: instead of fighting unknown ambient noise, AEC holds a &lt;strong&gt;cheat sheet&lt;/strong&gt;—the exact far-end audio \(x[t]\) currently playing out of the loudspeaker!&lt;/p&gt;

&lt;p&gt;In real browsers and VoIP stacks, AEC, NS, and Automatic Gain Control (AGC) live together inside the &lt;strong&gt;WebRTC Audio Processing Module (APM)&lt;/strong&gt;. This lesson explains how reference-driven adaptive cancellation works, why &lt;strong&gt;double-talk&lt;/strong&gt; is its hardest failure mode, and where a neural suppressor like DeepFilterNet3 must be placed in the chain.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/noise-mixture.png&quot; alt=&quot;Clean speech, additive noise, and their sum — the shape of a residual after echo has been subtracted&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. After a linear AEC, the residual is an additive mixture of near-end speech and whatever the canceller did not remove; this cartoon is that mixture, not the echo path itself.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (echo as reference-driven convolution, NLMS adaptive filtering, WebRTC APM block ordering) → AEC vs. NS comparison &amp;amp; residual echo → Worked example: hand-tracing one double-talk frame (residual echo power \(0.0025\) vs. total error power \(0.7225\)!) → Explanation: 3 steps explaining why block order (HPF → AEC → NS → AGC) is sacred → Integration checklist, Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-acoustic-echo-cancellation-and-the-webrtc-audio-chain&quot;&gt;Key ideas: Acoustic Echo Cancellation and the WebRTC Audio Chain&lt;/h2&gt;

&lt;h3 id=&quot;1-echo-is-known-reference-convolution-not-blind-noise&quot;&gt;1. Echo Is Known-Reference Convolution, Not Blind Noise&lt;/h3&gt;
&lt;p&gt;The microphone captures \(y[t] = s[t] + (h * x)[t] + n[t]\). Because the device &lt;em&gt;already knows&lt;/em&gt; the far-end render signal \(x[t]\), AEC runs an adaptive filter \(\hat{h}\) to predict and subtract the loudspeaker echo: \(e[t] = y[t] - (\hat{h} * x)[t]\). Blind noise suppression has no reference \(x\) and cannot distinguish loud far-end speech from near-end speech.&lt;/p&gt;

&lt;h3 id=&quot;2-double-talk-and-adaptive-filter-divergence&quot;&gt;2. Double-Talk and Adaptive Filter Divergence&lt;/h3&gt;
&lt;p&gt;The adaptive filter updates \(\hat{h}\) using the residual error \(e[t]\). When &lt;em&gt;both&lt;/em&gt; sides speak at once (&lt;strong&gt;double-talk&lt;/strong&gt;), \(e[t]\) is dominated by the near-end speaker \(s[t]\) rather than echo! If the filter keeps adapting blindly during double-talk, it diverges and corrupts \(\hat{h}\)—so every production AEC includes a double-talk detector to freeze or slow adaptation.&lt;/p&gt;

&lt;h3 id=&quot;3-why-block-ordering-in-webrtc-apm-matters&quot;&gt;3. Why Block Ordering in WebRTC APM Matters&lt;/h3&gt;
&lt;p&gt;WebRTC APM runs &lt;strong&gt;HPF → AEC → NS → AGC&lt;/strong&gt;. Putting AGC &lt;em&gt;before&lt;/em&gt; AEC modulates the echo path gain dynamically, forcing \(\hat{h}\) to chase a moving target; running neural NS &lt;em&gt;before&lt;/em&gt; AEC destroys the linear correlation between \(x\) and \(y\) that AEC relies on!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will draw the near-end / far-end signal flow with echo path \(\mathbf{h}\), explain why a reference-driven adaptive filter differs from blind NS, list the major WebRTC APM components (AEC, NS, AGC, HPF, VAD), and state practical constraints (delay, clock drift, nonlinear distortion) that leak residual echo into the NS stage.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Demo narrative: hear echo vs noise; identify the far-end reference.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Echo model \(y = s + \mathbf{h}*\mathbf{x} + n\); adaptive filter estimate \(\hat{\mathbf{h}}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — WebRTC APM pipeline tour (conceptual blocks, not line-by-line source).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Residual echo after AEC → why NS / neural postfilters still matter.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Pitfalls, exercises, checklist for product insertion points.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;echo-is-structured-noise&quot;&gt;Echo is structured “noise”&lt;/h3&gt;

&lt;p&gt;Near-end microphone signal:&lt;/p&gt;

\[y[t] = s[t] + \underbrace{(h * x)[t]}_{\text{echo}} + n[t],\]

&lt;p&gt;where \(x[t]\) is the &lt;strong&gt;far-end&lt;/strong&gt; signal (known to the device that renders it), \(h\) is the acoustic echo path (room + loudspeaker + mic), \(s\) is near-end speech, and \(n\) is ambient noise.&lt;/p&gt;

&lt;p&gt;AEC estimates \(\hat{h}\) (or an equivalent frequency-domain filter) and forms&lt;/p&gt;

\[e[t] = y[t] - (\hat{h} * x)[t].\]

&lt;p&gt;If \(\hat{h}\approx h\) and the path is linear and slowly varying, \(e\approx s+n\)—then a &lt;strong&gt;noise suppressor&lt;/strong&gt; can focus on \(n\) without fighting a loud echo replica.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;far-end x ──► loudspeaker ──► room h ──► mic y
near-end s ────────────────────────────► mic y
ambient n  ────────────────────────────► mic y
AEC:  e = y − ĥ ∗ x
NS:   operates on e, not on raw y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The residual after that subtraction is what a later suppressor actually hears. When the canceller is doing its job, \(e\) looks like the additive mixture in the figure: near-end speech plus whatever did not cancel (ambient noise, and a smaller leftover echo). The figure is not a drawing of the room path.&lt;/p&gt;

&lt;h3 id=&quot;adaptive-filter-intuition-nlms-sketch&quot;&gt;Adaptive filter intuition (NLMS sketch)&lt;/h3&gt;

&lt;p&gt;In the time domain, an FIR echo path \(\mathbf{h}\) of length \(L\) is updated with a normalized LMS-style rule:&lt;/p&gt;

\[\mathbf{h}_{\ell+1} = \mathbf{h}_\ell + \mu \frac{e_\ell\,\mathbf{x}_\ell}{\|\mathbf{x}_\ell\|^2 + \varepsilon},\]

&lt;p&gt;where \(\mathbf{x}_\ell\) is the far-end tap vector. Frequency-domain / partitioned-block adaptive filters (as in many WebRTC-oriented AECs) do the same idea with better complexity and delay control.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kalman connection (03-03):&lt;/strong&gt; covariance-aware step sizes replace the scalar \(\mu\); the product idea is identical—track \(\mathbf{h}\) recursively.&lt;/p&gt;

&lt;h3 id=&quot;why-aec--ns&quot;&gt;Why AEC ≠ NS&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt; &lt;/th&gt;
      &lt;th&gt;AEC&lt;/th&gt;
      &lt;th&gt;NS&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Reference&lt;/td&gt;
      &lt;td&gt;Far-end \(x\) required&lt;/td&gt;
      &lt;td&gt;Usually blind&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Target impairment&lt;/td&gt;
      &lt;td&gt;Echo \(h*x\)&lt;/td&gt;
      &lt;td&gt;Ambient \(n\) / interferers&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Failure mode&lt;/td&gt;
      &lt;td&gt;Delay misalignment, double-talk, nonlinear spk&lt;/td&gt;
      &lt;td&gt;Non-stationary noise, musical artifacts&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Typical place&lt;/td&gt;
      &lt;td&gt;Early in APM&lt;/td&gt;
      &lt;td&gt;After AEC / with residual-echo suppression&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Double-talk (near-end and far-end speak together) is the classic AEC stress case: the adaptive filter must freeze or slow updates so near-end speech is not mistaken for echo.&lt;/p&gt;

&lt;h3 id=&quot;webrtc-apm--mental-model&quot;&gt;WebRTC APM — mental model&lt;/h3&gt;

&lt;p&gt;The WebRTC &lt;strong&gt;Audio Processing Module&lt;/strong&gt; is a battle-tested chain used broadly in browsers and native stacks. Mentally order the blocks as:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;High-pass filter&lt;/strong&gt; — remove DC / rumble.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Echo canceller (AEC / AECM)&lt;/strong&gt; — reference-driven cancellation; mobile may use lighter variants.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Noise suppression&lt;/strong&gt; — classical spectral / Wiener-style NS (configurable levels).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Automatic gain control (AGC)&lt;/strong&gt; — level management (can interact badly with NS if ordered poorly).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Voice detection / other extras&lt;/strong&gt; — depending on build flags and API era.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Exact ordering and naming evolve across WebRTC versions; treat the above as an &lt;strong&gt;architecture cartoon&lt;/strong&gt; for teaching, and verify against current &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioProcessing&lt;/code&gt; docs when integrating.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Product relevance:&lt;/strong&gt; Mezon and many LiveKit / WebRTC apps may rely on browser AEC &lt;strong&gt;and&lt;/strong&gt; inject a neural NS (DeepFilterNet3 via AudioWorklet). You must know whether AEC already ran, whether you still see residual echo, and whether your NS was trained to treat residual echo as “noise.”&lt;/p&gt;

&lt;h3 id=&quot;residual-echo-and-neural-postfilters&quot;&gt;Residual echo and neural postfilters&lt;/h3&gt;

&lt;p&gt;Linear AEC leaves leftovers when:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Loudspeaker distortion is nonlinear,&lt;/li&gt;
  &lt;li&gt;Delay estimation is wrong (buffering, Bluetooth),&lt;/li&gt;
  &lt;li&gt;Clock drift between render and capture,&lt;/li&gt;
  &lt;li&gt;Soft furniture / moving talkers change \(h\) quickly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hybrid research (ULCNet + adaptive filter, etc.) trains a small network on the &lt;strong&gt;AEC residual&lt;/strong&gt;. Practically: measure ERLE (echo return loss enhancement) before/after AEC; if residual echo remains audible, either fix delay alignment or add a residual-echo suppressor—not only a generic NS.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-tracing-double-talk-and-why-apm-block-order-is-sacred&quot;&gt;Explanation: Tracing Double-Talk and Why APM Block Order Is Sacred&lt;/h3&gt;

&lt;h4 id=&quot;step-1-check-a-single-double-talk-frame-by-hand&quot;&gt;Step 1: Check a single double-talk frame by hand&lt;/h4&gt;
&lt;p&gt;Suppose the true room coupling is \(h = 0.5\), our adaptive estimate is already close at \(\hat{h} = 0.45\), and on frame 3 both sides speak: far-end \(x = 1.0\) and near-end \(s = 0.8\).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;True leftover echo: \((h - \hat{h})x = 0.05 \times 1.0 = 0.05\) (power \(0.0025\)—tiny!).&lt;/li&gt;
  &lt;li&gt;Measured error seen by the NLMS rule: \(e = s + 0.05 = 0.85\) (power \(0.7225\)—nearly &lt;strong&gt;300× larger&lt;/strong&gt;!).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If NLMS updates \(\hat{h}\) using \(e = 0.85\) with step \(\mu = 0.5\), it pushes \(\hat{h}\) from \(0.45\) up to \(0.45 + 0.5(0.85) = 0.875\)—completely ruining a nearly converged echo filter!&lt;/p&gt;

&lt;h4 id=&quot;step-2-why-aec-must-run-before-neural-ns&quot;&gt;Step 2: Why AEC MUST run before neural NS&lt;/h4&gt;
&lt;p&gt;A linear adaptive filter needs an untouched linear convolution \(h * x\) to cancel it. If a nonlinear neural noise suppressor runs &lt;em&gt;before&lt;/em&gt; AEC, it distorts the echo waveform so that no linear filter \(\hat{h}\) can match \(x\) anymore—leaving loud metallic echo bursts!&lt;/p&gt;

&lt;h4 id=&quot;step-3-why-agc-must-run-after-aec-and-avoid-duplicate-agcs&quot;&gt;Step 3: Why AGC MUST run after AEC (and avoid duplicate AGCs)&lt;/h4&gt;
&lt;p&gt;If Automatic Gain Control cranks microphone gain up and down &lt;em&gt;before&lt;/em&gt; AEC, the apparent room path \(h\) suddenly jumps every time someone pauses, forcing AEC to re-converge from scratch. Keep one clean chain: &lt;strong&gt;HPF → AEC → Neural/Classical NS → Single AGC&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Summary of the voice-processing chain:&lt;/p&gt;

\[y = s + h*x + n
\;\xrightarrow{\text{HPF}}\;
\xrightarrow{\text{AEC } (e = y - \hat{h}*x)}
\;\xrightarrow{\text{NS (e.g. DF3)}}\;
\xrightarrow{\text{AGC}}
\text{Clean send track}.\]

&lt;h2 id=&quot;integration-checklist-browser--native&quot;&gt;Integration checklist (browser / native)&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Confirm a &lt;strong&gt;far-end reference&lt;/strong&gt; is actually provided to AEC (loopback / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getUserMedia&lt;/code&gt; constraints / native ADM).&lt;/li&gt;
  &lt;li&gt;Measure round-trip buffering; align reference delay.&lt;/li&gt;
  &lt;li&gt;Test &lt;strong&gt;double-talk&lt;/strong&gt; clips explicitly.&lt;/li&gt;
  &lt;li&gt;Decide NS insertion: inside APM, after APM PCM, or AudioWorklet neural NS (Ch. 05, 07).&lt;/li&gt;
  &lt;li&gt;Disable duplicate AGC stages that fight each other.&lt;/li&gt;
  &lt;li&gt;Log whether echo or noise dominates customer complaints—triage AEC vs NS.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Running neural NS on a signal that still contains full-volume echo → over-suppression of near-end speech during far-end playback.&lt;/li&gt;
  &lt;li&gt;Assuming browser AEC is on without checking platform quirks (especially mobile OS effects).&lt;/li&gt;
  &lt;li&gt;Training / evaluating NS only on additive noise datasets (DNS-style) then deploying into echo-heavy laptop speakers.&lt;/li&gt;
  &lt;li&gt;Placing AGC before AEC so gains modulate the echo path and confuse adaptation.&lt;/li&gt;
  &lt;li&gt;Confusing &lt;strong&gt;acoustic&lt;/strong&gt; echo with &lt;strong&gt;line&lt;/strong&gt; echo in telephony gateways.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; A numeric cartoon of residual echo power versus the error you actually measure, and what one double-talk frame does. This is not a WebRTC build and it does not call the Audio Processing Module.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;far&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;near&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# double-talk only on frame 3
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.45&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;residual_echo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hhat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;far&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;near&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;residual_echo&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;residual echo power&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_echo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;measured error power&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; Residual echo power stays small: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0, 0.0001, 0.0025, 0.0025, 0.0002, 0.0036]&lt;/code&gt;. Measured error power matches it on every frame except frame 3, where near-end speech pushes it to about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.7225&lt;/code&gt; while the true leftover echo is still &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.0025&lt;/code&gt;. Adapting \(\hat{h}\) on that frame would treat the talker as echo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; If frame 3’s two powers match, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;near&lt;/code&gt; was left at zero and you are not in double-talk. If residual echo power is large on every voiced far-end frame, \(\hat{h}\) is far from \(h\) (try swapping 0.5 and 0.45). Interpreting the error power as a noise floor and feeding it to a Wiener gain will suppress the near-end talker. Nothing here instantiates WebRTC AEC.&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Signal-flow diagram.&lt;/strong&gt; Draw capture, render, \(\hat{h}\), error \(e\), and NS. Mark where AudioWorklet neural NS would sit in a web app.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Delay lab.&lt;/strong&gt; Explain what happens to NLMS if the reference is 40 ms early vs 40 ms late relative to the mic echo.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;APM config reading.&lt;/strong&gt; Skim current WebRTC APM docs; list the toggle names for NS level and AEC; note defaults.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Triage table.&lt;/strong&gt; Write a support playbook: symptom → likely AEC vs NS vs AGC cause → first diagnostic step.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Neural NS sits on \(e\), after \(\hat{h}\). In a browser graph that is often after the platform AEC and before the encoder.&lt;/li&gt;
  &lt;li&gt;A reference that is 40 ms early or late misses the taps that actually hold \(h\), so \(e\) still contains echo and the filter adapts on the wrong lag.&lt;/li&gt;
  &lt;li&gt;Look for the NS level and AEC enable on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioProcessing&lt;/code&gt;; names move between releases, so quote the revision you read.&lt;/li&gt;
  &lt;li&gt;Far-end playback with no near-end talker is the AEC test. Near-end talker in noise, far-end silent, is the NS test. A level jump when either party pauses is often AGC.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;WebRTC Audio Processing Module documentation and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioProcessing&lt;/code&gt; API (project website / source).&lt;/li&gt;
  &lt;li&gt;SpeexDSP echo canceller / preprocessor docs (related classical stack).&lt;/li&gt;
  &lt;li&gt;Haykin, &lt;em&gt;Adaptive Filter Theory&lt;/em&gt; — NLMS / frequency-domain adaptive filters.&lt;/li&gt;
  &lt;li&gt;Hybrid AENR survey pointers: ULCNet + adaptive filter / Align-ULCNet (name-level; residual echo + noise).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Revamping Audio Quality for RTC Part 1: Beryl Echo Cancellation&lt;/td&gt;
          &lt;td&gt;Sriram Srinivasan and Hoang Do](https://www.youtube.com/watch?v=lapq9zvUd-k) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the loudspeaker-to-microphone path and where echo removal sits in a real-time audio chain. That placement is the WebRTC APM context of the lesson.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. The echo section shows noise suppression and echo cancellation as neighbors, which is why this lesson refuses to collapse them into one switch.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-03 Kalman-style tracking (intuition)</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter03/03_03_kalman_tracking/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter03/03_03_kalman_tracking</id>
   <content type="html">&lt;p&gt;Imagine tracking a speaker’s room echo path as someone walks across a conference room, or tracking a slowly drifting noise floor during a live call. Estimating from scratch on every single 10 ms frame wastes everything you already learned one frame ago; freezing the old estimate forever falls behind the room.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Kalman filter&lt;/strong&gt; solves that tension cleanly: it is not “just another spectral mask,” but a &lt;strong&gt;recursive Bayesian tracker&lt;/strong&gt; that alternates between &lt;em&gt;predicting&lt;/em&gt; where the hidden state moved and &lt;em&gt;updating&lt;/em&gt; that belief with the latest microphone sample—weighted by how uncertain each side is. This lesson builds the Kalman intuition at the block-diagram level and shows why modern low-complexity audio products pair a classical Kalman/adaptive linear filter with a tiny neural residual cleaner.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/spectral-subtraction-wiener.png&quot; alt=&quot;A tracked noise floor beside the SNR gain that floor is used to compute&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The orange trace is a noise-floor tracker; the curve on the right is the gain that tracker feeds, which is the piece a Kalman update is trying to stabilize.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (state-space dynamics, Kalman gain as adaptive Wiener, hybrid classical + neural AENR) → Scalar predict–update model &amp;amp; speech/AEC state-space table → Worked example: tracing one concrete scalar predict–update step by hand for \(r = 0.1\) vs. \(r = 10.0\) → Explanation: 3 steps explaining why Kalman is “Wiener plus memory” → Checklist, Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-recursive-state-space-estimation-in-audio&quot;&gt;Key ideas: Recursive State-Space Estimation in Audio&lt;/h2&gt;

&lt;h3 id=&quot;1-state-space-modeling--separating-dynamics-from-observation&quot;&gt;1. State-Space Modeling — Separating Dynamics from Observation&lt;/h3&gt;
&lt;p&gt;A state-space model writes two equations: a &lt;strong&gt;process equation&lt;/strong&gt; describing how the hidden state \(x_\ell\) evolves over time (with process-noise variance \(q\)), and a &lt;strong&gt;measurement equation&lt;/strong&gt; describing how the noisy microphone \(y_\ell\) observes it (with measurement-noise variance \(r\)).&lt;/p&gt;

&lt;h3 id=&quot;2-kalman-gain-k--dynamic-trust-knob&quot;&gt;2. Kalman Gain \(K\) = Dynamic Trust Knob&lt;/h3&gt;
&lt;p&gt;At every hop, the predicted variance grows to \(p^- = p + q\), and the &lt;strong&gt;Kalman gain&lt;/strong&gt; \(K = p^- / (p^- + r)\) decides how much to trust the fresh microphone reading. Notice its exact algebraic twin: writing \(\xi = p^-/r\) turns \(K\) into \(\xi / (\xi + 1)\)—the Wiener gain from Lesson 03-02, now upgraded with evolving memory!&lt;/p&gt;

&lt;h3 id=&quot;3-the-hybrid-classical--neural-product-pattern&quot;&gt;3. The Hybrid Classical + Neural Product Pattern&lt;/h3&gt;
&lt;p&gt;In acoustic echo and noise reduction (AENR), asking a neural network to learn a 200-tap linear room echo path from scratch is wasteful. Production hybrids (e.g., Kalman/NLMS AEC \(\to\) ULCNet / DeepFilterNet postfilter) let a recursive linear tracker cancel the linear echo first, then hand the clean residual to a lightweight neural network.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will explain the predict–update loop with process and measurement noise covariances, map speech enhancement to a state-space sketch, contrast Kalman tracking with per-frame Wiener gains, and identify product patterns where Kalman (or RLS/LMS adaptive filters) front-end a neural residual suppressor.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Why recursive tracking beats “estimate from scratch every frame.”&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — State-space model, predict step, Kalman gain intuition (no giant matrix slog).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Speech/AEC instantiations: tracking AR speech coefficients or echo path.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Hybrid story: Align-ULCNet-style Kalman AEC + neural postfilter (survey pointer).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Pitfalls, exercises, link forward to WebRTC APM (03-04).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;the-one-sentence-kalman-idea&quot;&gt;The one-sentence Kalman idea&lt;/h3&gt;

&lt;p&gt;Maintain a belief about a hidden state \(x_\ell\) (for example, clean speech samples, LPC coefficients, or an echo-path impulse response). Each frame:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Predict&lt;/strong&gt; using dynamics: \(x_{\ell\vert\ell-1} = A x_{\ell-1\vert\ell-1}\) (plus process noise uncertainty).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Update&lt;/strong&gt; with measurement \(y_\ell = H x_\ell + v_\ell\): pull the prediction toward the observation in proportion to how trustworthy each is.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;strong&gt;Kalman gain&lt;/strong&gt; \(K_\ell\) is large when the measurement is reliable relative to the prediction—so you trust the mic more—and small when measurements are noisy—so you coast on the model.&lt;/p&gt;

&lt;h3 id=&quot;tiny-scalar-cartoon&quot;&gt;Tiny scalar cartoon&lt;/h3&gt;

&lt;p&gt;Suppose a scalar state with&lt;/p&gt;

\[x_\ell = x_{\ell-1} + w_\ell, \qquad y_\ell = x_\ell + v_\ell,\]

&lt;p&gt;variances \(q=\mathrm{Var}(w)\), \(r=\mathrm{Var}(v)\). After predicting variance \(p^{-}=p+q\), the gain is&lt;/p&gt;

\[K = \frac{p^{-}}{p^{-} + r}, \qquad \hat{x} = \hat{x}^{-} + K\bigl(y - \hat{x}^{-}\bigr).\]

&lt;p&gt;Compare to Wiener: \(K\) looks like \(\xi/(\xi+1)\) if you read \(p^{-}/r\) as a prior SNR. Kalman is Wiener &lt;strong&gt;plus memory&lt;/strong&gt; through the predicted state and variance. In the figure, the orange noise floor is the kind of level a recursive tracker maintains, and the blue curve is the gain that floor would feed. A Kalman step is one statistically explicit way to update that floor; the picture itself is still classical NS, not a block diagram of the filter.&lt;/p&gt;

&lt;h3 id=&quot;why-speech-engineers-care&quot;&gt;Why speech engineers care&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Use case&lt;/th&gt;
      &lt;th&gt;State \(x\)&lt;/th&gt;
      &lt;th&gt;Measurement \(y\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Clean-speech tracker&lt;/td&gt;
      &lt;td&gt;speech samples / spectral amplitudes&lt;/td&gt;
      &lt;td&gt;noisy mic&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;LPC / formant tracker&lt;/td&gt;
      &lt;td&gt;AR coefficients&lt;/td&gt;
      &lt;td&gt;residual / short-time spectrum&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;AEC path estimate&lt;/td&gt;
      &lt;td&gt;echo impulse response \(\mathbf{h}\)&lt;/td&gt;
      &lt;td&gt;mic, with far-end reference as regressor&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Residual echo PSD&lt;/td&gt;
      &lt;td&gt;residual echo power&lt;/td&gt;
      &lt;td&gt;error after adaptive filter&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Adaptive filters&lt;/strong&gt; (NLMS, RLS) used in AEC are close cousins: they recursively estimate an echo path. Kalman provides a statistically motivated gain schedule; NLMS provides a cheap normalized step-size heuristic. WebRTC APM and SpeexDSP historically lean on practical adaptive filters; research hybrids often say “Kalman AEC” when they mean a recursive echo-path tracker with covariance-aware steps.&lt;/p&gt;

&lt;h3 id=&quot;hybrid-classical--neural-product-pattern&quot;&gt;Hybrid classical + neural (product pattern)&lt;/h3&gt;

&lt;p&gt;A pattern that keeps reappearing in low-complexity AENR (acoustic echo and noise reduction):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Classical adaptive filter / Kalman cancels the &lt;strong&gt;linear&lt;/strong&gt; echo given a far-end reference.&lt;/li&gt;
  &lt;li&gt;A &lt;strong&gt;small neural&lt;/strong&gt; network (ULCNet-class, GTCRN-class, or DeepFilterNet postfilter) removes residual echo + noise that the linear model cannot catch (nonlinear loudspeaker distortion, non-stationary noise).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Survey pointers (name-level only, Chapter 04 will expand SE models): Align-ULCNet and related ULCNet+adaptive-filter hybrids; drone / GSC+DeepFilterNet2 pipelines where a spatial front-end feeds a neural enhancer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Engineering moral:&lt;/strong&gt; do not ask the neural net to learn pure linear echo cancellation from scratch if you already have a reference signal—give it a cleaned residual.&lt;/p&gt;

&lt;h3 id=&quot;relation-to-wiener-03-02&quot;&gt;Relation to Wiener (03-02)&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Wiener (typical STFT form): &lt;strong&gt;stateless per frame&lt;/strong&gt; given \(\xi_\ell\) (though \(\xi\) itself may be recursive).&lt;/li&gt;
  &lt;li&gt;Kalman: &lt;strong&gt;stateful&lt;/strong&gt;; the gain depends on predicted covariance, not only on an SNR number.&lt;/li&gt;
  &lt;li&gt;Decision-directed SNR tracking is a &lt;em&gt;poor man’s&lt;/em&gt; recursive prior—conceptually between naive Wiener and full Kalman.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-tracing-one-scalar-kalman-update-step-by-hand&quot;&gt;Explanation: Tracing One Scalar Kalman Update Step by Hand&lt;/h3&gt;

&lt;p&gt;Suppose our previous state estimate is \(\hat{x}_{0} = 2.0\) with uncertainty variance \(p = 1.0\), process noise \(q = 0.1\), and a fresh microphone measurement arrives at \(y_1 = 5.0\):&lt;/p&gt;

&lt;h4 id=&quot;step-1-predict-uncertainty-grows&quot;&gt;Step 1: Predict (uncertainty grows)&lt;/h4&gt;
&lt;p&gt;Before seeing \(y_1\), our prediction stays \(\hat{x}^- = 2.0\), and its variance grows by the process noise:
\(p^- = p + q = 1.0 + 0.1 = 1.1.\)&lt;/p&gt;

&lt;h4 id=&quot;step-2-compute-the-kalman-gain-k-under-clean-vs-noisy-sensors&quot;&gt;Step 2: Compute the Kalman gain \(K\) under clean vs. noisy sensors&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Trustworthy sensor (\(r = 0.1\)):&lt;/strong&gt; \(K = \frac{1.1}{1.1 + 0.1} \approx 0.917\) \(\implies \hat{x}_1 = 2.0 + 0.917(5.0 - 2.0) = 4.75\) (jumps straight toward the fresh measurement!), and posterior variance collapses to \(p_1 = (1 - 0.917)(1.1) \approx 0.091\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Noisy sensor (\(r = 10.0\)):&lt;/strong&gt; \(K = \frac{1.1}{1.1 + 10.0} \approx 0.099\) \(\implies \hat{x}_1 = 2.0 + 0.099(5.0 - 2.0) = 2.30\) (barely budges—coasts safely on the prior!), and posterior variance stays near \(0.99\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;step-3-why-covariance-aware-steps-beat-fixed-step-sizes-in-aec&quot;&gt;Step 3: Why covariance-aware steps beat fixed step sizes in AEC&lt;/h4&gt;
&lt;p&gt;When the far-end talker is silent or double-talk erupts, the effective measurement noise \(r\) spikes—automatically shrinking the Kalman gain \(K \to 0\) and freezing the echo-path estimate without brittle manual switches!&lt;/p&gt;

&lt;p&gt;Summary of the Kalman loop:&lt;/p&gt;

\[(\hat{x}_{\ell-1}, p_{\ell-1})
\;\xrightarrow{\text{Predict } (+q)}\;
(\hat{x}^-, p^-)
\;\xrightarrow{K = \frac{p^-}{p^- + r}}\;
\hat{x}_\ell = \hat{x}^- + K(y_\ell - \hat{x}^-).\]

&lt;h2 id=&quot;checklist-when-to-reach-for-kalman-style-thinking&quot;&gt;Checklist: when to reach for Kalman-style thinking&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;You have a &lt;strong&gt;dynamics model&lt;/strong&gt; (echo path slowly varying; speech AR envelope).&lt;/li&gt;
  &lt;li&gt;You have a &lt;strong&gt;reference&lt;/strong&gt; (far-end audio for AEC).&lt;/li&gt;
  &lt;li&gt;Residuals after a linear canceller still need a nonlinear cleaner.&lt;/li&gt;
  &lt;li&gt;You must run &lt;strong&gt;always-on&lt;/strong&gt; with bounded CPU—prefer classical adaptive filter + tiny NS over a huge end-to-end network.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Treating Kalman as magic noise reduction without specifying state and measurement models.&lt;/li&gt;
  &lt;li&gt;Underestimating model mismatch: wrong \(A\) or \(H\) → biased tracking.&lt;/li&gt;
  &lt;li&gt;Letting covariance inflate numerically (need Joseph form / SPD fixes in real code).&lt;/li&gt;
  &lt;li&gt;Using a full Kalman on huge STFT state vectors when a diagonal / per-bin approximation (or NLMS) is the practical choice.&lt;/li&gt;
  &lt;li&gt;Forgetting that neural residual suppressors can &lt;strong&gt;re-add latency&lt;/strong&gt; and streaming state (Chapters 05–06).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; One scalar predict–update step. Print the Kalman gain for a trustworthy measurement and for a noisy one.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;kalman_gain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;p_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p_pred&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;10.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;K&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;kalman_gain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;K&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;K&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; Prior variance after the predict step is \(1.1\). For \(r=0.1\), \(K\approx 0.917\) (trust the measurement). For \(r=10\), \(K\approx 0.099\) (coast on the prediction). Same shape as a Wiener gain: large when the “SNR” \(p^{-}/r\) is large.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Updating \(p\) with the measurement before computing \(K\) changes both numbers. Swapping \(q\) and \(r\) makes the noisy sensor look more trustworthy than the clean one. This is a scalar cartoon of the gain, not a speech Kalman filter and not a noise-PSD tracker implementation.&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Scalar Kalman.&lt;/strong&gt; Implement the scalar predict–update equations in a notebook; drive \(x\) with a slow sine and observe \(K\) as you change \(r\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mapping.&lt;/strong&gt; Write a one-page diagram mapping AEC to state \(=\mathbf{h}\), regressors \(=\) far-end taps, measurement \(=\) mic. Mark where a neural postfilter sits.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Compare.&lt;/strong&gt; List three similarities and three differences between decision-directed Wiener and Kalman tracking for speech PSD.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Design brief.&lt;/strong&gt; For a browser call with loudspeaker echo, propose a hybrid: WebRTC AEC → residual neural NS. State what each block is responsible for.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(K\) should fall as \(r\) rises, and the estimate should lag a fast wiggle in \(y\) when \(r\) is large.&lt;/li&gt;
  &lt;li&gt;Far-end taps are the regressor; the mic is \(y\); the neural block sees \(e=y-\hat{h}*x\), not the raw mic.&lt;/li&gt;
  &lt;li&gt;Both are recursive and both shrink the gain when noise dominates. Wiener (decision-directed) tracks a power ratio; Kalman tracks a state and a variance, and it has an explicit process model.&lt;/li&gt;
  &lt;li&gt;AEC owns linear echo given the far-end reference. The neural stage owns whatever is left: residual echo and ambient noise. Do not ask the network to rediscover \(\mathbf{h}\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;R. E. Kalman, “A new approach to linear filtering and prediction problems,” &lt;em&gt;ASME J. Basic Eng.&lt;/em&gt;, 1960 (foundational).&lt;/li&gt;
  &lt;li&gt;Adaptive filter chapters in Haykin, &lt;em&gt;Adaptive Filter Theory&lt;/em&gt; (NLMS/RLS as practical AEC engines).&lt;/li&gt;
  &lt;li&gt;WebRTC Audio Processing Module overview (engineering AEC+NS chain).&lt;/li&gt;
  &lt;li&gt;Survey pointers on hybrid Kalman/ULCNet AENR (Align-ULCNet and related ULCNet hybrid papers—name-level).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Why Use Kalman Filters?&lt;/td&gt;
          &lt;td&gt;Understanding Kalman Filters, Part 1](https://www.youtube.com/watch?v=mwn8xhgNpFY) — MATLAB, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the predict-then-correct picture. A noise tracker that only updates a floor is the same two-step idea with a much smaller state.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-DiZGpAh7T4&quot;&gt;Kalman Filter - VISUALLY EXPLAINED!&lt;/a&gt; — Kapil Sachdeva, English. The visual update is the part to watch: uncertainty shrinks when a measurement arrives, which is the intuition behind a recursive speech tracker.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-02 Wiener filtering for speech</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter03/03_02_wiener_filtering/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter03/03_02_wiener_filtering</id>
   <content type="html">&lt;p&gt;Where spectral subtraction acts like a blunt hatchet—“subtract the floor, clip negatives to zero”—the &lt;strong&gt;Wiener filter&lt;/strong&gt; acts like a smooth dimmer switch: at every frequency bin, it asks &lt;em&gt;“what fraction of this bin’s power belongs to speech?”&lt;/em&gt; and multiplies by that exact ratio \(G = \xi / (\xi + 1)\).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/spectral-subtraction-wiener.png&quot; alt=&quot;Wiener gain versus a priori SNR, beside the spectral-subtraction bars it softens&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The Wiener gain is \(1/2\) (\(-6\,\mathrm{dB}\)) when speech and noise power are equal, and it never becomes the hard holes of the subtraction bars on the left.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This single formula is the conceptual bridge from 1940s statistical estimation to 2020s neural speech enhancement: an Ideal Ratio Mask (IRM) in deep learning is &lt;em&gt;mathematically identical&lt;/em&gt; to the Wiener gain, and DeepFilterNet’s ERB gains are its learned, data-driven descendants. This lesson derives \(G = \xi / (\xi + 1)\), distinguishes a priori SNR \(\xi\) from a posteriori SNR \(\gamma\), and walks through Ephraim–Malah’s celebrated decision-directed tracker.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (MMSE estimation, a priori vs. a posteriori SNR, decision-directed smoothing) → Wiener formula, Ephraim–Malah recursion &amp;amp; soft-mask bridge → Worked example: evaluating \(G\) at \(-10, 0, +10\,\mathrm{dB}\) and tracing one decision-directed frame by hand → Explanation: 3 steps deriving \(G = \xi / (\xi + 1)\) from mean-squared error → Tuning checklist, Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-minimum-mean-square-error-mmse-speech-estimation&quot;&gt;Key ideas: Minimum Mean-Square Error (MMSE) Speech Estimation&lt;/h2&gt;

&lt;h3 id=&quot;1-from-heuristic-subtraction-to-optimal-mmse-gain&quot;&gt;1. From Heuristic Subtraction to Optimal MMSE Gain&lt;/h3&gt;
&lt;p&gt;Instead of guessing subtraction constants \(\alpha, \beta\), Norbert Wiener asked a clean optimization question: &lt;em&gt;which scalar multiplier \(G\) minimizes the expected squared error \(\mathbb{E}[\vert S - G Y\vert^2]\)?&lt;/em&gt; Under uncorrelated speech and noise, the exact answer is the ratio of speech power to total power: \(G = P_S / (P_S + P_N) = \xi / (\xi + 1)\).&lt;/p&gt;

&lt;h3 id=&quot;2-a-priori-snr-xi-vs-a-posteriori-snr-gamma&quot;&gt;2. A Priori SNR (\(\xi\)) vs. A Posteriori SNR (\(\gamma\))&lt;/h3&gt;
&lt;p&gt;Two SNR ratios look deceptively similar and must never be swapped:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;A posteriori SNR&lt;/strong&gt; \(\gamma = \vert Y\vert^2 / P_N\): directly observable from the current noisy frame, but wildly noisy frame-to-frame.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;A priori SNR&lt;/strong&gt; \(\xi = P_S / P_N\): the true underlying speech-to-noise power ratio—unobservable directly, estimated smoothly via Ephraim–Malah’s &lt;strong&gt;decision-directed recursion&lt;/strong&gt; (\(\eta \approx 0.98\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-the-bridge-to-neural-masks-irm--erb-gains&quot;&gt;3. The Bridge to Neural Masks (IRM &amp;amp; ERB Gains)&lt;/h3&gt;
&lt;p&gt;Notice that if you know the true clean and noise powers in each bin, the Ideal Ratio Mask \(M^{\mathrm{IRM}} = \vert S\vert^2 / (\vert S\vert^2 + \vert N\vert^2)\) is literally the Wiener gain! Neural enhancers beat classical Wiener not by inventing a magic curve shape, but by using deep temporal–spectral context to estimate \(\xi\) far more accurately during non-stationary bursts.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;You will derive the frequency-domain Wiener gain \(G = \xi/(1+\xi)\) from an MMSE argument under Gaussian assumptions, distinguish a priori SNR \(\xi\) from a posteriori SNR \(\gamma\), implement a decision-directed tracker at pseudocode level, and explain how Wiener gains relate to soft masks in neural speech enhancement.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — From hard subtraction to soft gains; listen to a Wiener vs subtractor demo narrative.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — MMSE derivation sketch → \(G^{\mathrm{Wiener}}(k)=\xi/(\xi+1)\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Estimating \(\xi\) and \(\gamma\); decision-directed recursion (Ephraim–Malah style).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Speech-specific tricks: flooring the gain, bias toward noise reduction, link to SpeexDSP / WebRTC NS.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Pitfalls, exercises, preview of Kalman tracking (03-03).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;wiener-gain-in-one-line&quot;&gt;Wiener gain in one line&lt;/h3&gt;

&lt;p&gt;For an additive model \(Y=S+N\) in a given STFT bin (drop \((k,\ell)\)), the &lt;strong&gt;linear MMSE estimator&lt;/strong&gt; of \(S\) given \(Y\) under uncorrelated zero-mean Gaussian assumptions is multiplication by&lt;/p&gt;

\[G^{\mathrm{W}} = \frac{P_S}{P_S + P_N} = \frac{\xi}{\xi + 1},\]

&lt;p&gt;where \(P_S=\mathbb{E}\vert S\vert^2\), \(P_N=\mathbb{E}\vert N\vert^2\), and the &lt;strong&gt;a priori SNR&lt;/strong&gt; is&lt;/p&gt;

\[\xi = \frac{P_S}{P_N}.\]

&lt;p&gt;The enhanced spectrum is \(\hat{S} = G^{\mathrm{W}} Y\) (complex multiply—phase of \(Y\) preserved automatically).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt; if speech power ≫ noise power (\(\xi\to\infty\)), \(G\to 1\) (pass-through). If noise dominates (\(\xi\to 0\)), \(G\to 0\) (suppress). Between those extremes the gain is a smooth soft mask—exactly the shape neural mask estimators rediscover from data.&lt;/p&gt;

&lt;h3 id=&quot;a-posteriori-snr&quot;&gt;A posteriori SNR&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;a posteriori SNR&lt;/strong&gt; uses the &lt;em&gt;observed&lt;/em&gt; power:&lt;/p&gt;

\[\gamma = \frac{\vert Y\vert^2}{P_N}.\]

&lt;p&gt;If \(P_N\) is known, \(\gamma\) is measurable each frame; \(\xi\) is not, because \(P_S\) is unknown. Classical speech enhancement spends most of its ingenuity on estimating \(\xi\).&lt;/p&gt;

&lt;p&gt;A useful identity under the model is \(\mathbb{E}[\gamma]=\xi+1\), so a naive plug-in is \(\hat{\xi}=\gamma-1\) clipped at zero—the &lt;strong&gt;ML estimate&lt;/strong&gt;—but it is noisy frame-to-frame and produces musical artifacts similar to aggressive subtraction.&lt;/p&gt;

&lt;h3 id=&quot;decision-directed-a-priori-snr-ephraimmalah&quot;&gt;Decision-directed a priori SNR (Ephraim–Malah)&lt;/h3&gt;

&lt;p&gt;The celebrated &lt;strong&gt;decision-directed&lt;/strong&gt; approach recursively blends a prediction from the previous enhanced frame with the instantaneous ML estimate:&lt;/p&gt;

\[\hat{\xi}(\ell) = \eta\,\frac{\vert G(\ell-1) Y(\ell-1)\vert^2}{P_N} + (1-\eta)\,\max\bigl(\gamma(\ell)-1,\,0\bigr),\]

&lt;p&gt;with \(\eta\) typically \(0.98\). Then set&lt;/p&gt;

\[G(\ell) = \frac{\hat{\xi}(\ell)}{\hat{\xi}(\ell)+1}.\]

&lt;p&gt;High \(\eta\) yields smooth gains (less musical noise, more reverberant / smeared speech). Low \(\eta\) tracks non-stationary noise better but sounds twitchy.&lt;/p&gt;

&lt;h3 id=&quot;power-spectra-and-noise-estimation&quot;&gt;Power spectra and noise estimation&lt;/h3&gt;

&lt;p&gt;You still need \(P_N(k,\ell)\). Reuse the noise trackers from spectral subtraction (VAD-gated recursive mean, min-statistics). Many VoIP preprocessors combine:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Noise PSD tracker,&lt;/li&gt;
  &lt;li&gt;Decision-directed \(\xi\),&lt;/li&gt;
  &lt;li&gt;Wiener or Ephraim–Malah MMSE gain,&lt;/li&gt;
  &lt;li&gt;Optional residual echo / AGC stages (Chapter 03-04).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;soft-mask-view-bridge-to-chapter-04&quot;&gt;Soft mask view (bridge to Chapter 04)&lt;/h3&gt;

&lt;p&gt;Define an ideal ratio mask (IRM) in power domain:&lt;/p&gt;

\[M^{\mathrm{IRM}} = \frac{\vert S\vert^2}{\vert S\vert^2 + \vert N\vert^2} = \frac{\xi}{\xi+1}.\]

&lt;p&gt;That is &lt;em&gt;exactly&lt;/em&gt; the Wiener gain when \(\xi\) is the true a priori SNR. Neural SE models often regress a mask \(\hat{M}\) toward IRM / ideal binary mask / complex ideal ratio mask targets. Reading DeepFilterNet as “learned multi-frame filtering + ERB-band gains” is easier once Wiener is in your bones: the classical formula is the closed-form optimum under strong assumptions; the network relaxes those assumptions using data.&lt;/p&gt;

&lt;h3 id=&quot;pseudocode&quot;&gt;Pseudocode&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;for each frame ell:
  Y = STFT(y_ell)
  γ = |Y|^2 / P_N
  ξ = η * |S_prev|^2 / P_N + (1-η) * max(γ - 1, 0)
  G = ξ / (ξ + 1)
  G = max(G, G_min)          # gain floor, e.g. -20 dB
  S_hat = G * Y
  S_prev = S_hat
  emit ISTFT_OLA(S_hat)
  update P_N if noise-only
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-deriving-g--xixi1-in-three-clean-lines&quot;&gt;Explanation: Deriving \(G = \xi/(\xi+1)\) in Three Clean Lines&lt;/h3&gt;

&lt;h4 id=&quot;step-1-expand-the-mean-squared-error-for-a-real-gain-g&quot;&gt;Step 1: Expand the mean-squared error for a real gain \(G\)&lt;/h4&gt;
&lt;p&gt;We want to minimize \(J(G) = \mathbb{E}[\vert S - G(S+N)\vert^2] = \mathbb{E}[\vert(1-G)S - GN\vert^2]\). Since clean speech \(S\) and noise \(N\) are uncorrelated (\(\mathbb{E}[S N^*] = 0\)), the cross-terms vanish identically:
\(J(G) = (1 - G)^2 P_S + G^2 P_N.\)&lt;/p&gt;

&lt;h4 id=&quot;step-2-differentiate-with-respect-to-g-and-set-to-zero&quot;&gt;Step 2: Differentiate with respect to \(G\) and set to zero&lt;/h4&gt;
&lt;p&gt;Take \(\frac{dJ}{dG} = -2(1 - G)P_S + 2G P_N = 0 \implies G(P_S + P_N) = P_S\), yielding:
\(G^{\mathrm{W}} = \frac{P_S}{P_S + P_N} = \frac{P_S / P_N}{P_S / P_N + 1} = \frac{\xi}{\xi + 1}!\)&lt;/p&gt;

&lt;h4 id=&quot;step-3-check-one-decision-directed-frame-by-hand&quot;&gt;Step 3: Check one decision-directed frame by hand&lt;/h4&gt;
&lt;p&gt;Suppose \(P_N = 1.0\), previous enhanced power \(\vert S_{\text{prev}}\vert^2 = 4.0\), current noisy bin power \(\vert Y(\ell)\vert^2 = 1.5\) (so \(\gamma = 1.5\)), and \(\eta = 0.98\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Decision-directed \(\hat{\xi} = 0.98(4.0/1.0) + 0.02(1.5 - 1) = 3.92 + 0.01 = 3.93\).&lt;/li&gt;
  &lt;li&gt;Smooth Wiener gain: \(G = 3.93 / 4.93 \approx 0.797\) (vs. twitchy ML plug-in \(0.5 / 1.5 = 0.333\)!). That \(0.98\) memory is what kills musical noise!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Summary of the Wiener enhancement chain:&lt;/p&gt;

\[\min_G \mathbb{E}[\vert S - GY\vert^2]
\;\Longrightarrow\;
G = \frac{\xi}{\xi+1}
\;\xrightarrow{\text{Decision-directed } \hat{\xi}}\;
\text{Smooth soft mask (classical IRM)}.\]

&lt;h2 id=&quot;worked-checklist-tuning-a-speech-wiener&quot;&gt;Worked checklist: tuning a speech Wiener&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Knob&lt;/th&gt;
      &lt;th&gt;Increase → effect&lt;/th&gt;
      &lt;th&gt;Decrease → effect&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;\(\eta\)&lt;/td&gt;
      &lt;td&gt;smoother, less musical&lt;/td&gt;
      &lt;td&gt;faster, twitchier&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(G_{\min}\)&lt;/td&gt;
      &lt;td&gt;more residual noise&lt;/td&gt;
      &lt;td&gt;more distortion / holes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Noise update rate&lt;/td&gt;
      &lt;td&gt;tracks non-stationary noise&lt;/td&gt;
      &lt;td&gt;stabler during speech&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Frame / hop&lt;/td&gt;
      &lt;td&gt;latency vs resolution (Ch. 02)&lt;/td&gt;
      &lt;td&gt;—&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Sanity check:&lt;/strong&gt; with \(P_N\to 0\), \(G\) should approach 1 and the output should match the input (OLA-perfect). Unit-test that path before shipping.&lt;/p&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Using \(\gamma/(\gamma+1)\) as if it were Wiener— that is a different (worse) plug-in; prefer \(\xi/(\xi+1)\) with a tracked \(\xi\).&lt;/li&gt;
  &lt;li&gt;Freezing \(P_N\) forever after the first second of a call.&lt;/li&gt;
  &lt;li&gt;No gain floor → abrupt zeros → musical noise return.&lt;/li&gt;
  &lt;li&gt;Applying Wiener after a nonlinear AGC without accounting for changed noise PSD.&lt;/li&gt;
  &lt;li&gt;Confusing &lt;strong&gt;echo&lt;/strong&gt; (correlated with far-end reference) with &lt;strong&gt;noise&lt;/strong&gt; (no reference)—Wiener NS is not AEC.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Evaluate Wiener gains at a priori SNRs of \(-10\), \(0\), and \(+10\,\mathrm{dB}\).&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;snr_db&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;snr_db&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;10.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;G&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;snr_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;xi&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
          &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;G_dB&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; \(-10\,\mathrm{dB}\) → \(\xi=0.1\), \(G\approx 0.091\) (\(-20.83\,\mathrm{dB}\)). \(0\,\mathrm{dB}\) → \(\xi=1\), \(G=0.5\) (\(-6.02\,\mathrm{dB}\)). \(+10\,\mathrm{dB}\) → \(\xi=10\), \(G\approx 0.909\) (\(-0.83\,\mathrm{dB}\)). The middle row is the point marked on the figure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Passing decibels straight into \(\xi/(\xi+1)\) (forgetting \(10^{\mathrm{SNR}/10}\)) makes the \(-10\,\mathrm{dB}\) gain larger than the \(+10\,\mathrm{dB}\) gain, which is the curve upside down. Using \(20\log_{10}\) to convert SNR to \(\xi\), or reporting \(10\log_{10} G\) instead of \(20\log_{10} G\), shifts the decibel column by about a factor of two. \(\gamma/(\gamma+1)\) is a different plug-in; this lab does not estimate \(\gamma\).&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Algebra.&lt;/strong&gt; Show that \(G^{\mathrm{W}}=\xi/(\xi+1)\) equals \(1-1/(\xi+1)\) and interpret \(1-G\) as the noise-attenuation factor.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Numerical.&lt;/strong&gt; For \(\xi\in\{0.1,1,10\}\) compute \(G\) in linear and dB. At what \(\xi\) is the gain \(-6\,\mathrm{dB}\)?&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Implement.&lt;/strong&gt; Code decision-directed Wiener on a WAV file; plot \(G(k,\ell)\) as a spectrogram-like image; compare musical noise against spectral subtraction from 03-01.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Concept link.&lt;/strong&gt; In two paragraphs, explain why a neural IRM estimator can beat a decision-directed Wiener on non-stationary noise &lt;em&gt;without&lt;/em&gt; abandoning the \(\xi/(\xi+1)\) intuition.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Subtract the two forms; \(1-G=1/(\xi+1)\) is the fraction of \(Y\) you attribute to noise.&lt;/li&gt;
  &lt;li&gt;\(G(-6\,\mathrm{dB})=1/2\) when \(\xi=1\). The three requested gains are about \(0.091\), \(0.5\), and \(0.909\).&lt;/li&gt;
  &lt;li&gt;Plot \(G\), not \(\vert Y\vert\). A twitchy \(\eta\) looks speckled; spectral subtraction looks like holes.&lt;/li&gt;
  &lt;li&gt;The network is still aiming at a ratio of powers. It wins by estimating that ratio from more context than one decision-directed recursion, not by inventing a different gain shape.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;N. Wiener, &lt;em&gt;Extrapolation, Interpolation, and Smoothing of Stationary Time Series&lt;/em&gt; (classical foundation).&lt;/li&gt;
  &lt;li&gt;Y. Ephraim &amp;amp; D. Malah, “Speech enhancement using a minimum mean-square error short-time spectral amplitude estimator,” &lt;em&gt;IEEE TASSP&lt;/em&gt;, 1984 (decision-directed SNR).&lt;/li&gt;
  &lt;li&gt;P. Scalart and J. V. Filho, “Speech enhancement based on a priori signal to noise estimation,” &lt;em&gt;ICASSP&lt;/em&gt;, 1996 — the a priori SNR form used in speech Wiener filters.&lt;/li&gt;
  &lt;li&gt;P. C. Loizou, &lt;em&gt;Speech Enhancement: Theory and Practice&lt;/em&gt; — textbook derivations of Wiener / MMSE estimators.&lt;/li&gt;
  &lt;li&gt;SpeexDSP / WebRTC Audio Processing Module noise-suppression overview (engineering instantiations).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=K_U0yeVdblU&quot;&gt;Lec 22: Causal IIR Wiener Filter&lt;/a&gt; — NPTEL IIT Guwahati, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the gain that depends on how noisy the measurement is. The lesson’s per-bin speech gain is this continuous rule on STFT magnitudes, not a hard subtract.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=U71siegOD48&quot;&gt;Wiener Filter Demonstration&lt;/a&gt; — Greg Malysa, English. A short demonstration of a Wiener filter at work. Treat it as the estimator’s behavior, then map the gain onto speech bins yourself.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xb--68NlxS0&quot;&gt;Spectral Subtraction In Python - Alexx Mitchell&lt;/a&gt; — The Audio Programmer, English. Keep the subtraction diagram beside the Wiener gain so the lesson’s contrast (floor after subtract versus a continuous SNR gain) stays visible.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>03-01 Spectral subtraction</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter03/03_01_spectral_subtraction/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter03/03_01_spectral_subtraction</id>
   <content type="html">&lt;p&gt;If you had to invent a noise suppressor from scratch in one afternoon, your first instinct would probably be Steven Boll’s 1979 classic: listen during a brief pause to measure the noise spectrum \(\widehat{\vert N\vert}\), subtract it from every noisy STFT frame \(\vert Y\vert\), clip any negative remainders to zero, and invert back to audio.&lt;/p&gt;

&lt;p&gt;It works astonishingly well on steady fan hum—and then, the moment you listen closely to the quiet pauses, you hear eerie, twinkling electronic “birdies” chirping at random pitches. That iconic artifact (&lt;strong&gt;musical noise&lt;/strong&gt;) is the single best teacher in classical speech enhancement. This lesson builds magnitude spectral subtraction with over-subtraction \(\alpha\) and flooring \(\beta\), walks through concrete bin calculations by hand, and explains when a cheap classical subtractor still sits in front of a neural model.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/spectral-subtraction-wiener.png&quot; alt=&quot;Power-domain spectral subtraction per bin, next to a Wiener gain curve that this lesson does not yet apply&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Spectral subtraction (left) removes a noise floor and then floors the remainder; the smooth curve on the right is the Wiener gain you get once subtraction becomes an SNR.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (magnitude-only estimation &amp;amp; noisy phase, noise-floor tracking, why musical noise happens) → Over-subtraction \(\alpha\) &amp;amp; spectral floor \(\beta\) + pseudocode → Worked example: 3-bin hand calculation showing why flooring prevents spectral holes → Explanation: 3 steps explaining how random noise peaks turn into “musical birdies” → Classical front-end use cases, Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-classical-spectral-subtraction-and-noise-floor-tracking&quot;&gt;Key ideas: Classical Spectral Subtraction and Noise-Floor Tracking&lt;/h2&gt;

&lt;h3 id=&quot;1-magnitude-only-subtraction--noisy-phase-reuse&quot;&gt;1. Magnitude-Only Subtraction &amp;amp; Noisy Phase Reuse&lt;/h3&gt;
&lt;p&gt;Under additive noise \(Y(k, \ell) = S(k, \ell) + N(k, \ell)\), spectral subtraction estimates only the clean &lt;strong&gt;magnitude&lt;/strong&gt; \(\vert \hat{S}\vert\) and keeps the &lt;strong&gt;noisy phase&lt;/strong&gt; \(\angle Y\). Because human hearing tolerates moderate phase error at high SNR (\(\ge 5\,\mathrm{dB}\)), this shortcut is fast and lightweight—though it breaks down in heavy noise.&lt;/p&gt;

&lt;h3 id=&quot;2-noise-floor-estimation-under-stationarity&quot;&gt;2. Noise-Floor Estimation Under Stationarity&lt;/h3&gt;
&lt;p&gt;Every classical subtractor lives or dies by its noise estimate \(\widehat{\vert N\vert}(k, \ell)\), typically updated recursively during non-speech frames via Voice Activity Detection (VAD) or minimum-statistics tracking. When background noise is stationary (HVAC), the estimate stays accurate; when noise is impulsive or speech-like (keyboard, babble), the tracker lags.&lt;/p&gt;

&lt;h3 id=&quot;3-over-subtraction-alpha-and-spectral-flooring-beta&quot;&gt;3. Over-Subtraction (\(\alpha\)) and Spectral Flooring (\(\beta\))&lt;/h3&gt;
&lt;p&gt;Because instantaneous noise fluctuates randomly around its mean \(\widehat{\vert N\vert}\), subtracting \(1.0\times \widehat{\vert N\vert}\) leaves half of the noise bins slightly positive and clips the other half to zero. Engineers introduce &lt;strong&gt;over-subtraction \(\alpha \ge 1\)&lt;/strong&gt; to push residual peaks down and a &lt;strong&gt;spectral floor \(\beta \in (0, 1)\)&lt;/strong&gt; to fill hard zero holes with a gentle broadband cushion.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;By the end of this lesson you will be able to state the additive mixture model in the STFT domain, write magnitude spectral subtraction with over-subtraction and flooring in pseudocode, explain why residual peaks sound like musical tones, and decide when a classical subtractor is a useful pre-stage versus when you should jump straight to a Wiener or neural masker.&lt;/p&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0–10 min&lt;/strong&gt; — Additive model \(Y = S + N\), magnitude vs power spectra, and why phase is usually kept from the noisy frame.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;10–25 min&lt;/strong&gt; — Noise estimation (VAD / min-statistics intuition) and the basic subtractor \(\vert\hat{S}\vert = \vert Y\vert - \alpha \widehat{\vert N\vert}\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;25–40 min&lt;/strong&gt; — Over-subtraction \(\alpha\), spectral floor \(\beta\), and a worked numerical example on a few bins.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;40–50 min&lt;/strong&gt; — Musical noise: mechanism, listening checklist, and SpeexDSP preprocessor as a production pointer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;50–60 min&lt;/strong&gt; — Pitfalls, exercises, and when subtraction is still a front-end before DeepFilterNet-class models.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;core-explanation&quot;&gt;Core explanation&lt;/h2&gt;

&lt;h3 id=&quot;mixture-model-and-stft-magnitudes&quot;&gt;Mixture model and STFT magnitudes&lt;/h3&gt;

&lt;p&gt;Assume a single-channel observation&lt;/p&gt;

\[y[t] = s[t] + n[t],\]

&lt;p&gt;where \(s\) is speech and \(n\) is additive noise. After a windowed STFT (Chapter 02), write complex spectra \(Y(k,\ell)\), \(S(k,\ell)\), \(N(k,\ell)\) for frequency bin \(k\) and frame \(\ell\). Under approximate additivity of complex STFT bins (true when the analysis window is long enough relative to impulse responses of interest),&lt;/p&gt;

\[Y(k,\ell) = S(k,\ell) + N(k,\ell).\]

&lt;p&gt;Classical spectral subtraction works on &lt;strong&gt;magnitudes&lt;/strong&gt; (or powers) and reuses the &lt;strong&gt;noisy phase&lt;/strong&gt;:&lt;/p&gt;

\[\hat{S}(k,\ell) = \bigl(\vert Y(k,\ell)\vert - \widehat{\vert N\vert}(k,\ell)\bigr)_{+} \; e^{j\angle Y(k,\ell)}.\]

&lt;p&gt;The positive-part \((\cdot)_{+}\) prevents negative magnitudes. Power-domain variants subtract estimated noise power from \(\vert Y\vert^2\) and take a square root—same philosophy, different bias/variance trade-offs.&lt;/p&gt;

&lt;h3 id=&quot;noise-floor-estimation-assumptions&quot;&gt;Noise floor estimation (assumptions)&lt;/h3&gt;

&lt;p&gt;You need \(\widehat{\vert N\vert}(k)\). Common teaching assumptions:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Stationary noise during an initial silence&lt;/strong&gt; — average magnitudes over the first \(L_0\) frames assumed to be noise-only.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Voice-activity detection (VAD)&lt;/strong&gt; — update the noise estimate only when speech is absent.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Min-statistics / recursive tracking&lt;/strong&gt; — track a smoothed minimum of the noisy spectrum (used widely in classical literature and in SpeexDSP-style preprocessors).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A simple recursive update during non-speech frames is&lt;/p&gt;

\[\widehat{\vert N\vert}(k,\ell) = \lambda \widehat{\vert N\vert}(k,\ell-1) + (1-\lambda)\,\vert Y(k,\ell)\vert,\]

&lt;p&gt;with smoothing factor \(\lambda \in (0,1)\) close to 1 for slow adaptation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Critical assumption:&lt;/strong&gt; if noise is non-stationary (keyboard clicks, competing talkers, music), a slowly adapted floor under-subtracts during bursts and over-subtracts afterward. That is the main reason pure subtraction fails in modern VoIP scenarios with highly non-stationary backgrounds.&lt;/p&gt;

&lt;h3 id=&quot;over-subtraction-and-spectral-flooring&quot;&gt;Over-subtraction and spectral flooring&lt;/h3&gt;

&lt;p&gt;Boll’s original idea and the Berouti-style refinements introduce two controls:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Over-subtraction factor&lt;/strong&gt; \(\alpha \ge 1\) — subtract &lt;em&gt;more&lt;/em&gt; than the estimated noise to reduce residual peaks.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Spectral floor&lt;/strong&gt; \(\beta \in (0,1)\) — never let the magnitude fall below \(\beta\,\vert Y\vert\) (or \(\beta\,\widehat{\vert N\vert}\)), which reduces musical noise at the cost of leaving some residual noise.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A practical magnitude rule is&lt;/p&gt;

\[\vert\hat{S}(k,\ell)\vert = \max\bigl(\vert Y(k,\ell)\vert - \alpha\,\widehat{\vert N\vert}(k,\ell),\; \beta\,\vert Y(k,\ell)\vert\bigr).\]

&lt;p&gt;Sometimes \(\alpha\) itself is SNR-dependent: larger \(\alpha\) at low a priori SNR, smaller \(\alpha\) when speech dominates. That heuristic already points toward &lt;strong&gt;Wiener filtering&lt;/strong&gt; (next lesson), which chooses a continuous gain from an SNR estimate rather than a hard subtract-and-floor.&lt;/p&gt;

&lt;h3 id=&quot;pseudocode-magnitude-stft&quot;&gt;Pseudocode (magnitude STFT)&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;for each frame ell:
  Y = STFT_frame(y_ell)           # complex
  magY = |Y|
  if is_noise_frame(ell):
      Nhat = λ * Nhat + (1-λ) * magY
  magS = max(magY - α * Nhat, β * magY)
  S_hat = magS * exp(j * angle(Y))
  emit ISTFT_OLA(S_hat)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Keep hop, window, and overlap-add consistent with Chapter 02 so that perfect reconstruction holds when \(\alpha=0\) and \(\beta=1\) (identity gain).&lt;/p&gt;

&lt;h3 id=&quot;musical-noise-what-you-hear-and-why&quot;&gt;Musical noise: what you hear and why&lt;/h3&gt;

&lt;p&gt;After subtraction, bins where the noise estimate was slightly &lt;strong&gt;too low&lt;/strong&gt; leave thin residual peaks; bins where it was &lt;strong&gt;too high&lt;/strong&gt; dig holes. Over frames, those residual peaks wander in frequency and sound like random tones or “birds”—hence &lt;strong&gt;musical noise&lt;/strong&gt;. Flooring and temporal smoothing of the gain reduce the artifact; aggressive \(\alpha\) without flooring makes it worse.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Listening checklist (30 seconds per clip):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Play noisy input and subtractor output at matched loudness.&lt;/li&gt;
  &lt;li&gt;Solo a noise-only region: do you hear chirps / whistling?&lt;/li&gt;
  &lt;li&gt;Solo a low-SNR speech region: is speech hollow or robotic?&lt;/li&gt;
  &lt;li&gt;Toggle \(\beta\) up: musical noise should drop; residual broadband noise should rise.&lt;/li&gt;
  &lt;li&gt;Toggle \(\alpha\) up: noise drops; speech distortion and musical tones often rise.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;worked-example-toy-bins&quot;&gt;Worked example (toy bins)&lt;/h2&gt;

&lt;p&gt;Suppose one frame, three bins, magnitudes \(\vert Y\vert = [5.0,\; 2.0,\; 1.2]\), noise estimate \(\widehat{\vert N\vert} = [1.0,\; 1.5,\; 1.0]\), \(\alpha=1.5\), \(\beta=0.1\).&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Bin 0:&lt;/strong&gt; \(5.0 - 1.5\cdot 1.0 = 3.5\), floor \(0.1 \cdot 5.0 = 0.5\) → &lt;strong&gt;\(3.5\)&lt;/strong&gt; (passes speech).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bin 1:&lt;/strong&gt; \(2.0 - 1.5\cdot 1.5 = -0.25\), floor \(0.1 \cdot 2.0 = 0.2\) → &lt;strong&gt;\(0.2\)&lt;/strong&gt; (floored).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Bin 2:&lt;/strong&gt; \(1.2 - 1.5\cdot 1.0 = -0.30\), floor \(0.1 \cdot 1.2 = 0.12\) → &lt;strong&gt;\(0.12\)&lt;/strong&gt; (floored).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bins 1–2 illustrate why flooring matters: without it you would clip to zero and create hard spectral holes that become musical after ISTFT.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-how-random-noise-fluctuations-turn-into-musical-birdies&quot;&gt;Explanation: How Random Noise Fluctuations Turn into “Musical Birdies”&lt;/h3&gt;

&lt;h4 id=&quot;step-1-the-noise-spectrum-is-a-random-variable-not-a-flat-constant&quot;&gt;Step 1: The noise spectrum is a random variable, not a flat constant&lt;/h4&gt;
&lt;p&gt;Even for pure stationary white noise with mean magnitude \(\widehat{\vert N\vert} = 1.0\), the actual magnitude in each STFT bin fluctuates randomly from frame to frame (following a Rayleigh distribution): some bins dip to \(0.4\) while neighboring bins spike to \(2.1\)!&lt;/p&gt;

&lt;h4 id=&quot;step-2-hard-half-wave-rectification-isolates-random-single-bin-spikes&quot;&gt;Step 2: Hard half-wave rectification isolates random single-bin spikes&lt;/h4&gt;
&lt;p&gt;When you subtract \(\widehat{\vert N\vert} = 1.0\) and clip negatives to \(0\), all the \(0.4\) bins become &lt;strong&gt;exact silence (\(0.0\))&lt;/strong&gt; while the occasional \(2.1\) bin survives as an isolated narrow spike (\(1.1\)) surrounded by zeros. An isolated spike in frequency is a &lt;strong&gt;pure sine tone&lt;/strong&gt; in time—lasting one 20 ms frame!&lt;/p&gt;

&lt;h4 id=&quot;step-3-frame-to-frame-wandering-creates-chirping-musical-noise&quot;&gt;Step 3: Frame-to-frame wandering creates chirping “musical noise”&lt;/h4&gt;
&lt;p&gt;On the next hop, a &lt;em&gt;different&lt;/em&gt; random bin spikes above \(1.0\), producing a short tone at a different pitch. Our ears perceive that rapid succession of random 20 ms sine bursts as metallic whistling or underwater chirping. Raising \(\beta\) (e.g., \(0.1\)) masks those isolated spikes in a soft broadband floor—and motivates the smooth continuous gains of Wiener filtering (Lesson 03-02).&lt;/p&gt;

&lt;p&gt;Summary of the spectral subtraction recipe:&lt;/p&gt;

\[\vert \hat{S}(k,\ell)\vert = \max\!\bigl(\vert Y(k,\ell)\vert - \alpha\,\widehat{\vert N\vert}(k,\ell),\; \beta\,\vert Y(k,\ell)\vert\bigr)
\;\xrightarrow{\times e^{j\angle Y}}\;
\text{ISTFT / OLA}.\]

&lt;h2 id=&quot;when-classical-subtraction-still-appears-as-a-front-end&quot;&gt;When classical subtraction still appears as a front-end&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Very cheap always-on gate&lt;/strong&gt; on embedded DSPs before a heavier neural stage.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Noise-floor bootstrap&lt;/strong&gt; to initialize a priori SNR for Wiener / MMSE estimators.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SpeexDSP preprocessor&lt;/strong&gt; and similar VoIP stacks: spectral subtraction / noise gating as part of a broader AGC + VAD + NS chain.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hybrid pipelines&lt;/strong&gt; where a classical block removes stationary HVAC hum and a neural model cleans residual non-stationary noise (see Chapter 04 hybrids).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For Mezon-class full-band real-time NS, subtraction alone is not enough—but understanding it makes DeepFilterNet’s “learned filter / mask” behavior much less mysterious. The left panel of the figure is this rule in the power domain: blue bars are \(\vert Y\vert^2\), the orange line is the noise floor, and the green bars are what survives the floor. The right panel is not subtraction; it is the soft Wiener gain of the next lesson.&lt;/p&gt;

&lt;h2 id=&quot;pitfalls&quot;&gt;Pitfalls&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Treating power and magnitude formulas as interchangeable without adjusting \(\alpha,\beta\).&lt;/li&gt;
  &lt;li&gt;Updating the noise estimate during speech → &lt;strong&gt;speech erasure&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;Setting \(\beta=0\) “to remove all noise” → severe musical noise.&lt;/li&gt;
  &lt;li&gt;Ignoring OLA window normalization → gain errors that sound like pumping.&lt;/li&gt;
  &lt;li&gt;Expecting subtraction to fix echo (that is AEC, lesson 03-04) or directional interferers (beamforming, 03-05).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Run magnitude spectral subtraction on eight bins and print which bins hit the floor.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;magY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;4.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Nhat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;raw&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;magY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Nhat&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;magS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;maximum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;magY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;clipped&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raw&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;magY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;raw&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;magS&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;magS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;clipped bins&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clipped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;raw&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[-0.8, 1.5, -1.0, 1.8, 0.2, -0.5, -0.9, 0.8]&lt;/code&gt;. After the floor, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;magS&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0.12, 1.5, 0.08, 1.8, 0.22, 0.11, 0.05, 0.8]&lt;/code&gt;. Clipped bins are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0, 2, 4, 5, 6]&lt;/code&gt;. Bins 1, 3, and 7 pass through unclipped.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Using power \(\vert Y\vert^2\) with these magnitude numbers, or forgetting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;beta * magY&lt;/code&gt;, changes both the clipped set and the floor values. A clip test written as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;raw &amp;lt; 0&lt;/code&gt; misses bin 4, where the raw remainder is positive but still under the floor. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alpha=1&lt;/code&gt; clips fewer bins and hides the over-subtraction the example is about.&lt;/p&gt;

&lt;h2 id=&quot;exercises&quot;&gt;Exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Derive the floor case.&lt;/strong&gt; Show that if \(\vert Y\vert &amp;lt; \alpha\widehat{\vert N\vert}\), the floored rule returns \(\beta\vert Y\vert\). Interpret \(\beta\) as a residual noise fraction.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Implement (offline).&lt;/strong&gt; In Python/NumPy, run magnitude spectral subtraction on a 16 kHz clip with a known stationary noise. Sweep \(\alpha\in\{1.0,1.5,2.0\}\) and \(\beta\in\{0.01,0.1,0.2\}\); note musical noise vs residual noise.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-stationary stress test.&lt;/strong&gt; Replace stationary noise with keyboard bursts. Explain why a fixed \(\widehat{\vert N\vert}\) fails; propose a VAD-gated update rule.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Product judgment.&lt;/strong&gt; Write five bullets arguing when you would keep SpeexDSP-style subtraction as a pre-stage in front of a DeepFilterNet3 WASM path versus disabling it entirely.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;max&lt;/code&gt; returns the second argument exactly when the first is smaller; \(\beta\vert Y\vert\) is a fraction of the noisy magnitude you refuse to erase.&lt;/li&gt;
  &lt;li&gt;Hold the noise estimate fixed from a leading noise-only region, then listen to noise-only tails as \(\alpha\) grows and \(\beta\) shrinks.&lt;/li&gt;
  &lt;li&gt;A burst above the frozen floor is under-subtracted; the frames after it are over-subtracted. Update \(\widehat{\vert N\vert}\) only when a VAD says noise.&lt;/li&gt;
  &lt;li&gt;Keep a cheap stationary front-end when the neural model is the expensive stage and the hum is steady; disable it when it already punches holes that the 48 kHz model then treats as speech structure.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;S. F. Boll, “Suppression of acoustic noise in speech using spectral subtraction,” &lt;em&gt;IEEE Trans. Acoust., Speech, Signal Process.&lt;/em&gt;, 1979 (classic formulation).&lt;/li&gt;
  &lt;li&gt;M. Berouti, R. Schwartz, J. Makhoul — over-subtraction / spectral floor refinements (cite by name; standard textbook treatment in Loizou, &lt;em&gt;Speech Enhancement&lt;/em&gt;).&lt;/li&gt;
  &lt;li&gt;SpeexDSP preprocessor documentation (Xiph) — production classical NS pointer.&lt;/li&gt;
  &lt;li&gt;Contrast next: Ephraim–Malah / Wiener estimators (lesson 03-02) and RNNoise’s hybrid design (lesson 04-06).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xb--68NlxS0&quot;&gt;Spectral Subtraction In Python - Alexx Mitchell&lt;/a&gt; — The Audio Programmer, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the algorithm diagram: estimate a noise magnitude, subtract, and floor. Musical noise is what a negative bin becomes if the floor is naive.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. Use the opening to hear why a product eventually replaced this classical suppressor, after you can implement it.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, English. Listen after the diagram. The demo is a later suppressor, useful as the sound spectral subtraction is trying and failing to reach.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-07 Pipeline latency–quality tradeoffs</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_07_pipeline_latency_quality/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_07_pipeline_latency_quality</id>
   <content type="html">&lt;p&gt;One of the costliest mistakes in audio product reviews is conflating two completely different clocks: &lt;strong&gt;“Our model runs in 3 ms, so latency is 3 ms!”&lt;/strong&gt; Wrong! If your causal STFT waits 20 ms to fill a 960-sample analysis window and takes 2 frames (20 ms) of look-ahead, your caller is already &lt;strong&gt;40 ms late&lt;/strong&gt;—even if your GPU finishes the forward pass in 0.1 ms!&lt;/p&gt;

&lt;p&gt;This capstone lesson of Chapter 02 separates &lt;strong&gt;algorithmic latency&lt;/strong&gt; (how late the audio is) from &lt;strong&gt;Real-Time Factor&lt;/strong&gt; (whether the CPU keeps up), maps all 9 stages of a production speech pipeline, and gives you a concrete go/no-go shipping scorecard.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/rtf-audioworklet.png&quot; alt=&quot;AudioWorklet quanta on a timeline, with process() sometimes overrunning a quantum: RTF is wall time over audio duration, and a good average can still miss a deadline&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Each tick is a render quantum; RTF compares process() wall time to that audio duration, which is a different number from the STFT window’s algorithmic delay.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (algorithmic delay vs. RTF, the 9-stage audio pipeline, three failure regimes) → Parameter-knob tradeoff table &amp;amp; 48 kHz vs. 16 kHz numerics → Shipping scorecard &amp;amp; DeepFilterNet contract → Worked examples: Config A vs. Config B sweep and splitting a 40 ms budget → Explanation: 3 steps preventing the “two-clock confusion” in design reviews → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-systems-engineering-of-real-time-audio-pipelines&quot;&gt;Key ideas: Systems Engineering of Real-Time Audio Pipelines&lt;/h2&gt;

&lt;h3 id=&quot;1-two-independent-clocks--delay-d_mathrmalg-vs-throughput-mathrmrtf&quot;&gt;1. Two Independent Clocks — Delay \(D_{\mathrm{alg}}\) vs. Throughput \(\mathrm{RTF}\)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic latency \(D_{\mathrm{alg}}\)&lt;/strong&gt; is dictated by the signal graph (window buffering \(L/f_s\) + model look-ahead + resampler group delay). Buying a faster CPU &lt;strong&gt;never&lt;/strong&gt; reduces \(D_{\mathrm{alg}}\)!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Real-Time Factor \(\mathrm{RTF} = T_{\mathrm{wall}} / T_{\mathrm{hop}}\)&lt;/strong&gt; is dictated by compute speed vs. hop cadence. Making the CPU faster lowers RTF, never \(D_{\mathrm{alg}}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-the-9-stage-end-to-end-voice-path&quot;&gt;2. The 9-Stage End-to-End Voice Path&lt;/h3&gt;
&lt;p&gt;Between microphone capture and the WebRTC encoder sit 9 distinct stages: quantum buffering, input resampling, mono downmix, STFT framing, feature extraction (ERB), enhancement, ISTFT/OLA, output resampling, and encoder handoff. Every stage contributes to &lt;em&gt;either&lt;/em&gt; delay, CPU, or both—and must be timestamped separately.&lt;/p&gt;

&lt;h3 id=&quot;3-three-ways-a-pipeline-fails-in-production&quot;&gt;3. Three Ways a Pipeline Fails in Production&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Too little latency budget&lt;/strong&gt; (tiny \(L\)): unresolved pitch harmonics and harsh masks.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Too much latency&lt;/strong&gt; (huge \(L\) or look-ahead): awkward conversational cross-talk and broken Acoustic Echo Cancellation (AEC).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Too little CPU headroom&lt;/strong&gt; (high p99 RTF): audible crackles and dropouts whenever a single callback overruns.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Enumerate pipeline stages that add latency and CPU.&lt;/li&gt;
  &lt;li&gt;Trade window/hop/FFT size against quality and delay with numbers.&lt;/li&gt;
  &lt;li&gt;Explain quality failure modes when over-optimizing latency.&lt;/li&gt;
  &lt;li&gt;Build a go/no-go scorecard for shipping configurations.&lt;/li&gt;
  &lt;li&gt;Connect tradeoffs to DeepFilterNet-class real-time design goals.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;End-to-end pipeline diagram (mic → NS → encoder)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–28&lt;/td&gt;
      &lt;td&gt;Parameter sweep thought experiments with numerics&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Quality vs latency failure modes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Scorecard for Mezon-like shipping&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;two-clocks&quot;&gt;Two clocks&lt;/h3&gt;

&lt;p&gt;Algorithmic latency is a property of the signal graph. For the causal STFT in lesson 02-02,&lt;/p&gt;

\[D_{\mathrm{alg}}\approx T_L=\frac{L}{f_s},\]

&lt;p&gt;plus look-ahead, resampling delay, and packet buffer. At 48 kHz, \(L=960\) contributes about &lt;strong&gt;20 ms&lt;/strong&gt; whether the FFT takes 0.2 ms or 2 ms of wall time. The samples are late because you waited to fill the window.&lt;/p&gt;

&lt;p&gt;Real-time factor is a property of the implementation:&lt;/p&gt;

\[\mathrm{RTF}=\frac{T_{\mathrm{wall}}(D)}{D}.\]

&lt;p&gt;\(D\) is the audio duration you just processed (one hop, or one quantum). \(\mathrm{RTF}&amp;lt;1\) means you finished before the next block was due. It does not say how much look-ahead you already inserted. The figure’s other warning: a mean RTF of 0.4 still clicks if p99 exceeds the hop. Log p95/p99.&lt;/p&gt;

&lt;p&gt;A 128-sample quantum at 48 kHz lasts \(128/48000\approx 2.67\,\mathrm{ms}\). That is the grid in the figure, not the model hop. A 10 ms hop spans about four quanta; the red &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt; bar is the quantum where the FFT and the network overrun. Cold start (WASM/ONNX compile) is main-thread work, not steady-state RTF.&lt;/p&gt;

&lt;h3 id=&quot;pipeline-stages-typical&quot;&gt;Pipeline stages (typical)&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Capture / AudioWorklet quantum buffering&lt;/li&gt;
  &lt;li&gt;Resample to model rate&lt;/li&gt;
  &lt;li&gt;Mono downmix&lt;/li&gt;
  &lt;li&gt;STFT framing (window/hop)&lt;/li&gt;
  &lt;li&gt;Feature transform (e.g. ERB)&lt;/li&gt;
  &lt;li&gt;Neural / classical enhance&lt;/li&gt;
  &lt;li&gt;Inverse features / ISTFT / OLA&lt;/li&gt;
  &lt;li&gt;Resample to sink rate&lt;/li&gt;
  &lt;li&gt;Hand off to WebRTC encoder&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For each stage, log waveform delay and RTF separately. A resampler can be cheap in RTF and still add group delay; an ONNX session can be expensive in RTF and add no look-ahead beyond the STFT.&lt;/p&gt;

&lt;h3 id=&quot;knobs-and-effects&quot;&gt;Knobs and effects&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Knob ↑&lt;/th&gt;
      &lt;th&gt;Latency&lt;/th&gt;
      &lt;th&gt;CPU&lt;/th&gt;
      &lt;th&gt;Quality tendency&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Window \(L\)&lt;/td&gt;
      &lt;td&gt;↑&lt;/td&gt;
      &lt;td&gt;↑ (larger FFT)&lt;/td&gt;
      &lt;td&gt;better freq detail; blurrier time&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hop \(R\)&lt;/td&gt;
      &lt;td&gt;hop itself is not \(D_{\mathrm{alg}}\); smaller \(R\) raises hops/s&lt;/td&gt;
      &lt;td&gt;↑ as \(R\)↓&lt;/td&gt;
      &lt;td&gt;smoother masks often&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Model size&lt;/td&gt;
      &lt;td&gt;≈ (if lookahead fixed)&lt;/td&gt;
      &lt;td&gt;↑&lt;/td&gt;
      &lt;td&gt;often ↑ until RTF fails&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Look-ahead&lt;/td&gt;
      &lt;td&gt;↑&lt;/td&gt;
      &lt;td&gt;↑&lt;/td&gt;
      &lt;td&gt;often ↑ quality&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Sample rate&lt;/td&gt;
      &lt;td&gt;↑&lt;/td&gt;
      &lt;td&gt;↑&lt;/td&gt;
      &lt;td&gt;↑ bandwidth if model trained for it&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Measure.&lt;/strong&gt; Cutting \(R\) from 480 to 240 at 48 kHz doubles hops/s (100 → 200) and STFT CPU; \(D_{\mathrm{alg}}\) stays near \(L/f_s\) unless the window shrinks too. Shortening the window widens bins (lesson 02-03). It is a quality change, not a free RTF win.&lt;/p&gt;

&lt;h3 id=&quot;numerics-to-keep&quot;&gt;Numerics to keep&lt;/h3&gt;

&lt;p&gt;At 48 kHz:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;128-sample quantum ≈ 2.67 ms&lt;/li&gt;
  &lt;li&gt;480-sample hop = 10 ms → 100 decisions/s&lt;/li&gt;
  &lt;li&gt;960-sample window = 20 ms buffering scale&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At 16 kHz, the same &lt;em&gt;milliseconds&lt;/em&gt; use fewer samples (cheaper FFTs) but less bandwidth. The same &lt;em&gt;sample counts&lt;/em&gt; are different milliseconds: \(L=512\) at 16 kHz is 32 ms, not 20 ms. A wall time of 3 ms on a 10 ms hop is \(\mathrm{RTF}=0.3\), comfortable. A wall time of 12 ms on that same hop is \(\mathrm{RTF}=1.2\), an overrun, even though 12 ms is less than a 20 ms window. The mini-lab prints both pairs so the two clocks stay in different variables.&lt;/p&gt;

&lt;h3 id=&quot;failure-modes&quot;&gt;Failure modes&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Too little latency budget:&lt;/strong&gt; tiny windows leave harmonics unresolved and masks harsh.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Too much latency:&lt;/strong&gt; the call feels late, and a look-ahead parked before AEC looks like a moving echo path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Too little CPU headroom:&lt;/strong&gt; a single p99 overrun (the red bar) crackles even when mean RTF looks fine.&lt;/p&gt;

&lt;h3 id=&quot;shipping-scorecard-example&quot;&gt;Shipping scorecard (example)&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Criterion&lt;/th&gt;
      &lt;th&gt;Target (illustrative)&lt;/th&gt;
      &lt;th&gt;Pass?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Algorithmic look-ahead&lt;/td&gt;
      &lt;td&gt;≤ product budget (e.g. 20–40 ms class)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;p95 RTF on device&lt;/td&gt;
      &lt;td&gt;≤ 0.5&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;COLA round-trip&lt;/td&gt;
      &lt;td&gt;error below threshold&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DNSMOS / listening&lt;/td&gt;
      &lt;td&gt;vs baseline WebRTC NS&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;No hop warble&lt;/td&gt;
      &lt;td&gt;listening + spectrogram&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Replace illustrative numbers with your product’s SLA. Do not mark “RTF ≤ 0.5” as a pass on algorithmic latency, or the reverse.&lt;/p&gt;

&lt;h3 id=&quot;deepfilternet-class-moral&quot;&gt;DeepFilterNet-class moral&lt;/h3&gt;

&lt;p&gt;The published full-band setup is 48 kHz, a 960-point STFT (20 ms), and 50% overlap (10 ms hop), plus a small frame look-ahead (&lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;). Treat those as hard requirements. Tradeoffs belong in graph placement, resampling, and device budget. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 is a 48 kHz processor on that contract; if p95 RTF fails, do not quietly change the hop.&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;sweep&quot;&gt;Sweep&lt;/h3&gt;

&lt;p&gt;Config A: 16 kHz, L=20 ms, R=10 ms, small model, RTF 0.2, MOS OK.
Config B: 48 kHz, L=40 ms, R=5 ms, large model, RTF 0.9, MOS higher offline, glitches on phone → &lt;strong&gt;do not ship B&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;B’s window is already 40 ms, and mean RTF 0.9 leaves no room for a red-bar quantum.&lt;/p&gt;

&lt;h3 id=&quot;budget-split&quot;&gt;Budget split&lt;/h3&gt;

&lt;p&gt;A 40 ms algorithmic budget that already spends 20 ms on the window cannot also absorb several 10 ms look-ahead frames. Do not “save” the 20 ms by reporting only the 3 ms of wall time.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-keeping-the-two-clocks-separate-in-design-reviews&quot;&gt;Explanation: Keeping the Two Clocks Separate in Design Reviews&lt;/h3&gt;

&lt;h4 id=&quot;step-1-compute-d_mathrmalg-purely-from-the-signal-graph&quot;&gt;Step 1: Compute \(D_{\mathrm{alg}}\) purely from the signal graph&lt;/h4&gt;
&lt;p&gt;Sum every structural delay: \(T_{\text{win}} = L/f_s\) (20 ms for DeepFilterNet 960 @ 48 kHz) + \(l_{\text{look-ahead}} \cdot T_{\text{hop}}\) (e.g., 20 ms for 2 frames) + resampler group delay (0 ms if already at 48 kHz). Notice that wall-clock CPU time does &lt;strong&gt;not&lt;/strong&gt; even appear in this sum!&lt;/p&gt;

&lt;h4 id=&quot;step-2-compute-mathrmrtf-purely-from-wall-clock-profiling-against-t_mathrmhop&quot;&gt;Step 2: Compute \(\mathrm{RTF}\) purely from wall-clock profiling against \(T_{\mathrm{hop}}\)&lt;/h4&gt;
&lt;p&gt;Always divide &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wall_ms&lt;/code&gt; by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hop_ms&lt;/code&gt; (\(10\,\mathrm{ms}\)), &lt;strong&gt;never&lt;/strong&gt; by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frame_ms&lt;/code&gt; (\(20\,\mathrm{ms}\))! Dividing \(12\,\mathrm{ms}\) of wall time by the \(20\,\mathrm{ms}\) window gives a fake RTF of \(0.60\), hiding a catastrophic \(1.20\) overrun on the \(10\,\mathrm{ms}\) hop!&lt;/p&gt;

&lt;h4 id=&quot;step-3-require-both-clocks-to-pass-before-shipping&quot;&gt;Step 3: Require BOTH clocks to pass before shipping&lt;/h4&gt;
&lt;p&gt;A shippable configuration satisfies \(D_{\mathrm{alg}} \le \text{call budget}\) &lt;strong&gt;AND&lt;/strong&gt; \(\mathrm{RTF}_{p95} \le 0.5\) &lt;strong&gt;AND&lt;/strong&gt; bit-clean COLA reconstruction &lt;strong&gt;AND&lt;/strong&gt; better listening quality than baseline WebRTC NS.&lt;/p&gt;

&lt;p&gt;Summary of the dual-clock shipping gate:&lt;/p&gt;

\[\text{Clock 1: } D_{\mathrm{alg}} = \frac{L}{f_s} + l_{\mathrm{LA}}\frac{R}{f_s} + D_{\mathrm{resamp}} \le B_{\mathrm{call}}
\quad\land\quad
\text{Clock 2: } \mathrm{RTF}_{p95} = \frac{T_{\mathrm{wall}, p95}}{R/f_s} \le 0.5.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Optimizing mean RTF only.&lt;/li&gt;
  &lt;li&gt;Changing L/R without regenerating eval sets.&lt;/li&gt;
  &lt;li&gt;Comparing quality at different latencies unfairly.&lt;/li&gt;
  &lt;li&gt;Ignoring resample cost in RTF.&lt;/li&gt;
  &lt;li&gt;Shipping debug builds’ timings as production truth.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Print algorithmic frame delay and RTF as different numbers for one 48 kHz hop, including an overrun case. No audio device required.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;960&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;480&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;frame_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;quantum_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;algorithmic frame ms&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;frame_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hop ms&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;quantum ms&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;quantum_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rtf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wall_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;audio_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wall_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;audio_ms&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;RTF if process() takes 3 ms&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rtf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;3.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;RTF if process() takes 12 ms&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rtf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;12.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; Frame delay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;20.0&lt;/code&gt; ms, hop &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10.0&lt;/code&gt; ms, quantum about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2.67&lt;/code&gt; ms. RTF prints &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.3&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.2&lt;/code&gt;. The second case misses the hop even though 12 ms is less than the 20 ms window.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Dividing wall time by the window instead of the hop reports RTF 12/20 = 0.6 and hides the overrun. Dividing the window by hops/s, or treating RTF 0.3 as “3 ms of latency,” mixes the two clocks and will pass a scorecard that users still hear as delay or as crackle. A p99 of 12 ms with a mean of 3 ms is the figure’s warning: log both.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Draw the 9-stage pipeline and mark where you would log timestamps.&lt;/li&gt;
  &lt;li&gt;If hop goes 10→5 ms, what happens to hops/s and CPU roughly?&lt;/li&gt;
  &lt;li&gt;Propose three scorecard metrics for a customer-support softphone.&lt;/li&gt;
  &lt;li&gt;Why might 48 kHz hurt a 16 kHz-trained model even if CPU allows?&lt;/li&gt;
  &lt;li&gt;Name one quality artifact from too-short windows.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Stamp capture, after resample, STFT in, STFT out, and encoder handoff; subtract to separate delay from wall time.&lt;/li&gt;
  &lt;li&gt;hops/s doubles (100 → 200 at 48 kHz if the hop was 480 samples); STFT CPU roughly doubles. \(D_{\mathrm{alg}}\) does not halve unless \(L\) changes.&lt;/li&gt;
  &lt;li&gt;For example p95 RTF, algorithmic delay against the call budget, and a listening/DNSMOS check on names and digits.&lt;/li&gt;
  &lt;li&gt;The network’s bins and ERB edges are laid out for 16 kHz; 48 kHz audio labeled as 16 kHz is the wrong spectrum, and extra bandwidth may alias in if you forgot the low-pass.&lt;/li&gt;
  &lt;li&gt;Unresolved harmonics and harsh, flickery masks; plosives smeared is the opposite fault, from a window that is too long.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DeepFilterNet real-time framing, &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt; and &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;github.com/Rikorose/DeepFilterNet&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;WebRTC APM overview: &lt;a href=&quot;https://webrtc.googlesource.com/src/+/refs/heads/main/modules/audio_processing/&quot;&gt;modules/audio_processing&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;MDN AudioWorklet performance guidance — quanta versus your hop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the stated latency next to the two enhancement stages. Algorithmic delay is how late the audio is; the multiply-add rate is whether the CPU keeps up.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. The complexity section is the quality side of the same trade: a heavier model can win a test and still miss a hop.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, English. Measured callback latency is the pipeline budget the STFT hop has to fit inside.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-06 Spectrograms: reading speech and noise</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_06_spectrograms_reading/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_06_spectrograms_reading</id>
   <content type="html">&lt;p&gt;A spectrogram is to an audio engineer what an X-ray is to a radiologist—and just like an X-ray, changing the contrast knob can make a healthy lung look broken or hide a fracture completely. A spectrogram is &lt;strong&gt;not&lt;/strong&gt; a raw picture of “the audio”; it is \(20\log_{10}(\max(\vert X(\ell, k)\vert, \varepsilon))\) computed from one specific STFT window, hop, and dB floor!&lt;/p&gt;

&lt;p&gt;This lesson trains your eye to read speech anatomy (harmonics, formants, plosives, fricatives), noise signatures (HVAC, clicks, babble), and enhancement artifacts (musical noise speckles, hop-rate COLA stripes, over-suppression)—while remembering the one thing every magnitude spectrogram hides: &lt;strong&gt;phase&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/spectrogram-reading.png&quot; alt=&quot;A speech spectrogram: stacked horizontal harmonic lines, then a vertical broadband noise burst&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Voiced harmonics are a vertical stack of ridges; a noise burst is a vertical bar that fills every band at once.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (log-magnitude color scales, speech vs. noise time–frequency geometry, what spectrograms hide) → 5-step diagnostic reading procedure &amp;amp; landmark tables → Worked examples: mapping 200/400/600 Hz harmonics to fractional bins \(6.4, 12.8, 19.2\) and stamping reproducible plot metadata → Explanation: 3-step visual triage of before/after NS spectrograms → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-visual-diagnostics-in-timefrequency-space&quot;&gt;Key ideas: Visual Diagnostics in Time–Frequency Space&lt;/h2&gt;

&lt;h3 id=&quot;1-decibel-compression-and-the-floor-clamp-varepsilon&quot;&gt;1. Decibel Compression and the Floor Clamp \(\varepsilon\)&lt;/h3&gt;
&lt;p&gt;Human hearing spans over 100 dB of dynamic range; plotting raw linear magnitude \(\vert X(\ell, k)\vert\) makes quiet fricatives and noise floors invisible next to loud vowels. Taking \(S(\ell, k) = 20\log_{10}(\max(\vert X(\ell, k)\vert, \varepsilon))\) reveals subtle structure, provided you fix a consistent floor (e.g., \(-80\,\mathrm{dB}\)) across before/after comparisons.&lt;/p&gt;

&lt;h3 id=&quot;2-geometry-of-speech-vs-noise&quot;&gt;2. Geometry of Speech vs. Noise&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Horizontal stacks&lt;/strong&gt; = periodic pitched energy (voiced vowels, music), spaced by fundamental frequency \(f_0\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Broad dark blobs across harmonics&lt;/strong&gt; = vocal-tract &lt;strong&gt;formants&lt;/strong&gt; that carry vowel identity.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Vertical broadband bars&lt;/strong&gt; = sharp time transients (plosives /p/, /t/, /k/, keyboard clicks, door slams).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High-frequency diffuse clouds&lt;/strong&gt; = unvoiced fricatives (/s/, /f/, /sh/) or fan hiss.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-the-blind-spot-phase-is-invisible&quot;&gt;3. The Blind Spot: Phase Is Invisible&lt;/h3&gt;
&lt;p&gt;A magnitude spectrogram discards \(\arg X(\ell, k)\) completely. Two clips can have &lt;em&gt;identical&lt;/em&gt; clean-looking spectrograms while one sounds crisp and the other sounds hollow and metallic due to noisy phase reuse or broken Hermitian symmetry—which is why spectrograms always &lt;strong&gt;pair with&lt;/strong&gt;, never replace, listening.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Interpret spectrogram axes (time, frequency, dB color).&lt;/li&gt;
  &lt;li&gt;Recognize voiced harmonics, formants, fricatives, and silence.&lt;/li&gt;
  &lt;li&gt;Identify stationary noise floors, bursts, babble, and music.&lt;/li&gt;
  &lt;li&gt;Spot common NS artifacts (musical noise, over-suppression, warble).&lt;/li&gt;
  &lt;li&gt;Use spectrograms responsibly alongside listening and metrics.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Anatomy of a spectrogram plot&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–28&lt;/td&gt;
      &lt;td&gt;Speech patterns gallery (describe without audio)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Noise gallery + mixture reading&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Before/after NS artifact reading&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;axes-and-scaling&quot;&gt;Axes and scaling&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;X:&lt;/strong&gt; time (s) or frame index.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Y:&lt;/strong&gt; Hz (linear) or Mel/ERB (perceptual).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Color:&lt;/strong&gt; usually \(20\log_{10}\vert X(\ell,k)\vert\) with a floor clamp.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Always record: \(f_s\), window, hop, FFT size, dB range (e.g. −80..0 dB). Without these, screenshots are not science.&lt;/p&gt;

&lt;p&gt;The color computation is worth writing once:&lt;/p&gt;

\[S(\ell,k)=20\log_{10}\bigl(\max(\vert X(\ell,k)\vert,\,\varepsilon)\bigr).\]

&lt;p&gt;\(\varepsilon\) is the floor. Without it, a silent bin (exact zero after a hard mask) becomes \(-\infty\) and the colormap stretches around a single hole, so the rest of the utterance looks like a flat beige bar. With a floor at, say, −80 dB relative to a full-scale sine, silence is a dark color and a vowel’s harmonics stay visible. Two screenshots are comparable only when \(\varepsilon\), the window, and the hop match. A Mel axis will not line up with linear-bin bugs: bin \(k\) maps to \(k f_s/N\) hertz, and a Mel filterbank has already summed those bins.&lt;/p&gt;

&lt;h3 id=&quot;a-reading-procedure&quot;&gt;A reading procedure&lt;/h3&gt;

&lt;p&gt;Use the figure as the worked case, then the same order on every bug-ticket image.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Stamp the STFT.&lt;/strong&gt; Read \(f_s\), window, hop, \(N\), and the dB range off the caption before you interpret color. The figure’s ridges sit near 1.2, 2.4, 3.6, 4.8, 6.0, and 7.2 kHz: a 1.2 kHz fundamental and its harmonics, drawn on a linear hertz axis.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Find silence or the noise floor.&lt;/strong&gt; The dark regions before 0.2 s and after the burst are the floor. If that floor is already bright, either the mic is hissy or the color scale is zoomed into the bottom 20 dB. Do not call the model “under-suppressing” until you know which.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Look for a harmonic stack.&lt;/strong&gt; Horizontal ridges, equally spaced, mean voiced speech (or music). Spacing is \(f_0\). In the figure the gap is about 1.2 kHz, which is a high pitched vowel or a sung note, not a typical 100–200 Hz speaking voice — the geometry is the same, the spacing is the pitch.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Look for vertical events.&lt;/strong&gt; A plosive or a noise burst lights many bins in one or two frames. The orange bar from about 0.85 s to 1.0 s is that: energy at every frequency, not a new harmonic. Keyboard clicks and coughs look similar and narrower.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Only then compare before and after NS&lt;/strong&gt;, on the same scale. Missing upper ridges mean over-suppression of harmonics. Speckles in the dark region mean musical noise. Periodic light/dark time stripes locked to the hop mean COLA or gain pumping, not “more noise.”&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Phase errors never appear in \(S(\ell,k)\). A watery residual with a clean magnitude spectrogram is a phase-reuse problem (lesson 02-04), and the picture will not confess.&lt;/p&gt;

&lt;h3 id=&quot;speech-landmarks&quot;&gt;Speech landmarks&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Pattern&lt;/th&gt;
      &lt;th&gt;Look&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Voiced vowel&lt;/td&gt;
      &lt;td&gt;Harmonic striations; dark formant bands&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Pitch change&lt;/td&gt;
      &lt;td&gt;Striations tilt / spacing change&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Plosive&lt;/td&gt;
      &lt;td&gt;Vertical broadband burst + closure gap&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Fricative&lt;/td&gt;
      &lt;td&gt;High-frequency noisy cloud&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Silence&lt;/td&gt;
      &lt;td&gt;Near floor (mic noise remaining)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;noise-landmarks&quot;&gt;Noise landmarks&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Noise&lt;/th&gt;
      &lt;th&gt;Look&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;HVAC&lt;/td&gt;
      &lt;td&gt;Low-frequency persistent ridge&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Fan hiss&lt;/td&gt;
      &lt;td&gt;Elevated broadband floor&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Keyboard&lt;/td&gt;
      &lt;td&gt;Thin vertical spikes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Babble&lt;/td&gt;
      &lt;td&gt;Speech-like but unruly competing structure&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Music&lt;/td&gt;
      &lt;td&gt;Stable harmonic stacks unlike speech formant motion&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;artifact-landmarks-after-ns&quot;&gt;Artifact landmarks after NS&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Artifact&lt;/th&gt;
      &lt;th&gt;Look / sound&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Musical noise&lt;/td&gt;
      &lt;td&gt;Speckled isolated bins in time&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Over-suppression&lt;/td&gt;
      &lt;td&gt;Missing fricative clouds; muffled&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hop warble&lt;/td&gt;
      &lt;td&gt;Periodic amplitude stripes at hop rate&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Residual reverb&lt;/td&gt;
      &lt;td&gt;Vertical smearing lasting after speech&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;good-practice&quot;&gt;Good practice&lt;/h3&gt;

&lt;p&gt;Spectrogram &lt;strong&gt;supports&lt;/strong&gt; listening and SI-SDR/DNSMOS (Ch. 08); it does not replace them. A pretty spectrogram can still sound bad (phase issues invisible on mag plots).&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;parameter-stamp&quot;&gt;Parameter stamp&lt;/h3&gt;

&lt;p&gt;“48 kHz, Hann 20 ms, hop 10 ms, N=1024, dB −70..0” — reproducible. Note \(N=1024\) at 48 kHz is about 21.3 ms if the window equals the FFT, which is &lt;em&gt;not&lt;/em&gt; the DeepFilterNet 960-point grid. Say so in the ticket or you will “fix” the wrong bins.&lt;/p&gt;

&lt;h3 id=&quot;which-bins-hold-the-harmonics&quot;&gt;Which bins hold the harmonics&lt;/h3&gt;

&lt;p&gt;Bin center frequency is \(k f_s/N\). A 200 Hz harmonic at \(f_s=8\,\mathrm{kHz}\), \(N=256\), falls at&lt;/p&gt;

\[k=\frac{200}{8000/256}=6.4,\]

&lt;p&gt;so the energy straddles bins 6 and 7. The second and third harmonics straddle 12–13 and land near 19. The mini-lab prints those bins. If your bug report says “the tone is in bin 200,” you mixed hertz with bin index.&lt;/p&gt;

&lt;h3 id=&quot;misread&quot;&gt;Misread&lt;/h3&gt;

&lt;p&gt;Bright low-frequency bar might be DC bias, not “noise the model failed.” High-pass before plotting if diagnosing NS.&lt;/p&gt;

&lt;h3 id=&quot;babble-vs-target&quot;&gt;Babble vs target&lt;/h3&gt;

&lt;p&gt;Both show harmonics; target often louder/closer (higher SNR tracks). Single-channel NS struggles — spectrogram sets expectations.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-how-to-read-a-beforeafter-ns-spectrogram-without-getting-fooled&quot;&gt;Explanation: How to Read a Before/After NS Spectrogram Without Getting Fooled&lt;/h3&gt;

&lt;h4 id=&quot;step-1-lock-identical-stft-and-db-color-limits-on-both-panels&quot;&gt;Step 1: Lock identical STFT and dB color limits on both panels&lt;/h4&gt;
&lt;p&gt;Always plot &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noisy&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enhanced&lt;/code&gt; with the exact same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vmin=-80, vmax=0&lt;/code&gt; (dB), same window, and same linear Hz axis. Auto-scaling each plot independently makes a quiet clean clip look just as bright as a noisy one!&lt;/p&gt;

&lt;h4 id=&quot;step-2-check-speech-preservation-before-celebrating-a-dark-noise-floor&quot;&gt;Step 2: Check speech preservation BEFORE celebrating a dark noise floor&lt;/h4&gt;
&lt;p&gt;Inspect high-frequency fricative clouds (4–10 kHz) and upper vocal harmonics during active speech. If the background turned pitch-black &lt;em&gt;only&lt;/em&gt; because the suppressor shaved off everything above 3 kHz, listeners will hear a muffled, underwater voice.&lt;/p&gt;

&lt;h4 id=&quot;step-3-hunt-for-geometric-artifact-fingerprints&quot;&gt;Step 3: Hunt for geometric artifact fingerprints&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Salt-and-pepper speckles&lt;/strong&gt; in quiet pauses \(\implies\) &lt;strong&gt;musical noise&lt;/strong&gt; (too little time/frequency gain smoothing).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Regular vertical zebra stripes&lt;/strong&gt; spaced every hop \(R\) \(\implies\) &lt;strong&gt;broken COLA&lt;/strong&gt; or callback underrun, not model error.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Clean-looking plot that still sounds hollow&lt;/strong&gt; \(\implies\) &lt;strong&gt;phase corruption&lt;/strong&gt; (invisible on magnitude plots; check complex filtering / Hermitian symmetry).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Summary of spectrogram diagnostics:&lt;/p&gt;

\[S(\ell, k) = 20\log_{10}\max(\vert X(\ell,k)\vert, \varepsilon)
\;\xrightarrow{\text{Same scale}}\;
\text{Harmonics + Fricatives + Artifacts}
\;\xrightarrow{+ \text{Ears}}\;
\text{Root cause}.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Comparing plots with different dB color ranges.&lt;/li&gt;
  &lt;li&gt;Using Mel plots to debug linear-STFT bin bugs.&lt;/li&gt;
  &lt;li&gt;Declaring victory from a quieter floor alone (speech may be damaged).&lt;/li&gt;
  &lt;li&gt;Ignoring that phase artifacts are mag-invisible.&lt;/li&gt;
  &lt;li&gt;Ultra-long windows that make everything look “stationary.”&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Build a tiny spectrogram from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; frames of a three-harmonic sine and print which bins light up.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;f0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;200.0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.25&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;frame&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;frame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# one column of the spectrogram; bin k &amp;lt;-&amp;gt; k * fs / L Hz
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;top&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;argsort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:][::&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;top bins&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;harmonic &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; expected k&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; Expected centers are &lt;strong&gt;6.4, 12.8, 19.2&lt;/strong&gt;. The strongest bins are the neighbors of those centers (typically 6 and 7 for 200 Hz, 12 and 13 for 400 Hz, and 19 for 600 Hz). That pair-of-bins pattern is leakage of an off-grid harmonic through the Hann main lobe, not noise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Printing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.argmax(mag)&lt;/code&gt; only returns bin 6 and hides the other harmonics. Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fft&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; duplicates the spectrum and shifts the index story. Forgetting the window makes sidelobes (lesson 02-03) promote unrelated bins into the top six. Interpreting bin 6 as 6 Hz instead of \(6\cdot8000/256=187.5\,\mathrm{Hz}\) is the usual ticket bug.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Sketch a spectrogram cartoon of “hello” in noise.&lt;/li&gt;
  &lt;li&gt;How would 10 ms hop COLA failure appear?&lt;/li&gt;
  &lt;li&gt;Why clamp log floors?&lt;/li&gt;
  &lt;li&gt;Name two cues distinguishing music interference from voiced speech.&lt;/li&gt;
  &lt;li&gt;What metadata must accompany a spectrogram in a bug ticket?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;A low-frequency harmonic stack for the vowel, a high-frequency cloud for the fricative, a vertical burst for the /h/ or the stop, on top of a steady floor.&lt;/li&gt;
  &lt;li&gt;Vertical light/dark stripes every 10 ms, locked to the hop, including through steady vowels.&lt;/li&gt;
  &lt;li&gt;Otherwise exact zeros become \(-\infty\) and the color scale collapses.&lt;/li&gt;
  &lt;li&gt;Music keeps rigid harmonic spacing and long stable partials; speech moves its formants and changes \(f_0\) with prosody.&lt;/li&gt;
  &lt;li&gt;\(f_s\), window, hop, FFT size, and dB range.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer, and Julius O. Smith’s spectral audio notes — what a short-time magnitude actually measures.&lt;/li&gt;
  &lt;li&gt;Speech processing textbooks’ spectrogram chapters (standard DSP/speech notes).&lt;/li&gt;
  &lt;li&gt;DNS Challenge visualization examples (dataset pages) and DeepFilterNet paper figures; read the axes before comparing them to a 48 kHz linear STFT.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EfWnEldTyPA&quot;&gt;The Spectrogram and the Gabor Transform&lt;/a&gt; — Steve Brunton, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch how a sliding window becomes a time-frequency image. Read axes before colors; that is the spectrogram this lesson asks you to trust.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=glnUFa2fLyE&quot;&gt;Speech Acoustics 5 - vowel formants&lt;/a&gt; — Listen Lab, English. Watch the dark bands, not every harmonic. Formants are the speech structure a noise suppressor must not erase.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=08mmKNLQVHU&quot;&gt;Coding Adventure: Analyzing Audio&lt;/a&gt; — Sebastian Lague, English. The short-time section shows a voice sliced into frames and drawn as a spectrogram, including how a single full-file FFT lies about timing.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-05 Filtering in time vs frequency</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_05_filtering_time_vs_frequency/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_05_filtering_time_vs_frequency</id>
   <content type="html">&lt;p&gt;At first glance, multiplying an STFT frame by a mask \(G(\ell, k)\) looks just like applying a frequency-domain filter \(H(e^{j\omega})\)—so why do seasoned audio engineers insist they are &lt;em&gt;fundamentally different beasts&lt;/em&gt;? Because a fixed FIR/IIR filter applies one static impulse response \(h[n]\) across the entire recording, whereas a noise suppressor invents a &lt;strong&gt;brand-new time-varying gain \(G(\ell, k)\) on every single 10 ms hop&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;This lesson draws the sharp boundary between time-domain LTI filtering, block FFT convolution (OLA/OLS), and adaptive STFT masking—showing by hand how circular wrap-around breaks naive FFT filtering and when a 2-tap time-domain filter still beats a neural network.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/spectral-subtraction-wiener.png&quot; alt=&quot;Left: per-bin spectral subtraction, a different gain on each frequency bin. Right: a smooth Wiener gain versus SNR, still one multiplier per bin rather than one fixed impulse response&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Both panels are per-bin gains, not a single convolution: the left bars change with the local spectrum, and the right curve assigns a different multiplier to each SNR.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (fixed LTI convolution vs. time-varying STFT gains, circular wrap-around vs. OLA/OLS, group delay in live calls) → Decision guide &amp;amp; DeepFilterNet multi-frame tie-in → Worked examples: 2-tap DC blocker \(h=[1,-1]\), Wiener gain curve \(G = \xi/(1+\xi)\), and an 8-point linear vs. circular convolution mismatch of 8.0 → Explanation: 3 steps choosing the right filtering domain → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-time-domain-vs-frequency-domain-filtering&quot;&gt;Key ideas: Time-Domain vs. Frequency-Domain Filtering&lt;/h2&gt;

&lt;h3 id=&quot;1-fixed-lti-convolution-vs-time-varying-stft-masking&quot;&gt;1. Fixed LTI Convolution vs. Time-Varying STFT Masking&lt;/h3&gt;
&lt;p&gt;A &lt;strong&gt;fixed LTI filter&lt;/strong&gt; \(y[n] = (h * x)[n]\) has one permanent frequency response \(H(e^{j\omega})\)—ideal for DC blocking, anti-alias low-passing, or static EQ, but blind to whether the current frame is a vowel or a coffee-cup clatter. An &lt;strong&gt;adaptive STFT suppressor&lt;/strong&gt; \(\hat{X}(\ell, k) = G(\ell, k)Y(\ell, k)\) updates its gain every hop \(\ell\) to track non-stationary speech and noise.&lt;/p&gt;

&lt;h3 id=&quot;2-circular-vs-linear-convolution-in-block-ffts&quot;&gt;2. Circular vs. Linear Convolution in Block FFTs&lt;/h3&gt;
&lt;p&gt;Multiplying two length-\(N\) DFTs implements &lt;strong&gt;circular&lt;/strong&gt; convolution modulo \(N\), wrapping the filter’s tail onto the beginning of the block! To execute true &lt;strong&gt;linear&lt;/strong&gt; convolution of a long FIR filter \(h\) (length \(L_h\)) with blocks of length \(L_x\), you must zero-pad to \(N \ge L_x + L_h - 1\) and stitch blocks via &lt;strong&gt;Overlap-Add (OLA)&lt;/strong&gt; or &lt;strong&gt;Overlap-Save (OLS)&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;3-group-delay-and-causality-constraints&quot;&gt;3. Group Delay and Causality Constraints&lt;/h3&gt;
&lt;p&gt;A symmetric linear-phase FIR filter of length \(L_h = 2881\) at 48 kHz has pristine magnitude flatness—and a fatal &lt;strong&gt;30 ms group delay&lt;/strong&gt; before any neural model even runs! Real-time calling paths prefer minimum-phase IIR/short FIR filters for pre-processing and causal STFT gains for enhancement.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Contrast time-domain LTI filtering with STFT-domain multiplicative gains.&lt;/li&gt;
  &lt;li&gt;Explain circular vs linear convolution and why OLA/OLS exist.&lt;/li&gt;
  &lt;li&gt;Relate classical Wiener / spectral subtraction gains to STFT filtering.&lt;/li&gt;
  &lt;li&gt;Describe when time-domain methods still win (DC block, click suppression heuristics).&lt;/li&gt;
  &lt;li&gt;Avoid illegal “filter” ops that break streaming COLA.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;LTI convolution review; frequency response&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;STFT-domain gains as time-varying filters&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Convolution via FFT; OLA/OLS&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;NS examples: high-pass, Wiener gain, neural mask&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;time-domain-lti-filter&quot;&gt;Time-domain LTI filter&lt;/h3&gt;

\[y[n]=(h*x)[n]=\sum_k h[k]x[n-k]\]

&lt;p&gt;Frequency response \(H(e^{j\omega})\) multiplies DTFT of \(x\) if \(h\) is fixed. Great for DC blockers, fixed shelving EQ, anti-alias low-passes. Bad alone for non-stationary noise that needs time-varying behavior.&lt;/p&gt;

&lt;p&gt;“Fixed” is the load-bearing word. One \(h\) has one \(H(k)\) for the whole utterance. A 2-tap difference \(h=[1,-1]\) is a high-pass you can write in one line, and its magnitude response does not care whether the current frame is a vowel or a keyboard click. That is why it belongs &lt;em&gt;before&lt;/em&gt; a suppressor as a DC/rumble removal, not instead of one.&lt;/p&gt;

&lt;h3 id=&quot;stft-domain-multiplicative-processing&quot;&gt;STFT-domain multiplicative processing&lt;/h3&gt;

&lt;p&gt;Per frame: \(\hat{X}(\ell,k)=G(\ell,k)Y(\ell,k)\). If \(G\) changes slowly, this approximates a slowly time-varying filter. If \(G\) jumps every hop/bin independently, you get musical noise and COLA stress.&lt;/p&gt;

&lt;p&gt;Classical &lt;strong&gt;spectral subtraction&lt;/strong&gt; and &lt;strong&gt;Wiener filtering&lt;/strong&gt; (Ch. 03) are recipes for \(G\). Neural masks learn \(G\) (or richer deep filters).&lt;/p&gt;

&lt;p&gt;The green bars are a per-bin subtraction (each bin its own gain). The right-hand curve \(H=\xi/(1+\xi)\) is 0.5 when speech and noise powers match (\(-6\,\mathrm{dB}\)). Neither picture is the FFT of one short fixed \(h\).&lt;/p&gt;

&lt;h3 id=&quot;convolution-via-fft&quot;&gt;Convolution via FFT&lt;/h3&gt;

&lt;p&gt;To apply a long FIR \(h\) efficiently: FFT multiply by \(H\), iFFT — but block-wise with &lt;strong&gt;overlap-add&lt;/strong&gt; or &lt;strong&gt;overlap-save&lt;/strong&gt; to realize &lt;em&gt;linear&lt;/em&gt; convolution. Naively multiplying per-frame STFT by a fixed \(H\) without care is not always identical to the same FIR in time — windowing leaks.&lt;/p&gt;

&lt;p&gt;Linear convolution of an 8-point ramp with \(h=[1,-1]\) has a tail; an 8-point circular convolution wraps that tail onto sample 0 (the mini-lab’s mismatch is 8). &lt;strong&gt;Overlap-add&lt;/strong&gt; keeps the tail and adds it into the next block. &lt;strong&gt;Overlap-save&lt;/strong&gt; discards the wrapped edge and hops by the valid samples. A per-bin \(G(\ell,k)\) that changes every hop is a different, time-varying filter, not automatically that FIR.&lt;/p&gt;

&lt;h3 id=&quot;time-vs-frequency-decision-guide&quot;&gt;Time vs frequency: decision guide&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Need&lt;/th&gt;
      &lt;th&gt;Prefer&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Fixed mild EQ / DC remove&lt;/td&gt;
      &lt;td&gt;small IIR/FIR time-domain&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Non-stationary NS&lt;/td&gt;
      &lt;td&gt;STFT + adaptive/neural \(G\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ultra-low CPU click gate&lt;/td&gt;
      &lt;td&gt;time-domain detector + attenuator&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Linear long reverb FIR&lt;/td&gt;
      &lt;td&gt;FFT OLA/OLS convolution&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;deepfilternet-tie-in&quot;&gt;DeepFilterNet tie-in&lt;/h3&gt;

&lt;p&gt;Deep filtering predicts filters across frequency (and temporal context) on complex STFT coefficients — still “frequency-domain filtering,” but richer than diagonal \(G(\ell,k)\). A diagonal gain cannot build a harmonic that the noise destroyed; a short filter along time or frequency can mix neighbors that still have phase structure. Time-domain waveform networks exist in literature; this course’s product alignment emphasizes STFT-centric DeepFilterNet-class pipelines at 48 kHz with the hop and window that match the checkpoint (lessons 02-02 and 02-04).&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;dc-blocker&quot;&gt;DC blocker&lt;/h3&gt;

&lt;p&gt;One-zero filter \(y[n]=x[n]-x[n-1]\) (simplified) high-passes; cheap pre-NS. Does not remove café babble. Its null is at DC (\(H(0)=0\)) and its peak is at Nyquist. Group delay is a fraction of a sample, so it does not eat the conversational latency budget the way a linear-phase FIR of hundreds of taps would.&lt;/p&gt;

&lt;h3 id=&quot;wiener-cartoon&quot;&gt;Wiener cartoon&lt;/h3&gt;

\[G(k)=\frac{P_x(k)}{P_x(k)+P_n(k)}\]

&lt;p&gt;Estimate powers from STFT magnitudes; apply as gains; ISTFT. Non-stationary \(P_n\) estimation is the hard part. This is the right-hand curve of the figure, one number per bin per frame. Chapter 03 derives it and the decision-directed tracker that feeds it.&lt;/p&gt;

&lt;h3 id=&quot;illegal-op&quot;&gt;Illegal op&lt;/h3&gt;

&lt;p&gt;Zeroing random bins each hop without smoothing → birdies. Time-domain equivalent would be a wildly varying impulse response — audible artifacts. Also illegal in a call path: a linear-phase FIR whose group delay is 30 ms. The magnitude response can be perfect and the conversation still feels late, because every sample waits for future context the filter used to stay symmetric.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-picking-the-right-filtering-domain-in-3-steps&quot;&gt;Explanation: Picking the Right Filtering Domain in 3 Steps&lt;/h3&gt;

&lt;h4 id=&quot;step-1-check-whether-the-filter-changes-over-time&quot;&gt;Step 1: Check whether the filter changes over time&lt;/h4&gt;
&lt;p&gt;If the frequency response is &lt;strong&gt;static&lt;/strong&gt; (removing DC bias below 60 Hz, anti-alias low-passing before decimation), a tiny 2–6 tap time-domain IIR/FIR filter runs in nanoseconds with near-zero delay. Do not waste an FFT on it!&lt;/p&gt;

&lt;h4 id=&quot;step-2-watch-circular-wrap-around-when-multiplying-spectra&quot;&gt;Step 2: Watch circular wrap-around when multiplying spectra&lt;/h4&gt;
&lt;p&gt;Take \(x = [1, 2, 3, 4, 5, 6, 7, 8]\) and \(h = [1, -1]\). True linear convolution yields \(y_{\text{lin}} = [1, 1, 1, 1, 1, 1, 1, 1, -8]\) (length \(8 + 2 - 1 = 9\)). If you multiply 8-point FFTs without padding to at least 9, the trailing \(-8\) wraps around and adds onto sample 0, turning \(y[0]\) from \(1\) into \(1 + (-8) = -7\)—an error of &lt;strong&gt;8.0&lt;/strong&gt;!&lt;/p&gt;

&lt;h4 id=&quot;step-3-understand-why-deepfilternet-upgrades-diagonal-masks-to-multi-frame-complex-filters&quot;&gt;Step 3: Understand why DeepFilterNet upgrades diagonal masks to multi-frame complex filters&lt;/h4&gt;
&lt;p&gt;A diagonal STFT gain \(\hat{X}(\ell, k) = G(\ell, k)Y(\ell, k)\) scales each bin in isolation. DeepFilterNet instead applies a short complex FIR filter across adjacent time frames \(\sum_{i=0}^{N_{\mathrm{DF}}-1} c_i(\ell, k)\,Y(\ell - i + l_{\mathrm{DF}}, k)\), recovering periodic harmonic structure even when a single frame is buried in noise!&lt;/p&gt;

&lt;p&gt;Summary of filtering domains:&lt;/p&gt;

\[\text{Static (DC/LPF)} \to \text{Short time-domain IIR/FIR}
\quad\vert\quad
\text{Adaptive NS} \to \text{Smooth STFT gain } G(\ell,k) \text{ / Deep Filtering}.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Assuming STFT gain multiply == arbitrary FIR exactly.&lt;/li&gt;
  &lt;li&gt;Using very long FIR in time on the audio thread without FFT acceleration.&lt;/li&gt;
  &lt;li&gt;Cascading unrelated high-pass + NS without measuring speech loss.&lt;/li&gt;
  &lt;li&gt;Applying linear-phase FIR with huge group delay in a call path.&lt;/li&gt;
  &lt;li&gt;Forgetting real-time causality when designing “cool” offline filters.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Contrast one fixed FIR (convolution) with a per-bin Wiener gain, and see circular convolution fail to match linear convolution.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;H&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fixed |H|&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;10.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# a priori SNR, five bins
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;G&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;per-bin G&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dtype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y_lin&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;convolve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;h_pad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;h_pad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y_circ&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;irfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h_pad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;linear   &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_lin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;circular &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y_circ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;max |linear[:8] - circular|&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y_lin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_circ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fixed |H|&lt;/code&gt; starts at 0 (DC null) and grows toward Nyquist. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;per-bin G&lt;/code&gt; is about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0.091, 0.231, 0.5, 0.75, 0.909]&lt;/code&gt; — a different shape, recomputed from SNR, not from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt;. Linear convolution ends in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-8&lt;/code&gt;; circular convolution wraps that tail onto the first sample. The max absolute mismatch on the first 8 samples is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;8.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; If the mismatch prints as 0, you zero-padded &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt; as well as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt; and accidentally computed linear convolution; that hides the bug OLA/OLS exist to fix. If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;G&lt;/code&gt; equals &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|H|&lt;/code&gt;, the SNR vector was replaced by the FIR. A DC blocker that does not print a 0 in the first bin of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|H|&lt;/code&gt; is not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h=[1,-1]&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Give one filter better in time-domain before NS.&lt;/li&gt;
  &lt;li&gt;Why do unsmoothed per-bin gains click/twitter?&lt;/li&gt;
  &lt;li&gt;OLA vs OLS: one-sentence distinction.&lt;/li&gt;
  &lt;li&gt;If group delay is 30 ms from a linear-phase FIR, is it call-safe?&lt;/li&gt;
  &lt;li&gt;Sketch how a neural mask is still a filter \(G(\ell,k)\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;A one-zero DC blocker, or the anti-alias low-pass in front of a 48→16 kHz downsample.&lt;/li&gt;
  &lt;li&gt;Each hop’s inverse transform is a different impulse response, so the OLA boundary jumps.&lt;/li&gt;
  &lt;li&gt;OLA keeps the convolution tail and adds it into the next block; OLS discards the time-aliased edge and hops by the valid part.&lt;/li&gt;
  &lt;li&gt;No for a live call: 30 ms is already a conversational delay before the encoder and the network.&lt;/li&gt;
  &lt;li&gt;\(\hat{X}(\ell,k)=G(\ell,k)Y(\ell,k)\) with \(G\) predicted per bin (or a short deep filter around that bin).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — filtering, FFT convolution, STFT processing.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Spectral Audio Signal Processing&lt;/em&gt; — overlap-add and overlap-save.&lt;/li&gt;
  &lt;li&gt;Classical speech enhancement (Wiener / spectral subtraction) as the bridge to Ch. 03. Boll, 1979, is the subtraction classic; the Wiener speech form is the next lesson.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=KuXjwB4LzSA&quot;&gt;But what is a convolution?&lt;/a&gt; — 3Blue1Brown, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the convolution theorem: a filter is a moving weighted average in time and a multiply in frequency. That is the domain choice in the lesson.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xb--68NlxS0&quot;&gt;Spectral Subtraction In Python - Alexx Mitchell&lt;/a&gt; — The Audio Programmer, English. The diagram is a per-bin magnitude rule, which is frequency-domain filtering under a noise estimate rather than a fixed FIR.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=K_U0yeVdblU&quot;&gt;Lec 22: Causal IIR Wiener Filter&lt;/a&gt; — NPTEL IIT Guwahati, English. This is the classical causal Wiener derivation, not a speech mask. Watch the gain that shrinks when the measurement is noisy; the lesson’s per-bin speech gain is that idea on an STFT.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-04 STFT / ISTFT for speech (DeepFilterNet tie-in)</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_04_stft_istft_speech/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_04_stft_istft_speech</id>
   <content type="html">&lt;p&gt;Every piece we built in Lessons 02-01 through 02-03—PCM scaling, overlapping frames, periodic Hann windows, and COLA—now clicks together into the single most important transform in speech enhancement: the &lt;strong&gt;Short-Time Fourier Transform (STFT)&lt;/strong&gt; and its inverse (&lt;strong&gt;ISTFT&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Whether you run classical Wiener filtering or &lt;strong&gt;DeepFilterNet3&lt;/strong&gt; at 48 kHz full-band, your enhancer lives on a 2D complex time–frequency grid \(X(\ell, k)\). This lesson makes the STFT/ISTFT contract exact, contrasts simple magnitude masking with complex deep filtering, and maps the published DeepFilterNet grid (\(f_s = 48\,\mathrm{kHz}\), \(N_{\mathrm{FFT}} = 960\), \(R = 480\)) onto real tensor shapes.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/stft-ola.png&quot; alt=&quot;The same overlap-add picture as framing: analysis frames, Hann windows stepping by hop R, and the window sum that ISTFT relies on&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Each colored frame is one STFT column; ISTFT overlap-adds the inverse frames, and the bottom sum must be constant or the sine wave on top comes back with a hop-rate envelope.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (the STFT time–frequency grid, magnitude masks vs. complex deep filtering, offline centered vs. causal streaming STFT) → Forward STFT &amp;amp; Inverse ISTFT equations → Published DeepFilterNet 48 kHz grid → Worked examples: computing exact tensor shapes for 16 kHz / 512 and 48 kHz / 960 (481 bins) and phase-reuse limits → Explanation: 3 steps verifying perfect reconstruction before adding a model → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-timefrequency-grids-and-speech-enhancement-front-ends&quot;&gt;Key ideas: Time–Frequency Grids and Speech Enhancement Front-Ends&lt;/h2&gt;

&lt;h3 id=&quot;1-the-stft-as-a-2d-complex-matrix-xell-k&quot;&gt;1. The STFT as a 2D Complex Matrix \(X(\ell, k)\)&lt;/h3&gt;
&lt;p&gt;Sliding a length-\(L\) analysis window across a waveform in steps of \(R\) and taking an \(N\)-point &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; produces a complex matrix of shape \([N/2 + 1,\; T_{\text{frames}}]\). Each column \(\ell\) is a snapshot of the local spectrum; each row \(k\) tracks how one frequency bin evolves over time.&lt;/p&gt;

&lt;h3 id=&quot;2-magnitude-masks-vs-complex-deep-filtering&quot;&gt;2. Magnitude Masks vs. Complex Deep Filtering&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Magnitude masking&lt;/strong&gt; multiplies \(\vert Y(\ell, k)\vert\) by a real gain \(M(\ell, k) \in [0, 1]\) and reuses the noisy phase \(\arg Y\). It is cheap, but at low SNR the noisy phase is corrupted, leaving speech sounding watery.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Complex deep filtering&lt;/strong&gt; (used by DeepFilterNet) predicts small complex FIR filters across neighboring time frames for each frequency bin—jointly refining both magnitude &lt;em&gt;and&lt;/em&gt; phase!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-centered-offline-stft-vs-causal-streaming-stft&quot;&gt;3. Centered Offline STFT vs. Causal Streaming STFT&lt;/h3&gt;
&lt;p&gt;Libraries like PyTorch &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.stft(..., center=True)&lt;/code&gt; pad \(L/2\) samples on the left, shifting every frame by \(L/2\) relative to a causal streaming STFT. Both satisfy COLA individually, yet mixing a centered training STFT with a causal serving STFT silently shifts alignment and degrades SI-SDR.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Build a mental model of the STFT grid (time × frequency).&lt;/li&gt;
  &lt;li&gt;Contrast magnitude masks, complex masks, and deep filtering ideas.&lt;/li&gt;
  &lt;li&gt;State practical perfect-reconstruction conditions.&lt;/li&gt;
  &lt;li&gt;Map STFT parameters (rate, \(N\), hop, window) to latency and resolution.&lt;/li&gt;
  &lt;li&gt;Connect DeepFilterNet’s published STFT-centric design to engineering parameters.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;STFT definition; spectrogram as \(\vert\text{STFT}\vert\)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;ISTFT / OLA; perfect reconstruction drills&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Mag vs complex processing; deep filtering intuition&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;DeepFilterNet paper parameter extraction exercise&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;stft&quot;&gt;STFT&lt;/h3&gt;

\[X(\ell,k)=\sum_{n=0}^{L-1}x[n+\ell R]\,w[n]\,e^{-j2\pi kn/N}\]

&lt;p&gt;Here \(w[n]\) is the &lt;strong&gt;analysis&lt;/strong&gt; window \(w_{\mathrm{ana}}\). Grid: columns = time frames \(\ell\), rows = frequency bins \(k\). Speech enhancement estimates clean \(\hat{X}(\ell,k)\) from noisy \(Y(\ell,k)\).&lt;/p&gt;

&lt;p&gt;\(N\) is the FFT length. It may exceed \(L\) when you zero-pad; smaller than \(L\) time-aliases the frame. Bin spacing is \(f_s/N\), but resolution is still the window (lesson 02-03). A real signal has \(N/2+1\) unique bins, Nyquist in the last.&lt;/p&gt;

&lt;h3 id=&quot;istft&quot;&gt;ISTFT&lt;/h3&gt;

&lt;p&gt;Inverse FFT per frame, optional synthesis window, then OLA. One frame of the inverse, before overlap-add, is&lt;/p&gt;

\[y_\ell[n]=\frac{1}{N}\sum_{k=0}^{N-1}\hat{X}(\ell,k)\,e^{j2\pi kn/N},\qquad n=0,\ldots,L-1\]

&lt;p&gt;(with the usual real-FFT packing when you call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;irfft&lt;/code&gt;). The waveform is&lt;/p&gt;

\[\hat{x}[n]=\sum_\ell w_{\mathrm{syn}}[n-\ell R]\,y_\ell[n-\ell R].\]

&lt;p&gt;If the forward transform already multiplied by \(w\) and \(w_{\mathrm{syn}}=1\), unmodified reconstruction reduces to \(\sum_\ell w[n-\ell R]=C\) and a divide by \(C\). If you also multiply by a synthesis window, COLA is the product sum from lesson 02-02:&lt;/p&gt;

\[\sum_\ell w[n-\ell R]\,w_{\mathrm{syn}}[n-\ell R]=C.\]

&lt;p&gt;If no modification and COLA holds, reconstruct \(x\) (delay/gain aside). A centered offline STFT shifts by about \(L/2\) relative to a causal stream; both can be COLA and still disagree by enough delay to wreck SI-SDR.&lt;/p&gt;

&lt;h3 id=&quot;representations&quot;&gt;Representations&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Representation&lt;/th&gt;
      &lt;th&gt;Contents&lt;/th&gt;
      &lt;th&gt;Typical use&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Complex \(X\)&lt;/td&gt;
      &lt;td&gt;real/imag or mag/phase&lt;/td&gt;
      &lt;td&gt;deep filtering, complex masks&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Magnitude \(\vert X\vert\)&lt;/td&gt;
      &lt;td&gt;nonneg&lt;/td&gt;
      &lt;td&gt;classical Wiener, mag masks&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Log-mag / dB&lt;/td&gt;
      &lt;td&gt;compressed&lt;/td&gt;
      &lt;td&gt;features, plots&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;ERB / Mel filterbanks&lt;/td&gt;
      &lt;td&gt;band energies&lt;/td&gt;
      &lt;td&gt;perceptual front-ends (DeepFilterNet uses ERB-scale features in papers)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;magnitude-masks-vs-deep-filtering-intuition&quot;&gt;Magnitude masks vs deep filtering (intuition)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Magnitude mask:&lt;/strong&gt; \(\hat{X}=M\odot\vert Y\vert e^{j\arg Y}\) (reuse noisy phase). Cheap; phase errors on low SNR.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complex mask / filtering:&lt;/strong&gt; predict filters that mix neighboring time-frequency bins — &lt;strong&gt;deep filtering&lt;/strong&gt; in DeepFilterNet literature applies learned filters on complex spectra to better recover structure than independent per-bin gains.&lt;/p&gt;

&lt;p&gt;Read DeepFilterNet / DeepFilterNet2 / DeepFilterNet3 papers for the precise architecture; this lesson only needs the engineering moral: &lt;strong&gt;you are modifying an STFT grid under causal constraints&lt;/strong&gt;, then ISTFT-ing back.&lt;/p&gt;

&lt;h3 id=&quot;perfect-reconstruction-practice&quot;&gt;Perfect reconstruction practice&lt;/h3&gt;

&lt;p&gt;Unit test: STFT→ISTFT without model ≈ identity. Then enable the model. If identity already fails, stop. The mini-lab is that test on a sine: float64 error around \(10^{-15}\) in the interior. An error of \(10^{-2}\) is a window or hop bug and becomes a hop-rate tremolo.&lt;/p&gt;

&lt;h3 id=&quot;parameter-mapping&quot;&gt;Parameter mapping&lt;/h3&gt;

&lt;p&gt;Extract from docs/papers:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
\[f_s\]
  &lt;/li&gt;
  &lt;li&gt;window type &amp;amp; \(L\) / FFT \(N\)&lt;/li&gt;
  &lt;li&gt;hop \(R\)&lt;/li&gt;
  &lt;li&gt;causal look-ahead&lt;/li&gt;
  &lt;li&gt;mono assumption&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Translate to ms and hops/s using Ch. 01–02 formulas before integration testing with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; or ORT.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Published DeepFilterNet grid.&lt;/strong&gt; The framework is specified for rates up to 48 kHz, and the reported full-band setup uses \(N_{\mathrm{FFT}}=960\) (20 ms at 48 kHz) with 50% overlap, so \(R=480\) (10 ms). See Schröter et al., &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;, and the reference configuration in &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;Rikorose/DeepFilterNet&lt;/a&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sr=48000&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fft_size=960&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hop_size=480&lt;/code&gt;). The window is part of that checkpoint: whatever analysis/synthesis pair the library applies, hop and window must match the model. The npm package &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 follows the same 48 kHz full-band contract. Swapping in a 16 kHz hop, a Blackman window, or a centered offline STFT does not “improve quality”; it feeds the ERB filterbank a different grid than the weights expect.&lt;/p&gt;

&lt;p&gt;That setup also reports a small convolutional look-ahead (\(l_{\mathrm{DNN}}=2\) frames and \(l_{\mathrm{DF}}=1\) frame). At a 10 ms hop those frames sit on top of the 20 ms window. Copy them from the checkpoint.&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;grid-shape&quot;&gt;Grid shape&lt;/h3&gt;

&lt;p&gt;1 s @ 16 kHz, \(R=256\), \(N=512\) real FFT → about \(16000/256\approx 62\) frames (edge policy can change this by one), 257 unique bins (0..Nyquist). A mask tensor might be \([1,257,62]\) or channels-first variants — match the model.&lt;/p&gt;

&lt;p&gt;2 s @ 48 kHz, \(R=480\), \(N=960\): frames \(\approx 96000/480=200\), unique bins \(960/2+1=481\). That is the shape family a 48 kHz DeepFilterNet integration has to allocate, not 257 bins.&lt;/p&gt;

&lt;h3 id=&quot;phase-reuse-limit&quot;&gt;Phase reuse limit&lt;/h3&gt;

&lt;p&gt;Low-SNR bin: noisy phase ≈ random. Magnitude mask cleans energy but residual sounds watery. Complex methods try harder — still not magic under babble.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-the-3-step-stftistft-contract-for-neural-speech-enhancement&quot;&gt;Explanation: The 3-Step STFT/ISTFT Contract for Neural Speech Enhancement&lt;/h3&gt;

&lt;h4 id=&quot;step-1-lock-the-five-grid-numbers-from-the-model-card&quot;&gt;Step 1: Lock the five grid numbers from the model card&lt;/h4&gt;
&lt;p&gt;Before writing a single line of inference code, copy \((f_s,\; L,\; N,\; R,\; w_{\mathrm{ana}}/w_{\mathrm{syn}})\) verbatim from the training config. For DeepFilterNet full-band: \(f_s = 48{,}000\), \(L = N = 960\), \(R = 480\), giving \(481\) real-FFT bins spaced by \(50\,\mathrm{Hz}\) and \(100\) frames per second.&lt;/p&gt;

&lt;h4 id=&quot;step-2-verify-bit-level-round-trip-identity-in-the-steady-interior&quot;&gt;Step 2: Verify bit-level round-trip identity in the steady interior&lt;/h4&gt;
&lt;p&gt;Run a pure sine wave through your streaming STFT \(\to\) ISTFT with no neural mask and check \(\max \vert \hat{x}[n] - x[n]\vert\) for \(n \in [L,\; N_{\text{tot}} - L]\). Float64 error must be \(\sim 10^{-15}\) (float32 \(\sim 10^{-6}\)). Anything around \(10^{-2}\) means your window or COLA divisor is broken.&lt;/p&gt;

&lt;h4 id=&quot;step-3-understand-why-istft-after-masking-is-a-projection-not-always-an-exact-stft&quot;&gt;Step 3: Understand why ISTFT after masking is a &lt;em&gt;projection&lt;/em&gt;, not always an exact STFT&lt;/h4&gt;
&lt;p&gt;When a suppressor modifies \(Y(\ell, k) \mapsto \hat{X}(\ell, k)\), adjacent modified frames may no longer be 100% mutually consistent in the time domain. Overlap-add acts as a &lt;strong&gt;least-squares projection&lt;/strong&gt; back onto a consistent waveform—which is why smooth complex masks (or DeepFilterNet’s multi-frame complex filters) synthesize far cleaner speech than jagged per-bin magnitude gates!&lt;/p&gt;

&lt;p&gt;Summary of the STFT enhancement pipeline:&lt;/p&gt;

\[x[n]
\;\xrightarrow{\text{Window } w_{\mathrm{ana}} + \text{rfft}}\;
Y(\ell, k) \in \mathbb{C}^{481 \times T}
\;\xrightarrow{\text{ERB + Deep Filtering}}\;
\hat{X}(\ell, k)
\;\xrightarrow{\text{irfft} + \text{COLA OLA}}\;
\hat{x}[n].\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Centering frames offline but not in streaming (alignment skew).&lt;/li&gt;
  &lt;li&gt;Training with different hop than serving.&lt;/li&gt;
  &lt;li&gt;Feeding Mel features into a model that expects ERB or linear STFT.&lt;/li&gt;
  &lt;li&gt;Batch ISTFT on whole files in prod (latency).&lt;/li&gt;
  &lt;li&gt;Claiming undocumented Mezon STFT constants from this course.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Round-trip a 440 Hz sine through an analysis-window STFT and an overlap-add ISTFT, and print the max absolute error in the interior.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;440&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;starts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;specs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;starts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros_like&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros_like&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;spec&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;specs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;irfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# analysis window already in the frame
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;slice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;max abs error&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;max abs error&lt;/code&gt; on the order of \(10^{-15}\) (float64 roundoff). The COLA divisor &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;acc&lt;/code&gt; is the constant 1 in the interior, as in lesson 02-02.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Omitting the divide by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;acc&lt;/code&gt; leaves a half-scale or rippling output and an error near \(10^{-1}\). Using a symmetric Hann, or applying &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt; again on the inverse frame, produces a hop-periodic error large enough to hear. Scoring the first &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L&lt;/code&gt; samples, where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;acc&lt;/code&gt; has not reached the constant, inflates the error even when the steady region is perfect. A non-zero error with this exact script means the FFT backend is not round-tripping, not that COLA is optional.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Write STFT shapes for 2 s audio @ 48 kHz, \(R=480\), \(N=960\) (approx frames).&lt;/li&gt;
  &lt;li&gt;Why reuse noisy phase fails in deep noise?&lt;/li&gt;
  &lt;li&gt;List four parameters to copy from a DeepFilterNet config into your integrator checklist.&lt;/li&gt;
  &lt;li&gt;What does COLA failure sound like after ISTFT?&lt;/li&gt;
  &lt;li&gt;ERB vs linear STFT: one reason for ERB in speech enhancement front-ends?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;About 200 frames and 481 real bins.&lt;/li&gt;
  &lt;li&gt;At low SNR the noisy phase is close to the noise’s phase, so a perfect magnitude still modulates the speech.&lt;/li&gt;
  &lt;li&gt;\(f_s\), FFT length, hop, window (and any stated look-ahead). The public defaults to check are 48 kHz, 960, 480.&lt;/li&gt;
  &lt;li&gt;Amplitude tremolo at \(f_s/R\) (100 Hz for a 10 ms hop).&lt;/li&gt;
  &lt;li&gt;ERB spends bins where the ear (and speech formants) have resolution, instead of uniform hertz.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DeepFilterNet, DeepFilterNet2, DeepFilterNet3 papers — STFT, ERB, deep filtering sections. Start at &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt; and the reference code &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;github.com/Rikorose/DeepFilterNet&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Spectral Audio Signal Processing&lt;/em&gt; — STFT and ISTFT definitions consistent with the windows.&lt;/li&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — filter banks / STFT connections.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-Yxj3yfvY-4&quot;&gt;Short-Time Fourier Transform Explained Easily&lt;/a&gt; — Valerio Velardo - The Sound of AI, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch analysis frames and the idea that an inverse transform has to undo them. That pair is the STFT/ISTFT contract for speech.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EfWnEldTyPA&quot;&gt;The Spectrogram and the Gabor Transform&lt;/a&gt; — Steve Brunton, English. A moving window on a Fourier transform is the spectrogram. Use it as the speech-time picture DeepFilterNet’s front end assumes.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. Watch the STFT into ERB bands and the inverse STFT out. The lesson’s DeepFilterNet tie-in is this block, not the training loss.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-03 Windowing and spectral leakage</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_03_windowing_leakage/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_03_windowing_leakage</id>
   <content type="html">&lt;p&gt;Even if you “never applied a window” to your audio frame, you already applied one—the harshest window in signal processing: a &lt;strong&gt;rectangular chop&lt;/strong&gt; that slams your waveform to zero at both ends of the buffer. That abrupt cliff smears every off-bin vocal harmonic across dozens of neighboring FFT bins with sidelobes only &lt;strong&gt;13 dB&lt;/strong&gt; below the main peak—loud enough to fool a noise estimator and trigger metallic “musical noise” chirps!&lt;/p&gt;

&lt;p&gt;Tapering the frame smoothly to zero with a &lt;strong&gt;Hann window&lt;/strong&gt; crushes that first sidelobe down to &lt;strong&gt;−31 dB&lt;/strong&gt; (an 18 dB cleaner floor) at the cost of a slightly wider main lobe. This lesson unpacks the exact main-lobe vs. sidelobe tradeoff, why window gain shifts Parseval checks by 6 dB, and why you should always test windows on a &lt;em&gt;half-bin&lt;/em&gt; tone.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/window-leakage.png&quot; alt=&quot;Rectangular window versus Hann: the rectangular transform keeps a slow sinc tail, the Hann transform drops its sidelobes and widens the main lobe&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Peak-normalized magnitude of a windowed tone: the rectangular window leaks a slow sidelobe tail, while the Hann window trades a wider main lobe for a much lower floor.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (time multiplication = spectral convolution, main-lobe vs. sidelobe tradeoff, window gain &amp;amp; COLA) → Window catalog (Rectangular, Hann, Hamming, Blackman) → Resolution tradeoffs &amp;amp; musical noise → Worked examples: 48 kHz Hann main-lobe width (200 Hz) and testing a half-bin tone (bin 32.5) → Explanation: 3 steps from edge discontinuity to −31 dB sidelobes → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-spectral-leakage-and-window-design&quot;&gt;Key ideas: Spectral Leakage and Window Design&lt;/h2&gt;

&lt;h3 id=&quot;1-time-multiplication--frequency-convolution&quot;&gt;1. Time Multiplication = Frequency Convolution&lt;/h3&gt;
&lt;p&gt;Extracting a finite frame multiplies the infinite signal \(x[n]\) by a window \(w[n]\). In frequency, that &lt;strong&gt;convolves&lt;/strong&gt; the true spectrum \(X(e^{j\omega})\) with the window’s Fourier transform \(W(e^{j\omega})\). Every pure sinusoid stops being a razor-thin spike and becomes a copy of \(W(e^{j\omega})\) centered at its frequency!&lt;/p&gt;

&lt;h3 id=&quot;2-the-universal-tradeoff-main-lobe-width-vs-sidelobe-height&quot;&gt;2. The Universal Tradeoff: Main-Lobe Width vs. Sidelobe Height&lt;/h3&gt;
&lt;p&gt;A window’s spectrum \(W(e^{j\omega})\) has two competing features:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Main-lobe width&lt;/strong&gt; (controls how close two tones can sit before merging into one blob—narrowest for Rectangular at ~2 bins, wider for Hann at ~4 bins).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sidelobe height&lt;/strong&gt; (controls how much energy leaks into distant bins—poor for Rectangular at \(-13\,\mathrm{dB}\), much cleaner for Hann at \(-31\,\mathrm{dB}\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-window-gain-and-why-independent-bin-masks-cause-musical-noise&quot;&gt;3. Window Gain and Why Independent-Bin Masks Cause Musical Noise&lt;/h3&gt;
&lt;p&gt;Because a Hann window has mean \(1/2\), multiplying a signal by it drops broadband magnitude by half (\(\approx -6\,\mathrm{dB}\))—which you must account for in Parseval/PSD checks. Furthermore, because real harmonics spill across adjacent bins inside \(W(e^{j\omega})\), hard per-bin masking chops sidelobes unevenly and creates isolated flickering peaks (&lt;strong&gt;musical noise&lt;/strong&gt;).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Explain spectral leakage from rectangular truncation.&lt;/li&gt;
  &lt;li&gt;Compare common windows (Hann, Hamming, Blackman) qualitatively.&lt;/li&gt;
  &lt;li&gt;Connect main-lobe width to frequency resolution and time localization.&lt;/li&gt;
  &lt;li&gt;State how windows interact with COLA and NS masking.&lt;/li&gt;
  &lt;li&gt;Choose windows consistently with a pretrained STFT front-end.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Rectangular window leakage demo (thought/plot)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;Window catalog; sidelobe vs main lobe&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;COLA + window choice; doubling windows&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Musical noise link to bin independence myth&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;leakage-mechanism&quot;&gt;Leakage mechanism&lt;/h3&gt;

&lt;p&gt;Multiplying by \(w[n]\) convolves the DTFT with \(W(e^{j\omega})\). Rectangular \(w\) has high sidelobes → distant bins contaminated. Tapered windows lower sidelobes, widen main lobe → nearby bins blurred together.&lt;/p&gt;

&lt;p&gt;A finite frame is already a multiply by a rectangle, even when you “did not apply a window.” The DTFT of that rectangle is a Dirichlet kernel. Its first sidelobe peaks about &lt;strong&gt;13 dB below&lt;/strong&gt; the main lobe, and the tail falls slowly. A tone that misses the bin center — every real speech harmonic eventually does — dumps energy tens of bins away at a level a noise tracker can mistake for noise.&lt;/p&gt;

&lt;p&gt;The Hann window is the periodic raised cosine from lesson 02-02,&lt;/p&gt;

\[w[n]=\frac12-\frac12\cos\frac{2\pi n}{L}.\]

&lt;p&gt;Its transform cancels that slow tail: the first sidelobe falls to about &lt;strong&gt;−31 dB&lt;/strong&gt;, roughly 18 dB quieter, and the far sidelobes keep falling. The price is main-lobe width, about four bins null-to-null instead of two. Lengthening \(L\) and switching to Hann are different knobs.&lt;/p&gt;

&lt;p&gt;The figure is that comparison. Read the axis as dB relative to the peak.&lt;/p&gt;

&lt;h3 id=&quot;qualitative-comparison&quot;&gt;Qualitative comparison&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Window&lt;/th&gt;
      &lt;th&gt;Sidelobes&lt;/th&gt;
      &lt;th&gt;Main lobe&lt;/th&gt;
      &lt;th&gt;Notes&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Rectangular&lt;/td&gt;
      &lt;td&gt;poor (first sidelobe ≈ −13 dB)&lt;/td&gt;
      &lt;td&gt;narrowest (~2 bins)&lt;/td&gt;
      &lt;td&gt;analysis curiosity; implicit if you skip windowing&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hann&lt;/td&gt;
      &lt;td&gt;good (first sidelobe ≈ −31 dB)&lt;/td&gt;
      &lt;td&gt;wider (~4 bins)&lt;/td&gt;
      &lt;td&gt;STFT favorite; COLA @ 50% with the periodic form&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hamming&lt;/td&gt;
      &lt;td&gt;similar&lt;/td&gt;
      &lt;td&gt;similar&lt;/td&gt;
      &lt;td&gt;sidelobe floor differs; not the same COLA identity&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Blackman&lt;/td&gt;
      &lt;td&gt;lower sidelobes&lt;/td&gt;
      &lt;td&gt;wider&lt;/td&gt;
      &lt;td&gt;more smoothing; do not swap in for a Hann model&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Exact coefficients are standard; copy from a DSP reference when implementing — do not invent. Hamming’s endpoints are not zero, so it is a poor drop-in replacement for a Hann COLA pair even though the plots “look alike.”&lt;/p&gt;

&lt;h3 id=&quot;resolution-tradeoff&quot;&gt;Resolution tradeoff&lt;/h3&gt;

&lt;p&gt;Effective frequency resolution \(\sim \alpha f_s/L\) with \(\alpha&amp;gt;1\) depending on window. Time localization \(\sim L/f_s\). Speech NS wants enough resolution to separate formants/noise floors, enough time locality for consonants — hence mid-length windows (tens of ms), not 1 ms and not 1 s.&lt;/p&gt;

&lt;p&gt;At 48 kHz with \(L=960\), a Hann main lobe of about four bins is \(4\cdot48000/960=200\,\mathrm{Hz}\) wide. It will not split harmonics of a low voice, and it smears a 5 ms plosive across the 20 ms window. Finer bins mean a longer \(L\) and more latency. Less distant leakage means a different window, not zero-padding: padding interpolates \(W(e^{j\omega})\), it does not narrow it.&lt;/p&gt;

&lt;h3 id=&quot;windows-and-masks&quot;&gt;Windows and masks&lt;/h3&gt;

&lt;p&gt;Neural/classical gains that jump wildly across adjacent bins fight the window’s inherent smoothing — or create musical noise when bins are treated as independent. Smooth masks in frequency (and time) match physics better. A rectangular analysis makes the “independent bin” assumption especially false: bin \(k+8\) still contains the tone from bin \(k\) at a level you can hear. Suppressing “noise bins” with a hard gate then chops the sidelobes of the vowel and leaves the main lobe, which is one recipe for musical noise even before the noise estimate is wrong.&lt;/p&gt;

&lt;h3 id=&quot;analysis-vs-synthesis&quot;&gt;Analysis vs synthesis&lt;/h3&gt;

&lt;p&gt;Some pipelines use \(w\) on analysis only and a different synthesis window for COLA. Others use \(\sqrt{\text{Hann}}\) on both (power complementary designs). &lt;strong&gt;Match training.&lt;/strong&gt; Randomly switching to Blackman “for quality” breaks reconstruction. Lesson 02-02 showed why the square of a Hann is not COLA: the product \(w\cdot w\) ripples between \(1/2\) and \(1\). The square root splits that window so each side is tapered and the product still sums flat.&lt;/p&gt;

&lt;p&gt;Window gain also moves Parseval checks. A Hann has mean \(1/2\), so an unnormalized analysis cuts broadband power by about 6 dB before any suppressor runs. SI-SDR against a time-domain reference will look like a systematic loss until you divide by the COLA constant or compensate the synthesis gain.&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;on-bin-vs-off-bin&quot;&gt;On-bin vs off-bin&lt;/h3&gt;

&lt;p&gt;16 kHz, \(L=512\), tone exactly bin 32 vs bin 32.5. Rectangular: off-bin spreads widely. Hann: sidelobes drop, main lobe wider — both bins 32 and 33 light up. An on-bin tone under a periodic window can look almost ideal (sidelobes at numerical floor) and will hide a bad window choice. Always test a half-bin offset. The mini-lab does that and prints the empirical sidelobe, which is not identical to the −13 / −31 dB textbook peaks because the peak sits between bins and the measurement skips a guard around it; the gap between rectangle and Hann is the same lesson as the figure.&lt;/p&gt;

&lt;h3 id=&quot;musical-noise&quot;&gt;Musical noise&lt;/h3&gt;

&lt;p&gt;Spectral subtraction with independent bin floors → isolated bin spikes surviving as birdies. Over-smoothing helps but blurs speech — classic tension before neural SE.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-why-tapering-to-zero-crushes-sidelobes-by-18-db&quot;&gt;Explanation: Why Tapering to Zero Crushes Sidelobes by 18 dB&lt;/h3&gt;

&lt;h4 id=&quot;step-1-see-why-the-rectangular-window-leaks-slowly-1f-decay&quot;&gt;Step 1: See why the rectangular window leaks slowly (\(1/f\) decay)&lt;/h4&gt;
&lt;p&gt;Under periodic extension, an off-bin sine wave jumps abruptly between sample \(L-1\) and sample \(0\)—a step discontinuity! The Fourier transform of a step discontinuity decays slowly as \(1/f\), leaving high sidelobes (\(-13\,\mathrm{dB}\) at the first peak) far away from the true tone.&lt;/p&gt;

&lt;h4 id=&quot;step-2-decompose-the-hann-window-into-three-shifted-sincs&quot;&gt;Step 2: Decompose the Hann window into three shifted sincs&lt;/h4&gt;
&lt;p&gt;Write \(w[n] = \frac{1}{2} - \frac{1}{4}e^{j2\pi n/L} - \frac{1}{4}e^{-j2\pi n/L}\). In frequency, its transform \(W(\omega)\) is a central rectangular sinc &lt;strong&gt;minus&lt;/strong&gt; two half-amplitude sincs shifted by \(\pm 1\) bin! In the far tails, those opposite-sign sinc lobes cancel each other out, speeding the decay from \(1/f\) to \(1/f^3\) and dropping the first sidelobe from \(-13\,\mathrm{dB}\) to \(-31\,\mathrm{dB}\)!&lt;/p&gt;

&lt;h4 id=&quot;step-3-always-test-window-leakage-at-a-half-bin-frequency-k--05&quot;&gt;Step 3: Always test window leakage at a half-bin frequency (\(k + 0.5\))&lt;/h4&gt;
&lt;p&gt;At an integer bin \(k\), the zeros of the rectangular Dirichlet kernel land &lt;em&gt;right on top of&lt;/em&gt; all other FFT bins, creating an illusion of zero leakage. Testing at \(k + 0.5\) places every other bin right on the sidelobe peaks—exposing the real gap between Rectangular and Hann!&lt;/p&gt;

&lt;p&gt;Summary of the windowing tradeoff:&lt;/p&gt;

\[x[n]\cdot w[n]
\;\xleftrightarrow{\text{DTFT}}\;
X * W
\;\Longrightarrow\;
\text{Rect } (-13\,\mathrm{dB},\ 2\text{ bins})
\;\text{vs.}\;
\text{Hann } (-31\,\mathrm{dB},\ 4\text{ bins}).\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Applying window twice unintentionally (pre-windowed API + manual window).&lt;/li&gt;
  &lt;li&gt;Using rectangular for NS because “FFT needs it.”&lt;/li&gt;
  &lt;li&gt;Ignoring window gain when checking Parseval / SI-SDR.&lt;/li&gt;
  &lt;li&gt;Different windows in train vs serve.&lt;/li&gt;
  &lt;li&gt;Expecting window alone to fix aliasing (it will not).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; FFT one off-bin sine under a rectangular window and under a periodic Hann, and print the sidelobe level in dB relative to the peak.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;32.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# halfway between bins 32 and 33
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hann&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sidelobe_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;guard&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;argmax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;side&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;concatenate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;guard&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:]])&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;side&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;rect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;han&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hann&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rect sidelobe dB&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sidelobe_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hann sidelobe dB&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sidelobe_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;han&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; Rectangular sidelobe near &lt;strong&gt;−17 dB&lt;/strong&gt;, Hann near &lt;strong&gt;−40 dB&lt;/strong&gt; (guard of 3 bins around an off-bin peak). The Hann number is lower, and the main lobe is the wider of the two if you plot them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; An integer bin (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;32 * fs / N&lt;/code&gt;) drives both sidelobes to the numerical floor (below −200 dB) and teaches nothing. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.hann&lt;/code&gt; versus the periodic formula changes the Hann number slightly but should not close the gap. Forgetting to normalize by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mag.max()&lt;/code&gt; prints absolute FFT units, not dB relative to the peak. A guard of 0 reports the main-lobe shoulder as a “sidelobe” and both windows look similarly bad.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Why do tapered windows reduce sidelobes?&lt;/li&gt;
  &lt;li&gt;If \(L\) doubles, what happens to main-lobe width roughly?&lt;/li&gt;
  &lt;li&gt;Name a COLA-friendly hop for Hann (common choice).&lt;/li&gt;
  &lt;li&gt;How can aggressive per-bin masks create musical noise?&lt;/li&gt;
  &lt;li&gt;Give one reason \(\sqrt{\text{Hann}}\) appears in STFT codebases.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;The window’s transform \(W\) has smaller sidelobes, and multiplication by \(w\) convolves the tone with \(W\).&lt;/li&gt;
  &lt;li&gt;Width in hertz scales as \(f_s/L\), so it halves; width in bins stays about 4 for a Hann.&lt;/li&gt;
  &lt;li&gt;\(R=L/2\) for the periodic Hann (lesson 02-02).&lt;/li&gt;
  &lt;li&gt;Hard zeros between bins chop the sidelobes of a real harmonic and leave isolated peaks that chirp after ISTFT.&lt;/li&gt;
  &lt;li&gt;So analysis and synthesis can each be tapered while their product still satisfies COLA.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — windows and spectral analysis.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Spectral Audio Signal Processing&lt;/em&gt; — sidelobe level and main-lobe width.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet STFT configuration: &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=tCWU9C-LdJQ&quot;&gt;Lecture 13: Spectral Leakage, Windowing, with Examples of Hanning and Hamming Windows&lt;/a&gt; — Bahga Lab IIT Delhi, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the rectangular sidelobes against Hann and Hamming. That main-lobe versus leakage trade is the whole lesson.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=MBnnXbOM5S4&quot;&gt;The more general uncertainty principle, regarding Fourier transforms&lt;/a&gt; — 3Blue1Brown, English. A shorter window is a shorter observation. The uncertainty section says why the main lobe must widen.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-Yxj3yfvY-4&quot;&gt;Short-Time Fourier Transform Explained Easily&lt;/a&gt; — Valerio Velardo - The Sound of AI, English. The window-multiply step shows the same taper on a speech frame, which is where leakage becomes musical noise later.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-02 Frames, hop size, and overlap-add</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_02_frames_hop_overlap_add/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_02_frames_hop_overlap_add</id>
   <content type="html">&lt;p&gt;Slice a continuous voice stream into separate 20 ms chunks, filter each chunk in the frequency domain, and butt the chunks end-to-end without overlap: you will hear a harsh, unmistakable buzz at 50 Hz—even if your neural network is perfect! Why? Because modifying frequency bins slightly shifts each block’s boundary, creating jump discontinuities every time one frame hands off to the next.&lt;/p&gt;

&lt;p&gt;The cure is &lt;strong&gt;overlapping frames glued back together by Overlap-Add (OLA)&lt;/strong&gt;—governed by a single algebraic rule called &lt;strong&gt;Constant Overlap-Add (COLA)&lt;/strong&gt;. This lesson derives the exact COLA identity for the periodic Hann window by hand, shows why accidentally windowing twice creates a hop-rate tremolo, and puts concrete milliseconds on \(L\) and \(R\).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/stft-ola.png&quot; alt=&quot;Overlapping analysis frames, sliding Hann windows of length L and hop R, and their overlap-add sum&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Frames of length \(L\) advance by hop \(R\); overlap-add rebuilds the waveform only where the sum of the shifted windows is constant.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (framing parameters \(L, R, \rho\), COLA perfect reconstruction, analysis vs. synthesis windowing) → Periodic Hann COLA derivation &amp;amp; double-window ripple trap → Streaming OLA accumulator mechanics → Worked examples: DeepFilterNet 48 kHz (\(L=960, R=480\)), 16 kHz (\(L=512, R=256\)), and diagnosing a 100 Hz COLA tremolo → Explanation: 3 steps explaining periodic vs. symmetric Hann and \(\sqrt{\mathrm{Hann}}\) → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-short-time-framing-and-overlap-add-reconstruction&quot;&gt;Key ideas: Short-Time Framing and Overlap-Add Reconstruction&lt;/h2&gt;

&lt;h3 id=&quot;1-two-independent-clocks-window-length-l-vs-hop-size-r&quot;&gt;1. Two Independent Clocks: Window Length \(L\) vs. Hop Size \(R\)&lt;/h3&gt;
&lt;p&gt;Every streaming STFT is parameterized by two integers: the &lt;strong&gt;window length \(L\)&lt;/strong&gt; (how many samples sit inside one FFT, controlling frequency resolution and initial buffering delay \(T_L = L / f_s\)) and the &lt;strong&gt;hop size \(R\)&lt;/strong&gt; (how many fresh samples arrive before the next FFT, controlling CPU cadence \(f_s / R\) and overlap ratio \(\rho = 1 - R/L\)).&lt;/p&gt;

&lt;h3 id=&quot;2-the-cola-constant-overlap-add-condition&quot;&gt;2. The COLA (Constant Overlap-Add) Condition&lt;/h3&gt;
&lt;p&gt;When an unmodified signal goes through analysis window \(w_{\mathrm{ana}}\), FFT, iFFT, synthesis window \(w_{\mathrm{syn}}\), and overlap-add, the output equals \(x[n]\) multiplied by the shifted window-product sum \(\sum_m w_{\mathrm{ana}}[n-mR]\,w_{\mathrm{syn}}[n-mR]\). Perfect reconstruction requires that sum to be a &lt;strong&gt;flat constant \(C\)&lt;/strong&gt; across every interior sample—otherwise the pipeline imprints a periodic amplitude tremolo at \(f_s / R\) Hz!&lt;/p&gt;

&lt;h3 id=&quot;3-periodic-vs-symmetric-windows-and-sqrtmathrmhann&quot;&gt;3. Periodic vs. Symmetric Windows and \(\sqrt{\mathrm{Hann}}\)&lt;/h3&gt;
&lt;p&gt;A subtle off-by-one trap breaks countless first STFT implementations: &lt;strong&gt;periodic Hann&lt;/strong&gt; (dividing by \(L\), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sym=False&lt;/code&gt;) sums to exactly \(1.0\) at 50% overlap, whereas &lt;strong&gt;symmetric Hann&lt;/strong&gt; (dividing by \(L-1\)) does not. And if you want &lt;em&gt;both&lt;/em&gt; analysis and synthesis tapering, you must split the window into \(w_{\mathrm{ana}} = w_{\mathrm{syn}} = \sqrt{w}\) so their product stays COLA!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Define frame length \(L\), hop \(R\), and overlap ratio.&lt;/li&gt;
  &lt;li&gt;Explain overlap-add reconstruction and the COLA condition.&lt;/li&gt;
  &lt;li&gt;Compute algorithmic delay implications of \(L\) and \(R\).&lt;/li&gt;
  &lt;li&gt;Choose hops for speech NS with latency/quality intuition.&lt;/li&gt;
  &lt;li&gt;Implement a mental model of streaming OLA buffers.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Frame/hop diagrams on the whiteboard&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;OLA math; COLA with Hann examples&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Streaming buffer mechanics; edge effects&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Numerics at 16/48 kHz for speech&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;framing&quot;&gt;Framing&lt;/h3&gt;

&lt;p&gt;Window length \(L\) samples; hop \(R\) samples (\(1\le R\le L\)). Overlap ratio:&lt;/p&gt;

\[\rho = 1-\frac{R}{L}\]

&lt;p&gt;50% overlap means \(R=L/2\); 75% means \(R=L/4\). The hop is also the number of new samples you must collect before the next FFT, so&lt;/p&gt;

\[T_R=\frac{R}{f_s},\qquad \text{hops/s}=\frac{f_s}{R},\qquad T_L=\frac{L}{f_s}.\]

&lt;p&gt;\(T_L\) is how much audio sits inside one analysis frame. \(T_R\) is how often you emit a new frame. They are not interchangeable: a 20 ms window with a 10 ms hop still looks at 20 ms of context every time it runs.&lt;/p&gt;

&lt;h3 id=&quot;overlap-add&quot;&gt;Overlap-add&lt;/h3&gt;

&lt;p&gt;Given modified frames \(y_m[n]=w_{\mathrm{syn}}[n]\cdot \mathrm{iFFT}(\hat{X}_m)\), output:&lt;/p&gt;

\[\hat{x}[n]=\sum_m y_m[n-mR]\]

&lt;p&gt;If \(\hat{X}_m\) equals analysis STFT of \(x\) and windows satisfy &lt;strong&gt;COLA&lt;/strong&gt;, \(\hat{x}\) reconstructs \(x\) (up to delay/gain). The analysis step already multiplied by \(w_{\mathrm{ana}}\). Anything you multiply again after the iFFT is \(w_{\mathrm{syn}}\). Writing both down is how you avoid windowing twice.&lt;/p&gt;

&lt;h3 id=&quot;cola-constant-overlap-add&quot;&gt;COLA (constant overlap-add)&lt;/h3&gt;

&lt;p&gt;For hop \(R\), analysis/synthesis windows must make the sum of shifted window products constant:&lt;/p&gt;

\[\sum_m w_{\mathrm{ana}}[n-mR]\,w_{\mathrm{syn}}[n-mR] = C\]

&lt;p&gt;(Exact statement depends on whether windows are applied once or twice; be consistent with your STFT definition.) Hann with 50% overlap is a classic COLA choice when used carefully.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Derivation for the periodic Hann.&lt;/strong&gt; Define&lt;/p&gt;

\[w[n]=\frac12-\frac12\cos\frac{2\pi n}{L},\qquad n=0,\ldots,L-1.\]

&lt;p&gt;The denominator is \(L\), not \(L-1\). That is the &lt;em&gt;periodic&lt;/em&gt; Hann (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sym=False&lt;/code&gt; in NumPy). The symmetric Hann that forces \(w[0]=w[L-1]=0\) does &lt;strong&gt;not&lt;/strong&gt; sum to a constant, and it is a common reason a “Hann 50%” unit test fails by a few thousandths.&lt;/p&gt;

&lt;p&gt;Set \(R=L/2\) and consider an interior sample where two windows cover \(n\). Let \(\theta=2\pi n/L\). Then&lt;/p&gt;

\[w[n]=\frac12(1-\cos\theta),\qquad
w[n+R]=\frac12\bigl(1-\cos(\theta+\pi)\bigr)=\frac12(1+\cos\theta).\]

&lt;p&gt;Add them:&lt;/p&gt;

\[w[n]+w[n+R]=\frac12(1-\cos\theta)+\frac12(1+\cos\theta)=1.\]

&lt;p&gt;So if \(w_{\mathrm{ana}}=w\) and \(w_{\mathrm{syn}}=1\) on the frame (you do not window a second time), the COLA sum in the steady region is the constant \(C=1\). The mini-lab prints that constant.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is not constant.&lt;/strong&gt; The sum of &lt;em&gt;squares&lt;/em&gt; of the same window is&lt;/p&gt;

\[w[n]^2+w[n+R]^2=\frac12\bigl(1+\cos^2\theta\bigr),\]

&lt;p&gt;which ripples between \(1/2\) and \(1\). If you apply the full Hann on the way in and again on the way out, the product sum is this ripple, and the waveform pumps at \(f_s/R\) hertz. The usual repair is to split the window: \(w_{\mathrm{ana}}=w_{\mathrm{syn}}=\sqrt{w}\). Then the product is \(w\), and the sum of products is the constant we just proved. That is why \(\sqrt{\mathrm{Hann}}\) shows up in STFT code even though the COLA identity is about \(w\).&lt;/p&gt;

&lt;h3 id=&quot;latency&quot;&gt;Latency&lt;/h3&gt;

&lt;p&gt;Larger \(L\) → more frequency detail, more buffering delay. Smaller \(R\) → denser updates, higher CPU (more hops/s), often smoother masks. Product NS usually lives in the 5–20 ms hop ballpark for speech, but &lt;strong&gt;match the model&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For a causal streaming analysis window, the algorithmic delay is on the order of the window, not the hop:&lt;/p&gt;

\[D_{\mathrm{alg}}\approx T_L=\frac{L}{f_s}.\]

&lt;p&gt;You cannot form the frame until its last sample has arrived. Shrinking \(R\) from \(L/2\) to \(L/4\) doubles hops/s but does not cut \(D_{\mathrm{alg}}\) in half. A centered STFT needs about \(T_L/2\) of look-ahead. Lesson 02-07 separates this delay from real-time factor.&lt;/p&gt;

&lt;h3 id=&quot;streaming-ola-buffer&quot;&gt;Streaming OLA buffer&lt;/h3&gt;

&lt;p&gt;Keep an output accumulator of length \(\ge L\). Each hop, add the new frame, emit the \(R\) samples no future frame will touch, and carry the tail. The first \(L-R\) samples are a partial sum, not the constant \(C\); fade them. Clearing the accumulator on every callback restarts that partial sum and &lt;em&gt;is&lt;/em&gt; the tremolo.&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;numbers&quot;&gt;Numbers&lt;/h3&gt;

&lt;p&gt;\(f_s=48\,\mathrm{kHz}\), \(L=960\) (20 ms), \(R=480\) (10 ms): \(\rho=0.5\), hops/s \(=48000/480=100\), \(D_{\mathrm{alg}}\approx 20\,\mathrm{ms}\). This is the public DeepFilterNet analysis grid: \(N_{\mathrm{FFT}}=960\) at 48 kHz with 50% overlap (&lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;\(f_s=16\,\mathrm{kHz}\), \(L=512\), \(R=256\): \(T_L=512/16000=32\,\mathrm{ms}\), \(T_R=16\,\mathrm{ms}\), hops/s \(=62.5\). (Dividing samples by \(f_s\) is the whole calculation; 512 samples is not 16 ms at 16 kHz.)&lt;/p&gt;

&lt;p&gt;A 10 ms hop at 16 kHz is \(R=160\), not 256.&lt;/p&gt;

&lt;h3 id=&quot;broken-cola-symptom&quot;&gt;Broken COLA symptom&lt;/h3&gt;

&lt;p&gt;Amplitude tremolo at \(f_s/R\) Hz (e.g. 100 Hz for a 10 ms hop). Listeners say “robotic” or “phasey.” A neural gain bug does not lock to exactly \(f_s/R\); a COLA bug does.&lt;/p&gt;

&lt;h3 id=&quot;warm-up&quot;&gt;Warm-up&lt;/h3&gt;

&lt;p&gt;The first \(L-R\) samples may be incomplete — discard or fade them before you score SI-SDR.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-why-periodic-hann--50-overlap-worksand-why-double-hann-fails&quot;&gt;Explanation: Why Periodic Hann + 50% Overlap Works—and Why Double Hann Fails&lt;/h3&gt;

&lt;h4 id=&quot;step-1-check-a-concrete-4-sample-periodic-hann-window-by-hand&quot;&gt;Step 1: Check a concrete 4-sample periodic Hann window by hand&lt;/h4&gt;
&lt;p&gt;Set \(L = 4, R = 2\). Evaluating \(w[n] = \frac{1}{2}(1 - \cos(2\pi n/4))\) gives \(w = [0,\; 0.5,\; 1.0,\; 0.5]\). Now shift by \(R = 2\) and add overlapping copies:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Copy 0: \([0,\; 0.5,\; 1.0,\; 0.5,\; 0,\; 0]\)&lt;/li&gt;
  &lt;li&gt;Copy 1: \([0,\; 0,\; 0,\; 0.5,\; 1.0,\; 0.5]\)&lt;/li&gt;
  &lt;li&gt;Sum in the interior (samples 2 and 3): \(1.0 + 0 = 1.0\) and \(0.5 + 0.5 = 1.0\)—&lt;strong&gt;dead flat!&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;step-2-watch-the-same-4-samples-fail-if-you-square-the-window-hann-in--hann-out&quot;&gt;Step 2: Watch the same 4 samples fail if you square the window (Hann in + Hann out)&lt;/h4&gt;
&lt;p&gt;Squaring gives \(w^2 = [0,\; 0.25,\; 1.0,\; 0.25]\). Adding Copy 0 and Copy 1 in the interior gives \(1.0 + 0 = 1.0\) at sample 2, then \(0.25 + 0.25 = 0.5\) at sample 3—a massive &lt;strong&gt;2:1 amplitude ripple&lt;/strong&gt; pulsing at the hop rate!&lt;/p&gt;

&lt;h4 id=&quot;step-3-repair-it-cleanly-with-sqrtmathrmhann&quot;&gt;Step 3: Repair it cleanly with \(\sqrt{\mathrm{Hann}}\)&lt;/h4&gt;
&lt;p&gt;Using \(w_{\mathrm{ana}} = w_{\mathrm{syn}} = \sqrt{w} = [0,\; \frac{1}{\sqrt{2}},\; 1,\; \frac{1}{\sqrt{2}}]\) tapers both edges (smoothing block discontinuities after spectral masking) while keeping the product \(w_{\mathrm{ana}} w_{\mathrm{syn}} = w\) flatly COLA!&lt;/p&gt;

&lt;p&gt;Summary of the OLA perfect-reconstruction rule:&lt;/p&gt;

\[w_{\mathrm{ana}} = w_{\mathrm{syn}} = \sqrt{w_{\text{Hann, periodic}}}
\;\xrightarrow{R = L/2}\;
\sum_m w_{\mathrm{ana}}[n-mR]\,w_{\mathrm{syn}}[n-mR] \equiv 1
\;\Longrightarrow\;
\hat{x}[n] = x[n].\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Analysis Hann + synthesis rectangular without checking COLA.&lt;/li&gt;
  &lt;li&gt;Changing hop but reusing windows from another hop.&lt;/li&gt;
  &lt;li&gt;Emitting full \(L\) samples every hop (massive overlap redundancy / desync).&lt;/li&gt;
  &lt;li&gt;Clearing OLA memory each callback.&lt;/li&gt;
  &lt;li&gt;Offline STFT (center-padded) vs streaming STFT mismatch in eval.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Overlap-add a periodic Hann at 50% hop and check that the sum is exactly flat in the interior.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# periodic Hann, not np.hann default
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;acc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;COLA constant&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;peak deviation&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; The printed constant is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.0&lt;/code&gt;. The peak deviation is on the order of \(10^{-15}\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.hann(L)&lt;/code&gt; (symmetric) makes the deviation jump to about \(10^{-2}\) or worse: the endpoints are both zero, so the pairwise sum derived above is not 1. Summing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w**2&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt; prints a constant that wanders between 0.5 and 1 — that is the double-window ripple, and the assertion must fail. A hop of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L/4&lt;/code&gt; with this same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt; is also not flat; 50% is the hop the identity used.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Overlap ratio for \(L=1024\), \(R=256\)?&lt;/li&gt;
  &lt;li&gt;Hop ms at 16 kHz with \(R=160\)?&lt;/li&gt;
  &lt;li&gt;Why does smaller hop increase CPU?&lt;/li&gt;
  &lt;li&gt;Sketch OLA buffer after 3 hops of length \(L=8\), \(R=4\) (toy).&lt;/li&gt;
  &lt;li&gt;Name one test signal to verify COLA (hint: impulse or linear chirp).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(\rho=1-256/1024=0.75\).&lt;/li&gt;
  &lt;li&gt;\(160/16000=10\,\mathrm{ms}\).&lt;/li&gt;
  &lt;li&gt;hops/s \(=f_s/R\) rises, and you run an FFT on every hop.&lt;/li&gt;
  &lt;li&gt;After three hops the accumulator holds a full interior region of length \(R\) where two windows overlap, plus a tail of length \(L-R\).&lt;/li&gt;
  &lt;li&gt;An impulse (or a constant) makes a non-flat COLA sum visible as a periodic amplitude envelope; a chirp also exposes time smearing.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — STFT / filterbank / OLA sections.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Spectral Audio Signal Processing&lt;/em&gt; — COLA and the Hann identity.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet framing: &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;, &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;github.com/Rikorose/DeepFilterNet&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-Yxj3yfvY-4&quot;&gt;Short-Time Fourier Transform Explained Easily&lt;/a&gt; — Valerio Velardo - The Sound of AI, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the frame, the hop, and the window multiply. Overlap-add is how those windowed frames become a waveform again.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=NA0TwPsECUQ&quot;&gt;Short-time Fourier Transform and the Spectogram&lt;/a&gt; — Barry Van Veen, English. The short-time transform lecture shows why successive frames must overlap if the spectrogram is going to invert.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=KuXjwB4LzSA&quot;&gt;But what is a convolution?&lt;/a&gt; — 3Blue1Brown, English. The FFT section is the part to watch: convolution in time is multiplication in frequency, and overlap-add is how a long signal is stitched back.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>02-01 PCM, sample rates, and channels</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_01_pcm_sample_rates_channels/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter02/02_01_pcm_sample_rates_channels</id>
   <content type="html">&lt;p&gt;Neural noise suppressors eat clean &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; tensors; real microphones hand you raw &lt;strong&gt;PCM byte streams&lt;/strong&gt;—sometimes signed 16-bit integers, sometimes 44.1 kHz instead of 48 kHz, sometimes interleaved stereo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LRLRLR...&lt;/code&gt; pretending to be mono. A single silent mismatch at this edge layer can either fold 7 kHz into 1 kHz, shift pitch by 8%, or turn anti-correlated stereo into exact silence before your model ever sees sample zero.&lt;/p&gt;

&lt;p&gt;Welcome to Chapter 02, where we build the complete &lt;strong&gt;audio processing pipeline&lt;/strong&gt;. This first lesson nails down PCM encodings, byte-length arithmetic, channel layouts, downmix policies, and device-clock hygiene.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/sampling-nyquist.png&quot; alt=&quot;Sampling at 8 kHz: a 1 kHz sine is unique, while a 7 kHz sine lands on the same samples and aliases to 1 kHz&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. At \(f_s=8\,\mathrm{kHz}\) the folding frequency is 4 kHz, so a 7 kHz tone and a 1 kHz tone produce the same sample sequence.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (PCM quantization &amp;amp; dynamic range, planar vs. interleaved memory layout, device clock boundaries) → Encodings, byte arithmetic, and Nyquist rate choices → Downmix policies &amp;amp; WebRTC/Mezon expectations → Worked examples: 3840-byte ambiguity (stereo s16 vs. mono f32), peak clipping, and wrong channel stride → Explanation: 3-step edge contract for safe PCM ingestion → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-digital-audio-representation-at-the-system-edge&quot;&gt;Key ideas: Digital Audio Representation at the System Edge&lt;/h2&gt;

&lt;h3 id=&quot;1-pulse-code-modulation-pcm--amplitude-discretization&quot;&gt;1. Pulse-Code Modulation (PCM) — Amplitude Discretization&lt;/h3&gt;
&lt;p&gt;A digital audio buffer stores a uniform sequence of quantized pressure readings. Voice pipelines rely on two workhorse formats: &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt;)&lt;/strong&gt; (range \([-32768, 32767]\), 2 bytes/sample, ~96 dB dynamic range, standard in WAV and WebRTC) and &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f32&lt;/code&gt;)&lt;/strong&gt; (normalized to \([-1.0, 1.0]\) full scale, 4 bytes/sample, standard in Web Audio and neural runtimes).&lt;/p&gt;

&lt;h3 id=&quot;2-memory-layout--interleaved-vs-planar&quot;&gt;2. Memory Layout — Interleaved vs. Planar&lt;/h3&gt;
&lt;p&gt;Multi-channel PCM packs samples in two incompatible ways: &lt;strong&gt;interleaved&lt;/strong&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L0, R0, L1, R1, ...&lt;/code&gt;) or &lt;strong&gt;planar&lt;/strong&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[L0, L1, ...], [R0, R1, ...]&lt;/code&gt;). Reading interleaved stereo as a mono stream alternates left and right samples at every step—injecting a massive phantom signal near the Nyquist frequency \(f_s/2\)!&lt;/p&gt;

&lt;h3 id=&quot;3-the-three-tuple-contract-samplerate-channels-dtype&quot;&gt;3. The Three-Tuple Contract: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(sampleRate, channels, dtype)&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;As our worked example proves, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;byteLength = 3840&lt;/code&gt; at 20 ms could be &lt;em&gt;either&lt;/em&gt; 48 kHz stereo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt; &lt;em&gt;or&lt;/em&gt; 48 kHz mono &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;. Every audio boundary must explicitly carry and validate the full tuple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(fs, C, layout, dtype)&lt;/code&gt; before allocating an STFT frame.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Describe PCM encodings common in browsers and native stacks (s16, f32, planar vs interleaved).&lt;/li&gt;
  &lt;li&gt;Convert fluently among samples, seconds, and bytes.&lt;/li&gt;
  &lt;li&gt;Handle mono/stereo layouts before mono NS models.&lt;/li&gt;
  &lt;li&gt;Explain device clock / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext.sampleRate&lt;/code&gt; mismatches.&lt;/li&gt;
  &lt;li&gt;Tie expected formats to WebRTC / Mezon-style public integration paths.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Open a raw dump: interpret bytes as s16 LE mono @ 16 kHz&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–25&lt;/td&gt;
      &lt;td&gt;Encodings, endianness, float Full Scale, clipping&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;25–40&lt;/td&gt;
      &lt;td&gt;Channels: interleaved/planar; downmix policies&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;40–52&lt;/td&gt;
      &lt;td&gt;Clocks &amp;amp; resampling placement in the graph&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;pcm-essentials&quot;&gt;PCM essentials&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pulse-code modulation&lt;/strong&gt; stores uniformly sampled amplitudes. Common voice formats:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Format&lt;/th&gt;
      &lt;th&gt;Range&lt;/th&gt;
      &lt;th&gt;Notes&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s16&lt;/code&gt;)&lt;/td&gt;
      &lt;td&gt;\([-32768,32767]\)&lt;/td&gt;
      &lt;td&gt;WebRTC, WAV; watch endianness&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;typically \([-1,1]\) FS&lt;/td&gt;
      &lt;td&gt;Web Audio &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioBuffer&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int32&lt;/code&gt; / 24-bit in containers&lt;/td&gt;
      &lt;td&gt;rare in NS hot path&lt;/td&gt;
      &lt;td&gt;convert once&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Conversion sketch:&lt;/p&gt;

\[x_{f32} \approx \frac{x_{s16}}{32768}\]

&lt;p&gt;(Exact libraries may use 32767; be consistent to avoid tiny gain errors.) Pick one scale at the edge of the graph and never mix the two inside the STFT. Samples already clipped in the microphone driver are a hard nonlinearity: the harmonics sit in the same bins as fricatives, so leave a few dB of headroom before the suppressor.&lt;/p&gt;

&lt;h3 id=&quot;time-samples-bytes&quot;&gt;Time, samples, bytes&lt;/h3&gt;

\[N_{\mathrm{samples}} = t\cdot f_s,\qquad
N_{\mathrm{bytes}} = N_{\mathrm{samples}}\cdot C\cdot B\]

&lt;p&gt;where \(C\) = channels, \(B\) = bytes per sample (2 for s16, 4 for f32).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; 20 ms, 48 kHz, stereo s16 → \(0.02\cdot48000\cdot2\cdot2=3840\) bytes.&lt;/p&gt;

&lt;p&gt;The same 20 ms as mono float32 is also 3840 bytes — same length, different layout. Check \(f_s\), \(C\), and dtype together; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;byteLength&lt;/code&gt; alone cannot tell them apart. A 128-sample Web Audio quantum is \(2.67\,\mathrm{ms}\) at 48 kHz and \(8\,\mathrm{ms}\) at 16 kHz, so it is not a stand-in for “10 ms.”&lt;/p&gt;

&lt;h3 id=&quot;nyquist-and-why-16-khz-is-not-a-free-downsample&quot;&gt;Nyquist, and why 16 kHz is not a free downsample&lt;/h3&gt;

&lt;p&gt;The sampling theorem (Oppenheim &amp;amp; Schafer) says a bandlimited signal whose spectrum is zero at and above \(f_s/2\) is determined by its samples. The figure is the picture of the failure mode: with \(f_s=8\,\mathrm{kHz}\),&lt;/p&gt;

\[\sin(2\pi\cdot 7000\cdot n/f_s)=\sin(2\pi\cdot(-1000)\cdot n/f_s)=-\sin(2\pi\cdot 1000\cdot n/f_s).\]

&lt;p&gt;The 7 kHz waveform and a polarity-flipped 1 kHz waveform hit the same dots. After sampling, no filter — Wiener, spectral subtraction, or DeepFilterNet — can tell them apart.&lt;/p&gt;

&lt;p&gt;Practical rates in this course:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Rate&lt;/th&gt;
      &lt;th&gt;Nyquist&lt;/th&gt;
      &lt;th&gt;What you keep&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;8 kHz&lt;/td&gt;
      &lt;td&gt;4 kHz&lt;/td&gt;
      &lt;td&gt;narrowband telephony; most fricative energy is already gone&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;16 kHz&lt;/td&gt;
      &lt;td&gt;8 kHz&lt;/td&gt;
      &lt;td&gt;wideband voice; common classical NS and DNS Challenge rate&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;48 kHz&lt;/td&gt;
      &lt;td&gt;24 kHz&lt;/td&gt;
      &lt;td&gt;full-band; DeepFilterNet’s published operating rate, and the rate &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 expects&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Downsampling 48 kHz to 16 kHz is legal only after a low-pass that stops the band above 8 kHz. Taking every third sample aliases 8–24 kHz into 0–8 kHz, and a later upsample does not restore it. The Mezon full-band path stays at 48 kHz unless you deliberately chose a 16 kHz model and an anti-alias filter.&lt;/p&gt;

&lt;h3 id=&quot;interleaved-vs-planar&quot;&gt;Interleaved vs planar&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Interleaved stereo:&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LRLRLR...&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Planar:&lt;/strong&gt; all L then all R (or separate pointers)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feeding interleaved stereo into a mono FFT “as mono” aliases channels into fake high frequencies — the same folding as the figure. Reading &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L,R,L,R&lt;/code&gt; as one sequence puts energy near \(f_s/2\). Deinterleave or downmix explicitly, then window.&lt;/p&gt;

&lt;h3 id=&quot;downmix-policies-for-speech-ns&quot;&gt;Downmix policies for speech NS&lt;/h3&gt;

&lt;p&gt;Pick one and document it:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Mean:&lt;/strong&gt; \(m=(L+R)/2\) (watch correlated vs anti-correlated content).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Left-only / right-only:&lt;/strong&gt; if product mic is known.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Energy-weighted:&lt;/strong&gt; rare in realtime.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Never average after independent NS on L and R without a spatial policy — phasey mess. Anti-correlated stereo \(L=-R\) (a common test tone, and a real situation with some mid-side mics) averages to exact silence. The suppressor then “succeeds” by outputting zeros. If the product microphone is known to be one capsule of a stereo pair, take that channel and do not average.&lt;/p&gt;

&lt;h3 id=&quot;clocks&quot;&gt;Clocks&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext.sampleRate&lt;/code&gt; may be 44100, 48000, or others. getUserMedia tracks may be resampled by the browser. &lt;strong&gt;Measure&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt;; do not hardcode. Place one high-quality resampler at the edge of the NS block to the model’s native rate.&lt;/p&gt;

&lt;p&gt;44.1 kHz is the trap on consumer DACs. Samples at 44.1 kHz labeled as 48 kHz shift every frequency by \(44100/48000\approx 0.919\), so harmonics land in the wrong ERB bands. Read the context rate and resample once.&lt;/p&gt;

&lt;h3 id=&quot;mezon--webrtc-expectations-public&quot;&gt;Mezon / WebRTC expectations (public)&lt;/h3&gt;

&lt;p&gt;Browser integrations typically see Float32 from Web Audio, often 48 kHz, mono after downmix. Public DeepFilterNet is full-band 48 kHz (&lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;). Confirm the current &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; README when shipping.&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;byte-length&quot;&gt;Byte length&lt;/h3&gt;

&lt;p&gt;1 second mono f32 @ 16 kHz → \(16000\cdot4=64000\) bytes.&lt;/p&gt;

&lt;p&gt;10 ms mono s16 @ 16 kHz → \(0.010\cdot16000\cdot2=320\) bytes. That is 160 samples, a common classical hop, not a 128-sample Web Audio quantum.&lt;/p&gt;

&lt;h3 id=&quot;peak-clipping&quot;&gt;Peak clipping&lt;/h3&gt;

&lt;p&gt;s16 near ±32767 clipping creates harmonics that NS may treat as speech or noise — prefer headroom before NS.&lt;/p&gt;

&lt;h3 id=&quot;wrong-channel-stride&quot;&gt;Wrong channel stride&lt;/h3&gt;

&lt;p&gt;Interleaved stereo length 960 frames misunderstood as 960 mono samples @ 48 kHz → you processed 10 ms of “scrambled” L/R as if 20 ms mono. At 48 kHz, 960 samples is the DeepFilterNet analysis length (20 ms). Halving it by a stride bug feeds the model a 10 ms scrambled frame and shifts every subsequent hop.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-the-3-step-edge-contract-for-safe-pcm-ingestion&quot;&gt;Explanation: The 3-Step Edge Contract for Safe PCM Ingestion&lt;/h3&gt;

&lt;h4 id=&quot;step-1-normalize-format-once-at-the-graph-boundary&quot;&gt;Step 1: Normalize format once at the graph boundary&lt;/h4&gt;
&lt;p&gt;Convert &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int16&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float32&lt;/code&gt; via \(x_{f32} = x_{s16} / 32768.0\) exactly once upon entering your DSP graph, and keep internal signals in \([-1, 1]\) with headroom so neither FFT scaling nor neural gains cause hard clipping.&lt;/p&gt;

&lt;h4 id=&quot;step-2-resolve-channel-layout-before-touching-any-fft&quot;&gt;Step 2: Resolve channel layout before touching any FFT&lt;/h4&gt;
&lt;p&gt;Deinterleave stereo explicitly and apply a documented mono policy (left-only for single-capsule headsets, or \((L+R)/2\) with a check against anti-correlated cancellation). Never let raw &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L,R,L,R&lt;/code&gt; stride into a mono window.&lt;/p&gt;

&lt;h4 id=&quot;step-3-lock-the-sample-rate-to-the-models-native-clock&quot;&gt;Step 3: Lock the sample rate to the model’s native clock&lt;/h4&gt;
&lt;p&gt;Query &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext.sampleRate&lt;/code&gt; dynamically. If the hardware runs at 44.1 kHz while the suppressor expects 48 kHz, insert &lt;strong&gt;one&lt;/strong&gt; polyphase resampler at the input edge (and its inverse at the output edge if required) rather than letting a \(0.919\times\) pitch shift corrupt every ERB band.&lt;/p&gt;

&lt;p&gt;Summary of the PCM ingestion pipeline:&lt;/p&gt;

\[\text{Raw PCM } (f_s, C, \text{s16/f32})
\;\xrightarrow{\text{Scale + Downmix}}\;
\text{Mono f32 } [-1,1]
\;\xrightarrow{\text{Resample if } f_s \neq f_{\mathrm{model}}}\;
\text{Clean STFT input}.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Assuming little-endian always when reading files on exotic platforms (usually LE, still assert).&lt;/li&gt;
  &lt;li&gt;Floats outside \([-1,1]\) after processing → sink distortion.&lt;/li&gt;
  &lt;li&gt;Hardcoding 48 kHz.&lt;/li&gt;
  &lt;li&gt;Stereo model input silently truncated to first half buffer.&lt;/li&gt;
  &lt;li&gt;Forgetting that WAV headers ≠ raw PCM from callbacks.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Show that a 7 kHz tone sampled at 8 kHz matches a polarity-flipped 1 kHz tone, and check two buffer lengths you will meet in the pipeline.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8000&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.004&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 4 ms, same idea as the figure
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s7&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;alias_err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s7&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;max |s7 - (-s1)|&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alias_err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nbytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channels&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bytes_per_sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channels&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bytes_per_sample&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;20 ms stereo s16 @ 48 kHz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nbytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.020&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;10 ms mono s16 @ 16 kHz&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nbytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.010&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alias_err&lt;/code&gt; is on the order of \(10^{-14}\) (numerical zero). The byte counts are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3840&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;320&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.linspace&lt;/code&gt; in a way that drops or duplicates the last sample makes the alias error jump from roundoff to \(O(1)\). Forgetting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;channels&lt;/code&gt; or using 4 bytes for s16 prints 7680 or 640 and will desynchronize a WAV writer from a worklet. If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alias_err&lt;/code&gt; is ~2, you compared &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s7&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s1&lt;/code&gt; without the minus sign from the folding identity — the samples match in magnitude and opposite sign, which is exactly the alias.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Bytes for 10 ms mono s16 @ 16 kHz?&lt;/li&gt;
  &lt;li&gt;Write downmix pseudocode interleaved → mono mean.&lt;/li&gt;
  &lt;li&gt;Why is anti-correlated stereo \((L=-R)\) dangerous for mean downmix?&lt;/li&gt;
  &lt;li&gt;List three places sampleRate can differ in a WebRTC send path.&lt;/li&gt;
  &lt;li&gt;Convert s16 value −16000 to float FS with /32768.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(0.010\times16000=160\) samples, times 2 bytes → 320.&lt;/li&gt;
  &lt;li&gt;Read pairs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(L, R)&lt;/code&gt; and emit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(L+R)/2&lt;/code&gt; in float; do not average bytes.&lt;/li&gt;
  &lt;li&gt;The mean is identically 0, so the model sees silence.&lt;/li&gt;
  &lt;li&gt;Capture device, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext&lt;/code&gt;, and the model’s native rate (48 kHz vs 16 kHz vs 44.1 kHz).&lt;/li&gt;
  &lt;li&gt;\(-16000/32768\approx -0.488\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer, &lt;em&gt;Discrete-Time Signal Processing&lt;/em&gt; — sampling and the Nyquist frequency.&lt;/li&gt;
  &lt;li&gt;Web Audio API &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioBuffer&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioWorkletProcessor&lt;/code&gt; buffer formats.&lt;/li&gt;
  &lt;li&gt;WebRTC media track constraints and PCM notes.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet full-band framing: &lt;a href=&quot;https://arxiv.org/abs/2110.05588&quot;&gt;arXiv:2110.05588&lt;/a&gt;, &lt;a href=&quot;https://github.com/Rikorose/DeepFilterNet&quot;&gt;github.com/Rikorose/DeepFilterNet&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://xiph.org/video/vid2.shtml&quot;&gt;Xiph.Org Video Presentations: Digital Show &amp;amp; Tell&lt;/a&gt; — Xiph.Org, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Official Xiph.Org presentation of PCM sampling, bit depth, and reconstruction. Watch it before debugging a 16 kHz tensor fed from a 48 kHz callback.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=KuaannH5pnM&quot;&gt;Aliasing and the Sampling Theorem Simplified&lt;/a&gt; — Barry Van Veen, English. The Nyquist wrap is the silent failure when a channel is resampled to the wrong rate.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-07 Fourier pitfalls checklist for engineers</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_07_fourier_pitfalls_checklist/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_07_fourier_pitfalls_checklist</id>
   <content type="html">&lt;p&gt;When a real-time noise suppressor sounds dull, metallic, or haunted, the reflex is almost always to blame the neural network and kick off a three-day retraining run. Nine times out of ten, the model weights are completely innocent—the culprit is an off-by-one Nyquist bin, a broken COLA window sum, swapped real/imaginary channels, or a silent 44.1 kHz vs. 48 kHz rate mismatch.&lt;/p&gt;

&lt;p&gt;This capstone lesson of Chapter 01 distills every Fourier and STFT failure mode into a &lt;strong&gt;10-point pre-flight engineering checklist&lt;/strong&gt; and a set of 5-line unit tests—so you always verify DSP hygiene first and touch model weights last.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/sampling-nyquist.png&quot; alt=&quot;Sampling copies of a spectrum, the picture behind a mis-labeled Nyquist bin&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The dominant pitfall in this lesson is a wrong frequency axis: Nyquist is \(f_s/2\), and an off-by-one bin is a different Hertz value, not a rounding error.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (the three categories of silent DSP bugs: axis, energy/window, and symmetry/layout) → 10-point master pre-flight checklist → Worked debugging walk-throughs: off-by-one Nyquist bin (\(7968.75\,\mathrm{Hz}\) vs. \(8000\,\mathrm{Hz}\)), swapped real/imag Hermitian violation, and 100 Hz COLA warble → Explanation: 3-step isolation protocol before touching neural weights → Unit tests, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-why-fourier-bugs-fail-silently-in-production&quot;&gt;Key ideas: Why Fourier Bugs Fail Silently in Production&lt;/h2&gt;

&lt;h3 id=&quot;1-axis--rate-bugs-right-math-wrong-units&quot;&gt;1. Axis &amp;amp; Rate Bugs (Right Math, Wrong Units)&lt;/h3&gt;
&lt;p&gt;An FFT array carries no sample-rate tag. Confusing bin \(N/2 - 1\) with Nyquist \(N/2\), labeling plots in raw bins instead of Hertz (\(f_k = k f_s / N\)), or feeding 48 kHz audio into a 16 kHz STFT produces zero runtime errors—yet shifts every spectral feature to the wrong physical frequency.&lt;/p&gt;

&lt;h3 id=&quot;2-energy-window-and-cola-bugs&quot;&gt;2. Energy, Window, and COLA Bugs&lt;/h3&gt;
&lt;p&gt;Double-dividing by \(N\) on the inverse FFT drains audio amplitude; breaking the Constant Overlap-Add (COLA) condition imprints an audible tremolo at the hop frequency (\(f_{\text{warble}} = 1 / T_{\mathrm{hop}}\)); and mixing \(10\log_{10}\) power dB with \(20\log_{10}\) amplitude dB misleads every QA dashboard.&lt;/p&gt;

&lt;h3 id=&quot;3-symmetry--memory-layout-bugs&quot;&gt;3. Symmetry &amp;amp; Memory-Layout Bugs&lt;/h3&gt;
&lt;p&gt;Real PCM requires a &lt;strong&gt;Hermitian-symmetric&lt;/strong&gt; spectrum (\(X[k] = X^*[(N-k)\bmod N]\) with purely real DC and Nyquist bins). Swapping real/imaginary parts or feeding interleaved stereo (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LRLR...&lt;/code&gt;) into a mono FFT destroys phase coherence and injects phantom high-frequency energy.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Diagnose common FT/DFT mistakes in audio pipelines.&lt;/li&gt;
  &lt;li&gt;Validate units (Hz vs bin vs normalized frequency).&lt;/li&gt;
  &lt;li&gt;Apply a structured pre-flight checklist before blaming the neural model.&lt;/li&gt;
  &lt;li&gt;Recognize window/COLA and conjugate-symmetry failures by ear and by test.&lt;/li&gt;
  &lt;li&gt;Tie checklist items to Mezon / DeepFilterNet-style debugging without inventing internals.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–8&lt;/td&gt;
      &lt;td&gt;War story format: symptom → wrong root cause → actual bug&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;8–30&lt;/td&gt;
      &lt;td&gt;Walk the master checklist with demos/thought experiments&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;30–45&lt;/td&gt;
      &lt;td&gt;Unit tests you should keep in repo&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;45–55&lt;/td&gt;
      &lt;td&gt;Mezon/DeepFilterNet debugging order&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;55–60&lt;/td&gt;
      &lt;td&gt;Exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations--master-checklist&quot;&gt;Core explanations — master checklist&lt;/h2&gt;

&lt;h3 id=&quot;1-sample-rate-truth&quot;&gt;1) Sample rate truth&lt;/h3&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;PCM rate equals model rate (or documented resampler in between).&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Anti-alias filter present on downsampling.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AudioContext.sampleRate&lt;/code&gt; not assumed 48 kHz on all devices.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Symptom of failure:&lt;/strong&gt; robotic pitch shifts, dull audio, mysterious noise textures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Walk-through: the Nyquist bin is an integer, and it knows \(f_s\).&lt;/strong&gt; For an even length \(N\), the Nyquist bin is \(k=N/2\), at&lt;/p&gt;

\[f_{\mathrm{Nyquist}}=\frac{N/2}{N}f_s=\frac{f_s}{2}.\]

&lt;p&gt;Take \(N=512\) and \(f_s=16\,\mathrm{kHz}\). The true bin is \(k=256\) at \(8000\,\mathrm{Hz}\). The off-by-one index \(k=255\) sits at \(255\times 16000/512=7968.75\,\mathrm{Hz}\). A mask aimed at “the last speech bin” using 255 never touches Nyquist, and a test that only checks “some high bin moved” will pass. The same index at the product default of 48 kHz is \(256\times 48000/512=24000\,\mathrm{Hz}\) if you forgot you were still on a 16 kHz array: you believe you are editing near 24 kHz while the samples only contain energy up to 8 kHz. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt; then changes depth on the wrong axis. Fix the rate and the bin map before you touch &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Walk-through: swapped real and imaginary parts.&lt;/strong&gt; A real PCM frame has a conjugate-symmetric DFT, \(X[k]=X^*[(N-k)\bmod N]\), and the Nyquist and DC bins are real. Swap real and imaginary parts and that identity fails by an amount on the order of the spectrum itself. The inverse transform grows a nonzero imaginary part that a “take the real part and move on” cast will hide as a dull, phasey residue. The mini-lab asserts both traps.&lt;/p&gt;

&lt;h3 id=&quot;2-units-on-the-frequency-axis&quot;&gt;2) Units on the frequency axis&lt;/h3&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Bin \(k\) converted with \(f=k f_s/N\).&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Filters specified in Hz converted using actual \(f_s\).&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Plots labeled Hz, not raw bin indices, in QA reports.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-fft-normalization--parseval&quot;&gt;3) FFT normalization / Parseval&lt;/h3&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Forward/inverse scaling matches library docs.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Round-trip STFT→ISTFT on impulse/random noise preserves energy (±window gain).&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Training and inference use the same norm.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Symptom:&lt;/strong&gt; output gain pumping; metrics disagree with listening.&lt;/p&gt;

&lt;h3 id=&quot;4-window--cola&quot;&gt;4) Window &amp;amp; COLA&lt;/h3&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Analysis window documented.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Synthesis window + hop satisfy COLA (constant overlap-add) for perfect reconstruction when \(\hat{X}=X\).&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Same windows as training for neural front-ends.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Symptom:&lt;/strong&gt; amplitude modulation at hop rate (tremolo), metallic warble.&lt;/p&gt;

&lt;h3 id=&quot;5-conjugate-symmetry--packing&quot;&gt;5) Conjugate symmetry / packing&lt;/h3&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Real iFFT inputs Hermitian.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Nyquist/DC imaginary parts ~0.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Packed real-FFT formats decoded correctly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Symptom:&lt;/strong&gt; imag leftovers, subtle distortion, framework errors.&lt;/p&gt;

&lt;h3 id=&quot;6-channel-layout&quot;&gt;6) Channel layout&lt;/h3&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Interleaved vs planar agreed.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Stereo → mono policy (mean / left / HRIR — pick one).&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Output channels match sink expectations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;7-hop--latency-accounting&quot;&gt;7) Hop / latency accounting&lt;/h3&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Look-ahead documented in ms.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Ring buffer latency included in UX budget.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Warmup frames discarded consistently in metrics.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;8-dc-and-low-frequency-junk&quot;&gt;8) DC and low-frequency junk&lt;/h3&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;DC blocker / high-pass if mic bias present.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Not confusing DC with “noise” the model should remove.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;9-db-displays&quot;&gt;9) dB displays&lt;/h3&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;\(20\log_{10}\vert X\vert\) vs \(10\log_{10}\vert X\vert^2\) consistency.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Floor clamps to avoid \(\log 0\).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;10-resampler--model-domain&quot;&gt;10) Resampler + model domain&lt;/h3&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Eval metrics at agreed rate.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;No double resampling in A/B tools.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;worked-debugging-scenarios&quot;&gt;Worked debugging scenarios&lt;/h2&gt;

&lt;h3 id=&quot;warble-at-100-hz&quot;&gt;Warble at 100 Hz&lt;/h3&gt;

&lt;p&gt;Hop 10 ms → 100 hops/s. If COLA broken, amplitude modulates near 100 Hz. Fix windows/hop before touching weights.&lt;/p&gt;

&lt;h3 id=&quot;model-muted-fricatives&quot;&gt;“Model muted fricatives”&lt;/h3&gt;

&lt;p&gt;Confirm input actually has energy &amp;gt;6 kHz (rate might be 8 kHz). Confirm mask not low-passing due to wrong bin mapping at 48 vs 16 kHz.&lt;/p&gt;

&lt;h3 id=&quot;si-sdr-great-users-hate-it&quot;&gt;SI-SDR great, users hate it&lt;/h3&gt;

&lt;p&gt;Phase/complex issues or musical noise; check symmetry and time-domain artifacts; run listening (Ch. 08).&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-the-3-step-isolation-protocol-before-touching-model-weights&quot;&gt;Explanation: The 3-Step Isolation Protocol Before Touching Model Weights&lt;/h3&gt;

&lt;h4 id=&quot;step-1-run-a-deterministic-sine--impulse-round-trip-with-the-neural-model-bypassed&quot;&gt;Step 1: Run a deterministic sine &amp;amp; impulse round-trip with the neural model bypassed&lt;/h4&gt;
&lt;p&gt;Feed a pure 1 kHz sine and a unit impulse through your exact PCM \(\to\) STFT \(\to\) ISTFT \(\to\) PCM wrapper with gain \(G \equiv 1\). Check three assertions: (a) peak stays at exactly 1 kHz (verifies \(f_s\) and channel stride), (b) output RMS matches input RMS to \(10^{-6}\) (verifies Parseval &amp;amp; COLA), and (c) imaginary residue after iFFT is \(&amp;lt; 10^{-12}\) (verifies Hermitian symmetry).&lt;/p&gt;

&lt;h4 id=&quot;step-2-check-boundary-bins-explicitly-dc-k0-and-nyquist-kn2&quot;&gt;Step 2: Check boundary bins explicitly (DC \(k=0\) and Nyquist \(k=N/2\))&lt;/h4&gt;
&lt;p&gt;Off-by-one indexing bugs almost always hide at the two endpoints. Verify that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;len(rfft_bins) == N // 2 + 1&lt;/code&gt;, that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bin[0]&lt;/code&gt; is DC (\(0\,\mathrm{Hz}\)), and that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bin[N // 2]&lt;/code&gt; maps to \(f_s / 2\)—not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;N // 2 - 1&lt;/code&gt;.&lt;/p&gt;

&lt;h4 id=&quot;step-3-change-only-one-variable-per-experiment&quot;&gt;Step 3: Change only ONE variable per experiment&lt;/h4&gt;
&lt;p&gt;Once the pass-through test is green, enable the neural model and inspect p99 callback time and listening samples. Never change sample rate, hop size, and checkpoint simultaneously—or you will never know which edit fixed (or broke) the call.&lt;/p&gt;

&lt;p&gt;Summary of the pre-flight isolation order:&lt;/p&gt;

\[\text{PCM rate \&amp;amp; layout}
\;\xrightarrow{\text{Bypass NS}}\;
\text{STFT}\to\text{ISTFT (COLA + Parseval + Hermitian)}
\;\xrightarrow{\text{All green}}\;
\text{Swap / tune neural model}.\]

&lt;h2 id=&quot;unit-tests-to-keep&quot;&gt;Unit tests to keep&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Impulse round-trip STFT/ISTFT (COLA).&lt;/li&gt;
  &lt;li&gt;Parseval check on FFT wrapper.&lt;/li&gt;
  &lt;li&gt;Hermitian projection test after random mask (optional).&lt;/li&gt;
  &lt;li&gt;Resampler sine: 1 kHz in → 1 kHz out, no alias spur.&lt;/li&gt;
  &lt;li&gt;Mono downmix length/channel asserts.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mezon--deepfilternet-debugging-order-public&quot;&gt;Mezon / DeepFilterNet debugging order (public)&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Verify PCM rate/channels against package README / model card.&lt;/li&gt;
  &lt;li&gt;Verify frame delivery (callbacks, ring buffer) — Ch. 05 themes.&lt;/li&gt;
  &lt;li&gt;Verify STFT hygiene (this checklist).&lt;/li&gt;
  &lt;li&gt;Only then swap model variants / strengths / npm options.&lt;/li&gt;
  &lt;li&gt;Cite public DeepFilterNet papers for expected algorithmic behavior; do not claim unpublished Mezon graph details.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Changing three things at once (rate, hop, model).&lt;/li&gt;
  &lt;li&gt;Trusting a single café demo.&lt;/li&gt;
  &lt;li&gt;Using offline non-causal checkpoint in a streaming wrapper accidentally.&lt;/li&gt;
  &lt;li&gt;Ignoring p99 hop times.&lt;/li&gt;
  &lt;li&gt;“Fixing” warble with more aggressive NS gain.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Fail an assert on a swapped real/imaginary spectrum, and show an off-by-one Nyquist bin is not 8 kHz.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hermitian_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mirror&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;conj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mirror&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;swapped&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;real&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nyquist_hz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;return &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_fft&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;//&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_fft&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;good=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;hermitian_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;swapped=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;hermitian_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;swapped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;nyquist=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nyquist_hz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;off_by_one=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;//&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hermitian_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-8&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hermitian_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;swapped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1e-3&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nyquist_hz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;8000.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;good=0.000e+00&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swapped=3.400&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nyquist=8000.00&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;off_by_one=7968.75&lt;/code&gt;. The three asserts pass. Delete the swap assert and a broken spectrum ships; point &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nyquist_hz&lt;/code&gt; at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;N/2-1&lt;/code&gt; and the last assert fires.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Checking symmetry with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.allclose(X, np.conj(X[::-1]))&lt;/code&gt; and forgetting that index 0 must match itself, not a reversed neighbor (the formula above uses \((N-k)\bmod N\), so DC maps to DC). Treating 7968.75 Hz as “close enough to Nyquist” for a unit test.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Pick three checklist items and write a unit test name for each.&lt;/li&gt;
  &lt;li&gt;Hop 5 ms warble frequency if COLA fails?&lt;/li&gt;
  &lt;li&gt;Why does wrong \(f_s\) in \(f=kf_s/N\) mimic a bad model?&lt;/li&gt;
  &lt;li&gt;Draft a 6-step incident report template for “NS sounds bad in Chrome.”&lt;/li&gt;
  &lt;li&gt;Which checklist item catches interleaved stereo fed to a mono FFT?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Name tests after the failure: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test_cola_impulse_roundtrip&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test_parseval_scale&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test_downmix_length&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;A broken COLA at a 5 ms hop modulates near \(1/0.005=200\,\mathrm{Hz}\).&lt;/li&gt;
  &lt;li&gt;Every bin label scales with \(f_s\). A 16 kHz model fed 48 kHz numbers looks like a low-pass even when the weights are untouched.&lt;/li&gt;
  &lt;li&gt;Rate, channels, hop in ms, p95 callback time, one COLA impulse check, then the model id. One change per retry.&lt;/li&gt;
  &lt;li&gt;Channel layout: interleaved stereo read as mono alternates left and right into consecutive “time” samples.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — windows, scaling, DFT pitfalls chapters.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588), DeepFilterNet2 (arXiv:2205.05474), DeepFilterNet3 (arXiv:2305.08227) — configuration and real-time notes. Julius O. Smith, https://ccrma.stanford.edu/~jos/mdft/, for the DFT symmetries the asserts check.&lt;/li&gt;
  &lt;li&gt;ORT / browser profiling docs (high level) for separating STFT vs net costs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=4ip-4ai6kN8&quot;&gt;11: Spectral Analysis Part 1 - Intro to Neural Computation&lt;/a&gt; — MIT OpenCourseWare, English. &lt;strong&gt;xem trước.&lt;/strong&gt; The lecture’s point is that calling an FFT is easy to do wrong. Watch the axis, scaling, and window warnings before you retrain a model.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=tCWU9C-LdJQ&quot;&gt;Lecture 13: Spectral Leakage, Windowing, with Examples of Hanning and Hamming Windows&lt;/a&gt; — Bahga Lab IIT Delhi, English. Hann versus rectangular sidelobes are the leakage half of the checklist.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://xiph.org/video/vid2.shtml&quot;&gt;Xiph.Org Video Presentations: Digital Show &amp;amp; Tell&lt;/a&gt; — Xiph.Org, English. Official Xiph.Org presentation of sampling and reconstruction. Use it when a frequency axis is wrong because the rate, not the network, moved.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-06 FFT in real-time framed audio</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_06_fft_realtime_framing/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_06_fft_realtime_framing</id>
   <content type="html">&lt;p&gt;A DSP textbook stops the moment it proves the FFT runs in \(O(N\log N)\); a real-time audio product &lt;em&gt;begins&lt;/em&gt; when that FFT has to fire every 10 milliseconds inside a browser AudioWorklet without dropping a single sample.&lt;/p&gt;

&lt;p&gt;In streaming speech enhancement, you never transform a whole file at once. You slide a short analysis window of length \(L\) across an incoming ring buffer in steps of hop \(R\), run a forward FFT, enhance the bins, run an inverse FFT, and overlap-add back into an output ring buffer. This lesson turns that loop into exact numbers: hops per second, FFTs per second, AudioWorklet quantum mismatches, and zero-allocation streaming hygiene.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/stft-ola.png&quot; alt=&quot;Overlapping analysis frames, each one a windowed FFT, added back on the synthesis side&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Real-time FFT work is this picture on a clock: one new hop in, one windowed transform, overlap-add out. The basis is still the DFT basis; the schedule is the hop.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (streaming STFT loop, hop rate vs. window delay, callback quanta vs. DSP hops) → Key formulas &amp;amp; full 48 kHz / \(L=960, R=480\) accounting → DeepFilterNet configuration pointers &amp;amp; audio-thread hygiene → Worked examples: FFTs/s across 48 kHz &amp;amp; 16 kHz and latency sketches → Explanation: 3 steps budgeting a live AudioWorklet STFT loop → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-streaming-stft-on-a-hard-real-time-clock&quot;&gt;Key ideas: Streaming STFT on a Hard Real-Time Clock&lt;/h2&gt;

&lt;h3 id=&quot;1-the-five-stage-streaming-loop&quot;&gt;1. The Five-Stage Streaming Loop&lt;/h3&gt;
&lt;p&gt;Every hop advance of \(R\) samples triggers one complete cycle: (1) pull \(L\) samples from the input ring buffer, (2) multiply by analysis window \(w\), (3) run forward FFT, (4) apply classical or neural enhancement, and (5) run inverse FFT + overlap-add (OLA) into the output ring buffer.&lt;/p&gt;

&lt;h3 id=&quot;2-window-length-l-vs-hop-size-r&quot;&gt;2. Window Length \(L\) vs. Hop Size \(R\)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Window \(L\)&lt;/strong&gt; sets your &lt;strong&gt;frequency resolution&lt;/strong&gt; (\(\Delta f \sim f_s/L\)) and the initial &lt;strong&gt;buffering delay&lt;/strong&gt; to assemble a full analysis frame.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hop \(R\)&lt;/strong&gt; sets your &lt;strong&gt;compute cadence&lt;/strong&gt; (\(\text{hops/s} = f_s / R\), with \(2 f_s / R\) forward+inverse transforms per second per channel) and the time budget \(T_{\mathrm{hop}} = R / f_s\) before the next frame arrives.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-audioworklet-quanta-are-not-stft-hops&quot;&gt;3. AudioWorklet Quanta Are Not STFT Hops&lt;/h3&gt;
&lt;p&gt;Web Audio invokes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;process()&lt;/code&gt; in fixed &lt;strong&gt;128-sample quanta&lt;/strong&gt; (\(2.67\,\mathrm{ms}\) at 48 kHz), while a speech model may expect a &lt;strong&gt;480-sample hop&lt;/strong&gt; (\(10\,\mathrm{ms}\)). A lock-free ring buffer bridges the non-integer ratio (\(480 / 128 = 3.75\) quanta/hop), and all FFT plans and scratch arrays must be preallocated so the audio thread never triggers garbage collection.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Budget FFT cost inside a frame callback / AudioWorklet quantum.&lt;/li&gt;
  &lt;li&gt;Relate hop size, \(N\)-point FFT, and algorithmic latency.&lt;/li&gt;
  &lt;li&gt;Compute FFTs/s for common speech configurations.&lt;/li&gt;
  &lt;li&gt;Identify when FFT dominates RTF versus neural ops.&lt;/li&gt;
  &lt;li&gt;Apply streaming hygiene: preallocated buffers, plan reuse, OLA continuity.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Streaming STFT as repeated windowed FFTs&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–25&lt;/td&gt;
      &lt;td&gt;Numerics: hops/s, FFTs/s, latency formulas&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;25–40&lt;/td&gt;
      &lt;td&gt;Audio thread constraints; ring buffers; underrun math&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;40–52&lt;/td&gt;
      &lt;td&gt;Case study pointer: DeepFilterNet STFT configuration&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;streaming-stft-loop&quot;&gt;Streaming STFT loop&lt;/h3&gt;

&lt;p&gt;Each hop:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Assemble \(L\) samples (from ring buffer) with hop advance \(R\).&lt;/li&gt;
  &lt;li&gt;Multiply by analysis window \(w\).&lt;/li&gt;
  &lt;li&gt;FFT → \(X(\ell,\cdot)\).&lt;/li&gt;
  &lt;li&gt;Enhance → \(\hat{X}(\ell,\cdot)\) (mask/filter/net).&lt;/li&gt;
  &lt;li&gt;iFFT → windowed frame; overlap-add into output ring.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;State across hops: OLA buffer, any RNN/DF state, noise tracker state.&lt;/p&gt;

&lt;h3 id=&quot;key-formulas&quot;&gt;Key formulas&lt;/h3&gt;

\[T_{\mathrm{hop}}=\frac{R}{f_s},\qquad
\mathrm{hops/s}=\frac{f_s}{R}\]

&lt;p&gt;With analysis FFT and synthesis iFFT each hop (typical):&lt;/p&gt;

\[\mathrm{FFTs/s}\approx 2\cdot\frac{f_s}{R}\]

&lt;p&gt;(per channel). Stereo without downmix doubles that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algorithmic buffering&lt;/strong&gt; is at least related to \(L\) and look-ahead frames; details in Ch. 02. Rule of thumb: larger \(L\) → better frequency detail, more delay.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One configuration, fully counted.&lt;/strong&gt; Take \(f_s=48\,\mathrm{kHz}\) (the full-band default of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0), \(L=960\), \(R=480\). These are lesson numbers for the arithmetic, not a claim that Mezon’s unpublished graph uses this exact pair.&lt;/p&gt;

\[T_{\mathrm{hop}}=\frac{480}{48000}=10\,\mathrm{ms},\qquad
\frac{f_s}{R}=100\ \mathrm{hops/s},\qquad
T_{\mathrm{win}}=\frac{960}{48000}=20\,\mathrm{ms}.\]

&lt;p&gt;Overlap is \((L-R)/L=1/2\). A causal implementation cannot run the first analysis FFT until 960 samples have arrived, so the buffering delay before that first transform is 20 ms. We will call that the algorithmic delay of &lt;em&gt;filling the analysis window&lt;/em&gt;. Releasing samples earlier, or holding an extra look-ahead hop, changes the constant; it does not change the hop rate. Two transforms per hop (forward and inverse) give \(2\times 100=200\) FFTs per second per channel. The hop budget is 10 ms of wall clock. At 48 kHz a 128-sample AudioWorklet quantum is \(128/480=0.267\) of a hop, so you need \(480/128=3.75\) quanta to fill \(R\), and \(960/128=7.5\) quanta to fill \(L\). &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; still has to be fed on whatever hop the model card states; this count is how you check that card against the callback.&lt;/p&gt;

&lt;h3 id=&quot;audioworklet-quanta-vs-stft-hops&quot;&gt;AudioWorklet quanta vs STFT hops&lt;/h3&gt;

&lt;p&gt;Browser render quanta are often 128 samples. At 48 kHz, \(128/48000\approx2.67\,\mathrm{ms}\). Your STFT hop might be 5–10 ms. Design a ring buffer: accumulate quanta until a hop is ready; never assume quantum == hop.&lt;/p&gt;

&lt;h3 id=&quot;underrun-inequality&quot;&gt;Underrun inequality&lt;/h3&gt;

&lt;p&gt;Let \(T_{\mathrm{proc}}(\ell)\) be wall time for hop \(\ell\). Need&lt;/p&gt;

\[T_{\mathrm{proc}}(\ell) &amp;lt; T_{\mathrm{hop}}\]

&lt;p&gt;almost always, with cushion for jitter. If neural net averages 3 ms but spikes to 12 ms on a 10 ms hop, you glitch.&lt;/p&gt;

&lt;h3 id=&quot;deepfilternet-oriented-case-study-public-papers&quot;&gt;DeepFilterNet-oriented case study (public papers)&lt;/h3&gt;

&lt;p&gt;DeepFilterNet family papers describe STFT-based front-ends with ERB-scale features and deep filtering on complex spectra, engineered for &lt;strong&gt;real-time&lt;/strong&gt; operation. When you read them (Ch. 04), extract: sample rate, window/FFT size, hop, and causal claims. Map those numbers onto the formulas above before integrating &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; or custom ORT graphs. Do not invent undocumented Mezon-specific STFT constants — read the package/model docs you actually ship.&lt;/p&gt;

&lt;h3 id=&quot;implementation-hygiene-checklist&quot;&gt;Implementation hygiene checklist&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Do&lt;/th&gt;
      &lt;th&gt;Don’t&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Preallocate hop scratch, FFT workspace&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;malloc&lt;/code&gt; / JS &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new Float32Array&lt;/code&gt; per hop on audio thread&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Reuse FFT plans&lt;/td&gt;
      &lt;td&gt;Rebuild plans each callback&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Fixed mono policy&lt;/td&gt;
      &lt;td&gt;Silently ignore second channel&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Measure p95/p99 hop time&lt;/td&gt;
      &lt;td&gt;Trust mean RTF only&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;ffts-per-second&quot;&gt;FFTs per second&lt;/h3&gt;

&lt;p&gt;\(f_s=48\,\mathrm{kHz}\), \(R=480\) (10 ms): hops/s=100, FFT+iFFT ≈200 transforms/s/channel.&lt;/p&gt;

&lt;p&gt;\(f_s=16\,\mathrm{kHz}\), \(R=160\) (10 ms): same 100 hops/s; smaller \(N\) often.&lt;/p&gt;

&lt;h3 id=&quot;latency-sketch&quot;&gt;Latency sketch&lt;/h3&gt;

&lt;p&gt;\(L=20\,\mathrm{ms}\), \(R=10\,\mathrm{ms}\), model look-ahead 1 hop → ballpark algorithmic delay tens of ms (exact depends on OLA definition). Product budgets must measure end-to-end.&lt;/p&gt;

&lt;h3 id=&quot;when-fft-dominates&quot;&gt;When FFT dominates&lt;/h3&gt;

&lt;p&gt;Classical spectral subtraction on MCU: FFT~all. DFN-class on laptop: net~all. Mobile mid-tier + debug WASM without SIMD: both hurt — profile.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-budgeting-a-live-streaming-stft-callback-step-by-step&quot;&gt;Explanation: Budgeting a Live Streaming STFT Callback Step by Step&lt;/h3&gt;

&lt;h4 id=&quot;step-1-separate-how-often-you-compute-from-how-long-you-wait&quot;&gt;Step 1: Separate “how often you compute” from “how long you wait”&lt;/h4&gt;
&lt;p&gt;With \(L = 960, R = 480\) at \(48\,\mathrm{kHz}\), your compute cadence is governed by \(R\) (\(100\,\mathrm{hops/s} \implies 200\,\mathrm{FFTs/s}\) and a \(10\,\mathrm{ms}\) deadline per hop), whereas your initial buffering delay is governed by \(L\) (\(20\,\mathrm{ms}\) to fill the first window). Halving \(R\) from \(480\) to \(240\) &lt;strong&gt;doubles&lt;/strong&gt; your FFT + neural CPU load even if \(L\) stays unchanged!&lt;/p&gt;

&lt;h4 id=&quot;step-2-account-for-the-non-integer-quantum-ratio-480--128--375&quot;&gt;Step 2: Account for the non-integer quantum ratio (\(480 / 128 = 3.75\))&lt;/h4&gt;
&lt;p&gt;Because Web Audio delivers 128 samples per callback, your ring buffer accumulates \(128 \to 256 \to 384 \to 512\) samples: on callback #4 you pop 480 samples, run STFT + NS + ISTFT, push 480 clean samples to the output ring, and keep the remaining 32 samples for the next cycle.&lt;/p&gt;

&lt;h4 id=&quot;step-3-profile-all-three-stages-separately-at-p95p99&quot;&gt;Step 3: Profile all three stages separately at p95/p99&lt;/h4&gt;
&lt;p&gt;Instrument &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t_stft&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t_model&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t_istft_ola&lt;/code&gt; individually across several thousand hops. Never assume &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t_istft_ola&lt;/code&gt; is free—especially in unoptimized JS/WASM without SIMD or when an accidental &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new Float32Array&lt;/code&gt; triggers garbage collection mid-call.&lt;/p&gt;

&lt;p&gt;Summary of the real-time framed FFT budget:&lt;/p&gt;

\[128\text{-smp quanta}
\;\xrightarrow{\text{Ring buffer (3.75}\times)}\;
R = 480\ (10\,\mathrm{ms})
\;\xrightarrow{200\text{ FFTs/s + NS}}\;
T_{\mathrm{stft}} + T_{\mathrm{ns}} + T_{\mathrm{istft}} &amp;lt; 10\,\mathrm{ms}.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Equating AudioWorklet quantum with model hop.&lt;/li&gt;
  &lt;li&gt;Measuring latency with wall clock only on the main thread.&lt;/li&gt;
  &lt;li&gt;Resetting OLA state every callback.&lt;/li&gt;
  &lt;li&gt;Running stereo FFTs when model is mono.&lt;/li&gt;
  &lt;li&gt;Forgetting that iFFT + OLA is part of the budget, not “free after the net.”&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Count hops per second and the analysis-window delay for \(L=960\), \(R=480\) at 48 kHz.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;960&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;480&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;win_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hops_per_s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ffts_per_s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hops_per_s&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hops_per_s=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hops_per_s&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; hop_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; win_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;win_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ffts_per_s=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ffts_per_s&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; algo_delay_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;win_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hops_per_s=100 hop_ms=10.0 win_ms=20.0&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ffts_per_s=200 algo_delay_ms=20.0&lt;/code&gt;. The delay printed here is the time to collect one analysis window, not a full-product mouth-to-ear figure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Setting algorithmic delay to the hop (10 ms) and forgetting the window must fill first. Counting one FFT per hop when the inverse is also on the clock. Copying \(L\) and \(R\) onto a model card that documents a different pair.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;\(f_s=16\,\mathrm{kHz}\), \(R=256\): hop ms and hops/s?&lt;/li&gt;
  &lt;li&gt;Budget \(T_{\mathrm{proc}}\) for RTF 0.4 at that hop.&lt;/li&gt;
  &lt;li&gt;128-sample quantum at 48 kHz: how many quanta to fill a 10 ms hop?&lt;/li&gt;
  &lt;li&gt;List state that must persist across hops for STFT-NS.&lt;/li&gt;
  &lt;li&gt;Sketch a profiler plan separating STFT vs neural vs ISTFT time.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(256/16000=16\,\mathrm{ms}\), so hops/s \(=1000/16=62.5\).&lt;/li&gt;
  &lt;li&gt;RTF 0.4 on a 16 ms hop allows \(6.4\,\mathrm{ms}\) of processing.&lt;/li&gt;
  &lt;li&gt;A 10 ms hop at 48 kHz is 480 samples, and \(480/128=3.75\) quanta. You accumulate four quanta and still have a remainder unless the ring buffer stores the extra 0.25.&lt;/li&gt;
  &lt;li&gt;OLA tail, analysis window, hop counter, and any recurrent state inside the suppressor.&lt;/li&gt;
  &lt;li&gt;Three timers around analysis FFT, the neural forward, and iFFT plus overlap-add, reported as p95 over at least a few thousand hops.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588), DeepFilterNet2 (arXiv:2205.05474), DeepFilterNet3 (arXiv:2305.08227) — STFT and real-time configuration sections. Reference code: https://github.com/Rikorose/DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;MDN AudioWorkletProcessor documentation.&lt;/li&gt;
  &lt;li&gt;WebRTC APM overview (processing in framed blocks).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-Yxj3yfvY-4&quot;&gt;Short-Time Fourier Transform Explained Easily&lt;/a&gt; — Valerio Velardo - The Sound of AI, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the slide from one DFT of the whole file to one DFT per frame. That hop is where a real-time callback actually calls the FFT.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=NA0TwPsECUQ&quot;&gt;Short-time Fourier Transform and the Spectogram&lt;/a&gt; — Barry Van Veen, English. A signal-processing lecture on the short-time transform and the spectrogram it produces, which is the framed FFT this lesson places on a clock.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. Watch the STFT block at the front of a causal enhancer: the FFT here is a hop budget, not a textbook complexity line.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-05 FFT algorithms and complexity</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_05_fft_radix2_complexity/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_05_fft_radix2_complexity</id>
   <content type="html">&lt;p&gt;Multiplying an \(N \times N\) DFT matrix by a 1024-sample audio frame takes over a &lt;strong&gt;million&lt;/strong&gt; complex multiply-adds—every single hop, twice (forward and inverse), a hundred times a second. On a phone CPU or inside a browser AudioWorklet, that naive \(O(N^2)\) cost burns your real-time budget before the neural network even starts.&lt;/p&gt;

&lt;p&gt;Enter the &lt;strong&gt;Fast Fourier Transform (FFT)&lt;/strong&gt;: not a new transform, not an approximation, but a breathtaking algebraic factorization (rediscovered by Cooley and Tukey in 1965, traced back to Gauss in 1805!) that computes the &lt;em&gt;exact same&lt;/em&gt; DFT in \(O(N \log N)\) operations—cutting \(1{,}048{,}576\) ops down to roughly \(10{,}240\). This lesson unpacks how the butterfly split works, why real-FFT and mixed-radix sizes like \(960 = 2^6 \cdot 3 \cdot 5\) matter in DeepFilterNet, and what production rules keep FFTs fast on live audio threads.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/dft-basis.png&quot; alt=&quot;The same DFT basis tones an FFT evaluates; the algorithm changes the schedule, not the tones&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Radix-2 still computes inner products against these basis tones. It only changes the order of the arithmetic, which is why the result matches a naive DFT up to roundoff.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (divide-and-conquer factorization, twiddle symmetries, real &amp;amp; mixed-radix FFTs) → Radix-2 Cooley–Tukey butterflies &amp;amp; complexity table → Practical production rules (plan reuse, zero-alloc, SIMD) → Worked examples: 10 ms hop ops budget, padding 960 → 1024, and a 4-point butterfly checked by hand → Explanation: 3 steps from the even/odd split to \(O(N\log N)\) → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-fast-algorithms-for-the-dft&quot;&gt;Key ideas: Fast Algorithms for the DFT&lt;/h2&gt;

&lt;h3 id=&quot;1-same-mathematics-smarter-factorization&quot;&gt;1. Same Mathematics, Smarter Factorization&lt;/h3&gt;
&lt;p&gt;The FFT does not change a single output number of the DFT (up to floating-point roundoff \(\sim 10^{-14}\)). It exploits the periodicity and symmetry of roots of unity \(W_N^k = e^{-j2\pi k/N}\) to factor the dense \(N\times N\) matrix \(\mathbf{F}\) into \(\log_2 N\) ultra-sparse &lt;strong&gt;butterfly stages&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;2-real-input-and-mixed-radix-ffts&quot;&gt;2. Real-Input and Mixed-Radix FFTs&lt;/h3&gt;
&lt;p&gt;Two optimizations matter constantly in speech pipelines:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Real FFT (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt;):&lt;/strong&gt; Since audio PCM is real, conjugate symmetry cuts the arithmetic roughly in &lt;strong&gt;half&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Mixed-radix FFT:&lt;/strong&gt; You do &lt;em&gt;not&lt;/em&gt; need \(N\) to be a power of 2! A 20 ms frame at 48 kHz has \(N = 960 = 2^6 \cdot 3 \cdot 5\)—smooth small prime factors that mixed-radix libraries (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pocketfft&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rustfft&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FFTW&lt;/code&gt;) run almost as fast as \(N = 1024\) without altering bin frequencies!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-audio-thread-engineering-plans-allocations-and-simd&quot;&gt;3. Audio-Thread Engineering: Plans, Allocations, and SIMD&lt;/h3&gt;
&lt;p&gt;Asymptotic \(O(N\log N)\) is only half the story. In production, allocating scratch buffers or recomputing twiddle tables inside a 10 ms callback will blow past your deadline. Always precompute FFT plans once at startup, preallocate workspaces, and enable SIMD (WASM SIMD / NEON / AVX).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Explain why FFT is \(O(N\log N)\) versus naive \(O(N^2)\) DFT.&lt;/li&gt;
  &lt;li&gt;Describe radix-2 Cooley–Tukey divide-and-conquer at a cartoon level.&lt;/li&gt;
  &lt;li&gt;List practical constraints: power-of-two sizes, real-FFT optimizations, plan reuse.&lt;/li&gt;
  &lt;li&gt;Estimate FFT cost relative to neural ops in a hop budget.&lt;/li&gt;
  &lt;li&gt;Know what “calling FFT” means inside ONNX graphs vs hand-written WASM.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Complexity arithmetic: \(N=1024\) naive vs FFT ops order&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–28&lt;/td&gt;
      &lt;td&gt;Radix-2 butterfly idea; bit reversal awareness&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Real FFT packing; non-power-of-two Bluestein/mixed radix (awareness)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Library landscape: native, WASM SIMD, ORT FFT ops&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;naive-cost&quot;&gt;Naive cost&lt;/h3&gt;

&lt;p&gt;Each of \(N\) outputs sums \(N\) complex multiply-adds → \(\Theta(N^2)\). For \(N=1024\), ~\(10^6\) complex MACs per transform; per direction; per hop; two ways (FFT+iFFT) → tens of millions of ops/s at fine hops — doable on desktop, painful when stacked with a neural net on mobile, especially at 48 kHz with small hops.&lt;/p&gt;

&lt;h3 id=&quot;cooleytukey-radix-2-idea&quot;&gt;Cooley–Tukey radix-2 idea&lt;/h3&gt;

&lt;p&gt;If \(N=2^m\), split even/odd indices:&lt;/p&gt;

\[X[k]=E[k]+e^{-j2\pi k/N}O[k]\]

\[X[k+N/2]=E[k]-e^{-j2\pi k/N}O[k]\]

&lt;p&gt;where \(E\) and \(O\) are length-\(N/2\) DFTs of even/odd parts. Recurse. The cost satisfies&lt;/p&gt;

\[T(N)=2T(N/2)+\Theta(N).\]

&lt;p&gt;Unroll it: \(T(N)=\Theta(N)+2\Theta(N/2)+4\Theta(N/4)+\cdots\), and there are \(\log_2 N\) generations until the problem size is 1. Each generation sums to \(\Theta(N)\), so \(T(N)=\Theta(N\log N)\). Depth \(\log_2 N\) stages, each stage \(\Theta(N)\) work. For \(N=1024\), \(\log_2 N=10\) and the leading-term ratio \(N^2/(N\log_2 N)=1024/10=102.4\). That is about a hundred times fewer multiply-adds before you count that a real PCM FFT can skip the redundant half. It is not a claim that wall-clock time drops by exactly 102; constants, SIMD, and Python overhead move the measured ratio, which is what the mini-lab is for.&lt;/p&gt;

&lt;p&gt;The twiddle \(e^{-j2\pi k/N}\) is the “butterfly” rotation. In-place implementations overwrite buffers; &lt;strong&gt;bit-reversed&lt;/strong&gt; order appears in some stages — libraries hide this, but debugging raw implementations needs awareness.&lt;/p&gt;

&lt;h3 id=&quot;short-video-why-fft-is-fast&quot;&gt;Short video: why FFT is fast&lt;/h3&gt;

&lt;p&gt;A short reel from MathDiagram that asks how the FFT computes the Fourier transform so efficiently. Watch it after the even/odd split above.&lt;/p&gt;

&lt;div class=&quot;video-embed&quot; style=&quot;text-align:center;margin:1em 0;&quot;&gt;&lt;iframe src=&quot;https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Freel%2F4039621483008687&amp;amp;show_text=false&amp;amp;width=315&amp;amp;height=560&quot; width=&quot;315&quot; height=&quot;560&quot; style=&quot;border:none;overflow:hidden;max-width:100%;&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;true&quot; allow=&quot;autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;

&lt;p&gt;If the video does not load, &lt;a href=&quot;https://www.facebook.com/reel/4039621483008687&quot;&gt;open it on Facebook&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;complexity-comparison-order-of-magnitude&quot;&gt;Complexity comparison (order of magnitude)&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;\(N\)&lt;/th&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;\(N^2\)&lt;/th&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;\(N\log_2 N\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;256&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;65k&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;~2k&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;512&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;262k&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;~4.5k&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;1024&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;1.0M&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;~10k&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Constants matter (complex vs real, SIMD), but the scaling is why FFT is mandatory.&lt;/p&gt;

&lt;h3 id=&quot;real-input-fft&quot;&gt;Real-input FFT&lt;/h3&gt;

&lt;p&gt;Speech PCM is real. A real-FFT computes packed Hermitian spectrum with roughly half the work of a full complex FFT. Use it when APIs allow. Neural graphs sometimes consume complex or magnitude features — still compute efficiently underneath.&lt;/p&gt;

&lt;h3 id=&quot;non-power-of-two&quot;&gt;Non-power-of-two&lt;/h3&gt;

&lt;p&gt;DeepFilterNet-style windows may use sizes like 960 samples (20 ms at the 48 kHz full-band rate used by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;). Note that \(960=2^6\cdot 3\cdot 5\), so a mixed-radix FFT applies directly; you do not need a power of two for the transform to exist. FFTs of that length are fine (mixed radix, Bluestein’s chirp z-transform, or pad to 1024). Padding to 1024 is simple but changes bin centers slightly and costs a bit more — document what training used. Running a length-256 plan because “FFT means power of two” on 48 kHz frames is a different bug: you have changed \(N\), not sped up the same DFT.&lt;/p&gt;

&lt;h3 id=&quot;plans-and-allocations&quot;&gt;Plans and allocations&lt;/h3&gt;

&lt;p&gt;Production rules:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Create FFT plans once&lt;/strong&gt; (FFTW wisdom, pocketfft setup, Rust realfft plans, etc.).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Never allocate&lt;/strong&gt; on the audio thread.&lt;/li&gt;
  &lt;li&gt;Prefer &lt;strong&gt;SIMD&lt;/strong&gt; builds (WASM SIMD, NEON, AVX) when packaging (Ch. 06).&lt;/li&gt;
  &lt;li&gt;In &lt;strong&gt;ONNX Runtime&lt;/strong&gt;, STFT may be a graph op or a pre-process outside the graph — know which, for profiling.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;when-fft-dominates-vs-neural-ops&quot;&gt;When FFT dominates vs neural ops&lt;/h3&gt;

&lt;p&gt;Tiny classical NS: FFT+iFFT may dominate. DeepFilterNet-class nets: neural matmuls usually dominate, but FFT is still non-negligible at high rates / small hops / debug builds without SIMD. Profile both.&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;hand-checking-a-4-point-butterfly-on-x--1-0--1-0&quot;&gt;Hand-checking a 4-point butterfly on \(x = [1, 0, -1, 0]\)&lt;/h3&gt;

&lt;p&gt;Split \(x\) into even indices \(x_{\text{even}} = [1, -1]\) and odd indices \(x_{\text{odd}} = [0, 0]\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Length-2 DFT of even part: \(E[0] = 1 + (-1) = 0\), \(E[1] = 1 - (-1) = 2\).&lt;/li&gt;
  &lt;li&gt;Length-2 DFT of odd part: \(O[0] = 0\), \(O[1] = 0\).&lt;/li&gt;
  &lt;li&gt;Combine with twiddle \(W_4^k = (-j)^k\):
    &lt;ul&gt;
      &lt;li&gt;\(k = 0\): \(X[0] = E[0] + 1\cdot O[0] = 0\), \(X[2] = E[0] - 1\cdot O[0] = 0\).&lt;/li&gt;
      &lt;li&gt;\(k = 1\): \(X[1] = E[1] + (-j)\cdot O[1] = 2\), \(X[3] = E[1] - (-j)\cdot O[1] = 2\).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Result \([0, 2, 0, 2]\) matches the full \(4\times 4\) matrix product from Lesson 01-04—using only half-size sub-DFTs!&lt;/p&gt;

&lt;h3 id=&quot;ops-budget-sketch&quot;&gt;Ops budget sketch&lt;/h3&gt;

&lt;p&gt;Hop 10 ms → 100 FFT+iFFT pairs/s/channel. \(N=512\) complex FFT ~ \(5\cdot10^3\) MACs order → \(10^6\) MACs/s for FFT side — small vs a multi-layer conv-RNN. At hop 2.5 ms and \(N=1024\) without real-FFT, costs rise fast.&lt;/p&gt;

&lt;h3 id=&quot;pad-9601024&quot;&gt;Pad 960→1024&lt;/h3&gt;

&lt;p&gt;20 ms @ 48 kHz = 960. Pad 64 zeros: denser DTFT sampling, slightly different from training if training used exact 960 mixed-radix — &lt;strong&gt;match training&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-how-one-algebraic-sign-flip-saves-100-the-work&quot;&gt;Explanation: How One Algebraic Sign Flip Saves 100× the Work&lt;/h3&gt;

&lt;h4 id=&quot;step-1-split-the-dft-sum-into-even-and-odd-time-indices&quot;&gt;Step 1: Split the DFT sum into even and odd time indices&lt;/h4&gt;
&lt;p&gt;Write \(n = 2m\) for even indices and \(n = 2m + 1\) for odd indices:
\(X[k] = \sum_{m=0}^{N/2-1} x[2m] e^{-j2\pi k(2m)/N} + e^{-j2\pi k/N}\sum_{m=0}^{N/2-1} x[2m+1] e^{-j2\pi k(2m)/N} = E[k] + W_N^k O[k].\)&lt;/p&gt;

&lt;h4 id=&quot;step-2-exploit-half-period-symmetry-to-get-two-outputs-for-the-price-of-one&quot;&gt;Step 2: Exploit half-period symmetry to get two outputs for the price of one&lt;/h4&gt;
&lt;p&gt;Notice that \(E[k]\) and \(O[k]\) are periodic with period \(N/2\), while the twiddle flips sign half a circle later: \(W_N^{k + N/2} = e^{-j\pi} W_N^k = -W_N^k\)! Therefore you compute \(W_N^k O[k]\) &lt;strong&gt;once&lt;/strong&gt;, add it to \(E[k]\) to get \(X[k]\), and subtract it from \(E[k]\) to get \(X[k + N/2]\) for free!&lt;/p&gt;

&lt;h4 id=&quot;step-3-recurse-log_2-n-levels-deep&quot;&gt;Step 3: Recurse \(\log_2 N\) levels deep&lt;/h4&gt;
&lt;p&gt;Each split cuts problem size in half while keeping total work per level at \(O(N)\). For \(N = 1024\), there are only \(\log_2 1024 = 10\) levels—shrinking \(1{,}048{,}576\) ops to \(\approx 10{,}240\)!&lt;/p&gt;

&lt;p&gt;Summary of the Cooley–Tukey speedup:&lt;/p&gt;

\[\text{DFT } O(N^2)
\;\xrightarrow{\text{Even/Odd split}}\;
E[k] \pm W_N^k O[k]
\;\xrightarrow{\log_2 N \text{ stages}}\;
\text{FFT } O(N\log N)\ (\sim 100\times \text{ faster at } N=1024).\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Rebuilding FFT plans every hop.&lt;/li&gt;
  &lt;li&gt;Using complex FFT APIs on real data without packing gains.&lt;/li&gt;
  &lt;li&gt;Assuming \(O(N\log N)\) means “free.”&lt;/li&gt;
  &lt;li&gt;Changing \(N\) to next power of two without verifying model compatibility.&lt;/li&gt;
  &lt;li&gt;Comparing timings from DEBUG vs Release / without SIMD.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Time a direct DFT matrix-vector product against &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.fft.fft&lt;/code&gt; at \(N=256\) and \(N=1024\). This is an order-of-magnitude check, not a benchmark paper.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;naive_dft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;empty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dtype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;complex128&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;default_rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1024&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;standard_normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;perf_counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Xn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;naive_dft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t_naive&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;perf_counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t0&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;perf_counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Xf&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t_fft&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;perf_counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t0&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Xn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Xf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;naive_s=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t_naive&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fft_s=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t_fft&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;err=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;err&lt;/code&gt; below &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-8&lt;/code&gt; at both sizes (around &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-12&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-11&lt;/code&gt; on a typical laptop). Naive time at \(N=1024\) is several times the naive time at \(N=256\), on the order of the \(4^2=16\) growth of \(N^2\), with loop overhead eating part of that factor. FFT time stays well under 1 ms. At \(N=1024\) the naive call is hundreds of times slower than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.fft.fft&lt;/code&gt;. Absolute seconds will not match a classmate’s machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Treating one timing run as a published RTF. Forgetting that this “naive” loop still uses a vectorized &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.dot&lt;/code&gt; per bin, so it is not a pure Python double loop. Comparing a warm FFT to a first-call naive that also builds twiddles, then quoting the ratio as the Cooley–Tukey constant.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Compute \(\log_2 1024\) stages; rough \(N\log N\) vs \(N^2\).&lt;/li&gt;
  &lt;li&gt;Why does real-FFT roughly halve work?&lt;/li&gt;
  &lt;li&gt;List three FFT implementation concerns on AudioWorklet/WASM.&lt;/li&gt;
  &lt;li&gt;If hop halves and \(N\) fixed, how does FFT CPU roughly scale?&lt;/li&gt;
  &lt;li&gt;Give one reason to avoid padding when using pretrained STFT front-ends.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(\log_2 1024=10\) stages. \(N\log_2 N=10240\) against \(N^2=1048576\), a factor of about 102 in the leading term.&lt;/li&gt;
  &lt;li&gt;Real spectra are conjugate symmetric, so a packed algorithm skips the redundant half of the bins. The savings are about half, not a second asymptotic class.&lt;/li&gt;
  &lt;li&gt;No allocations on the audio thread, reuse the FFT plan, and ship a SIMD build. A fourth you should also name: do not rebuild twiddle tables per hop.&lt;/li&gt;
  &lt;li&gt;Hops per second double, so FFT work per second roughly doubles if \(N\) stays fixed.&lt;/li&gt;
  &lt;li&gt;Padding moves bin centers and the length the weights saw. A pretrained front-end then reads the wrong Hertz for the same index.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Cooley &amp;amp; Tukey FFT lineage overviews (classic DSP references; Oppenheim &amp;amp; Schafer FFT sections).&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Mathematics of the DFT&lt;/em&gt;, https://ccrma.stanford.edu/~jos/mdft/ — FFT factorization as a faster DFT, not a different transform.&lt;/li&gt;
  &lt;li&gt;ONNX STFT / DFT operator docs when using ORT graphs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=E8HeD-MUrjY&quot;&gt;The Fast Fourier Transform (FFT)&lt;/a&gt; — Steve Brunton, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the contrast between the dense DFT and the factored FFT; the lesson’s O(N log N) claim is this argument.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=toj_IoCQE-4&quot;&gt;The Fast Fourier Transform Algorithm&lt;/a&gt; — Steve Brunton, English. The radix-2 split is the part to watch: half-size transforms and twiddle factors, which is where the log factor comes from.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xw4voABxU5c&quot;&gt;Computing the DFT Matrix&lt;/a&gt; — Steve Brunton, English. Keep this as the O(N²) baseline the FFT is not allowed to change numerically.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-04 DFT as matrix / orthonormal basis</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_04_dft_as_matrix_and_basis/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_04_dft_as_matrix_and_basis</id>
   <content type="html">&lt;p&gt;If you only ever think of an FFT as a black box that spits out a pretty spectrogram, one subtle scaling mismatch between Python (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.fft&lt;/code&gt;) and C++/Rust (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FFTW&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;realfft&lt;/code&gt;) will silently drain your audio by \(10\times\)—or blow it up into harsh clipping.&lt;/p&gt;

&lt;p&gt;The cleanest cure is linear algebra: &lt;strong&gt;the length-\(N\) DFT is simply a rotation into an orthogonal basis&lt;/strong&gt;, represented by a single \(N \times N\) Vandermonde matrix \(\mathbf{F}\). Once you view &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fft(x)&lt;/code&gt; as \(\mathbf{X} = \mathbf{F}\mathbf{x}\), Parseval’s energy check becomes a one-line unit test, conjugate symmetry becomes obvious, and spectral leakage stops looking mysterious.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/dft-basis.png&quot; alt=&quot;Eight DFT basis tones: the coordinates a length-N transform uses&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Each row of the DFT matrix is one of these complex tones; a bin is the inner product of the frame with that row.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (orthogonal complex exponentials, unitary vs. unnormalized scaling, Parseval’s theorem) → Matrix form, frequency axis, and leakage → Worked examples: length-4 DFT of \(x = [1, 0, -1, 0]\) checked by hand against Parseval, 48 kHz bin mapping, and white-noise energy check → Explanation: 3 steps turning orthogonality into your STFT/ISTFT unit tests → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-linear-algebra-of-the-discrete-fourier-transform&quot;&gt;Key ideas: Linear Algebra of the Discrete Fourier Transform&lt;/h2&gt;

&lt;h3 id=&quot;1-orthogonal-basis-in-mathbbcn&quot;&gt;1. Orthogonal Basis in \(\mathbb{C}^N\)&lt;/h3&gt;
&lt;p&gt;The \(N\) complex exponential vectors \(w_k[n] = e^{j2\pi kn/N}\) (\(k = 0, \ldots, N-1\)) are mutually perpendicular in \(\mathbb{C}^N\): \(\langle w_k, w_\ell \rangle = N\delta_{k\ell}\). Taking a DFT is literally projecting your audio frame \(\mathbf{x}\) onto these \(N\) perpendicular axes.&lt;/p&gt;

&lt;h3 id=&quot;2-unitary-scaling-vs-library-scaling-conventions&quot;&gt;2. Unitary Scaling vs. Library Scaling Conventions&lt;/h3&gt;
&lt;p&gt;Dividing \(\mathbf{F}\) by \(\sqrt{N}\) yields a &lt;strong&gt;unitary matrix&lt;/strong&gt; \(\mathbf{U} = \mathbf{F}/\sqrt{N}\) satisfying \(\mathbf{U}^H \mathbf{U} = \mathbf{I}\), which preserves vector length identically (\(\Vert \mathbf{Ux}\Vert_2 = \Vert \mathbf{x}\Vert_2\)). Most numerical libraries (NumPy, FFTW, kissfft) avoid \(\sqrt{N}\) for speed: they put factor \(1\) on the forward transform and \(1/N\) on the inverse (or expect &lt;em&gt;you&lt;/em&gt; to divide by \(N\)). Forgetting which convention your library uses is one of the top silent bugs in streaming audio!&lt;/p&gt;

&lt;h3 id=&quot;3-on-bin-tones-vs-off-bin-spectral-leakage&quot;&gt;3. On-Bin Tones vs. Off-Bin Spectral Leakage&lt;/h3&gt;
&lt;p&gt;A sinusoid that completes an exact integer number of cycles inside \(N\) samples aligns with a single basis vector \(w_k\), putting 100% of its energy into one bin (plus its conjugate twin). Any fractional-cycle sinusoid sits &lt;em&gt;between&lt;/em&gt; basis axes—its projection spills non-zero coefficients across all \(N\) bins (&lt;strong&gt;spectral leakage&lt;/strong&gt;).&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;View the DFT as projection onto complex exponentials.&lt;/li&gt;
  &lt;li&gt;Write the DFT as a matrix acting on vectors; know unitary vs unnormalized conventions.&lt;/li&gt;
  &lt;li&gt;Apply Parseval-type energy checks when validating STFT/ISTFT.&lt;/li&gt;
  &lt;li&gt;Convert among bin index, Hz, and normalized frequency fluently.&lt;/li&gt;
  &lt;li&gt;Predict and recognize off-bin spectral leakage.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Orthogonal exponentials; inner-product view&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;Matrix \(\mathbf{F}\); unitary scaling; library conventions&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Bin↔Hz drills; DC/Nyquist; negative frequencies&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Off-bin leakage; tone+noise lab sketch&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises / checklist&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;analysis-as-inner-products&quot;&gt;Analysis as inner products&lt;/h3&gt;

&lt;p&gt;Basis vectors \(w_k[n]=e^{j2\pi kn/N}\) satisfy&lt;/p&gt;

\[\langle w_k,w_\ell\rangle=\sum_{n=0}^{N-1}w_k[n]w_\ell[n]^*=N\delta_{k\ell}\]

&lt;p&gt;DFT analysis: \(X[k]=\langle x,w_k\rangle\) (with conjugation conventions matching the forward sign). One check of the inner-product claim: the geometric sum \(\sum_{n=0}^{N-1}e^{j2\pi(k-\ell)n/N}\) equals \(N\) when \(k\equiv\ell\pmod N\) and equals 0 otherwise, which is exactly \(\langle w_k,w_\ell\rangle=N\delta_{k\ell}\). Synthesis divides by that \(N\). This is why modifying \(X[k]\) is surgery in a coordinate system — illegal surgery (breaking symmetries, inconsistent hop windows) shows up as time-domain garbage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;From unitary to the library’s \(1/N\).&lt;/strong&gt; Let \(\mathbf{U}=\mathbf{F}/\sqrt{N}\). Orthonormality says \(\|\mathbf{Ux}\|_2=\|\mathbf{x}\|_2\). The unnormalized forward transform used by NumPy’s default &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fft&lt;/code&gt; is \(\mathbf{X}=\mathbf{Fx}=\sqrt{N}\,\mathbf{Ux}\), so&lt;/p&gt;

\[\sum_k\vert X[k]\vert^2=N\sum_n\vert x[n]\vert^2
\quad\Rightarrow\quad
\sum_n\vert x[n]\vert^2=\frac{1}{N}\sum_k\vert X[k]\vert^2.\]

&lt;p&gt;If your streaming inverse divides by \(N\) and the overlap-add path divides by \(N\) again, a 48 kHz full-band waveform gets quieter on every hop. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; does not audit that bug: the slider scales suppression, it does not check Parseval in a hand-written STFT sitting beside the package.&lt;/p&gt;

&lt;h3 id=&quot;matrix-form&quot;&gt;Matrix form&lt;/h3&gt;

\[\mathbf{X}=\mathbf{F}\mathbf{x},\quad F_{kn}=e^{-j2\pi kn/N}\]

&lt;p&gt;Unitary DFT \(\mathbf{U}=\mathbf{F}/\sqrt{N}\) obeys \(\mathbf{U}^H\mathbf{U}=\mathbf{I}\) and preserves \(\|\mathbf{x}\|_2\). Many FFT APIs use unnormalized forward + \(1/N\) inverse (or the opposite). &lt;strong&gt;ISTFT scaling bugs&lt;/strong&gt; are among the top silent quality killers: output too quiet/loud, or OLA not COLA-normalized.&lt;/p&gt;

&lt;h3 id=&quot;frequency-axis&quot;&gt;Frequency axis&lt;/h3&gt;

\[f_k=\frac{k}{N}f_s,\quad k=0,1,\ldots,\lfloor N/2\rfloor\]

&lt;ul&gt;
  &lt;li&gt;\(k=0\): DC (mean).&lt;/li&gt;
  &lt;li&gt;\(k=N/2\) (even \(N\)): Nyquist.&lt;/li&gt;
  &lt;li&gt;\(k&amp;gt;N/2\): negative frequencies for real signals (\(k\leftrightarrow k-N\)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;parseval-unnormalized-dft-common-form&quot;&gt;Parseval (unnormalized DFT common form)&lt;/h3&gt;

\[\sum_{n}\vert x[n]\vert^2=\frac{1}{N}\sum_{k}\vert X[k]\vert^2\]

&lt;p&gt;Use this to unit-test your STFT→ISTFT round trip on random vectors (with windows/hop accounted for).&lt;/p&gt;

&lt;h3 id=&quot;leakage&quot;&gt;Leakage&lt;/h3&gt;

&lt;p&gt;A sinusoid whose frequency is not an integer number of cycles inside the DFT block is discontinuous under periodic extension → spectral sidelobes. Windows taper edges (Ch. 02) to reduce sidelobes at the cost of main-lobe width.&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;mapping&quot;&gt;Mapping&lt;/h3&gt;

&lt;p&gt;\(f_s=48\,\mathrm{kHz}\), \(N=1024\), \(\Delta f\approx46.875\,\mathrm{Hz}\). HVAC ~100 Hz → near bins 2–3. A mask that only zeros bin 2 but leaves 3–10 may do little; smooth gains across neighbors.&lt;/p&gt;

&lt;h3 id=&quot;energy-check&quot;&gt;Energy check&lt;/h3&gt;

&lt;p&gt;Unit-variance white noise length 256: time energy \(\approx256\). Unnormalized DFT energy \(\sum_k\vert X[k]\vert^2\approx 256\cdot 256=65536\), so divide by \(N=256\) to match Parseval.&lt;/p&gt;

&lt;h3 id=&quot;on-bin-cosine-n4&quot;&gt;On-bin cosine, \(N=4\)&lt;/h3&gt;

&lt;p&gt;Let \(x=[1,0,-1,0]\), which is \(\cos(2\pi n/4)\): one cycle in four samples, so it is exactly basis bin \(k=1\). Multiply by the \(4\times 4\) DFT matrix \(\mathbf{F}\) (where \(F_{kn} = (-j)^{kn}\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
\[X[0] = 1 + 0 - 1 + 0 = 0\]
  &lt;/li&gt;
  &lt;li&gt;
\[X[1] = 1 + 0 - (-1)(-1) + 0 = 1 - (-1) = 2\]
  &lt;/li&gt;
  &lt;li&gt;
\[X[2] = 1 + 0 - 1 + 0 = 0\]
  &lt;/li&gt;
  &lt;li&gt;
\[X[3] = 1 + 0 - (-1)(-1) + 0 = 2\]
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Time energy is \(1^2+0^2+(-1)^2+0^2=2\). Frequency energy is \((0^2+2^2+0^2+2^2)/4=8/4=2\)—exact Parseval match! Exercise 1 still asks you to write the whole matrix; this walk-through checks the two peaks and Parseval. Off-bin tones do not collapse to two spikes — that is leakage, and a rectangular window makes it obvious.&lt;/p&gt;

&lt;h3 id=&quot;tone--noise&quot;&gt;Tone + noise&lt;/h3&gt;

&lt;p&gt;On-bin tone: single spike (rectangular window). Add white noise: floor rises. Classical Wiener gain \(\approx \frac{P_s}{P_s+P_n}\) per bin rides on estimating those powers — neural masks learn similar ideas with more context.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-turning-orthogonality-into-rock-solid-fft-unit-tests&quot;&gt;Explanation: Turning Orthogonality into Rock-Solid FFT Unit Tests&lt;/h3&gt;

&lt;h4 id=&quot;step-1-verify-orthogonality-via-the-finite-geometric-sum&quot;&gt;Step 1: Verify orthogonality via the finite geometric sum&lt;/h4&gt;
&lt;p&gt;For \(k \neq \ell\), let \(r = e^{j2\pi(k-\ell)/N} \neq 1\). Because \(r^N = e^{j2\pi(k-\ell)} = 1\), the geometric series collapses identically to zero:
\(\langle w_k, w_\ell \rangle = \sum_{n=0}^{N-1} r^n = \frac{1 - r^N}{1 - r} = 0.\)
When \(k = \ell\), every term is \(1\), summing to \(N\). That single identity proves \(\mathbf{F}^H\mathbf{F} = N\mathbf{I}\)—meaning the inverse DFT is literally \(\mathbf{F}^{-1} = \frac{1}{N}\mathbf{F}^H\)!&lt;/p&gt;

&lt;h4 id=&quot;step-2-catch-cross-language-fft-scaling-bugs-with-parseval&quot;&gt;Step 2: Catch cross-language FFT scaling bugs with Parseval&lt;/h4&gt;
&lt;p&gt;Before plugging an FFT wrapper (FFTW in C++, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rustfft&lt;/code&gt; in Rust, or WebAssembly) into your audio graph, run one random real vector through it and check \(\sum \vert X[k]\vert^2 / N \approx \sum \vert x[n]\vert^2\). If they differ by \(N\) or \(\sqrt{N}\), you caught a normalization mismatch in 5 lines of code.&lt;/p&gt;

&lt;h4 id=&quot;step-3-enforce-hermitian-symmetry-whenever-editing-complex-bins&quot;&gt;Step 3: Enforce Hermitian symmetry whenever editing complex bins&lt;/h4&gt;
&lt;p&gt;If your neural mask or filter modifies bin \(k\) (\(1 \le k &amp;lt; N/2\)) in a full complex FFT, you &lt;em&gt;must&lt;/em&gt; apply the conjugate modification to bin \(N - k\) (and keep DC \(k=0\) and Nyquist \(k=N/2\) purely real), or use a dedicated &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;irfft&lt;/code&gt; that handles mirroring automatically.&lt;/p&gt;

&lt;p&gt;Summary of the matrix DFT toolkit:&lt;/p&gt;

\[\mathbf{X} = \mathbf{F}\mathbf{x}
\;\xrightarrow{\mathbf{F}^H\mathbf{F} = N\mathbf{I}}\;
\mathbf{x} = \frac{1}{N}\mathbf{F}^H\mathbf{X}
\;\Longrightarrow\;
\sum_n \vert x[n]\vert^2 = \frac{1}{N}\sum_k \vert X[k]\vert^2.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Double \(1/N\).&lt;/li&gt;
  &lt;li&gt;Displaying mirrored spectrum as if unique content doubled.&lt;/li&gt;
  &lt;li&gt;Editing half-spectrum without conjugate mirror.&lt;/li&gt;
  &lt;li&gt;Comparing different FFT norms across languages (NumPy vs FFTW vs Rust libs).&lt;/li&gt;
  &lt;li&gt;Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|X|**2&lt;/code&gt; without window power normalization when estimating PSD.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Build a length-8 DFT matrix and check conjugate symmetry and Parseval on one real vector.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;F&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;outer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sym&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;conj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;energy_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;energy_freq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sym=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sym&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;time=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;energy_time&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; freq=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;energy_freq&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sym&lt;/code&gt; below &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-12&lt;/code&gt; (about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.200e-15&lt;/code&gt;). Both energies print &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.462500&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Using \(e^{+j2\pi kn/N}\) and comparing to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy.fft.fft&lt;/code&gt; without a sign note (this lab does not call NumPy’s FFT; the symmetry and Parseval checks still hold for this \(F\)). Forgetting the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/ N&lt;/code&gt; in Parseval and “fixing” it by dividing the time energy instead. Editing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X[1]&lt;/code&gt; and not its conjugate partner &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X[7]&lt;/code&gt;, then expecting a real inverse.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;For \(N=4\), write \(\mathbf{F}\) explicitly.&lt;/li&gt;
  &lt;li&gt;\(k=32\), \(f_s=16\,\mathrm{kHz}\), \(N=256\) → Hz?&lt;/li&gt;
  &lt;li&gt;Why do off-bin tones look broadband under rectangular windows?&lt;/li&gt;
  &lt;li&gt;Design a 5-line unit test for Parseval on your FFT wrapper.&lt;/li&gt;
  &lt;li&gt;If DC bin is huge, what time-domain symptom do you expect?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Row \(k\), column \(n\) is \(e^{-j2\pi kn/4}\). Row 0 is all ones. Row 2 is \([1,-1,1,-1]\).&lt;/li&gt;
  &lt;li&gt;\(f=32\times 16000/256=2000\,\mathrm{Hz}\).&lt;/li&gt;
  &lt;li&gt;Periodic extension jumps at the block edge, so the tone is not one basis vector. The rectangular window’s sinc spreads it.&lt;/li&gt;
  &lt;li&gt;Draw a real vector, compare \(\sum\vert x\vert^2\) with \((\sum\vert X\vert^2)/N\), and assert the absolute gap is under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-6&lt;/code&gt; for your FFT’s documented scale.&lt;/li&gt;
  &lt;li&gt;A large DC bin is a large mean. The waveform sits off zero; a DC blocker or a bias in the mic path is the first place to look.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — DFT properties, Parseval, eigenreading of DFT.&lt;/li&gt;
  &lt;li&gt;Library docs for your FFT (normalization flags).&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Mathematics of the DFT&lt;/em&gt;, https://ccrma.stanford.edu/~jos/mdft/ — the DFT matrix, orthogonality, and Parseval.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xw4voABxU5c&quot;&gt;Computing the DFT Matrix&lt;/a&gt; — Steve Brunton, English. &lt;strong&gt;xem trước.&lt;/strong&gt; This is the matrix whose rows are the complex tones. Watch how a bin is one inner product, which is the change of basis in the lesson.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nl9TZanwbBk&quot;&gt;The Discrete Fourier Transform (DFT)&lt;/a&gt; — Steve Brunton, English. The opening derives that matrix multiplication before any FFT speedup, which is the object this lesson asks you to debug with.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=bC5umvKV8bE&quot;&gt;Chương 3.1: Biến đổi Fourier rời rạc (DFT)&lt;/a&gt; — Tín hiệu và hệ thống UEt, Vietnamese. Vietnamese walk-through of the DFT sum. Pair it with the matrix video when the bin index is the thing that breaks.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-03 DTFT, DFS, and DFT relationships</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_03_dtft_dfs_dft_relationships/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_03_dtft_dfs_dft_relationships</id>
   <content type="html">&lt;p&gt;Open any signal-processing textbook and you immediately run into an alphabet soup of four transforms: CTFT, DTFT, DFS, and DFT. Yet production audio code never evaluates an infinite DTFT sum—it computes finite &lt;strong&gt;DFTs&lt;/strong&gt; (via FFTs) on short windowed blocks, hop after hop.&lt;/p&gt;

&lt;p&gt;Why bother learning the DTFT at all? Because the &lt;strong&gt;DFT is just a finite grid of samples pulled off the DTFT&lt;/strong&gt; of your windowed audio block! Once you see that single geometric relationship, three notorious engineering myths vanish on the spot: why zero-padding does &lt;em&gt;not&lt;/em&gt; sharpen pitch resolution, why multiplying two DFTs causes circular wrap-around echoes, and why a real-FFT only needs \(N/2 + 1\) bins.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/dft-basis.png&quot; alt=&quot;DFT basis tones drawn as the discrete grid the FFT actually evaluates&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. A DFT does not draw a continuous curve; it reports inner products against these discrete complex tones, one bin per tone.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (the four-transform zoo, windowing as frequency smearing, conjugate symmetry &amp;amp; circular convolution) → DTFT vs. DFT definitions &amp;amp; zero-padding myth → Worked examples: bin listing at 16 kHz / 512, circular convolution wrap-around, and zero-padding 64 samples to 512 → Explanation: 3 steps separating grid density from true frequency resolution → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-from-continuous-theory-to-finite-fft-grids&quot;&gt;Key ideas: From Continuous Theory to Finite FFT Grids&lt;/h2&gt;

&lt;h3 id=&quot;1-the-four-transform-map-time-vs-frequency&quot;&gt;1. The Four-Transform Map (Time vs. Frequency)&lt;/h3&gt;
&lt;p&gt;Every Fourier variant obeys one dual rule: &lt;strong&gt;discreteness in one domain causes periodicity in the other&lt;/strong&gt;.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Sampling in time (discrete time) makes the spectrum \(2\pi\)-periodic (&lt;strong&gt;DTFT&lt;/strong&gt;).&lt;/li&gt;
  &lt;li&gt;Sampling the spectrum at \(N\) uniform points (discrete frequency) forces the time signal to be treated as \(N\)-periodic (&lt;strong&gt;DFT / DFS&lt;/strong&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-windowing-sets-true-resolution-zero-padding-only-interpolates&quot;&gt;2. Windowing Sets True Resolution; Zero-Padding Only Interpolates&lt;/h3&gt;
&lt;p&gt;Slicing \(L\) samples from a stream multiplies the true signal by a length-\(L\) window \(w[n]\), which &lt;strong&gt;convolves&lt;/strong&gt; its true spectrum with the window’s main lobe (width \(\propto f_s / L\)). Appending zeros to reach length \(N &amp;gt; L\) samples that &lt;em&gt;exact same&lt;/em&gt; smeared DTFT on a finer grid—it makes plots look smoother without ever separating two closely spaced harmonics!&lt;/p&gt;

&lt;h3 id=&quot;3-circular-convolution-and-hermitian-symmetry&quot;&gt;3. Circular Convolution and Hermitian Symmetry&lt;/h3&gt;
&lt;p&gt;Because the DFT treats a length-\(N\) block as a closed ring, multiplying two length-\(N\) DFTs performs &lt;strong&gt;circular&lt;/strong&gt; (wrap-around) convolution—not linear filtering—unless you pad to \(N \ge L_x + L_h - 1\). Meanwhile, for real-valued audio PCM, negative frequencies are exact complex conjugates of positive ones (\(X[k] = X^*[N-k]\)), so real-FFT APIs only store \(N/2 + 1\) unique bins.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Distinguish DTFT (discrete time, continuous frequency) from DFT (finite grid).&lt;/li&gt;
  &lt;li&gt;Explain periodicity relationships among time and frequency without full proofs.&lt;/li&gt;
  &lt;li&gt;Interpret DFT bins as samples of a windowed segment’s spectrum.&lt;/li&gt;
  &lt;li&gt;Contrast zero-padding with true frequency resolution.&lt;/li&gt;
  &lt;li&gt;Use conjugate symmetry and explain why NS stacks cite “N-point FFT” frames.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Taxonomy of transforms; where STFT sits&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;DTFT definition; windowing as spectral convolution&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;DFT formulas; zero-padding experiment design&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Real symmetry; circular convolution warning&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Exercises tied to DeepFilterNet-style N choices&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;transform-zoo-engineer-edition&quot;&gt;Transform zoo (engineer edition)&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Time domain&lt;/th&gt;
      &lt;th&gt;Frequency domain&lt;/th&gt;
      &lt;th&gt;In NS code?&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;CTFT&lt;/td&gt;
      &lt;td&gt;continuous&lt;/td&gt;
      &lt;td&gt;continuous&lt;/td&gt;
      &lt;td&gt;theory&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DTFT&lt;/td&gt;
      &lt;td&gt;infinite discrete&lt;/td&gt;
      &lt;td&gt;continuous, \(2\pi\)-periodic&lt;/td&gt;
      &lt;td&gt;theory / math&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DFS&lt;/td&gt;
      &lt;td&gt;periodic discrete&lt;/td&gt;
      &lt;td&gt;periodic discrete&lt;/td&gt;
      &lt;td&gt;rare by name&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DFT/FFT&lt;/td&gt;
      &lt;td&gt;length-\(N\) vector&lt;/td&gt;
      &lt;td&gt;\(N\) bins&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;everywhere&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;STFT&lt;/td&gt;
      &lt;td&gt;windowed frames&lt;/td&gt;
      &lt;td&gt;DFT per frame&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;NS backbone&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;dtft&quot;&gt;DTFT&lt;/h3&gt;

\[X(e^{j\omega})=\sum_{n=-\infty}^{\infty}x[n]e^{-j\omega n},\qquad
x[n]=\frac{1}{2\pi}\int_{-\pi}^{\pi}X(e^{j\omega})e^{j\omega n}\,\mathrm{d}\omega\]

&lt;p&gt;\(\omega\) is normalized radians/sample. Physical Hz needs \(f_s\).&lt;/p&gt;

&lt;h3 id=&quot;dft&quot;&gt;DFT&lt;/h3&gt;

&lt;p&gt;For \(x[0],\ldots,x[N-1]\):&lt;/p&gt;

\[X[k]=\sum_{n=0}^{N-1}x[n]e^{-j2\pi kn/N}\]

\[x[n]=\frac{1}{N}\sum_{k=0}^{N-1}X[k]e^{j2\pi kn/N}\]

&lt;p&gt;Interpretation that prevents bugs: &lt;strong&gt;DFT values are samples of the DTFT&lt;/strong&gt; of the finite sequence (zero outside the block) at \(\omega_k=2\pi k/N\), equivalently samples of the DTFT of the periodic extension. Write the DTFT sum, then restrict the frequency:&lt;/p&gt;

\[X(e^{j\omega})\Big|_{\omega=2\pi k/N}
=\sum_{n=0}^{N-1}x[n]e^{-j2\pi kn/N}
=X[k].\]

&lt;p&gt;Nothing in that substitution invents new information between the bins. Multiplying two DFTs ↔ &lt;strong&gt;circular&lt;/strong&gt; convolution of length \(N\), not linear convolution — hence overlap-save/overlap-add methods for long filters.&lt;/p&gt;

&lt;h3 id=&quot;windowing--frequency-domain-smearing&quot;&gt;Windowing = frequency-domain smearing&lt;/h3&gt;

&lt;p&gt;Rectangular truncation to length \(L\) multiplies by a window \(w[n]\), convolving \(X(e^{j\omega})\) with \(W(e^{j\omega})\). Main lobe width scales like \(1/L\). That is why 5 ms windows cannot separate 50 Hz pitch harmonics cleanly, while 40 ms windows blur plosive timing.&lt;/p&gt;

&lt;h3 id=&quot;zero-padding--magic-resolution&quot;&gt;Zero-padding ≠ magic resolution&lt;/h3&gt;

&lt;p&gt;Pad length-\(L\) data to \(N&amp;gt;L\) zeros:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;DFT samples the &lt;em&gt;same&lt;/em&gt; underlying DTFT more densely.&lt;/li&gt;
  &lt;li&gt;Peak locations interpolate more smoothly.&lt;/li&gt;
  &lt;li&gt;Two close tones under one main lobe remain unresolvable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Need finer true resolution → longer coherent observation (larger \(L\)), paying latency and non-stationarity.&lt;/p&gt;

&lt;h3 id=&quot;conjugate-symmetry-real-pcm&quot;&gt;Conjugate symmetry (real PCM)&lt;/h3&gt;

\[X[k]=X^*[N-k]\]

&lt;p&gt;Unique info in \(0\le k\le N/2\). Real-FFT packing stores roughly \(N/2+1\) complex bins. If your mask network outputs \(N/2+1\) magnitudes, mirror before iFFT — or use a library that expects packed format.&lt;/p&gt;

&lt;h3 id=&quot;typical-n-in-speech-ns&quot;&gt;Typical N in speech NS&lt;/h3&gt;

&lt;p&gt;Orders of magnitude seen in RNNoise / DeepFilterNet-class systems: hundreds to ~1024 bins depending on rate and window. Always read the &lt;strong&gt;specific&lt;/strong&gt; paper or config: wrong \(N\) breaks pretrained weights.&lt;/p&gt;

&lt;p&gt;Example: \(f_s=48\,\mathrm{kHz}\), \(N=960\) (exactly 20 ms if hop framing aligns). \(\Delta f=50\,\mathrm{Hz}\). At 16 kHz, \(N=512\) ⇒ \(\Delta f=31.25\,\mathrm{Hz}\).&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;bin-listing&quot;&gt;Bin listing&lt;/h3&gt;

&lt;p&gt;\(f_s=16\,\mathrm{kHz}\), \(N=512\). Bin \(k \leftrightarrow k\cdot 31.25\,\mathrm{Hz}\). Speech fundamental 120 Hz ≈ bin 3.84 → energy spreads over bins 3–5 due to window lobe — masks should be smoothed.&lt;/p&gt;

&lt;h3 id=&quot;circular-convolution-trap&quot;&gt;Circular convolution trap&lt;/h3&gt;

&lt;p&gt;Multiply DFT of signal by DFT of a long FIR reverb impulse truncated poorly into \(N\) taps: time-domain wrap creates metallic pre-echoes. Use OLA with sufficient FFT size \(N \ge L_x+L_h-1\) for linear convolution blocks.&lt;/p&gt;

&lt;h3 id=&quot;zero-pad-demo-design&quot;&gt;Zero-pad demo design&lt;/h3&gt;

&lt;p&gt;Take 64 samples of a 1 kHz tone at 16 kHz. The tone completes \(1000\times 64/16000=4\) cycles, so the length-64 DFT peaks at bin 4. Pad to 512 and the same 64 samples peak at bin \(1000\times 512/16000=32\). Bin spacing changed from \(16000/64=250\,\mathrm{Hz}\) to \(16000/512=31.25\,\mathrm{Hz}\), but the main lobe in hertz is still set by the 64-sample observation, about 250 Hz wide, not by 31.25 Hz. The mini-lab prints those two peak indices. At the 48 kHz product default, the same trap appears when someone zero-pads a 10 ms frame and calls the new bin spacing “better pitch resolution” without lengthening the window the mic actually filled.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-why-zero-padding-never-creates-new-information&quot;&gt;Explanation: Why Zero-Padding Never Creates New Information&lt;/h3&gt;

&lt;h4 id=&quot;step-1-write-the-dtft-of-a-zero-padded-sequence&quot;&gt;Step 1: Write the DTFT of a zero-padded sequence&lt;/h4&gt;
&lt;p&gt;Suppose your signal \(x[0], \ldots, x[L-1]\) has length \(L = 64\), and you append \(N - L = 448\) zeros to form \(\tilde{x}[n]\) of length \(N = 512\). Compute the DTFT of \(\tilde{x}\):
\(\tilde{X}(e^{j\omega}) = \sum_{n=0}^{511} \tilde{x}[n]e^{-j\omega n} = \sum_{n=0}^{63} x[n]e^{-j\omega n} = X(e^{j\omega}).\)
The continuous spectrum \(X(e^{j\omega})\) did not change by a single decimal place!&lt;/p&gt;

&lt;h4 id=&quot;step-2-evaluate-that-unchanged-curve-on-two-different-grids&quot;&gt;Step 2: Evaluate that unchanged curve on two different grids&lt;/h4&gt;
&lt;p&gt;The 64-point DFT reads \(X(e^{j\omega})\) every \(250\,\mathrm{Hz}\) (\(\Delta f = 16000/64\)); the 512-point zero-padded DFT reads the &lt;strong&gt;exact same curve&lt;/strong&gt; every \(31.25\,\mathrm{Hz}\) (\(\Delta f = 16000/512\)). If two speech harmonics sit \(100\,\mathrm{Hz}\) apart inside a \(250\,\mathrm{Hz}\)-wide main lobe, they have already merged into one single lump in \(X(e^{j\omega})\)—sampling that lump 8× more densely only draws a smoother lump!&lt;/p&gt;

&lt;h4 id=&quot;step-3-know-when-zero-padding-is-genuinely-useful&quot;&gt;Step 3: Know when zero-padding IS genuinely useful&lt;/h4&gt;
&lt;p&gt;Zero-padding is not useless—it just solves &lt;em&gt;different&lt;/em&gt; problems: (a) reaching a fast FFT size (e.g., power-of-two or smooth composite), (b) preventing circular wrap-around when multiplying by an FIR filter (\(N \ge L_x + L_h - 1\)), and (c) interpolating peak frequencies more accurately when tones are already well separated.&lt;/p&gt;

&lt;p&gt;Summary of the DTFT-to-DFT relationship:&lt;/p&gt;

\[x[0\ldots L-1]
\;\xrightarrow{\text{Window width } L}\;
\text{True resolution } \sim \frac{f_s}{L}
\;\xrightarrow{\text{Zero-pad to } N}\;
\text{Finer grid } \Delta f = \frac{f_s}{N}\ (\text{same DTFT!}).\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Marketing zero-padding as super-resolution.&lt;/li&gt;
  &lt;li&gt;Forgetting circular vs linear convolution.&lt;/li&gt;
  &lt;li&gt;Comparing \(\vert X[k]\vert\) across different \(N\) without normalization.&lt;/li&gt;
  &lt;li&gt;Breaking conjugate symmetry then taking “real” iFFT (imag leftovers = bugs).&lt;/li&gt;
  &lt;li&gt;Changing \(N\) between training and inference for a neural masker.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Compare a 64-point DFT of a 1 kHz tone at 16 kHz with the same 64 samples zero-padded to 512.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_win&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_win&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;tone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;peak64&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;argmax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;peak512&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;argmax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;peak64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peak512&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_win&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4 32 250.0 31.25&lt;/code&gt;. The peak index moved because the grid got denser. The observation length did not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Reading bin 32 at \(N=512\) as “the tone got sharper.” Comparing raw &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|rfft|&lt;/code&gt; peak heights across the two lengths without a scale convention. Forgetting that a cosine at an integer bin also has a negative-frequency twin that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; does not print separately.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Nearest bin to 1 kHz at \(f_s=16\,\mathrm{kHz}\), \(N=512\).&lt;/li&gt;
  &lt;li&gt;One sentence: zero-pad vs longer window.&lt;/li&gt;
  &lt;li&gt;On-bin vs half-bin tone: which leaks more with a rectangular window?&lt;/li&gt;
  &lt;li&gt;Why does STFT use hop \(R&amp;lt;N\) instead of adjacent non-overlapping DFTs only?&lt;/li&gt;
  &lt;li&gt;If weights expect 513 magnitude bins, what \(N\) is implied for a real FFT?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(\Delta f=16000/512=31.25\,\mathrm{Hz}\), so 1 kHz is bin \(1000/31.25=32\) exactly.&lt;/li&gt;
  &lt;li&gt;Zero-padding densifies samples of the same DTFT. A longer window narrows the main lobe.&lt;/li&gt;
  &lt;li&gt;An on-bin tone matches one basis vector and, with a rectangular window, sits in one bin. A half-bin tone is discontinuous under periodic extension and leaks.&lt;/li&gt;
  &lt;li&gt;Hop \(R&amp;lt;N\) is what builds overlap so the inverse STFT can satisfy constant overlap-add. Adjacent DFTs with \(R=N\) leave a rectangular splice.&lt;/li&gt;
  &lt;li&gt;A packed real FFT keeps \(N/2+1\) bins, so 513 bins means \(N=1024\).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — relationships among DTFT/DFS/DFT.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Mathematics of the DFT&lt;/em&gt;, https://ccrma.stanford.edu/~jos/mdft/ — DFT, DTFT, and zero-padding.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588) and the reference repo https://github.com/Rikorose/DeepFilterNet for the frame length the weights actually saw. RNNoise’s public docs are the classical comparison for a smaller FFT.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=nl9TZanwbBk&quot;&gt;The Discrete Fourier Transform (DFT)&lt;/a&gt; — Steve Brunton, English. &lt;strong&gt;xem trước.&lt;/strong&gt; He argues the DFT is a finite Fourier series, not an infinite integral. That naming point is the DTFT–DFS–DFT map this lesson draws.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xw4voABxU5c&quot;&gt;Computing the DFT Matrix&lt;/a&gt; — Steve Brunton, English. Watch the matrix that samples the same tones the DFT definition uses, so the finite sum becomes an inner product per bin.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=bC5umvKV8bE&quot;&gt;Chương 3.1: Biến đổi Fourier rời rạc (DFT)&lt;/a&gt; — Tín hiệu và hệ thống UEt, Vietnamese. A Vietnamese lecture on the DFT sum. Use it beside the English lectures when you want the same definition in the course’s other language.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-02 Sampling, aliasing, and Nyquist</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_02_sampling_aliasing_nyquist/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_02_sampling_aliasing_nyquist</id>
   <content type="html">&lt;p&gt;Here is a classic production postmortem: an engineer drops a crisp 16 kHz speech-enhancement ONNX model into a 48 kHz browser WebRTC graph—skipping the resampler “because 48 kHz has more detail.” The call immediately sounds like a haunted robot, yet no exception is thrown and every tensor shape matches. What went wrong? &lt;strong&gt;Sampling rate is not metadata; it defines the entire frequency axis.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every WebRTC track and every DeepFilterNet forward pass assumes a specific sample rate \(f_s\). Getting \(f_s\) wrong—or decimating without an anti-alias filter—folds high-frequency energy irreversibly on top of speech, creating phantom interference that no neural network can undo. This lesson makes the Nyquist–Shannon sampling theorem concrete and operational for audio engineers.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/sampling-nyquist.png&quot; alt=&quot;A spectrum copied at every sample rate, with copies overlapping when the signal is too wide&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Sampling repeats the spectrum every \(f_s\) hertz; overlap of those copies is aliasing, and it is not undone by a neural suppressor.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (impulse-train sampling, spectral replicas &amp;amp; aliasing, normalized digital frequency \(\omega\)) → Nyquist criterion, product rates (8/16/48 kHz), and anti-alias filters → Worked examples: 7 kHz cosine sampled at 8 kHz collapsing identically to 1 kHz, broadband fold, and 20 ms frame sizes across rates → Explanation: 3 steps explaining why aliasing is irreversible and how decimation must be ordered → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-sampling-theory-and-multirate-audio&quot;&gt;Key ideas: Sampling Theory and Multirate Audio&lt;/h2&gt;

&lt;h3 id=&quot;1-multiplying-in-time--replicating-in-frequency&quot;&gt;1. Multiplying in Time = Replicating in Frequency&lt;/h3&gt;
&lt;p&gt;Ideal sampling multiplies a continuous waveform \(x_c(t)\) by a periodic impulse train spaced by \(T = 1/f_s\). Because the Fourier transform of a pulse train is another pulse train spaced by \(f_s\) Hz, sampling &lt;strong&gt;copies the original spectrum every \(f_s\) Hz&lt;/strong&gt; across the entire frequency axis.&lt;/p&gt;

&lt;h3 id=&quot;2-nyquist-frequency-and-aliasing-fold-back&quot;&gt;2. Nyquist Frequency and Aliasing Fold-Back&lt;/h3&gt;
&lt;p&gt;As long as the original signal contains no energy above the &lt;strong&gt;Nyquist frequency&lt;/strong&gt; \(f_s / 2\), the spectral copies stay cleanly separated and an ideal low-pass filter recovers \(x_c(t)\) with zero loss. If energy exceeds \(f_s / 2\), neighboring copies &lt;strong&gt;overlap and add&lt;/strong&gt;—a permanent collision called &lt;strong&gt;aliasing&lt;/strong&gt; where high frequencies impersonate low ones.&lt;/p&gt;

&lt;h3 id=&quot;3-normalized-digital-frequency-omega--2pi-f--f_s&quot;&gt;3. Normalized Digital Frequency \(\omega = 2\pi f / f_s\)&lt;/h3&gt;
&lt;p&gt;Once audio is a sequence of numbers \(x[n]\), the array itself has no idea what \(f_s\) was. Digital filters and FFT bins live on normalized frequency \(\omega \in [-\pi, \pi]\), where \(\omega = \pi\) always maps to \(f_s / 2\). Running a 16 kHz filter on 48 kHz PCM stretches every frequency cutoff by \(3\times\)!&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;State the sampling theorem and the Nyquist rate / Nyquist frequency.&lt;/li&gt;
  &lt;li&gt;Explain aliasing with concrete audio numerics (tones and broadband noise).&lt;/li&gt;
  &lt;li&gt;Choose among 8 / 16 / 48 kHz thoughtfully for speech NS pipelines.&lt;/li&gt;
  &lt;li&gt;Describe anti-alias filtering before ADC and before decimation.&lt;/li&gt;
  &lt;li&gt;List resampling pitfalls when bridging browser clocks and neural model rates.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Hook: “we ran the 16 kHz ONNX at 48 kHz and quality tanked” postmortem&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–25&lt;/td&gt;
      &lt;td&gt;Impulse-train sampling; spectrum replicas; Nyquist proof sketch&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;25–40&lt;/td&gt;
      &lt;td&gt;Worked aliases; speech bandwidth tables; product rate choices&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;40–52&lt;/td&gt;
      &lt;td&gt;Anti-alias + resampling pipeline design; WebAudio/WebRTC notes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Pitfalls and exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;sampling-replicates-spectra&quot;&gt;Sampling replicates spectra&lt;/h3&gt;

&lt;p&gt;Ideal impulse-train sampling with period \(T=1/f_s\):&lt;/p&gt;

\[x_s(t)=x_c(t)\sum_{n=-\infty}^{\infty}\delta(t-nT)\]

&lt;p&gt;yields spectrum copies every \(f_s\) Hz:&lt;/p&gt;

\[X_s(j2\pi f)=f_s\sum_{k} X_c\!\big(j2\pi(f-kf_s)\big)\]

&lt;p&gt;If the support of \(X_c\) is wider than \(f_s/2\), replicas &lt;strong&gt;overlap&lt;/strong&gt;. The overlap region is irreversibly confused — &lt;strong&gt;aliasing&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The identity you will use in the lab is one line of the replica sum. On the sample grid \(t=n/f_s\),&lt;/p&gt;

\[\cos\!\left(2\pi\frac{f}{f_s}n\right)
=\cos\!\left(2\pi\frac{f-mf_s}{f_s}n\right)\]

&lt;p&gt;because \(2\pi m n\) is an integer number of turns. Fold the representative into \([0,f_s/2]\) by reflecting at Nyquist if needed. For a 7 kHz cosine sampled at 8 kHz, take \(m=1\): \(\vert 7000-8000\vert=1000\,\mathrm{Hz}\). The 7 kHz cosine and the 1 kHz cosine are the same sequence. A sine picks up a minus sign, \(\sin(2\pi\cdot 7n/8)=-\sin(2\pi\cdot 1n/8)\), because sine is odd under that full-turn shift. “Matches” means identical samples, not “sounds close.”&lt;/p&gt;

&lt;h3 id=&quot;nyquist-criterion&quot;&gt;Nyquist criterion&lt;/h3&gt;

&lt;p&gt;If \(x_c\) is bandlimited with highest frequency \(B\) Hz, choose&lt;/p&gt;

\[f_s &amp;gt; 2B\]

&lt;p&gt;Then an ideal low-pass (sinc interpolator) reconstructs \(x_c\) from samples \(x[n]=x_c(nT)\). Real systems approximate this with analog anti-alias filters + practical interpolators.&lt;/p&gt;

&lt;p&gt;Definitions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nyquist rate&lt;/strong&gt; \(= 2B\) for a bandlimit \(B\).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Nyquist frequency&lt;/strong&gt; \(= f_s/2\) for a given sampler.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;discrete-time-frequency-mapping&quot;&gt;Discrete-time frequency mapping&lt;/h3&gt;

&lt;p&gt;After sampling, digital frequency \(\omega\) (rad/sample) relates to Hz by&lt;/p&gt;

\[\omega = 2\pi\frac{f}{f_s},\qquad f = \frac{\omega}{2\pi}f_s\]

&lt;p&gt;\(\omega=\pi\) always means Nyquist (Hz value depends on \(f_s\)). This is why the same FIR coefficients implement different Hz cutoffs at 16 vs 48 kHz.&lt;/p&gt;

&lt;h3 id=&quot;audio-bandwidth-vs-product-rates&quot;&gt;Audio bandwidth vs product rates&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Rate&lt;/th&gt;
      &lt;th&gt;Nyquist&lt;/th&gt;
      &lt;th&gt;Typical use in voice&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;8 kHz&lt;/td&gt;
      &lt;td&gt;4 kHz&lt;/td&gt;
      &lt;td&gt;Narrowband telephony&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;16 kHz&lt;/td&gt;
      &lt;td&gt;8 kHz&lt;/td&gt;
      &lt;td&gt;Wideband speech ML&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;48 kHz&lt;/td&gt;
      &lt;td&gt;24 kHz&lt;/td&gt;
      &lt;td&gt;WebRTC/full-band device clock&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Speech intelligibility energy is not uniform: vowels live lower; consonants need highs. 8 kHz shreds many fricatives. 16 kHz is a common &lt;strong&gt;model native&lt;/strong&gt; rate. 48 kHz often matches &lt;strong&gt;device&lt;/strong&gt; graphs, and it is the full-band default of npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0, where Nyquist is 24 kHz. Your job is to resample &lt;strong&gt;deliberately&lt;/strong&gt; between them. Feeding 48 kHz PCM to a 16 kHz STFT does not “give the net more resolution.” It assigns the wrong Hertz label to every bin and, without a low-pass near 8 kHz, folds 8–24 kHz energy into the band the model was trained to interpret as speech.&lt;/p&gt;

&lt;h3 id=&quot;anti-alias-filters&quot;&gt;Anti-alias filters&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Analog (before ADC):&lt;/strong&gt; attenuate above \(f_s/2\). Cheap products with weak filters alias ultrasonic energy into the band.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Digital (before decimation):&lt;/strong&gt; when going 48→16 kHz (factor \(M=3\)), low-pass near 8 kHz, &lt;em&gt;then&lt;/em&gt; keep every third sample. Decimate-first is a bug.&lt;/p&gt;

&lt;h3 id=&quot;resampling-quality-tiers&quot;&gt;Resampling quality tiers&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Wrong:&lt;/strong&gt; drop/repeat samples; nearest-neighbor.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Better:&lt;/strong&gt; linear interpolation (still poor near Nyquist).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Production:&lt;/strong&gt; proper low-pass + polyphase resampler (libsamplerate-class, SoX, browser Offline resamplers, etc.).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Neural NS is sensitive: aliasing tones become “extra noise” the model never saw in training.&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;tone-alias&quot;&gt;Tone alias&lt;/h3&gt;

&lt;p&gt;\(f=5\,\mathrm{kHz}\), \(f_s=8\,\mathrm{kHz}\). Nyquist 4 kHz. Fold: \(f_{\mathrm{alias}}=f_s-f=3\,\mathrm{kHz}\) (first folding). You perceive 3 kHz.&lt;/p&gt;

&lt;h3 id=&quot;broadband-fold&quot;&gt;Broadband fold&lt;/h3&gt;

&lt;p&gt;White-ish noise up to 20 kHz sampled at 16 kHz without anti-alias: energy from 8–20 kHz folds into 0–8 kHz, raising the in-band noise floor — SNR worsens &lt;em&gt;before&lt;/em&gt; NS runs.&lt;/p&gt;

&lt;h3 id=&quot;frame-sizes-at-fixed-20-ms&quot;&gt;Frame sizes at fixed 20 ms&lt;/h3&gt;

\[L = T\cdot f_s \Rightarrow L_{16k}=320,\quad L_{48k}=960\]

&lt;p&gt;Same latency budget, different FFT sizes and bin widths \(\Delta f=f_s/N\).&lt;/p&gt;

&lt;h3 id=&quot;rtf-impact-of-rate&quot;&gt;RTF impact of rate&lt;/h3&gt;

&lt;p&gt;If compute scales roughly with samples/s (FFT + hop rate), jumping 16→48 kHz without changing hop &lt;em&gt;seconds&lt;/em&gt; can cost ~3× STFT throughput. Measure; don’t guess.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-why-aliasing-cannot-be-filtered-out-after-sampling&quot;&gt;Explanation: Why Aliasing Cannot Be Filtered Out After Sampling&lt;/h3&gt;

&lt;h4 id=&quot;step-1-check-the-exact-sample-values-at-n--0-1-2-3&quot;&gt;Step 1: Check the exact sample values at \(n = 0, 1, 2, 3\)&lt;/h4&gt;
&lt;p&gt;Sample both \(x_1(t) = \cos(2\pi \cdot 7000\,t)\) and \(x_2(t) = \cos(2\pi \cdot 1000\,t)\) at \(f_s = 8000\,\mathrm{Hz}\):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;At \(n = 0\): \(\cos(0) = 1\) for both.&lt;/li&gt;
  &lt;li&gt;At \(n = 1\): \(\cos(7\pi/4) = +\frac{\sqrt{2}}{2}\) and \(\cos(\pi/4) = +\frac{\sqrt{2}}{2}\).&lt;/li&gt;
  &lt;li&gt;At \(n = 2\): \(\cos(14\pi/4) = 0\) and \(\cos(2\pi/4) = 0\).&lt;/li&gt;
  &lt;li&gt;At \(n = 3\): \(\cos(21\pi/4) = -\frac{\sqrt{2}}{2}\) and \(\cos(3\pi/4) = -\frac{\sqrt{2}}{2}\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every single sample is &lt;strong&gt;mathematically identical&lt;/strong&gt; to machine precision! Once those numbers are written to memory, no filter in the universe can tell whether the original wave was 7 kHz or 1 kHz.&lt;/p&gt;

&lt;h4 id=&quot;step-2-why-decimation-must-always-be-low-pass-first-drop-samples-second&quot;&gt;Step 2: Why decimation must ALWAYS be “Low-Pass FIRST, Drop Samples SECOND”&lt;/h4&gt;
&lt;p&gt;Suppose you have 48 kHz PCM containing a 12 kHz cymbal hiss and you want 16 kHz PCM (\(M = 3\)):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Wrong order (drop 2 of every 3 samples first):&lt;/strong&gt; the 12 kHz tone exceeds the new 8 kHz Nyquist and immediately folds to \(\vert 12 - 16\vert = 4\,\mathrm{kHz}\)—smack inside the human voice band!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Right order (low-pass below 8 kHz first, then keep every 3rd sample):&lt;/strong&gt; the 12 kHz energy is erased &lt;em&gt;before&lt;/em&gt; the sample grid coarsens, so nothing folds into 0–8 kHz.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;step-3-guard-the-rate-boundary-in-every-audio-graph&quot;&gt;Step 3: Guard the rate boundary in every audio graph&lt;/h4&gt;
&lt;p&gt;Whenever a 48 kHz browser graph talks to a 16 kHz model—or when an evaluation script computes SI-SDR—explicitly assert &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fs_in == fs_model&lt;/code&gt; or insert a proper polyphase resampler. Never trust “it sounds okay on one voice note.”&lt;/p&gt;

&lt;p&gt;Summary of safe multirate downsampling:&lt;/p&gt;

\[x_{48\text{k}}[n]
\;\xrightarrow{\text{LPF } &amp;lt; 8\,\mathrm{kHz}}\;
\tilde{x}_{48\text{k}}[n]
\;\xrightarrow{\downarrow 3}\;
x_{16\text{k}}[m]\ (\text{alias-free}).\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Running a 16 kHz-trained model on 48 kHz PCM “because higher is better.”&lt;/li&gt;
  &lt;li&gt;Claiming aliasing is impossible in float32 pipelines — aliasing is about rate, not bit depth.&lt;/li&gt;
  &lt;li&gt;Mixing 44.1 kHz media with 48 kHz graphs without a resampler node.&lt;/li&gt;
  &lt;li&gt;Using FFT-based resample incorrectly (block boundary clicks).&lt;/li&gt;
  &lt;li&gt;Forgetting anti-alias when downsampling for SI-SDR eval at another rate.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Sample a 7 kHz cosine at 8 kHz and show it is the same sequence as a 1 kHz cosine.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8000&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;high&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;low&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;high&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;low&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;high&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; An error below &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1e-12&lt;/code&gt; (typically about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.354e-14&lt;/code&gt;). The first eight samples round to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1.0, 0.707107, -0.0, -0.707107, -1.0, -0.707107, -0.0, 0.707107]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Comparing sines and expecting a zero error without the sign flip. Declaring “no alias” because both arrays are float64. Low-pass filtering &lt;em&gt;after&lt;/em&gt; the 8 kHz sampler and hoping the 7 kHz tone returns.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Nyquist frequency at 48 kHz and 16 kHz?&lt;/li&gt;
  &lt;li&gt;Alias of 10 kHz tone when \(f_s=16\,\mathrm{kHz}\) (express in \([0,f_s/2]\)).&lt;/li&gt;
  &lt;li&gt;Samples in 10 ms at 8/16/48 kHz.&lt;/li&gt;
  &lt;li&gt;Write a 4-step checklist to convert a 48 kHz mono Float32 track to a 16 kHz model input safely.&lt;/li&gt;
  &lt;li&gt;Why does \(\omega=\pi\) mean different Hz at different \(f_s\)?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Nyquist frequency is \(f_s/2\): 24 kHz at 48 kHz, 8 kHz at 16 kHz.&lt;/li&gt;
  &lt;li&gt;\(10\,\mathrm{kHz}\) at \(16\,\mathrm{kHz}\) folds once: \(16-10=6\,\mathrm{kHz}\).&lt;/li&gt;
  &lt;li&gt;\(10\,\mathrm{ms}\) is 80, 160, and 480 samples.&lt;/li&gt;
  &lt;li&gt;Confirm 48 kHz mono float; low-pass near 8 kHz; decimate by 3; check a 1 kHz sine is still 1 kHz and that energy above 8 kHz is gone.&lt;/li&gt;
  &lt;li&gt;\(\omega=\pi\) is half a cycle per sample, which is \(f_s/2\) hertz. The digital frequency is normalized; the physical frequency is not.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Oppenheim &amp;amp; Schafer — sampling theorem and multirate chapters.&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Mathematics of the DFT&lt;/em&gt;, https://www.dsprelated.com/freebooks/mdft/ — sampling and the frequency axis used by an FFT.&lt;/li&gt;
  &lt;li&gt;Web Audio API AudioContext &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sampleRate&lt;/code&gt; behavior; WebRTC getUserMedia constraints docs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=KuaannH5pnM&quot;&gt;Aliasing and the Sampling Theorem Simplified&lt;/a&gt; — Barry Van Veen, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the wrap from continuous frequency into one 2π interval; that fold is the aliasing bug a wrong sample rate hides.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://xiph.org/video/vid2.shtml&quot;&gt;Xiph.Org Video Presentations: Digital Show &amp;amp; Tell&lt;/a&gt; — Xiph.Org, English. Official Xiph.Org presentation of sampling, bit depth, and reconstruction. Use it to separate a real sample-rate limit from the stair-step myth.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>01-01 Continuous Fourier transform intuition</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_01_continuous_ft_intuition/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter01/01_01_continuous_ft_intuition</id>
   <content type="html">&lt;p&gt;Look at a raw microphone waveform of someone saying “hello” in a noisy office: in the time domain, the speech and the air-conditioner hum are tangled together at every single millisecond. Yet the moment you switch coordinates into the &lt;strong&gt;frequency domain&lt;/strong&gt;, the mess snaps into focus—the low-frequency HVAC rumble sits in one quiet corner, the speaker’s vocal harmonics stack neatly like a comb, and you can attenuate the noise without amputating the voice.&lt;/p&gt;

&lt;p&gt;This lesson builds &lt;strong&gt;continuous-time Fourier intuition&lt;/strong&gt; from the ground up so that the discrete STFT parameters you configure in later chapters are never magic numbers. We connect complex exponentials, LTI eigenfunctions, magnitude vs. phase percepts, and concrete numerical calculations into one coherent mental model.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/fourier-intuition.png&quot; alt=&quot;A waveform split into a few sinusoids whose sum rebuilds the original curve&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Frequency is a coordinate: each sinusoid is one basis tone, and the transform measures how much of that tone is in the signal.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (frequency as a basis coordinate, LTI eigenfunctions, magnitude vs. phase) → CTFT analysis/synthesis &amp;amp; operational properties → Speech formants vs. noise spectra → Worked examples: Euler decomposition of two tones, phase ramp from a 5 ms delay, and the dB addition trap → Explanation: 3 steps explaining why complex exponentials diagonalize filters and why phase still matters → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-harmonic-analysis-and-frequency-domain-audio&quot;&gt;Key ideas: Harmonic Analysis and Frequency-Domain Audio&lt;/h2&gt;

&lt;h3 id=&quot;1-frequency-as-an-orthogonal-coordinate-system&quot;&gt;1. Frequency as an Orthogonal Coordinate System&lt;/h3&gt;
&lt;p&gt;Just as a 3D vector breaks into \((x, y, z)\) components along orthogonal axes, a time-domain sound wave \(x(t)\) breaks into complex sinusoidal components \(e^{j\Omega t}\). The Continuous-Time Fourier Transform (CTFT) computes the inner product of \(x(t)\) against every basis frequency \(\Omega\); the inverse transform sums those weighted tones back into the exact waveform.&lt;/p&gt;

&lt;h3 id=&quot;2-why-complex-exponentials-eigenfunctions-of-lti-systems&quot;&gt;2. Why Complex Exponentials? Eigenfunctions of LTI Systems&lt;/h3&gt;
&lt;p&gt;If you feed \(e^{j\Omega t}\) into any Linear Time-Invariant (LTI) filter (a room, a loudspeaker, an equalizer), the output is simply a scaled and phase-shifted version of the &lt;strong&gt;exact same frequency&lt;/strong&gt;: \(H(j\Omega)e^{j\Omega t}\). No new frequencies are born. Convolution in time turns into plain multiplication in frequency—the mathematical foundation of every spectral noise suppressor.&lt;/p&gt;

&lt;h3 id=&quot;3-magnitude-and-phase--two-halves-of-sound&quot;&gt;3. Magnitude and Phase — Two Halves of Sound&lt;/h3&gt;
&lt;p&gt;Every Fourier coefficient \(X(j\Omega) = \vert X(j\Omega)\vert e^{j\phi(\Omega)}\) carries &lt;strong&gt;magnitude&lt;/strong&gt; (how much energy lives at that pitch—vowels, formants, hiss) and &lt;strong&gt;phase&lt;/strong&gt; (exact timing alignment of waves—attacks, pitch fine structure). Plotting only magnitude spectrograms tricks beginners into ignoring phase, yet preserving or filtering complex spectra (as DeepFilterNet does) is essential for natural-sounding speech.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Explain frequency as rate of oscillation and as a coordinate in a signal basis.&lt;/li&gt;
  &lt;li&gt;State the forward and inverse continuous-time Fourier transform (CTFT) and the analysis/synthesis story.&lt;/li&gt;
  &lt;li&gt;Use linearity, shift, and differentiation/integration properties at an operational level.&lt;/li&gt;
  &lt;li&gt;Connect magnitude and phase spectra to audible percepts at a high level.&lt;/li&gt;
  &lt;li&gt;Explain why speech and noise often separate more cleanly in frequency than in time — and when that intuition fails.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–8&lt;/td&gt;
      &lt;td&gt;Hook: same waveform, time vs frequency pictures; why VoIP stacks are spectral&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;8–20&lt;/td&gt;
      &lt;td&gt;Sinusoids, Euler, LTI eigenfunction intuition&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;20–35&lt;/td&gt;
      &lt;td&gt;CTFT pair; magnitude/phase; linearity &amp;amp; shift worked examples&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;35–48&lt;/td&gt;
      &lt;td&gt;Speech formants vs noise floors; phase myths; DeepFilterNet motivation pointer&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;48–60&lt;/td&gt;
      &lt;td&gt;Pitfalls, mini exercises, preview of sampling&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;frequency-is-a-coordinate-system&quot;&gt;Frequency is a coordinate system&lt;/h3&gt;

&lt;p&gt;A complex sinusoid \(e^{j\Omega t}\) oscillates at radian frequency \(\Omega\) rad/s (\(f=\Omega/(2\pi)\) Hz). Real audio is real-valued, so we often write cosines and sines; complex exponentials are preferred in analysis because they are &lt;strong&gt;eigenfunctions of LTI systems&lt;/strong&gt;: if input \(e^{j\Omega t}\) enters a stable LTI filter with frequency response \(H(j\Omega)\), the output is \(H(j\Omega)e^{j\Omega t}\). No new frequencies appear.&lt;/p&gt;

&lt;p&gt;That is the deep reason frequency-domain NS is attractive: under additivity and approximate short-time LTI behavior, you can attenuate “noise bins” and pass “speech bins.” Reality is messier (non-stationary noise, mask errors, phase), but the eigenfunction picture explains the architecture of almost every classical NS block and of STFT-domain neural SE.&lt;/p&gt;

&lt;h3 id=&quot;continuous-time-fourier-transform&quot;&gt;Continuous-time Fourier transform&lt;/h3&gt;

&lt;p&gt;For a suitable continuous signal \(x(t)\),&lt;/p&gt;

\[X(j\Omega) = \int_{-\infty}^{\infty} x(t)\,e^{-j\Omega t}\,\mathrm{d}t\]

\[x(t) = \frac{1}{2\pi}\int_{-\infty}^{\infty} X(j\Omega)\,e^{j\Omega t}\,\mathrm{d}\Omega\]

&lt;p&gt;&lt;strong&gt;Analysis&lt;/strong&gt; (\(x\to X\)): measure how much of each frequency is present. &lt;strong&gt;Synthesis&lt;/strong&gt; (\(X\to x\)): rebuild the waveform by integrating complex exponentials.&lt;/p&gt;

&lt;p&gt;Polar form \(X(j\Omega)=\vert X(j\Omega)\vert e^{j\phi(\Omega)}\) with \(\phi=\arg X\):&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Quantity&lt;/th&gt;
      &lt;th&gt;Rough audible role&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;\(\vert X\vert\)&lt;/td&gt;
      &lt;td&gt;Energy distribution: vowels’ formants, hiss, rumble&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;\(\phi\)&lt;/td&gt;
      &lt;td&gt;Timing structure: attacks, pitch fine structure; careless phase damage → hollowness&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Spectrogram UIs plot magnitudes (often in dB). That trains a bad habit: “phase doesn’t matter.” For synthesis after aggressive masking, phase (or complex spectrum) handling is a first-class design choice — DeepFilterNet’s deep filtering on complex spectra exists partly because magnitude masks alone are limited.&lt;/p&gt;

&lt;h3 id=&quot;properties-you-will-actually-use&quot;&gt;Properties you will actually use&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Linearity.&lt;/strong&gt; \(a x(t)+b y(t) \leftrightarrow a X(j\Omega)+b Y(j\Omega)\). Under \(y=x+n\), spectra add &lt;strong&gt;linearly&lt;/strong&gt;. They do not add in dB. If you average dB magnitudes, you are doing something else.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time shift.&lt;/strong&gt; \(x(t-t_0)\leftrightarrow X(j\Omega)e^{-j\Omega t_0}\). A delay is a phase ramp. Two mics with different delays have different phases even when magnitudes match — relevant when you later read about multi-channel front-ends.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Frequency shift / modulation.&lt;/strong&gt; \(x(t)e^{j\Omega_0 t}\leftrightarrow X(j(\Omega-\Omega_0))\). Useful mental model for heterodyning; also explains why periodic pitch creates harmonic stacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parseval (energy).&lt;/strong&gt; Time energy and frequency energy match up to convention constants. Operational moral: zeroing large spectral regions &lt;em&gt;must&lt;/em&gt; reduce waveform energy — if your “NS” output has the same RMS but “looks cleaner” on a mis-scaled plot, check scaling bugs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Differentiation.&lt;/strong&gt; \(\frac{d}{dt}x(t)\leftrightarrow j\Omega X(j\Omega)\). High-frequency emphasis; related to why derivatives/pre-emphasis appear in speech features historically.&lt;/p&gt;

&lt;h3 id=&quot;speech-vs-noise-in-frequency-cartoon-physics&quot;&gt;Speech vs noise in frequency (cartoon physics)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Voiced speech.&lt;/strong&gt; Quasi-periodic glottal excitation with fundamental \(f_0\) (say 80–250 Hz for many adults) produces harmonics at \(kf_0\). The vocal tract filters them into &lt;strong&gt;formants&lt;/strong&gt; (broad peaks). On a spectrogram: horizontal striations (harmonics) and darker blobs (formants) that move with phonemes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unvoiced speech.&lt;/strong&gt; Noise-like excitation (fricatives) shaped by the tract — energy often high-frequency. Over-suppressing highs destroys intelligibility (s, f, t).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stationary noise.&lt;/strong&gt; HVAC: low-frequency ridge. Fan hiss: flatter floor. Classical estimators shine here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-stationary / babble.&lt;/strong&gt; Energy comes and goes in speech-like patterns; frequency separation alone is insufficient — you need temporal models (RNN/TCN/attention over frames) as in modern SE.&lt;/p&gt;

&lt;h3 id=&quot;bridge-to-the-rest-of-chapter-01&quot;&gt;Bridge to the rest of Chapter 01&lt;/h3&gt;

&lt;p&gt;Microphones give samples. Continuous integrals become DTFT/DFT/FFT on windows. If you keep one sentence from this lesson, keep this: &lt;strong&gt;frequency is a basis coefficient; STFT bins are local, windowed estimates of those coefficients.&lt;/strong&gt; Lesson 01-02 adds sampling; 01-03–01-05 make the discrete transforms precise; 01-06 puts FFTs on the audio thread.&lt;/p&gt;

&lt;h2 id=&quot;worked-examples&quot;&gt;Worked examples&lt;/h2&gt;

&lt;h3 id=&quot;two-tones-and-a-low-pass&quot;&gt;Two tones and a low-pass&lt;/h3&gt;

&lt;p&gt;Let \(x(t)=\cos(2\pi\cdot 440\,t)+0.3\cos(2\pi\cdot 880\,t)\). Euler’s identity is the derivation, not a slogan:&lt;/p&gt;

\[\cos\theta=\frac{e^{j\theta}+e^{-j\theta}}{2}.\]

&lt;p&gt;So the 440 Hz cosine is a pair of lines at \(\pm 440\,\mathrm{Hz}\), each with complex amplitude \(1/2\), and the 880 Hz cosine is a pair at \(\pm 880\,\mathrm{Hz}\) with amplitude \(0.3/2=0.15\). A low-pass at 600 Hz removes the octave partial and dulls brightness. NS that blindly low-passes “to remove hiss” makes the same mistake on fricatives. On a 48 kHz full-band path (the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; default) those fricatives are allowed to live well above 8 kHz; a continuous-frequency picture that stops at telephony bandwidth will not match what the product mic can capture.&lt;/p&gt;

&lt;h3 id=&quot;phase-ramp-from-delay&quot;&gt;Phase ramp from delay&lt;/h3&gt;

&lt;p&gt;Delay \(t_0=5\,\mathrm{ms}\). At \(f=1\,\mathrm{kHz}\), phase shift is \(-2\pi f t_0 = -10\pi\) radians \(= -5\) turns — i.e. \(0\) mod \(2\pi\) (or compare \(t_0 = 5.5\,\mathrm{ms}\), which gives \(-11\pi \equiv -\pi\) after wrapping to \((-\pi,\pi]\)). Magnitude is unchanged. If you estimate magnitude masks from one alignment and apply them to a differently delayed buffer, reconstruction suffers.&lt;/p&gt;

&lt;h3 id=&quot;db-addition-mistake&quot;&gt;dB addition mistake&lt;/h3&gt;

&lt;p&gt;Speech bin magnitude 0.10, noise 0.10 (linear). Sum 0.20 if &lt;strong&gt;coherent&lt;/strong&gt; same-phase (worst-case cartoon), or power sum \(\sqrt{0.01+0.01}\approx0.141\) for random-phase intuition in bins. In dB: \(20\log_{10}0.1=-20\,\mathrm{dB}\). You cannot say “−20 dB + −20 dB = −40 dB” for the mixture.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-why-spectral-filtering-worksand-where-it-breaks&quot;&gt;Explanation: Why Spectral Filtering Works—and Where It Breaks&lt;/h3&gt;

&lt;h4 id=&quot;step-1-complex-exponentials-turn-convolution-into-pointwise-multiplication&quot;&gt;Step 1: Complex exponentials turn convolution into pointwise multiplication&lt;/h4&gt;
&lt;p&gt;Suppose an LTI system has impulse response \(h(t)\). Feed in \(e^{j\Omega t}\):
\((h * e^{j\Omega\cdot})(t) = \int_{-\infty}^{\infty} h(\tau)\,e^{j\Omega(t-\tau)}\,\mathrm{d}\tau = e^{j\Omega t}\underbrace{\int_{-\infty}^{\infty} h(\tau)\,e^{-j\Omega\tau}\,\mathrm{d}\tau}_{H(j\Omega)}.\)
Every frequency component scales independently by \(H(j\Omega)\) without leaking into neighboring frequencies!&lt;/p&gt;

&lt;h4 id=&quot;step-2-why-noisy-speech-is-still-a-complex-sum-in-each-bin&quot;&gt;Step 2: Why noisy speech is still a complex sum in each bin&lt;/h4&gt;
&lt;p&gt;In an additive mixture \(Y(j\Omega) = X(j\Omega) + N(j\Omega)\), each frequency bin is a &lt;strong&gt;2D vector in the complex plane&lt;/strong&gt; (magnitude + phase). Even if you know the exact clean magnitude \(\vert X\vert\), reusing the noisy phase \(\arg Y\) leaves a phase error whenever noise is strong (\(\mathrm{SNR} \le 0\,\mathrm{dB}\)), producing a characteristic “rough” or “hollow” timbre.&lt;/p&gt;

&lt;h4 id=&quot;step-3-why-timefrequency-localization-is-needed-next&quot;&gt;Step 3: Why time–frequency localization is needed next&lt;/h4&gt;
&lt;p&gt;The CTFT integrates from \(t = -\infty\) to \(+\infty\), telling you &lt;em&gt;which&lt;/em&gt; frequencies occurred over all of history, never &lt;em&gt;when&lt;/em&gt; a consonant started or stopped. To enhance live speech, we must sample the signal (Lesson 01-02) and chop it into short moving windows (STFT, Chapter 02).&lt;/p&gt;

&lt;p&gt;Summary of the Fourier intuition chain:&lt;/p&gt;

\[x(t)
\;\xrightarrow{\text{CTFT}}\;
X(j\Omega) = \vert X(j\Omega)\vert e^{j\phi(\Omega)}
\;\xrightarrow{\text{LTI filter}}\;
H(j\Omega)X(j\Omega)
\;\xrightarrow{\text{Next: Sampling + STFT}}\;
\text{Real-time spectral NS}.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Treating spectrogram magnitude as the whole story; ignoring phase/complex filtering.&lt;/li&gt;
  &lt;li&gt;Adding dB values as if they were linear amplitudes.&lt;/li&gt;
  &lt;li&gt;Confusing \(\Omega\) (rad/s) with \(f\) (Hz): \(\Omega=2\pi f\).&lt;/li&gt;
  &lt;li&gt;Assuming “more frequency resolution is always better” without latency cost (later lessons).&lt;/li&gt;
  &lt;li&gt;Expecting CTFT symbols to appear in code — production uses FFT windows.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Synthesize one second of 200 Hz + 600 Hz + 1000 Hz at 8 kHz and read the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; peak bins. With \(N=f_s\), bin index equals frequency in Hz.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8000&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;600&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rfft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;argsort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:])&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[200, 600, 1000]&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[4000.0, 4000.0, 4000.0]&lt;/code&gt;. Each unit-amplitude sine, held for an integer number of cycles, lands on one positive bin with magnitude \(N/2=4000\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;np.fft.fft&lt;/code&gt; and reporting a negative-frequency index as a second peak. Choosing \(N\) not divisible by the periods, then watching the peak smear off the integer bin. Reading the magnitude as the cosine’s \(1/2\) coefficient from the worked example — a sine’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rfft&lt;/code&gt; scaling is \(N/2\), not \(1/2\).&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Write \(\sin(\Omega t)\) as complex exponentials via Euler’s formula.&lt;/li&gt;
  &lt;li&gt;Delay 2 ms: phase shift at 500 Hz and at 2 kHz (before wrapping).&lt;/li&gt;
  &lt;li&gt;Sketch cartoon spectra: voiced vowel, white noise, keyboard click, babble.&lt;/li&gt;
  &lt;li&gt;In one paragraph, why are complex exponentials preferred when analyzing LTI filters?&lt;/li&gt;
  &lt;li&gt;Give one case where time-domain methods might beat naive spectral subtraction (hint: impulsive clicks).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(\sin\theta=(e^{j\theta}-e^{-j\theta})/(2j)\). Two lines, opposite sign, factor \(1/(2j)\).&lt;/li&gt;
  &lt;li&gt;\(\Delta\phi=-2\pi f t_0\). At 500 Hz and 2 ms: \(-2\pi\cdot 0.5\cdot 2=-2\pi\) radians (one full turn). At 2 kHz: \(-8\pi\) radians, four turns. Magnitude is unchanged.&lt;/li&gt;
  &lt;li&gt;Vowel: harmonic stack plus formant blobs. White noise: flat. Click: broadband spike. Babble: a second, messier harmonic stack.&lt;/li&gt;
  &lt;li&gt;An LTI filter multiplies \(e^{j\Omega t}\) by \(H(j\Omega)\) and creates no new frequencies. A cosine splits into two such eigenfunctions.&lt;/li&gt;
  &lt;li&gt;A single-sample click is already spread across every bin. A short time-domain gate can catch it; a slow noise-floor tracker cannot.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Alan V. Oppenheim &amp;amp; Ronald W. Schafer, &lt;em&gt;Discrete-Time Signal Processing&lt;/em&gt; — Fourier transform overview chapters (any recent edition).&lt;/li&gt;
  &lt;li&gt;Julius O. Smith, &lt;em&gt;Mathematics of the DFT&lt;/em&gt;, https://ccrma.stanford.edu/~jos/mdft/ — sinusoids as a basis, before any STFT code.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588) — skim that enhancement runs in an STFT / deep-filtering domain. Motivation only in this lesson.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=spUNpyF58BY&quot;&gt;But what is the Fourier Transform?  A visual introduction.&lt;/a&gt; — 3Blue1Brown, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the winding picture before the integral: each frequency is a coordinate, which is the intuition this lesson writes as a transform.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=MBnnXbOM5S4&quot;&gt;The more general uncertainty principle, regarding Fourier transforms&lt;/a&gt; — 3Blue1Brown, English. The sound-wave section is the time-versus-frequency tradeoff the lesson needs before any window length is chosen.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>00-04 Course map and Mezon product context</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter00/00_04_course_map_mezon/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter00/00_04_course_map_mezon</id>
   <content type="html">&lt;p&gt;Installing an npm package and wiring &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await filter.process(audioFrame)&lt;/code&gt; into a voice call takes ten minutes. Debugging why that exact call develops a metallic 100 Hz warble on MacBooks, or why your p95 latency spikes after twenty minutes in a Chrome tab, takes real signal-processing literacy.&lt;/p&gt;

&lt;p&gt;This lesson is your &lt;strong&gt;map and contract&lt;/strong&gt; for the entire course: how Chapters 00 through 10 build systematically from Fourier mathematics to a Mezon-aligned real-time capstone, what the public product surface exposes, and how to diagnose production audio bugs by tracing them back to the exact mathematical layer where they originate.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/livekit-trackprocessor.png&quot; alt=&quot;A LiveKit track processor drawn as the public slot where a noise filter can sit&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The drawing is only the public integration slot: a TrackProcessor on a media track. It does not reveal private Mezon internals.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (three-layer architecture of a voice NS product, techniques vs. wrappers, systematic bug triage) → Full 11-chapter map &amp;amp; recommended study tracks → Public Mezon product surface → Worked example: diagnosing a 10 ms (100 Hz) robotic warble back to the right chapter → Explanation: 3-step engineering triage loop for audio pipelines → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-the-three-layer-stack-behind-every-real-time-noise-suppressor&quot;&gt;Key ideas: The Three-Layer Stack Behind Every Real-Time Noise Suppressor&lt;/h2&gt;

&lt;h3 id=&quot;1-layer-1--discrete-signal--stft-foundations-chapters-0102&quot;&gt;1. Layer 1 — Discrete Signal &amp;amp; STFT Foundations (Chapters 01–02)&lt;/h3&gt;
&lt;p&gt;Before any machine learning runs, raw microphone PCM is resampled to a fixed clock (e.g., 48 kHz), sliced into overlapping windows, transformed by an FFT, and later reassembled via Overlap-Add (OLA). Most “mysterious model bugs” (clicks, pitch shifts, metallic modulation) actually happen right here—in wrong hop sizes, broken COLA window sums, or un-filtered resampling.&lt;/p&gt;

&lt;h3 id=&quot;2-layer-2--classical-priors--neural-enhancement-chapters-0304&quot;&gt;2. Layer 2 — Classical Priors &amp;amp; Neural Enhancement (Chapters 03–04)&lt;/h3&gt;
&lt;p&gt;Classical estimators (spectral subtraction, Wiener filtering, Kalman tracking, AEC/beamforming) establish the statistical priors that modern neural suppressors like &lt;strong&gt;DeepFilterNet&lt;/strong&gt; still inherit: separating broadband envelope gains (ERB bands) from fine complex harmonic filtering.&lt;/p&gt;

&lt;h3 id=&quot;3-layer-3--real-time-runtime-product-integration-and-evaluation-chapters-0509&quot;&gt;3. Layer 3 — Real-Time Runtime, Product Integration, and Evaluation (Chapters 05–09)&lt;/h3&gt;
&lt;p&gt;Turning a trained checkpoint into a shippable feature requires ring buffers, AudioWorklet/WASM or ONNX/Rust execution, LiveKit/WebRTC TrackProcessor integration, and rigorous evaluation (SI-SDR, DNSMOS, and listening tests) so you know quality truly improved.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Navigate the chapter map from DSP → classical NS → DeepFilterNet → realtime/on-device → product → eval → capstone.&lt;/li&gt;
  &lt;li&gt;Describe the mezon-noise-suppression stack at a &lt;strong&gt;high level&lt;/strong&gt; using only public information.&lt;/li&gt;
  &lt;li&gt;State the pedagogical contract: teach techniques; npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; is a &lt;em&gt;surface&lt;/em&gt;, not the syllabus.&lt;/li&gt;
  &lt;li&gt;Plan a study path (full vs fast-track) matching your background.&lt;/li&gt;
  &lt;li&gt;Know where to find advisor outline and contribution rules.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–15&lt;/td&gt;
      &lt;td&gt;Walk COURSE_OUTLINE.md chapter table; mark prerequisites&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;15–30&lt;/td&gt;
      &lt;td&gt;Product context: GitHub / npm / local instructor path; do’s and don’ts&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;30–45&lt;/td&gt;
      &lt;td&gt;Capstone preview (Ch. 09) and evaluation mindset (Ch. 08)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;45–55&lt;/td&gt;
      &lt;td&gt;Personal study plan worksheet&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;55–60&lt;/td&gt;
      &lt;td&gt;Mini exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;chapter-map-0010&quot;&gt;Chapter map (00–10)&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Ch&lt;/th&gt;
      &lt;th&gt;Theme&lt;/th&gt;
      &lt;th&gt;Why it exists&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;00&lt;/td&gt;
      &lt;td&gt;Problem framing&lt;/td&gt;
      &lt;td&gt;Shared vocabulary, Mezon context&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;01&lt;/td&gt;
      &lt;td&gt;Fourier &amp;amp; discrete transforms (&lt;strong&gt;deep&lt;/strong&gt;)&lt;/td&gt;
      &lt;td&gt;STFT/FFT literacy for engineers&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;02&lt;/td&gt;
      &lt;td&gt;Audio processing pipeline&lt;/td&gt;
      &lt;td&gt;PCM → frames → STFT → latency tradeoffs&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;03&lt;/td&gt;
      &lt;td&gt;Classical NS / AEC / beamforming&lt;/td&gt;
      &lt;td&gt;Priors DeepFilterNet still sits on&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;04&lt;/td&gt;
      &lt;td&gt;Neural SE &amp;amp; DeepFilterNet family&lt;/td&gt;
      &lt;td&gt;Core model ideas and successors survey&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;05&lt;/td&gt;
      &lt;td&gt;Real-time constraints&lt;/td&gt;
      &lt;td&gt;RTF, AudioWorklet, ring buffers, state&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;06&lt;/td&gt;
      &lt;td&gt;On-device inference&lt;/td&gt;
      &lt;td&gt;ONNX / tract, quantization, WASM/SIMD&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;07&lt;/td&gt;
      &lt;td&gt;Product integration&lt;/td&gt;
      &lt;td&gt;WebRTC, LiveKit, CDN models, npm surface&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;08&lt;/td&gt;
      &lt;td&gt;Evaluation&lt;/td&gt;
      &lt;td&gt;SI-SDR, DNSMOS, listening, DNS metrics&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;09&lt;/td&gt;
      &lt;td&gt;Capstone: Mezon NS&lt;/td&gt;
      &lt;td&gt;Techniques demonstrated end-to-end&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;10&lt;/td&gt;
      &lt;td&gt;References &amp;amp; further paths&lt;/td&gt;
      &lt;td&gt;Curated reading only&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Chapters &lt;strong&gt;01&lt;/strong&gt; and &lt;strong&gt;02&lt;/strong&gt; are first-class modules (seven lessons each), not a DSP “appendix.” If you skim them, later debugging will feel like superstition.&lt;/p&gt;

&lt;h3 id=&quot;recommended-paths&quot;&gt;Recommended paths&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Full path (engineers new to DSP):&lt;/strong&gt; 00 → 01 → 02 → 03 → 04 → 05 → 06 → 07 → 08 → 09.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fast path (strong DSP, new to neural SE):&lt;/strong&gt; 00 → skim 01–02 checklists → 04 → 05–07 → 08 → 09.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Product integration focus:&lt;/strong&gt; 00, 02-07, 05, 06, 07, 08, 09 — but still read 01-07 pitfalls.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;mezon-product-context-public&quot;&gt;Mezon product context (public)&lt;/h3&gt;

&lt;p&gt;Aligned artifacts named in this course:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Repository: https://github.com/mezonai/mezon-noise-suppression (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;npm package: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; &lt;strong&gt;1.3.0&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Public classes named on that surface: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Public control: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Product default rate: &lt;strong&gt;48 kHz full-band&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Instructor local path (optional): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Rules of engagement&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Do &lt;strong&gt;not&lt;/strong&gt; modify the product repository from course tasks.&lt;/li&gt;
  &lt;li&gt;Do &lt;strong&gt;not&lt;/strong&gt; invent unpublished architecture claims; cite public README / npm docs / papers.&lt;/li&gt;
  &lt;li&gt;Capstone should show you can explain STFT framing, model placement, latency, and evaluation — optionally using the public package as an integration target.&lt;/li&gt;
  &lt;li&gt;Optional Rust native (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df-core&lt;/code&gt;) paths are stretch goals (Ch. 09).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;what-techniques-not-wrapper-means&quot;&gt;What “techniques not wrapper” means&lt;/h3&gt;

&lt;p&gt;Being able to write:&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// illustrative — check current npm API before shipping&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;audioFrame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;is useful and insufficient. You should also be able to answer:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;What hop / window / sample rate does the pipeline assume?&lt;/li&gt;
  &lt;li&gt;Where does algorithmic latency come from?&lt;/li&gt;
  &lt;li&gt;What happens on stereo input?&lt;/li&gt;
  &lt;li&gt;How do you know quality improved beyond “sounds nicer today”?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those answers live in Chapters 01–02, 04–08 — not in autocomplete.&lt;/p&gt;

&lt;p&gt;Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel&lt;/code&gt; is a one-line product control. Explaining it is a chapter-map question: the integer chooses an operating point on a trained gain or mask (Ch. 03–04), the 48 kHz default fixes Nyquist and hop arithmetic (Ch. 01–02), and the processor still has to finish inside the audio callback (Ch. 05). The LiveKit figure above is a preview of where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt; can sit on a track (Ch. 07). Nothing in that drawing authorizes a guess about unpublished buffers inside the instructor tree.&lt;/p&gt;

&lt;h3 id=&quot;how-this-site-is-organized&quot;&gt;How this site is organized&lt;/h3&gt;

&lt;p&gt;Lessons live under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;contents/{en,vi}/chapterXX/_posts/&lt;/code&gt; with YAML front matter (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chapter&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;order&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lang&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;draft: false&lt;/code&gt;). English and Vietnamese are parallel; study in either language, but keep terminology consistent (STFT, hop, RTF, SI-SDR are shared).&lt;/p&gt;

&lt;h2 id=&quot;worked-example--mapping-a-bug-to-a-chapter&quot;&gt;Worked example — mapping a bug to a chapter&lt;/h2&gt;

&lt;p&gt;Symptom: “NS output has robotic warble every 10 ms.”&lt;/p&gt;

&lt;p&gt;Possible chapter triage:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;02&lt;/strong&gt; — hop/window/OLA mismatch or wrong ISTFT COLA.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;01&lt;/strong&gt; — interpreting FFT bins incorrectly after resampling.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;05&lt;/strong&gt; — underruns causing repeated frames.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;04&lt;/strong&gt; — over-aggressive periodic masking (model) — &lt;em&gt;last&lt;/em&gt;, after pipeline hygiene.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This triage habit is the point of the course map. A 10 ms warble is \(100\,\mathrm{Hz}\) because \(1/0.010=100\). That number points at hop-rate amplitude modulation (Ch. 02) before it points at a bad checkpoint (Ch. 04). The mini-lab turns the same arithmetic into a pass/fail on p95 processing time.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-how-experienced-audio-engineers-triage-a-broken-pipeline&quot;&gt;Explanation: How Experienced Audio Engineers Triage a Broken Pipeline&lt;/h3&gt;

&lt;h4 id=&quot;step-1-turn-every-audible-symptom-into-a-frequency-or-time-period&quot;&gt;Step 1: Turn every audible symptom into a frequency or time period&lt;/h4&gt;
&lt;p&gt;Never stop at “it sounds robotic.” Measure the period of the artifact: a periodic buzz every \(10\,\mathrm{ms}\) is a \(1/0.010 = 100\,\mathrm{Hz}\) modulation—which immediately matches a \(480\)-sample hop at \(48\,\mathrm{kHz}\). A pitch drop of \(3\times\) immediately screams “48 kHz PCM fed into a 16 kHz consumer.”&lt;/p&gt;

&lt;h4 id=&quot;step-2-bypass-the-neural-model-first-identity--pass-through-test&quot;&gt;Step 2: Bypass the neural model first (Identity / Pass-through test)&lt;/h4&gt;
&lt;p&gt;Replace the neural network with an identity gain (\(G(\ell, k) \equiv 1\)) and run STFT \(\to\) ISTFT on a clean sine wave. If the 100 Hz warble is &lt;em&gt;still there&lt;/em&gt;, the bug is 100% in framing, COLA windowing, or ring-buffer underruns (Chapters 01, 02, 05)—not in the model weights!&lt;/p&gt;

&lt;h4 id=&quot;step-3-gate-changes-with-objective--listening-checks&quot;&gt;Step 3: Gate changes with objective + listening checks&lt;/h4&gt;
&lt;p&gt;Once pass-through reconstruction is bit-clean (\(\text{error} &amp;lt; 10^{-6}\)), re-enable the suppressor and verify both tail compute (\(\text{p95 } T_{\mathrm{proc}} &amp;lt; T_{\mathrm{hop}}\)) and perceptual metrics (Ch. 08) before merging.&lt;/p&gt;

&lt;p&gt;Summary of the audio debugging loop:&lt;/p&gt;

\[\text{Audible symptom}
\;\xrightarrow{f = 1/T}\;
\text{Bypass model (STFT}\to\text{ISTFT)}
\;\xrightarrow{\text{Isolate layer}}\;
\text{Fix Ch. 01/02/05 before Ch. 04}.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Jumping to Ch. 04 weights before securing sample-rate and mono downmix correctness.&lt;/li&gt;
  &lt;li&gt;Treating the npm package name as proof of a particular unpublished model graph.&lt;/li&gt;
  &lt;li&gt;Studying only EN or only VI and missing fixes in one locale (contribute both when you improve a lesson).&lt;/li&gt;
  &lt;li&gt;Skipping Ch. 08 and declaring victory from one café demo.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Tie the “warble every 10 ms” bug to a hop at the 48 kHz product default, and gate it on p95 processing time.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;480&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;warble_hz&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hop_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; warble_if_cola_fails_hz=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warble_hz&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p95_ms&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;6.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;12.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p95_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p95_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hop_ms=10.0 warble_if_cola_fails_hz=100&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.0 True&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;12.0 False&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Blaming &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNet3Core&lt;/code&gt; before measuring the hop. Treating a 12 ms p95 as acceptable because the mean was 4 ms. Reading the LiveKit diagram as a private architecture spec.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Write your background (DSP: none/some/strong; WebAudio: none/some) and choose full vs fast path.&lt;/li&gt;
  &lt;li&gt;From COURSE_OUTLINE.md, list the seven EN lesson titles in Chapter 01.&lt;/li&gt;
  &lt;li&gt;Name three public sources you are allowed to cite for DeepFilterNet behavior.&lt;/li&gt;
  &lt;li&gt;Draft one capstone success criterion that is &lt;em&gt;measurable&lt;/em&gt; (e.g. “p95 RTF ≤ 0.5 on machine X at 48 kHz mono”).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;No DSP and no WebAudio means the full path. Strong DSP and new neural SE means the fast path, including the 01-07 checklist rather than a total skip.&lt;/li&gt;
  &lt;li&gt;The seven titles are the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;title:&lt;/code&gt; fields of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;contents/en/chapter01/_posts/&lt;/code&gt;, orders 1 through 7, from continuous Fourier intuition through the pitfalls checklist.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet arXiv:2110.05588, DeepFilterNet2 arXiv:2205.05474, DeepFilterNet3 arXiv:2305.08227, plus the public README at https://github.com/mezonai/mezon-noise-suppression. The reference implementation is https://github.com/Rikorose/DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;Name the machine, the rate (48 kHz full-band if you mean the product default), mono or the downmix rule, and a tail statistic such as p95 RTF. “Sounds cleaner” is not the criterion.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;This repo: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COURSE_OUTLINE.md&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AGENTS.md&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;README.md&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Public GitHub README: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;npm landing page: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588), DeepFilterNet2 (arXiv:2205.05474), DeepFilterNet3 (arXiv:2305.08227) for algorithmic context, not Mezon-specific claims.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=spUNpyF58BY&quot;&gt;But what is the Fourier Transform?  A visual introduction.&lt;/a&gt; — 3Blue1Brown, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Start here for the frequency-domain picture the map’s early chapters formalize before any suppressor appears.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. This is the neural destination of the map: STFT in, real-time full-band enhancement out.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. Watch the path from open datasets to a shipped calling feature; later chapters follow that evaluation loop.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>00-03 Real-time vs offline enhancement</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter00/00_03_realtime_vs_offline/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter00/00_03_realtime_vs_offline</id>
   <content type="html">&lt;p&gt;A neural speech enhancer can win a benchmark by 2 dB, run smoothly in a Jupyter notebook on a 10-second WAV file, and still shatter into robotic clicks the instant you put it on a live WebRTC call. Why? Because &lt;strong&gt;shipping noise suppression is less about peak leaderboard MOS and more about surviving the audio thread&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;On a live audio thread, time is a hard wall: the OS hands you a tiny block of samples every few milliseconds, and if your code is even 1 millisecond late, the speaker plays silence or garbage. This lesson defines latency and RTF rigorously, explains causal streaming state, and walks through the exact failure modes you will debug in Mezon-like integrations.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/realtime-vs-offline.png&quot; alt=&quot;The same suppressor drawn as an offline batch job and as a causal streaming block&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. Offline look-ahead and a streaming hop are different delays: the picture is the split you have to budget, not a second algorithm.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (three latency layers, RTF vs. tail latency, causal stateful filtering) → Causal vs. offline comparison &amp;amp; streaming failure modes → Worked examples: 10 ms hop RTF spike (mean 0.312 hiding a 1.50 underrun!), 128-sample WebAudio quantum mismatch, and a ship/no-ship model audit → Explanation: 3 steps explaining why mean RTF lies on real-time audio threads → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-real-time-signal-processing-and-streaming-systems&quot;&gt;Key ideas: Real-Time Signal Processing and Streaming Systems&lt;/h2&gt;

&lt;h3 id=&quot;1-three-distinct-layers-of-latency&quot;&gt;1. Three Distinct Layers of Latency&lt;/h3&gt;
&lt;p&gt;“Latency” is not a single number—it is the sum of three independent clocks:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Buffering latency:&lt;/strong&gt; waiting for enough fresh samples to fill an analysis window or hop.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic latency:&lt;/strong&gt; built-in delay from future look-ahead frames, filter group delay, or overlap-add synthesis.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;System latency:&lt;/strong&gt; OS audio callback quanta (e.g., 128 samples in browser AudioWorklet), JS/Wasm marshalling, and network jitter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-real-time-factor-rtf-vs-tail-latency-p95--p99&quot;&gt;2. Real-Time Factor (RTF) vs. Tail Latency (p95 / p99)&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;Real-Time Factor&lt;/strong&gt; \(\mathrm{RTF} = T_{\mathrm{proc}} / T_{\mathrm{audio}}\) measures compute load relative to wall-clock audio time. While offline batch jobs only care about average throughput, a streaming audio thread is a &lt;strong&gt;hard real-time deadline&lt;/strong&gt;: one single slow frame (caused by garbage collection, OS preemption, or CPU thermal throttling) causes an &lt;strong&gt;underrun&lt;/strong&gt; even when the average RTF looks comfortable.&lt;/p&gt;

&lt;h3 id=&quot;3-stateful-causal-processing&quot;&gt;3. Stateful Causal Processing&lt;/h3&gt;
&lt;p&gt;Offline models can run bidirectional RNNs or full-utterance attention over the entire recording. A causal streaming suppressor processes one hop at a time and must carry &lt;strong&gt;persistent state&lt;/strong&gt; across callbacks: overlap-add tail buffers, running noise-floor trackers, and recurrent/convolutional hidden states. Dropping or resetting that state creates audible clicks and pumping.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Define algorithmic latency, buffering latency, and real-time factor (RTF).&lt;/li&gt;
  &lt;li&gt;Explain causal / streaming constraints versus offline look-ahead.&lt;/li&gt;
  &lt;li&gt;Relate frame size, hop size, and end-to-end delay budgets for calls.&lt;/li&gt;
  &lt;li&gt;List failure modes: underruns, choppy audio, clock drift, state discontinuities.&lt;/li&gt;
  &lt;li&gt;Apply “worst-case RTF on target devices” thinking to model choice.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–12&lt;/td&gt;
      &lt;td&gt;Definitions: latency types + RTF with numerical drills&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;12–28&lt;/td&gt;
      &lt;td&gt;Causal STFT pipelines; why offline SOTA fails WebRTC/LiveKit paths&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;28–42&lt;/td&gt;
      &lt;td&gt;Streaming state: OLA continuity, RNN/DF hidden state&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;42–52&lt;/td&gt;
      &lt;td&gt;Failure modes and product SLA checklist&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;52–60&lt;/td&gt;
      &lt;td&gt;Mini exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;three-latency-concepts&quot;&gt;Three latency concepts&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Buffering latency&lt;/strong&gt; — time spent collecting samples before a frame can be processed (related to window length and hop).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic latency&lt;/strong&gt; — delay inherent in the algorithm (look-ahead frames, filter group delay, overlap-add reconstruction delay).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;System latency&lt;/strong&gt; — OS/audio callback quantum, JS/Wasm bridges, network jitter (out of pure DSP scope but kills products).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For interactive voice, total mouth-to-ear delay budgets are often discussed in tens of milliseconds of &lt;em&gt;additional&lt;/em&gt; processing before users notice awkward turn-taking. Exact product budgets vary; the engineering rule is: &lt;strong&gt;measure&lt;/strong&gt; on the real path.&lt;/p&gt;

&lt;h3 id=&quot;real-time-factor&quot;&gt;Real-time factor&lt;/h3&gt;

\[\mathrm{RTF} = \frac{T_{\mathrm{proc}}}{T_{\mathrm{audio}}}\]

&lt;p&gt;If you process 20 ms of audio in 5 ms wall-clock, \(\mathrm{RTF}=0.25\). Streaming systems need &lt;strong&gt;headroom&lt;/strong&gt;: mean RTF of 0.9 still fails when a GC pause or thermal throttle spikes a frame to RTF 2.0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Worked example.&lt;/strong&gt; Hop \(R = 480\) samples at \(f_s = 48\,\mathrm{kHz}\) → \(T_{\mathrm{audio}} = 10\,\mathrm{ms}\). Budget RTF \(\le 0.5\) ⇒ \(T_{\mathrm{proc}} \le 5\,\mathrm{ms}\) for that hop’s STFT + model + ISTFT path (amortized).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A healthy mean can still glitch.&lt;/strong&gt; Suppose 100 hops of 10 ms: 99 of them finish in 3 ms and one finishes in 15 ms. The mean processing time is \((99\times 3+15)/100=3.12\,\mathrm{ms}\), so mean RTF is \(0.312\). The slow hop has RTF \(15/10=1.5\) and misses the callback. Quote p95 or p99 next to the mean, or the average will green-wash an underrun.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quanta are not hops.&lt;/strong&gt; A browser render quantum of 128 samples at 48 kHz lasts \(128/48000\approx 2.67\,\mathrm{ms}\). A 480-sample hop is \(480/128=3.75\) quanta. The processor has to accumulate partial quanta in a ring buffer; it cannot assume the audio callback and the STFT hop are the same object. DeepFilterNet3 (arXiv:2305.08227) is the real-time member of that family; an offline checkpoint with hundreds of milliseconds of look-ahead does not become causal because you wrapped it in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DeepFilterNoiseFilterProcessor&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;causal-vs-offline&quot;&gt;Causal vs offline&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Property&lt;/th&gt;
      &lt;th&gt;Offline&lt;/th&gt;
      &lt;th&gt;Real-time / streaming&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Future frames&lt;/td&gt;
      &lt;td&gt;yes&lt;/td&gt;
      &lt;td&gt;no (or tiny look-ahead)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Bidirectional recurrent / attention over whole file&lt;/td&gt;
      &lt;td&gt;common&lt;/td&gt;
      &lt;td&gt;restricted / chunked&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Batch size&lt;/td&gt;
      &lt;td&gt;large&lt;/td&gt;
      &lt;td&gt;1 frame / small chunk&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Metric shopping&lt;/td&gt;
      &lt;td&gt;easy&lt;/td&gt;
      &lt;td&gt;must include latency + device RTF&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;DeepFilterNet2/3 literature emphasizes &lt;strong&gt;real-time / causal&lt;/strong&gt; design choices (see papers’ real-time sections). That is why this course anchors on the DeepFilterNet family rather than only offline diffusion SE models.&lt;/p&gt;

&lt;h3 id=&quot;frames-hops-and-delay&quot;&gt;Frames, hops, and delay&lt;/h3&gt;

&lt;p&gt;For window length \(L\) samples and hop \(R\) samples:&lt;/p&gt;

\[T_{\mathrm{hop}} = \frac{R}{f_s},\qquad T_{\mathrm{win}} = \frac{L}{f_s}\]

&lt;p&gt;Overlap-add (OLA) reconstruction typically introduces delay on the order of the window / hop structure (exact constant depends on implementation). Reducing \(L\) lowers delay but hurts frequency resolution — Chapter 02 develops this tradeoff.&lt;/p&gt;

&lt;h3 id=&quot;streaming-state&quot;&gt;Streaming state&lt;/h3&gt;

&lt;p&gt;Real-time NS is a &lt;strong&gt;stateful&lt;/strong&gt; filter:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Overlap-add buffers and window leftovers.&lt;/li&gt;
  &lt;li&gt;Noise estimators / VAD state (classical).&lt;/li&gt;
  &lt;li&gt;Recurrent or temporal convolutional state (neural), including DeepFilterNet-style temporal modules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cold-starting state each callback produces clicks and “pumping.” Dumping state across sample-rate changes without reset logic produces mush.&lt;/p&gt;

&lt;h3 id=&quot;failure-modes&quot;&gt;Failure modes&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Underrun / glitch&lt;/strong&gt; — processing exceeds the callback budget; audio drops or repeats.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choppy / watery speech&lt;/strong&gt; — over-aggressive masking, window mismatch, or phase errors.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Drift&lt;/strong&gt; — producer/consumer clock mismatch in ring buffers (Ch. 05).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Tail artifacts&lt;/strong&gt; — state not flushed at end of utterance (offline eval vs call hang-up).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Thermal cliffs&lt;/strong&gt; — RTF fine for 30 s, fails at 30 min on a phone.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;worked-example--can-this-model-ship&quot;&gt;Worked example — can this model ship?&lt;/h2&gt;

&lt;p&gt;Published offline model: look-ahead 300 ms, RTF 0.15 on GPU, RTF 1.2 on target CPU laptop for 48 kHz mono.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Call path budget: \(\le 40\,\mathrm{ms}\) algorithmic look-ahead → &lt;strong&gt;fail&lt;/strong&gt; (300 ms).&lt;/li&gt;
  &lt;li&gt;Even if you chop look-ahead, RTF 1.2 on CPU → &lt;strong&gt;fail&lt;/strong&gt; without downsampling, quantization, or a smaller student model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A DeepFilterNet-class streaming model with small hop and RTF \(\sim 0.2\)–\(0.5\) on target is in the plausible shipping region — validate on &lt;em&gt;your&lt;/em&gt; device, not the paper’s.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-why-streaming-audio-threads-punish-averages&quot;&gt;Explanation: Why Streaming Audio Threads Punish Averages&lt;/h3&gt;

&lt;h4 id=&quot;step-1-decouple-the-os-callback-quantum-from-your-dsp-hop&quot;&gt;Step 1: Decouple the OS callback quantum from your DSP hop&lt;/h4&gt;
&lt;p&gt;The browser AudioWorklet fires every \(128\) samples (\(2.67\,\mathrm{ms}\) at 48 kHz), while your STFT hop might be \(480\) samples (\(10\,\mathrm{ms}\)). Because \(480 / 128 = 3.75\) is not an integer, your DSP loop runs &lt;strong&gt;irregularly&lt;/strong&gt;: three callbacks do almost nothing (just copying into a ring buffer), and the fourth callback triggers the entire STFT + neural forward pass + ISTFT!&lt;/p&gt;

&lt;h4 id=&quot;step-2-budget-for-the-bursty-callback-not-the-amortized-mean&quot;&gt;Step 2: Budget for the bursty callback, not the amortized mean&lt;/h4&gt;
&lt;p&gt;That fourth callback must still finish before the audio buffer drains (plus whatever ring-buffer slack you intentionally paid for in latency). That is why a \(0.312\) mean RTF with a single \(15\,\mathrm{ms}\) spike produces an unmistakable click: audio hardware never waits for slow frames.&lt;/p&gt;

&lt;h4 id=&quot;step-3-preserve-every-byte-of-state-across-hops&quot;&gt;Step 3: Preserve every byte of state across hops&lt;/h4&gt;
&lt;p&gt;Between hop \(\ell\) and hop \(\ell+1\), three memories must stay intact: the input ring buffer, the overlap-add synthesis tail, and the model’s hidden state (GRU/TCN buffers). Any glitch that resets state mid-sentence introduces an artificial transient that sounds like a broken connection.&lt;/p&gt;

&lt;p&gt;Summary of the streaming deadline rule:&lt;/p&gt;

\[\text{Quanta } (128\text{ smp})
\;\xrightarrow{\text{Ring buffer}}\;
\text{Hop } (480\text{ smp})
\;\xrightarrow{\text{Stateful NS}}\;
\text{Ship iff } \text{Look-ahead} \le B_{\mathrm{lat}} \text{ and } \mathrm{RTF}_{p99} &amp;lt; 1.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Quoting paper RTF measured offline with huge batch FFT plans.&lt;/li&gt;
  &lt;li&gt;Ignoring &lt;strong&gt;tail latency&lt;/strong&gt; (p95/p99) under CPU contention.&lt;/li&gt;
  &lt;li&gt;Using non-causal checkpoints “just for demos” then wondering why integration lags.&lt;/li&gt;
  &lt;li&gt;Measuring latency with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Date.now()&lt;/code&gt; across layers full of hidden buffers.&lt;/li&gt;
  &lt;li&gt;Forgetting that browser AudioWorklet quanta (e.g. 128 samples at 48 kHz ≈ 2.67 ms) are not the same as your STFT hop.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Print the 10 ms hop budget at 48 kHz, then show a spiked hop whose mean RTF still looks safe.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;480&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t_audio_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t_proc_max_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t_audio_ms&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mean_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;99&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;quantum_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;t_audio_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t_audio_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; t_proc_max_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t_proc_max_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;mean_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mean_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; mean_rtf=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mean_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t_audio_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;spike_rtf=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t_audio_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;quantum_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;quantum_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; quanta_per_hop=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t_audio_ms=10.0 t_proc_max_ms=5.0&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mean_ms=3.12 mean_rtf=0.312&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;spike_rtf=1.50&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;quantum_ms=2.67 quanta_per_hop=3.75&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Averaging RTF across hops and ignoring the spike. Treating 128 samples as a 10 ms hop. Inverting RTF so a slower machine prints a smaller number.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Hop 256 samples at 16 kHz: hop ms? Max \(T_{\mathrm{proc}}\) for RTF 0.25?&lt;/li&gt;
  &lt;li&gt;List three state tensors/buffers a streaming STFT-NS system must keep between hops.&lt;/li&gt;
  &lt;li&gt;Explain why mean RTF 0.4 can still glitch in Chrome under load.&lt;/li&gt;
  &lt;li&gt;Propose a go/no-go checklist of 5 measurements before enabling NS by default in a call product.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;\(256/16000=16\,\mathrm{ms}\). RTF \(0.25\) allows \(4\,\mathrm{ms}\) of processing.&lt;/li&gt;
  &lt;li&gt;OLA overlap buffer, analysis window state, and the neural or noise-tracker recurrence. Sample-rate and channel count belong in that list too.&lt;/li&gt;
  &lt;li&gt;The mean hides a GC pause, a thermal spike, or one hop that exceeds 16 ms. p99 is the number the callback feels.&lt;/li&gt;
  &lt;li&gt;A usable five: causal look-ahead in ms, p95 RTF on the target CPU, underrun count over a 10-minute call, stereo downmix policy, and a listening check at the product sample rate.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DeepFilterNet2 (arXiv:2205.05474) and DeepFilterNet3 (arXiv:2305.08227) — real-time and causal sections. Code: https://github.com/Rikorose/DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;WebRTC APM processing graph overview (where NS sits among AEC/AGC).&lt;/li&gt;
  &lt;li&gt;MDN AudioWorklet documentation (callback timing constraints).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch the latency and real-time-factor claims next to the two-stage diagram; that is the ship-or-not test this lesson defines.&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. The complexity-versus-quality section shows why an offline score is not a streaming budget.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EeQr0zfvF04&quot;&gt;Sonic Boom! Audio Programming on Android and Chrome (Google I/O’19)&lt;/a&gt; — Google for Developers, English. The callback-latency measurements are the device half of the lesson: algorithmic look-ahead and the audio thread are different clocks.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>00-02 Noise types and speech mixture models</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter00/00_02_noise_types/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter00/00_02_noise_types</id>
   <content type="html">&lt;p&gt;Calling everything that ruins a voice call “noise” is like a doctor calling every illness “fever.” An air-conditioner hum, a clattering coffee cup, a competing talker in the background, and a cavernous echoey hallway obey completely different physics—and break completely different parts of a suppressor.&lt;/p&gt;

&lt;p&gt;Before you pick spectral subtraction, a Wiener filter, or DeepFilterNet, you need a crisp shared vocabulary for &lt;em&gt;what&lt;/em&gt; is corrupting speech and &lt;em&gt;how hard&lt;/em&gt; the mixture actually is. This lesson classifies degradations, writes down the additive and convolutional mixture models, and shows by hand why a single global SNR number can fool a QA team.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/noise-mixture.png&quot; alt=&quot;Clean speech, additive noise, and the microphone mixture on one timeline&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. The default NS observation is a sum: the microphone records speech plus interference, and the suppressor estimates the speech term.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (additive vs. convolutional models, power vs. amplitude in decibels, global vs. segmental SNR) → Taxonomy of noise &amp;amp; DNS generative training recipe → Worked example: exact noise scaling factor \(\alpha\) for a target SNR and a 2-frame counterexample where global SNR and segmental SNR disagree by 9.5 dB → Explanation: 3 steps from mixture physics to dataset diversity → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-signal-mixtures-decibels-and-room-acoustics&quot;&gt;Key ideas: Signal Mixtures, Decibels, and Room Acoustics&lt;/h2&gt;

&lt;h3 id=&quot;1-additive-noise-vs-convolutional-reverberation&quot;&gt;1. Additive Noise vs. Convolutional Reverberation&lt;/h3&gt;
&lt;p&gt;When background sound travels independently to the microphone, it &lt;strong&gt;adds&lt;/strong&gt; to clean speech: \(y[n] = x[n] + n[n]\). When your own voice bounces off walls and ceilings before hitting the mic, it &lt;strong&gt;convolves&lt;/strong&gt; with the Room Impulse Response (RIR) \(h[n]\): \(y[n] = (x * h)[n] + n[n]\). Additive noise is a separate source you can mask out; late reverberation smears the speech &lt;em&gt;itself&lt;/em&gt; across time and frequency.&lt;/p&gt;

&lt;h3 id=&quot;2-power-ratios-vs-amplitude-rms-ratios-in-decibels&quot;&gt;2. Power Ratios vs. Amplitude (RMS) Ratios in Decibels&lt;/h3&gt;
&lt;p&gt;Audio engineers measure signal-to-noise ratio on a logarithmic scale (dB), and the single most common bug in mixing scripts is confusing &lt;strong&gt;power&lt;/strong&gt; (\(10\log_{10}\)) with &lt;strong&gt;amplitude / RMS&lt;/strong&gt; (\(20\log_{10}\)). Because power scales as amplitude squared (\(E \propto A^2\)), cutting noise amplitude in half (\(\alpha = 0.5\)) cuts noise &lt;em&gt;power&lt;/em&gt; to \(0.25\)—a &lt;strong&gt;\(6\,\mathrm{dB}\)&lt;/strong&gt; improvement, not \(3\,\mathrm{dB}\)!&lt;/p&gt;

&lt;h3 id=&quot;3-stationarity-and-time-scale-mismatch&quot;&gt;3. Stationarity and Time-Scale Mismatch&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Stationary&lt;/strong&gt; noise (HVAC) keeps a nearly constant power spectrum over seconds, letting classical estimators average quiet pauses. &lt;strong&gt;Non-stationary&lt;/strong&gt; noise (dishes, clicks) and &lt;strong&gt;babble&lt;/strong&gt; (competing talkers) shift faster than a single syllable—which is why modern neural enhancers must learn short- and medium-term temporal structure from diverse synthetic mixtures.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Classify additive, convolutional, and non-stationary degradations with engineering examples.&lt;/li&gt;
  &lt;li&gt;Relate SNR (and segmental SNR) to perceived difficulty and to metric sensitivity.&lt;/li&gt;
  &lt;li&gt;Sketch the single-channel generative model used by DNS-style training pipelines.&lt;/li&gt;
  &lt;li&gt;Explain when reverberation should be treated as a separate problem from NS.&lt;/li&gt;
  &lt;li&gt;Contrast single-channel vs multi-channel observations at a product level.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–10&lt;/td&gt;
      &lt;td&gt;Taxonomy whiteboard: stationary / non-stationary / babble / impulsive / music&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;10–25&lt;/td&gt;
      &lt;td&gt;Mixture equations; SNR definitions; numerical examples at 16 kHz&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;25–40&lt;/td&gt;
      &lt;td&gt;Reverb vs noise; single- vs multi-channel; DNS Challenge corpora intuition&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;40–50&lt;/td&gt;
      &lt;td&gt;Pitfalls: training–test mismatch, gain riding, “noise” that is speech&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;50–60&lt;/td&gt;
      &lt;td&gt;Mini exercises&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;additive-noise-the-default-ns-assumption&quot;&gt;Additive noise (the default NS assumption)&lt;/h3&gt;

\[y[n] = x[n] + n[n]\]

&lt;p&gt;Here \(x\) is clean speech, \(n\) is unwanted interference, and \(y\) is what the microphone captures (after ADC). Classical NS and most neural speech enhancement (SE) training recipes start here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stationary&lt;/strong&gt; noise: statistics change slowly (HVAC hum). Power spectral density \(S_{nn}(e^{j\omega})\) can be estimated from noise-only regions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-stationary&lt;/strong&gt; noise: statistics change within tens of milliseconds (dishes, keyboard, door slam). Estimators that assume long-term stationarity fail; this is why neural SE and carefully designed trackers matter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Babble&lt;/strong&gt;: sum of other talkers. Spectrally speech-like; masks that wipe babble often wipe target consonants too.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Music / media&lt;/strong&gt;: harmonic structure; can fool voice-activity detectors (VAD).&lt;/p&gt;

&lt;h3 id=&quot;convolutional-degradation-reverb&quot;&gt;Convolutional degradation (reverb)&lt;/h3&gt;

\[y[n] = (x * h)[n] + n[n]\]

&lt;p&gt;where \(h\) is a room impulse response (RIR). Late reverberation smears energy across time and frequency. &lt;strong&gt;Dereverberation&lt;/strong&gt; is related to enhancement but is not identical to NS. Shipping an NS model trained only on additive noise into a cathedral will underperform; DNS Challenge tracks sometimes include RIR augmentation — read track statements carefully.&lt;/p&gt;

&lt;h3 id=&quot;signal-to-noise-ratio&quot;&gt;Signal-to-noise ratio&lt;/h3&gt;

&lt;p&gt;Global SNR in dB:&lt;/p&gt;

\[\mathrm{SNR}_{\mathrm{dB}} = 10\log_{10}\frac{\sum_n x[n]^2}{\sum_n n[n]^2}\]

&lt;p&gt;&lt;strong&gt;Segmental SNR&lt;/strong&gt; averages short-frame SNRs and correlates better with short-term quality, but both are imperfect proxies for listening tests. Neural SE papers (including DeepFilterNet family) typically report SI-SDR / DNSMOS-style metrics rather than raw SNR improvement alone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Numerical intuition.&lt;/strong&gt; Suppose clean speech has RMS \(0.1\) (linear full-scale) and you want SNR \(= 0\,\mathrm{dB}\). Then noise RMS should also be \(0.1\), because RMS ratios and power ratios are not the same knob: \(0\,\mathrm{dB}\) means equal &lt;em&gt;power&lt;/em&gt;, and power is the square of RMS. At SNR \(= -5\,\mathrm{dB}\), noise power is \(10^{0.5}\approx 3.16\times\) speech power, so noise RMS is \(\sqrt{3.16}\approx 1.78\times\) speech RMS — already a hard conversational condition.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Segmental SNR disagrees with one global number.&lt;/strong&gt; Take two equal-length frames with speech energy 1 in each. Frame A has noise energy \(0.01\) (SNR \(20\,\mathrm{dB}\)). Frame B has noise energy \(10^{0.5}\approx 3.16\) (SNR \(-5\,\mathrm{dB}\)). The average of the two frame SNRs is \(7.5\,\mathrm{dB}\). The global SNR uses total energies \(2\) and \(0.01+3.16\):&lt;/p&gt;

\[10\log_{10}\frac{2}{3.17}\approx -2.0\,\mathrm{dB}.\]

&lt;p&gt;A QA sheet that quotes only the global figure calls this file “below 0 dB.” A sheet that quotes the segmental mean calls it “comfortably positive.” Neither number is the listening test. DeepFilterNet-family results therefore emphasize SI-SDR and DNSMOS-style scores, which still must be read next to the mixture condition you actually shipped.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What a suppression slider does not change.&lt;/strong&gt; npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt; 1.3.0 exposes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setSuppressionLevel(0–100)&lt;/code&gt; on the public processor. That integer scales how hard a trained suppressor pushes; it does not rewrite \(y=x+n\). A −5 dB babble mixture stays babble at every slider position. The product default rate is 48 kHz full-band, so the noise you must name extends toward a 24 kHz Nyquist even when the vowel formants sit much lower.&lt;/p&gt;

&lt;h3 id=&quot;toy-generative-model-for-training&quot;&gt;Toy generative model for training&lt;/h3&gt;

&lt;p&gt;DNS Challenge–style pipelines roughly:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Sample clean speech utterance \(x\).&lt;/li&gt;
  &lt;li&gt;Sample noise clip \(n\) (and optionally convolve \(x\) with an RIR \(h\)).&lt;/li&gt;
  &lt;li&gt;Scale \(n\) to hit a target SNR; form \(y = x * h + n\) (or \(y = x + n\)).&lt;/li&gt;
  &lt;li&gt;Train a model to predict \(x\), a mask, or filter coefficients from \(y\) (often in STFT / ERB domains).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is why &lt;strong&gt;data diversity&lt;/strong&gt; beats clever losses when the product domain shifts (motorcycle helmet mics ≠ DNS office noise).&lt;/p&gt;

&lt;h3 id=&quot;single-channel-vs-multi-channel&quot;&gt;Single-channel vs multi-channel&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Setup&lt;/th&gt;
      &lt;th&gt;Observation&lt;/th&gt;
      &lt;th&gt;Typical tools&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Single-channel&lt;/td&gt;
      &lt;td&gt;one mic \(y\)&lt;/td&gt;
      &lt;td&gt;spectral NS, RNNoise-class, DeepFilterNet-class&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Multi-channel&lt;/td&gt;
      &lt;td&gt;vector \(\mathbf{y}\)&lt;/td&gt;
      &lt;td&gt;beamforming, GSC, IVA, neural multi-channel SE&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Mezon’s public npm-oriented path is framed around &lt;strong&gt;single-channel real-time&lt;/strong&gt; enhancement in browser / WebRTC-like settings. Multi-channel methods appear later only as front-end context (Ch. 03).&lt;/p&gt;

&lt;h2 id=&quot;worked-example--mixing-at-a-target-snr&quot;&gt;Worked example — mixing at a target SNR&lt;/h2&gt;

&lt;p&gt;Given speech \(x\) and noise \(n\) with energies \(E_x = \sum x^2\), \(E_n = \sum n^2\), scale noise by \(\alpha\) so that SNR is \(S\) dB. Start from the definition and do not skip the square:&lt;/p&gt;

\[10\log_{10}\frac{E_x}{\alpha^2 E_n} = S
\quad\Rightarrow\quad
\frac{E_x}{\alpha^2 E_n}=10^{S/10}
\quad\Rightarrow\quad
\alpha = \sqrt{\frac{E_x}{E_n}\cdot 10^{-S/10}}.\]

&lt;p&gt;When \(E_x=E_n\), the ratio under the square root collapses and \(\alpha=10^{-S/20}\). For \(S=5\), \(\alpha=10^{-0.25}\approx 0.562\), and noise &lt;em&gt;power&lt;/em&gt; is \(10^{-0.5}\approx 0.316\) times speech power. Then \(y = x + \alpha n\) (truncate or resample to equal length first). Always match sample rates before mixing — a silent bug in many student pipelines. The mini-lab checks both the equal-energy shortcut and a seeded draw whose energies are not equal.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-why-mixture-physics-dictates-both-training-and-qa&quot;&gt;Explanation: Why Mixture Physics Dictates Both Training and QA&lt;/h3&gt;

&lt;h4 id=&quot;step-1-separate-what-a-single-microphone-can-and-cannot-tell-apart&quot;&gt;Step 1: Separate what a single microphone can and cannot tell apart&lt;/h4&gt;
&lt;p&gt;In \(y[n] = x[n] + n[n]\), stationary hiss occupies a broad, steady floor while voiced speech sits in sharp harmonic ridges—easy to separate in STFT space. Competing babble has the &lt;em&gt;same&lt;/em&gt; harmonic ridges as the target speaker; without spatial cues (multiple mics) or speaker enrollment, any single-channel suppressor can only guess which voice is “target” by loudness or continuity.&lt;/p&gt;

&lt;h4 id=&quot;step-2-watch-the-square-root-in-snr-scaling&quot;&gt;Step 2: Watch the square root in SNR scaling&lt;/h4&gt;
&lt;p&gt;Because energy is quadratic in amplitude, scaling noise samples by \(\alpha\) scales noise energy by \(\alpha^2\). Forgetting the square root in \(\alpha = \sqrt{(E_x/E_n)10^{-S/10}}\) silently shifts your entire training and evaluation SNR distribution by a factor of \(2\times\) in dB!&lt;/p&gt;

&lt;h4 id=&quot;step-3-always-pair-global-metrics-with-time-localized-inspection&quot;&gt;Step 3: Always pair global metrics with time-localized inspection&lt;/h4&gt;
&lt;p&gt;As the 2-frame calculation showed (\(+7.5\,\mathrm{dB}\) segmental vs. \(-2.0\,\mathrm{dB}\) global), one loud burst dominates total noise energy while leaving quiet frames untouched. Real-world QA must stratify by noise type (stationary, transient, babble, reverb) and check both objective metrics and listening tests.&lt;/p&gt;

&lt;p&gt;Summary of the mixture-to-training pipeline:&lt;/p&gt;

\[(x, n, h)
\;\xrightarrow{\alpha = \sqrt{\frac{E_x}{E_n}10^{-S/10}}}\;
y = (x * h) + \alpha n
\;\xrightarrow{\text{STFT / ERB}}\;
\hat{x} \approx x.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Calling everything “noise” including echo (AEC territory) and codec artifacts.&lt;/li&gt;
  &lt;li&gt;Reporting huge SNR gains on near-silent files (division by tiny energy).&lt;/li&gt;
  &lt;li&gt;Training only on stationary noise then testing on babble.&lt;/li&gt;
  &lt;li&gt;Forgetting that &lt;strong&gt;gain mismatch&lt;/strong&gt; (different RMS) between train and prod mics shifts effective SNR.&lt;/li&gt;
  &lt;li&gt;Expecting single-channel NS to separate two equal-level talkers reliably.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Mix a sine “speech” tone with seeded Gaussian noise at 5 dB SNR and print the scale you actually applied.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;default_rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16_000&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;220&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rng&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;en&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s_db&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;5.0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sqrt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;en&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s_db&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;measured&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;noise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;snr_db=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;measured&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;alpha_equal_energy=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s_db&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alpha=0.039870&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;snr_db=5.00&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alpha_equal_energy=0.562341&lt;/code&gt;. The measured SNR is exactly the target because \(\alpha\) was solved from the two energies; the equal-energy line is the shortcut \(10^{-S/20}\), not the \(\alpha\) of this draw.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Scaling the noise by \(10^{-S/10}\) and forgetting the square root (that applies a 10 dB shift when you asked for 5). Mixing a 48 kHz tone with 16 kHz noise without resampling. Computing SNR from RMS values without squaring.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Classify: keyboard clicks, HVAC, TV dialogue under speech, underground reverb — additive vs convolutional vs both.&lt;/li&gt;
  &lt;li&gt;Compute \(\alpha\) if \(E_x=E_n\) and target SNR \(= 5\,\mathrm{dB}\).&lt;/li&gt;
  &lt;li&gt;Why might SI-SDR improve while listeners hate the audio? Give one artifact class (e.g. musical noise).&lt;/li&gt;
  &lt;li&gt;Sketch how a non-stationary burst fools a noise-floor tracker that updates with a long smoother.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Clicks are additive and impulsive; HVAC is additive and slow; TV dialogue is additive babble; subway reverb is convolutional, usually with additive noise on top.&lt;/li&gt;
  &lt;li&gt;Equal energy and \(S=5\) give \(\alpha=10^{-5/20}\approx 0.562\).&lt;/li&gt;
  &lt;li&gt;Musical noise is a classic: isolated bins pumped on and off. SI-SDR can rise while that texture is unpleasant.&lt;/li&gt;
  &lt;li&gt;A long smoother keeps the pre-burst floor, so the burst is treated as speech and passes. After the burst, the floor stays high and eats the next vowel.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;DNS Challenge noise / speech corpora descriptions and track overviews.&lt;/li&gt;
  &lt;li&gt;SpeexDSP / WebRTC NS design notes (classical priors and noise estimation ideas).&lt;/li&gt;
  &lt;li&gt;DeepFilterNet (arXiv:2110.05588), DeepFilterNet2 (arXiv:2205.05474), DeepFilterNet3 (arXiv:2305.08227) — additive STFT mixture sections. Code: https://github.com/Rikorose/DeepFilterNet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; The dataset section is the part to watch: stationary noise, transient events, and competing speech are mixed on purpose, which is this lesson’s noise vocabulary.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Xb--68NlxS0&quot;&gt;Spectral Subtraction In Python - Alexx Mitchell&lt;/a&gt; — The Audio Programmer, English. Watch the white-noise picture and the magnitude-spectrum subtraction diagram; they assume the additive mixture this lesson writes down.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, English. Use the demo as an ear check for non-stationary noise that a single noise-floor number does not describe.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>00-01 Why real-time noise suppression matters</title>
   <link href="https://audio-processing-self-learning.pages.dev/contents/en/chapter00/00_01_problem_and_motivation/"/>
   <updated>2021-01-01T00:00:00+00:00</updated>
   <id>https://audio-processing-self-learning.pages.dev/contents/en/chapter00/00_01_problem_and_motivation</id>
   <content type="html">&lt;p&gt;Picture yourself joining a high-stakes design review from a bustling café—espresso grinders roaring behind you, a mechanical keyboard clacking beside the laptop mic, and two colleagues debating at the next table. The person on the other end does not care how impressive your neural network’s offline benchmark looks on a research leaderboard; they care about one thing: &lt;em&gt;can they understand you effortlessly, without robotic warble and without an awkward half-second delay?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That lived product constraint is &lt;strong&gt;real-time noise suppression (NS)&lt;/strong&gt;. This opening lesson frames the &lt;em&gt;problem&lt;/em&gt; before a single filter or neural layer is chosen: what “good” actually means to human ears versus speech recognizers, why streaming causality changes everything, and how this course connects to Mezon’s public noise-suppression stack.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/generated/realtime-vs-offline.png&quot; alt=&quot;Offline file enhancement beside a causal call path that cannot see the future&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure. A real-time suppressor may use audio only up to “now,” plus a small look-ahead budget; an offline enhancer may see the whole file.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson roadmap:&lt;/strong&gt; Key ideas (additive mixture model, causal vs. offline systems, three competing enhancement goals) → Core product constraints &amp;amp; Mezon public surface → Worked example: a complete 48 kHz latency &amp;amp; RTF budget checked by hand → Explanation: 3 steps from raw microphone PCM to a shippable real-time budget → Pitfalls, Mini-lab, Exercises &amp;amp; Videos.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;key-ideas-what-does-real-time-speech-enhancement-actually-study&quot;&gt;Key ideas: What Does Real-Time Speech Enhancement Actually Study?&lt;/h2&gt;

&lt;h3 id=&quot;1-the-observation-model--separating-signal-from-interference&quot;&gt;1. The Observation Model — Separating Signal from Interference&lt;/h3&gt;
&lt;p&gt;At the microphone, clean speech \(x(t)\) and unwanted background noise \(n(t)\) add together into a single waveform \(y(t) = x(t) + n(t)\) (or in a reverberant room, \(y(t) = (x * h)(t) + n(t)\)). Single-channel noise suppression is an &lt;strong&gt;ill-posed inverse problem&lt;/strong&gt;: you receive one sum and must recover one of its two unknown summands in real time, usually after transforming short overlapping frames into the time–frequency (STFT) domain \(Y(\ell, k) = X(\ell, k) + N(\ell, k)\).&lt;/p&gt;

&lt;h3 id=&quot;2-three-competing-objectives--intelligibility-quality-and-asr&quot;&gt;2. Three Competing Objectives — Intelligibility, Quality, and ASR&lt;/h3&gt;
&lt;p&gt;A quieter spectrogram is not automatically a better call. Speech enhancement balances three distinct targets: &lt;strong&gt;intelligibility&lt;/strong&gt; (preserving consonants like /s/, /f/, /t/ so words stay clear), &lt;strong&gt;perceptual quality&lt;/strong&gt; (natural timbre without watery “musical noise”), and &lt;strong&gt;ASR accuracy&lt;/strong&gt; (avoiding spectral distortions that confuse downstream speech-to-text models). Optimizing one can degrade another.&lt;/p&gt;

&lt;h3 id=&quot;3-causality-latency-and-real-time-factor-rtf&quot;&gt;3. Causality, Latency, and Real-Time Factor (RTF)&lt;/h3&gt;
&lt;p&gt;In interactive voice calls, a suppressor cannot peek 500 ms into the future. It must run &lt;strong&gt;causally&lt;/strong&gt; inside a strict &lt;strong&gt;latency budget&lt;/strong&gt; (typically \(\le 20\text{–}40\,\mathrm{ms}\) algorithmic buffering) and finish each audio hop faster than the hop arrives—measured by the &lt;strong&gt;Real-Time Factor&lt;/strong&gt; \(\mathrm{RTF} = T_{\mathrm{proc}} / T_{\mathrm{audio}} \ll 1\) on the &lt;em&gt;actual target CPU&lt;/em&gt;, including worst-case spikes.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;learning-objectives&quot;&gt;Learning objectives&lt;/h2&gt;

&lt;p&gt;By the end of this lesson (~60 minutes) you should be able to:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Explain why single-channel NS is a first-class requirement in VoIP, conferencing, and embedded voice UIs.&lt;/li&gt;
  &lt;li&gt;Separate three enhancement goals: &lt;strong&gt;intelligibility&lt;/strong&gt;, &lt;strong&gt;perceptual quality&lt;/strong&gt;, and &lt;strong&gt;ASR-friendly&lt;/strong&gt; input.&lt;/li&gt;
  &lt;li&gt;Distinguish real-time / causal enhancement from offline batch enhancement in product terms (latency, RTF).&lt;/li&gt;
  &lt;li&gt;Locate this course relative to the public Mezon stack (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt;, npm &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;) without inventing unpublished internals.&lt;/li&gt;
  &lt;li&gt;State what this course will &lt;em&gt;not&lt;/em&gt; treat as primary (full AEC/AGC product stacks).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;60-minute-teaching-plan&quot;&gt;60-minute teaching plan&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Minutes&lt;/th&gt;
      &lt;th&gt;Activity&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;0–8&lt;/td&gt;
      &lt;td&gt;Warm-up: listen mentally to three scenes (office HVAC, street, keyboard) and list what breaks in a call&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;8–20&lt;/td&gt;
      &lt;td&gt;Product goals: intelligibility vs quality vs ASR; map each to a failure mode&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;20–35&lt;/td&gt;
      &lt;td&gt;Real-time constraints: frame delay, RTF, why offline SOTA often cannot ship&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;35–48&lt;/td&gt;
      &lt;td&gt;Mezon / DeepFilterNet product context (public surface only) and course scope&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;48–60&lt;/td&gt;
      &lt;td&gt;Mini exercises + discussion of pitfalls&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;core-explanations&quot;&gt;Core explanations&lt;/h2&gt;

&lt;h3 id=&quot;noise-as-a-product-constraint&quot;&gt;Noise as a product constraint&lt;/h3&gt;

&lt;p&gt;In consumer and enterprise voice products, noise is not an academic additive disturbance \(n(t)\). It is a &lt;strong&gt;user-visible SLA&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Office / HVAC&lt;/strong&gt;: quasi-stationary low-frequency rumble; easy for classical estimators, annoying if left alone.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Street / café&lt;/strong&gt;: non-stationary bursts; classical noise-floor trackers lag; neural models earn their keep.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Keyboard / mouse&lt;/strong&gt;: impulsive, broadband clicks that punch through speech formants.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Babble&lt;/strong&gt;: competing speech; the hardest single-channel case because the “noise” lives in the same time–frequency patterns as the target.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A usable NS block must reduce these without turning speech into watery artifacts, without adding tens of milliseconds of delay that destroy conversational turn-taking, and without burning so much CPU that an AudioWorklet callback underruns.&lt;/p&gt;

&lt;h3 id=&quot;three-enhancement-goals-do-not-collapse-them&quot;&gt;Three enhancement goals (do not collapse them)&lt;/h3&gt;

&lt;p&gt;Engineers often say “make it cleaner.” That hides three different objectives:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Intelligibility&lt;/strong&gt; — can a listener (or ASR) recover words? Spectral distortion that removes consonants can &lt;em&gt;look&lt;/em&gt; quieter on a spectrogram and still destroy intelligibility.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Perceptual quality&lt;/strong&gt; — MOS / DNSMOS-style pleasantness: less hiss, less musical noise, natural timbre.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ASR upstream&lt;/strong&gt; — some pipelines optimize word-error rate; aggressive NS that helps humans can &lt;em&gt;hurt&lt;/em&gt; ASR if it removes cues the recognizer relies on.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Classical metrics (SI-SDR) and listening metrics (DNSMOS) disagree often enough that product teams must pick a primary goal. This course emphasizes &lt;strong&gt;real-time conversational quality&lt;/strong&gt; aligned with Mezon-style browser / WebRTC paths, while teaching evaluation tools in Chapter 08.&lt;/p&gt;

&lt;h3 id=&quot;real-time-vs-offline-preview-deep-dive-in-00-03&quot;&gt;Real-time vs offline (preview; deep dive in 00-03)&lt;/h3&gt;

&lt;p&gt;Offline enhancement may use the whole utterance, bidirectional context, and large networks. Real-time enhancement is &lt;strong&gt;causal&lt;/strong&gt;: at time \(t\) you may only use audio up to \(t\) (plus a small intentional look-ahead budget).&lt;/p&gt;

&lt;p&gt;Two numbers dominate design reviews:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Algorithmic / buffering latency&lt;/strong&gt; (ms): how long until the cleaned sample leaves the pipeline.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Real-time factor (RTF)&lt;/strong&gt;: wall-clock processing time divided by audio duration. For streaming, you need worst-case RTF \(\ll 1\) on the &lt;em&gt;target&lt;/em&gt; device, not the mean on a laptop CPU.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If a published model needs 200 ms look-ahead and RTF 0.8 on a phone CPU, it is research-interesting and product-dead for interactive calls.&lt;/p&gt;

&lt;h3 id=&quot;mixture-model-one-equation-to-keep&quot;&gt;Mixture model (one equation to keep)&lt;/h3&gt;

&lt;p&gt;Single-channel observation in the time domain:&lt;/p&gt;

\[y(t) = x(t) + n(t)\]

&lt;p&gt;or, after an STFT,&lt;/p&gt;

\[Y(\ell,k) = X(\ell,k) + N(\ell,k)\]

&lt;p&gt;where \(\ell\) is the frame index and \(k\) the frequency bin. Almost every classical and neural NS method is a strategy for estimating \(X\) (or a mask / filter that recovers \(X\)) from \(Y\) under real-time constraints. Convolutional distortion (reverb) is a &lt;em&gt;related but separate&lt;/em&gt; problem:&lt;/p&gt;

\[y(t) = (x * h)(t) + n(t)\]

&lt;p&gt;Do not claim a single-channel NS model “solves reverb” unless evaluation explicitly includes it.&lt;/p&gt;

&lt;h3 id=&quot;mezon-product-context-public-facts-only&quot;&gt;Mezon product context (public facts only)&lt;/h3&gt;

&lt;p&gt;This course is aligned with Mezon noise-suppression product work:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;GitHub organization/repo: &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;npm package surface commonly referenced in the outline: &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deepfilternet3-noise-filter&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Instructor local checkout (do not require students to have this path): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/nguyenlelinh/ncc/mezon-noise-suppression&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Teach techniques&lt;/strong&gt; (DSP → classical NS → DeepFilterNet family → realtime/on-device → eval → integration), not “how to call one npm wrapper.” Anything not documented in public READMEs, papers, or npm docs is out of scope for claims.&lt;/p&gt;

&lt;h3 id=&quot;scope-boundaries&quot;&gt;Scope boundaries&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;In scope&lt;/th&gt;
      &lt;th&gt;Out of scope as primary syllabus&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Framing, STFT, classical NS, DeepFilterNet ideas, RTF, ORT/WASM, WebRTC/LiveKit integration patterns, metrics&lt;/td&gt;
      &lt;td&gt;Full acoustic echo cancellation (AEC) product design, multi-mic beamforming hardware, unpublished Mezon internals&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;AEC / AGC / WebRTC APM as &lt;em&gt;context&lt;/em&gt; (Ch. 03)&lt;/td&gt;
      &lt;td&gt;Claiming the course replaces WebRTC APM&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;worked-example--latency-budget-sketch&quot;&gt;Worked example — latency budget sketch&lt;/h2&gt;

&lt;p&gt;A conferencing product targets \(\le 40\,\mathrm{ms}\) algorithmic buffering from mic callback to cleaned PCM handed to the encoder.&lt;/p&gt;

&lt;p&gt;Assume \(f_s = 48\,\mathrm{kHz}\), frame length \(L = 480\) samples (10 ms), hop \(R = 240\) samples (5 ms), and a model that needs one frame of look-ahead.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Buffering to assemble one analysis window of 10 ms already costs 10 ms if you wait for a full window (implementations can overlap; still, &lt;em&gt;some&lt;/em&gt; buffering exists).&lt;/li&gt;
  &lt;li&gt;Hop 5 ms means you emit a new STFT column every 5 ms — good for continuity, but CPU must finish each hop’s work within that budget on average.&lt;/li&gt;
  &lt;li&gt;One-frame look-ahead adds another \(\sim 5\)–\(10\,\mathrm{ms}\) depending on definition.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Numerical intuition.&lt;/strong&gt; At 48 kHz, 1 ms is 48 samples, so the 40 ms budget is \(40\times 48=1920\) samples. Waiting for the 480-sample window spends 10 ms; one hop of look-ahead spends another 5 ms; 25 ms remain for everything else in that sketch. A forward pass that takes 8 ms on a separate 20 ms hop has RTF \(8/20=0.40\). The same pass at 22 ms has RTF \(1.1\) and will underrun unless you lengthen the hop or shrink the model. The mini-lab prints the first set of figures.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;explanation-how-a-product-latency-budget-constrains-your-algorithm&quot;&gt;Explanation: How a Product Latency Budget Constrains Your Algorithm&lt;/h3&gt;

&lt;p&gt;Why do so many impressive academic speech-enhancement papers fail the moment you drop them into a browser call? Trace the 3-step constraint chain:&lt;/p&gt;

&lt;h4 id=&quot;step-1-convert-milliseconds-into-exact-sample-counts-at-the-device-clock&quot;&gt;Step 1: Convert milliseconds into exact sample counts at the device clock&lt;/h4&gt;
&lt;p&gt;At \(f_s = 48{,}000\,\mathrm{Hz}\), every millisecond equals exactly \(48\) samples. A \(40\,\mathrm{ms}\) total algorithmic budget gives you only \(1{,}920\) samples of leeway from the moment air hits the microphone until clean PCM reaches the network encoder.&lt;/p&gt;

&lt;h4 id=&quot;step-2-subtract-unavoidable-framing-and-look-ahead-delay-before-running-a-single-layer&quot;&gt;Step 2: Subtract unavoidable framing and look-ahead delay before running a single layer&lt;/h4&gt;
&lt;p&gt;Assembling a \(480\)-sample analysis window spends \(10\,\mathrm{ms}\); granting the neural network just one hop (\(240\) samples) of future look-ahead spends another \(5\,\mathrm{ms}\). Before you write a single line of model code, \(15\,\mathrm{ms}\) is already spoken for—leaving \(25\,\mathrm{ms}\) for overlap-add reconstruction, WebAudio callback buffering, and jitter margin.&lt;/p&gt;

&lt;h4 id=&quot;step-3-gate-the-compute-path-by-worst-case-rtf-not-mean-rtf&quot;&gt;Step 3: Gate the compute path by worst-case RTF, not mean RTF&lt;/h4&gt;
&lt;p&gt;Every \(5\,\mathrm{ms}\) hop triggers a new forward pass. Even if average compute is \(2\,\mathrm{ms}\) (\(\mathrm{RTF} = 0.40\)), a single \(7\,\mathrm{ms}\) thermal or garbage-collection spike pushes that hop to \(\mathrm{RTF} = 1.40\), causing an audible dropout. Real-time engineering therefore designs for &lt;strong&gt;causal look-ahead + p99 RTF \(\ll 1\)&lt;/strong&gt; from Day 1.&lt;/p&gt;

&lt;p&gt;Summary of the real-time NS design gate:&lt;/p&gt;

\[y(t) = x(t) + n(t)
\;\xrightarrow{\text{STFT } (L, R)}\;
\text{Latency} \le 40\,\mathrm{ms}
\quad \&amp;amp; \quad
\mathrm{RTF}_{p99} = \frac{T_{\mathrm{proc}, p99}}{T_{\mathrm{hop}}} \ll 1.\]

&lt;h2 id=&quot;common-pitfalls&quot;&gt;Common pitfalls&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Optimizing SI-SDR offline&lt;/strong&gt; and shipping the same checkpoint for streaming without measuring causal latency and device RTF.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Treating “noise reduction %”&lt;/strong&gt; as a metric — undefined for product QA.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Assuming mono NS&lt;/strong&gt; works unchanged on stereo without a documented downmix policy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Blaming the neural model&lt;/strong&gt; when the bug is sample-rate mismatch, wrong hop, or OLA window mismatch (Ch. 01–02 checklists).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Claiming Mezon-specific secrets&lt;/strong&gt; from reading this course — stick to public surfaces and general DeepFilterNet literature.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mini-lab&quot;&gt;Mini-lab&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal.&lt;/strong&gt; Recompute the 48 kHz sketch so a hop change cannot hide inside a spreadsheet.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;budget_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;48_000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;240&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;480&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;40.0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;window_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;window&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;hop_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; window_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;window_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;samples_per_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; budget_samples=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;budget_ms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;remaining_ms=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;budget_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;window_ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hop_ms&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; rtf=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Expected.&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hop_ms=5.0 window_ms=10.0&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;samples_per_ms=48 budget_samples=1920&lt;/code&gt;, then &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;remaining_ms=25.0 rtf=0.40&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure modes.&lt;/strong&gt; Swapping hop and window, counting 16 kHz samples inside a 48 kHz budget, or defining RTF as audio duration over processing time.&lt;/p&gt;

&lt;h2 id=&quot;mini-exercises&quot;&gt;Mini exercises&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Pick a 10-second mental scene (café). List three noise events and mark each as stationary / non-stationary / speech-like.&lt;/li&gt;
  &lt;li&gt;Write one sentence each for intelligibility, quality, and ASR goals for a customer-support softphone.&lt;/li&gt;
  &lt;li&gt;Given \(f_s=16\,\mathrm{kHz}\) and hop \(R=160\) samples, compute hop duration in ms and the maximum average processing time for RTF \(= 0.5\).&lt;/li&gt;
  &lt;li&gt;Browse the public &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mezonai/mezon-noise-suppression&lt;/code&gt; README (when online) and list three &lt;em&gt;documented&lt;/em&gt; capabilities — do not invent others.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;answer-hints&quot;&gt;Answer hints&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;HVAC changes slowly; a door slam does not; a nearby talker is speech-like babble.&lt;/li&gt;
  &lt;li&gt;Intelligibility is words recovered, quality is pleasantness, ASR is word error — the third can move against the first two.&lt;/li&gt;
  &lt;li&gt;Hop duration is \(160/16000=10\,\mathrm{ms}\). RTF \(0.5\) allows \(5\,\mathrm{ms}\) of average processing on that hop.&lt;/li&gt;
  &lt;li&gt;Quote README bullets only (package, runtime, sample rate). Do not infer an unpublished graph.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;WebRTC Audio Processing Module (APM) documentation — noise suppression overview.&lt;/li&gt;
  &lt;li&gt;Schröter et al., DeepFilterNet (arXiv:2110.05588), DeepFilterNet2 (arXiv:2205.05474), DeepFilterNet3 (arXiv:2305.08227) — introductions for why causal enhancement is the product problem. Repo: https://github.com/Rikorose/DeepFilterNet.&lt;/li&gt;
  &lt;li&gt;DNS Challenge overview pages (dataset and track motivation).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;video-tham-khảo&quot;&gt;Video tham khảo&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;[Developing Machine Learning Based Speech Enhancement Models for Teams and Skype&lt;/td&gt;
          &lt;td&gt;Ross Cutler](https://www.youtube.com/watch?v=Gdvhv8SYcTg) — @Scale, English. &lt;strong&gt;xem trước.&lt;/strong&gt; Watch how a calling product treats background noise as a user complaint before any filter is chosen; that is the problem this lesson frames.&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=it90gBqkY6k&quot;&gt;DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio (ICASSP 2022)&lt;/a&gt; — Hendrik Schröter, English. The author states a full-band causal enhancer with a few milliseconds of latency, which is the real-time constraint the lesson contrasts with offline enhancement.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EO7n96YwnyE&quot;&gt;DeepFilterNet Noise Suppression Demo&lt;/a&gt; — Hendrik Schröter, English. Listen to the before-and-after the lesson is motivating: office and non-stationary noise on a live suppressor, not a metric table.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 

</feed>
