本页提供可独立运行的 BDAQ 1× 窄带实验材料。代码不需要生产工程、仪器或网络连接;计算模型、图片、CSV 和结果摘要来自同一次固定种子的主机运行。
阅读顺序:项目入口 → 原理与公式 → 完整测试方案 → 本页。
完整下载与在线工具
跳转到“完整下载与在线工具”- 完整实验包 ZIP:Python、C、依赖版本、离线交互 HTML、说明、全部模型结果和四张图。
- 交互频响工具:无需安装,可切换 NT、N、RPM、频偏、初相位和纵轴。
- Python 完整实验脚本。
- 可移植 C 点积核心。
- 依赖版本与离线复现说明。实验包内仍提供标准的 requirements.txt。
- 主机验证摘要 JSON与交互页面检查 JSON。
- 完整浏览器检查脚本,用于可选的交互回归。
- 16004 点扫频 CSV、带宽 CSV、白噪声 CSV。
所有附件均以 BDAQ 为项目名。完整实验包只包含本专题可复现材料,未打包本机运行环境或编译后的平台二进制。
复现命令
跳转到“复现命令”使用 Python 3.12,先安装固定版本依赖,再执行:
python -m venv .venv# Windows: .venv\Scripts\activate# Linux/macOS: source .venv/bin/activatepython -m pip install -r requirements.txtpython bdaq_dft_lab.py --output results纯 Python 模式执行 9 组模型检查。需要验证 C 参考时,额外编译后使用 --c-library,总计 11 组检查:
# Windows / MinGW GCCgcc -std=c11 -O2 -Wall -Wextra -Werror -pedantic -shared bdaq_1x.c -o bdaq_1x.dll -lmpython bdaq_dft_lab.py --output results --c-library ./bdaq_1x.dll
# Linux / GCCgcc -std=c11 -O2 -Wall -Wextra -Werror -pedantic -fPIC -shared bdaq_1x.c -o libbdaq_1x.so -lmpython bdaq_dft_lab.py --output results --c-library ./libbdaq_1x.so本次实际运行使用 Windows、Python 3.12.14、NumPy 2.3.4、Matplotlib 3.10.7 和原生 GCC。Linux 命令是标准可移植编译方式,本专题没有将其标成已在 Linux 上执行。
results/ 包含 JSON、3 个 CSV 和 4 张图。无 C 参数时不会声称 C 已验证;脚本失败会返回非零退出码。不同平台字体可能改变图片像素,不影响数值核对。
C 核心与固件计算的关系
跳转到“C 核心与固件计算的关系”生产计算的核心结构是“累计数组 × 余弦/正弦查表 → 点积 → 乘 ”。附件提供同一数学约定的独立双精度 C 版本:
/* BDAQ 1x reference kernel. Double precision; no hardware or protocol access. */#include <math.h>#include <stddef.h>#include <stdint.h>#if defined(_WIN32)#define BDAQ_API __declspec(dllexport)#else#define BDAQ_API#endif
typedef struct { double vx, vy; } bdaq_iq;
/* acc contains sums at equal angles over exactly nt complete revolutions. * Positive sine convention: input A*cos(theta+phi) gives vy=-A*sin(phi). * Return 0 on success. Invalid inputs leave out unchanged. */BDAQ_API int bdaq_1x_reference(const double *acc, size_t n, uint32_t nt, bdaq_iq *out){ const double two_pi = 6.283185307179586476925286766559; double sx = 0.0, sy = 0.0; if (acc == NULL || out == NULL || n < 3 || nt == 0) return -1; for (size_t i = 0; i < n; ++i) { if (!isfinite(acc[i])) return -1; const double angle = two_pi * (double)i / (double)n; sx += acc[i] * cos(angle); sy += acc[i] * sin(angle); } const double k = 2.0 / ((double)n * (double)nt); const bdaq_iq candidate = { sx * k, sy * k }; if (!isfinite(candidate.vx) || !isfinite(candidate.vy)) return -1; *out = candidate; return 0;}此版本每次生成 sin/cos,使用标准库 double,并检查非法输入;生产实现使用预生成查表、float32 和 CMSIS 点积。两者用于核对数学约定,不能据此声称 MCU 汇编、性能、饱和路径、双通道封包或实时调度已经通过。
对有效同频输入 ,预期输出为 、。参考代码与页面上的相位恢复均采用此约定。
Python 模型的关键函数
跳转到“Python 模型的关键函数”以下片段说明完整脚本采用的解析式与独立折叠计算;完整画图、测试、CSV 及结果生成代码见上面的下载文件。
import numpy as npTWO_PI = 2 * np.pi
def mean_exp(length: int, cycles_per_sample): """(1/L) sum exp(+j 2 pi a k), stable at a=integer.""" if length < 1: raise ValueError("length must be positive") a = np.asarray(cycles_per_sample, dtype=float) a = a - np.rint(a) return np.exp(1j * np.pi * (length - 1) * a) * np.sinc(length*a) / np.sinc(a)
def positive_branch(nt: int, n: int, delta_order): """Normalized positive complex-frequency branch, not a real-sine estimate.""" return mean_exp(nt*n, -np.asarray(delta_order)/n)
def real_iq(nt: int, n: int, order, phase_rad=0.0): """Unit real cosine, 2/L normalization, positive-sine IQ convention.""" return (np.exp(-1j*phase_rad)*mean_exp(nt*n, (1-np.asarray(order))/n) + np.exp(1j*phase_rad)*mean_exp(nt*n, (1+np.asarray(order))/n))
def extract_iq(samples, n: int): """Fold complete turns, then take cos/sin dot products.""" samples = np.asarray(samples, dtype=float) if n < 3 or samples.ndim != 1 or len(samples) == 0 or len(samples) % n: raise ValueError("expected a nonempty 1-D record of complete turns") if not np.all(np.isfinite(samples)): raise ValueError("samples must be finite") nt = len(samples)//n acc = samples.reshape(nt, n).sum(axis=0) return 2.0/(n*nt) * np.dot(acc, np.exp(1j*TWO_PI*np.arange(n)/n))
def hann_branch(nt: int, n: int, delta_order): """Periodic Hann across the entire L-point record; comparison only.""" length = nt*n a = -np.asarray(delta_order)/n return mean_exp(length, a) - .5*mean_exp(length, a+1/length) - .5*mean_exp(length, a-1/length)
def half_power_width(nt: int, n: int, branch=positive_branch): lo, hi = 0., (2. if branch is hann_branch else 1.)/nt for _ in range(64): mid = (lo+hi)/2 if abs(branch(nt, n, mid)) > 1/np.sqrt(2): lo = mid else: hi = mid return 2*(lo+hi)/2mean_exp 用稳定有限和计算,并对整数频率使用 sinc 的极限;实余弦同时计算两个分支。验证另外构建完整记录并逐点求和,所以不会只让解析式与调用自身的包装函数互相比较。
本次运行结果
跳转到“本次运行结果”| 检查 | 用例数 | 最大误差 / 相对偏差 | 阈值 | 结果 |
|---|---|---|---|---|
| 复频率解析式与完整直接和 | 60 | 2.48253e-16 | 1e-11 | 通过 |
| 实余弦与负频率镜像 | 192 | 1.38168e-14 | 1e-11 | 通过 |
| 逐转折叠与完整记录 IQ | 192 | 2.46585e-14 | 1e-11 | 通过 |
| 同频幅值与相位 | 60 | 4.14475e-14 | 1e-11 | 通过 |
| DC 与整数阶正交抑制 | 48 | 2.15775e-15 | 1e-11 | 通过 |
| N−1 阶折叠到 1× 的反例 | 3 | 1.33227e-15 | 1e-10 | 通过 |
| 连续等长结果块满窗平均 | 1 | 0 | 1e-11 | 通过 |
| 独立白噪声 IQ 标准差 | 4 | 0.0449561 | 0.15 | 通过 |
| 非法记录拒绝 | 3 | 0 | 0 | 通过 |
| 编译后的可移植 C 核心 | 48 | 1.10086e-14 | 1e-11 | 通过 |
| C 失败时保留原输出 | 1 | 0 | 0 | 通过 |
确定性模型容差是双精度参考的检查阈值;白噪声项另用统计相对偏差阈值,不能把二者当成同一种误差。
交互页面另核对:默认观察时间、200 转观察时间与带宽、中心单位增益、首零点、正正弦约定的实信号结果、移动端横向布局和脚本异常。其记录与数值实验摘要分开保存。
可核对的带宽和噪声数值
跳转到“可核对的带宽和噪声数值”3000 rpm、每转 128 点:
| NT | 观察时间 / s | −3 dB 全宽 / Hz | 首零点偏移 / Hz |
|---|---|---|---|
| 1 | 0.02 | 44.295813802 | ±50 |
| 4 | 0.08 | 11.073679997 | ±12.5 |
| 16 | 0.32 | 2.768415727 | ±3.125 |
| 200 | 4 | 0.221473235 | ±0.25 |
| NT | Vx 标准差理论值 | 本次 512 段估计值 | 相对偏差 |
|---|---|---|---|
| 1 | 0.125000000 | 0.130619511 | 4.4956% |
| 4 | 0.062500000 | 0.062559956 | 0.0959% |
| 16 | 0.031250000 | 0.030809979 | 1.4081% |
| 200 | 0.008838835 | 0.008900412 | 0.6967% |
白噪声每个 NT 使用 512 段独立记录、N=128、输入样本标准差 1。这里比较的是 Vx 标准差,没有把零信号时的幅值正偏掩盖成零。
四张结果图
跳转到“四张结果图”



结果可以支持和不能支持的结论
跳转到“结果可以支持和不能支持的结论”模型支持有限长 1× 点积具有窄带选择性、带宽随总观察时间缩小、完整转折叠与整段 IQ 等价,以及给定假设下白噪声的统计下降规律。
N−1 阶折叠到 1× 的反例也通过了预期检查:这意味着反例成立,不能解读为“抗混叠通过”。它恰好说明必须单独检验上游 FIR 和采样链。
本次材料不包含板上数据,不提供真实 ADC/FIR/插值/参考抖动的误差预算,也不宣布幅相精度、长期稳定性或整板验收完成。后续实测应按测试方案追加独立数据记录。