Suppose a continuous-time signal $x_c(t)$ was sampled with period $T$ to give $x[n] = x_c(nT)$, but we now need the same underlying signal sampled at a different period $T_d$:假設一個連續時間訊號 $x_c(t)$ 已經以週期 $T$ 取樣,得到 $x[n] = x_c(nT)$,但我們現在需要的是同一個原始訊號以另一個週期 $T_d$ 取樣的結果:連続時間信号 $x_c(t)$ を周期 $T$ で標本化して $x[n] = x_c(nT)$ を得たとしよう。ところがいま必要なのは、同じ元の信号を別の周期 $T_d$ で標本化した結果である:
This is needed constantly in practice: audio moves between 48 kHz (studio) and 44.1 kHz (CD), biomedical recorders sample at 2000 Hz but analysis may only need 250 Hz, and a modem may need fractional rate offsets corrected. The question of this chapter: can we obtain $x_d[n]$ from $x[n]$ using only discrete-time operations?這在實務上不斷出現:音訊要在 48 kHz(錄音室)與 44.1 kHz(CD)之間轉換,生醫記錄器以 2000 Hz 取樣但分析可能只需要 250 Hz,數據機則可能需要修正小數倍率的偏移。本章要問的是:能不能只用離散時間的運算,就從 $x[n]$ 得到 $x_d[n]$?これは実務で絶えず必要になる。音声は 48 kHz(スタジオ)と 44.1 kHz(CD)のあいだを行き来し、生体信号レコーダは 2000 Hz で標本化するが解析には 250 Hz しか要らないこともあり、モデムでは小数倍のレート偏差を補正しなければならない。本章の問いはこうである:離散時間の演算だけで $x[n]$ から $x_d[n]$ を得られるか。
One conceptual approach is to go back to the analog world:概念上有一條路是回到類比世界:概念的には、いったんアナログの世界に戻るという道がある:
The reconstruction filter, D/A and A/D converters are all non-ideal: the analog lowpass has finite roll-off and passband ripple, and each conversion adds noise and distortion. Every trip through the analog domain degrades the signal.重建濾波器、D/A 與 A/D 轉換器全都是非理想的:類比低通濾波器的滾降有限、通帶有漣波,而每一次轉換都會加進雜訊與失真。每繞一次類比域,訊號就劣化一次。所以實務上要盡量避免這條路。再構成フィルタ、D/A 変換器、A/D 変換器はいずれも非理想的である。アナログ低域通過フィルタのロールオフは有限で通過帯域にはリップルがあり、変換のたびに雑音と歪みが加わる。アナログ領域を一度通るたびに信号は劣化する。
All rate changes can instead be built from two purely discrete-time primitives — the compressor(壓縮器 / 降取樣) $\downarrow M$ and the expander(擴張器 / 升取樣) $\uparrow L$ — combined with digital lowpass filters. The whole system then behaves like an ideal LTI resampler with no analog imperfection. This chapter develops both primitives, their spectra, and the rational-rate combination $L/M$.所有的倍率轉換,都可以改用兩個純粹的離散時間基本元件搭起來——壓縮器(compressor,降取樣) $\downarrow M$ 與擴張器(expander,升取樣) $\uparrow L$——再配合數位低通濾波器。整個系統的行為就像一個理想的 LTI 重新取樣器,完全沒有類比的不完美。本章會逐一發展這兩個元件、它們的頻譜,以及兩者合起來的有理數倍率 $L/M$。レート変換はすべて、二つの純粋に離散時間的な基本要素——圧縮器(compressor、ダウンサンプリング) $\downarrow M$ と拡張器(expander、アップサンプリング) $\uparrow L$——をディジタル低域通過フィルタと組み合わせて構成できる。そうして得られる系全体は、アナログ的な不完全さを一切もたない理想的な LTI 再標本化器として振る舞う。本章ではこの二つの基本要素、そのスペクトル、そして両者を組み合わせた有理数倍 $L/M$ を順に展開する。
The sampling-rate compressor(取樣率壓縮器), written $\downarrow M$, keeps every $M$-th sample and discards the rest:取樣率壓縮器(記為 $\downarrow M$)保留每第 $M$ 個樣本,其餘全部丟棄:標本化レート圧縮器(compressor)は $\downarrow M$ と書き、$M$ 個おきの標本だけを残して残りを捨てる:
The output is exactly what we would have obtained by sampling $x_c(t)$ directly with the longer period $T' = MT$ — the sampling rate drops by $M$, the sample period grows by $M$. A decimator adds a protective lowpass filter in front of the compressor (next subsection):輸出結果,恰好等同於一開始就用較長的週期 $T' = MT$ 直接對 $x_c(t)$ 取樣——取樣率降為 $1/M$,取樣週期則變成 $M$ 倍。抽取器(decimator)則是在壓縮器前面再加一個保護用的低通濾波器(下一小節):この出力は、はじめから長い周期 $T' = MT$ で $x_c(t)$ を直接標本化して得られるものとちょうど一致する——標本化レートは $M$ 分の 1 になり、標本周期は $M$ 倍になる。間引き器(decimator)は、圧縮器の前に保護用の低域通過フィルタを置いたものである(次の小節):
To see what downsampling does in frequency, write $x_d[n]$ as a two-step operation: (1) multiply $x[n]$ by the periodic sampling train $c_M[n] = \frac{1}{M}\sum_{i=0}^{M-1} e^{j2\pi i n/M}$, which equals 1 when $n$ is a multiple of $M$ and 0 otherwise; (2) discard the zeros. Step (1) gives $\tilde{x}[n] = x[n]\,c_M[n]$, whose DTFT is an average of $M$ shifted copies of $X(e^{j\omega})$; step (2) rescales the frequency axis by $M$. The result:要看出降取樣在頻域做了什麼,可以把 $x_d[n]$ 拆成兩個步驟:(1) 把 $x[n]$ 乘上週期性的取樣串 $c_M[n] = \frac{1}{M}\sum_{i=0}^{M-1} e^{j2\pi i n/M}$,它在 $n$ 為 $M$ 的倍數時等於 1、其餘為 0;(2) 把那些零丟掉。步驟 (1) 得到 $\tilde{x}[n] = x[n]\,c_M[n]$,其 DTFT 是 $X(e^{j\omega})$ 的 $M$ 個平移複本的平均;步驟 (2) 則把頻率軸縮放 $M$ 倍。結果是:ダウンサンプリングが周波数領域で何をしているかを見るには、$x_d[n]$ を二段階の演算として書けばよい。(1) $x[n]$ に周期的な標本化列 $c_M[n] = \frac{1}{M}\sum_{i=0}^{M-1} e^{j2\pi i n/M}$ を掛ける。これは $n$ が $M$ の倍数のとき 1、それ以外では 0 となる。(2) その零を捨てる。段階 (1) からは $\tilde{x}[n] = x[n]\,c_M[n]$ が得られ、その DTFT は $X(e^{j\omega})$ を平行移動した $M$ 個の複製の平均である。段階 (2) は周波数軸を $M$ 倍に伸縮する。結果は次のとおり:
Equivalently, in terms of the original continuous-time spectrum $X_c(j\Omega)$, the downsampled sequence looks exactly like sampling with period $MT$:等價地,若用原本的連續時間頻譜 $X_c(j\Omega)$ 來看,降取樣後的序列就等同於以週期 $MT$ 取樣:同じことを元の連続時間スペクトル $X_c(j\Omega)$ の言葉で言えば、ダウンサンプリングされた系列は、周期 $MT$ で標本化したものとまったく同じに見える:
$X_d(e^{j\omega})$ is built from $M$ copies of $X(e^{j\omega})$, each frequency-scaled (stretched) by $M$(頻率軸被拉寬 $M$ 倍), shifted by integer multiples of $2\pi$, and scaled in amplitude by $1/M$. A band edge that sat at $\omega_N$ before downsampling moves out to $M\omega_N$ after.$X_d(e^{j\omega})$ 是由 $X(e^{j\omega})$ 的 $M$ 個複本組成的,每個複本都被在頻率軸上拉寬 $M$ 倍、平移 $2\pi$ 的整數倍,並且振幅縮小為 $1/M$。降取樣前位於 $\omega_N$ 的頻帶邊界,降取樣後會外移到 $M\omega_N$。$X_d(e^{j\omega})$ は $X(e^{j\omega})$ の $M$ 個の複製から組み立てられる。各複製は周波数軸上で $M$ 倍に引き伸ばされ(周波数軸が $M$ 倍に広がる)、$2\pi$ の整数倍だけ平行移動され、さらに振幅が $1/M$ 倍される。ダウンサンプリング前に $\omega_N$ にあった帯域端は、変換後には $M\omega_N$ まで外へ移る。
The two boxes above are the same spectrum written from two different starting points. Knowing how they connect is what makes the $1/M$ and the "only $M$ copies" stop looking arbitrary.上面兩個方框寫的是同一個頻譜,只是出發點不同。把兩者的關係弄清楚之後,那個 $1/M$ 以及「只有 $M$ 份複本」就不再像是憑空冒出來的了。上の二つの枠は、出発点が違うだけで同じスペクトルを書いたものである。両者のつながりを押さえれば、あの $1/M$ と「複製は $M$ 個だけ」という話が、どこからともなく降ってきたものには見えなくなる。
| View 1 — from $X_c(j\Omega)$ | View 2 — from $X(e^{j\omega})$ | |
|---|---|---|
| Starting point | the analog spectrum | the sequence you actually hold |
| Number of copies | infinitely many ($r \in \mathbb{Z}$) | exactly $M$ ($i = 0,\dots,M-1$) |
| Copy spacing | the new sampling rate $2\pi/T_d$ on the $\Omega$ axis | $2\pi$ on the output $\omega$ axis |
| Amplitude factor | $1/T_d = 1/(MT)$ | $1/M$ |
| Usable when | you know $X_c$ | always |
| 看法 1 — 從 $X_c(j\Omega)$ 出發 | 看法 2 — 從 $X(e^{j\omega})$ 出發 | |
|---|---|---|
| 起點 | 類比頻譜 | 你手上真正有的那個序列 |
| 複本數目 | 無限多份($r \in \mathbb{Z}$) | 剛好 $M$ 份($i = 0,\dots,M-1$) |
| 複本間隔 | $\Omega$ 軸上的新取樣角頻率 $2\pi/T_d$ | 輸出 $\omega$ 軸上的 $2\pi$ |
| 振幅因子 | $1/T_d = 1/(MT)$ | $1/M$ |
| 什麼時候能用 | 你知道 $X_c$ 的時候 | 永遠可用 |
| 見方 1 — $X_c(j\Omega)$ から出発する | 見方 2 — $X(e^{j\omega})$ から出発する | |
|---|---|---|
| 出発点 | アナログスペクトル | 実際に手もとにある系列 |
| 複製の個数 | 無限個($r \in \mathbb{Z}$) | ちょうど $M$ 個($i = 0,\dots,M-1$) |
| 複製の間隔 | $\Omega$ 軸上の新しい標本化角周波数 $2\pi/T_d$ | 出力の $\omega$ 軸上で $2\pi$ |
| 振幅の因子 | $1/T_d = 1/(MT)$ | $1/M$ |
| 使える条件 | $X_c$ が分かっているとき | つねに使える |
View 1 needs no new derivation: downsampling is sampling $x_c(t)$ directly with period $T_d = MT$, so substitute $T \to T_d$ in the sampling formula and read off three things — the frequency axis is scaled through $\omega = \Omega T_d$, the copies are shifted by integer multiples of $2\pi/T_d$ on the analog axis, and there is an infinite set of them. It is the more intuitive picture, but in practice you hold only $x[n]$ and may have no access to $X_c$ at all. Hence view 2.看法 1 不需要任何新的推導:降取樣就是以週期 $T_d = MT$ 直接對 $x_c(t)$ 取樣,所以只要把取樣公式裡的 $T$ 換成 $T_d$,就能讀出三件事——頻率軸透過 $\omega = \Omega T_d$ 被縮放、各複本在類比軸上平移 $2\pi/T_d$ 的整數倍、而且複本有無限多份。這個畫面比較直觀,但實務上你手上只有 $x[n]$,甚至可能根本拿不到 $X_c$。所以才需要看法 2。見方 1 には新しい導出は要らない。ダウンサンプリングとは、周期 $T_d = MT$ で $x_c(t)$ を直接標本化することそのものだから、標本化の公式で $T \to T_d$ と置き換えれば三つのことが読み取れる——周波数軸は $\omega = \Omega T_d$ を通して伸縮され、複製はアナログ軸上で $2\pi/T_d$ の整数倍だけ平行移動し、しかもその個数は無限である。こちらのほうが直観的な絵だが、実務で手もとにあるのは $x[n]$ だけで、$X_c$ にはまったく手が届かないこともある。だから見方 2 が要る。
The whole trick is to split the summation index. Every integer $r$ decomposes uniquely as整個訣竅就在於把求和的索引拆開。任何整數 $r$ 都可以唯一地分解成要点は総和の添字を分解することに尽きる。任意の整数 $r$ は一意に次のように分解できる
(For $M = 3$, $r = 7$ is $i = 1$, $k = 2$.) Substituting into view 1 with $T_d = MT$ and grouping the $k$-sum inside the $i$-sum:(當 $M = 3$ 時,$r = 7$ 就是 $i = 1$、$k = 2$。)代入看法 1 並取 $T_d = MT$,再把對 $k$ 的求和收進對 $i$ 的求和裡:($M = 3$ なら $r = 7$ は $i = 1$、$k = 2$ である。)見方 1 に $T_d = MT$ を代入し、$k$ についての和を $i$ についての和の内側にまとめると:
Put $\omega' = (\omega - 2\pi i)/M$, so that $\dfrac{\omega - 2\pi i}{MT} = \dfrac{\omega'}{T}$. The bracket is then exactly the sampling formula for $X(e^{j\omega'})$ — the spectrum of the sequence before downsampling. Therefore令 $\omega' = (\omega - 2\pi i)/M$,於是 $\dfrac{\omega - 2\pi i}{MT} = \dfrac{\omega'}{T}$。中括號裡的東西就正好是 $X(e^{j\omega'})$ 的取樣公式——也就是降取樣之前那個序列的頻譜。因此$\omega' = (\omega - 2\pi i)/M$ と置くと $\dfrac{\omega - 2\pi i}{MT} = \dfrac{\omega'}{T}$ となる。すると角括弧の中身は、ちょうど $X(e^{j\omega'})$ に対する標本化の公式——すなわちダウンサンプリング前の系列のスペクトル——そのものである。したがって
Take the infinitely many $X_c$ copies and deal them into $M$ piles by $r \bmod M$. Each pile assembles into exactly one complete $X(e^{j\omega})$. Nothing was added or discarded — the infinite sum was only rebracketed, which is why both expressions must give the same answer.把無限多份 $X_c$ 複本按照 $r \bmod M$ 發成 $M$ 疊。每一疊剛好湊成一個完整的 $X(e^{j\omega})$。過程中沒有增加也沒有丟掉任何東西——那個無窮級數只是被重新加了括號,所以兩個式子必然給出同樣的結果。無限個ある $X_c$ の複製を、$r \bmod M$ にしたがって $M$ 個の山に配る。どの山もちょうど一つの完全な $X(e^{j\omega})$ を組み上げる。何も足されず、何も捨てられていない——無限和は括弧をつけ直されただけであり、だからこそ二つの式は同じ答えを与えなければならない。
| Action | What it does |
|---|---|
| 1. Stretch by $M$ | $X(e^{j\omega/M})$ widens the spectrum on the $\omega$ axis: a component that sat at $\omega_0$ moves out to $M\omega_0$. |
| 2. Shift | The $i$-th copy has its argument shifted by $2\pi i/M$. On the output $\omega$ axis this places one copy every $2\pi$. |
| 3. Scale by $1/M$ | Each copy's height is divided by $M$ — the averaging of $M$ copies. |
| 動作 | 它做了什麼 |
|---|---|
| 1. 拉寬 $M$ 倍 | $X(e^{j\omega/M})$ 把頻譜在 $\omega$ 軸上拉寬:原本在 $\omega_0$ 的成分會移到 $M\omega_0$。 |
| 2. 平移 | 第 $i$ 個複本的引數平移了 $2\pi i/M$。換到輸出的 $\omega$ 軸上看,就是每隔 $2\pi$ 放一份。 |
| 3. 高度乘 $1/M$ | 每一份複本的高度都除以 $M$——這就是 $M$ 份複本取平均的結果。 |
| 動作 | その内容 |
|---|---|
| 1. $M$ 倍に引き伸ばす | $X(e^{j\omega/M})$ はスペクトルを $\omega$ 軸上で広げる:$\omega_0$ にあった成分は $M\omega_0$ へ移る。 |
| 2. 平行移動する | $i$ 番目の複製は偏角が $2\pi i/M$ だけずれる。出力の $\omega$ 軸で見れば、$2\pi$ ごとに複製が一つ置かれることになる。 |
| 3. $1/M$ 倍する | 各複製の高さは $M$ で割られる——$M$ 個の複製を平均することに対応する。 |
Actions 1 and 2 have to come as a pair, and the reason is periodicity. $X(e^{j\omega})$ is $2\pi$-periodic; stretching it by $M$ would make it $2\pi M$-periodic, which a DTFT is not allowed to be. The $M-1$ shifted copies drop into exactly those gaps and restore the period to $2\pi$. Take $M = 2$: stretching gives period $4\pi$ with a hole between $\pi$ and $3\pi$, and the single shifted copy ($i=1$) fills it.動作 1 與動作 2 必須成對出現,理由是週期性。$X(e^{j\omega})$ 的週期是 $2\pi$;把它拉寬 $M$ 倍之後週期會變成 $2\pi M$,但 DTFT 不可能是這樣。那 $M-1$ 份平移過的複本,正好落進那些空隙裡,把週期還原成 $2\pi$。以 $M = 2$ 為例:拉寬後週期變成 $4\pi$,在 $\pi$ 與 $3\pi$ 之間留下一個空洞,而唯一那份平移的複本($i=1$)剛好補上。動作 1 と動作 2 は必ず対で現れる。理由は周期性である。$X(e^{j\omega})$ は $2\pi$ 周期であり、これを $M$ 倍に引き伸ばすと $2\pi M$ 周期になってしまうが、DTFT がそうなることは許されない。$M-1$ 個の平行移動された複製がちょうどその隙間に落ち込み、周期を $2\pi$ に戻す。$M = 2$ で見てみよう:引き伸ばしによって周期は $4\pi$ となり $\pi$ と $3\pi$ のあいだに空白ができるが、ただ一つの平行移動された複製($i=1$)がそこを埋める。
This also re-derives the no-aliasing condition in one line. After stretching, the band occupies $M\omega_N$, so the copies stay clear of one another exactly when這同時也用一行就重新導出了避免混疊的條件。拉寬之後頻帶占據 $M\omega_N$,所以各複本彼此不相干擾的條件恰好是これは同時に、エイリアシングが起きない条件を一行で導き直してもいる。引き伸ばしたあと帯域は $M\omega_N$ を占めるので、複製どうしが互いに重ならないのは、ちょうど次の場合である
— the condition of §7.2.3. If it fails, lowpass-filter with cutoff $\pi/M$ first; that cascade is decimation.——正是 §7.2.3 的條件。若不滿足,就要先用截止頻率 $\pi/M$ 的低通濾波器處理;這個串接就是抽取(decimation)。——これが §7.2.3 の条件である。満たされない場合は、まず遮断周波数 $\pi/M$ の低域通過フィルタをかける。この縦続接続こそが間引き(decimation)である。
From Fig. 7-3, downsampling is alias-free only when the original spectrum leaves room to be stretched:從圖 7-3 可以看出,只有當原始頻譜留有足夠空間可供拉寬時,降取樣才不會產生混疊:図 7-3 から分かるように、ダウンサンプリングがエイリアシングを免れるのは、元のスペクトルが引き伸ばされるだけの余地を残しているときだけである:
In digital frequency: the highest frequency present in $x[n]$, $\omega_N = \Omega_N T$, must satisfy $\omega_N < \dfrac{\pi}{M}$.換成數位頻率:$x[n]$ 的最高頻率 $\omega_N = \Omega_N T$ 必須滿足 $\omega_N < \dfrac{\pi}{M}$。ディジタル周波数で言えば、$x[n]$ に含まれる最高周波数 $\omega_N = \Omega_N T$ は次を満たさなければならない:$\omega_N < \dfrac{\pi}{M}$.
The boxed condition above writes $\le$ rather than $<$ because at exactly $\omega_N = \pi/M$ the stretched replicas only touch at $\pi$ and do not overlap — the middle panel of Fig. 7-3. The strict $<$ is the design-safe form: it leaves a margin instead of relying on a boundary that any filter roll-off or frequency drift would cross.上面方框內寫的是 $\le$ 而不是 $<$,是因為在 $\omega_N = \pi/M$ 恰好相等時,被拉寬的複本只是在 $\pi$ 處相接而不重疊——就是圖 7-3 中間那一張。嚴格的 $<$ 則是設計上安全的寫法:它留了餘裕,而不是把希望托在一個只要濾波器有滾降、或頻率有漂移就會跨過的邊界上。上の枠内の条件が $<$ ではなく $\le$ と書かれているのは、ちょうど $\omega_N = \pi/M$ のとき、引き伸ばされた複製は $\pi$ で接するだけで重なり合わないからである——図 7-3 の中央の図がそれにあたる。設計上安全な書き方は厳密な $<$ のほうである。フィルタのロールオフや周波数のずれがあればすぐに越えてしまう境界に頼るのではなく、余裕を残しておくという意味である。
If $x[n]$ is not bandlimited to $\pi/M$, we must lowpass-filter first. The cascade of an ideal lowpass filter (gain 1, cutoff $\pi/M$) and the compressor $\downarrow M$ is called a decimator(十中抽一器/降頻器), and the whole operation decimation(抽取). The prefilter deliberately throws away the band $|\omega| > \pi/M$ so that the surviving band comes through clean.如果 $x[n]$ 沒有帶限在 $\pi/M$ 以內,就必須先做低通濾波。把一個理想低通濾波器(增益 1、截止頻率 $\pi/M$)與壓縮器 $\downarrow M$ 串接起來,就稱為抽取器(decimator),整個運算則稱為抽取(decimation)。前置濾波器是刻意把 $|\omega| > \pi/M$ 這一段丟掉,好讓留下來的那一段能乾乾淨淨地通過。$x[n]$ が $\pi/M$ に帯域制限されていない場合には、まず低域通過フィルタをかけなければならない。理想低域通過フィルタ(利得 1、遮断周波数 $\pi/M$)と圧縮器 $\downarrow M$ を縦続接続したものを間引き器(decimator)と呼び、この演算全体を間引き(decimation)と呼ぶ。前置フィルタは $|\omega| > \pi/M$ の帯域をあえて捨て、残った帯域がきれいに通るようにする。
Once spectral copies overlap and add, no later processing can separate them — the folded
high-frequency energy is permanently mixed into the low band. This is exactly the difference between MATLAB's
downsample (no protection) and decimate (lowpass first) demonstrated below.一旦頻譜複本重疊並相加,之後任何處理都無法把它們分開——被反摺下來的高頻能量已經永久混進低頻帶裡了。所以重新取樣前務必確認高頻成分:高頻會反摺(fold)到低頻,與其他低頻成分混在一起。這正是下面要示範的 MATLAB downsample(毫無保護)與 decimate(先低通)之間的差別。スペクトルの複製がいったん重なって加算されてしまうと、その後どんな処理をしても両者を分離することはできない——折り返された高周波のエネルギーは低域に永久に混ざり込む。これはまさに、以下で示す MATLAB の downsample(保護なし)と decimate(先に低域通過)の違いそのものである。
downsample folds the 100 Hz tone to a false 25 Hz tone; decimate removes it with the prefilter first(downsample 讓 100 Hz 假冒成 25 Hz;decimate 先低通把它濾掉).圖 7-4 — 實際示範:$x[n]=\sin(2\pi 20t)+\sin(2\pi 100t)$ 以 1000 Hz 取樣,再用 $M=8$ 把取樣率降到 125 Hz(Nyquist 頻率 62.5 Hz)。單純的 downsample 把 100 Hz 的音反摺成一個假的 25 Hz 音;decimate 則先用前置濾波器把它濾掉。図 7-4 — 実例による確認:$x[n]=\sin(2\pi 20t)+\sin(2\pi 100t)$ を 1000 Hz で標本化し、$M=8$ によってレートを 125 Hz(ナイキスト周波数 62.5 Hz)まで下げる。素の downsample は 100 Hz の音を偽の 25 Hz の音へ折り返してしまうが、decimate は前置フィルタで先にそれを取り除く。To raise the sampling rate we want $x_i[n] = x_c(nT_i)$ with $T_i = T/L$ — i.e. we must create $L-1$ new samples between every pair of existing ones. The first stage is the sampling-rate expander(取樣率擴張器) $\uparrow L$, which inserts $L-1$ zeros between samples:要提高取樣率,我們想得到 $x_i[n] = x_c(nT_i)$,其中 $T_i = T/L$——也就是必須在每一對既有樣本之間製造出 $L-1$ 個新樣本。第一級是取樣率擴張器 $\uparrow L$,它在樣本之間插入 $L-1$ 個零:標本化レートを上げるには、$T_i = T/L$ として $x_i[n] = x_c(nT_i)$ を得たい——つまり、既存の標本の各対のあいだに $L-1$ 個の新しい標本を作り出さなければならない。その第一段が標本化レート拡張器(expander) $\uparrow L$ であり、標本と標本のあいだに $L-1$ 個の零を挿入する:
The DTFT of the zero-stuffed sequence follows directly from the definition:補零後序列的 DTFT 可以直接由定義得出:零詰めされた系列の DTFT は、定義から直ちに得られる:
The spectrum is frequency-compressed by $L$(頻譜被壓縮 $L$ 倍): the baseband copy now occupies $|\omega| \le \omega_N/L$, but the $2\pi$-periodicity of the original spectrum drags in $L-1$ extra copies — images(鏡像) — centered at $\omega = 2\pi i/L,\ i = 1,\dots,L-1$. No information is lost (zero insertion is invertible); the images are simply unwanted and must be filtered away.頻譜被在頻率軸上壓縮 $L$ 倍:基頻的那個複本現在只佔 $|\omega| \le \omega_N/L$,但原始頻譜本身的 $2\pi$ 週期性,會把另外 $L-1$ 個複本一起拉進來——這些就是映像(images),中心位於 $\omega = 2\pi i/L,\ i = 1,\dots,L-1$。過程中沒有損失任何資訊(補零是可逆的);這些映像只是我們不想要的東西,必須用濾波器去掉。スペクトルは周波数軸上で $L$ 倍に圧縮される(周波数軸は $L$ 分の 1 に縮む)。基底帯域の複製はいまや $|\omega| \le \omega_N/L$ を占めるが、元のスペクトルがもつ $2\pi$ 周期性が $L-1$ 個の余分な複製——イメージ(images)——を引き込み、その中心は $\omega = 2\pi i/L,\ i = 1,\dots,L-1$ にある。情報は何も失われない(零挿入は可逆である)。イメージは単に不要なものであり、フィルタで取り除かなければならない。
The lecture draws the same story in four stacked panels, with the image bands shaded. Panel by panel:投影片把同一件事畫成上下疊起來的四格,並把映像的頻帶塗色標出來。一格一格看:講義ではこれと同じ話を、上下に積んだ四つの図で描き、イメージの帯域に色を付けている。一段ずつ見ていこう:
The ideal anti-imaging filter has gain $L$ and cutoff $\pi/L$:理想的去鏡像濾波器增益為 $L$、截止頻率為 $\pi/L$:理想のアンチイメージングフィルタは、利得 $L$、遮断周波数 $\pi/L$ をもつ:
$H_i(e^{j\omega})$ is an ideal lowpass filter(理想低通濾波器), and the name is a literal description of the two cases above: the passband(通帶) $|\omega| < \pi/L$ sits around $\omega = 0$ and is kept (scaled by $L$), while the stopband(止帶) $\pi/L \le |\omega| \le \pi$ is zeroed. It passes the low frequencies and blocks everything above the cutoff $\omega_c = \pi/L$.$H_i(e^{j\omega})$ 是一個理想低通濾波器,而這個名字就是上面那兩個 case 的字面描述:通帶 $|\omega| < \pi/L$ 落在 $\omega = 0$ 附近,會被保留下來(並乘上增益 $L$);止帶 $\pi/L \le |\omega| \le \pi$ 則被歸零。也就是「讓低頻通過、把截止頻率 $\omega_c = \pi/L$ 以上全部擋掉」。$H_i(e^{j\omega})$ は理想低域通過フィルタであり、その名前は上の二つの場合分けをそのまま言い表したものである。通過帯域 $|\omega| < \pi/L$ は $\omega = 0$ のまわりにあって保たれ($L$ 倍される)、阻止帯域 $\pi/L \le |\omega| \le \pi$ は零にされる。低い周波数を通し、遮断周波数 $\omega_c = \pi/L$ より上をすべて阻止するわけである。
Upsampling needs exactly that shape. Zero insertion gives $X_e(e^{j\omega}) = X(e^{j\omega L})$ — the original spectrum compressed by $L$ — which leaves the baseband copy inside $|\omega| \le \pi/L$ and the $L-1$ unwanted images(映像) outside it (Fig. 7-7). The images are the high-frequency content, so a lowpass with cutoff $\pi/L$ keeps the baseband copy and deletes every image at once. That is what turns the jagged zero-stuffed sequence into a smooth interpolated one; the gain $L$ then restores the amplitude.升取樣需要的正是這個形狀。補零之後 $X_e(e^{j\omega}) = X(e^{j\omega L})$——原頻譜被壓縮了 $L$ 倍——基頻那一份落在 $|\omega| \le \pi/L$ 之內,而 $L-1$ 個不要的映像落在它外面(見圖 7-7)。這些映像就是高頻成分,所以一個截止頻率為 $\pi/L$ 的低通濾波器,一次就能留下基頻、刪掉所有映像。這就是把補零後鋸齒狀的序列變成平滑內插訊號的原因;而增益 $L$ 再把振幅補回正確值。アップサンプリングが必要とするのは、まさにこの形である。零挿入によって $X_e(e^{j\omega}) = X(e^{j\omega L})$——元のスペクトルを $L$ 倍に圧縮したもの——が得られ、基底帯域の複製は $|\omega| \le \pi/L$ の内側に、不要な $L-1$ 個のイメージはその外側に残る(図 7-7)。イメージこそが高周波成分なので、遮断周波数 $\pi/L$ の低域通過フィルタは基底帯域の複製を残したまま、すべてのイメージを一度に消し去る。これが、ぎざぎざの零詰め系列を滑らかな補間信号へ変えるものである。そのあと利得 $L$ が振幅を元に戻す。
The response above is a perfect brick wall(磚牆): zero transition width and infinite
stopband attenuation. That is why its impulse response is the sinc on the right of the equation,
and a sinc is infinitely long and non-causal ($h_i[n] \ne 0$
for $n < 0$) — so the ideal filter can never be implemented exactly. A real interpolator uses
a finite FIR approximation instead: a windowed sinc (fir1), an equiripple
Parks–McClellan design (firpm), or a ready-made interp /
upfirdn. The approximation trades the brick wall for a narrow but nonzero
transition band and a finite stopband attenuation, so a little image energy always leaks
through. §7.3.4 takes this to the crude extreme with the zero-order hold and the linear
interpolator.上面那個響應是一面完美的磚牆(brick wall):過渡帶寬度為零、止帶衰減無限大。正因如此,它的脈衝響應才會是等式右邊那個 sinc,而 sinc 是無限長且非因果的($n < 0$ 時 $h_i[n] \ne 0$)——所以理想濾波器永遠無法被精確實現。實際的內插器改用有限長的 FIR 近似:加窗的 sinc(fir1)、等漣波的 Parks–McClellan 設計(firpm),或是現成的 interp/upfirdn。這些近似把磚牆換成一段很窄但不為零的過渡帶與有限的止帶衰減,因此總會有一點映像能量漏過去。§7.3.4 會把這件事推到最粗糙的極端:零階保持與線性內插。上の応答は完全なブリックウォール(brick wall)である。遷移帯域の幅は零、阻止帯域の減衰は無限大。だからこそそのインパルス応答は式の右辺の sinc になるのだが、sinc は無限に長く、しかも非因果的($n < 0$ でも $h_i[n] \ne 0$)である——したがって理想フィルタを厳密に実現することはできない。実際の補間器は、そのかわりに有限長の FIR 近似を用いる。窓をかけた sinc(fir1)、等リップルの Parks–McClellan 設計(firpm)、あるいは出来合いの interp/upfirdn である。この近似はブリックウォールを、狭いが零ではない遷移帯域と有限の阻止帯域減衰に置き換えるので、わずかなイメージのエネルギーはつねに漏れ出る。§7.3.4 では、零次ホールドと線形補間器によってこれを最も粗い極端まで押し進める。
Panel (d) is a product in frequency, and multiplication in frequency is convolution in time — so the same step written in the time domain is $x_i[n] = x_e[n] * h_i[n]$, with the kernel being the impulse response of the filter in panel (c). That convolution is the discrete-time version of Shannon sinc interpolation (the formula on slide 17):(d) 格在頻域是一個乘法,而頻域相乘就是時域摺積——所以同一個步驟寫在時域就是 $x_i[n] = x_e[n] * h_i[n]$,其中的核正是 (c) 格那個濾波器的脈衝響應。這個摺積就是 Shannon sinc 內插的離散時間版本(投影片第 17 頁的公式):(d) の段は周波数領域での積であり、周波数領域での掛け算は時間領域での畳み込みである——だから同じ段階を時間領域で書けば $x_i[n] = x_e[n] * h_i[n]$ となり、その核はまさに (c) の段のフィルタのインパルス応答である。この畳み込みこそが、シャノンの sinc 補間の離散時間版(スライド 17 の式)である:
The two lines say the same thing. The first is the convolution sum verbatim, running over every index of the zero-stuffed sequence. But $x_e[k]$ is nonzero only at multiples of $L$, where $x_e[mL] = x[m]$, so all but every $L$-th term vanishes: substituting $k = mL$ and renaming $m \to k$ gives the second line. The first form is written in terms of the sequence that actually enters the filter, the second in terms of the original samples you started from — and both are "delete the shaded image bands", seen in the time domain.這兩行說的是同一件事。第一行就是摺積和的原樣,對補零序列的每一個索引求和。但 $x_e[k]$ 只有在 $L$ 的倍數上才不為零,且 $x_e[mL] = x[m]$,所以除了每第 $L$ 項以外全部消失:代入 $k = mL$ 再把 $m$ 改名為 $k$,就得到第二行。第一種寫法是用「真正進到濾波器裡的那個序列」來表示,第二種則是用「你一開始手上的原樣本」來表示——而兩者都是同一件事:在時域看到的「把塗色的映像頻帶刪掉」。この二行は同じことを言っている。第一行は畳み込み和をそのまま書いたもので、零詰め系列のすべての添字にわたって和をとる。しかし $x_e[k]$ が零でないのは $L$ の倍数のところだけで、そこでは $x_e[mL] = x[m]$ であるから、$L$ 個おきの項を除いてすべて消える。$k = mL$ を代入し $m \to k$ と名前を付け替えれば、第二行が得られる。第一の表現は実際にフィルタへ入る系列の言葉で書かれ、第二の表現は出発点となった元の標本の言葉で書かれている——そしてどちらも、時間領域から見た「色付きのイメージ帯域を消す」という同じ操作である。
Two properties follow immediately, because $h_i[0]=1$ and $h_i[kL]=0$ for $k \ne 0$:由於 $h_i[0]=1$ 且當 $k \ne 0$ 時 $h_i[kL]=0$,立刻可以得到兩個性質:$h_i[0]=1$ であり、$k \ne 0$ のとき $h_i[kL]=0$ であることから、二つの性質が直ちに従う:
It is worth reading the second form of the sum once more, because it says something very concrete. Write it as a superposition:值得再讀一次那個和式的第二種寫法,因為它說的事情非常具體。把它寫成疊加的形式:この和の第二の表現をもう一度読む価値がある。きわめて具体的なことを言っているからである。重ね合わせの形に書いてみよう:
Each original sample $x[k]$ plants one sinc pulse, centered at its own new position $kL$ and scaled by its own value. The output at any index $n$ is the sum of all those overlapping pulses read at $n$. The expander does not create any values — it only makes room, moving $x[k]$ to position $kL$ and leaving $L-1$ empty slots between neighbors. The filter is what fills those slots.每一個原始樣本 $x[k]$ 都種下一個 sinc 脈衝,中心落在它自己的新位置 $kL$,高度按它自己的值縮放。任何索引 $n$ 上的輸出,就是所有這些互相重疊的脈衝在 $n$ 處的總和。擴張器並沒有造出任何值——它只是挪出空間,把 $x[k]$ 搬到位置 $kL$,並在相鄰兩者之間留下 $L-1$ 個空格。真正把空格填起來的是濾波器。元の標本 $x[k]$ はそれぞれ、自分の新しい位置 $kL$ を中心とし、自分の値で振幅を決めた sinc パルスを一つ植える。任意の添字 $n$ における出力は、それら重なり合うパルスをすべて $n$ で読んだ値の総和である。拡張器は値を何も作り出さない——ただ場所を空け、$x[k]$ を位置 $kL$ へ移し、隣り合う標本のあいだに $L-1$ 個の空きを残すだけである。その空きを埋めるのがフィルタである。
Why the original samples survive is now visible in one line: $h_i[0]=1$ while $h_i[\pm L] = h_i[\pm 2L] = \dots = 0$. At $n = kL$ exactly one pulse — the one belonging to $x[k]$ — is at its peak, and every other pulse is crossing zero. Hence $x_i[kL] = x[k]$.原始樣本為什麼能原封不動保留下來,現在一行就看得出來:$h_i[0]=1$,而 $h_i[\pm L] = h_i[\pm 2L] = \dots = 0$。在 $n = kL$ 上恰好只有一個脈衝——屬於 $x[k]$ 的那一個——正處於峰值,其他每個脈衝都剛好過零。因此 $x_i[kL] = x[k]$。元の標本がなぜそのまま残るのかは、いまや一行で見える。$h_i[0]=1$ である一方、$h_i[\pm L] = h_i[\pm 2L] = \dots = 0$ である。$n = kL$ ではちょうど一つのパルス——$x[k]$ に属するもの——がピークにあり、他のパルスはすべて零を横切っている。ゆえに $x_i[kL] = x[k]$ となる。
At an in-between index the neighboring sincs are not zero, so the output is a weighted mix of nearby original samples. For $L=3$ and $n=1$, evaluating $h_i$ at the distances $1, 2, 4, 5$ gives但在兩者之間的索引上,鄰近的 sinc 不為零,所以輸出是附近若干原始樣本的加權混合。以 $L=3$、$n=1$ 為例,把 $h_i$ 在距離 $1, 2, 4, 5$ 上求值,得到あいだの添字では隣接する sinc は零でないので、出力は近傍の元の標本の重み付き混合になる。$L=3$、$n=1$ の場合、距離 $1, 2, 4, 5$ で $h_i$ を評価すると
The nearest sample carries the largest weight; samples farther away contribute smaller corrections, sometimes negative. Those alternating-sign tails are exactly what makes the result land on the smooth bandlimited(帶限) curve through the original samples, rather than on the straight chords a linear interpolator would draw.最近的樣本權重最大;比較遠的樣本給出較小的修正,而且有時是負的。正是這些正負交替的尾巴,讓結果落在通過原始樣本的那條平滑帶限曲線上,而不是落在線性內插會畫出的直線弦上。最も近い標本が最大の重みをもち、遠い標本は小さな補正を、ときに負の値で与える。この符号が交互に入れ替わる裾こそが、結果を、元の標本を通る滑らかな帯域制限された曲線の上に乗せるものであって、線形補間器が描くような直線の弦の上には乗せないのである。
The same operation, seen from the two domains:同一個運算,從兩個域分別來看:同じ演算を、二つの領域から見てみよう:
| Domain | What happens |
|---|---|
| Time | Each original sample emits a sinc centered at $kL$; the overlapping sincs add up and fill the inserted zeros smoothly, while leaving the originals untouched at $n=kL$. |
| Frequency | The lowpass removes the images (the shaded bands of Fig. 7-7), leaving only the baseband spectrum. |
| 域 | 發生了什麼 |
|---|---|
| 時域 | 每個原始樣本送出一個以 $kL$ 為中心的 sinc;這些重疊的 sinc 相加之後,平滑地把補進去的零填滿,同時在 $n=kL$ 處不動到原樣本。 |
| 頻域 | 低通濾波器移除映像(圖 7-7 裡塗色的頻帶),只留下基頻的頻譜。 |
| 領域 | そこで起きること |
|---|---|
| 時間領域 | 元の標本はそれぞれ $kL$ を中心とする sinc を放ち、重なり合った sinc が加算されて、挿入された零を滑らかに埋める。その一方で $n=kL$ にある元の標本には手を触れない。 |
| 周波数領域 | 低域通過フィルタがイメージ(図 7-7 の色付きの帯域)を取り除き、基底帯域のスペクトルだけを残す。 |
The two are the same statement: smooth in time means no high-frequency images in frequency. That is why a lowpass filter — and nothing more — is the interpolator. The gain $L$ is the bookkeeping that restores the amplitude lost when the same energy was spread over $L$ times as many samples.這兩句話其實是同一句:時域上平滑,就等於頻域上沒有高頻映像。這就是為什麼一個低通濾波器——不多不少——就是內插器。而增益 $L$ 只是把帳算回來:同樣的能量被攤到 $L$ 倍多的樣本上,振幅掉了 $L$ 倍,乘回去就對了。この二つは同じ主張である。時間領域で滑らかだということは、周波数領域に高周波のイメージがないということに等しい。だからこそ低域通過フィルタが——それ以上のものは要らず——補間器そのものである。利得 $L$ は帳尻合わせであり、同じエネルギーが $L$ 倍の個数の標本に広げられたときに失われた振幅を戻している。
The ideal sinc filter is infinitely long and non-causal, so practical systems use short approximations. The two classics:理想的 sinc 濾波器是無限長且非因果的,所以實際系統只能用簡短的近似。兩個經典做法:理想の sinc フィルタは無限に長く非因果的なので、実際の系では短い近似を使う。古典的なのは次の二つである:
The ZOH simply repeats each sample $L$ times (a staircase); the linear interpolator draws straight lines between samples (note $h_{\mathrm{lin}} = \tfrac{1}{L}\, h_{\mathrm{zoh}} * h_{\mathrm{zoh}}$, a triangle). Their frequency responses,ZOH 只是把每個樣本重複 $L$ 次(階梯狀);線性內插器則在樣本之間拉直線(注意 $h_{\mathrm{lin}} = \tfrac{1}{L}\, h_{\mathrm{zoh}} * h_{\mathrm{zoh}}$,是一個三角形)。它們的頻率響應,ZOH は各標本を単に $L$ 回繰り返すだけである(階段状になる)。線形補間器は標本と標本のあいだに直線を引く($h_{\mathrm{lin}} = \tfrac{1}{L}\, h_{\mathrm{zoh}} * h_{\mathrm{zoh}}$、すなわち三角形であることに注意)。それらの周波数応答は、
only approximate the ideal brick wall: the passband droops slightly and the images around $2\pi i/L$ are attenuated but not eliminated (the linear interpolator at least places spectral zeros exactly at the image centers $\omega = 2\pi i /L$). They work well when the signal is heavily oversampled, i.e. its energy is concentrated at $|\omega| \ll \pi$.只能近似理想的直角截止:通帶會略微下垂,而 $2\pi i/L$ 附近的映像只被衰減、並未消除(線性內插器至少把頻譜的零點剛好放在映像中心 $\omega = 2\pi i /L$ 上)。當訊號被大幅過取樣,也就是能量集中在 $|\omega| \ll \pi$ 時,它們的效果就很好。理想のブリックウォールを近似するにとどまる。通過帯域はわずかに垂れ下がり、$2\pi i/L$ のまわりのイメージは減衰こそするが消えはしない(線形補間器は少なくとも、スペクトルの零点をイメージの中心 $\omega = 2\pi i /L$ にちょうど置いてくれる)。信号が大きく過標本化されているとき、すなわちエネルギーが $|\omega| \ll \pi$ に集中しているときには、これらはよく働く。
A noninteger rate change is achieved by interpolating by $L$ first, then decimating by $M$, giving a new sampling period非整數的倍率轉換,做法是先內插 $L$ 倍、再抽取 $M$ 倍,得到新的取樣週期非整数のレート変換は、まず $L$ 倍に補間し、続いて $M$ 倍に間引くことで実現され、新しい標本化周期は次のようになる
In the cascade, the interpolation filter (gain $L$, cutoff $\pi/L$) and the decimation filter (gain 1, cutoff $\pi/M$) operate back-to-back at the same (high) rate, so they collapse into one lowpass filter taking the tighter of the two cutoffs:在這個串接中,內插濾波器(增益 $L$、截止 $\pi/L$)與抽取濾波器(增益 1、截止 $\pi/M$)背靠背地跑在同一個(高)取樣率上,所以兩者可以合併成一個低通濾波器,截止頻率取兩者中較嚴格的那一個:この縦続接続では、補間フィルタ(利得 $L$、遮断 $\pi/L$)と間引きフィルタ(利得 1、遮断 $\pi/M$)が同じ(高い)レートで背中合わせに動くので、両者は遮断周波数の厳しいほうをとった一つの低域通過フィルタにまとまる:
Filtering at the high rate $LT$ seems wasteful: most input samples of the filter are the
inserted zeros, and most output samples are immediately discarded by $\downarrow M$. A
polyphase implementation reorganizes the FIR filter into $L$ short subfilters so
that only the samples actually kept are ever computed. MATLAB's resample uses exactly
this ("using a polyphase implementation", per its help text) — that is why it is fast.在高取樣率 $LT$ 上做濾波看起來很浪費:濾波器的輸入樣本大多是補進去的零,而輸出樣本又大多立刻被 $\downarrow M$ 丟掉。多相(polyphase)實現把 FIR 濾波器重新組織成 $L$ 個短的子濾波器,使得只有真正會被保留的樣本才會被計算。MATLAB 的 resample 用的正是這個方法(其說明文字寫著「using a polyphase implementation」)——這就是它為什麼快。高いレート $LT$ でフィルタリングするのは無駄に見える。フィルタの入力標本の大半は挿入された零であり、出力標本の大半は直後に $\downarrow M$ によって捨てられるからである。多相(polyphase)実現は、FIR フィルタを $L$ 個の短い部分フィルタに組み替え、実際に残される標本だけが計算されるようにする。MATLAB の resample はまさにこれを用いており(ヘルプにも「using a polyphase implementation」とある)、それが速さの理由である。
y = resample(x, 3, 2); — and remember to rebuild the time axis: ty = (0:length(y)-1)/3000;MATLAB:y = resample(x, 3, 2);——並且別忘了重建時間軸:ty = (0:length(y)-1)/3000;MATLAB:y = resample(x, 3, 2);——そして時間軸を作り直すのを忘れないこと:ty = (0:length(y)-1)/3000;The lecture's running example: a signal sampled at 1000 Hz must be reduced to $1000/8 = 125$ Hz. Two one-line options exist, and they are not equivalent:課堂上一路使用的例子:一個以 1000 Hz 取樣的訊號,必須降到 $1000/8 = 125$ Hz。有兩種一行就能寫完的做法,而它們並不等價:講義を通して使われている例。1000 Hz で標本化された信号を $1000/8 = 125$ Hz まで落とさなければならない。一行で書ける方法が二つあるが、両者は等価ではない:
| Call | What it does | Aliasing protection |
|---|---|---|
down_signal = downsample(signal, 8); | keeps every 8th sample (pure compressor $\downarrow 8$) | None — high frequencies fold into the low band |
deci_signal = decimate(signal, 8); | lowpass-filters (8th-order Chebyshev Type I, cutoff $0.8\,(f_s/2)/8$, applied forward-backward), then keeps every 8th sample | Yes — band above the new Nyquist is removed first |
| 呼叫方式 | 它做了什麼 | 有無抗混疊保護 |
|---|---|---|
down_signal = downsample(signal, 8); | 保留每第 8 個樣本(純粹的壓縮器 $\downarrow 8$) | 沒有——高頻會反摺進低頻帶 |
deci_signal = decimate(signal, 8); | 先做低通濾波(8 階 Chebyshev I 型,截止頻率 $0.8\,(f_s/2)/8$,以前向—後向方式施加),再保留每第 8 個樣本 | 有——高於新 Nyquist 頻率的頻帶會先被移除 |
| 呼び出し | その内容 | エイリアシング保護 |
|---|---|---|
down_signal = downsample(signal, 8); | 8 個おきの標本だけを残す(純粋な圧縮器 $\downarrow 8$) | なし——高周波が低域へ折り返す |
deci_signal = decimate(signal, 8); | 低域通過フィルタ(8 次チェビシェフ I 型、遮断周波数 $0.8\,(f_s/2)/8$、前向き・後ろ向きに適用)をかけてから、8 個おきの標本を残す | あり——新しいナイキスト周波数より上の帯域が先に取り除かれる |
Watch for high-frequency content before resampling: anything above the new Nyquist frequency folds down and mixes with the genuine low-frequency components. decimate lowpass-filters before reducing the rate; downsample does not. If the signal has any energy above the new Nyquist frequency, use decimate
(or resample), never bare downsample.重新取樣要注意高頻成分的混疊!高頻成分會反摺到低頻、與其他低頻成分混合。decimate 會在降低取樣頻率之前先做低通濾波;downsample 不會。只要訊號在新的 Nyquist 頻率以上還有任何能量,就該用 decimate(或 resample),絕不要用光禿禿的 downsample。再標本化の前に高周波成分に注意すること。新しいナイキスト周波数より上にあるものはすべて折り返し、本物の低周波成分と混ざり合う。decimate はレートを下げる前に低域通過フィルタをかけるが、downsample はかけない。信号が新しいナイキスト周波数より上にわずかでもエネルギーをもつなら、decimate(あるいは resample)を使い、裸の downsample は決して使ってはならない。
Y = resample(X, P, Q) resamples X at $P/Q$ times the original rate
(polyphase implementation; length of Y is $\lceil P/Q \cdot \mathrm{length}(X)\rceil$). It applies an
anti-aliasing lowpass FIR filter during the conversion and compensates the filter delay.
[N, D] = rat(X, tol) returns integers with $|N/D - X| \le tol$ (continued-fraction
truncation; default tolerance $10^{-6}\,\lVert X\rVert_1$) — the standard way to get $P$ and $Q$
from a ratio of sampling rates:Y = resample(X, P, Q) 會把 X 重新取樣成原取樣率的 $P/Q$ 倍(採多相實現;Y 的長度為 $\lceil P/Q \cdot \mathrm{length}(X)\rceil$)。轉換過程中它會施加一個抗混疊低通 FIR 濾波器,並補償濾波器的延遲。[N, D] = rat(X, tol) 則回傳滿足 $|N/D - X| \le tol$ 的整數(以連分數截斷求得;預設容忍度為 $10^{-6}\,\lVert X\rVert_1$)——這是從兩個取樣率的比值求出 $P$ 與 $Q$ 的標準做法:Y = resample(X, P, Q) は X を元のレートの $P/Q$ 倍に再標本化する(多相実現。Y の長さは $\lceil P/Q \cdot \mathrm{length}(X)\rceil$ である)。変換の途中でアンチエイリアス低域通過 FIR フィルタをかけ、そのフィルタ遅延も補償する。[N, D] = rat(X, tol) は $|N/D - X| \le tol$ を満たす整数を返す(連分数の打ち切りによる。既定の許容値は $10^{-6}\,\lVert X\rVert_1$)——標本化レートの比から $P$ と $Q$ を求める標準的な方法である:
org_SR = 2000; % original rate (Hz) new_SR3 = 300; % target rate (Hz) [p, q] = rat(new_SR3/org_SR); % p = 3, q = 20 new_signal3 = resample(org_signal, p, q); new_taxis3 = (1:length(new_signal3))'/new_SR3; % REBUILD the time axis!
After resampling, the old time vector no longer matches the data length or spacing.
Always recompute it from the new sampling rate, e.g.
t_new = (1:length(y))'/new_SR; — forgetting this stretches or squeezes the waveform
on every later plot and analysis.重新取樣之後,舊的時間向量在長度與間距上都已經對不上資料了。務必用新的取樣率重新算一次,例如 t_new = (1:length(y))'/new_SR;——忘了這一步,之後每一張圖與每一項分析上的波形都會被拉長或壓扁。再標本化のあと、古い時間ベクトルはデータの長さにも間隔にももう合っていない。かならず新しい標本化レートから計算し直すこと。たとえば t_new = (1:length(y))'/new_SR; とする——これを忘れると、以後のすべての図と解析で波形が引き伸ばされたり押し縮められたりする。
| Function | Purpose(用途) |
|---|---|
interp(x, L) | 內插訊號以提高取樣頻率 — interpolate, rate × L (anti-imaging filter built in) |
decimate(x, M) | 低通濾波過後降低取樣頻率 — lowpass then rate ÷ M |
downsample(x, M) / upsample(x, L) | bare compressor / bare zero-insertion expander (no filters) |
resample(x, P, Q) | 執行 P 倍的 interp 提高取樣頻率,再執行 Q 倍的 decimate 降低取樣頻率 — rational P/Q change, polyphase |
rat(x, tol) | 找出最接近輸入數值的分數形式(P/Q)— rational approximation via continued fractions |
| 函式 | 用途 |
|---|---|
interp(x, L) | 內插訊號以提高取樣頻率——倍率 × L(已內建去鏡像濾波器) |
decimate(x, M) | 低通濾波過後降低取樣頻率——先低通,再 ÷ M |
downsample(x, M) / upsample(x, L) | 光禿禿的壓縮器/光禿禿的補零擴張器(都沒有濾波器) |
resample(x, P, Q) | 執行 P 倍的 interp 提高取樣頻率,再執行 Q 倍的 decimate 降低取樣頻率——有理數 P/Q 倍率轉換,多相實現 |
rat(x, tol) | 找出最接近輸入數值的分數形式(P/Q)——以連分數做有理數近似 |
| 関数 | 用途 |
|---|---|
interp(x, L) | 補間によって標本化周波数を上げる — レート × L(アンチイメージングフィルタ内蔵) |
decimate(x, M) | 低域通過フィルタをかけてから標本化周波数を下げる — 先に低域通過、そのうえでレート ÷ M |
downsample(x, M) / upsample(x, L) | 裸の圧縮器/裸の零挿入拡張器(どちらもフィルタなし) |
resample(x, P, Q) | P 倍の interp で標本化周波数を上げ、続いて Q 倍の decimate で下げる — 有理数 P/Q のレート変換、多相実現 |
rat(x, tol) | 入力の数値に最も近い分数の形(P/Q)を求める — 連分数による有理数近似 |
| Downsampling $\downarrow M$(降取樣) | Upsampling $\uparrow L$(升取樣) | |
|---|---|---|
| Sampling rate | reduced by $M$ | increased by $L$ |
| Sample period | increases: $T' = MT$ | decreases: $T' = T/L$ |
| With its lowpass filter, called | decimation(抽取) | interpolation(內插) |
| Spectrum | stretched by $M$, amplitude $\times \tfrac1M$, $M$ copies | compressed by $L$, $L-1$ images appear |
| Hazard | aliasing(混疊)— irreversible | imaging(鏡像)— removable |
| Filter | before $\downarrow M$: gain 1, cutoff $\pi/M$ | after $\uparrow L$: gain $L$, cutoff $\pi/L$ |
| Information | lost above $\pi/M$ | fully preserved |
| 降取樣 $\downarrow M$ | 升取樣 $\uparrow L$ | |
|---|---|---|
| 取樣率 | 降為 $1/M$ | 提高 $L$ 倍 |
| 取樣週期 | 變長:$T' = MT$ | 變短:$T' = T/L$ |
| 加上低通濾波器後稱為 | 抽取(decimation) | 內插(interpolation) |
| 頻譜 | 被拉寬 $M$ 倍、振幅 $\times \tfrac1M$、共 $M$ 個複本 | 被壓縮 $L$ 倍、出現 $L-1$ 個映像 |
| 風險 | 混疊(aliasing)——不可逆 | 映像(imaging)——可以濾掉 |
| 濾波器位置 | $\downarrow M$ 之前:增益 1、截止 $\pi/M$ | $\uparrow L$ 之後:增益 $L$、截止 $\pi/L$ |
| 資訊 | $\pi/M$ 以上的部分永久失去 | 完整保留 |
| ダウンサンプリング $\downarrow M$ | アップサンプリング $\uparrow L$ | |
|---|---|---|
| 標本化レート | $M$ 分の 1 になる | $L$ 倍になる |
| 標本周期 | 長くなる:$T' = MT$ | 短くなる:$T' = T/L$ |
| 低域通過フィルタを伴うときの呼び名 | 間引き(decimation) | 補間(interpolation) |
| スペクトル | $M$ 倍に引き伸ばされ、振幅は $\times \tfrac1M$、複製は $M$ 個 | $L$ 倍に圧縮され、$L-1$ 個のイメージが現れる |
| 危険 | エイリアシング — 不可逆 | イメージング — 取り除ける |
| フィルタ | $\downarrow M$ の前:利得 1、遮断 $\pi/M$ | $\uparrow L$ の後:利得 $L$、遮断 $\pi/L$ |
| 情報 | $\pi/M$ より上は失われる | 完全に保たれる |
$X_d(e^{j\omega}) = \dfrac{1}{M}\displaystyle\sum_{i=0}^{M-1} X\big(e^{j(\omega-2\pi i)/M}\big)$ — stretch by $M$, average $M$ copies. Safe iff $\omega_N \le \pi/M$.$X_d(e^{j\omega}) = \dfrac{1}{M}\displaystyle\sum_{i=0}^{M-1} X\big(e^{j(\omega-2\pi i)/M}\big)$——拉寬 $M$ 倍,再把 $M$ 個複本平均。當且僅當 $\omega_N \le \pi/M$ 時安全。$X_d(e^{j\omega}) = \dfrac{1}{M}\displaystyle\sum_{i=0}^{M-1} X\big(e^{j(\omega-2\pi i)/M}\big)$——$M$ 倍に引き伸ばし、$M$ 個の複製を平均する。$\omega_N \le \pi/M$ のとき、かつそのときにかぎり安全である。
$X_e(e^{j\omega}) = X(e^{j\omega L})$ — compress by $L$; remove images with lowpass of gain $L$, cutoff $\pi/L$; then $x_i[n]=x_c(nT/L)$ exactly.$X_e(e^{j\omega}) = X(e^{j\omega L})$——壓縮 $L$ 倍;用增益 $L$、截止 $\pi/L$ 的低通去掉映像;於是 $x_i[n]=x_c(nT/L)$ 完全成立。$X_e(e^{j\omega}) = X(e^{j\omega L})$——$L$ 倍に圧縮する。利得 $L$、遮断 $\pi/L$ の低域通過でイメージを取り除けば、$x_i[n]=x_c(nT/L)$ が厳密に成り立つ。
$\uparrow L \to$ lowpass (gain $L$, cutoff $\min(\pi/L,\pi/M)$) $\to\ \downarrow M$ gives $T' = MT/L$. Interpolate first so information is only lost when unavoidable.$\uparrow L \to$ 低通(增益 $L$、截止 $\min(\pi/L,\pi/M)$)$\to\ \downarrow M$,得到 $T' = MT/L$。先內插,這樣才只在不得已時才失去資訊。$\uparrow L \to$ 低域通過(利得 $L$、遮断 $\min(\pi/L,\pi/M)$)$\to\ \downarrow M$ とすれば $T' = MT/L$ が得られる。先に補間すること。そうすれば情報が失われるのは、やむを得ない場合だけになる。
ZOH repeats samples; linear connects them ($h_{\mathrm{lin}} = $ triangle, $H_{\mathrm{lin}} = \frac{1}{L}\big[\frac{\sin(\omega L/2)}{\sin(\omega/2)}\big]^2$). Both leave residual images — fine only when oversampled.ZOH 重複樣本;線性內插把樣本連成直線($h_{\mathrm{lin}} = $ 三角形,$H_{\mathrm{lin}} = \frac{1}{L}\big[\frac{\sin(\omega L/2)}{\sin(\omega/2)}\big]^2$)。兩者都會留下殘餘映像——只有在大幅過取樣時才夠用。ZOH は標本を繰り返し、線形補間は標本どうしを直線で結ぶ($h_{\mathrm{lin}} = $ 三角形、$H_{\mathrm{lin}} = \frac{1}{L}\big[\frac{\sin(\omega L/2)}{\sin(\omega/2)}\big]^2$)。どちらもイメージを残す——大きく過標本化されているときにかぎって使える。
decimate = filter + $\downarrow M$; downsample = bare $\downarrow M$ (danger);
interp = $\uparrow L$ + filter; resample(x,P,Q) = polyphase $P/Q$; get $P,Q$ with rat.decimate = 濾波 + $\downarrow M$;downsample = 光禿禿的 $\downarrow M$(危險);interp = $\uparrow L$ + 濾波;resample(x,P,Q) = 多相的 $P/Q$ 轉換;$P,Q$ 用 rat 求得。decimate = フィルタ + $\downarrow M$、downsample = 裸の $\downarrow M$(危険)、interp = $\uparrow L$ + フィルタ、resample(x,P,Q) = 多相による $P/Q$ 変換。$P,Q$ は rat で求める。
(1) Filter before you compress, after you expand. (2) Aliasing is forever; images wash off. (3) Rebuild the time axis after every rate change.(1) 壓縮之前要濾波,擴張之後要濾波。(2) 混疊是永久的,映像則洗得掉。(3) 每做一次倍率轉換,就要重建時間軸。(1) 圧縮する前に、そして拡張した後にフィルタをかける。(2) エイリアシングは永久に残るが、イメージは洗い落とせる。(3) レートを変えたら毎回、時間軸を作り直す。
All five problems of ICE503 DSP Homework #7, restated with full worked solutions.ICE503 DSP 作業 #7 的全部五題,重新敘述並附完整解答。ICE503 DSP 宿題 #7 の全 5 題を、完全な解答つきで述べ直したものである。
Problem: Consider the system below. Assume $R_c(j\Omega)$ is bandlimited, $R_c(j\Omega) = 0$ for $|\Omega| \ge 2\pi(1000)$, with the triangular shape of Fig. 2 of the homework (peak $R_c(0)$ at $\Omega = 0$, decreasing linearly to zero at $|\Omega| = 2\pi(1000)$).題目:考慮下面的系統。假設 $R_c(j\Omega)$ 是帶限的,當 $|\Omega| \ge 2\pi(1000)$ 時 $R_c(j\Omega) = 0$,形狀為作業圖 2 的三角形(在 $\Omega = 0$ 處有峰值 $R_c(0)$,線性遞減到 $|\Omega| = 2\pi(1000)$ 處歸零)。問題:下の系を考える。$R_c(j\Omega)$ は帯域制限されており、$|\Omega| \ge 2\pi(1000)$ では $R_c(j\Omega) = 0$ で、形は宿題の図 2 の三角形($\Omega = 0$ でピーク $R_c(0)$ をとり、$|\Omega| = 2\pi(1000)$ で線形に零まで減少する)とする。
(a) For $L = 3$, $T_1 = \tfrac{1}{2000}$ s, and $H(e^{j\omega}) = 1$ for $|\omega|\le\omega_0$, $0$
otherwise — sketch $R(e^{j\omega})$ and $X(e^{j\omega})$.
(b) For $M = 2$, choose nonzero $\omega_0$ and $T_2$ such that $y[n] = \alpha\, r_c(nT_2)$ for some
nonzero constant $\alpha$.
(c) Using the $\omega_0$ from (b), determine $T_3$ such that $s_c(t) = \beta\, r_c(t)$ for some
nonzero $\beta$.
(d) Now let $M = 3$ and $T_3 = \tfrac{1}{2000}$. If the output must be
$s_c(t) = r_c\!\big(t - \tfrac{1}{1000}\big)$, is it possible to obtain $s[n] \,(= y[n])$ from $r[n]$?
If so, what should $H(e^{j\omega})$ be?(a) 當 $L = 3$、$T_1 = \tfrac{1}{2000}$ s,且 $|\omega|\le\omega_0$ 時 $H(e^{j\omega}) = 1$、其餘為 $0$——畫出 $R(e^{j\omega})$ 與 $X(e^{j\omega})$。
(b) 當 $M = 2$,選出非零的 $\omega_0$ 與 $T_2$,使得 $y[n] = \alpha\, r_c(nT_2)$($\alpha$ 為某個非零常數)。
(c) 沿用 (b) 的 $\omega_0$,決定 $T_3$ 使得 $s_c(t) = \beta\, r_c(t)$($\beta$ 為某個非零常數)。
(d) 現在令 $M = 3$、$T_3 = \tfrac{1}{2000}$。若輸出必須是 $s_c(t) = r_c\!\big(t - \tfrac{1}{1000}\big)$,有沒有可能從 $r[n]$ 得到 $s[n] \,(= y[n])$?若可以,$H(e^{j\omega})$ 應該是什麼?(a) $L = 3$、$T_1 = \tfrac{1}{2000}$ s とし、$|\omega|\le\omega_0$ では $H(e^{j\omega}) = 1$、それ以外では $0$ とする——$R(e^{j\omega})$ と $X(e^{j\omega})$ を描け。
(b) $M = 2$ のとき、ある零でない定数 $\alpha$ に対して $y[n] = \alpha\, r_c(nT_2)$ となるような、零でない $\omega_0$ と $T_2$ を選べ。
(c) (b) で得た $\omega_0$ を用いて、ある零でない $\beta$ に対して $s_c(t) = \beta\, r_c(t)$ となる $T_3$ を定めよ。
(d) いま $M = 3$、$T_3 = \tfrac{1}{2000}$ とする。出力が $s_c(t) = r_c\!\big(t - \tfrac{1}{1000}\big)$ でなければならないとき、$r[n]$ から $s[n] \,(= y[n])$ を得ることは可能か。可能ならば $H(e^{j\omega})$ はどうあるべきか。
Sampling at $f_1 = 1/T_1 = 2000$ Hz a signal whose highest frequency is 1000 Hz puts the band edge exactly at $\Omega_N T_1 = 2\pi(1000)/2000 = \pi$ — critical sampling, no aliasing, the spectrum fills the whole $[-\pi,\pi]$ interval:以 $f_1 = 1/T_1 = 2000$ Hz 去取樣一個最高頻率為 1000 Hz 的訊號,會把頻帶邊界剛好放在 $\Omega_N T_1 = 2\pi(1000)/2000 = \pi$——這是臨界取樣,沒有混疊,而頻譜正好填滿整個 $[-\pi,\pi]$ 區間:最高周波数が 1000 Hz の信号を $f_1 = 1/T_1 = 2000$ Hz で標本化すると、帯域端はちょうど $\Omega_N T_1 = 2\pi(1000)/2000 = \pi$ に来る——臨界標本化であり、エイリアシングはなく、スペクトルは区間 $[-\pi,\pi]$ の全体を埋め尽くす:
$$R(e^{j\omega}) = \frac{1}{T_1}\sum_{k} R_c\!\left(j\Big(\frac{\omega - 2\pi k}{T_1}\Big)\right) \;\Rightarrow\; \text{triangles of peak } \frac{R_c(0)}{T_1} = 2000\,R_c(0) \text{ centered at } \omega = 2\pi k,$$$$R(e^{j\omega}) = \frac{1}{T_1}\sum_{k} R_c\!\left(j\Big(\frac{\omega - 2\pi k}{T_1}\Big)\right) \;\Rightarrow\; \text{peak } \frac{R_c(0)}{T_1} = 2000\,R_c(0),\ \text{centered at } \omega = 2\pi k,$$$$R(e^{j\omega}) = \frac{1}{T_1}\sum_{k} R_c\!\left(j\Big(\frac{\omega - 2\pi k}{T_1}\Big)\right) \;\Rightarrow\; \text{triangles of peak } \frac{R_c(0)}{T_1} = 2000\,R_c(0) \text{ centered at } \omega = 2\pi k,$$
each triangle reaching zero at odd multiples of $\pi$. The expander output is $X(e^{j\omega}) = R(e^{j3\omega})$: the same shape compressed by $L=3$, now periodic with period $2\pi/3$ — a baseband triangle on $|\omega| \le \pi/3$ plus images centered at $\pm 2\pi/3$ (and $2\pi$-translates). Both are sketched below (taking $R_c(0)=1$).每個三角形在 $\pi$ 的奇數倍處歸零。擴張器的輸出是 $X(e^{j\omega}) = R(e^{j3\omega})$:同樣的形狀被壓縮 $L=3$ 倍,現在的週期變成 $2\pi/3$——在 $|\omega| \le \pi/3$ 上有一個基頻三角形,另外在 $\pm 2\pi/3$(以及平移 $2\pi$ 的位置)有映像。兩者都畫在下面(取 $R_c(0)=1$)。各三角形は $\pi$ の奇数倍のところで零になる。拡張器の出力は $X(e^{j\omega}) = R(e^{j3\omega})$ であり、同じ形が $L=3$ 倍に圧縮されて、周期はいまや $2\pi/3$ である——$|\omega| \le \pi/3$ 上の基底帯域の三角形に加え、$\pm 2\pi/3$(および $2\pi$ だけ平行移動した位置)を中心とするイメージが現れる。以下に両方を描いた($R_c(0)=1$ とした)。
$y[n]$ holds samples of $r_c$ taken every $T_2 = 1/3000$ s, and $y[n]$ is alias-free. The ideal D/C converter reconstructs the original continuous-time signal precisely when its period matches the actual sample spacing:$y[n]$ 裝的是每隔 $T_2 = 1/3000$ s 取一次的 $r_c$ 樣本,而且 $y[n]$ 沒有混疊。理想的 D/C 轉換器,只有在它的週期與實際的樣本間距相符時,才會精確重建出原本的連續時間訊號:$y[n]$ は $T_2 = 1/3000$ s ごとに取られた $r_c$ の標本を保持しており、しかも $y[n]$ にはエイリアシングがない。理想 D/C 変換器は、その周期が実際の標本間隔と一致するときにかぎって、元の連続時間信号を厳密に再構成する:
$$\boxed{T_3 = T_2 = \frac{1}{3000}\ \text{s}} \;\Rightarrow\; s_c(t) = \beta\, r_c(t).$$$$\boxed{T_3 = T_2 = \frac{1}{3000}\ \text{s}} \;\Rightarrow\; s_c(t) = \beta\, r_c(t).$$$$\boxed{T_3 = T_2 = \frac{1}{3000}\ \text{s}} \;\Rightarrow\; s_c(t) = \beta\, r_c(t).$$
(Any other $T_3$ would produce a time-scaled $r_c(t\,T_2/T_3)$, not $\beta r_c(t)$.)(任何其他的 $T_3$ 都只會得到時間被縮放的 $r_c(t\,T_2/T_3)$,而不是 $\beta r_c(t)$。)(これ以外の $T_3$ をとると、時間軸の伸縮された $r_c(t\,T_2/T_3)$ が得られるだけで、$\beta r_c(t)$ にはならない。)
Note the delay had to be an integer multiple of $M = 3$ at the high rate (here $6 = 2\cdot 3$); a half-sample-type shift such as $r_c(t - \tfrac{1}{4000})$ would still be realizable with a fractional-delay allpass term $e^{-j\omega d}$, $d$ non-integer — the multirate chain is more flexible than a plain delay line.注意這個延遲在高取樣率上必須是 $M = 3$ 的整數倍(這裡是 $6 = 2\cdot 3$);至於像 $r_c(t - \tfrac{1}{4000})$ 這種半樣本式的平移,仍然可以用一個分數延遲全通項 $e^{-j\omega d}$($d$ 非整數)做到——多率的架構比單純的延遲線更有彈性。この遅延が高いレートにおいて $M = 3$ の整数倍でなければならなかったことに注意しよう(ここでは $6 = 2\cdot 3$)。$r_c(t - \tfrac{1}{4000})$ のような半標本ぶんのずれであっても、分数遅延の全域通過項 $e^{-j\omega d}$($d$ は非整数)を使えばなお実現できる——マルチレートの構成は、単なる遅延線よりも柔軟なのである。
Problem: Generate $x(t) = \sin(2\pi\,20t) + \sin(2\pi\,100t)$ and sample it at
1000 Hz to obtain $x[n]$. (a) Reduce the rate by 5 using both decimate and
downsample; plot each result against $x[n]$. (b) Repeat with factor 8.題目:產生 $x(t) = \sin(2\pi\,20t) + \sin(2\pi\,100t)$ 並以 1000 Hz 取樣得到 $x[n]$。(a) 分別用 decimate 與 downsample 把取樣率降低 5 倍,並把各自的結果與 $x[n]$ 疊在一起畫出。(b) 換成 8 倍再做一次。問題:$x(t) = \sin(2\pi\,20t) + \sin(2\pi\,100t)$ を生成し、1000 Hz で標本化して $x[n]$ を得よ。(a) decimate と downsample の両方を使ってレートを 5 分の 1 にし、それぞれの結果を $x[n]$ と重ねて描け。(b) 因子 8 で同じことを繰り返せ。
fs = 1000; t = 0:1/fs:2-1/fs;
x = sin(2*pi*20*t) + sin(2*pi*100*t);
for M = [5 8] % (a) M = 5, (b) M = 8
x_down = downsample(x, M); % bare compressor, no filter
x_deci = decimate(x, M); % Chebyshev LPF, then compressor
t_M = downsample(t, M);
figure;
subplot(2,1,1);
plot(t, x, 'Color', [.75 .75 .75]); hold on;
stem(t_M, x_down, '.'); xlim([0 0.25]);
title(sprintf('downsample, M = %d (fs'' = %g Hz)', M, fs/M));
subplot(2,1,2);
plot(t, x, 'Color', [.75 .75 .75]); hold on;
stem(t_M, x_deci, '.'); xlim([0 0.25]);
title(sprintf('decimate, M = %d', M));
xlabel('time (s)');
end
decimate reproduced as 8th-order Chebyshev-I zero-phase filtering + compression). Left column $M=5$, right column $M=8$; top row downsample, bottom row decimate. Gray: original 1000 Hz signal.圖 7-11 — 習題 2 的結果(以數值方式重現;decimate 以 8 階 Chebyshev I 型零相位濾波加上壓縮來複製)。左欄 $M=5$、右欄 $M=8$;上列為 downsample、下列為 decimate。灰色為原始的 1000 Hz 訊號。図 7-11 — 演習 2 の結果(数値的に再現したもの。decimate は 8 次チェビシェフ I 型の零位相フィルタリングと圧縮によって模している)。左列が $M=5$、右列が $M=8$。上段が downsample、下段が decimate。灰色は元の 1000 Hz の信号である。downsample happens to hit every zero
crossing, so the 100 Hz tone silently vanishes and only the 20 Hz tone remains.
decimate gives nearly the same 20 Hz result because its lowpass cutoff
($0.8 \times 100 = 80$ Hz) also removes the 100 Hz tone. The two outputs look similar here, but
for downsample it is pure luck of sampling phase — a cosine at 100 Hz would have
aliased to a frozen $\pm 1$ pattern instead.(a) $M = 5$ → $f_s' = 200$ Hz,Nyquist 頻率 100 Hz。100 Hz 的那個音恰好落在新的 Nyquist 頻率上。它被保留下來的樣本是 $\sin(2\pi 100 \cdot 5n/1000) = \sin(\pi n) = 0$——downsample 剛好每次都踩在零交越點上,於是 100 Hz 的音悄悄消失,只剩下 20 Hz。decimate 給出幾乎相同的 20 Hz 結果,因為它的低通截止頻率($0.8 \times 100 = 80$ Hz)同樣會濾掉 100 Hz。兩者在這裡看起來很像,但對 downsample 而言純粹是取樣相位的運氣——換成 100 Hz 的餘弦波,混疊後會變成一個凍住的 $\pm 1$ 圖樣。(a) $M = 5$ → $f_s' = 200$ Hz、ナイキスト周波数 100 Hz。100 Hz の音は新しいナイキスト周波数にちょうど載っている。残される標本は $\sin(2\pi 100 \cdot 5n/1000) = \sin(\pi n) = 0$ であり——downsample はたまたま零交差ばかりを拾うので、100 Hz の音は音もなく消え、20 Hz の音だけが残る。decimate もほぼ同じ 20 Hz の結果を与える。低域通過の遮断周波数($0.8 \times 100 = 80$ Hz)が同じく 100 Hz を取り除くからである。ここでは二つの出力は似て見えるが、downsample のほうは標本化位相の運のよさにすぎない——100 Hz の余弦波であったなら、凍りついた $\pm 1$ の並びへエイリアスしていたはずである。downsample it folds to $125 - 100 = 25$ Hz, and the output
is $\sin(2\pi 20t) + $ a false 25 Hz tone — visible as a slow 5 Hz beating envelope
against the true 20 Hz component (and clearly a different waveform from the gray original).
With decimate the prefilter removes the 100 Hz tone before compression, leaving a clean
20 Hz sinusoid. This is precisely the spectral picture of Fig. 7-4.(b) $M = 8$ → $f_s' = 125$ Hz,Nyquist 頻率 62.5 Hz。現在 100 Hz 高於新的 Nyquist:用 downsample 時它會反摺到 $125 - 100 = 25$ Hz,輸出變成 $\sin(2\pi 20t)$ 加上一個假的 25 Hz 音——表現為與真正的 20 Hz 成分互相拍擊、約 5 Hz 的緩慢包絡(波形明顯和灰色的原始訊號不同)。改用 decimate 時,前置濾波器在壓縮之前就把 100 Hz 去掉了,留下乾淨的 20 Hz 正弦波。這正是圖 7-4 所畫的頻譜圖像。(b) $M = 8$ → $f_s' = 125$ Hz、ナイキスト周波数 62.5 Hz。こんどは 100 Hz が新しいナイキスト周波数より上にある。downsample ではそれが $125 - 100 = 25$ Hz へ折り返し、出力は $\sin(2\pi 20t) + $ 偽の 25 Hz の音となる——本物の 20 Hz 成分とのあいだに生じる、約 5 Hz のゆっくりしたうなりの包絡として見える(灰色の元の波形とは明らかに異なる)。decimate では前置フィルタが圧縮の前に 100 Hz の音を取り除くので、きれいな 20 Hz の正弦波が残る。これはまさに図 7-4 のスペクトル図そのものである。decimate (or resample).結論:兩者的差別就在於有沒有抗混疊低通濾波。當訊號在新的 Nyquist 頻率以上還有能量時,必須用 decimate(或 resample)。結論:両者の違いは、アンチエイリアス低域通過を先にかけるかどうか、ただそれだけである。信号が新しいナイキスト周波数より上にまだエネルギーを運んでいるときは、かならず decimate(あるいは resample)を使わなければならない。Problem: Load EMG_ICA.mat (from demodata_L4.zip, course site) and take
channel 1: org_signal = fdata(:,1);, already sampled at 2000 Hz.
(a) Use rat and resample to upsample to 5000 Hz, then downsample back to
2000 Hz; plot against the original. What happened? (b) Downsample to 300 Hz, then upsample
back to 2000 Hz; plot against the original. What happened?題目:載入 EMG_ICA.mat(來自課程網站的 demodata_L4.zip)並取第 1 通道:org_signal = fdata(:,1);,其取樣率為 2000 Hz。(a) 用 rat 與 resample 升頻到 5000 Hz,再降回 2000 Hz;與原始訊號疊圖比較。發生了什麼事?(b) 降頻到 300 Hz,再升回 2000 Hz;與原始訊號疊圖比較。發生了什麼事?問題:EMG_ICA.mat(授業サイトの demodata_L4.zip に含まれる)を読み込み、第 1 チャネル org_signal = fdata(:,1); を取る。これはすでに 2000 Hz で標本化されている。(a) rat と resample を使って 5000 Hz へアップサンプリングし、そのあと 2000 Hz へ戻せ。元の信号と重ねて描き、何が起きたかを述べよ。(b) 300 Hz へダウンサンプリングし、そのあと 2000 Hz へ戻せ。元の信号と重ねて描き、何が起きたかを述べよ。
load('EMG_ICA.mat');
org_signal = fdata(:,1); % channel 1, fs = 2000 Hz
org_SR = 2000;
t_org = (1:length(org_signal))'/org_SR;
% ---------- (a) 2000 -> 5000 -> 2000 ----------
[p1, q1] = rat(5000/org_SR); % p1 = 5, q1 = 2
up_sig = resample(org_signal, p1, q1); % now 5000 Hz
[p2, q2] = rat(org_SR/5000); % p2 = 2, q2 = 5
back_a = resample(up_sig, p2, q2); % back to 2000 Hz
t_a = (1:length(back_a))'/org_SR;
figure; plot(t_org, org_signal); hold on; plot(t_a, back_a);
legend('original 2000 Hz', 'up 5000 \rightarrow down 2000');
% ---------- (b) 2000 -> 300 -> 2000 ----------
[p3, q3] = rat(300/org_SR); % p3 = 3, q3 = 20
low_sig = resample(org_signal, p3, q3); % now 300 Hz
[p4, q4] = rat(org_SR/300); % p4 = 20, q4 = 3
back_b = resample(low_sig, p4, q4); % back to 2000 Hz
t_b = (1:length(back_b))'/org_SR;
figure; plot(t_org, org_signal); hold on; plot(t_b, back_b);
legend('original 2000 Hz', 'down 300 \rightarrow up 2000');
EMG_ICA.mat.圖 7-12 — 習題 3 的現象,以一段模擬的表面肌電爆發訊號重現(20–450 Hz 帶通雜訊加上爆發包絡,$f_s = 2000$ Hz),因為課程的 .mat 檔案不可轉散布。現象與你用 EMG_ICA.mat 會看到的完全相同。図 7-12 — 演習 3 の現象を、模擬した表面筋電様のバースト信号(20–450 Hz の帯域通過雑音にバースト包絡を掛けたもの、$f_s = 2000$ Hz)で再現したもの。授業で配られる .mat ファイルは再配布できないためである。現象は EMG_ICA.mat を使ったときに見えるものとまったく同じである。