Пример #1
0
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)
    desired_freqs = [freq_sb1, freq_pb1, freq_pb2, freq_sb2]
    desired_ripple = [stopband_dev, passband_dev, stopband_dev]
    (n, fo, ao, w) = remezord (desired_freqs, desired_ampls,
                               desired_ripple, Fs)
    # The remezord typically under-estimates the filter order, so add 2 taps by default
    taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass")
    return taps
Пример #2
0
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)
    (n, fo, ao, w) = remezord ([freq1, freq2], desired_ampls,
                               [stopband_dev, passband_dev], Fs)
    # For a HPF, we need to use an odd number of taps
    # In gr.remez, ntaps = n+1, so n must be even
    if((n+nextra_taps)%2 == 1):
        n += 1

    # The remezord typically under-estimates the filter order, so add 2 taps by default
    taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass")
    return taps
Пример #3
0
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)
    desired_freqs = [freq_pb1, freq_sb1, freq_sb2, freq_pb2]
    desired_ripple = [passband_dev, stopband_dev, passband_dev]
    (n, fo, ao, w) = remezord (desired_freqs, desired_ampls,
                               desired_ripple, Fs)
    # Make sure we use an odd number of taps
    if((n+nextra_taps)%2 == 1):
        n += 1
    # The remezord typically under-estimates the filter order, so add 2 taps by default
    taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass")
    return taps
Пример #4
0
def low_pass (gain, Fs, freq1, freq2, passband_ripple_db, stopband_atten_db,
              nextra_taps=0):
    passband_dev = passband_ripple_to_dev (passband_ripple_db)
    stopband_dev = stopband_atten_to_dev (stopband_atten_db)
    desired_ampls = (gain, 0)
    (n, fo, ao, w) = remezord ([freq1, freq2], desired_ampls,
                               [passband_dev, stopband_dev], Fs)
    taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass")
    return taps
Пример #5
0
def low_pass (gain, Fs, freq1, freq2, passband_ripple_db, stopband_atten_db,
              nextra_taps=2):
    passband_dev = passband_ripple_to_dev (passband_ripple_db)
    stopband_dev = stopband_atten_to_dev (stopband_atten_db)
    desired_ampls = (gain, 0)
    (n, fo, ao, w) = remezord ([freq1, freq2], desired_ampls,
                               [passband_dev, stopband_dev], Fs)
    # The remezord typically under-estimates the filter order, so add 2 taps by default
    taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass")
    return taps
Пример #6
0
def high_pass (Fs, freq1, freq2, stopband_atten_db, passband_ripple_db, 
               nextra_taps=0):
    """FIXME: broken"""
    passband_dev = passband_ripple_to_dev (passband_ripple_db)
    stopband_dev = stopband_atten_to_dev (stopband_atten_db)
    desired_ampls = (0, 1)
    (n, fo, ao, w) = remezord ([freq1, freq2], desired_ampls,
                               [stopband_dev, passband_dev], Fs)
    taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass")
    return taps
Пример #7
0
def band_pass (gain, Fs, freq_sb1, freq_pb1, freq_pb2, freq_sb2,
               passband_ripple_db, stopband_atten_db,
               nextra_taps=2):
    passband_dev = passband_ripple_to_dev (passband_ripple_db)
    stopband_dev = stopband_atten_to_dev (stopband_atten_db)
    desired_ampls = (0, gain, 0)
    desired_freqs = [freq_sb1, freq_pb1, freq_pb2, freq_sb2]
    desired_ripple = [stopband_dev, passband_dev, stopband_dev]
    (n, fo, ao, w) = remezord (desired_freqs, desired_ampls,
                               desired_ripple, Fs)
    # The remezord typically under-estimates the filter order, so add 2 taps by default
    taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass")
    return taps
Пример #8
0
def high_pass (gain, Fs, freq1, freq2, passband_ripple_db, stopband_atten_db,
               nextra_taps=2):
    passband_dev = passband_ripple_to_dev (passband_ripple_db)
    stopband_dev = stopband_atten_to_dev (stopband_atten_db)
    desired_ampls = (0, 1)
    (n, fo, ao, w) = remezord ([freq1, freq2], desired_ampls,
                               [stopband_dev, passband_dev], Fs)
    # For a HPF, we need to use an odd number of taps
    # In gr.remez, ntaps = n+1, so n must be even
    if((n+nextra_taps)%2 == 1):
        n += 1

    # The remezord typically under-estimates the filter order, so add 2 taps by default
    taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass")
    return taps
Пример #9
0
def band_reject (gain, Fs, freq_pb1, freq_sb1, freq_sb2, freq_pb2,
                 passband_ripple_db, stopband_atten_db,
                 nextra_taps=2):
    passband_dev = passband_ripple_to_dev (passband_ripple_db)
    stopband_dev = stopband_atten_to_dev (stopband_atten_db)
    desired_ampls = (gain, 0, gain)
    desired_freqs = [freq_pb1, freq_sb1, freq_sb2, freq_pb2]
    desired_ripple = [passband_dev, stopband_dev, passband_dev]
    (n, fo, ao, w) = remezord (desired_freqs, desired_ampls,
                               desired_ripple, Fs)
    # Make sure we use an odd number of taps
    if((n+nextra_taps)%2 == 1):
        n += 1
    # The remezord typically under-estimates the filter order, so add 2 taps by default
    taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass")
    return taps