[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] notch filter
From: |
Chuck Swiger |
Subject: |
Re: [Discuss-gnuradio] notch filter |
Date: |
Mon, 18 Oct 2004 21:45:57 -0400 |
Here's the final working notch filter script -
notch.py
----------------------------------------------------------
#!/usr/bin/env python
#
# Copyright 2004 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
import sys
from gnuradio import gr
from gnuradio import audio
def build_graph (freq):
sampling_freq = 48000
fg = gr.flow_graph ()
# notch filter frequency = ( 1 / ( delays * unit_delay ) ) / 2
# where unit_delay = 20.8333 uSec for 48000 sampling rate
nd = (int) ( .5 + ( 1 / ( 2 * freq * 20.8333e-6 ) ) )
print "Exact notch freq = ",( 1 / ( nd * 20.8333e-6 * 2 ) )
taps = [1]
for i in range(1,nd):
taps = taps + [0]
taps = taps + [1]
src0 = audio.source (sampling_freq)
notch = gr.fir_filter_fff (1, taps)
scale = gr.multiply_const_ff (.5)
dst = audio.sink (sampling_freq)
fg.connect (src0, notch)
fg.connect (notch, scale)
fg.connect (scale, dst)
return fg
def main (args):
nargs = len (args)
if nargs == 1:
freq = float (args[0])
else:
sys.stderr.write ('usage: notch.py freq\n')
sys.exit (1)
fg = build_graph (freq)
fg.start ()
raw_input ('Press Enter to quit: ')
fg.stop ()
if __name__ == '__main__':
main (sys.argv[1:])