4Weighting and calibration filter in one
5@author: J.A. de Jong - ASCEE
7from .lasp_common
import FreqWeighting
8from .filter
import SPLFilterDesigner
10from .wrappers
import FilterBank
18 Frequency weighting and calibration FIR filter
26 Initialize the frequency weighting and calibration FIR filters.
29 fw: Frequency weighting to apply
30 nchannels: Number of channels for the input data
31 fs: Sampling frequency [Hz]
32 calfile: Calibration file to load.
42 freq_design = np.linspace(0, 17e3, 3000)
43 freq_design[-1] = fs/2
46 frp_obj = self.
frpObj(freq_design)
53 fir = arbitrary_fir_design(fs, P, freq_design,
56 self.
_firs[:, chan] = fir
58 self.
_fbs.append(FilterBank(fir[:, np.newaxis], 2*P))
64 Filter data using the calibration and frequency weighting filter.
67 data: (Weighted) raw time data that needs to be filtered, should
68 have the same number of columns as the number of channels. First
69 axis is assumed to be the time axis
72 Filtered data for each channel
77 assert data.shape[1] == nchan
78 assert data.shape[0] > 0
81 for chan
in range(nchan):
82 filtered.append(self.
_fbs[chan].
filter_(data[:, [chan]])[:, 0])
83 filtered = np.asarray(filtered).transpose()
84 if filtered.ndim == 1:
85 filtered = filtered[:, np.newaxis]
90 Computes the objective frequency response of the calibration filter
93 if calfile
is not None:
94 cal = np.loadtxt(calfile, skiprows=2)
98 raise ValueError(
'Number of channels in calibration file does'
99 ' not equal to given number of channels')
100 calfac = 10**(-cal/20)
101 filter_calfac = empty((freq_design.shape[0], self.
nchannels))
104 filter_calfac[:, chan] = np.interp(freq_design, freq,
108 filter_calfac = ones((freq_design.shape[0], self.
nchannels,))
114 Computes the objective frequency response of the frequency weighting
118 if fw == FreqWeighting.A:
119 return A(freq_design)
120 elif fw == FreqWeighting.C:
121 return C(freq_design)
122 elif fw == FreqWeighting.Z:
123 return ones(freq_design.shape[0])
125 raise ValueError(
'Invalid fw parameter')
129 Combines the frequency weighting and the calibration filter into
130 one frequency response objective function.
133 frp_objective = self.
frpCalObj(freq_design) * \
135 frp_objective[-1] = 0.
139 def freqResponse(self, chan=0, freq=None):
141 Returns the frequency response of the designed FIR filter
144 freq = np.logspace(1, np.log10(self.
fs/2), 500)
145 return (freq, frp(self.
fs, freq, self.
_firs[chan]),
146 self.
frpObj(freq)[:, chan])
Frequency weighting and calibration FIR filter.
__init__(self, fw=FreqWeighting.default, nchannels=1, fs=48000., calfile=None)
Initialize the frequency weighting and calibration FIR filters.
filter_(self, data)
Filter data using the calibration and frequency weighting filter.
frpWeightingObj(self, freq_design)
Computes the objective frequency response of the frequency weighting filter.
frpCalObj(self, freq_design)
Computes the objective frequency response of the calibration filter.
frpObj(self, freq_design)
Combines the frequency weighting and the calibration filter into one frequency response objective fun...