<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Generating Simple Audio Signals\n",
    "\n",
    "[back to main page](index.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We create a simple sine wave as an introductory example using Python and NumPy.\n",
    "\n",
    "Let's start with some basic Python. We create three numbers and give each of them a name.\n",
    "\n",
    "> Sometimes these are called *variables*, but that is actually misleading.\n",
    "> Think about objects and names. An object is created (in our case a number) and we specify a name by which we want to access this object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dur = 1.5  # duration in seconds\n",
    "freq = 440.  # frequency in Hertz\n",
    "fs = 44100  # sampling frequency in Hertz"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Everything following a `#` sign is a comment.\n",
    "\n",
    "There is no output. If you want to see which object a certain name refers to, just type the name:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dur"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In Python, *everything* is an object. And every object has a *type*. Let's see ..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(dur), type(freq), type(fs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that we didn't specify any types explicitly, we just got Python's default types. Numbers with a comma are by default of type `float`, values without comma are of type `int`.\n",
    "\n",
    "There are many more types in Python (strings, tuples, lists, dictionaries, ...), but let's ignore them for now.\n",
    "\n",
    "If you want an overview about all the objects you have defined up to now, use `%who` or its more verbose cousin `%whos`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%whos"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, let's bring NumPy into the game. The canonical way to do that in a Python script is"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With this, we'll have to prepend \"`np.`\" to all NumPy functions, types etc.\n",
    "\n",
    "Now let's create the most basic signal, a sine. This is kind of the \"Hello World!\" of signals.\n",
    "\n",
    "In order to create a sine tone, we need first a series of time instances to represent our sampling times. The distance between those instances is the *sampling interval* $\\tau = \\frac{1}{f_s}$, where $f_s$ is the *sampling frequency*.\n",
    "\n",
    "To create a series of regularly ascending (or descending) values, NumPy provides the function `arange()`. Let's use that."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "t = np.arange(0, np.ceil(dur * fs)) / fs\n",
    "t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see, this creates an array of numbers from 0 to just below the value specified in `dur`. These are a lot of numbers, so to avoid flooding us with heaps of useless output, IPython just shows the first and last few values. Very handy.\n",
    "\n",
    "> Note that in Python 2 and before, the division operator works a little differently then in Python 3. Here we assume we're using the latter, where the division of two `int`s returns a `float` value (and not an `int` with the truncated result!).\n",
    "> To make sure this also works as expected in Python 2, you can convert one operand to `float` before the division or use a special `import` statement:\n",
    ">\n",
    "> ```python\n",
    ">     1. / fs\n",
    "> ```\n",
    ">\n",
    "> or\n",
    ">\n",
    "> ```python\n",
    ">     1 / float(fs)\n",
    "> ```\n",
    ">\n",
    "> or\n",
    ">\n",
    "> ```python\n",
    ">     from __future__ import division\n",
    ">     1 / fs\n",
    "> ```\n",
    "\n",
    "Let's check the type of `t`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(t)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [<commit_msg>Fix some Markdown code stuff<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Generating Simple Audio Signals\n",
    "\n",
    "[back to main page](index.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We create a simple sine wave as an introductory example using Python and NumPy.\n",
    "\n",
    "Let's start with some basic Python. We create three numbers and give each of them a name.\n",
    "\n",
    "> Sometimes these are called *variables*, but that is actually misleading.\n",
    "> Think about objects and names. An object is created (in our case a number) and we specify a name by which we want to access this object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dur = 1.5  # duration in seconds\n",
    "freq = 440.  # frequency in Hertz\n",
    "fs = 44100  # sampling frequency in Hertz"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Everything following a `#` sign is a comment.\n",
    "\n",
    "There is no output. If you want to see which object a certain name refers to, just type the name:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dur"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In Python, *everything* is an object. And every object has a *type*. Let's see ..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(dur), type(freq), type(fs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that we didn't specify any types explicitly, we just got Python's default types. Numbers with a comma are by default of type `float`, values without comma are of type `int`.\n",
    "\n",
    "There are many more types in Python (strings, tuples, lists, dictionaries, ...), but let's ignore them for now.\n",
    "\n",
    "If you want an overview about all the objects you have defined up to now, use `%who` or its more verbose cousin `%whos`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%whos"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, let's bring NumPy into the game. The canonical way to do that in a Python script is"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With this, we'll have to prepend \"`np.`\" to all NumPy functions, types etc.\n",
    "\n",
    "Now let's create the most basic signal, a sine. This is kind of the \"Hello World!\" of signals.\n",
    "\n",
    "In order to create a sine tone, we need first a series of time instances to represent our sampling times. The distance between those instances is the *sampling interval* $\\tau = \\frac{1}{f_s}$, where $f_s$ is the *sampling frequency*.\n",
    "\n",
    "To create a series of regularly ascending (or descending) values, NumPy provides the function `arange()`. Let's use that."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "t = np.arange(0, np.ceil(dur * fs)) / fs\n",
    "t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see, this creates an array of numbers from 0 to just below the value specified in `dur`. These are a lot of numbers, so to avoid flooding us with heaps of useless output, IPython just shows the first and last few values. Very handy.\n",
    "\n",
    "> Note that in Python 2 and before, the division operator works a little differently then in Python 3. Here we assume we're using the latter, where the division of two `int`s returns a `float` value (and not an `int` with the truncated result!).\n",
    "> To make sure this also works as expected in Python 2, you can convert one operand to `float` before the division or use a special `import` statement:\n",
    ">\n",
    "> ```python\n",
    "> 1. / fs\n",
    "> ```\n",
    ">\n",
    "> or\n",
    ">\n",
    "> ```python\n",
    "> 1 / float(fs)\n",
    "> ```\n",
    ">\n",
    "> or\n",
    ">\n",
    "> ```python\n",
    "> from __future__ import division\n",
    "> 1 / fs\n",
    "> ```\n",
    "\n",
    "Let's check the type of `t`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(t)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
{'fraction_non_alphanumeric': 0.17227372148734507, 'fraction_numerical': 0.003957921049890636, 'mean_word_length': 2.6192989068978516, 'pattern_counts': {'":': 126, '<': 3, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5176385', 'n_tokens_mistral': 3323, 'n_tokens_neox': 3178, 'n_words': 1140}