Python implements digital filter IIR FIR

Source: Internet
Author: User

import scipy.signal as signalimport numpy as npimport pylab as plimport matplotlib.pyplot as pltimport matplotlib
Set filter parameters, create signals
# Parameters of a certain equalization filterA = NP. Array([1.0, -1.947463016918843,0.9555873701383931]) B = NP. Array([0.9833716591860479, -1.947463016918843,0.9722157109523452])# 44.1kHz, 1-second frequency sweep waveT = NP. Arange(0,0.5,1/44100.0)x= Signal. Chirp(T, f0=Ten, T1 =0.5, f1=1000.0)# directly compute the output of the filter at oncey= Signal. Lfilter(b, A,x) PLT. Plot(x) PLT. Show()
# Divide the input signal into 50 data setsx2 =x. Reshape((-1, -))# The initial state of the filter is 0 and the length is the filter coefficient length-1Z= NP. Zeros(Max (Len (a), Len (b))-1, DTYPE=NP. Float) y2 = []# Save the list of outputsFor TXinchX2:# Filter Each signal and update the status of the filter ZTyZ= Signal. Lfilter(b, A, TX, zi=Z)# Add the output to the output listb y2. Append(Ty)# Convert output y2 to one-dimensional arraysy2 = NP. Array(y2) y2 = y2. Reshape((-1,))# Error between output y and y2Print NP. Sum((y-Y2) * *2)# DrawingPl. Plot(T,y, T, y2) PL. Show()

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Python implements digital filter IIR FIR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.