aboutsummaryrefslogtreecommitdiffstats
path: root/generate_compensated_2_tone_file.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'generate_compensated_2_tone_file.ipynb')
-rw-r--r--generate_compensated_2_tone_file.ipynb291
1 files changed, 291 insertions, 0 deletions
diff --git a/generate_compensated_2_tone_file.ipynb b/generate_compensated_2_tone_file.ipynb
new file mode 100644
index 0000000..7037d3b
--- /dev/null
+++ b/generate_compensated_2_tone_file.ipynb
@@ -0,0 +1,291 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%matplotlib inline\n",
+ "import matplotlib.pyplot as plt\n",
+ "import numpy as np"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "a = np.fromfile(\"./out_sin\", np.complex64)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "a.shape"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "a = a[0:100]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "mag = np.abs(a)\n",
+ "plt.plot(mag)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.plot(a.imag[0:100])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.plot(a.real[0:100])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def complex_exp(freq, samp_rate, periods, phase_deg=0):\n",
+ " t_max = 1.0 * samp_rate / freq * periods\n",
+ " t = np.arange(t_max)\n",
+ " fac = t / samp_rate * freq\n",
+ " phase = 1j * phase_deg/360*2*np.pi\n",
+ " ret = np.exp(phase + 1j * 2 * np.pi * fac - 1j * np.pi / 2, dtype=np.complex64)\n",
+ " return ret\n",
+ "ret = complex_exp(10,40,2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "samp_rate = 4000000 #samples / second\n",
+ "frequency_0 = samp_rate/9. #cycles / second\n",
+ "frequency_1 = samp_rate/10. #cycles / second\n",
+ "tone_0 = complex_exp(frequency_0, samp_rate, 10, 180)\n",
+ "tone_1 = complex_exp(frequency_1, samp_rate, 9)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def complex_exp(freq, samp_rate, periods):\n",
+ " t_max = 1.0 * samp_rate / freq * periods\n",
+ " t = np.arange(t_max)\n",
+ " fac = t / samp_rate * freq\n",
+ " ret = np.exp(1j * 2 * np.pi * fac - 1j * np.pi / 2)\n",
+ " return ret\n",
+ "ret = complex_exp(10,40,2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "two_tone = 1/2.0 * (tone_0 + tone_1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "two_tone[-1]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "two_tone.tofile(\"./np_twotone\")\n",
+ "two_tone.dtype"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "a_load = np.fromfile(\"./np_twotone\", dtype=np.complex64)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.plot(a_load.real[0:100])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import pickle"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "lut_dict = pickle.load(open(\"./lut_tab.pkl\", \"rb\"))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def dpd(x):\n",
+ " mag = np.abs(x)\n",
+ " fac = np.interp(mag/2.0, lut_dict[\"ampl\"], lut_dict[\"fac\"])\n",
+ " ret = x*fac\n",
+ " return ret.astype(np.complex64)\n",
+ "\n",
+ "#def dpd(x):\n",
+ "# return x*0.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "tone_0_dpd = np.apply_along_axis(dpd, 0, tone_0)\n",
+ "tone_1_dpd = np.apply_along_axis(dpd, 0, tone_1)\n",
+ "two_tone_dpd = 1/2. * (tone_0_dpd + tone_1_dpd)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.plot(two_tone_dpd.real[0:200])\n",
+ "plt.plot(two_tone.real[0:200])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "two_tone_dpd.tofile(\"./np_twotone\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "two_tone.tofile(\"./np_twotone\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "a_load = np.fromfile(\"./np_twotone_dpd\", dtype=np.complex64)\n",
+ "plt.plot(a_load.real[0:200])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 1
+}