Averaged power spectrum calculation

Hi,

I am attempting to calculate a simple averaged power spectrum and save
it to a file, but for some reason the averaging part does not work
(averaging uses single_pole_iir_filter, which is copied from some
example). I’m sure that my code has some simple bug. Here is the code:

def boxcar(wsize):
window = [1.0 for i in range(wsize)]
return window

fft_size = 2048
sample_rate = 2e6
fft_rate = 1.0

fg = gr.flow_graph()
src = gr.noise_source_c(gr.GR_UNIFORM,5000.0)
N = int(math.floor(sample_rate/fft_size/fft_rate))
head = gr.head(gr.sizeof_gr_complex, int(Nfft_size))
s2p = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
fft = gr.fft_vcc(fft_size, True, boxcar(fft_size))
c2mag = gr.complex_to_mag(fft_size)
avg = gr.single_pole_iir_filter_ff(1.0, fft_size)
tail = gr.skiphead(gr.sizeof_float
fft_size, N-1)
sink = gr.file_sink (fft_size*gr.sizeof_float, “test.dat”)
fg.connect(src, head, s2p, fft, c2mag, avg, tail, sink)
fg.run()

The avg block should simply sum up all the vectors that come out of
Mod(fft(signal)), but this doesn’t seem to happen. It almost seems as
if nothing is done in the avg block. What am I doing wrong?

juha

Juha V. wrote:

avg = gr.single_pole_iir_filter_ff(1.0, fft_size)

The avg block should simply sum up all the vectors that come out of
Mod(fft(signal)), but this doesn’t seem to happen. It almost seems as
if nothing is done in the avg block. What am I doing wrong?

The single pole IIR is an exponential averaging filter. The “alpha”
parameter becomes the feed-forward tap, and 1.0-alpha becomes the
feedback tap. So in your case, you’ve set it such that there is no
averaging done.

Try some value like 0.001. You’ll need to experiment to get the amount
of smoothing that you want.

You can also look in fftsink2.py in gr-wxgui to see how this same
technique is used to “average” the FFT display in usrp_fft.py. When it
is turned off, alpha is set to 1.0, when it is turned on, alpha is set
to a value dependent on the FFT frame rate.


Johnathan C.
Corgan Enterprises LLC
http://corganenterprises.com