{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Signal Generator" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pylab inline\n", "pylab.rcParams['savefig.dpi'] = 300" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from caf_verilog.sig_gen import SigGen, lut_values" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fs = 625e3\n", "n_bits = 8\n", "freq_res = 200\n", "f_out = 20e3" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "values = lut_values(n_bits)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(values)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sg = SigGen(freq_res, fs, n_bits)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sg.phase_bits" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sg.gen_tb(f_out)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from caf_verilog.io_helper import read_complex_output" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "output_values = read_complex_output(sg.test_output_filename)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from caf_verilog.quantizer import quantize" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vals = 40\n", "n = arange(0, vals)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cref = cos(2 * pi * (f_out / fs) * n)\n", "cquant = quantize(cref, n_bits)\n", "plot(array(output_values[:vals]).real)\n", "plot(cquant)\n", "title(r'Quantized Cosine Output')\n", "ylabel(\"8-bit Magnitude\")\n", "xlabel(\"N-th Sample\")\n", "savefig('dds_one_cycle.png')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sref = sin(2 * pi * (f_out / fs) * n)\n", "squant = quantize(sref, n_bits)\n", "plot(array(output_values[:vals]).imag)\n", "plot(squant)\n", "title(r'Quantized Sine Output')\n", "ylabel(\"8-bit Magnitude\")\n", "xlabel(\"N-th Sample\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Px, ff = psd(output_values, 2**12, fs)\n", "plot(ff, 10*log10(Px))\n", "xlim([15000, 25000])\n", "ylim([-80, 20])\n", "xlabel(\"Frequency (Hz)\")\n", "title(\"Output Spectrum Centered at 20kHz\")\n", "savefig('sig_gen_8_200.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.7" } }, "nbformat": 4, "nbformat_minor": 2 }