软件 171 谢金宏 1706300001@e.gzhu.edu.cn 通信原理课程作业 1
Aka. Lightyears1998 lightyears1998@hotmail.com 2019 年 11 月 8 日
A 律 13 折线 PCM 编码转换器
代码
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
/**
* A 律 13 折线编码器
*
* 输入:±1 内的浮点数
* 输出:8 位 PCM 码组
*/
class A13Coder {
protected:
vector<uint8_t> table; // 输入电压到 PCM 码组的转换表
public:
A13Coder() {
this->buildTable(); // 建立输入电压到 PCM 码组的转换表
}
uint8_t convert(double rawInput) {
double voltInput = this->limitRange(rawInput); // 限制输入电压范围
int normInput = this->normalize(voltInput); // 将输入电压转换为量化单位
uint8_t sign = normInput > 0 ? uint8_t(1 << 7) : 0; // 根据符号获得极性码
uint8_t para = this->table[abs(normInput)]; // 查表获得段落码和段内码
return sign + para;
}
private:
// 建立输入电压到 PCM 码组的转换表
void buildTable() {