简体   繁体   English

如何使用python打印调幅信号

[英]How to print a amplitude modulated signal using python

I have an matlab example of this program but I can't do it in Python.我有这个程序的 matlab 示例,但我无法在 Python 中执行此操作。 How it must look like (mathlab example) https://imgur.com/a/oam3jXl .它的外观(数学实验室示例) https://imgur.com/a/oam3jXl

import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hilbert, chirp
duration = int(input("Input duration of signal = "))
A = int(input("Input amplitude of signal = "))
start = int(input("Input start of modulation time = "))
end = int(input("Input lenght of modulation = "))
fs = 400.0
samples = int(fs*duration)
t = np.arange(samples) / fs
main_t = []
result = []
counter=0
for l in range(0,samples):
    main_t.append(0)
    result.append(0)
start_mod = np.arange(start*fs)
end_mod = np.arange(end*fs)
signal = chirp(t, 20.0, t[-1], 100.0)
signal *= (A + 0.5 * np.sin(2.0*np.pi*3.0*t) )

for i in np.arange(0,start*fs):
    signal.insert(i,0)

fig = plt.figure()
ax0 = fig.add_subplot(211)
ax0.plot(main_t, result)
ax0.set_xlabel("time in seconds")
plt.show()

I expect the inputing some data from console and then print graph using matplotlib for example.我希望从控制台输入一些数据,然后使用 matplotlib 打印图形。 Graph must look like graph that u can see on image(mathlab example).图形必须看起来像您可以在图像上看到的图形(数学实验室示例)。

Ignoring all the fiddling with getting input (which will vary a lot depending on other constraints), the code to generate an amplitude modulated signal should be simple.忽略对获取输入的所有摆弄(这将根据其他约束而有很大差异),生成调幅信号的代码应该很简单。

I start by pulling in numpy, generating a set of points on which to sample the signal, calculating an amplitude, then combine them:我首先引入 numpy,生成一组对信号进行采样的点,计算幅度,然后将它们组合起来:

import numpy as np

x = np.linspace(0, 10, 501)
ampl = np.exp(-(x - 3.5)**2 / 0.8)
y = np.sin(x * 25) * ampl

we can then plot these using matplotlib with something like:然后我们可以使用 matplotlib 绘制这些图,例如:

import matplotlib.pyplot as plt

plt.figure(figsize=(10,5))
plt.plot(x, y, label='signal')
plt.plot(x, ampl, ':', label='amplitude')
plt.xlabel('time')
plt.ylabel('value')
plt.legend()

演示图

I've pulled in seaborn and am using their ticks style to make it a bit prettier.我已经加入了 seaborn 并使用他们的ticks风格使它更漂亮一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法使用 python 发送和接收调制信号的信号? - Is there a way of sending and receiving signals for modulated signal's using python? 使用Python使用幅度解调进行载波信号提取 - Carrier signal extraction using Amplitude Demodulation using Python 使用Python使用正弦波和PWM信号生成脉冲幅度调制 - Generating Pulse Amplitude Modulation using sine wave and PWM signal using python 使用信号在 python 中延迟打印文本 - Print text with delay in python by using signal 信号fft的幅度错误 - Wrong Amplitude of the fft of a signal 如何获得信号的(x,y)坐标,其最大振幅的10%? - How to get (x, y) coordinates of a signal at 10% of its maximum amplitude? 如何映射与时间戳相关的 ECG 信号幅度? - How can I map the amplitude of an ECG signal in relation to the time stamp? 使用Python和openCV进行打印缺陷检测并发送信号 - Defect Detection of a Print Using Python and openCV and Sending a Signal 如何在python中修改幅度、频率和带宽值 - How to modify amplitude, frequency and bandwidth values in python 如何使用python-scipy消除余弦函数中的可变幅度? - How to get rid of variable amplitude in cosine function using python-scipy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM