aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandreas128 <Andreas>2016-12-02 10:03:43 +0100
committerandreas128 <Andreas>2016-12-02 10:03:43 +0100
commit9623ce222ae217b816eb11dcb4bdf3289dc616cb (patch)
treec12230ebcb3ea77ead6814585c2b897646f2d2ba
parentd31ea5a51f0cc17b0556423896b7b0b7b3c2c217 (diff)
downloadODR-StaticPrecorrection-9623ce222ae217b816eb11dcb4bdf3289dc616cb.tar.gz
ODR-StaticPrecorrection-9623ce222ae217b816eb11dcb4bdf3289dc616cb.tar.bz2
ODR-StaticPrecorrection-9623ce222ae217b816eb11dcb4bdf3289dc616cb.zip
Linearised by using search for best amplitude
-rw-r--r--.gitignore35
-rwxr-xr-xamplitude_ramp.py14
-rw-r--r--lut_generator.ipynb136
3 files changed, 177 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..54b9753
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,35 @@
+.directory
+.ipynb_checkpoints/
+.plot.py.swp
+dual_tone.py
+dual_tone.pyc
+lut.pkl
+lut_plot/
+lut_sq.pkl
+lut_tab.pkl
+measurements.csv
+measurements.pkl
+measurements_lut.pkl
+measurements_lut_sq.pkl
+measurements_tab.pkl
+plots/
+tcp_async.pyc
+usrp_rx
+usrp_tx
+lut_generator.py
+
+
+
+# Created by https://www.gitignore.io/api/vim
+
+### Vim ###
+# swap
+[._]*.s[a-w][a-z]
+[._]s[a-w][a-z]
+# session
+Session.vim
+# temporary
+.netrwhist
+*~
+# auto-generated tag files
+tags
diff --git a/amplitude_ramp.py b/amplitude_ramp.py
index 7ef72e8..fb06d84 100755
--- a/amplitude_ramp.py
+++ b/amplitude_ramp.py
@@ -68,6 +68,9 @@ class RampGenerator(threading.Thread):
if not options.lut is '':
self.lut_dict = pickle.load(open(options.lut, "rb"))
+ assert(type(self.lut_dict) == dict)
+ assert(len(self.lut_dict["ampl"]) > 2)
+ assert(len(self.lut_dict["fac"]) > 2)
self.tcpa = tcpa
@@ -75,7 +78,10 @@ class RampGenerator(threading.Thread):
if self.lut_dict is None:
return 1
else:
- return np.interp(ampl, self.lut_dict["ampl"], self.lut_dict["fac"])
+ interp = np.interp(ampl, self.lut_dict["ampl"], self.lut_dict["fac"])
+ print("interp " + str(interp))
+ print("ampl " + str(ampl))
+ return interp
def set_source_ampl(self, ampl):
self.event_queue_.put(ampl)
@@ -107,8 +113,10 @@ class RampGenerator(threading.Thread):
amplitudes = xrange(self.ampl_start, self.ampl_stop, self.ampl_step)
measurements = []
- for ampl in amplitudes:
+ for idx, ampl in enumerate(amplitudes):
+ print("run ampl " + str(ampl))
ampl_lut = self.lut(ampl) * ampl
+ print("run ampl_lut " + str(ampl_lut))
measurement_correct = False
max_iter = 10
while measurement_correct == False and max_iter > 0:
@@ -240,6 +248,8 @@ try:
elif event == "quit":
break
else:
+ print("event")
+ print(event)
top.set_source_ampl(event)
rampgen.confirm_source_ampl_updated()
finally:
diff --git a/lut_generator.ipynb b/lut_generator.ipynb
index 489203f..d19ac58 100644
--- a/lut_generator.ipynb
+++ b/lut_generator.ipynb
@@ -38,7 +38,8 @@
"source": [
"df = get_meas(\"./measurements.pkl\")\n",
"df_lut = get_meas(\"./measurements_lut.pkl\")\n",
- "df_lut_sq = get_meas(\"./measurements_lut_sq.pkl\")"
+ "df_lut_sq = get_meas(\"./measurements_lut_sq.pkl\")\n",
+ "df_tab = get_meas(\"./measurements_tab.pkl\")"
]
},
{
@@ -46,7 +47,9 @@
"execution_count": null,
"metadata": {},
"outputs": [],
- "source": []
+ "source": [
+ "df.plot()"
+ ]
},
{
"cell_type": "code",
@@ -68,8 +71,8 @@
"outputs": [],
"source": [
"def get_fac(ampl, mag_feedback):\n",
- " slope, intersect = get_slope(df[\"ampl\", df[\"mag_feedback\"]])\n",
- " return[(x*slope + intersect) / y for (x,y) in zip(df[\"ampl\"], df[\"mag_feedback\"])]\n",
+ " slope, intersect = get_slope(ampl, mag_feedback)\n",
+ " return[(x*slope + intersect) / y for (x,y) in zip(ampl, mag_feedback)]\n",
"def interp(x): return np.interp(x, df[\"ampl\"], fac)"
]
},
@@ -80,6 +83,7 @@
"outputs": [],
"source": [
"x = np.linspace(0.1, 0.5, num = 50)\n",
+ "slope, intersect = get_slope(df[\"ampl\"], df[\"mag_feedback\"])\n",
"\n",
"plt.plot(df[\"ampl\"], df[\"mag_feedback\"], label=\"measurement\")\n",
"plt.plot(x, x*slope + intersect, label = \"linear model\")\n",
@@ -130,11 +134,36 @@
"metadata": {},
"outputs": [],
"source": [
+ "slope, intersect = get_slope(df_tab[\"ampl\"], df_tab[\"mag_feedback\"])\n",
+ "\n",
+ "plt.plot(df_tab[\"ampl\"], df_tab[\"mag_feedback\"], label=\"measurement\")\n",
+ "plt.plot(x, x*slope + intersect, label = \"linear model\")\n",
+ "\n",
+ "plt.legend(loc=0)\n",
+ "plt.title(\"Lut Tab Measurement\")\n",
+ "\n",
+ "plt.savefig(\"./lut_plot/lut_tab_measurement.png\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
"slope, intersect = get_slope(df[\"ampl\"], df[\"mag_feedback\"])\n",
"\n",
"plt.plot(df[\"ampl\"], df[\"mag_feedback\"], label=\"measurement\")\n",
"plt.plot(df_lut[\"ampl\"], df_lut[\"mag_feedback\"], label=\"measurement lut\")\n",
"plt.plot(df_lut_sq[\"ampl\"], df_lut_sq[\"mag_feedback\"], label=\"measurement lut sq\")\n",
+ "plt.plot(df_tab[\"ampl\"], df_tab[\"mag_feedback\"], label=\"measurement tab sq\")\n",
"plt.plot(x, x*slope + intersect, label = \"linear model\")\n",
"\n",
"plt.legend(loc=0)\n",
@@ -149,8 +178,103 @@
"metadata": {},
"outputs": [],
"source": [
- "pickle.dump({\"ampl\":df[\"ampl\"],\"fac\":[f for f in fac]}, open(\"lut.pkl\", \"wb\"))\n",
- "pickle.dump({\"ampl\":df[\"ampl\"],\"fac\":[f**2 for f in fac]}, open(\"lut_sq.pkl\", \"wb\"))"
+ "fac = get_fac(df[\"ampl\"], df[\"mag_feedback\"])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "pickle.dump({\"ampl\":list(df[\"ampl\"]),\"fac\":[f for f in fac]}, open(\"lut.pkl\", \"wb\"))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "pickle.dump({\"ampl\":list(df[\"ampl\"]),\"fac\":[f**2 for f in fac]}, open(\"lut_sq.pkl\", \"wb\"))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "slope, intersect = get_slope(df[\"ampl\"], df[\"mag_feedback\"])\n",
+ "ampl_corr = []\n",
+ "for ampl in df[\"ampl\"]:\n",
+ " y = ampl * slope + intersect\n",
+ " mag_feedback_idx = np.argmin(np.abs(df[\"mag_feedback\"] - y))\n",
+ " ampl_corr.append(df[\"ampl\"][mag_feedback_idx])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ampl_corr = np.array(ampl_corr)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "idx_start = np.argmax(ampl_corr != ampl_corr.min()) - 1\n",
+ "idx_end = np.argmin(ampl_corr != ampl_corr.max()) \n",
+ "start = 1.0 * idx_start / len(ampl_corr)\n",
+ "end = 1.0 * idx_end / len(ampl_corr)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "orig_range = np.linspace(start,end,num=len(ampl_corr))\n",
+ "new_range = np.linspace(0,1,num=len(ampl_corr))\n",
+ "\n",
+ "ampl_corr_new = []\n",
+ "for f in new_range:\n",
+ " ratio = np.interp(f, new_range, orig_range)\n",
+ " new_ampl = np.interp(ratio, new_range, ampl_corr)\n",
+ " ampl_corr_new.append(new_ampl)\n",
+ "ampl_corr_new"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "fac = ampl_corr_new / df[\"ampl\"]\n",
+ "pickle.dump({\"ampl\":list(df[\"ampl\"]),\"fac\":[f for f in list(fac)]}, open(\"lut_tab.pkl\", \"wb\"))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "pickle.load(open(\"./lut_tab.pkl\"))"
]
},
{