{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "c9a47191",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "333401dc",
            "cell_type": "markdown",
            "source": "Simple operations:\n",
            "metadata": {}
        },
        {
            "id": "9c21316c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.signal import upfirdn\nupfirdn([1, 1, 1], [1, 1, 1])   # FIR filter",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 1.,  2.,  3.,  2.,  1.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "c38d6ae5",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "upfirdn([1], [1, 2, 3], 3)  # upsampling with zeros insertion",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 1.,  0.,  0.,  2.,  0.,  0.,  3.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "1c65712d",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "upfirdn([1, 1, 1], [1, 2, 3], 3)  # upsampling with sample-and-hold",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 1.,  1.,  1.,  2.,  2.,  2.,  3.,  3.,  3.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "ad3bdea4",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "upfirdn([.5, 1, .5], [1, 1, 1], 2)  # linear interpolation",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 0.5,  1. ,  1. ,  1. ,  1. ,  1. ,  0.5])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "6ab475e0",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "upfirdn([1], np.arange(10), 1, 3)  # decimation by 3",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 0.,  3.,  6.,  9.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "7d1d06c9",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "upfirdn([.5, 1, .5], np.arange(10), 2, 3)  # linear interp, rate 2/3",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 0. ,  1. ,  2.5,  4. ,  5.5,  7. ,  8.5])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "83773b6b",
            "cell_type": "markdown",
            "source": "Apply a single filter to multiple signals:\n",
            "metadata": {}
        },
        {
            "id": "d7d750ae",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = np.reshape(np.arange(8), (4, 2))\nx",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0, 1],\n       [2, 3],\n       [4, 5],\n       [6, 7]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "7865ed03",
            "cell_type": "markdown",
            "source": "Apply along the last dimension of ``x``:\n",
            "metadata": {}
        },
        {
            "id": "24f3ae9a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "h = [1, 1]\nupfirdn(h, x, 2)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 0.,  0.,  1.,  1.],\n       [ 2.,  2.,  3.,  3.],\n       [ 4.,  4.,  5.,  5.],\n       [ 6.,  6.,  7.,  7.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "31a5ff5d",
            "cell_type": "markdown",
            "source": "Apply along the 0th dimension of ``x``:\n",
            "metadata": {}
        },
        {
            "id": "02aa464e",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "upfirdn(h, x, 2, axis=0)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 0.,  1.],\n       [ 0.,  1.],\n       [ 2.,  3.],\n       [ 2.,  3.],\n       [ 4.,  5.],\n       [ 4.,  5.],\n       [ 6.,  7.],\n       [ 6.,  7.]])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}