Use python to implement digital filter (FIR)

Source: Internet
Author: User

Use python to implement digital filter (FIR)

import scipy.signal as signalimport numpy as npimport pylab as plimport matplotlib.pyplot as pltimport matplotlib
Set filter parameters and create Signals
# A = np. array ([1.0,-1.947463016918843, 0.9555873701383931]) B = np. array ([0.9833716591860479,-1.947463016918843, 0.9722157109523452]) #44.1 kHz, 1 second frequency scanning wave t = np. arange (0, 0.5, 1/44100. 0) x = signal. chirp (t, f0 = 10, t1 = 0.5, f1 = 1000.0) # output of the directly one-time computing filter y = signal. lfilter (B, a, x) plt. plot (x) plt. show ()
# Divide the input signal into 50 data sets x2 = x. reshape (-) # The initial state of the filter is 0, and the length is the length of the filter coefficient-1z = np. zeros (max (len (a), len (B)-1, dtype = np. float) y2 = [] # Save the output list for tx in x2: # filter each signal segment and update the filter status z ty, z = signal. lfilter (B, a, tx, zi = z) # Add the output to the output List B y2.append (ty) # convert the output y2 to a one-dimensional array y2 = np. array (y2) y2 = y2.reshape (-1,) # print np. sum (y-y2) ** 2) # plot pl. plot (t, y, t, y2) pl. show ()

 

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.