{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Complex Multipy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pylab inline\n", "pylab.rcParams['savefig.dpi'] = 400\n", "import numpy as np\n", "from caf_verilog.cpx_multiply import CpxMultiply" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Source Signals" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fs = 1\n", "n = np.arange(0,10000)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = np.exp(2*np.pi*0.15*n*1j)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Pxp, ffp = psd(x,2**10, fs)\n", "plot(ffp, 10*np.log10(Pxp))\n", "ylim([-80, 25])\n", "xlim([0, 0.2])\n", "savefig('cpx_multiply_pos.png')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "y = np.exp(-2*np.pi*0.05*n*1j)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Pxn, ffn = psd(y,2**10, fs)\n", "plot(ffn, 10*np.log10(Pxn))\n", "ylim([-80, 25])\n", "savefig('cpx_multiply_neg.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Shifted Signal" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "shifted_signal = x * y\n", "Px, ff = psd(shifted_signal,2**10, fs)\n", "plot(ff, 10*np.log10(Px))\n", "ylim([-80, 25])\n", "xlim([0, 0.2])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## CpxMultiply" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "output_dir = '.'\n", "cpx_multipy = CpxMultiply(x, y, output_dir=output_dir)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Power Loss" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Px, ff = psd(cpx_multipy.x_quant,2**10, fs)\n", "plot(ff, 10*np.log10(Px))\n", "ylim(bottom=0)\n", "xlim([0, 0.2])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Optimal Shifted Signal" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Px, ff = psd(cpx_multipy.gen_quantized_output(),2**10, fs)\n", "plot(ff, 10*np.log10(Px))\n", "ylim(bottom=0)\n", "xlim([0, 0.2])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Module Shifted Output" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cpx_multipy.gen_tb()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from caf_verilog.io_helper import read_complex_output\n", "import os\n", "cpx_output = read_complex_output(os.path.join('.', cpx_multipy.test_output_filename))\n", "cpx_output = array(cpx_output)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qt_check = cpx_multipy.gen_quantized_output()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "assert len(qt_check) == len(cpx_output)\n", "for qt,cpo in zip(qt_check, cpx_output):\n", " assert qt == cpo" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Px_out, ff_out = psd(cpx_output.real,2**10, fs)\n", "plot(ff_out, 10*np.log10(Px_out))\n", "ylim(bottom=0)\n", "xlim([0, 0.2])\n", "savefig('cpx_multiply_module_out.png')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }