{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "b2d45592-5695-40ec-ad90-7d03275337a6", "metadata": {}, "outputs": [], "source": [ "# import scipy.signal\n", "\n", "# def high_pass_filter(audio, sr, cutoff=200, order=3):\n", "# \"\"\"\n", "# Applies a high-pass filter to an audio signal.\n", "\n", "# Parameters:\n", "# audio (numpy array): The input audio signal.\n", "# sr (int): The sample rate of the audio signal.\n", "# cutoff (float): The cutoff frequency in Hz. Default is 100 Hz.\n", "# order (int): The order of the filter. Default is 5.\n", " \n", "# Returns:\n", "# numpy array: The filtered audio signal.\n", "# \"\"\"\n", "# # Design the high-pass filter using a Butterworth filter design\n", "# sos = scipy.signal.butter(order, cutoff, btype='highpass', fs=sr, output='sos')\n", " \n", "# # Apply the filter using sosfilt (second-order sections filter)\n", "# filtered_audio = scipy.signal.sosfilt(sos, audio)\n", " \n", "# return filtered_audio" ] }, { "cell_type": "code", "execution_count": null, "id": "8a1efa78-61d4-4545-b50a-080161bb6aa5", "metadata": {}, "outputs": [], "source": [ "def high_pass_filter(audio, sr, cutoff=300):\n", " # Design a Butterworth high-pass filter\n", " nyquist = 0.5 * sr\n", " normal_cutoff = cutoff / nyquist\n", " b, a = butter(1, normal_cutoff, btype='high', analog=False)\n", " filtered_audio = lfilter(b, a, audio)\n", " return filtered_audio" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.7" } }, "nbformat": 4, "nbformat_minor": 5 }