{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# EECS16A Discussion 6B" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 2: Identifying Satellites and their Delays" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Parts (a) & (b)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s1 = [1, 1, -1, 1, 1]\n", "s2 = [1, 1, 1, -1, -1]\n", "r = [0.2, 0.2, 1, 1, -1.2, 1, 1, 0.2, -0.2]\n", "#r = [0, 1, 1, -1, 2, 2, 1, -1, -1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Use the function np.correlate with mode='full' for linear cross correlation.\n", "corr_r_s1 = ?\n", "\n", "#Since both the arrays start at 0, the last \"shift\" where the signals overlap is the length of the first array\n", "end_index = ?\n", "#Similarly, the first \"shift\" where the signals overlap is the negative of the length of the second array, offset by one because of the zero index.\n", "st_index = ?\n", "\n", "indices = np.arange(st_index, end_index) \n", "print('Linear correlation of r and s1:',corr_r_s1)\n", "plt.figure(figsize = (10, 5))\n", "plt.stem(indices, corr_r_s1)\n", "plt.xlabel(\"Index of correlation\")\n", "plt.ylabel(\"Correlation value\")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "corr_r_s2 = ?\n", "\n", "end_index = ?\n", "st_index = ?\n", "\n", "indices = np.arange(st_index, end_index) \n", "print('Linear correlation of r and s2:',corr_r_s2)\n", "plt.figure(figsize = (10, 5))\n", "plt.stem(indices, corr_r_s2)\n", "plt.xlabel(\"Index of correlation\")\n", "plt.ylabel(\"Correlation value\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernel_info": { "name": "python3" }, "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.7.1" }, "nteract": { "version": "0.12.3" } }, "nbformat": 4, "nbformat_minor": 1 }