FIR filter Python code | FIR python script
This FIR filter python code script covers simulation of FIR filter of Low pass type. The output plots of this FIR python script are also mentioned.
Introduction : FIR filter uses only current and past input digital samples to obtain a current output sample value. It does not utilize past output samples.
Simple FIR equation is mention below.
y(n)= h(0)x(n) + h(1)x(n-1) + h(2)x(n-2) + h(3)x(n-3) + h(4)x(n-4)
Refer FIR vs IIR filter for more information.
FIR filter python code
import matplotlib.pyplot as plt
import scipy.signal as sig
import numpy as np
from math import pi
plt.close('all')
N = 20
fc = 100
Fs = 1000
w_c = 2 *fc/Fs
t = sig.firwin(N, w_c)
[w, h] = sig.freqz(t, worN = 2000)
w = Fs*w/(2*pi)
h_db = 20 * np.log10(abs(h))
plt.figure()
plt.plot(w, h_db)
plt.title('FIR filter response')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Magnitude (dB)')
plt.show()
import scipy.signal as sig
import numpy as np
from math import pi
plt.close('all')
N = 20
fc = 100
Fs = 1000
w_c = 2 *fc/Fs
t = sig.firwin(N, w_c)
[w, h] = sig.freqz(t, worN = 2000)
w = Fs*w/(2*pi)
h_db = 20 * np.log10(abs(h))
plt.figure()
plt.plot(w, h_db)
plt.title('FIR filter response')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Magnitude (dB)')
plt.show()
FIR python Output plots
Following are the plots of above FIR python code.
Other useful DSP codes in Python
Correlation python script
Python programming tutorial
Convolution python script
BPSK QPSK 16QAM 64QAM modulation
16-Point FFT code
OFDM transmitter simulation code
Rayleigh Fading Channel
Rician Fading Channel
ASK modulation python code
FSK modulation python code
PSK modulation python code
IIR filter python code
Useful Links to MATLAB codes
OFDM Preamble generation
Time off estimation corr
Freq off estimation corr
channel estimation
11a WLAN channel
PN sequence generation
OFDMA Tx Rx
AES DES
carrier aggregation
CCDF
FIR Filter
IIR Filter
Low Pass FIR
Viterbi decoder
CRC8 CRC32