# Raspberry Pi 搭配訊號處理的應用 ## 開放課程 * [傅立葉分析及應用 Fourier Analysis and Applications](http://ocw.nctu.edu.tw/course_detail.php?bgid=1&gid=1&nid=13) ## 展示影片 * [XPSA spectrum analyzer with GPU FFT enhancement](https://www.youtube.com/watch?v=qGJZ8FOn36s) * 搭配 [XPSA 頻譜分析軟體](http://panteltje.com/panteltje/xpsa/),實現透過快速傅立葉轉換來分析聲音訊號 * [Raspberry Pi Guitar Effect Box](https://www.youtube.com/watch?v=bLcW70tcBX8) * 吉他效果器 * [Basic Video Surveillance with the Raspberry Pi](https://www.youtube.com/watch?v=4rfGc8WM0vk) * 整合簡易的 WebCam,讓 Raspberry Pi 變成遠端監控裝置 * [RNNoise: Using Deep Learning for Noise Suppression](https://hacks.mozilla.org/2017/09/rnnoise-deep-learning-noise-suppression/) * 主要想法是結合經典的信號處理與深度學習,建立輕巧快速的即時雜訊抑制演算法,不仰賴 GPU,並可在 Raspberry Pi 運作。 * 用到 FFT,對應原始程式碼在 `src/kiss_fft.c` ## [RNNoise](https://people.xiph.org/~jm/demo/rnnoise/): 用深度學習抑制雜訊 噪音抑制是訊號處理領域中相當古老的話題,至少可追溯到 1970 年代。顧名思義,這個想法是採取吵雜的信號,儘可能消除噪音,同時對人們感興趣的聲音造成最小的失真。  上圖展示典型雜訊抑制演算法的概念,其中語音活動檢測 (VAD) 模組偵測訊號何時包含人們在意的聲音以及雜訊。這被雜訊譜估計模組用於計算雜訊的頻譜特性 (每個頻率、多少功率)。然後,一旦我們知道雜訊,它可以從輸入音頻「減去」(這裡用不精確的方式描述)。 深度學習 (deep learning) 是類神經網路 (artificial neural network) 近年流行的新說法,實際上從 1960 年代就出現。類神經網路的想法是由收集的系統輸入 (input) 與輸出 (output) 的資料,建立模式 (model, 也就是輸入資料與輸出資料的關聯性),之後便可用於預測、決策、分類。就統計分析而言,輸入資料即爲解釋變項,而輸出資料即可視爲結果變項,在統計分析方法中,常見的迴歸分析即可以視為一種類神經網路的模式。而類神經網路可以有更複雜的型式,例如解釋變項爲非線性的模式等等。 類神經網路主要的目的通常在於預測,通常我們會將資料分成兩個部份:建模資料(training data)以及驗證資料(testing data);也就是說,先以建模資料建立模式,再將驗證資料代入建立完成的模式以確認其預測力高低。 循環神經網絡 ([recurrent neural network](https://en.wikipedia.org/wiki/Recurrent_neural_network); RNN) 在此扮演重要角色,因為可對時間序列建模,不僅僅只考慮輸入和輸出的訊號。這對雜訊抑制特別重要,因為我們需要時間來獲得良好的雜訊估計。過往 RNN 的能力受到很大的限制,因為無法長期保存資訊,並且經由時間反向傳播時涉及的梯度下降過程很沒效率 (也就是 vanishing gradient problem)。如今這兩個問題可由 gated unit 的引入而解決,諸如 Long Short-Term Memory (LSTM), Gated Recurrent Unit (GRU),以及相關變形。  [RNNoise](https://people.xiph.org/~jm/demo/rnnoise/) 採納 GRU,因為處理抑制雜訊的執行狀況比 LSTM 略好,並用更少的 CPU 和儲存資源。RNNoise 保持所有必要的基本訊號處理 (不用類神經網路),但讓類神經網路學習所有需要不必要的調整的棘手部分。和其他既有類神經網路研究不同的是,該專案的目標是即時通信 (可搭配 [WebRTC](https://webrtc.org/)),而非語音辨識,因此運算時間一般不能超過 10ms,否則會造成無法接受的延遲。 打開 [RNNoise](https://people.xiph.org/~jm/demo/rnnoise/) 網頁,用你的網頁瀏覽器測試! :::info 移動到 ==Try it on your voice!== 段落 ::: > 其他聲音樣本: [nn_hack1](https://jmvalin.ca/misc_stuff/rnn_hack1/) 技術細節: [A Hybrid DSP/Deep Learning Approach toReal-Time Full-Band Speech Enhancement](https://arxiv.org/pdf/1709.08243.pdf) ## 實作: 分析聲音訊號 - [ ] 目標設定 * 透過 Python 的 Matplotlib,實現聲音訊號的視覺化分析 * 傅立葉轉換 :::info 下方 ==`$ `== 開頭表示在終端機裡頭的命令輸入,只要敲入 `$ ` 之後的指令即可 ::: * 準備相關套件 ```shell $ sudo apt-get install ffmpeg $ sudo apt-get install python-matplotlib $ sudo apt-get install python-numpy $ sudo apt-get install mplayer ``` * 取得原始程式碼 ```shell $ git clone https://github.com/jserv/python-visualizer $ cd python-visualizer ``` * 測試 ```shell $ wget http://static1.grsites.com/archive/sounds/cartoon/cartoon001.wav $ ./make.sh cartoon001.wav ``` 預期會看到類似以下的輸出: (保持耐心,過程約 2 分鐘) ``` Sample rate: 11025 Fourier width: 0.0416666666667 Duration: 4.56562358277 For Fourier width of 0.0416666666667 need 459.375 samples each FFT Doing 24 Fouriers per second Total 3.0 Spacing: 459.0 Total transforms 72 Processing sample 1 of 72 (0 seconds) Processing sample 2 of 72 (0 seconds) ... ``` 得到 `out.mp4` 輸出檔案。可用 mplayer 來測試: ```shell $ mplayer out.mp4 ``` 執行畫面 / 動畫: [Python Audio Visualiser](https://www.youtube.com/watch?v=VpmYtO-xk_I)  :::success 可進一步參照 [Watch Videos in ASCII Art](http://archive.oreilly.com/pub/h/4441),體驗文字模式的影片播放效果 ::: ## 延伸挑戰:移植 [RNNoise](https://people.xiph.org/~jm/demo/rnnoise/) 到 Raspberry Pi * 10 月 23 日課堂的練習 * 預先準備 * FFmpeg: 研讀 [Audio Types](https://trac.ffmpeg.org/wiki/audio%20types) * 安裝 automake / autconf: `sudo apt-get install automake autoconf libtool` * 自 [SampleRadar](http://www.musicradar.com/news/tech/sampleradar-502-free-noise-hiss-and-crackle-samples-627134) 下載 Vinyl crackle (該項目右方有下載圖示) 並保存為 `Noise.mp3` * 執行以下命令: ```shell $ git clone https://git.xiph.org/rnnoise.git $ cd rnnoise $ make $ ffmpeg -i Noise.mp3 -f s16le -acodec pcm_s16le input.pcm $ ./examples/rnnoise_demo input.pcm output.pcm $ ffmpeg -f s16le -ar 44.1k -ac 2 -i output.pcm output.wav ``` * 比較抑制噪音前後的效果 ```shell $ mplayer Noise.mp3 output.wav ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up