[PYTHON] Create filter with scipy

Continue to scipy story. When I was looking at the official reference, I found a function for creating a filter, so I immediately experimented. This time, I made a low-pass filter by the remez method and the window function method.

filter.py


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import scipy as sp
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

if __name__ == '__main__':
    #Passband is 0 to 0 with 64 taps.25,Blocking area is 0.3〜0.5 filters
    taps = 64;
    edge = [ 0,  0.25 , 0.3, 0.5 ]
    gain = [ 1.0,  0.000 ]
    weight = [ 0.2, 1.0 ]

    remez_impres = sp.signal.remez( taps,  edge, gain )
    remez_freq, remez_fresponse = sp.signal.freqz( remez_impres )
    remez_amp = np.abs( remez_fresponse )

    wf_impres = sp.signal.firwin( taps, 2.0 * edge[1] );
    wf_freq, wf_fresponse = sp.signal.freqz( wf_impres )
    wf_amp = np.abs( wf_fresponse )

    plt.subplot(221)
    plt.semilogy( remez_freq / ( 2 * np.pi ),  remez_amp, 'b-' )
    plt.title( 'Frequency Response( Remez )' )

    plt.subplot(222)
    plt.plot( remez_impres, 'b-' )
    plt.title( 'Impres Response( Remez )' )

    plt.subplot(223)
    plt.semilogy( wf_freq / ( 2 * np.pi ),  wf_amp, 'b-' )
    plt.title( 'Frequency Response( Window )' )

    plt.subplot(224)
    plt.plot( wf_impres, 'b-' )
    plt.title( 'Impres Response( Window )' )
    plt.show()

The window function method was unexpectedly good. It's easy to set parameters, and I think this is better if you want to use it casually.

filter_design.png

Recommended Posts

Create filter with scipy
LPC with Scipy
ICA with Scipy
CORDIC with Scipy
About scipy Gaussian filter
Create games with Pygame
Create 3D scatter plot with SciPy + matplotlib (Python)
Normarize data with Scipy
FFT processing with numpy and scipy and low pass filter
Create an environment with virtualenv
Create Cloud TPU with tf-nightly
Create an API with Django
Create / search / create table with PynamoDB
Create 3d gif with python3
Create graph with plotly button
Create a homepage with django
[Python] Filter spreadsheets with gspread
Create Image Viewer with Tkinter
Create custom rules with ElastAlert
Create patent map with Streamlit
Create a heatmap with pyqtgraph
Use OpenBLAS with numpy, scipy
Create a directory with python
Parameter estimation with Kalman filter
Extract peak values with scipy
Create xlsx file with XlsxWriter
Harmonic mean with Python Harmonic mean (using SciPy)
Calculate sample distribution with Scipy (discrete distribution)
Create Awaitable with Python / C API
Create screen scroll with Pythonista + scene
Generate a normal distribution with SciPy
[AWS] Create API with API Gateway + Lambda
Create folders from '01' to '12' with python
Create a virtual environment with Python!
Create an Excel file with Python3
Create LGTM images with GIMP! (Python-fu)
Dynamically create new dataframes with pandas
Create basic algorithms with Smart Trade
Change point detection with Kalman filter
Make a filter with a django template
Create API using hug with mod_wsgi
Create an age group with pandas
Create a poisson stepper with numpy.random
Create github pages with lektor Part 1
Create a file uploader with Django
Image processing with Python 100 knock # 10 median filter
Create an application by classifying with Pygame
Create a Python function decorator with Class
Create RESTful APIs with Django Rest Framework
Create wordcloud from your tweet with python3
Build a blockchain with Python ① Create a class
Create an image processing viewer with PySimpleGUI
Create a dummy image with Python + PIL.
Easy filter management with Python's -m option
Create your own DNS server with Twisted
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Quickly create an excel file with Python #python
Create your own Composite Value with SQLAlchemy
Create a GUI app with Python's Tkinter
Create Python + uWSGI + Nginx environment with Docker