discuss-gnuradio
[Top][All Lists]
Advanced

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

[Discuss-gnuradio] Noise problem in multiband FM transmitter


From: mayur sarode
Subject: [Discuss-gnuradio] Noise problem in multiband FM transmitter
Date: Wed, 13 May 2009 11:27:22 +0530

Hello,
I have built a Multi band NBFM transmitter.As I increase the number of channels for transmission ,the noise is increasing.How do i counteract this in the code.The code is given below

#!/usr/bin/env python
## a program to send multiple mp3 playlist on the FM band
#in this example a single mp3 is sent over N channels on the fm band

from gnuradio import gr, eng_notation
from gnuradio import usrp
from gnuradio import audio
from gnuradio import blks2
from gnuradio.eng_option import eng_option
from optparse import OptionParser
from usrpm import usrp_dbid
import math
import sys,os,re,tempfile,time,thread

from gnuradio.wxgui import stdgui2, fftsink2
#from gnuradio import tx_debug_gui
import wx

# instantiate one transmit chain for each call

class pipeline(gr.hier_block2):
def __init__(self, outputfile, lo_freq, audio_rate, if_rate):

gr.hier_block2.__init__(self, "pipeline",
gr.io_signature(0, 0, 0), # Input signature
gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature

src = "" (gr.sizeof_float,outputfile, False)
fmtx = blks2.nbfm_tx (audio_rate, if_rate, max_dev=75e3, tau=75e-6)


# Local oscillator
lo = gr.sig_source_c (if_rate, # sample rate
gr.GR_SIN_WAVE, # waveform type
lo_freq, #frequency
0.1, # amplitude
0) # DC Offset
mixer = gr.multiply_cc ()

self.connect (src, fmtx, (mixer, 0))
self.connect (lo, (mixer, 1))
self.connect (mixer, self)

####Working with playlist####################################
def mp3toraw(filename,outputfile):
print("n ice -n 19 sox \"%s\" -r 32000 -t raw -f -L -c 1 %s " % (filename,outputfile))
os.system("nice -n 19 sox \"%s\" -r 32000 -t raw -f -L -c 1 %s" % (filename,outputfile))

# Read in .pls format (can be made e.g., using beep-media-player)
def read_playlist(fname):
input = open(fname, 'r')

playlist=[]

#[playlist]
l = input.readline()
# NumberOfEntries
l = input.readline()
nentries = int(re.findall("NumberOfEntries=([0-9]+)",l)[0])

print "Number of items in list %d " % nentries
i = 1
while l:
l=input.readline()

filepath = re.findall("File[0-9]+=(.*)$",l)
if filepath:
print filepath[0]
playlist.append(filepath[0])
i = i + 1

input.close()
return(playlist)

## just create a standard tempfn (sox will create the file, so remove one made by system)
def mktempfn():
tf = tempfile.mkstemp(".raw")
outputfile = tf[1]
os.close(tf[0])
os.remove(tf[1])
return(outputfile)


############################################################################################


class wfm_tx:
def __init__(self):

parser = OptionParser (option_class=eng_option)
parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
help="select USRP Tx side A or B")
parser.add_option("-f", "--freq", type ="eng_float", default=90e6,
help="set Tx frequency to FREQ (default 90e6)", metavar="FREQ")
parser.add_option("-l","--playlist", action="", default=None,
help="MP3 playlist containing files to air.")
parser.add_option("-n", "--nchannels", type="int", default=4,
help="number of Tx channels [1,4]")
(options, args) = parser.parse_args ()

if len(args) != 0:
parser.print_help()
sys.exit(1)

if options.playlist == None:
print "No playlist specified "
sys.exit()

# parse playlist
playlist = read_playlist(options.playlist)

self.fg = gr.top_block()

# setup IQ rate to 320kS/s and audio rate to 32kS/s
self.u = usrp.sink_c()
self.dac_rate = self.u.dac_rate() # 128 MS/s
self.usrp_interp = 400
self.u.set_interp_rate(self.usrp_interp)
self.usrp_rate = self.dac_rate / self.usrp_interp # 320 kS/s
self.sw_interp = 10
self.audio_rate = self.usrp_rate / self.sw_interp # 32 kS/s

# determine the daughterboard subdevice we're using
if options.tx_subdev_spec is None:
options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
self.u.set_mux(m)

self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
print "Using TX d'board %s" % (self.subdev.side_and_name(),)

self.subdev.set_gain(self.subdev.gain_range()[1]) # set max Tx gain

if not self.set_freq(options.freq):
freq_range = self.subdev.freq_range()
print "Failed to set frequency to %s. Daughterboard supports %s to %s" % (
eng_notation.num_to_str(options.freq),
eng_notation.num_to_str(freq_range[0]),
eng_notation.num_to_str(freq_range[1]))
raise SystemExit
self.subdev.set_enable(True) # enable transmitter
print "TX freq %1.2f MHz " % (options.freq/1e6)

sum = gr.add_cc ()


# Instantiate N NBFM channels
step = 25e3
offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step, -3 * step, 4 * step,-4 * step )
for i in range (options.nchannels):
outputfile = mktempfn()
# write raw sound to named pipe in
thread.start_new_thread(mp3toraw,(playlist[i],outputfile))
# sleep until we are sure there is something to play
time.sleep(3)
print "File size %d " % int(os.stat(outputfile)[6])
t = pipeline(outputfile,offset[i],
self.audio_rate, self.usrp_rate)
self.fg.connect(t,(sum, i))

gain = gr.multiply_const_cc (4000.0)
# connect it all
self.fg.connect (sum, gain,self.u)
#src = "" (gr.sizeof_float,outputfile, False)
# stop and wait to finish
print "Starting to play"
self.fg.run()
print "Done"

#stop and wait to finish
self.fg.stop()
self.fg.wait()
#src=""> #fmtx=get_fmtx()
#self.fg.disconnect(src, fmtx, gain, self.u)

os.remove(outputfile)
# hack, we should get pid and kill sox only if necessary.
os.system("killall sox")

def set_freq(self, target_freq):
"""
Set the center frequency we're interested in.
"""
r = self.u.tune(self.subdev.which(), self.subdev, target_freq)
if r:
print "r.baseband_freq =", eng_notation.num_to_str(r.baseband_freq)
print "r.dxc_freq =", eng_notation.num_to_str(r.dxc_freq)
print "r.residual_freq =", eng_notation.num_to_str(r.residual_freq)
print "r.inverted =", r.inverted
return True
return False

if __name__ == '__main__':
wfm_tx()


Regards,
Mayur Sarode

Get Yourself a cool, short @in.com Email ID now!

reply via email to

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