discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] Filter delays and direction of time.


From: Achilleas Anastasopoulos
Subject: [Discuss-gnuradio] Filter delays and direction of time.
Date: Thu, 20 Jan 2005 18:54:38 -0500
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)

Dear all,

I was wondering what is the direction of time in the input/output
streams used in gnuradio.

In the C files (eg, gr_fir_fff_generic.cc) the output
of a filter is evaluated as

y[k]= sum_i=0 to N    h[i] x[k+i]

If the stream indexing coincides with actual time
(ie, higher index means later sample), then
it seems that the filter coeficients have to be
fliped around 0 (non-causal filter).

The reason I am asking is that I cannot explain
the findings of the simple experiment
(see attached code) where
a sinusoid is passed through a filter.
The evaluated and measured delays are exactly the negative
of each other....


Thanks for the help,
Achilleas



========================
#!/usr/bin/env python

from gnuradio import gr
import sys
import math
from gnuradio.wxgui import stdgui, fftsink, scopesink
import wx

class wfm_rx_graph (stdgui.gui_flow_graph):
    def __init__(self,frame,panel,vbox,argv):
        stdgui.gui_flow_graph.__init__ (self,frame,panel,vbox,argv)

        rate = 256e3

        #find_arg((0,0,1),1,0.1) test if find_arg() works OK

        f0 = 42e3;
        src = gr.sig_source_f (rate, gr.GR_SIN_WAVE, f0, 1.0)

        # compute FIR filter taps for bandpass filter
band_coefs = gr.firdes.band_pass (0.8,rate, 23e3, 53e3, 1e3, gr.firdes.WIN_HAMMING)
        print "Delay of BPF"
        phi = find_arg(band_coefs,rate,f0)
        band_filter = gr.fir_filter_fff (1, band_coefs)

        self.connect (src,band_filter)

scope, win5 = scopesink.make_scope_sink_f (self, panel, "In and Out", rate)
        self.connect (src,(scope,0))           # green
        self.connect (band_filter,(scope,1))   # red
        vbox.Add (win5, 1, wx.EXPAND)


def find_arg(coefs,rate,f0):
    l = len(coefs)
    ii = range(l)
    s=0
    for i in ii:
        p = -2*math.pi*ii[i]*f0/rate
        s = s + coefs[ii[i]] * (math.cos(p) + math.sin(p) * (0+1j))
    if s.real > 0:
        phi = math.atan(s.imag/s.real)
    elif s.imag > 0:
        phi = math.atan(s.imag/s.real) + math.pi
    else:
        phi = math.atan(s.imag/s.real) - math.pi

    print "argument = " , phi * 180 / math.pi
    print "norm delay = ", - phi / 2 / math.pi / (f0/rate)
    print "abs delay =", - phi / 2 / math.pi / f0
    return phi


if __name__ == '__main__':
    app = stdgui.stdapp (wfm_rx_graph, "Test Filter Delays")
    app.MainLoop ()
========================================






reply via email to

[Prev in Thread] Current Thread [Next in Thread]