Files
ncmr-songs/wip/dsp.md

297 lines
20 KiB
Markdown
Raw Permalink Normal View History

2026-03-10 20:27:17 +09:00
# digital signal processing
A boring lecture about signals and systems, and its digital implementation in DSP.
Borderline 'song' less 'poetic'.
2026-03-13 21:05:26 +09:00
The actual material (text that is read out by a vocal synthesiser) is in Japanese.
## Simple notes
For things that are not easily pronounced (e.g. formulae, expressions, symbols), inclusive either:
- Mark how the thing should be pronounced in a pair of adjacent parentheses
- e.g. $H(\omega)$ (エッチオメガ)
2026-03-13 21:05:26 +09:00
- (inclusive) Or don't embed these elements too deep into the flow of sentences; use common, laymen's language instead
- e.g. not `Fs/2サンプリング周波数の半分までの帯域を忠実に再構成できる` but `サンプリング周波数の半分までの帯域を忠実に再構成できる`
The general direction is to stay boring, but the deadpan kind of boring. Keep technical language appearing but explain things in more laymen's language.
2026-03-10 20:27:17 +09:00
## Outline
2026-03-10 22:51:12 +09:00
### 1. Signals and systems
- What is a signal
- A function of one or more variables carrying information; here, amplitude over time
- What is a system
- A system maps an input signal to an output signal
- Characterized entirely by its behavior on inputs — the internals are not required
- Most systems are nonlinear — linearity is a special property, not the default
- Linearity: superposition holds — scaling and additivity
- Most physical systems violate this under sufficient conditions (e.g. overdrive: linear below clip threshold, nonlinear at and above it)
- Time-invariance
- A time-invariant system responds identically regardless of when the input arrives
- Violation: any system with time-varying parameters (e.g. modulated effects)
- LTI as the restricted, studied case
- Satisfies both simultaneously — analytically tractable
- A deliberate simplification; not a description of typical reality
- The impulse signal; impulse response
- The impulse: unit energy concentrated at a single point in time
- The impulse response: what an LTI system outputs when fed an impulse
- Completely characterizes the system
- The impulse response is a function — it exists in the same space as signals; systems are absorbed into signal space
### 2. LTI and convolution
- An LTI system is fully characterized by its impulse response
- Any input decomposes into scaled, shifted impulses
- By linearity and time-invariance, the output is the corresponding sum of scaled, shifted impulse responses
- Convolution as the operation
- That sum is convolution: $y = x * h$
- In continuous time, this is an integral: $y(t) = \int x(\tau) \, h(t - \tau) \, d\tau$
- Symmetric in its arguments: $x * h = h * x$
2026-03-10 22:51:12 +09:00
- Signal and system are interchangeable operands — both are functions; convolution makes no distinction between them
- Commutativity: for LTI systems, order of composition is irrelevant
- Two LTI systems in series have a combined impulse response equal to the convolution of each
- $h_1 * h_2 = h_2 * h_1$ — order does not affect the result
2026-03-10 22:51:12 +09:00
### 3. Signal transformation
2026-03-13 21:05:26 +09:00
- A signal can be represented equivalently in the frequency domain
- The Fourier transform: $s(t) \leftrightarrow S(\omega)$; any signal is a sum of sinusoids at different frequencies
2026-03-13 21:05:26 +09:00
- Each sinusoid has a frequency, amplitude, and phase
- $S(\omega)$ is the spectrum: how much of each frequency is present
2026-03-13 21:05:26 +09:00
- Analog signals carry components from DC to arbitrarily high frequencies
2026-03-10 22:51:12 +09:00
2026-03-10 23:10:13 +09:00
### 4. Filters
- A filter is an LTI system — characterized by its frequency response $H(\omega)$
- $H(\omega)$ is the Fourier transform of the impulse response $h(t)$
2026-03-10 23:10:13 +09:00
- Filtering: shaping a signal's spectrum by selectively attenuating or preserving frequency bands
- Basic types: lowpass, highpass, bandpass
- Lowpass: passes low frequencies, attenuates high
- Highpass: passes high frequencies, attenuates low
- Bandpass: passes a target band, attenuates above and below
- In discrete time: finite impulse response (FIR) and infinite impulse response (IIR) filters
### 5. Discretization
2026-03-13 21:05:26 +09:00
- Moving from continuous to discrete: two axes require discretization
- Amplitude: $N$ bits → $2^N$ discrete levels
2026-03-13 21:05:26 +09:00
- Each sample is mapped to the nearest representable level; the error is quantization noise
- The representable range is fixed by design and hardware (ADC/DAC reference voltage)
- Hard clip at the boundary — analog degrades gradually toward its physical limits; digital does not
- Time axis: sampling captures only finitely many values per second
- Analog signals contain frequency components up to infinity — a discrete system cannot represent all of them
- Discrete time is viable when the high-frequency components that would be lost are not needed
- Nyquist: given sampling rate $F_s$, faithful reconstruction is guaranteed up to $F_s/2$
- What $F_s/2$ should be is an applied engineering question — Nyquist does not answer it
- Components above $F_s/2$ are lost: aliasing
2026-03-10 22:51:12 +09:00
- LTI and convolution hold in discrete time — commutativity survives
2026-03-13 21:05:26 +09:00
- Convolution becomes a sum (finite for FIR, infinite for IIR)
2026-03-10 22:51:12 +09:00
2026-03-10 23:10:13 +09:00
### 6. Nonlinearity and consequences
2026-03-10 22:51:12 +09:00
- Real systems violate LTI: time-varying parameters, feedback, saturation
- Each breaks a different condition: time-variance breaks TI, feedback and saturation break linearity
2026-03-10 23:10:13 +09:00
- Examples
- Modulated delay (chorus, flanger): delay time varies with time → time-invariance breaks; same input at different times yields different output
- Overdrive: saturation above threshold → linearity breaks; EQ before overdrive ≠ overdrive before EQ
2026-03-10 22:51:12 +09:00
- Commutativity breaks — order of composition is no longer irrelevant
- $h_1$ followed by $h_2$ ≠ $h_2$ followed by $h_1$ in general
2026-03-10 22:51:12 +09:00
- No universal rule; behavior must be examined per case
### 7. Summary
- Most of the framework rests on the LTI assumption
- Signalsystem equivalence, convolution, commutativity, frequency-domain analysis — all require linearity and time-invariance
- Real systems break the assumption routinely
2026-03-17 17:33:38 +09:00
- Nonlinearity is not binary — it is a spectrum
- Some systems are close enough to linear that the theory applies as a practical approximation
- Others are not — linear theory offers no useful prediction
- Judging where a system falls requires knowing what linearity is in the first place
- The framework is studied not as a description of reality, but as a baseline against which deviations are measured
2026-03-10 22:51:12 +09:00
## Text (lyrics if you insist)
2026-03-17 17:33:38 +09:00
今度は、信号とシステム、そしてデジタル信号処理について説明する。
2026-03-10 22:51:12 +09:00
### 1. 信号とシステム
2026-03-17 17:33:38 +09:00
信号とシステムを知るには、信号とシステム両方を知る必要がある。
2026-03-10 22:51:12 +09:00
2026-03-13 21:05:26 +09:00
信号とは情報を運ぶものである。
ここでは時間の経過とともに振幅がどう変化するか、その関数として扱う。
2026-03-10 22:51:12 +09:00
2026-03-17 17:33:38 +09:00
システムとは、入力信号を受け取り、出力信号を出す箱である。
2026-03-13 21:05:26 +09:00
箱の中身は問わない。何を入れたら何が出るか、その関係だけがシステムを定義する。
2026-03-10 22:51:12 +09:00
2026-03-17 17:33:38 +09:00
システムにはいくつか性質がある。線形性。
2026-03-13 21:05:26 +09:00
線形システムとは、重ね合わせの原理が成り立つシステムである。
入力を2倍にすれば出力も2倍になる。二つの入力を足し合わせたときの出力は、それぞれ単独で入れたときの出力を足したものと等しい。
この二つの条件が揃ったとき、そのシステムは線形である。
2026-03-10 22:51:12 +09:00
2026-03-17 17:33:38 +09:00
ただ、多くの物理システムはこの条件を満たさない。線形性は特殊であり、当たり前ではない。
2026-03-10 22:51:12 +09:00
2026-03-17 17:33:38 +09:00
そして時不変性。
2026-03-13 21:05:26 +09:00
時不変システムとは、入力を時間軸上でずらしたとき、出力も同じだけずれるシステムである。
今日と明日で同じ入力を与えれば、同じ出力が返ってくる。
パラメータが時間とともに変わるシステムは、この条件を満たさない。
2026-03-17 17:33:38 +09:00
線形かつ時不変なシステムを、線形時不変システムと呼ぶ。ここから先は一旦これだけを扱う。
これは解析的に扱いやすい、意図的に絞った特殊ケースである。現実の大半はこれに当てはまらない。けど、解析的に扱いやすいから線形時不変だけを考える。
2026-03-13 21:05:26 +09:00
2026-03-17 17:33:38 +09:00
ここで道具を一つ出す。インパルス信号である。
単一の瞬間に単位エネルギーが集中した信号で、実際には存在しない理想だが、使える。ちなみに瞬間とは無限に短い間のことである。
このインパルスをある線形時不変システムに通した出力を、そのシステムのインパルス応答と呼ぶ。
2026-03-13 21:05:26 +09:00
2026-03-17 17:33:38 +09:00
インパルス応答は、そのシステムを完全に表現できる。システムが確定したらインパルス応答も唯一になり、インパルス応答があれば唯一に対応するシステムも特定できる。
任意の入力はインパルスの積み重ねとして分解できる。インパルス応答さえ分かれば、どんな入力に対する出力も計算できる。
2026-03-13 21:05:26 +09:00
2026-03-17 17:33:38 +09:00
それと、インパルス応答はシステムの出力でありながら、信号と同じ種類の関数である。
つまりインパルス応答によって、システムは信号と同じ空間に置ける。操作の上では、システムと信号の区別は消える。
2026-03-10 22:51:12 +09:00
### 2. 線形時不変システムと畳み込み
2026-03-17 17:33:38 +09:00
インパルス応答がシステムを決定すると言った。なぜだろう。
2026-03-13 21:05:26 +09:00
任意の入力信号は、大きさの異なるインパルスを時間軸上に並べたものとして表せる。
線形時不変システムはそれぞれのインパルスに独立に反応し、その応答を全て重ね合わせる。
この重ね合わせ全体の操作を、畳み込みと呼ぶ。
2026-03-19 19:26:10 +09:00
連続時間では、畳み込みは積分になる。連続じゃない時間の場合は後ほど。
2026-03-13 21:05:26 +09:00
時間軸に沿って入力を少しずつずらしながら、そのずれに対応するインパルス応答を強さに応じて足し合わせる。その積分の結果が出力である。
2026-03-10 22:51:12 +09:00
$y = x * h$ y イコール x 畳み込み h
2026-03-10 22:51:12 +09:00
2026-03-17 17:33:38 +09:00
畳み込みはその二つの引数に対して対称である。
$x * h = h * x$ x 畳み込み h イコール h 畳み込み x
2026-03-17 17:33:38 +09:00
これは計算上の偶然ではない。x と h が同じ種類の対象だからそうなる。前の節で言った、インパルス応答で、システムが信号空間に変換される話の続きである。
2026-03-10 22:51:12 +09:00
2026-03-17 17:33:38 +09:00
この対称性には実用上の意味がある。
2026-03-13 21:05:26 +09:00
二つの線形時不変システムを直列につないだとき、合成されたシステムのインパルス応答は、各インパルス応答の畳み込みである。
$h_1 * h_2 = h_2 * h_1$ h1 畳み込み h2 イコール h2 畳み込み h1
2026-03-13 21:05:26 +09:00
どちらを先につないでも、結果は変わらない。
2026-03-10 22:51:12 +09:00
2026-03-19 19:26:10 +09:00
数学ではこれを可換性と呼ぶ。一応。
2026-03-10 22:51:12 +09:00
### 3. 信号変換
2026-03-19 19:26:10 +09:00
これまで信号を、時間に対する振幅の変化として扱ってきた。同じ信号を、周波数に対する振幅の分布として見ることもできる。
厳密には各周波数成分に位相もあるが、ここでは振幅に注目する。
2026-03-10 22:51:12 +09:00
2026-03-19 19:26:10 +09:00
そのためにフーリエ変換がある。というか、フーリエがその変換の仕方を決めたのでフーリエ変換と呼ばれた。
$s(t)$(エス ティー)と $S(\omega)$(エス オメガ)は同じ信号の二つの顔である。
2026-03-13 21:05:26 +09:00
一方は時間の経過を、もう一方は周波数の分布を示す。
2026-03-10 22:51:12 +09:00
2026-03-19 19:26:10 +09:00
つまり、どんな信号も、周波数の異なる正弦波をいくつか重ね合わせたものとして表せる。
楽器かエンジンの音がわかりやすい。どちらも複数の周波数成分が混ざっている。その配合が音色を決める。
$S(\omega)$ はその内訳である。どの周波数の成分がどれだけの強さで含まれているか、それがスペクトルである。
2026-03-10 22:51:12 +09:00
2026-03-13 21:05:26 +09:00
アナログ信号は原理的には、ゼロから無限大まであらゆる周波数成分を持ちうる。
2026-03-19 19:26:10 +09:00
これが後で問題になる。
2026-03-10 22:51:12 +09:00
2026-03-10 23:10:13 +09:00
### 4. フィルタ
信号は原理的に無限の周波数成分を持ちうると述べた。
実用上、その全てが必要なことはまずない。例えば人間の聴覚はおよそ20kHzまでしか知覚できない。
聞こえないので、人間に聞くための信号では要らない。必要な帯域だけを残し、不要な成分を落とす。それがフィルタの仕事である。
フィルタは線形時不変システムであり、フーリエ変換の言葉で言えば、信号のスペクトルを形作るシステムである。
2026-03-13 21:05:26 +09:00
フィルタを特徴づけるのは周波数応答 $H(\omega)$(エイチ オメガ)である。
これはインパルス応答 $h(t)$ をフーリエ変換したものである。
2026-03-13 21:05:26 +09:00
インパルス応答が時間領域でシステムを表すように、周波数応答は周波数領域でそのシステムを表している。
2026-03-10 23:10:13 +09:00
2026-03-13 21:05:26 +09:00
フィルタの働きは、周波数によって信号をふるいにかけることである。
2026-03-10 23:10:13 +09:00
基本的な分類としてローパス、ハイパス、バンドパスがある。
2026-03-13 21:05:26 +09:00
ローパスフィルタは低い周波数だけを通し、高い周波数を削ぎ落とす。
ハイパスフィルタはその逆で、高い周波数を通し、低い周波数を削ぐ。
バンドパスフィルタは特定の帯域だけを通し、それより低い成分も高い成分も減衰させる。
2026-03-10 23:10:13 +09:00
バンドパスフィルタは普通にローパスとハイパスを組み合わせたものと見なせる。
どちらを先に適用しても結果は変わらない。線形時不変システムだからの可換性です。
これらのフィルタは全て、カットオフ周波数という境界を持つ。
理想的には、境界の手前までゲインが1、超えた瞬間にゲインが0になる。垂直な壁である。
しかし、そのような理想は実現できない。
現実のフィルタは、カットオフ周波数の周辺に曲線を持つ。急な減衰ではなく、緩やかに下る斜面になる。
理想の壁に近づけようとすると、設計が複雑になり、部品が増え、コストが上がる。
時には、緩やかな斜面で十分である。
2026-03-10 23:10:13 +09:00
離散時間においては、有限インパルス応答フィルタと無限インパルス応答フィルタの区別がある。
2026-03-13 21:05:26 +09:00
前者のインパルス応答はある時点で終わる。後者は終わらない。
2026-03-10 23:10:13 +09:00
### 5. 離散化
2026-03-10 22:51:12 +09:00
フィルタはアナログにもデジタルにも存在する。
アナログ空間では、振幅も時間も連続である。最小単位というものがない。なめらかに、切れ目なく続く。
デジタル空間では、切れ目がある。
2026-03-13 21:05:26 +09:00
デジタルシステムが振幅を表現できる精度は、ビット深度によって決まる。
$N$ ビットのシステムは $2^N$ 個の離散的な振幅レベルを持つ。別にこういう二進数の話はしなくていいはずですが。
2026-03-13 21:05:26 +09:00
各サンプルの値は、最も近いレベルに丸められる。この丸め誤差を量子化ノイズと呼ぶ。
表現できる振幅の上限と下限は、設計とハードウェアによって固定されている。ADCやDACの基準電圧がそれを決める。
その境界を超えると、ハードクリップが起きる。
アナログ回路は限界に近づくにつれて少しずつ歪む。デジタルにそういう曖昧さはない。境界は硬い。
次に時間軸について。
デジタルシステムは、連続した時間の流れから、一定間隔で値を取り出す。これがサンプリングである。
ここで問題がある。前の節で述べたように、アナログ信号は原理的には無限大まで周波数成分を持ちうる。
しかし有限のサンプリング頻度では、表現できる周波数に上限がある。全てを保存することはできない。
その上限を超える成分がサンプリング時に残っていると、消えるわけではない。
折り返される。上限を超えた分だけ、反対側に折り返して、低い周波数の成分として現れる。
サンプリング周波数が40kHzのとき、25kHzの成分は15kHzとして記録される。存在しないはずの周波数が信号に混入する。
これをエイリアシングと呼ぶ。
対策は、サンプリングの前にローパスフィルタをかけておくことである。
ではそのフィルタのカットオフ周波数をどこに設定するか。
それは用途次第である。例えば人間の聴覚はおよそ20kHzまでしか知覚できない。
音声信号であれば、20kHz以上を保持する理由はない。
ただし、ここで単純に20kHzでローパスをかけて20kHzでサンプリングすると、情報は失われる。
サンプリング周波数と保存したい帯域の上限が同じでは、再構成できない。余裕が要る。
2026-03-13 21:05:26 +09:00
ナイキストの定理が、その余裕を定量化する。
サンプリング周波数を $F_s$ としたとき、$F_s/2$ より低い周波数成分は忠実に再構成できる。
つまり保存したい帯域の上限の2倍でサンプリングすれば、再構成が保証される。
人間の聴覚が20kHzまでなら、$F_s$ が40kHzを超えていれば聞こえる範囲はカバーできる。
余裕を持たせて、一般的には44.1kHzや48kHzが使われる。192kHzは人間以外の何かのためにあるのだろう。
定理が言うのはそれだけである。$F_s$ をどこに設定すべきかは用途が決める。
$F_s/2$ を超える成分は再構成できない。それがエイリアシングである。
2026-03-10 22:51:12 +09:00
2026-03-13 21:05:26 +09:00
補足しておく。この離散化によって、線形時不変システムの性質が崩れるわけではない。
連続時間において積分であった畳み込みは、離散時間においては和になる。有限インパルス応答なら有限和、無限インパルス応答なら無限和である。
2026-03-10 22:51:12 +09:00
可換性を含む全ての性質は引き継がれる。
2026-03-10 23:10:13 +09:00
### 6. 非線形性とその影響
2026-03-10 22:51:12 +09:00
では、現実のシステムに戻る。
先ほど線形時不変システムは特殊ケースであると述べた。
現実のシステムは線形時不変システムの条件を様々な形で破る。
時変パラメータは時不変性を破る。
フィードバックと飽和は線形性を破る。
2026-03-10 23:10:13 +09:00
例を挙げる。
モジュレーテッドディレイを考える。コーラスやフランジャーがその例である。
ディレイタイムが時間とともに変化するとき、同じ入力でも入力するタイミングによって出力が異なる。
これは時不変性の破れである。
次にオーバードライブを考える。
入力が閾値を超えると飽和が生じ、出力は入力に比例しなくなる。
これは線形性の破れである。
そして順序が問題になる。EQの後にオーバードライブを適用した結果と、オーバードライブの後にEQを適用した結果は、一般に異なる。
2026-03-10 22:51:12 +09:00
このとき、畳み込みの可換性は成立しない。
非線形システムでは、一般に
$h_1$システム1の後に$h_2$システム2を適用した結果と、
$h_2$システム2の後に$h_1$システム1を適用した結果は、等しくない。
2026-03-10 22:51:12 +09:00
普遍的な規則は存在しない。
各ケースを個別に検討する必要がある。
### まとめ
以上がデジタル信号処理の基本的な枠組みである。
振り返ると、ここで述べたことの大半は線形時不変システムという前提の上に成り立っている。
信号とシステムが同じ空間に住むこと。畳み込みによる合成。可換性。周波数領域での見通しのよさ。
これらは全て、線形性と時不変性が揃っているからこそ成り立つ性質である。
2026-03-17 14:20:01 +09:00
そして最後で述べた通り、現実のシステムはその前提をしばしば破る。
2026-03-17 17:33:38 +09:00
では、なぜこの枠組みを学ぶのか、現実のシステムはほとんど非線形なのに。
非線形性は白黒ではないから。線形と見なして良いシステムもあれば、線形理論が全く通用しないシステムもある。
その見極めには、何が破れているのかを知る必要がある。線形の理論はそのためにある。
線形時不変システムの理論は、現実そのものの記述ではない。現実を測るための基準線である。