本文整理汇总了Python中scipy.signal.firwin方法的典型用法代码示例。如果您正苦于以下问题:Python signal.firwin方法的具体用法?Python signal.firwin怎么用?Python signal.firwin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.signal
的用法示例。
在下文中一共展示了signal.firwin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mono_FM
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def mono_FM(x,fs=2.4e6,file_name='test.wav'):
"""
Decimate complex baseband input by 10
Design 1st decimation lowpass filter (f_c = 200 KHz)
"""
b = signal.firwin(64,2*200e3/float(fs))
# Filter and decimate (should be polyphase)
y = signal.lfilter(b,1,x)
z = ss.downsample(y,10)
# Apply complex baseband discriminator
z_bb = discrim(z)
# Design 2nd decimation lowpass filter (fc = 12 KHz)
bb = signal.firwin(64,2*12e3/(float(fs)/10))
# Filter and decimate
zz_bb = signal.lfilter(bb,1,z_bb)
# Decimate by 5
z_out = ss.downsample(zz_bb,5)
# Save to wave file
ss.to_wav(file_name, 48000, z_out/2)
print('Done!')
return z_bb, z_out
示例2: test_vs_lfilter
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def test_vs_lfilter(self):
# Check that up=1.0 gives same answer as lfilter + slicing
random_state = np.random.RandomState(17)
try_types = (int, np.float32, np.complex64, float, complex)
size = 10000
down_factors = [2, 11, 79]
for dtype in try_types:
x = random_state.randn(size).astype(dtype)
if dtype in (np.complex64, np.complex128):
x += 1j * random_state.randn(size)
for down in down_factors:
h = firwin(31, 1. / down, window='hamming')
yl = lfilter(h, 1.0, x)[::down]
y = upfirdn(h, x, up=1, down=down)
assert_allclose(yl, y[:yl.size], atol=1e-7, rtol=1e-7)
示例3: low_cut_filter
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def low_cut_filter(x, fs, cutoff=70):
"""FUNCTION TO APPLY LOW CUT FILTER
Args:
x (ndarray): Waveform sequence
fs (int): Sampling frequency
cutoff (float): Cutoff frequency of low cut filter
Return:
(ndarray): Low cut filtered waveform sequence
"""
nyquist = fs // 2
norm_cutoff = cutoff / nyquist
# low cut filter
fil = firwin(255, norm_cutoff, pass_zero=False)
lcf_x = lfilter(fil, 1, x)
return lcf_x
示例4: __init__
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def __init__(self, fs, parameters):
fs_min = 1000.0
if (fs > fs_min):
dec_factor = parameters['dec_factor']
else:
dec_factor = 1
filter_order = parameters['bp_forder']
f_hp = parameters['bp_low']
f_lp = parameters['bp_high']
f1 = f_hp/(fs/2)
f2 = f_lp/(fs/2)
self.b = firwin(filter_order+1, [f1, f2], pass_zero=False)
self.a = 1
self.dec_factor = dec_factor
示例5: __init__
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def __init__(self, id_mask='F1804', ntaps=4, debug=False):
"""Initialize the WeightSensor.
Parameters
----------
id_mask : str
A template for the first n digits of the device IDs for valid load cells.
ntaps : int
Maximum number of samples to perform filtering over.
debug : bool
If True, have sensor seem to work normally but just return zeros.
"""
self._id_mask = id_mask
self._weight_buffers = []
self._ntaps = ntaps
self._debug = debug
self._filter_coeffs = signal.firwin(ntaps, 0.1)
self._running = False
示例6: design
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def design(self, fs, fc, bandwidth, ripple_db=60.0):
"""
Designs a FIR filter that is a low-pass filter.
fs : sampling frequency (Hz)
fc : cut-off frequency (Hz)
bandwidth : transition bandwidth (Hz)s
"""
# Compute the order and Kaiser parameter for the FIR filter.
N, beta = signal.kaiserord(ripple_db, bandwidth / fs * 2)
# Use firwin with a Kaiser window to create a lowpass FIR filter.
fir = signal.firwin(N, fc / fs * 2, window=('kaiser', beta))
# the filter must be symmetric, in order to be zero-phase
assert np.all(np.abs(fir - fir[::-1]) < 1e-15)
self.fir = fir / np.sum(fir)
self.fs = fs
return self
示例7: low_cut_filter
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def low_cut_filter(x, fs, cutoff=70):
"""Low cut filter
Parameters
---------
x : array, shape(`samples`)
Waveform sequence
fs: array, int
Sampling frequency
cutoff : float, optional
Cutoff frequency of low cut filter
Default set to 70 [Hz]
Returns
---------
lcf_x : array, shape(`samples`)
Low cut filtered waveform sequence
"""
nyquist = fs // 2
norm_cutoff = cutoff / nyquist
# low cut filter
fil = firwin(255, norm_cutoff, pass_zero=False)
lcf_x = lfilter(fil, 1, x)
return lcf_x
示例8: _high_frequency_completion
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def _high_frequency_completion(self, x, transformed):
"""
Please see Sect. 3.2 and 3.3 in the following paper to know why we complete the
unvoiced synthesized voice of the original voice into high frequency range
of F0 transformed voice.
- K. Kobayashi et al., "F0 transformation techniques for statistical voice
conversion with direct waveform modification with spectral differential,"
Proc. IEEE SLT 2016, pp. 693-700. 2016.
"""
# construct feature extractor and synthesis
feat = FeatureExtractor(fs=self.fs)
f0, spc, ap = feat.analyze(x)
uf0 = np.zeros(len(f0))
# synthesis
synth = Synthesizer(fs=self.fs)
unvoice_anasyn = synth.synthesis_spc(uf0, spc, ap)
# HPF for synthesized speech
fil = firwin(255, self.f0rate, pass_zero=False)
HPFed_unvoice_anasyn = filtfilt(fil, 1, unvoice_anasyn)
if len(HPFed_unvoice_anasyn) > len(transformed):
return transformed + HPFed_unvoice_anasyn[:len(transformed)]
else:
transformed[:len(HPFed_unvoice_anasyn)] += HPFed_unvoice_anasyn
return transformed
示例9: low_pass_filter
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def low_pass_filter(data, cutoff, fs, n_taps=255):
"""Apply low-pass filter
Parameters
----------
data : array, shape (`T`, `dim`)
Array of sequence.
cutoff : int,
Cutoff frequency
fs : int,
Sampling frequency
n_taps : int, optional
Tap number
Returns
-------
modified data: array, shape (`T`, `dim`)
Array of modified sequence.
"""
if data.shape[0] < n_taps * 3:
raise ValueError(
'Length of data should be three times longer than n_taps.')
fil = firwin(n_taps, cutoff, pass_zero=True, nyq=fs//2)
modified_data = filtfilt(fil, 1, data, axis=0)
return modified_data
示例10: high_pass_filter
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def high_pass_filter(data, cutoff, fs, n_taps=255):
"""Apply high-pass filter
Parameters
----------
data : array, shape (`T`, `dim`)
Array of sequence.
cutoff : int,
Cutoff frequency
fs : int,
Sampling frequency
n_taps : int, optional
Tap number
Returns
-------
modified data: array, shape (`T`, `dim`)
Array of modified sequence.
"""
if data.shape[0] < n_taps * 3:
raise ValueError(
'Length of data should be three times longer than n_taps.')
fil = firwin(n_taps, cutoff, pass_zero=False, nyq=fs//2)
modified_data = filtfilt(fil, 1, data, axis=0)
return modified_data
示例11: polyphase_lowpass
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def polyphase_lowpass(arr, downsample=2, n_taps=50, filter_pad=1.1):
filt = firwin(downsample * n_taps, 1 / (downsample * filter_pad))
filtered = polyphase_single_filter(arr, downsample, filt)
return filtered
示例12: test_poly_vs_filtfilt
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def test_poly_vs_filtfilt(self):
# Check that up=1.0 gives same answer as filtfilt + slicing
random_state = np.random.RandomState(17)
try_types = (int, np.float32, np.complex64, float, complex)
size = 10000
down_factors = [2, 11, 79]
for dtype in try_types:
x = random_state.randn(size).astype(dtype)
if dtype in (np.complex64, np.complex128):
x += 1j * random_state.randn(size)
# resample_poly assumes zeros outside of signl, whereas filtfilt
# can only constant-pad. Make them equivalent:
x[0] = 0
x[-1] = 0
for down in down_factors:
h = signal.firwin(31, 1. / down, window='hamming')
yf = filtfilt(h, 1.0, x, padtype='constant')[::down]
# Need to pass convolved version of filter to resample_poly,
# since filtfilt does forward and backward, but resample_poly
# only goes forward
hc = convolve(h, h[::-1])
y = signal.resample_poly(x, 1, down, window=hc)
assert_allclose(yf, y, atol=1e-7, rtol=1e-7)
示例13: pb2bb
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def pb2bb(x, fs, fc, fd=None, flen=127, cutoff=None, axis=-1):
"""Convert passband signal to baseband.
The baseband conversion uses a low-pass filter after downconversion, with a
default cutoff frequency of `0.6*fd`, if `fd` is specified, or `1.1*fc` if `fd`
is not specified. Alternatively, the user may specify the cutoff frequency
explicitly.
For communication applications, one may wish to use :func:`arlpy.comms.downconvert` instead,
as that function supports matched filtering with a pulse shape rather than a generic
low-pass filter.
The convention used in that exp(2j*pi*fc*t) is a positive frequency carrier.
:param x: passband signal
:param fs: sampling rate of passband signal in Hz
:param fc: carrier frequency in passband in Hz
:param fd: sampling rate of baseband signal in Hz (``None`` => same as `fs`)
:param flen: number of taps in the low-pass FIR filter
:param cutoff: cutoff frequency in Hz (``None`` means auto-select)
:param axis: axis of the signal, if multiple signals specified
:returns: complex baseband signal, sampled at `fd`
"""
if cutoff is None:
cutoff = 0.6*fd if fd is not None else 1.1*_np.abs(fc)
osc = _np.sqrt(2)*_np.exp(-2j*_np.pi*fc*time(x.shape[axis],fs))
y = x * _utils.broadcastable_to(osc, x.shape, axis)
hb = _sig.firwin(flen, cutoff=cutoff, nyq=fs/2.0)
y = _sig.filtfilt(hb, 1, y, axis=axis)
if fd is not None and fd != fs:
y = _sig.resample_poly(y, 2*fd, fs, axis=axis)
y = _np.apply_along_axis(lambda a: a[::2], axis, y)
return y
示例14: save_wav
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def save_wav(wav, path, hparams):
wav = wav / np.abs(wav).max() * 0.999
f1 = 0.5 * 32767 / max(0.01, np.max(np.abs(wav)))
f2 = np.sign(wav) * np.power(np.abs(wav), 0.95)
wav = f1 * f2
wav = signal.convolve(wav, signal.firwin(hparams.num_freq, [hparams.fmin, hparams.fmax], pass_zero=False, fs=hparams.sample_rate))
#proposed by @dsmiller
wavfile.write(path, hparams.sample_rate, wav.astype(np.int16))
示例15: firwin_lpf
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import firwin [as 别名]
def firwin_lpf(N_taps, fc, fs = 1.0):
"""
Design a windowed FIR lowpass filter in terms of passband
critical frequencies f1 < f2 in Hz relative to sampling rate
fs in Hz. The number of taps must be provided.
Mark Wickert October 2016
"""
return signal.firwin(N_taps,2*fc/fs)