diff options
Diffstat (limited to 'gr-filter/python')
-rw-r--r-- | gr-filter/python/optfir.py | 117 | ||||
-rw-r--r-- | gr-filter/python/rational_resampler.py | 26 |
2 files changed, 79 insertions, 64 deletions
diff --git a/gr-filter/python/optfir.py b/gr-filter/python/optfir.py index bccb8c68d0..47b0ac4e8d 100644 --- a/gr-filter/python/optfir.py +++ b/gr-filter/python/optfir.py @@ -32,16 +32,20 @@ import filter_swig as filter # ---------------------------------------------------------------- -## Builds a low pass filter. -# @param gain Filter gain in the passband (linear) -# @param Fs Sampling rate (sps) -# @param freq1 End of pass band (in Hz) -# @param freq2 Start of stop band (in Hz) -# @param passband_ripple_db Pass band ripple in dB (should be small, < 1) -# @param stopband_atten_db Stop band attenuation in dB (should be large, >= 60) -# @param nextra_taps Extra taps to use in the filter (default=2) def low_pass (gain, Fs, freq1, freq2, passband_ripple_db, stopband_atten_db, nextra_taps=2): + """ + Builds a low pass filter. + + Args: + gain: Filter gain in the passband (linear) + Fs: Sampling rate (sps) + freq1: End of pass band (in Hz) + freq2: Start of stop band (in Hz) + passband_ripple_db: Pass band ripple in dB (should be small, < 1) + stopband_atten_db: Stop band attenuation in dB (should be large, >= 60) + nextra_taps: Extra taps to use in the filter (default=2) + """ passband_dev = passband_ripple_to_dev (passband_ripple_db) stopband_dev = stopband_atten_to_dev (stopband_atten_db) desired_ampls = (gain, 0) @@ -51,19 +55,23 @@ def low_pass (gain, Fs, freq1, freq2, passband_ripple_db, stopband_atten_db, taps = filter.pm_remez (n + nextra_taps, fo, ao, w, "bandpass") return taps -## Builds a band pass filter. -# @param gain Filter gain in the passband (linear) -# @param Fs Sampling rate (sps) -# @param freq_sb1 End of stop band (in Hz) -# @param freq_pb1 Start of pass band (in Hz) -# @param freq_pb2 End of pass band (in Hz) -# @param freq_sb2 Start of stop band (in Hz) -# @param passband_ripple_db Pass band ripple in dB (should be small, < 1) -# @param stopband_atten_db Stop band attenuation in dB (should be large, >= 60) -# @param nextra_taps Extra taps to use in the filter (default=2) def band_pass (gain, Fs, freq_sb1, freq_pb1, freq_pb2, freq_sb2, passband_ripple_db, stopband_atten_db, nextra_taps=2): + """ + Builds a band pass filter. + + Args: + gain: Filter gain in the passband (linear) + Fs: Sampling rate (sps) + freq_sb1: End of stop band (in Hz) + freq_pb1: Start of pass band (in Hz) + freq_pb2: End of pass band (in Hz) + freq_sb2: Start of stop band (in Hz) + passband_ripple_db: Pass band ripple in dB (should be small, < 1) + stopband_atten_db: Stop band attenuation in dB (should be large, >= 60) + nextra_taps: Extra taps to use in the filter (default=2) + """ passband_dev = passband_ripple_to_dev (passband_ripple_db) stopband_dev = stopband_atten_to_dev (stopband_atten_db) desired_ampls = (0, gain, 0) @@ -75,21 +83,24 @@ def band_pass (gain, Fs, freq_sb1, freq_pb1, freq_pb2, freq_sb2, taps = filter.pm_remez (n + nextra_taps, fo, ao, w, "bandpass") return taps - -## Builds a band pass filter with complex taps by making an LPF and -# spinning it up to the right center frequency -# @param gain Filter gain in the passband (linear) -# @param Fs Sampling rate (sps) -# @param freq_sb1 End of stop band (in Hz) -# @param freq_pb1 Start of pass band (in Hz) -# @param freq_pb2 End of pass band (in Hz) -# @param freq_sb2 Start of stop band (in Hz) -# @param passband_ripple_db Pass band ripple in dB (should be small, < 1) -# @param stopband_atten_db Stop band attenuation in dB (should be large, >= 60) -# @param nextra_taps Extra taps to use in the filter (default=2) def complex_band_pass (gain, Fs, freq_sb1, freq_pb1, freq_pb2, freq_sb2, passband_ripple_db, stopband_atten_db, nextra_taps=2): + """ + Builds a band pass filter with complex taps by making an LPF and + spinning it up to the right center frequency + + Args: + gain: Filter gain in the passband (linear) + Fs: Sampling rate (sps) + freq_sb1: End of stop band (in Hz) + freq_pb1: Start of pass band (in Hz) + freq_pb2: End of pass band (in Hz) + freq_sb2: Start of stop band (in Hz) + passband_ripple_db: Pass band ripple in dB (should be small, < 1) + stopband_atten_db: Stop band attenuation in dB (should be large, >= 60) + nextra_taps: Extra taps to use in the filter (default=2) + """ center_freq = (freq_pb2 + freq_pb1) / 2.0 lp_pb = (freq_pb2 - center_freq)/1.0 lp_sb = freq_sb2 - center_freq @@ -100,20 +111,24 @@ def complex_band_pass (gain, Fs, freq_sb1, freq_pb1, freq_pb2, freq_sb2, return taps -## Builds a band reject filter -# spinning it up to the right center frequency -# @param gain Filter gain in the passband (linear) -# @param Fs Sampling rate (sps) -# @param freq_pb1 End of pass band (in Hz) -# @param freq_sb1 Start of stop band (in Hz) -# @param freq_sb2 End of stop band (in Hz) -# @param freq_pb2 Start of pass band (in Hz) -# @param passband_ripple_db Pass band ripple in dB (should be small, < 1) -# @param stopband_atten_db Stop band attenuation in dB (should be large, >= 60) -# @param nextra_taps Extra taps to use in the filter (default=2) def band_reject (gain, Fs, freq_pb1, freq_sb1, freq_sb2, freq_pb2, passband_ripple_db, stopband_atten_db, nextra_taps=2): + """ + Builds a band reject filter + spinning it up to the right center frequency + + Args: + gain: Filter gain in the passband (linear) + Fs: Sampling rate (sps) + freq_pb1: End of pass band (in Hz) + freq_sb1: Start of stop band (in Hz) + freq_sb2: End of stop band (in Hz) + freq_pb2: Start of pass band (in Hz) + passband_ripple_db: Pass band ripple in dB (should be small, < 1) + stopband_atten_db: Stop band attenuation in dB (should be large, >= 60) + nextra_taps: Extra taps to use in the filter (default=2) + """ passband_dev = passband_ripple_to_dev (passband_ripple_db) stopband_dev = stopband_atten_to_dev (stopband_atten_db) desired_ampls = (gain, 0, gain) @@ -129,16 +144,20 @@ def band_reject (gain, Fs, freq_pb1, freq_sb1, freq_sb2, freq_pb2, return taps -## Builds a high pass filter. -# @param gain Filter gain in the passband (linear) -# @param Fs Sampling rate (sps) -# @param freq1 End of stop band (in Hz) -# @param freq2 Start of pass band (in Hz) -# @param passband_ripple_db Pass band ripple in dB (should be small, < 1) -# @param stopband_atten_db Stop band attenuation in dB (should be large, >= 60) -# @param nextra_taps Extra taps to use in the filter (default=2) def high_pass (gain, Fs, freq1, freq2, passband_ripple_db, stopband_atten_db, nextra_taps=2): + """ + Builds a high pass filter. + + Args: + gain: Filter gain in the passband (linear) + Fs: Sampling rate (sps) + freq1: End of stop band (in Hz) + freq2: Start of pass band (in Hz) + passband_ripple_db: Pass band ripple in dB (should be small, < 1) + stopband_atten_db: Stop band attenuation in dB (should be large, >= 60) + nextra_taps: Extra taps to use in the filter (default=2) + """ passband_dev = passband_ripple_to_dev (passband_ripple_db) stopband_dev = stopband_atten_to_dev (stopband_atten_db) desired_ampls = (0, 1) diff --git a/gr-filter/python/rational_resampler.py b/gr-filter/python/rational_resampler.py index 312b011d32..97df283e67 100644 --- a/gr-filter/python/rational_resampler.py +++ b/gr-filter/python/rational_resampler.py @@ -28,13 +28,12 @@ def design_filter(interpolation, decimation, fractional_bw): Given the interpolation rate, decimation rate and a fractional bandwidth, design a set of taps. - @param interpolation: interpolation factor - @type interpolation: integer > 0 - @param decimation: decimation factor - @type decimation: integer > 0 - @param fractional_bw: fractional bandwidth in (0, 0.5) 0.4 works well. - @type fractional_bw: float - @returns: sequence of numbers + Args: + interpolation: interpolation factor (integer > 0) + decimation: decimation factor (integer > 0) + fractional_bw: fractional bandwidth in (0, 0.5) 0.4 works well. (float) + Returns: + : sequence of numbers """ if fractional_bw >= 0.5 or fractional_bw <= 0: @@ -67,14 +66,11 @@ class _rational_resampler_base(gr.hier_block2): If neither is specified, a reasonable default, 0.4, is used as the fractional_bw. - @param interpolation: interpolation factor - @type interpolation: integer > 0 - @param decimation: decimation factor - @type decimation: integer > 0 - @param taps: optional filter coefficients - @type taps: sequence - @param fractional_bw: fractional bandwidth in (0, 0.5), measured at final freq (use 0.4) - @type fractional_bw: float + Args: + interpolation: interpolation factor (integer > 0) + decimation: decimation factor (integer > 0) + taps: optional filter coefficients (sequence) + fractional_bw: fractional bandwidth in (0, 0.5), measured at final freq (use 0.4) (float) """ if not isinstance(interpolation, int) or interpolation < 1: |