159 lines
6.8 KiB
Plaintext
159 lines
6.8 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"# 声速测量计算器 (逐差法)\n",
|
||
"\n",
|
||
"本 Notebook 用于通过**干涉法(驻波法)**与**相位法(李萨如图形法)**测得的接收器位移坐标,利用**逐差法**计算超声波在空气中的波长 $\\lambda$、实际声速 $v$,并与理论声速进行对比和不确定度评定。\n",
|
||
"\n",
|
||
"---\n",
|
||
"### 实验原理与数学公式\n",
|
||
"\n",
|
||
"#### 1. 理论声速公式\n",
|
||
"在摄氏温度 $t\\,({}^\\circ\\mathrm{C})$ 下,空气中理想声速为:\n",
|
||
"$$v_t = 331.45 \\sqrt{1 + \\frac{t}{273.15}} \\quad (\\mathrm{m/s})$$\n",
|
||
"\n",
|
||
"#### 2. 逐差法测波长 $\\lambda$\n",
|
||
"两组数据各测 12 个极值或特定相位位置坐标 $x_1, x_2, \\dots, x_{12}$,分成两组逐差:\n",
|
||
"$$\\Delta x_i = x_{i+6} - x_i \\quad (i = 1, 2, \\dots, 6), \\quad \\Delta x_{\\mathrm{avg}} = \\frac{1}{6} \\sum_{i=1}^6 \\Delta x_i$$\n",
|
||
"* **干涉法(驻波法)**:相邻波腹间距为 $\\lambda/2$,6 个间隔对应 $\\Delta x = 6 \\times (\\lambda/2) = 3\\lambda$,故:\n",
|
||
"$$\\lambda = \\frac{\\Delta x_{\\mathrm{avg}}}{3}$$\n",
|
||
"* **相位法(李萨如法)**:相邻同向直线相位差为 $2\\pi$,对应间距为 $\\lambda$,6 个间隔对应 $\\Delta x = 6\\lambda$,故:\n",
|
||
"$$\\lambda = \\frac{\\Delta x_{\\mathrm{avg}}}{6}$$\n",
|
||
"\n",
|
||
"#### 3. 声速与不确定度传递公式\n",
|
||
"实验测得声速为 $v = f \\cdot \\lambda$。\n",
|
||
"* 逐差平均值的 A 类不确定度:$u_A(\\Delta x_{\\mathrm{avg}}) = \\frac{s_\\Delta}{\\sqrt{6}}$\n",
|
||
"* 逐差平均值的 B 类不确定度:$u_B(\\Delta x_{\\mathrm{avg}}) = \\sqrt{\\frac{2}{6}} \\frac{\\Delta_{\\mathrm{inst}}}{\\sqrt{3}} = \\frac{\\Delta_{\\mathrm{inst}}}{3}$\n",
|
||
"* 合成不确定度:$u_c(\\Delta x_{\\mathrm{avg}}) = \\sqrt{u_A^2 + u_B^2}$\n",
|
||
"* 波长及声速不确定度(忽略频率 $f$ 极小的不确定度):\n",
|
||
"$$u(\\lambda) = \\frac{u_c(\\Delta x_{\\mathrm{avg}})}{k}, \\quad u(v) = f \\cdot u(\\lambda)$$"
|
||
],
|
||
"id": "db386d820ed39819"
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import math\n",
|
||
"from decimal import Decimal\n",
|
||
"from python.utils import scientific_round\n",
|
||
"\n",
|
||
"print(\"声速计算模块加载完成。\")"
|
||
],
|
||
"id": "72c0a986ef718706"
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 1. 实验条件与测量数据输入\n",
|
||
"> **提示**:可在此输入环境温度、激励信号源频率,以及干涉法和相位法分别测得的 12 个坐标值 $x_i\\,(\\mathrm{mm})$。"
|
||
],
|
||
"id": "b2da551f9b00370d"
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 实验环境参数\n",
|
||
"t_celsius = 24.0 # 环境温度 (℃)\n",
|
||
"freq = 37000.0 # 谐振超声波频率 (Hz)\n",
|
||
"delta_inst = Decimal(\"0.02\") # 游标卡尺/测微鼓轮分度值误差 (mm)\n",
|
||
"\n",
|
||
"# 1. 干涉法 (驻波法) 12 个坐标 (mm)\n",
|
||
"x_vals_interference = [\n",
|
||
" Decimal(\"10.20\"), Decimal(\"14.85\"), Decimal(\"19.50\"), Decimal(\"24.15\"), Decimal(\"28.80\"), Decimal(\"33.45\"),\n",
|
||
" Decimal(\"38.10\"), Decimal(\"42.75\"), Decimal(\"47.40\"), Decimal(\"52.05\"), Decimal(\"56.70\"), Decimal(\"61.35\")\n",
|
||
"]\n",
|
||
"\n",
|
||
"# 2. 相位法 (李萨如图形法) 12 个坐标 (mm)\n",
|
||
"x_vals_phase = [\n",
|
||
" Decimal(\"12.00\"), Decimal(\"21.30\"), Decimal(\"30.60\"), Decimal(\"39.90\"), Decimal(\"49.20\"), Decimal(\"58.50\"),\n",
|
||
" Decimal(\"67.80\"), Decimal(\"77.10\"), Decimal(\"86.40\"), Decimal(\"95.70\"), Decimal(\"105.00\"), Decimal(\"114.30\")\n",
|
||
"]\n",
|
||
"\n",
|
||
"v_theory = 331.45 * math.sqrt(1 + t_celsius / 273.15)\n",
|
||
"print(f\"当前温度 {t_celsius} ℃ 下的理论声速 v_t: {v_theory:.2f} m/s\")"
|
||
],
|
||
"id": "634f5ee7bd5300e5"
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 2. 逐差法处理与声速不确定度评定"
|
||
],
|
||
"id": "223b20661658522d"
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"def process_speed_of_sound(method_name, x_vals, f, k, delta_inst):\n",
|
||
" M = 6\n",
|
||
" deltas = []\n",
|
||
" for i in range(M):\n",
|
||
" diff = x_vals[i + M] - x_vals[i]\n",
|
||
" deltas.append(diff)\n",
|
||
" mean_delta = sum(deltas) / Decimal(str(M))\n",
|
||
" \n",
|
||
" # 计算波长 (mm -> m)\n",
|
||
" wavelength_mm = mean_delta / Decimal(str(k))\n",
|
||
" wavelength_m = wavelength_mm / Decimal(\"1000\")\n",
|
||
" velocity = Decimal(str(f)) * wavelength_m\n",
|
||
" \n",
|
||
" # 不确定度分析\n",
|
||
" variance_delta = sum((d - mean_delta)**2 for d in deltas) / Decimal(str(M - 1))\n",
|
||
" s_delta = Decimal(str(math.sqrt(float(variance_delta))))\n",
|
||
" u_a_delta = s_delta / Decimal(str(math.sqrt(M)))\n",
|
||
" \n",
|
||
" u_x = delta_inst / Decimal(str(math.sqrt(3)))\n",
|
||
" u_b_delta = Decimal(str(math.sqrt(2.0 / M))) * u_x\n",
|
||
" u_delta_combined = Decimal(str(math.sqrt(float(u_a_delta**2 + u_b_delta**2))))\n",
|
||
" \n",
|
||
" u_wavelength_mm = u_delta_combined / Decimal(str(k))\n",
|
||
" u_wavelength_m = u_wavelength_mm / Decimal(\"1000\")\n",
|
||
" u_velocity = Decimal(str(f)) * u_wavelength_m\n",
|
||
" \n",
|
||
" v_final, uv_final = scientific_round(velocity, u_velocity)\n",
|
||
" \n",
|
||
" print(\"=\" * 45)\n",
|
||
" print(f\" {method_name} 计算结果 \")\n",
|
||
" print(\"=\" * 45)\n",
|
||
" print(f\"逐差平均位移 Δx_avg : {mean_delta:.4f} mm\")\n",
|
||
" print(f\"位移标准差 s(Δx) : {s_delta:.4f} mm\")\n",
|
||
" print(f\"声波波长 λ : {wavelength_mm:.4f} mm\")\n",
|
||
" print(f\"波长不确定度 u(λ) : {u_wavelength_mm:.4f} mm\")\n",
|
||
" print(f\"实验声速 v (原始) : {velocity:.2f} m/s\")\n",
|
||
" print(f\"声速合成不确定度 u(v): {u_velocity:.2f} m/s\")\n",
|
||
" rel_error = abs(float(velocity) - v_theory) / v_theory * 100\n",
|
||
" print(f\"与理论声速相对误差 : {rel_error:.2f}%\")\n",
|
||
" print(\"-\" * 45)\n",
|
||
" print(f\"★ 最终修约结果 : v = {v_final} ± {uv_final} m/s\")\n",
|
||
" print(\"=\" * 45 + \"\\n\")\n",
|
||
"\n",
|
||
"# 处理两种方法\n",
|
||
"process_speed_of_sound(\"干涉法 (驻波法)\", x_vals_interference, freq, 3, delta_inst)\n",
|
||
"process_speed_of_sound(\"相位法 (李萨如法)\", x_vals_phase, freq, 6, delta_inst)"
|
||
],
|
||
"id": "70554a3d5158f78e"
|
||
}
|
||
],
|
||
"metadata": {
|
||
"language_info": {
|
||
"name": "python"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|