|
发表于 2024-2-23 14:32:06
|
显示全部楼层
本帖最后由 demacia 于 2024-2-27 11:37 编辑
楼主想请教下,帖子里说的第6点和一开始esphome remote receiver 接收不到,是差在什么地方吗?只是增加超外差带芯片和长天线的模块吗?原来用的是什么模块。
_________ 接收器不是433Mhz的所以没有接收到________
提供个思路,esphome remote receive raw模式下的绘图出来去查
import matplotlib.pyplot as plt
import numpy as np
# 假设你有一个一维数组,例如:
#pulse_signal = np.array([1.5, -2.3, 3.1, -1.8]) # 数组元素按正负交替,绝对值代表时间长度
pulse_signal = np.array([4805, -1503, 359, -717, 710, -361, 692, -359, 358, -715, 357, -716, 358, -716, 693, -359, 357, -723, 713, -358, 358, -716, 694, -358, 358, -715, 359, -714, 359, -696, 713, -358, 359, -722, 713, -358, 358, -696, 358, -716, 713, -358, 359, -714, 359, -695, 359, -713, 360, -720, 359, -714, 359, -695, 360, -713, 360, -713, 360, -714, 695, -358, 714, -356, 361, -720, 360, -714, 696, -356, 360, -714, 715, -355, 361, -714, 696, -355, 361, -713, 715])
fs = 10000000 # 采样频率(Hz)
# 计算每个样本点对应的时间,并找到正负电平切换的边界
t = np.cumsum(np.abs(pulse_signal)) / fs
switch_points = np.flatnonzero(np.diff(np.signbit(pulse_signal))) # 找到正负值切换的位置索引
switch_times = t[switch_points]
print(switch_points)
print(switch_times)
# 构建broken_barh所需的坐标参数
ranges = []
for i in range(1, len(switch_points)):
ranges.append((switch_times[i-1], switch_times[i] - switch_times[i-1]))
# 添加第一个和最后一个区间的范围
if pulse_signal[0] < 0:
ranges.insert(0, (0, switch_times[0]))
else:
ranges.append((switch_times[-1], t[-1] - switch_times[-1]))
# 创建颜色列表,这里假设红色代表正值(高电位),蓝色代表负值(低电位)
facecolors = ['red' if x > 0 else 'blue' for x in pulse_signal[::]]
# 绘制脉冲信号
fig, ax = plt.subplots()
print(ranges)
print((np.zeros(len(ranges)), np.ones(len(ranges))))
print(facecolors)
ax.broken_barh(ranges, (0.5, 1), facecolors=facecolors)
ax.set_ylim([-0.5, 1.5])
ax.set_yticks([0, 1])
ax.set_yticklabels(['Low', 'High'])
ax.set_xlabel('Time (s)')
ax.set_title('Pulse Signal')
# 显示图形
plt.show()
线性图
import matplotlib.pyplot as plt
import numpy as np
# 假设你有一组正负交替的数据,比如:
#pulse_data = np.array([1.5, -2.3, 3.1, -1.8, 0.5, -0.8])# 数组元素代表每个电平的持续时间
pulse_data = np.array([4805, -1503, 359, -717, 710, -361, 692, -359, 358, -715, 357, -716, 358, -716, 693, -359, 357, -723, 713, -358, 358, -716, 694, -358, 358, -715, 359, -714, 359, -696, 713, -358, 359, -722, 713, -358, 358, -696, 358, -716, 713, -358, 359, -714, 359, -695, 359, -713, 360, -720, 359, -714, 359, -695, 360, -713, 360, -713, 360, -714, 695, -358, 714, -356, 361, -720, 360, -714, 696, -356, 360, -714, 715, -355, 361, -714, 696, -355, 361, -713, 715])
fs = 10000000 # 采样频率(Hz)
# 如果数据不是按照时间步长排列的,你需要首先生成一个时间轴
time_axis = np.cumsum(np.abs(pulse_data)/fs) # 累加绝对值生成时间轴
# 由于matplotlib绘制线图需要x和y坐标,这里我们将时间轴作为x轴数据
# 对于y轴,我们将数据视为标量值0和1,分别代表低电位和高电位
y_pulse = np.where(pulse_data > 0, 1, 0) # 将正值映射为1(高电位),负值映射为0(低电位)
# 开始绘制脉冲信号图
plt.figure(figsize=(10, 6))
plt.step(time_axis, y_pulse, where='post') # 使用step函数绘制阶梯图,'post'表示在每个区间结束处绘制垂直线
# 设置图形属性,如标题、标签等
plt.title('Pulse Signal')
plt.xlabel('Time')
plt.ylabel('Voltage Level (High=1, Low=0)')
plt.grid(True)
# 显示图形
plt.show()
|
|