LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
decimation_fir.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""!
4Author: J.A. de Jong - ASCEE
5
6Description: Decimation filter design.
7"""
8import numpy as np
9import matplotlib.pyplot as plt
10from fir_design import freqResponse, lowpass_fir_design
11
12L = 128 # Filter order
13fs = 48000. # Sampling frequency
14
15d = 4 # Decimation factor
16
17fd = fs/d # Decimated sampling frequency
18fc = fd/2/1.5 # Filter cut-off frequency
19
20fir = lowpass_fir_design(L, fs, fc)
21
22fig = plt.figure()
23ax = fig.add_subplot(111)
24
25freq = np.logspace(1, np.log10(fs/2), 1000)
26
27H = freqResponse(fs, freq, fir)
28dBH = 20*np.log10(np.abs(H))
29ax.plot(freq, dBH)
30ax.axvline(fs/2, color='green')
31ax.axvline(fd/2, color='red')
32
33# Index of Nyquist freq
34fn_index = np.where(freq <= fd/2)[0][-1]
35
36dBHmax_above_Nyq = np.max(dBH[fn_index:])
37
38print(f"Reduction above Nyquist: {dBHmax_above_Nyq} dB")
39plt.show()