Hello,I have built a Multi band NBFMtransmitter.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 bandfrom gnuradio import gr, engnotationfrom gnuradio
import usrpfrom gnuradio import audiofrom gnuradio import blks2from
gnuradio.engoption import engoptionfrom optparse import OptionParserfrom usrpm
import usrpdbidimport mathimport sys,os,re,tempfile,time,threadfrom
gnuradio.wxgui import stdgui2, fftsink2#from gnuradio import txdebugguiimport
wx# instantiate one transmit chain for each callclass
pipeline(gr.hierblock2):def init(self, outputfile, lofreq, audiorate,
ifrate):gr.hierblock2.init(self, "pipeline",gr.iosignature(0, 0, 0),# Input
signaturegr.iosignature(1, 1, gr.sizeofgrcomplex)) # Output signaturesrc =
gr.filesource (gr.sizeoffloat,outputfi
le, False)fmtx = blks2.nbfmtx (audiorate, ifrate, maxdev=75e3, tau=75e6) #
Local oscillatorlo = gr.sigsourcec (ifrate,# sample rategr.GRSINWAVE, #
waveform typelofreq,#frequency0.1,# amplitude0)# DC Offsetmixer = gr.multiplycc
()self.connect (src, fmtx, (mixer, 0))self.connect (lo, (mixer, 1))self.connect
(mixer, self) ####Working with playlist####################################def
mp3toraw(filename,outputfile):print("nice 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
beepmediaplayer)def readplaylist(fname):input = open(fname,
'r')playlist=[]#[playlist]l = input.readline()# NumberOfEntriesl =
input.readline()nentries = int(re.findall("NumberOfEntries=([09]+)",l)[0])print
"Number of items in list %d
" % nentriesi = 1while l:l=input.readline()filepath =
re.findall("File[09]+=(.*)$",l)if filepath:print
filepath[0]playlist.append(filepath[0])i = i + 1input.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
wfmtx:def init(self):parser = OptionParser
(optionclass=engoption)parser.addoption("T", "txsubdevspec", type="subdev",
default=None,help="select USRP Tx side A or B")parser.addoption("f", "freq",
type="engfloat", default=90e6, help="set Tx frequency to FREQ (default 90e6)",
metavar="FREQ")parser.addoption("l","playlist", action="store",
default=None,help="MP3 playlist containing files to air.")parser.addoption("n",
"nchannels", type="int", default=4, help="number of Tx channels
[1,4]")(options, args) = pars
er.parseargs ()if len(args) != 0:parser.printhelp()sys.exit(1)if
options.playlist == None:print "No playlist specified
"sys.exit()# parse playlistplaylist = readplaylist(options.playlist) self.fg =
gr.topblock()# setup IQ rate to 320kS/s and audio rate to 32kS/sself.u =
usrp.sinkc()self.dacrate = self.u.dacrate()# 128 MS/sself.usrpinterp =
400self.u.setinterprate(self.usrpinterp)self.usrprate = self.dacrate /
self.usrpinterp# 320 kS/sself.swinterp = 10self.audiorate = self.usrprate /
self.swinterp# 32 kS/s# determine the daughterboard subdevice we're usingif
options.txsubdevspec is None:options.txsubdevspec =
usrp.picktxsubdevice(self.u)m = usrp.determinetxmuxvalue(self.u,
options.txsubdevspec)self.u.setmux(m)self.subdev = usrp.selectedsubdev(self.u,
options.txsubdevspec)print "Using TX d'board %s" %
(self.subdev.sideandname(),)self.subdev.setgain(self.subdev.gainrange()[1])#
set max Tx gainif not self.setfreq(options.freq):freqrange =
self.subdev.freqrange()print "Failed to set frequency to %s.Daughterboard
supports %s to %s" %
(engnotation.numtostr(options.freq),engnotation.numtostr(freqran
ge[0]),engnotation.numtostr(freqrange[1]))raise
SystemExitself.subdev.setenable(True) # enable transmitterprint "TX freq %1.2f
MHz
" % (options.freq/1e6) sum = gr.addcc ()# Instantiate N NBFM channelsstep =
25e3offset = (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.startnewthread(mp3toraw,(playlist[i],outputfile))# sleep until we are
sure there is something to playtime.sleep(3)print "File size %d
" % int(os.stat(outputfile)[6]) t = pipeline(outputfile,offset[i],
self.audiorate, self.usrprate)self.fg.connect(t,(sum, i))gain =
gr.multiplyconstcc (4000.0) # connect it allself.fg.connect (sum,
gain,self.u)#src = gr.filesource (gr.sizeoffloat,outputfile, False)# stop and
wait to finishprint "Starting to play"self.fg.run()print "Done" #stop and wait
to
finishself.fg.stop()self.fg.wait()#src=getsrc()#fmtx=getfmtx()#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 setfreq(self, targetfreq):"""Set
the center frequency we're interested in."""r =
self.u.tune(self.subdev.which(), self.subdev, targetfreq)if r:print
"r.basebandfreq =", engnotation.numtostr(r.basebandfreq)print "r.dxcfreq=",
engnotation.numtostr(r.dxcfreq)print "r.residualfreq =",
engnotation.numtostr(r.residualfreq)print "r.inverted=", r.invertedreturn
Truereturn Falseif name == 'main':wfmtx()Regards, Mayur Sarode Ge
t Yourself a cool, short @in.com Email ID now!
_______________________________________________
Discuss-gnuradio mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio