{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "VqZvf8p_wDFu"
},
"source": [
"# Basic properties of signals\n",
"\n",
"> Marcos Duarte, Renato Naville Watanabe \n",
"> [Laboratory of Biomechanics and Motor Control](https://bmclab.pesquisa.ufabc.edu.br) \n",
"> Federal University of ABC, Brazil"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "NCIR4smjwDFw"
},
"source": [
"A signal is a set of data that conveys information about some phenomenon (Bendat, Piersol 2010; Lathi 2009; Lyons 2010). A signal can be represented mathematically by a function of one or more independent variables. We also refer to signal as simply data. The time-dependent voltage of an electric circuit and the acceleration of a moving body are examples of signals. \n",
"\n",
"Let's see now a brief description about the basic properties of signals (for a more detailed description, see Bendat, Piersol 2010; Lathi 2009; Lyons 2010; Smith 1997)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "XSF2B4wAwDFx"
},
"source": [
"## Setup"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2017-12-30T08:08:39.303536Z",
"start_time": "2017-12-30T08:08:39.066942Z"
},
"id": "CEiIvPBpwDFy"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "VrQZuzW8wDFz"
},
"source": [
"## Amplitude, frequency, period, and phase\n",
"\n",
"A periodic function can be characterized by the properties: amplitude, frequency, period, and phase. Let's exemplify these properties for a periodic function composed by a single frequency, the sine wave or sinusoid [trigonometric function](https://en.wikipedia.org/wiki/Trigonometric_functions):\n",
"\n",
"$$ x(t) = A\\sin(2 \\pi f t + \\phi) $$\n",
"\n",
"Where $A$ is the amplitude, $f$ the frequency, $\\phi$ the phase, and $T=1/f$ the period of the function $x(t)$. \n",
"\n",
"We can define $\\omega=2\\pi f = 2\\pi/T$ as the angular frequency, then:\n",
"\n",
"$$ x(t) = A\\sin(\\omega t + \\phi) $$\n",
"\n",
"Let's visualize this function:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2017-12-30T08:08:40.307624Z",
"start_time": "2017-12-30T08:08:40.297248Z"
},
"id": "FdRKd9szwDFz"
},
"outputs": [],
"source": [
"t = np.linspace(-2, 2, 101) # time vector\n",
"A = 2 # amplitude\n",
"freq = 0.5 # frequency, Hz\n",
"phase = np.pi/4 # phase, radians (45o)\n",
"x1 = 1 * np.sin(2 * np.pi * 1 * t + 0) # sinusoid 1\n",
"x2 = A * np.sin(2 * np.pi * freq * t + phase) # sinusoid 2"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "-GqyzwJuwDFz"
},
"outputs": [],
"source": [
"def wave_plot(freq, t, y, y2, ax=None):\n",
" \"\"\"Propertie of waves: amplitude, frequency, phase.\n",
" \"\"\"\n",
" import matplotlib.pyplot as plt\n",
" from matplotlib.ticker import MultipleLocator\n",
"\n",
" plt.rc('xtick', labelsize=14)\n",
" plt.rc('ytick', labelsize=14)\n",
" if ax is None:\n",
" fig, ax = plt.subplots(1, 1, figsize=(12, 4))\n",
" ax.plot(t, y, color=[0, .5, 0, .5], linewidth=5)\n",
" ax.plot(t, y2, color=[0, 0, 1, .5], linewidth=5)\n",
" ax.spines['bottom'].set_position('zero')\n",
" ax.spines['top'].set_color('none')\n",
" ax.spines['left'].set_position('zero')\n",
" ax.spines['right'].set_color('none')\n",
" ax.xaxis.set_ticks_position('bottom')\n",
" ax.yaxis.set_ticks_position('left')\n",
" ax.tick_params(axis='both', direction='inout', which='both', length=5)\n",
" ax.set_xlim((-2.05, 2.05))\n",
" ax.set_ylim((-2.1, 2.1))\n",
" ax.locator_params(axis='both', nbins=7)\n",
" ax.xaxis.set_minor_locator(MultipleLocator(.25))\n",
" ax.yaxis.set_minor_locator(MultipleLocator(.5))\n",
" ax.grid(which='both')\n",
" ax.set_title(r'$Asin(2\\pi ft+\\phi)$', loc='left', size=20, color=[0, 0, 0])\n",
" ax.set_title(r'$x_1=sin(2\\pi t)$', loc='center', size=20, color=[0, .5, 0])\n",
" ax.set_title(r'$x_2=2sin(\\pi t + \\pi/4)$', loc='right', size=20, color=[0, 0, 1])\n",
" ax.annotate('', xy=(.25, 0), xycoords='data', xytext=(.25, 2), size=16,\n",
" textcoords='data',\n",
" arrowprops={'arrowstyle': '<->', 'fc': 'b', 'ec': 'b'})\n",
" ax.annotate(r'$A=2$', xy=(.25, 1.1), xycoords = 'data', xytext=(0, 0),\n",
" textcoords = 'offset points', size=18, color='b')\n",
" ax.annotate('', xy=(0, 1.6), xycoords='data', xytext=(-.25, 1.6), size=16,\n",
" textcoords='data',\n",
" arrowprops={'arrowstyle': '<->', 'fc': 'b', 'ec': 'b'})\n",
" ax.annotate(r'$t_{\\phi}=\\phi/2\\pi f\\,(\\phi=\\pi/4)$', xy=(-1.25, 1.6),\n",
" xycoords = 'data', xytext=(0, -5),\n",
" textcoords = 'offset points', size=18, color='b')\n",
" ax.annotate('', xy=(-.25, 0), xycoords='data', xytext=(-.25, 2),\n",
" textcoords='data', arrowprops={'arrowstyle': '-',\n",
" 'linestyle': 'dotted', 'fc': 'b', 'ec': 'b'}, size=16)\n",
" ax.annotate('', xy=(-.75, -1.8), xycoords='data', xytext=(1.25, -1.8),\n",
" textcoords='data', size=10,\n",
" arrowprops={'arrowstyle': '|-|', 'fc': 'b', 'ec': 'b'})\n",
" ax.annotate(r'$T=1/f\\,(f=0.5\\,Hz)$', xy=(-.16, -1.8), xycoords = 'data',\n",
" xytext=(0, 8), textcoords = 'offset points', size=18, color='b')\n",
" ax.annotate(r'$t[s]$', xy=(2.05, -.5), xycoords = 'data', xytext=(0, 0),\n",
" textcoords = 'offset points', size=18, color='k')\n",
" plt.suptitle(r'Amplitude ($A$), frequency ($f$), period ($T$), phase ($\\phi$)',\n",
" fontsize=18, y=1.08)\n",
"\n",
" return ax"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2017-12-30T08:08:41.829023Z",
"start_time": "2017-12-30T08:08:41.184890Z"
},
"id": "K4R-nZDtwDF0",
"outputId": "97d11390-5fc0-4663-b086-ec248812e99f",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 429
}
},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"