支撐半個網際網路的 200 年數學:傅立葉分析
本頁標題、字幕、摘要與閱讀筆記為已儲存的 AI 譯文,可能有誤。時間戳與來源一致,可展開查看原始字幕,並對照原影片核對。
將聲音與訊號分解為正弦波頻率,如何推動網際網路上的音樂串流、音訊辨識與高解析度影片壓縮。
逐字稿來源:創作者上傳至 YouTube 的字幕。AI 標點由 Vidleaf 加入;原始措辭與時間戳錨點均保留。原始逐字稿可在下方取得。
AI 生成摘要
本影片探討傅立葉分析如何支撐數位聲音與影像壓縮,從函數與曲線開始,並介紹正弦函數,其波形由振幅(聽起來是音量)與頻率(聽起來是音高)描述。純粹的嗶聲是氣壓隨時間變化的完美正弦波,而在 44.1 千赫的取樣率下,儲存每一個取樣點會產生非常大的檔案,例如 Wave 檔案格式;由於純正弦波只需振幅與頻率即可重現,疊加許多正弦波便能以遠少於原始資料的數值逼近真實聲音,這被稱為緊湊 MP3 格式背後的數學魔法。影片將數學背景歸功於 1822 年的約瑟夫·傅立葉,並將一種稱為離散傅立葉轉換的高效演算法歸功於 1965 年的詹姆斯·庫利與約翰·圖基。MP3 會將音訊切成短幀,只保留振幅最大的正弦波,之所以稱為有損,是因為部分正弦波被捨棄,若追求高音訊保真度便可能造成影響。傅立葉轉換將波動訊號轉換為振幅對頻率的關係,再依時間以振幅著色便得到頻譜圖,這正是歌曲辨識應用程式的原理;傅立葉濾波可移除不要的頻率或雜訊,講者也提到使用 Audacity,其頻譜圖模式讓呼吸聲很容易被辨識出來。本節並延伸至二維資料:將 x 與 y 的正弦波各自乘上其頻率,可產生二維波,而網格上影像像素的亮度則可用二維傅立葉轉換分解。JPEG 等有損格式透過捨棄低振幅正弦波來壓縮,將較大的影像切成較小的區塊,就像 MP3 將歌曲切成幀一樣,低品質的 JPEG 只儲存極少數波形,因而產生失真;文字影像常產生失真,因為字母大多是高對比的線條,而多數影像並未充滿大量對比鮮明的邊緣,因此 JPEG 方法效果相當不錯。PNG 等無損壓縮則在不改變資料的情況下緊湊地儲存影像,同樣的技術也能壓縮影片,通常會完整儲存一個關鍵幀,接著儲存最多 30 秒的像素變化,而畫面錯亂的影片通常在到達下一個關鍵幀後就會恢復正常。
由逐字稿生成。請對照原始影片檢查連結的段落。
含時間戳的章節摘要
傅立葉在數位聲音中的遺產
傅立葉為現代音訊技術奠定的基礎
函數作為規則及其曲線
- [0:27] 函式是一條規則,它接收一個輸入變數,對其進行運算並傳回輸出,例如將攝氏轉換為華氏。
- [0:46] 輸入變數通常記為「x」,因此 x 的平方加 1 表示將一個數乘以自身再加上 1。
- [0:54] 曲線是透過對函式在許多 x 值上求值,將結果標記為點並連接起來而得到的。
- [1:04] 將函式的輸出乘以或除以一個數會垂直拉伸或壓縮曲線,而在函式運算前對 x 做同樣的動作則會水平拉伸或壓縮曲線。
正弦波、振幅與頻率
- [1:22] 三角學中的正弦函式接收一個角度並傳回與三角形邊長相關的比值,其曲線看起來像帶有波峰和波谷的波浪。
- [1:37] 振幅會垂直拉伸波浪,給出從中間到波峰或波谷的高度,而頻率則水平拉伸它,決定波浪重複的頻繁程度。
- [1:54] 頻率越高,波浪重複得越頻繁。
聲音作為壓力波
- [1:58] 純粹的嗶聲會產生一條隨時間變化的氣壓曲線,它是一條完美的正弦波。
- [2:07] 振幅決定音量:隨著聲音傳播得越遠,波的振幅和壓力變化會變小,聲音也會變得更安靜。
- [2:23] 頻率決定音高;範例聲音為 500 赫茲,即每秒 500 個波峰和波谷,而將頻率加倍會提高感知到的音高。
數位播放與取樣率
正弦波與 MP3 壓縮
原始 PCM 資料大小問題
- [3:17] 以每秒 44,000 個步階、每步階四個位元組計算,資料速率約為每 5 秒一兆位元組。
- [3:22] 這樣的資料量使得儲存歌曲或透過網際網路串流語音聊天變得困難。
- [3:28] 錄音器所使用的 Wave 檔案格式就是這樣運作,並會產生非常大的檔案。
將純正弦波儲存為參數
疊加正弦波以提升真實感
- [3:55] 純正弦音適合復古電腦遊戲,但不太真實,因為自然界中聽不到這種嗶嗶聲。
- [4:03] 兩個數學函數可以相加成新的函數,例如兩個振幅與頻率不同的正弦波。
- [4:13] 對人類來說,逐一相加 100 組振幅與頻率很繁瑣,但對電腦而言卻輕而易舉。
- [4:27] 由 100 個不同正弦波組成的聲音,聽起來會稍微真實一些。
MP3 壓縮原理
MP3 壓縮如何運用傅立葉分析
傅立葉轉換與 Cooley-Tukey 演算法
- [5:14] 1822 年,Joseph Fourier 發展出數學基礎,用來判定重現訊號所需的頻率與振幅。
- [5:21] 1965 年,James Cooley 與 John Tukey 開發出一套高效率的電腦演算法,能接收任何訊號(例如聲音),並計算出重現該訊號所需的正弦波振幅。
- [5:35] 這類演算法稱為離散傅立葉轉換,以其公認的主要創始者命名,儘管還有許多人也做出了貢獻。
以較少正弦波逼近訊號
- [5:44] 基本上,要把任意訊號拆解成個別正弦波,所需的資料量會和原本一樣多,因為完美重現需要非常非常多的正弦波。
- [5:59] 實務上,只要有限數量的正弦波就能做出相當不錯的近似。
- [6:04] 在低音域的的聲音中,高頻正弦波的振幅非常低、幾乎為零,因此錄製短促的低音片段只需儲存低頻;反之,只有高頻的片段亦然。
逐幀 MP3 編碼與有損壓縮
傅立葉轉換與頻譜圖
正弦波的頻域表示
- [7:11] 頻率圖以頻率為橫軸、振幅為縱軸。
- [7:21] 單一頻率的純正弦波表示為一條除該頻率處的尖峰外處處為零的曲線。
- [7:33] 兩個正弦波,其中一個振幅為另一個的兩倍,會在各自頻率處產生一個大尖峰和一個小尖峰。
- [7:47] 當成分波的頻率非常接近時,它們的尖峰會稍微變寬。
傅立葉轉換與色彩編碼振幅
頻譜圖與音樂視覺化
音訊中的傅立葉濾波與頻譜圖
透過傅立葉分解進行頻率濾波
- [9:44] 傅立葉轉換可將聲音分解為組成正弦波,讓特定頻率能被刻意移除或濾除。
- [9:53] 惱人的高頻噪音可透過將其振幅設為零,並由其餘正弦波重建聲音來移除。
- [10:00] 用這種方式可以濾除整段頻率範圍,而含有不想要雜訊的時間區段也可以直接剪掉。
Audacity 波形檢視與頻譜圖檢視
- [10:11] 講者說他們的影片音質無論怎麼衡量都不算好,但他們確實用一套叫做 Audacity 的程式稍微濾除了一些雜訊。
- [10:19] 波形模式只顯示正弦訊號,以及某段時間內聲音有多大,其他資訊一概不顯示。
- [10:28] 頻譜圖模式則有教學意義得多:講者的聲音會產生明亮的線條,而呼氣則會在許多頻率上呈現散落的中等振幅。
- [10:41] 頻譜圖檢視讓呼吸聲很容易辨識,因此講者盡力把這類雜亂的聲音從音訊中移除。
頻譜方法的應用
被動聲納與潛艦識別
從聲波到 2D 影像壓縮
雙變數函數與 2D 波
- [11:19] 先前的函數只有一個變數,以聲波而言就是時間,但函數也可以有兩個以上的變數,例如 x 和 y。
- [11:28] 範例函數將 x 平方、將 y 立方,再把結果相乘。
- [11:37] 將 x 的正弦乘以 y 的正弦,兩者各有自己的頻率,就能產生二維的波。
像素作為 2D 亮度值網格
- [11:47] 電腦影像由像素組成,每個像素有三種顏色:紅、綠、藍。
- [11:52] 只取紅色通道的話,資料會以數字形式儲存在二維網格上。
- [12:00] 影像不是把時間切成步驟,而是在兩個方向上切成像素,每個像素都有一個數字代表亮度。
2D 傅立葉轉換與 JPEG 壓縮
- [12:12] 亮度資料可以分解為不同振幅的正弦波,此時對應到一對頻率,使用二維傅立葉轉換。
- [12:20] 像 JPEG 這類有損格式會藉由捨棄、不記錄低振幅的正弦波來壓縮資料。
- [12:41] JPEG 會把較大的影像切成較小的區塊,就像 MP3 把歌曲切成影格一樣,而在這些小區塊內,色彩變化可以用正弦波來表示。
- [12:53] 相對於影像而言檔案較小、品質較低的 JPEG 只儲存了重建影像所需的極少數波形,因而導致失真。
步階函數邊緣與 JPEG 失真
- [13:05] 在一棟公寓大樓的高品質與低品質 JPEG 中,放大垂直邊緣會看到失真,在邊緣旁出現顏色錯誤的垂直線。
- [13:18] 原始影像的水平切片顯示,右側是數值大的亮像素,左側則驟降為數值小的暗像素,這條曲線稱為步階函數。
- [13:40] 把這條曲線分解成正弦波但只保留少數幾個,會使曲線振盪;若保留更多正弦波,就能填補其波谷所在之處,反之亦然。
- [13:54] 文字影像經常產生失真,因為字母大多是由對比強烈、亮度急遽變化的線條構成,而大多數影像並未充滿許多對比強烈的邊緣,所以 JPEG 方法運作得相當不錯。
使用 PNG 的無損壓縮
視訊壓縮中的傅立葉方法
以影格為基礎的視訊壓縮
- [14:42] 同樣的技術可用來壓縮影片,聲音則像 MP3 或類似格式那樣處理。
- [14:48] 視覺部分由連續的影格組成,其中有些可以類似 JPEG 的方式儲存。
- [14:56] 因為兩個影格之間通常變化不大,只儲存從前一影格到下一影格的像素變化會更經濟。
- [15:09] 傅立葉方法同樣可用來有效率地儲存這些變化。
關鍵影格與損毀的影片
傅立葉分解摘要
前 3 段雙語對照預覽 · 免消耗額度
以下展示前 3 段已儲存繁體中文譯文與英文原版字幕的逐段對照(零額度消耗):
讓你隨身攜帶上百萬首歌的技術,也讓應用程式能快速辨識出一段音樂,並讓這部影片壓縮到足以串流播放,甚至在高解析度下也沒問題。或許會讓你驚訝的是,這一切的基礎是由一位名叫約瑟夫·傅立葉的法國科學家在大約 200 年前奠定的。在談到那裡之前,恐怕我得先帶你回到高中一下。我知道、我知道,但請耐心聽我說。在數學中,函數就像一份食譜:它是一條規則,取一個數字——稱為變數——對它執行一些運算,然後回傳一個新數字——也就是輸出。舉例來說,有個函數會取攝氏溫度,乘以某數再加上某數,然後回傳華氏溫度。通常我們用「x」表示輸入變數,所以函數 x 平方加 1 的意思是:取一個數字,將它自己乘自己,再加上 1。
The technology which allows you to carry a million songs around in your pocket also allows apps to quickly identify a piece of music and to make this video compact enough to stream even in high resolution. What might surprise you is that the foundation for all this was laid down by a French scientist called Joseph Fourier about 200 years ago. Before I get to that, I'm afraid I'll have to take you back to high school for a moment. I know, I know, but bear with me. In mathematics a function is like a recipe: it is a rule to take a number - referred to as a variable - perform some operations on it and return a new number - the output. One example of a function will take a temperature in Celsius multiply and add to it and then return the temperature in Fahrenheit. Usually, we denote the input variable by "x", so the function x squared plus 1 means: take a number, multiply it by itself and add 1.
我們可以對函數代入許多不同的 x 值來求值,將結果標記為點,再把它們連接起來,就能得到一條曲線。如果在對函數求值之後,我們再加上一步乘以或除以某個數字,這會讓曲線在垂直方向上拉伸或壓縮。如果我們在 x 進入函數之前先將它乘以或除以某個數字,則會讓曲線在水平方向上拉伸或壓縮。一個重要的數學函數是三角學中的正弦,它取一個角度並回傳與三角形邊長有關的比值。在這情況下那並不重要,但有趣的是它所形成的曲線。它看起來像一道有波峰與波谷的波。就像先前一樣,我們可以用兩個數字來操控這道波。
We can get a curve from a function by evaluating it for a bunch of different values of x, marking the results as points and then joining them together. If, once we have evaluated the function, we add another step to multiply or divide by a number, this will stretch or squash the curve in the vertical direction. If we multiply or divide x by a number before it goes through the function, it will stretch or squash the curve in the horizontal direction. One important mathematical function is sine from trigonometry, which takes an angle and returns a ratio to do with the sides of the triangle. That doesn't matter in this case, but what is interesting is the curve it makes. It looks like a wave with peaks and troughs. Just as before, we can use two numbers to manipulate this wave.
其中一個會將它垂直拉伸——通常稱為振幅——也就是從中間向上到波峰或向下到波谷的高度。另一個會將它水平拉伸——通常稱為頻率——也就是波峰或波谷出現的頻繁程度。頻率越高,波重複自身的次數就越多。你大概熟悉聲音是由波所組成的這個概念。當發出這個聲音時 [beep],氣壓隨時間變化的曲線就是一條完美的正弦波。振幅決定它有多大聲,所以舉例來說,當聲音傳得越遠,波的振幅就越低,它對背景氣壓造成的變化就越來越小,聲音也就越來越小。這是同一個聲音,但更小聲 [beep]。
One will stretch it vertically - usually called the amplitude - the height from the middle up to the peak or down to a trough. The other will stretch it horizontally - usually called the frequency - namely how frequently the peaks or troughs appear. The higher the frequency, the more often the wave repeats itself. You are probably familiar with the idea that sound consists of waves. When this sound is made [beep] a curve of the air pressure with time is a perfect sine. The amplitude determines how loud it is, so for example as the sound travels further the wave amplitude gets lower, the changes it makes to the background air pressure gets smaller and smaller and the sound gets quieter. This is the same sound, but quieter [beep].
[0:00] 讓你隨身攜帶上百萬首歌的技術,也讓應用程式能快速辨識出一段音樂,並讓這部影片壓縮到足以串流播放,甚至在高解析度下也沒問題。或許會讓你驚訝的是,這一切的基礎是由一位名叫約瑟夫·傅立葉的法國科學家在大約 200 年前奠定的。在談到那裡之前,恐怕我得先帶你回到高中一下。我知道、我知道,但請耐心聽我說。在數學中,函數就像一份食譜:它是一條規則,取一個數字——稱為變數——對它執行一些運算,然後回傳一個新數字——也就是輸出。舉例來說,有個函數會取攝氏溫度,乘以某數再加上某數,然後回傳華氏溫度。通常我們用「x」表示輸入變數,所以函數 x 平方加 1 的意思是:取一個數字,將它自己乘自己,再加上 1。
[0:54] 我們可以對函數代入許多不同的 x 值來求值,將結果標記為點,再把它們連接起來,就能得到一條曲線。如果在對函數求值之後,我們再加上一步乘以或除以某個數字,這會讓曲線在垂直方向上拉伸或壓縮。如果我們在 x 進入函數之前先將它乘以或除以某個數字,則會讓曲線在水平方向上拉伸或壓縮。一個重要的數學函數是三角學中的正弦,它取一個角度並回傳與三角形邊長有關的比值。在這情況下那並不重要,但有趣的是它所形成的曲線。它看起來像一道有波峰與波谷的波。就像先前一樣,我們可以用兩個數字來操控這道波。
[1:39] 其中一個會將它垂直拉伸——通常稱為振幅——也就是從中間向上到波峰或向下到波谷的高度。另一個會將它水平拉伸——通常稱為頻率——也就是波峰或波谷出現的頻繁程度。頻率越高,波重複自身的次數就越多。你大概熟悉聲音是由波所組成的這個概念。當發出這個聲音時 [beep],氣壓隨時間變化的曲線就是一條完美的正弦波。振幅決定它有多大聲,所以舉例來說,當聲音傳得越遠,波的振幅就越低,它對背景氣壓造成的變化就越來越小,聲音也就越來越小。這是同一個聲音,但更小聲 [beep]。
[2:23] 頻率決定聲音的音高,在剛才的例子中是 500 赫茲,也就是每秒 500 個波峰與波谷。頻率越高,波振盪得越快,你感知到的音高就越高。這是同一個聲音,但頻率加倍 [beep]。你或許也熟悉,產生聲音的電子裝置通常有磁鐵和線圈。線圈兩端的電壓會變化,帶動薄膜進出,產生你剛才聽到的壓力波。控制線圈的軟體必須接收一串數字,對應到每個時間步驟必須設定的電壓。舉例來說,這部影片的取樣率是 44.1 千赫茲,意思是它把每一秒切成大約 44,000 個相等的步驟,並在每個步驟送一個數字給喇叭以控制電壓。至少在我製作這部影片時是這樣。
[3:17] 每秒 44,000 個步驟,每個步驟四個位元組,那就是每 5 秒一兆位元組的資料。這樣的資料量會讓把歌曲存放在儲存媒體上,或在網際網路上串流語音聊天變得相當困難。聲音錄製器常用的 Wave 檔案格式就是這樣運作的。你可能注意到它會產生非常大的檔案。但這裡有個更好的辦法:我告訴過你,我播放的聲音是純正弦波。要重現它,我們可以只儲存或傳送兩個數字,振幅和頻率,電腦就能藉由在每個時間點簡單計算正弦函數來重現這條曲線。
[3:55] 我播放的聲音對於復古電腦遊戲之類的用途來說都還不錯,但並不是非常逼真。你在自然界中聽不到那種嗶嗶聲。不過,你隨時可以加入兩個數學函數來產生新的聲音。這裡是一條曲線,代表兩個振幅與頻率各不相同的正弦波相加的結果。你還可以繼續疊加下去。我可以給你 100 組振幅與頻率,讓你把它們所產生的各個時間函數全部加總起來。對人類來說既繁瑣又無聊,但對電腦來說卻非常直接。這裡就是一個由 100 個不同正弦波所構成的聲音 [sound]。
[4:31] 聽起來比較逼真了。要儲存一秒的這種聲音,你仍然只需要 200 個數字,而不是我們之前所用的 44,000 個。所以這就是 MP3 檔案格式背後數學上的神奇之處,也是 MP3 檔案如此精簡的原因。與其儲存聲音訊號在每一個時間點上的值,我們改為儲存一小批頻率及其振幅,再由電腦反覆使用正弦函數來產生聲音。希望我已經成功向你說明了如何把成對的振幅與頻率轉換成可播放的聲音。但如果你已經有一段聲音,又要如何算出需要哪些頻率與振幅呢?
[5:09] 換句話說,一開始要如何從一段錄音產生 MP3 檔案呢?嗯,1822 年約瑟夫·傅立葉建立了這麼做的數學基礎,而 1965 年詹姆斯·庫利與約翰·圖基開發出一種高效率的電腦演算法,能接收任何訊號(例如聲音),並計算出重現該訊號所需的正弦波振幅。這類演算法以其公認的主要創始人命名,稱為離散傅立葉轉換,儘管還有許多其他人也對這項工作有所貢獻。但這裡有個陷阱。如果你真的把任意訊號拆解成各個正弦波,基本上,你會需要同樣份量的資訊——同樣份量的資料——才能把它儲存起來。這是因為要完美重現一個訊號,你會需要非常非常多的正弦波。但在實務上,你只要用有限的数量就能做出相當不錯的近似。當我用低音域說話時,你聽不到任何高音,對吧?用數學術語來說,高頻的正弦波具有非常
[6:10] 低,幾乎為零的振幅。所以,當錄製一段低音調聲音的短片時,只需要儲存低頻。反之亦然,如果一段短片只有高頻,例如帕華洛帝踢到腳趾時。當把一首長歌或語音製作成 MP3 時,會先將其切割成較短的影格,然後依序對每個影格套用傅立葉轉換。MP3 的重點在於只保留每個影格中恰好具有最大振幅的有限數量正弦波。
[6:43] 一般而言,這是可行的。這就是為什麼 MP3 被稱為有損壓縮:你確實會捨棄一些忠實重建原始聲音所需的正弦波,因此最終儲存的內容與原始聲音略有不同。如果你想要高音訊保真度,這可能會有影響,但通常有損壓縮已經足夠。考量到這些,這裡有另一種看待聲音的方式。在螢幕上向上延伸,我會有一個表示頻率的軸。在水平方向上,我會有一個對應振幅的軸。
[7:17] 還記得我播放的第一個聲音嗎?[嗶] 這是一個只有單一頻率的純正弦波。為了表示它,我們畫出一條曲線,除了在該正弦波頻率處有一個尖峰外,其餘各處的值都是 0。現在,如果我們有一個由兩個正弦波組成的聲音,其中一個的振幅是另一個的兩倍,我們就會在相應的頻率處得到一個大尖峰和一個小尖峰。我也播放了一個由一百個正弦波組成的聲音。[聲音] 其實,組成那個聲音的某些波在頻率上非常接近,這意味著那些尖峰會稍微變寬。事實上,那個聲音最初是我聲音的錄音。以下是保留所有頻率的原始版本聽起來和看起來的樣子。[啊聲音] 這就是傅立葉轉換這個詞所指的意思:我已經把聲音訊號的波浪曲線轉換成振幅對頻率的曲線。
[8:14] 請稍等一下,我要根據振幅大小為這條曲線上色。振幅高的尖峰顏色會變亮,振幅低的地方則會變暗。這讓我能把圖形壓縮成一條細長條帶,只代表一小段時間間隔。如果我再次讓時間沿水平方向延伸,我就能視覺化頻率在長得多的聲音中如何變化。例如,聽聽這段簡短的音樂,同時我就這麼做。
[8:45] [音樂] 這張圖稱為聲譜圖。它顯示當不同音符被演奏時,各種頻率的進出變化。請記得,明亮的顏色代表對應頻率的波在橫軸所標示的時間點具有較大的振幅。這張聲譜圖看起來與五線譜音樂記譜法極為相似。第一個演奏的音符是約 350 赫茲的 F,接著停止,然後演奏 G 音。你可以看到垂直間距與頻率對應於音符之間音高的差異。
[9:23] 對於更複雜的樂曲,你就能真正看出不同長度音符之間在水平方向上的持續時間差異。聲譜圖正是那些能只憑一小段音訊就辨識歌曲的應用程式背後的原理。我提過 MP3 如何可能透過只保留最重要的頻率來壓縮聲音。我們可以利用傅立葉轉換將聲音分解成組成之正弦波的方式,刻意移除或濾除某些頻率。如果有惱人的高頻噪音,可以將其振幅設為零,再從其餘正弦波重建聲音。整段頻率範圍都能以這種方式濾除。這也讓直接剪掉含有不想要噪音的時段變得更容易。我的影片音質無論怎麼看都不算好,但我確實會稍微過濾一下。和許多人一樣,我使用一套叫做 Audacity 的程式。通常,它以波形模式顯示聲音,也就是單純的正弦訊號。它只會告訴
[10:24] 你在特定時段內聲音有多大,除此之外別無其他資訊。然而,將檢視切換到聲譜圖模式,就更有啟發性了。我的聲音在聲譜圖中產生明亮的線條,而當我呼氣時,則會在許多頻率上散布著中等振幅。聲譜圖檢視讓我很容易察覺自己何時吸了氣,因此我會努力從音訊中移除那類雜訊。這類頻譜方法讓音樂得以自動調音,據說甚至能用於導引飛彈。任何對無線電技術、聲學和類比電子學有興趣的人,都應該對聲譜圖不陌生。《獵殺紅色十月》等書籍和電影描繪了被動聲納的運用:安靜地監聽敵方潛艦透過水傳遞的聲音。螺旋槳和引擎產生的噪音對每一級潛艦都是獨特的,當以聲譜圖視覺化時很容易就能分辨。到目前為止,我談的都是單變數函數,就聲音而言
[11:24] 波就是時間。也可以有兩個以上變數的函數,例如「x」和「y」。這個函數的意思是:取數字 x 並平方,取數字 y 並立方,再把它們相乘。把 x 的正弦乘以 y 的正弦,各自有各自的頻率,就能在二維中產生波。電腦上的影像由像素組成,像素有三種顏色:紅、綠、藍。現在只取紅色,它會以數字的形式儲存在二維網格上。以前我們把時間切成步驟,每個步驟都有一個數字代表當下的聲音;現在我們把影像在兩個方向上切成像素,每個像素都有一個數字代表亮度。你大概可以看出我要講什麼了。可以把這些亮度資料分解成不同振幅的正弦波,現在對應的是一對頻率,使用二維傅立葉轉換。像 JPEG 這種有損格式接著會壓縮資料,方式是
[12:25] 捨棄並不再記錄那些振幅較低的正弦波。這可能看起來有點奇怪。在聲音方面,我們處理的東西本來就大致像波。但圖片除非是在海邊拍的,否則一般來說不會含有波吧?首先,JPEG 會把較大的影像切成較小的區塊,就像 MP3 把歌曲切成影格一樣。在這些小區塊裡,事實證明隨著顏色變化,是可以把它們表示成正弦波的。品質低、因此相對於影像尺寸檔案很小的 JPEG,只會儲存重建影像所需極少數的波。這會導致失真。這裡有一棟公寓大樓的高品質與低品質 JPEG。如果我們放大這棟大樓的垂直邊緣,就能看到一些這類失真。邊緣旁邊似乎出現了顏色錯誤的垂直線。為了說明這點,讓我們從原始影像取一條水平切片,看看各個像素的亮度值。右邊的像素很亮,
[13:26] 因此數值很大。接著突然下降,左邊的像素很暗,或者說數值很低。定義這條曲線的數學函數不意外地叫做階梯函數。如果我們把這條曲線分解成組成的正弦波,但只保留其中幾個,就會長這樣。曲線會振盪。要是你保留更多正弦波,它們的波峰就會填補這條曲線波谷所在的位置,反之亦然。文字影像經常產生失真,因為字母基本上就是高對比度的線條,亮度有急遽變化。
[14:01] 另一方面,大多數影像並沒有充滿大量對比強烈的邊緣,所以 JPEG 方法效果相當不錯。另外還有無損壓縮,顧名思義,它能緊湊地儲存影像,但完全不改變資料。舉例來說,如果將一張黑底藍色矩形的影像存成 PNG,檔案不會儲存每個像素的值,而是儲存以下指令:將每個像素設為黑色,然後在兩個水平與垂直位置之間,將每個像素設為藍色。在這個情況下不會有壓縮失真,但一般來說 PNG 檔案會比 JPEG 更大。最後,我談到的所有內容都可以用來壓縮影片。聲音可以當成 MP3 或類似格式來處理。視覺部分由連續的影格組成,其中一些可以用類似 JPEG 的方式儲存。不過,通常任兩個影格之間不會有太多變化。車子可能向前移動一小段距離,而背景保持不變。
[15:02] 因此,只儲存從前一影格到下一影格的像素變化會更經濟。傅立葉方法可以再次用來有效率地儲存這些變化。通常會有一個關鍵影格完整儲存,然後接著最多 30 秒的這些細微變化。當你看到畫面混亂時,通常是因為編碼這些變化的資料損毀了。最終,當到達下一個關鍵影格時,影片又會恢復正常。總結來說,我談到了網際網路流量中很大一部分的數學:大多數的音訊、影像和影片。所有這些都能透過先將訊號分解成波來有效率地儲存和傳輸。在數學上,波是三角函數中的正弦函數,具有特定的振幅和頻率。傅立葉轉換是允許這種分解發生的數學工具,它計算出這些正弦波的振幅與對應頻率的組合,將它們加總後便能讓
[16:03] 訊號得以重現。感謝您的觀看。
查看英文原始字幕
[0:00] The technology which allows you to carry a million songs around in your pocket also allows apps to quickly identify a piece of music and to make this video compact enough to stream even in high resolution. What might surprise you is that the foundation for all this was laid down by a French scientist called Joseph Fourier about 200 years ago. Before I get to that, I'm afraid I'll have to take you back to high school for a moment. I know, I know, but bear with me. In mathematics a function is like a recipe: it is a rule to take a number - referred to as a variable - perform some operations on it and return a new number - the output. One example of a function will take a temperature in Celsius multiply and add to it and then return the temperature in Fahrenheit. Usually, we denote the input variable by "x", so the function x squared plus 1 means: take a number, multiply it by itself and add 1.
[0:54] We can get a curve from a function by evaluating it for a bunch of different values of x, marking the results as points and then joining them together. If, once we have evaluated the function, we add another step to multiply or divide by a number, this will stretch or squash the curve in the vertical direction. If we multiply or divide x by a number before it goes through the function, it will stretch or squash the curve in the horizontal direction. One important mathematical function is sine from trigonometry, which takes an angle and returns a ratio to do with the sides of the triangle. That doesn't matter in this case, but what is interesting is the curve it makes. It looks like a wave with peaks and troughs. Just as before, we can use two numbers to manipulate this wave.
[1:39] One will stretch it vertically - usually called the amplitude - the height from the middle up to the peak or down to a trough. The other will stretch it horizontally - usually called the frequency - namely how frequently the peaks or troughs appear. The higher the frequency, the more often the wave repeats itself. You are probably familiar with the idea that sound consists of waves. When this sound is made [beep] a curve of the air pressure with time is a perfect sine. The amplitude determines how loud it is, so for example as the sound travels further the wave amplitude gets lower, the changes it makes to the background air pressure gets smaller and smaller and the sound gets quieter. This is the same sound, but quieter [beep].
[2:23] The frequency determines the pitch of the sound which in the last case was 500 Hertz or 500 peaks and troughs in a second. The higher the frequency, the more rapidly the wave oscillates and you perceive a higher pitch. This is the same sound at double the frequency [beep]. You may also be familiar that electronic devices which produce sounds usually have a magnet and a coil. A voltage is varied across the coil which pulls a membrane in and out to create the pressure waves you just heard. The software which controls the coil must receive a stream of numbers corresponding to the voltage which must be set at every step in time. This video, for example, has a sample rate of 44.1 kilohertz meaning that it breaks every second into about 44,000 equal steps and at each step sends a number to the speaker to control the voltage. Or at least, it did when I made the video.
[3:17] 44,000 steps per second with four bytes per step and that's a megabyte of data every 5 seconds. This amount of data would make it quite difficult to keep songs on storage media or stream voice chat over the internet. This is how the Wave file format that sound recorders often use works. You might have noticed that it produces very large files. But here is a better idea: I told you that the sound I played was a pure sine wave. To reproduce it, we can store or send just two numbers, the amplitude and frequency, and the computer can reproduce the curve by simply calculating the sine function at every point in time.
[3:55] The sounds I played are all well and good for something like a retro computer game, but they're not very realistic. You don't hear that sort of beep in nature. However, you can always add two mathematical functions to make a new one. Here is a curve for two sines with different amplitudes and frequencies added together. You can keep going though. I could give you 100 pairs of amplitudes and frequencies and you could add up all the individual functions of time that arise as a result. Tedious and boring for a human, but for a computer this is very straightforward. Here is just such a sound made out of 100 different sine waves [sound].
[4:31] Sounds a bit more realistic. To store a second of it you still only need 200 numbers as opposed to the 44,000 we had before. So that is the mathematical bit of magic behind the MP3 file format and why MP3 files are so compact. Rather than store the value of the sound signal at every single step in time, we store a smaller bunch of frequencies with amplitudes and the computer generates the sound by repeatedly using the sine function. Hopefully I've managed to explain to you how to turn pairs of amplitudes and frequencies into a sound to play it. But if you already have a sound, how do you work out what frequencies and amplitudes you need?
[5:09] In other words, how do you produce an MP3 file from a recording in the first place? Well, in 1822 Joseph Fourier developed the mathematical background to do this and in 1965 James Cooley and John Tukey developed an efficient computer algorithm which takes any signal, such as a sound, and calculates the amplitudes of sine waves required to reproduce that signal again. This type of algorithm is called a Discrete Fourier Transform after arguably its main originator, although many others contributed to this work. But here's a catch. If you did break up an arbitrary signal into individual sine waves, in basic terms you would need the same amount of information - the same amount of data - to store it. That's because to reproduce a signal perfectly, you would need lots and lots of sine waves. But in practice you can make a pretty good approximation with only a limited amount. When I talk in a low register you can't hear any high-pitched sound, right? In mathematical terms, the sines with high frequencies have very
[6:10] low, almost zero, amplitudes. So, when recording a short clip of a sound with low pitch, only low frequencies need to be stored. The opposite is of course true if a clip had only high frequencies, such as Pavarotti stubbing his toe. When making an MP3 out of a long song or speech, it is first broken up into shorter frames and the Fourier Transform is applied to each one in turn. The point of MP3s is to only keep a limited number of sines which happen to have the largest amplitudes in each frame.
[6:43] Generally speaking, it works. This is why MP3s are referred to as a lossy form of compression: you do end up throwing away some of the sine waves required to faithfully recreate the original sound, and therefore what you end up storing is slightly different to the original. That can make a difference if you want high audio fidelity, but usually lossy compression is good enough. With all that in mind, here is another way of looking at sound. Running up the screen, I will have an axis denoting the frequency. In the horizontal direction I will have an axis with the corresponding amplitude.
[7:17] Remember the first sound I played? [Beep] This was a pure sine wave with just one frequency. To represent this, we draw a curve which takes a value of 0 everywhere except a spike at the frequency of that one sine. Now, if we have a sound made of two sine waves, one of them twice the amplitude of the other, we get a big spike and a little spike at the appropriate frequencies. I also played a sound made up of a hundred sine waves. [Sound] Actually, some of the waves that made that sound were really close together in frequency, so it means that those spikes become slightly wider. In fact, that sound began as a recording of my voice. Here is what the original with all the frequencies kept in sounds and looks like. [Aaah sound] This is what the term Fourier Transform refers to: I've taken the wavy curve of a sound signal and transformed it into a curve of amplitude against frequency.
[8:14] Bear with me for a moment, but I'm going to color this curve by how large the amplitude is. The spikes where the amplitude is high become bright in color and where the amplitude is low becomes dark. This allows me to squash the graph into a thin strip representing just a short interval of time. If I once again have time running along the horizontal direction, I can visualize frequencies as they change in a much longer sound. For example, listen to this short piece of music as I do just that.
[8:45] [Music] This graph is called a spectrogram. It shows different frequencies come in and out as different notes are played. Remember that bright colors mean that waves with corresponding frequencies have a large amplitude at the times indicated on the horizontal axis. This spectrogram looks remarkably similar to the staff music notation. The first note being played is an F at about 350 Hertz and then it stops and the note G is played. You can see that the vertical spacing and frequency corresponds to the difference in pitch between the notes.
[9:23] With a more complicated piece of music, you could really see the horizontal difference in duration between notes of different lengths. Spectrograms are the principle behind apps which can recognize a song based on just a short clip. I mentioned how MP3s might compress sounds by keeping in only the most important frequencies. It is possible to use the way that Fourier Transforms decompose a sound into its constituent sine waves to deliberately remove or filter out certain frequencies. If there is an annoying high-pitched noise, it's possible to set its amplitude to zero, but then recreate the sound from the rest of the sine waves. Whole ranges of frequencies can be filtered out in this way. It also makes it easier to simply cut out periods of time with undesired noise. My videos don't have good audio quality by any measure, but I do filter them a little bit. Like many others, I use a program called Audacity. Normally, it shows sounds in waveform mode which is just the sinusoidal signal. It only tells
[10:24] you how loud the sound is in a given period, but nothing else about it. However, putting the view into spectrogram mode is much more instructive. My voice produces bright lines in the spectrogram, whereas when I breathe out there is a smattering of medium amplitudes across many frequencies. The spectrogram view makes it very easy to spot whenever I've taken a breath and I therefore endeavor to remove that sort of clutter from my audio. These sorts of spectral methods allow music to be auto tuned and apparently can even be used for guiding missiles. Spectrograms should be familiar to anyone interested in radio technology, acoustics and analog electronics. Books and movies like "The Hunt for Red October" depict the use of passive sonar: quietly listening for the sound of enemy submarines carried through the water. The noises produced by the propellers and engines are unique to each class of submarine and can easily be distinguished when visualized by a spectrogram So far, I've talked about functions of one variable, which in the case of sound
[11:24] waves is time. It's also possible to have functions of two or more variables like "x" and "y". This function means: take the number x and square it, take the number y and cube it and multiply them together. By multiplying the sine of x by the sine of y, each with their own frequency, it's possible to have a wave in two dimensions. An image on a computer is composed of pixels with three colors: red green and blue. Taking just the red for now, this is stored as numbers on a two-dimensional grid. Whereas before we split time into steps and had a number representing the sound at every step, we split an image into pixels in both directions and have a number representing the brightness at every pixel. You can probably see where I'm going with this. It's possible to decompose that brightness data into sine waves of different amplitudes, corresponding now to a pair of frequencies using a two-dimensional Fourier Transform. A lossy format such as a JPEG will then compress the data by
[12:25] throwing away and not recording those sine waves which have low amplitudes. This might seem a little weird. With sound, we had something that basically looks like a wave already. But surely a picture, unless it's taken at the seaside, doesn't in general contain waves? Firstly, a JPEG breaks up larger images into smaller pieces just like an MP3 breaks up a song into frames. Within these small pieces, it turns out as the colors change it is possible to represent them as sine waves. JPEGs with a low quality and therefore a small file size relative to the size of the image store very few of the waves required to reconstruct the image. This leads to artifacts. Here are JPEGs of an apartment building in high and low quality. If we zoom in on a vertical edge of this building, we can see some of these artifacts. There appear to be vertical lines of the wrong color next to the edges. To explain this, let's take a horizontal slice from the original image to see the brightness values of the individual pixels. On the right, the pixels are bright and
[13:26] therefore have a large value. Then there is a sudden drop and the pixels on the left are dark or have low values. The mathematical function which defines this curve is unsurprisingly called the step function. If we decompose this curve into its constituent sine waves, but only keep a few of them, this is what it will look like. The curve oscillates. If only you had kept more sine waves, their peaks would have filled in where this curve's troughs are and vice versa. Images of text often produce artifacts because letters pretty much are high contrast lines with sharp changes in brightness.
[14:01] On the flip side, most images are not filled with a large number of sharply contrasted edges, so the JPEG method works pretty well. There is also lossless compression, which as the name suggests stores an image compactly, but without altering data in any way. For example, if an image of a blue rectangle on a black background is saved as a PNG, rather than storing the value of every single pixel, the file would store the following instructions: set every pixel to black and then go between two horizontal and vertical positions and set every pixel to blue. In this case there are no compression artifacts, but generally PNG files come out larger than JPEGs. Finally, everything I've talked about can be used to compress movies. The sound can be treated like an MP3 or similar. The visual component consists of sequential frames, some of which can be stored in a similar way to JPEGs. Usually, though, not much changes between any two frames. A car might move forward by a short amount, while the background remains the same.
[15:02] Therefore, it's more economical to store only the change in pixels from the previous frame to the next. Fourier methods can again be used to store these changes efficiently. Typically, there will be a key frame which is stored in its entirety and then up to 30 seconds of these little changes. When you see garbled footage, this is usually due to the data encoding those changes being corrupted. Eventually, when the next key frame is reached, the video looks good again. In summary, I've talked about the mathematics of a huge chunk of internet traffic: most audio, images and video. All of these are stored and transmitted efficiently by first decomposing the signal into waves. Mathematically, waves are the sine function from trigonometry with a particular amplitude and frequency. A Fourier Transform is the mathematical tool which allows this decomposition to take place, calculate the combination of amplitudes and matching frequencies of those sines which when added together allow the
[16:03] signal to be reproduced. Thank you for watching.
在 Vidleaf 工作台中開啟
搜尋逐字稿、選取行、複製帶時間戳的引文、翻譯。
署名
《半個網際網路背後的 200 年數學》由 Improbable Matter(https://www.youtube.com/@improbablematter)製作,以 CC BY 4.0(https://creativecommons.org/licenses/by/4.0/)授權。來源影片:https://www.youtube.com/watch?v=wtSd7l-dG4o。本頁是該影片的文字轉錄,並加入了段落分隔與時間戳記;創作者與 Vidleaf 無隸屬關係,也不為 Vidleaf 背書。Vidleaf 加入了 AI 標點與 AI 生成的摘要;原始措辭仍可於本頁取得。
你是創作者或權利持有人嗎?請求更正或移除:copyright@vidleaf.app(參見 關於這些頁面)。
最後更新