/Designs/Measuring_instruments/Echo01A/DOC/sonar.nb
0,0 → 1,700
(* Content-type: application/vnd.wolfram.mathematica *)
 
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
 
(* CreatedBy='Mathematica 8.0' *)
 
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 157, 7]
NotebookDataLength[ 21630, 691]
NotebookOptionsPosition[ 20709, 656]
NotebookOutlinePosition[ 21044, 671]
CellTagsIndexPosition[ 21001, 668]
WindowFrame->Normal*)
 
(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
RowBox[{"Simplify", "[",
RowBox[{"Solve", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"f", "\[Equal]",
RowBox[{
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"y", "^", "2"}], "+",
RowBox[{
RowBox[{"(",
RowBox[{"x", "-", "Xl"}], ")"}], "^", "2"}]}], "]"}], " ", "+",
" ",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"x", "^", "2"}], "+",
RowBox[{"y", "^", "2"}]}], "]"}]}]}], ",",
RowBox[{"g", "\[Equal]",
RowBox[{
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"y", "^", "2"}], "+",
RowBox[{
RowBox[{"(",
RowBox[{"x", "-", "Xr"}], ")"}], "^", "2"}]}], "]"}], " ", "+",
" ",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"x", "^", "2"}], "+",
RowBox[{"y", "^", "2"}]}], "]"}]}]}]}], "}"}], ",", " ",
RowBox[{"{",
RowBox[{"x", ",", "y"}], "}"}]}], "]"}], "]"}]], "Input",
CellChangeTimes->{{3.515426716401871*^9, 3.51542694508688*^9}, {
3.515494250442916*^9, 3.515494312592763*^9}, {3.515494443619315*^9,
3.515494481698374*^9}, {3.515495886073002*^9, 3.515495892041057*^9}, {
3.515496075998226*^9, 3.515496077798789*^9}}],
 
Cell[BoxData[
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"x", "\[Rule]",
FractionBox[
RowBox[{
RowBox[{
SuperscriptBox["f", "2"], " ", "g"}], "-",
RowBox[{"g", " ",
SuperscriptBox["Xl", "2"]}], "+",
RowBox[{"f", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-",
SuperscriptBox["g", "2"]}], "+",
SuperscriptBox["Xr", "2"]}], ")"}]}]}],
RowBox[{
RowBox[{
RowBox[{"-", "2"}], " ", "g", " ", "Xl"}], "+",
RowBox[{"2", " ", "f", " ", "Xr"}]}]]}], ",",
RowBox[{"y", "\[Rule]",
RowBox[{"-",
FractionBox[
SqrtBox[
RowBox[{"-",
FractionBox[
RowBox[{
SuperscriptBox["g", "2"], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
SuperscriptBox["Xl", "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
RowBox[{"2", " ", "f", " ", "g"}], "+",
SuperscriptBox["g", "2"], "-",
SuperscriptBox[
RowBox[{"(",
RowBox[{"Xl", "-", "Xr"}], ")"}], "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["g", "2"], "-",
SuperscriptBox["Xr", "2"]}], ")"}]}],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]}]],
RowBox[{"2", " ", "g"}]]}]}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"x", "\[Rule]",
FractionBox[
RowBox[{
RowBox[{
SuperscriptBox["f", "2"], " ", "g"}], "-",
RowBox[{"g", " ",
SuperscriptBox["Xl", "2"]}], "+",
RowBox[{"f", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-",
SuperscriptBox["g", "2"]}], "+",
SuperscriptBox["Xr", "2"]}], ")"}]}]}],
RowBox[{
RowBox[{
RowBox[{"-", "2"}], " ", "g", " ", "Xl"}], "+",
RowBox[{"2", " ", "f", " ", "Xr"}]}]]}], ",",
RowBox[{"y", "\[Rule]",
FractionBox[
SqrtBox[
RowBox[{"-",
FractionBox[
RowBox[{
SuperscriptBox["g", "2"], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
SuperscriptBox["Xl", "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
RowBox[{"2", " ", "f", " ", "g"}], "+",
SuperscriptBox["g", "2"], "-",
SuperscriptBox[
RowBox[{"(",
RowBox[{"Xl", "-", "Xr"}], ")"}], "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["g", "2"], "-",
SuperscriptBox["Xr", "2"]}], ")"}]}],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]}]],
RowBox[{"2", " ", "g"}]]}]}], "}"}]}], "}"}]], "Input",
CellChangeTimes->{{3.515496935952406*^9, 3.515496938796506*^9}}],
 
Cell[BoxData[
RowBox[{
RowBox[{"position", "[",
RowBox[{"f_", ",", "g_"}], "]"}], ":=",
RowBox[{"{",
RowBox[{
FractionBox[
RowBox[{
RowBox[{
SuperscriptBox["f", "2"], " ", "g"}], "-",
RowBox[{"g", " ",
SuperscriptBox["Xl", "2"]}], "+",
RowBox[{"f", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-",
SuperscriptBox["g", "2"]}], "+",
SuperscriptBox["Xr", "2"]}], ")"}]}]}],
RowBox[{
RowBox[{
RowBox[{"-", "2"}], " ", "g", " ", "Xl"}], "+",
RowBox[{"2", " ", "f", " ", "Xr"}]}]], ",",
FractionBox[
SqrtBox[
RowBox[{"-",
FractionBox[
RowBox[{
SuperscriptBox["g", "2"], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
SuperscriptBox["Xl", "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
RowBox[{"2", " ", "f", " ", "g"}], "+",
SuperscriptBox["g", "2"], "-",
SuperscriptBox[
RowBox[{"(",
RowBox[{"Xl", "-", "Xr"}], ")"}], "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["g", "2"], "-",
SuperscriptBox["Xr", "2"]}], ")"}]}],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]}]],
RowBox[{"2", " ", "g"}]]}], "}"}]}]], "Input",
CellChangeTimes->{{3.515496295181325*^9, 3.515496373145641*^9}}],
 
Cell[BoxData[
RowBox[{
RowBox[{"distance", "[",
RowBox[{"x_", ",", "y_"}], "]"}], ":=",
RowBox[{"{",
RowBox[{
RowBox[{
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"y", "^", "2"}], "+",
RowBox[{
RowBox[{"(",
RowBox[{"x", "-", "Xl"}], ")"}], "^", "2"}]}], "]"}], " ", "+", " ",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"x", "^", "2"}], "+",
RowBox[{"y", "^", "2"}]}], "]"}]}], ",",
RowBox[{
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"y", "^", "2"}], "+",
RowBox[{
RowBox[{"(",
RowBox[{"x", "-", "Xr"}], ")"}], "^", "2"}]}], "]"}], " ", "+", " ",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"x", "^", "2"}], "+",
RowBox[{"y", "^", "2"}]}], "]"}]}]}], "}"}]}]], "Input",
CellChangeTimes->{{3.515496905741654*^9, 3.515496944394813*^9}}],
 
Cell[CellGroupData[{
 
Cell[BoxData[
RowBox[{"distance", "[",
RowBox[{"0.3", ",", "7.4"}], "]"}]], "Input",
CellChangeTimes->{{3.515496403004589*^9, 3.515496473593597*^9}, {
3.515496631709924*^9, 3.515496675661791*^9}, {3.515496758217258*^9,
3.51549676557555*^9}, {3.515496952775792*^9, 3.515496982312476*^9}}],
 
Cell[BoxData[
RowBox[{"{",
RowBox[{"14.919400087018944`", ",", "14.839112958173462`"}],
"}"}]], "Output",
CellChangeTimes->{3.515496996655669*^9}]
}, Open ]],
 
Cell[CellGroupData[{
 
Cell[BoxData[
RowBox[{"position", "[",
RowBox[{"14.919400087018944`", ",", "14.839112958173462`"}], "]"}]], "Input",
CellChangeTimes->{{3.515496988909477*^9, 3.515497012744518*^9}}],
 
Cell[BoxData[
RowBox[{"{",
RowBox[{"0.3000000000000122`", ",", "7.399999999999991`"}], "}"}]], "Output",\
 
CellChangeTimes->{3.515497013951068*^9}]
}, Open ]],
 
Cell[BoxData[""], "Input",
CellChangeTimes->{{3.515496949744564*^9, 3.515496949783665*^9}}],
 
Cell[CellGroupData[{
 
Cell[BoxData[
RowBox[{"Simplify", "[",
RowBox[{"Solve", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"f", "\[Equal]",
RowBox[{
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"y", "^", "2"}], "+",
RowBox[{
RowBox[{"(",
RowBox[{"x", "-", "Xl"}], ")"}], "^", "2"}]}], "]"}], " ", "+",
" ",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"x", "^", "2"}], "+",
RowBox[{"y", "^", "2"}]}], "]"}]}]}], ",",
RowBox[{"g", "\[Equal]",
RowBox[{
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"y", "^", "2"}], "+",
RowBox[{
RowBox[{"(",
RowBox[{"x", "-", "Xr"}], ")"}], "^", "2"}]}], "]"}], " ", "+",
" ",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"x", "^", "2"}], "+",
RowBox[{"y", "^", "2"}]}], "]"}]}]}], ",",
RowBox[{"a", "==",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"y", "^", "2"}], "+",
RowBox[{
RowBox[{"(",
RowBox[{"x", "-", "Xl"}], ")"}], "^", "2"}]}], "]"}]}], ",",
RowBox[{"b", "==",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"y", "^", "2"}], "+",
RowBox[{
RowBox[{"(",
RowBox[{"x", "-", "Xr"}], ")"}], "^", "2"}]}], "]"}]}], ",",
RowBox[{"c", "==",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"x", "^", "2"}], "+",
RowBox[{"y", "^", "2"}]}], "]"}]}]}], "}"}], ",", " ",
RowBox[{"{",
RowBox[{"x", ",", "y", ",", "a", ",", "b", ",", "c"}], "}"}]}], "]"}],
"]"}]], "Input",
CellChangeTimes->{{3.515497849255536*^9, 3.515497856520988*^9}, {
3.515497888462276*^9, 3.515497937952609*^9}},
FontWeight->"Plain"],
 
Cell[BoxData[
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"x", "\[Rule]",
FractionBox[
RowBox[{
RowBox[{
SuperscriptBox["f", "2"], " ", "g"}], "-",
RowBox[{"g", " ",
SuperscriptBox["Xl", "2"]}], "+",
RowBox[{"f", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-",
SuperscriptBox["g", "2"]}], "+",
SuperscriptBox["Xr", "2"]}], ")"}]}]}],
RowBox[{
RowBox[{
RowBox[{"-", "2"}], " ", "g", " ", "Xl"}], "+",
RowBox[{"2", " ", "f", " ", "Xr"}]}]]}], ",",
RowBox[{"y", "\[Rule]",
RowBox[{"-",
FractionBox[
SqrtBox[
RowBox[{"-",
FractionBox[
RowBox[{
SuperscriptBox["g", "2"], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
SuperscriptBox["Xl", "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
RowBox[{"2", " ", "f", " ", "g"}], "+",
SuperscriptBox["g", "2"], "-",
SuperscriptBox[
RowBox[{"(",
RowBox[{"Xl", "-", "Xr"}], ")"}], "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["g", "2"], "-",
SuperscriptBox["Xr", "2"]}], ")"}]}],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]}]],
RowBox[{"2", " ", "g"}]]}]}], ",",
RowBox[{"a", "\[Rule]",
RowBox[{"f", "-",
RowBox[{
FractionBox["1", "2"], " ",
SqrtBox[
FractionBox[
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{
SuperscriptBox["g", "2"], " ", "Xl"}], "-",
RowBox[{"Xr", " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "+",
RowBox[{"Xl", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-", "Xl"}], "+", "Xr"}], ")"}]}]}], ")"}]}]}],
")"}], "2"],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]]}]}]}], ",",
RowBox[{"b", "\[Rule]",
RowBox[{"g", "-",
RowBox[{
FractionBox["1", "2"], " ",
SqrtBox[
FractionBox[
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{
SuperscriptBox["g", "2"], " ", "Xl"}], "-",
RowBox[{"Xr", " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "+",
RowBox[{"Xl", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-", "Xl"}], "+", "Xr"}], ")"}]}]}], ")"}]}]}],
")"}], "2"],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]]}]}]}], ",",
RowBox[{"c", "\[Rule]",
RowBox[{
FractionBox["1", "2"], " ",
SqrtBox[
FractionBox[
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{
SuperscriptBox["g", "2"], " ", "Xl"}], "-",
RowBox[{"Xr", " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "+",
RowBox[{"Xl", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-", "Xl"}], "+", "Xr"}], ")"}]}]}], ")"}]}]}],
")"}], "2"],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]]}]}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"x", "\[Rule]",
FractionBox[
RowBox[{
RowBox[{
SuperscriptBox["f", "2"], " ", "g"}], "-",
RowBox[{"g", " ",
SuperscriptBox["Xl", "2"]}], "+",
RowBox[{"f", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-",
SuperscriptBox["g", "2"]}], "+",
SuperscriptBox["Xr", "2"]}], ")"}]}]}],
RowBox[{
RowBox[{
RowBox[{"-", "2"}], " ", "g", " ", "Xl"}], "+",
RowBox[{"2", " ", "f", " ", "Xr"}]}]]}], ",",
RowBox[{"y", "\[Rule]",
FractionBox[
SqrtBox[
RowBox[{"-",
FractionBox[
RowBox[{
SuperscriptBox["g", "2"], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
SuperscriptBox["Xl", "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
RowBox[{"2", " ", "f", " ", "g"}], "+",
SuperscriptBox["g", "2"], "-",
SuperscriptBox[
RowBox[{"(",
RowBox[{"Xl", "-", "Xr"}], ")"}], "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["g", "2"], "-",
SuperscriptBox["Xr", "2"]}], ")"}]}],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]}]],
RowBox[{"2", " ", "g"}]]}], ",",
RowBox[{"a", "\[Rule]",
RowBox[{"f", "-",
RowBox[{
FractionBox["1", "2"], " ",
SqrtBox[
FractionBox[
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{
SuperscriptBox["g", "2"], " ", "Xl"}], "-",
RowBox[{"Xr", " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "+",
RowBox[{"Xl", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-", "Xl"}], "+", "Xr"}], ")"}]}]}], ")"}]}]}],
")"}], "2"],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]]}]}]}], ",",
RowBox[{"b", "\[Rule]",
RowBox[{"g", "-",
RowBox[{
FractionBox["1", "2"], " ",
SqrtBox[
FractionBox[
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{
SuperscriptBox["g", "2"], " ", "Xl"}], "-",
RowBox[{"Xr", " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "+",
RowBox[{"Xl", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-", "Xl"}], "+", "Xr"}], ")"}]}]}], ")"}]}]}],
")"}], "2"],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]]}]}]}], ",",
RowBox[{"c", "\[Rule]",
RowBox[{
FractionBox["1", "2"], " ",
SqrtBox[
FractionBox[
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{
SuperscriptBox["g", "2"], " ", "Xl"}], "-",
RowBox[{"Xr", " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "+",
RowBox[{"Xl", " ",
RowBox[{"(",
RowBox[{
RowBox[{"-", "Xl"}], "+", "Xr"}], ")"}]}]}], ")"}]}]}],
")"}], "2"],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]]}]}]}], "}"}]}],
"}"}]], "Output",
CellChangeTimes->{3.515497857789938*^9, 3.515497938817161*^9,
3.515498443550477*^9, 3.515498495049169*^9}]
}, Open ]],
 
Cell[CellGroupData[{
 
Cell[BoxData[
RowBox[{"CForm", "[",
FractionBox[
SqrtBox[
RowBox[{"-",
FractionBox[
RowBox[{
SuperscriptBox["g", "2"], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
SuperscriptBox["Xl", "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["f", "2"], "-",
RowBox[{"2", " ", "f", " ", "g"}], "+",
SuperscriptBox["g", "2"], "-",
SuperscriptBox[
RowBox[{"(",
RowBox[{"Xl", "-", "Xr"}], ")"}], "2"]}], ")"}], " ",
RowBox[{"(",
RowBox[{
SuperscriptBox["g", "2"], "-",
SuperscriptBox["Xr", "2"]}], ")"}]}],
SuperscriptBox[
RowBox[{"(",
RowBox[{
RowBox[{"g", " ", "Xl"}], "-",
RowBox[{"f", " ", "Xr"}]}], ")"}], "2"]]}]],
RowBox[{"2", " ", "g"}]], "]"}]], "Input",
CellChangeTimes->{{3.515498536581236*^9, 3.515498539213621*^9}, {
3.515498650974364*^9, 3.515498653572732*^9}, {3.515499109832382*^9,
3.515499111554484*^9}, 3.515499287277104*^9}],
 
Cell["\<\
Sqrt(-((Power(g,2)*(Power(f,2) - Power(Xl,2))*
(Power(f,2) - 2*f*g + Power(g,2) - Power(Xl - Xr,2))*
(Power(g,2) - Power(Xr,2)))/Power(g*Xl - f*Xr,2)))/(2.*g)\
\>", "Output",
GeneratedCell->False,
CellAutoOverwrite->False,
CellChangeTimes->{{3.515498539771723*^9, 3.515498545680778*^9},
3.515498654644995*^9, 3.515499112485191*^9, 3.515499287974278*^9}],
 
Cell["\<\
(Power(f,2)*g - g*Power(Xl,2) + f*(-Power(g,2) + Power(Xr,2)))/
(-2*g*Xl + 2*f*Xr)\
\>", "Output",
GeneratedCell->False,
CellAutoOverwrite->False,
CellChangeTimes->{{3.515498539771723*^9, 3.515498545680778*^9},
3.515498654644995*^9, 3.515499112485191*^9}],
 
Cell["\<\
g - Sqrt(Power(Power(g,2)*Xl - Xr*(Power(f,2) + Xl*(-Xl + Xr)),
2)/Power(g*Xl - f*Xr,2))/2.\
\>", "Output",
GeneratedCell->False,
CellAutoOverwrite->False,
CellChangeTimes->{{3.515498539771723*^9, 3.515498545680778*^9},
3.515498654644995*^9}]
}, Open ]]
},
WindowSize->{1280, 723},
WindowMargins->{{0, Automatic}, {Automatic, 0}},
FrontEndVersion->"8.0 for Linux x86 (32-bit) (October 10, 2011)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
 
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[557, 20, 1292, 37, 30, "Input"],
Cell[1852, 59, 3322, 100, 176, "Input"],
Cell[5177, 161, 1590, 50, 88, "Input"],
Cell[6770, 213, 894, 30, 30, "Input"],
Cell[CellGroupData[{
Cell[7689, 247, 297, 5, 30, "Input"],
Cell[7989, 254, 154, 4, 30, "Output"]
}, Open ]],
Cell[CellGroupData[{
Cell[8180, 263, 186, 3, 30, "Input"],
Cell[8369, 268, 152, 4, 30, "Output"]
}, Open ]],
Cell[8536, 275, 92, 1, 30, "Input"],
Cell[CellGroupData[{
Cell[8653, 280, 1821, 56, 50, "Input"],
Cell[10477, 338, 8155, 250, 297, "Output"]
}, Open ]],
Cell[CellGroupData[{
Cell[18669, 593, 1086, 32, 88, "Input"],
Cell[19758, 627, 388, 8, 62, "Output"],
Cell[20149, 637, 275, 7, 46, "Output"],
Cell[20427, 646, 266, 7, 46, "Output"]
}, Open ]]
}
]
*)
 
(* End of internal cache information *)
/Designs/Measuring_instruments/Echo01A/README
0,0 → 1,4
Uprava kaklikova ovladace pro sonar.
 
Balicky potrebne pro kompilaci:
libsdl1.2-dev
/Designs/Measuring_instruments/Echo01A/SW/Makefile
0,0 → 1,32
ifneq ($(V),1)
Q := @
endif
 
INCDIR = -I /usr/include/SDL
CCFLAGS = -g -O2 -Wall -W $(INCDIR)
CXXFLAGS = $(CCFLAGS)
LDFLAGS = -l asound -l SDL
CC = gcc $(CCFLAGS)
CXX = g++ $(CXXFLAGS)
LD = g++ $(LDFLAGS)
 
BINS = sonar
OBJS = sonar.o
 
all: $(BINS)
 
clean:
$(Q) rm -f *.o $(BINS) $(OBJS)
@printf " CLEAN\n";
 
.c.o:
@printf " CC $(subst $(shell pwd)/,,$(@))\n";
$(Q) $(CC) -c -o$@ $<
 
.cpp.o:
@printf " CXX $(subst $(shell pwd)/,,$(@))\n";
$(Q) $(CXX) -c -o$@ $<
 
sonar: $(OBJS)
@printf " LD $(subst $(shell pwd)/,,$(@))\n";
$(Q) $(LD) -o$@ $(OBJS)
/Designs/Measuring_instruments/Echo01A/SW/sonar.c
0,0 → 1,318
///////////////////////////////////////////////////////////////////////////////////
// A small demo of sonar.
// Program allow distance measuring.
// Uses cross-correlation algorithm to find echos
//
// Author: kaklik (kaklik@mlab.cz)
//$Id:$
///////////////////////////////////////////////////////////////////////////////////
 
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <SDL.h>
#include <alsa/asoundlib.h>
 
#define SOUND_SPEED 340.0 // sound speed in air in metrs per second
#define MAX_RANGE 5.0 // maximal working radius in meters
#define Xl -0.1 // microphones position
#define Xr 0.1
 
// Alsa settings
static char *alsa_device = "plughw:0,0";
static snd_pcm_format_t alsa_format = SND_PCM_FORMAT_S16; /* sample format */
static unsigned int alsa_rate = 96000; /* stream rate */
static unsigned int alsa_buffer_time = 2 * (MAX_RANGE / SOUND_SPEED * 1e6); /* ring buffer length in us */
static unsigned int alsa_period_time = MAX_RANGE / SOUND_SPEED * 1e6; /* period time in us */
static int alsa_resample = 1;
 
#define V2D SOUND_SPEED/alsa_rate // count of values to distance
 
// Alsa driver
 
// Hasn't so pretty error messages, but can really cut off count of the lines
#define ALSA_ERR(a) { \
int err; \
err = a; \
if (err < 0) { \
printf("alsa: " #a /* stringify a */ ": %s\n", snd_strerror(err)); \
return err; \
} \
}
static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, unsigned int channels, unsigned int rate,
int resample, unsigned int buffer_time, snd_pcm_sframes_t *buffer_size,
unsigned int period_time, snd_pcm_sframes_t *period_size, snd_pcm_format_t format)
{
unsigned int rrate;
snd_pcm_uframes_t size;
int dir;
/* choose all parameters */
ALSA_ERR(snd_pcm_hw_params_any(handle, params));
/* set hardware resampling */
ALSA_ERR(snd_pcm_hw_params_set_rate_resample(handle, params, resample));
/* set the interleaved read/write format */
ALSA_ERR(snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED));
/* set the sample format */
ALSA_ERR(snd_pcm_hw_params_set_format(handle, params, format));
/* set the count of channels */
ALSA_ERR(snd_pcm_hw_params_set_channels(handle, params, channels));
/* set the stream rate */
rrate = rate;
ALSA_ERR(snd_pcm_hw_params_set_rate_near(handle, params, &rrate, 0));
if (rrate != rate) {
printf("alsa: rate doesn't match (requested %iHz, get %iHz)\n", rate, rrate);
return -EINVAL;
} else {
printf("alsa: rate set to %i Hz\n", rate);
}
/* set the buffer time */
ALSA_ERR(snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, &dir));
ALSA_ERR(snd_pcm_hw_params_get_buffer_size(params, &size));
*buffer_size = size;
printf("alsa: bufffer size set to: %d requested buffer time: %ld \n", (int) *buffer_size,
(long) buffer_time);
// set the period time
ALSA_ERR(snd_pcm_hw_params_set_period_time_near(handle, params, &period_time, &dir));
ALSA_ERR(snd_pcm_hw_params_get_period_size(params, &size, &dir));
*period_size = size;
printf("alsa: period size set to: %d requested period time: %ld \n", (int) *period_size,
(long) period_time);
/* write the parameters to device */
ALSA_ERR(snd_pcm_hw_params(handle, params));
return 0;
}
 
static int set_swparams(snd_pcm_t *handle, snd_pcm_sw_params_t *swparams, unsigned int buffer_size)
{
/* get the current swparams */
ALSA_ERR(snd_pcm_sw_params_current(handle, swparams));
// start the transfer when the buffer is almost full: never for our case
ALSA_ERR(snd_pcm_sw_params_set_start_threshold(handle, swparams, 2 * buffer_size));
ALSA_ERR(snd_pcm_sw_params_set_period_event(handle, swparams, 1));
/* write the parameters to the playback device */
ALSA_ERR(snd_pcm_sw_params(handle, swparams));
return 0;
}
 
unsigned int linear_windowed_chirp(short *pole) // generate the ping signal
{
unsigned int maxval = (1 << (snd_pcm_format_width(alsa_format) - 1)) - 1;
static const float f0 = 5000; // starting frequency
static const float fmax = 10000; // ending frequency
static const float Tw = 0.0015; // time width of ping in seconds
static float k;
unsigned int n=0;
double t;
unsigned int chirp_samples; //number of samples per period
k=2*(fmax-f0)/Tw;
chirp_samples = ceil(alsa_rate*Tw); // compute size of ping sinal in samples
for (n=0;n<=chirp_samples;n++)
{
t = (double) n / (double)alsa_rate;
pole[n] = (short) floor( (0.35875 - 0.48829*cos(2*M_PI*t*1/Tw) + 0.14128*cos(2*M_PI*2*t*1/Tw) - 0.01168*cos(2*M_PI*3*t*1/Tw))*maxval*sin(2*M_PI*(t)*(f0+(k/2)*(t))) ); // signal generation formula
}
return (chirp_samples); // return count of samples in ping
}
 
int main (int argc, char *argv[]) {
snd_pcm_t *playback_handle, *capture_handle;
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
snd_pcm_sframes_t buffer_size; // size of buffer at sound card
snd_pcm_sframes_t period_size; // samples per frame
int err, j, l, i, r;
unsigned int n, m;
printf("Simple PC sonar $Rev:$ starting work.. \n");
printf("Initializing ALSA.. \r");
fflush(stdout);
snd_pcm_hw_params_alloca(&hwparams); // allocation of soundcard parameters registers
snd_pcm_sw_params_alloca(&swparams);
ALSA_ERR(snd_pcm_open(&playback_handle, alsa_device, SND_PCM_STREAM_PLAYBACK, 0));
ALSA_ERR(set_hwparams(playback_handle, hwparams, 1, alsa_rate, alsa_resample,
alsa_buffer_time, &buffer_size, alsa_period_time, &period_size, alsa_format));
ALSA_ERR(set_swparams(playback_handle, swparams, buffer_size));
ALSA_ERR(snd_pcm_open(&capture_handle, alsa_device, SND_PCM_STREAM_CAPTURE, 0));
ALSA_ERR(set_hwparams(capture_handle, hwparams, 2, alsa_rate, alsa_resample,
alsa_buffer_time, &buffer_size, alsa_period_time, &period_size, alsa_format));
ALSA_ERR(set_swparams(capture_handle, swparams, buffer_size));
printf("Initializing ALSA.. done!\n");
short *chirp = calloc(2*period_size, sizeof(short));
short *signal = malloc(2*period_size * sizeof(short));
short *signal_l = malloc(period_size * sizeof(short));
short *signal_r = malloc(period_size * sizeof(short));
long int *correlation_l = malloc(period_size * sizeof(long int)); // arrays to store correlation curve
long int *correlation_r = malloc(period_size * sizeof(long int));
float *echo_map = malloc(period_size * period_size * sizeof(float));
unsigned char *echo_map_ = malloc(400 * 400 * sizeof(unsigned char));
if (!chirp || !signal) {
printf("Can't allocate buffers!\n");
}
printf("Generating ping signal.. \r");
fflush(stdout);
unsigned int chirp_size = linear_windowed_chirp(chirp);
printf("Generating ping signal.. done!\n");
SDL_Surface *sdl_screen;
{
SDL_Init(SDL_INIT_VIDEO);
sdl_screen = SDL_SetVideoMode(400, 400, 32, SDL_SWSURFACE);
}
while (1) {
ALSA_ERR(snd_pcm_writei(playback_handle, chirp, period_size));
ALSA_ERR(snd_pcm_start(playback_handle));
ALSA_ERR(snd_pcm_start(capture_handle));
while (snd_pcm_avail_update(capture_handle) < period_size) {
usleep(1000);
}
ALSA_ERR(snd_pcm_drop(playback_handle));
ALSA_ERR(snd_pcm_drain(capture_handle));
ALSA_ERR(snd_pcm_readi(capture_handle, signal, period_size));
for (i = 0; i < period_size * 2; i += 2) {
signal_l[i >> 1] = signal[i];
signal_r[i >> 1] = signal[i + 1];
}
{
printf("Chirp transmitted\nCorrelating\n");
for (n = 0; n < (period_size - chirp_size - 1); n++) {
l = 0;
r = 0;
for (m = 0; m < chirp_size; m++) {
l += chirp[m] * signal_l[m + n];// correlate with left channel
r += chirp[m] * signal_r[m + n];// correlate with right channel
}
correlation_l[n] = abs(l);
correlation_r[n] = abs(r);
}
for (i = 0; i < period_size * period_size; i += 1)
echo_map[i] = 0.0f;
for (i = 0; i < 400 * 400; i += 1)
echo_map_[i] = 0;
for (i = 0; i < period_size; i += 1) {
double f = V2D * i;
for (j = 0; j < period_size; j += 1) {
double g = V2D * j;
double a, b;
/*
a=(2*f*g*Xl+f*f*Xr+Xl*(g*g+(Xl-Xr)*Xr))/(2*g*Xl+2*f*Xr);
b=(g*g*Xl-2*f*g*Xr+Xr*(f*f+Xl*(-Xl+Xr)))/(2*g*Xl-2*f*Xr);
*/
a = f - sqrt(pow(g * g * Xl - Xr * (f * f + Xl *
(-Xl + Xr)), 2) / pow(g * Xl - f * Xr, 2)) / 2.0;
b = g - sqrt(pow(g * g * Xl - Xr * (f * f + Xl *
(-Xl + Xr)), 2) / pow(g * Xl - f * Xr, 2)) / 2.0;
if (((Xr-Xl)<=a+b) && (b<=a+(Xr-Xl)) && (a<=b+(Xr-Xl))) {
/*
float x = (f*((f-g)*g + Xl*Xl)-b*Xr*Xr)/(2*f*Xl-2*g*Xr);
float y = sqrt(((-g*g+Xl*Xl)*(f-Xr)*(f-g+Xl-Xr)*(f+Xr)
*(f-g-Xl+Xr))/(4*(f*Xl-g*Xr)*(f*Xl-g*Xr)));
*/
errno = 0;
float x = (f * f * g - g * Xl * Xl + f
* (- g * g + Xr * Xr))
/ (-2 * g * Xl + 2 * f * Xr);
float y = sqrt(-((g * g * (f * f - Xl * Xl)
* (f * f - 2 * f * g + g * g
- (Xl - Xr) * (Xl - Xr)) * (g * g - Xr * Xr))
/ pow(g * Xl - f * Xr, 2)))/(2.0 * g);
/*
if (x < 0)
printf("%f\n", x);
*/
if ((x == x) && (y == y) && (errno != EDOM)) // check for NaN (NaN == NaN is false)
echo_map[period_size * ((int) (y / ((float) V2D)))
+ ((int) (x / ((float) V2D))
+ (period_size/2))] =
sqrt(correlation_l[i]/2)*sqrt(correlation_r[j]/2);
}
}
}
for (i = 0; i < period_size; i += 1) {
for (j = 0; j < period_size; j += 1) {
int y = i * 400 / period_size;
int x = j * 400 / period_size;
Uint8 green = echo_map[i*period_size+j]/(2000000000/255);
Uint8 *pointer = &echo_map_[y*400+x];
if (green > *pointer)
*pointer = green;
}
}
for (i = 0; i < 400; i += 1) {
for (j = 0; j < 400; j += 1) {
Uint32* bufp = (Uint32 *)sdl_screen->pixels + i*sdl_screen->pitch/4 + j;
*bufp = SDL_MapRGB(sdl_screen->format, 0, echo_map_[i*400+j], 0);
}
}
SDL_UpdateRect(sdl_screen, 0, 0, 400, 400);
SDL_Event sdl_event;
while (SDL_PollEvent(&sdl_event)) {
if (sdl_event.type == SDL_QUIT)
return 0;
}
/*
FILE *out = fopen("output", "w");
for (i = 0; i <= (period_size - 1); i++) {
fprintf(out, "%2.3f %6d %6d %9ld %9ld\n", (float)i*V2D, signal_l[i], signal_r[i], correlation_l[i], correlation_r[i]);
}
fclose(out);
*/
}
ALSA_ERR(snd_pcm_prepare(playback_handle));
ALSA_ERR(snd_pcm_prepare(capture_handle));
}
return 0;
}