支撑半个互联网的 200 年数学:傅里叶分析
本页标题、字幕、摘要和阅读笔记为已保存的 AI 译文,可能有误。时间戳与来源一致,可展开查看原始字幕,并对照原视频核对。
如何将声音和信号分解为正弦波频率,从而推动互联网上的音乐流媒体、音频识别和高分辨率视频压缩。
文字稿来源:创作者上传至 YouTube 的字幕。AI 标点由 Vidleaf 添加;原始措辞和时间戳锚点均保留。原始文字稿见下方。
AI 生成的摘要
本视频追溯了傅里叶分析如何支撑数字声音与图像压缩,从函数与曲线讲起,并引入正弦函数,其波形由振幅(听感上即响度)和频率(听感上即音高)来描述。一个纯音是气压随时间变化的完美正弦波,而在 44.1 千赫兹的采样率下存储每一步会产生非常大的文件,例如 Wave 文件格式中的那些文件;由于纯正弦波仅凭振幅和频率即可重现,将许多正弦波叠加起来就能用少得多的数字近似出逼真的声音,这被称为紧凑的 MP3 格式背后的数学魔法。视频将数学背景归功于 1822 年的约瑟夫·傅里叶,将一种称为离散傅里叶变换的高效算法归功于 1965 年的詹姆斯·库利和约翰·图基。MP3 将音频切分成短帧,只保留振幅最大的正弦波,被称为有损是因为一些正弦波被丢弃了,若想要高音频保真度,这一点可能很重要。傅里叶变换将起伏的信号转换为振幅随频率的分布,再按时间对振幅着色便得到频谱图,这正是歌曲识别应用背后的原理;傅里叶滤波可以去除不需要的频率或噪声,讲者提到使用 Audacity,其中频谱图模式让呼吸声很容易被识别出来。本节将此扩展到二维数据:将 x 和 y 的正弦波各自乘以自己的频率可以产生二维波,而网格上的图像像素亮度可以用二维傅里叶变换来分解。JPEG 等有损格式通过丢弃低振幅正弦波来压缩,将较大的图像拆分成更小的块,就像 MP3 把一首歌拆成帧一样,低质量的 JPEG 存储的波非常少,从而导致伪影;文字图像常常产生伪影,因为字母在很大程度上是高对比度的线条,而大多数图像并不会充满大量对比强烈的边缘,因此 JPEG 方法效果相当不错。PNG 等无损压缩在不改变数据的情况下紧凑地存储图像,同样的技术也可以压缩电影,其中关键帧通常被完整存储,随后最多存储 30 秒的像素变化,而一旦到达下一个关键帧,通常画面就会恢复正常。
根据文字稿生成。请对照原始视频核查所链接的段落。
带时间戳的章节摘要
傅里叶在数字声音中的遗产
傅里叶为现代音频技术奠定的基础
- [0:00] 让你口袋里装下一百万首歌的同一项技术,也让应用能快速识别音乐,并让视频足够紧凑,可以以高分辨率流式播放。
- [0:14] 这一切的基础是由法国科学家约瑟夫·傅里叶在大约 200 年前奠定的。
作为规则的函数及其曲线
- [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压缩如何利用傅里叶分析
傅里叶变换与库利-图基算法
- [5:14] 1822年,约瑟夫·傅里叶奠定了确定重现信号所需频率和振幅的数学基础。
- [5:21] 1965年,詹姆斯·库利和约翰·图基开发了一种高效的计算机算法,可以接收任何信号(如声音)并计算出重现它所需的正弦波振幅。
- [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 个不同正弦波合成的声音 [声音]。
[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 添加了 AI 标点和 AI 生成的摘要;原始措辞仍可在本页查看。
您是创作者或权利持有人吗?请求更正或移除:copyright@vidleaf.app(参见关于这些页面)。
最后更新于