🥥Python和MATLAB数字信号波形和模型模拟

关键词

Python | MATLAB | 数字信号 | 波形 | 模型 | 采样率 | 方波信号 | 矩形脉冲 | 调频信号 | 离散傅里叶变换 | 快速傅里叶变换 | NumPy | SciPy | Matplotlib | 绘图 | 离散时域 | 频域 | 韦尔奇功率谱密度估计 | 幅度谱 | 功率谱密度 | 载波 | 信号功率 | 数值计算 | 信号多项式 | 托普利茨矩阵 | 卷积计算 | 分析信号 | 希尔伯特变换 | 幅度 | 相位 | 二元相移键控 | 差分 | 正交相移键控

🏈page指点迷津 | Brief

要点

  1. Python和MATLAB实现以下波形和模型模拟

    1. 以给定采样率模拟正弦信号,生成给定参数的方波信号,生成给定参数隔离矩形脉冲,生成并绘制线性调频信号。

    2. 快速傅里叶变换结果释义:复数离散傅里叶变换、频率仓和快速傅里叶变换移位,逆快速傅里叶变换移位,数值NumPy对比观察FFT移位和逆FFT移位。

    3. 离散时域表示:余弦信号生成取样,使用FFT频域信号表示,使用FFT计算离散傅里叶变换DFT,获得幅度谱并提取正确的相位谱,从频域样本重建时域信号。

    4. 功率谱密度:使用数值计算库NumPy和科学计算包SciPy以及韦尔奇功率谱密度估计方法 绘制载波调制信号的功率谱密度。

    5. 信号功率:生成的 10 个正弦波周期并绘图,使用数值库NumPy计算信号功率,使用科学计算包SciPy计算频域中总功率。

    6. 信号中多项式:SciPy计算托普利茨矩阵

    7. 信号卷积计算方法:暴力方法计算卷积矢量,托普利茨矩阵方法,快速傅里叶变换方法,对比不同方法计算结果。

    8. 使用频域方法生成分析信号,研究分析信号的组成部分,使用傅立叶变换进行希尔伯特变换:演示从实值调制信号构造的分析信号中提取瞬时幅度和相位,演示使用希尔伯特变换简单的相位解调。f1

    9. 使用二元相移键控调制传入二元流的函数,解调二元相移键控信号,使用二元相移键控调制的信息传输波形模拟生成。

    10. 差分编码和差分解码波形模拟生成

    11. 差分编码二元相移键控调制解调模拟波形

    12. 使用正交相移键控调制传入的二元流模拟波形,解调正交相移键控模拟波形

    13. 偏移正交相移键控调制解调模拟波形

    14. 差分编码偏移正交相移键控调制解调相位映射器和调制解调

信号处理Python示例

信号处理是一门科学领域,涉及信号从时域到频域的处理,反之亦然,平滑信号,从信号中分离噪声,即过滤,从信号中提取信息。自然界中存在的信号都是连续信号。连续时间(或模拟)信号存在于连续间隔 (t1,t2)(\mathrm{t} 1, \mathrm{t} 2) 范围从 -\infty++\infty

模拟量转数字量

  • 采样:采样是将连续时间信号还原为离散时间信号。一个常见的例子是将声波(连续信号)转换为样本序列(离散时间信号)

  • 量化:量化是将输入值从大集合(通常是连续集合)映射到(可数)较小集合(通常具有有限数量的元素)中的输出值的过程。 路由和截断是量化过程的典型示例。

  • 编码:对每个样本进行量化并确定每个样本的位数后,可以将每个样本变为nb位码字。每个样本的位数由量化级别的数量确定。

 import numpy as np
 import matplotlib.pyplot as plt
 ​
 import scipy
 from scipy import signal
 t = np.arange(0, 11)
 x = (0.85) ** t

连续信号

 plt.figure(figsize = (10,8)) # set the size of figure
 ​
 # 1. Plotting Analog Signal
 plt.subplot(2, 2, 1)
 plt.title('Analog Signal', fontsize=20)
 ​
 plt.plot(t, x, linewidth=3, label='x(t) = (0.85)^t')
 plt.xlabel('t' , fontsize=15)
 plt.ylabel('amplitude', fontsize=15)
 plt.legend(loc='upper right')
 ​
 # 2. Sampling and Plotting of Sampled signal
 plt.subplot(2, 2, 2)
 plt.title('Sampling', fontsize=20)
 plt.plot(t, x, linewidth=3, label='x(t) = (0.85)^t')
 n = t
 ​
 markerline, stemlines, baseline = plt.stem(n, x, label='x(n) = (0.85)^n')
 plt.setp(stemlines, 'linewidth', 3)
 plt.xlabel('n' , fontsize = 15)
 plt.ylabel('amplitude', fontsize = 15)
 plt.legend(loc='upper right')
 ​
 # 3. Quantization
 plt.subplot(2, 2, 3)
 plt.title('Quantization', fontsize = 20)
 ​
 plt.plot(t, x, linewidth =3)
 markerline, stemlines, baseline=plt.stem(n,x)
 plt.setp(stemlines, 'linewidth', 3)
 plt.xlabel('n', fontsize = 15)
 plt.ylabel('Range of Quantizer', fontsize=15)
 ​
 plt.axhline(y = 0.1, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.2, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.3, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.4, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.5, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.6, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.7, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.8, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.9, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 1.0, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 ​
 plt.subplot(2, 2, 4)
 plt.title('Quantized Signal', fontsize = 20)
 xq = np.around(x,1)
 markerline, stemlines, baseline = plt.stem(n,xq)
 plt.setp(stemlines, 'linewidth', 3) 
 plt.xlabel('n', fontsize = 15)
 plt.ylabel('Range of Quantizer', fontsize=15)
 ​
 plt.axhline(y = 0.1, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.2, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.3, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.4, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.5, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.6, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.7, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.8, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 0.9, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 plt.axhline(y = 1.0, xmin = 0, xmax = 10, color = 'r', linewidth = 3.0)
 ​
 plt.tight_layout()
 ​

单位脉冲信号

 impulse = signal.unit_impulse(10, 'mid')
 shifted_impulse = signal.unit_impulse(7, 2)
 ​
 # Sine wave
 t = np.linspace(0, 10, 100)
 amp = 5 # Amplitude
 f = 50
 x = amp * np.sin(2 * np.pi * f * t)
 ​
 # Exponential Signal
 x_ = amp * np.exp(-t)
 plt.figure(figsize=(10, 8))
 ​
 plt.subplot(2, 2, 1)
 plt.plot(np.arange(-5, 5), impulse, linewidth=3, label='Unit impulse function')
 plt.ylim(-0.01,1)
 plt.xlabel('time.', fontsize=15)
 plt.ylabel('Amplitude', fontsize=15)
 plt.legend(fontsize=10, loc='upper right')
 ​
 plt.subplot(2, 2, 2)
 plt.plot(shifted_impulse, linewidth=3, label='Shifted Unit impulse function')
 ​
 plt.xlabel('time.', fontsize=15)
 plt.ylabel('Amplitude', fontsize=15)
 plt.legend(fontsize=10, loc='upper right')
 ​
 plt.subplot(2, 2, 3)
 plt.plot(t, x, linewidth=3, label='Sine wave')
 ​
 plt.xlabel('time.', fontsize=15)
 plt.ylabel('Amplitude', fontsize=15)
 plt.legend(fontsize=10, loc='upper right')
 ​
 plt.subplot(2, 2, 4)
 plt.plot(t, x_, linewidth=3, label='Exponential Signal')
 ​
 plt.xlabel('time.', fontsize=15)
 plt.ylabel('Amplitude', fontsize=15)
 plt.legend(fontsize=10, loc='upper right')
 ​
 plt.tight_layout()

正弦波

 # Sine wave
 n = np.linspace(0, 10, 100)
 amp = 5 # Amplitude
 f = 50
 x = amp * np.sin(2 * np.pi * f * n)
 ​
 # Exponential Signal
 x_ = amp * np.exp(-n)

离散信号

 plt.figure(figsize=(12, 8))
 ​
 plt.subplot(2, 2, 1)
 plt.stem(n, x, 'yo', label='Sine wave')
 ​
 plt.xlabel('time.', fontsize=15)
 plt.ylabel('Amplitude', fontsize=15)
 plt.legend(fontsize=10, loc='upper right')
 ​
 plt.subplot(2, 2, 2)
 plt.stem(n, x_, 'yo', label='Exponential Signal')
 ​
 plt.xlabel('time.', fontsize=15)
 plt.ylabel('Amplitude', fontsize=15)
 plt.legend(fontsize=10, loc='upper right')

傅里叶变换

傅里叶变换是分析信号的强大工具,可用于从音频处理到图像处理再到图像压缩的各个领域。傅里叶分析是研究如何将数学函数分解为一系列更简单的三角函数的领域。 傅立叶变换是该领域的一种工具,用于将函数分解为其分量频率。 换句话说,傅立叶变换是一种工具,可让您获取信号并查看其中每个频率的功率。 看看这句话中的重要术语:

  • 信号是随时间变化的信息。例如,音频、视频和电压迹线都是信号的示例。

  • 频率是某事物重复的速度。例如,时钟以一赫特 (Hz) 的频率滴答,或每秒重复一次。

  • 在这种情况下,功率仅指每个频率的强度。

下图是一些正弦波的频率和功率的直观演示:

高频正弦波的峰值比低频正弦波的峰值更接近,因为它们重复得更频繁。低功率正弦波的峰值比其他两个正弦波小。

傅立叶变换在许多应用中都很有用。 图像压缩使用傅立叶变换的变体来去除图像的高频分量。 语音识别使用傅里叶变换和相关变换从原始音频中恢复口语单词。

一般来说,如果您需要查看信号中的频率,则需要傅立叶变换。如果在时域处理信号很困难,那么使用傅立叶变换将其移至频域值得尝试。

Last updated