#!/usr/bin/env python # coding: utf-8 # ## Experiment 4a - Filters - Blackman Harris filter # Refs [1] https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.signal.freqz.html # BlackmanHarris filter is an averaging filter, mainly used to remove the additive gaussian noise. This is how it looks like in time domain # In[1]: import os, sys nb_dir = os.path.split(os.getcwd())[0] if nb_dir not in sys.path: sys.path.append(nb_dir) get_ipython().run_line_magic('matplotlib', 'inline') get_ipython().run_line_magic('load_ext', 'autoreload') get_ipython().run_line_magic('autoreload', '2') # In[9]: from directdemod import filters import matplotlib.pyplot as plt import numpy as np from scipy import signal # In[8]: bh = filters.blackmanHarris(151) plt.plot(bh.getB) # Let us observe in frequency domain [1]. Assuming we have a sampling rate of 2MHz # In[32]: bh = filters.blackmanHarris(101) plt.plot(bh.getB) w, h = signal.freqz(bh.getB) Fs = 2048000 w *= Fs/(2*np.pi) plt.clf() fig = plt.figure() plt.title('Digital filter frequency response') ax1 = fig.add_subplot(111) plt.plot(w, 20 * np.log10(abs(h)), 'b') plt.ylabel('Amplitude [dB]', color='b') plt.xlabel('Frequency [Hz]') ax2 = ax1.twinx() angles = np.unwrap(np.angle(h)) plt.plot(w, angles, 'g') plt.ylabel('Angle (radians)', color='g') plt.grid() plt.axis('tight') plt.show() hDB = 20 * np.log10(abs(h)) print("3dB point:", w[hDB < (hDB[0]-3)][0], "Hz") # ### Observations and Conclusions # # This filter is a low pass filter. Another advantage of using the filter is the 34bB boost it gives to the lower frequencies. This filter will be mainly used to reduce gaussian noise in raw IQ data.