简体   繁体   中英

How can I design a Butterworth filter with python specifying that my cutoff frequency is 0.1 Hz?

Here I am trying to create a highpass butterworth digital filter with a cutoff frequency at 0.1 Hz. I had implemented the following code and I am not sure if it is true

#%% creating the filter 
# filter parameters 
order=6
btype='highpass'
cutoff_frequency=0.1*2*np.pi
analog=False

b, a= signal.butter(order,cutoff_frequency,btype, analog)
w, h = signal.freqs(b, a)

plt.figure() 
plt.plot(w, 20 * np.log10(abs(h)))
plt.xscale('log')
plt.title('Butterworth filter frequency response')
plt.xlabel('Frequency [radians / second]')
plt.ylabel('Amplitude [dB]')
plt.margins(0, 0.1)
plt.grid(which='both', axis='both')
plt.axvline(0.1*2*np.pi, color='green') # cutoff frequency
plt.show()

My confusion is about the cutoff frequency here I multiplied it by 2*pi because as I understood the cutoff_frequency of scipy.signal.butter corresponds to an angular frequency in rad/s.

Knowing that my sampling frequency is 1Hz I have performed the following steps to design the highpass 6th order Butterworth digital filter with a cutoff frequency at 0.1 Hz:

order=6 # order of the filter
btype='highpass' # type
F_sampling=1.0   # my sampling freq
Nyqvist_freq=F_sampling/2 # Nyqvist frequency in function of my sampling frequency
cut_off_Hz=0.1 # my cutoff frequency in Hz
cutoff_frequency=cut_off_Hz/Nyqvist_freq    # normalized cut_off frequency
analog=False #digital filter
b, a= signal.butter(order,cutoff_frequency,btype, analog)
w, h = signal.freqs(b, a)
Detrend_carrierPhase=signal.filtfilt(b, a, Carrier_phase) # filtering my high rate carrier phase

I am using the scipy library where the cut_off frequency is a fraction of the Nyqvist frequency and it is a non-dimensional value that's why I need to transform my sampling frequency expressed in Hz to the Nyqvist freq through dividing it by 2, so it is equal to 1Hz/2 =0.5 Hz it is the Nyqvist frequency of my system. The normalized Nyqvist cut_off freq given to the butter filter is 0.1 (Cut_off frequency in Hz) divided by 0.5 (Nyqvist frequency of my system).

I used the signal.filtfilt to filter my carrier phase (signal)

Hope this will be helpful!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM