##################################################
# Gnuradio Python Flow Graph
# Title: Top Block
# Generated: Tue Jul 29 15:40:54 2014
##################################################
#import the overall GUI module
from gnuradio.wxgui import stdgui2
#import fft module for spectrum analyzers etc.
from gnuradio.wxgui import fftsink2
#import wx module
import wx
#import the common gnuradio modules
from gnuradio import gr, eng_notation, blks2, window
from gnuradio import audio
from gnuradio.eng_option import eng_option
import sys
import math
class average_energy_flow_graph (stdgui2.std_top_block):
def __init__(self, frame, panel, vbox, argv):
stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv)
# remainder of the script goes here
ampl = .5
seed1=0
NFFT=1024
samp_rate = int(48000)
self.frame = frame
self.panel = panel
self.samp_rate=samp_rate
#define noise source
self.src1 = gr.noise_source_f (gr.GR_GAUSSIAN, ampl, seed1)
mywindow = window.blackmanharris(NFFT)
self.fft = gr.fft_vcc(NFFT, True, mywindow)
self.c2ms = gr.complex_to_mag_squared(NFFT)
#self.connect (self.src1, self.fft, self.c2ms)
self._set_status_msg(str(self.samp_rate), 0)
self._set_status_msg("Put average here!!!", 1)
self.spectrum_display = fftsink2.fft_sink_f (panel, title="Noise pectrum", ref_level= 30, fft_size=NFFT, sample_rate=samp_rate)
# connect the noise source to fft display
self.connect (self.src1, self.spectrum_display)
vbox.Add (self.spectrum_display.win, 1, wx.EXPAND)
def _set_status_msg(self, msg, which=0):
self.frame.GetStatusBar().SetStatusText(msg, which)
#this runs everything
if __name__ == '__main__':
app = stdgui2.stdapp (average_energy_flow_graph, "Tone Generator")
app.MainLoop()
Hello all
I am new to GNUradio software. I would like to compute the average energy and display it in the status message in real time.
To achieve this I tried to write a simple Python code attached (Simple2.pyw). However, I am not able to retrieve data from the
self.c2ms=gr.complex_to_mag_squared(NFFT) block
1. Could you please help me what method should I use to retrieve the data contents of self.c2ms
2. And perform averaging (This could be performed easily using the function below)
3. Display the average in the right status message (i.e., in self._set_status_msg("Put average here!!!", 1)).
Finally for any given block, how can I see and modify the methods easily.
Note that I am using windows command line to run the python file.
A.
get average_energy(data):
avg1=0
for i in data
avg1=avg1+i
return avg1/len(data)
No comments:
Post a Comment