如何解码脉冲密度调制信号?

问题描述 投票:0回答:1

我正在尝试学习脉冲密度调制的概念。

wiki页面提供了编码过程的良好概述和伪代码,但缺少解码部分:

将 PDM 信号解码为模拟信号的过程很简单:只需将 PDM 信号通过低通滤波器即可。这是有效的,因为低通滤波器的功能本质上是对信号进行平均。脉冲的平均幅度是通过这些脉冲随时间的密度来测量的,因此低通滤波器是解码过程中所需的唯一步骤。

我正在尝试复制正弦波示例,但在解码部分陷入困境。我尝试过与高斯滤波器进行卷积。结果不是很好,也有点不切实际(因为为了恢复时间 t 的模拟信号,我需要知道将来的数字信号)。

这是我编写的代码及其外观:

import numpy as np
import matplotlib.pyplot as plt

N = 100
xs = np.linspace(0, 2 * np.pi, N)
ys = np.sin(xs)

def pdm(real_samples):
    res = []

    error = 0

    for item in real_samples:
        error += item
        res.append(-1 if error <= 0 else 1)
        error -= res[-1]

    return np.array(res)

def decode(encoded):
    n = len(encoded)
    res = np.zeros(n)

    t = 10
    sigma = 4

    ws = np.arange(-t, t + 1)
    w = np.exp(-((ws) ** 2) / (2 * sigma ** 2))
    w /= np.sum(w)

    xs = np.arange(t, n - t)
    for x in xs:
        res[x] = np.sum(encoded[x - t: x + t + 1] * w)

    res = res[t:n - t]

    return xs, res

encoded = pdm(ys)
decoded_xs, decoded = decode(encoded)
decoded_xs = xs[decoded_xs]

plt.figure()

plt.plot(xs, ys, label='original')
plt.step(xs, encoded, color='orange', linewidth=0.5, label='PDM')
plt.plot(decoded_xs, decoded, color='red', label='restored')

plt.legend()
plt.show()

问题:如何正确恢复脉冲密度调制编码信号?我应该使用什么样的低通滤波器?

python signal-processing modulation
1个回答
0
投票

如果我改变 N=200,将 pi 乘以 4(而不是 2),t=30,sigma=10,恕我直言,我会得到更好的结果。总之,我认为您正在尝试降低样本量。

© www.soinside.com 2019 - 2024. All rights reserved.