Bohrium
robot
新建

空间站广场

论文
Notebooks
比赛
课程
Apps
我的主页
我的Notebooks
我的论文库
我的足迹

我的工作空间

任务
节点
文件
数据集
镜像
项目
数据库
公开
Digital-Signal-Processing_06_Quantization of Signals_Requantization of a Speech Signal
English
notebook
Signal Processing
EnglishnotebookSignal Processing
喇叭花
发布于 2023-08-02
推荐镜像 :digital-signal-processing:Digital-Signal-Processing-Lecture
推荐机型 :c2_m4_cpu
Quantization of Signals
Requantization of a Speech Signal
Requantization to 8 bit
Requantization to 6 bit
Requantization to 4 bit
Requantization to 2 bit

Quantization of Signals

🏃🏻 Getting Started Guide
This document can be executed directly on the Bohrium Notebook. To begin, click the Connect button located at the top of the interface, then select the digital-signal-processing:Digital-Signal-Processing-Lecture Image and choose your desired machine configuration to proceed.

📖 Source
This Notebook is from a famous Signal Processing Lecture. The notebooks constitute the lecture notes to the masters course Digital Signal Processing read by Sascha Spors, Institute of Communications Engineering, Universität Rostock.

This jupyter notebook is part of a collection of notebooks on various topics of Digital Signal Processing. Please direct questions and suggestions to Sascha.Spors@uni-rostock.de.

代码
文本

Requantization of a Speech Signal

The following example illustrates the requantization of a speech signal. The signal was originally recorded with a wordlength of bits. It is requantized by a uniform mid-tread quantizer to various wordlengths. The signal-to-noise ratio (SNR) after quantization is computed and a portion of the (quantized) signal is plotted. It is further possible to listen to the requantized signal and the quantization error. Note, the level of the quantization error has been normalized for better audability of the effects.

代码
文本
[1]
import numpy as np
import matplotlib.pyplot as plt
import soundfile as sf

idx = 130000 # index to start plotting


def uniform_midtread_quantizer(x, w):
'''Uniform mid-tread quantizer with limiter.'''
# quantization step
Q = 1/(2**(w-1))
# limiter
x = np.copy(x)
idx = np.where(x <= -1)
x[idx] = -1
idx = np.where(x > 1 - Q)
x[idx] = 1 - Q
# linear uniform quantization
xQ = Q * np.floor(x/Q + 1/2)

return xQ


def evaluate_requantization(x, xQ):
'''Evaluate rquantization by plotting signals and computing SNR.'''
e = xQ - x
# SNR
SNR = 10*np.log10(np.var(x)/np.var(e))
print('SNR: {:2.1f} dB'.format(SNR))
# plot signals
plt.figure(figsize=(10, 4))
plt.plot(x[idx:idx+100], label=r'signal $x[k]$')
plt.plot(xQ[idx:idx+100], label=r'requantized signal $x_Q[k]$')
plt.plot(e[idx:idx+100], label=r'quantization error $e[k]$')
plt.xlabel(r'sample index $k$')
plt.grid()
plt.legend()
# normalize error
e = .2 * e / np.max(np.abs(e))
return e


# load speech sample
x, fs = sf.read('/digital-signal-processing-lecture/data/speech.wav')
# normalize sample
x = x/np.max(np.abs(x))
代码
文本

Original Signal ../data/speech.wav

代码
文本

Requantization to 8 bit

代码
文本
[2]
xQ = uniform_midtread_quantizer(x, 8)
e = evaluate_requantization(x, xQ)
sf.write('speech_8bit.wav', xQ, fs)
sf.write('speech_8bit_error.wav', e, fs)
SNR: 34.0 dB
代码
文本

Requantized Signal speech_8bit.wav

Quantization Error speech_8bit_error.wav

代码
文本

Requantization to 6 bit

代码
文本
[3]
xQ = uniform_midtread_quantizer(x, 6)
e = evaluate_requantization(x, xQ)
sf.write('speech_6bit.wav', xQ, fs)
sf.write('speech_6bit_error.wav', e, fs)
SNR: 22.9 dB
代码
文本

Requantized Signal speech_6bit.wav

Quantization Error speech_6bit_error.wav

代码
文本

Requantization to 4 bit

代码
文本
[4]
xQ = uniform_midtread_quantizer(x, 4)
e = evaluate_requantization(x, xQ)
sf.write('speech_4bit.wav', xQ, fs)
sf.write('speech_4bit_error.wav', e, fs)
SNR: 11.7 dB
代码
文本

Requantized Signal speech_4bit.wav

Quantization Error speech_4bit_error.wav

代码
文本

Requantization to 2 bit

代码
文本
[5]
xQ = uniform_midtread_quantizer(x, 2)
e = evaluate_requantization(x, xQ)
sf.write('speech_2bit.wav', xQ, fs)
sf.write('speech_2bit_error.wav', e, fs)
SNR: 2.4 dB
代码
文本

Requantized Signal speech_2bit.wav

Quantization Error speech_2bit_error.wav

代码
文本

Copyright

This notebook is provided as Open Educational Resource. Feel free to use the notebook for your own purposes. The text is licensed under Creative Commons Attribution 4.0, the code of the IPython examples under the MIT license. Please attribute the work as follows: Sascha Spors, Digital Signal Processing - Lecture notes featuring computational examples.

代码
文本
English
notebook
Signal Processing
EnglishnotebookSignal Processing
点个赞吧
推荐阅读
公开
Digital-Signal-Processing_06_Quantization of Signals_Oversampling
EnglishnotebookSignal Processing
EnglishnotebookSignal Processing
喇叭花
发布于 2023-08-02
公开
Digital-Signal-Processing_06_Quantization of Signals_Oversampling
EnglishnotebookSignal Processing
EnglishnotebookSignal Processing
喇叭花
发布于 2023-08-02