[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r11579 - in gnuradio/branches/developers/trondeau/pfb/
From: |
trondeau |
Subject: |
[Commit-gnuradio] r11579 - in gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python: . pfb |
Date: |
Tue, 11 Aug 2009 17:29:57 -0600 (MDT) |
Author: trondeau
Date: 2009-08-11 17:29:57 -0600 (Tue, 11 Aug 2009)
New Revision: 11579
Added:
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/Makefile.am
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/fmtest.py
Modified:
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/Makefile.am
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/channelize.py
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/chirp_channelize.py
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/decimate.py
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/interpolate.py
Log:
Updating PFB examples.
Modified:
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/Makefile.am
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/Makefile.am
2009-08-11 23:24:29 UTC (rev 11578)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/Makefile.am
2009-08-11 23:29:57 UTC (rev 11579)
@@ -32,5 +32,6 @@
multi_usrp \
network \
ofdm \
+ pfb \
usrp \
usrp2
Added:
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/Makefile.am
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/Makefile.am
(rev 0)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/Makefile.am
2009-08-11 23:29:57 UTC (rev 11579)
@@ -0,0 +1,31 @@
+#
+# Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+include $(top_srcdir)/Makefile.common
+
+ourdatadir = $(exampledir)/pfb
+
+dist_ourdata_SCRIPTS = \
+ channelize.py \
+ chirp_channelize.py \
+ decimate.py \
+ interpolate.py \
+ fmtest.py
Modified:
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/channelize.py
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/channelize.py
2009-08-11 23:24:29 UTC (rev 11578)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/channelize.py
2009-08-11 23:29:57 UTC (rev 11579)
@@ -1,49 +1,72 @@
#!/usr/bin/env python
+#
+# Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
from gnuradio import gr, blks2
-import math
-import os
+import os, time
import scipy, pylab
from scipy import fftpack
-import time
+from pylab import mlab
-#print os.getpid()
-#raw_input()
-
class pfb_top_block(gr.top_block):
def __init__(self):
gr.top_block.__init__(self)
- self._N = 2000000
- self._fs = 9000
- self._Tmax = self._N * (1.0/self._fs)
- self._M = 9
- self._taps = gr.firdes.low_pass_2(1, self._fs, 475,50, 100,5)
+ self._N = 2000000 # number of samples to use
+ self._fs = 9000 # initial sampling rate
+ self._M = 9 # Number of channels to channelize
- fc = 200
+ # Create a set of taps for the PFB channelizer
+ self._taps = gr.firdes.low_pass_2(1, self._fs, 475.50, 50,
+ attenuation_dB=10,
window=gr.firdes.WIN_BLACKMAN_hARRIS)
- tpc = math.ceil(float(len(self._taps)) / float(self._M))
-
+ # Calculate the number of taps per channel for our own information
+ tpc = scipy.ceil(float(len(self._taps)) / float(self._M))
print "Number of taps: ", len(self._taps)
print "Number of channels: ", self._M
print "Taps per channel: ", tpc
+ # Create a set of signals at different frequencies
+ # freqs lists the frequencies of the signals that get stored
+ # in the list "signals", which then get summed together
self.signals = list()
self.add = gr.add_cc()
- freqs = [-4070, -3050, -2030, -1010, 10, 1020, 2040, 3060, 4300]
+ freqs = [-4070, -3050, -2030, -1010, 10, 1020, 2040, 3060, 4080]
for i in xrange(len(freqs)):
self.signals.append(gr.sig_source_c(self._fs, gr.GR_SIN_WAVE,
freqs[i], 1))
self.connect(self.signals[i], (self.add,i))
self.head = gr.head(gr.sizeof_gr_complex, self._N)
+
+ # Construct the channelizer filter
self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps)
+
+ # Construct a vector sink for the input signal to the channelizer
self.snk_i = gr.vector_sink_c()
# Connect the blocks
self.connect(self.add, self.head, self.pfb)
self.connect(self.add, self.snk_i)
- # Create a file sink for each of M output channels of the filter and
connect it
+ # Create a vector sink for each of M output channels of the filter and
connect it
self.snks = list()
for i in xrange(self._M):
self.snks.append(gr.vector_sink_c())
@@ -75,9 +98,9 @@
d = tb.snk_i.data()[Ns:Ne]
spin_f = fig_in.add_subplot(2, 1, 1)
- X,freq = spin_f.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
- window = lambda d: d*winfunc(fftlen),
- visible=False)
+ X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
+ window = lambda d: d*winfunc(fftlen),
+ scale_by_freq=True)
X_in = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
f_in = scipy.arange(-fs/2.0, fs/2.0, fs/float(X_in.size))
pin_f = spin_f.plot(f_in, X_in, "b")
@@ -88,7 +111,11 @@
spin_f.set_xlabel("Frequency (Hz)")
spin_f.set_ylabel("Power (dBW)")
- t_in = scipy.arange(0, tb._Tmax, tb._Tmax/float(len(d)))
+
+ Ts = 1.0/fs
+ Tmax = len(d)*Ts
+
+ t_in = scipy.arange(0, Tmax, Ts)
x_in = scipy.array(d)
spin_t = fig_in.add_subplot(2, 1, 2)
pin_t = spin_t.plot(t_in, x_in.real, "b")
@@ -105,6 +132,8 @@
# Plot each of the channels outputs. Frequencies on Figure 2 and
# time signals on Figure 3
fs_o = tb._fs / tb._M
+ Ts_o = 1.0/fs_o
+ Tmax_o = len(d)*Ts_o
for i in xrange(len(tb.snks)):
# remove issues with the transients at the beginning
# also remove some corruption at the end of the stream
@@ -112,9 +141,9 @@
d = tb.snks[i].data()[Ns:Ne]
sp1_f = fig1.add_subplot(Nrows, Ncols, 1+i)
- X,freq = sp1_f.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs_o,
- window = lambda d: d*winfunc(fftlen),
- visible=False)
+ X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs_o,
+ window = lambda d: d*winfunc(fftlen),
+ scale_by_freq=True)
X_o = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
f_o = scipy.arange(-fs_o/2.0, fs_o/2.0, fs_o/float(X_o.size))
p2_f = sp1_f.plot(f_o, X_o, "b")
@@ -125,15 +154,15 @@
sp1_f.set_xlabel("Frequency (Hz)")
sp1_f.set_ylabel("Power (dBW)")
-
x_o = scipy.array(d)
- t_o = scipy.arange(0, tb._Tmax, tb._Tmax/float(x_o.size))
+ t_o = scipy.arange(0, Tmax_o, Ts_o)
sp2_o = fig2.add_subplot(Nrows, Ncols, 1+i)
p2_o = sp2_o.plot(t_o, x_o.real, "b")
p2_o = sp2_o.plot(t_o, x_o.imag, "r")
sp2_o.set_xlim([min(t_o), max(t_o)+1])
sp2_o.set_ylim([-2, 2])
+ sp2_o.set_title(("Channel %d" % i), weight="bold")
sp2_o.set_xlabel("Time (s)")
sp2_o.set_ylabel("Amplitude")
Modified:
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/chirp_channelize.py
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/chirp_channelize.py
2009-08-11 23:24:29 UTC (rev 11578)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/chirp_channelize.py
2009-08-11 23:29:57 UTC (rev 11579)
@@ -1,49 +1,76 @@
#!/usr/bin/env python
+#
+# Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
from gnuradio import gr, blks2
-import math
-import os
+import os, time
import scipy, pylab
from scipy import fftpack
-import time
+from pylab import mlab
-#print os.getpid()
-#raw_input()
-
class pfb_top_block(gr.top_block):
def __init__(self):
gr.top_block.__init__(self)
- self._N = 200000
- self._fs = 9000
- self._Tmax = self._N * (1.0/self._fs)
- self._M = 9
- self._taps = gr.firdes.low_pass_2(1, self._fs, 800,100 ,90,5)
- fc = 200
+ self._N = 200000 # number of samples to use
+ self._fs = 9000 # initial sampling rate
+ self._M = 9 # Number of channels to channelize
- tpc = math.ceil(float(len(self._taps)) / float(self._M))
+ # Create a set of taps for the PFB channelizer
+ self._taps = gr.firdes.low_pass_2(1, self._fs, 500, 20,
+ attenuation_dB=10,
window=gr.firdes.WIN_BLACKMAN_hARRIS)
+ # Calculate the number of taps per channel for our own information
+ tpc = scipy.ceil(float(len(self._taps)) / float(self._M))
print "Number of taps: ", len(self._taps)
print "Number of channels: ", self._M
print "Taps per channel: ", tpc
- data = scipy.arange(0, 1000, 100.0/float(self._N))
-
- #self.vco_input = gr.sig_source_f(self._fs, gr.GR_SIN_WAVE, 0.25, 100)
- self.vco_input = gr.vector_source_f(data, False)
+ repeated = True
+ if(repeated):
+ self.vco_input = gr.sig_source_f(self._fs, gr.GR_SIN_WAVE, 0.25,
110)
+ else:
+ amp = 100
+ data = scipy.arange(0, amp, amp/float(self._N))
+ self.vco_input = gr.vector_source_f(data, False)
+
+ # Build a VCO controlled by either the sinusoid or single chirp tone
+ # Then convert this to a complex signal
self.vco = gr.vco_f(self._fs, 225, 1)
self.f2c = gr.float_to_complex()
self.head = gr.head(gr.sizeof_gr_complex, self._N)
+
+ # Construct the channelizer filter
self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps)
+
+ # Construct a vector sink for the input signal to the channelizer
self.snk_i = gr.vector_sink_c()
- # Connect the rest
+ # Connect the blocks
self.connect(self.vco_input, self.vco, self.f2c)
self.connect(self.f2c, self.head, self.pfb)
self.connect(self.f2c, self.snk_i)
- # Create a file sink for each of M output channels of the filter and
connect it
+ # Create a vector sink for each of M output channels of the filter and
connect it
self.snks = list()
for i in xrange(self._M):
self.snks.append(gr.vector_sink_c())
@@ -60,42 +87,100 @@
print "Run time: %f" % (tend - tstart)
if 1:
- fig1 = pylab.figure(1, figsize=(16,9))
- fig2 = pylab.figure(2, figsize=(16,9))
+ fig_in = pylab.figure(1, figsize=(16,9), facecolor="w")
+ fig1 = pylab.figure(2, figsize=(16,9), facecolor="w")
+ fig2 = pylab.figure(3, figsize=(16,9), facecolor="w")
+ fig3 = pylab.figure(4, figsize=(16,9), facecolor="w")
- Ns = 100
- Ne = tb._N
+ Ns = 650
+ Ne = 20000
+
+ fftlen = 8192
+ winfunc = scipy.blackman
+ fs = tb._fs
+
+ # Plot the input signal on its own figure
d = tb.snk_i.data()[Ns:Ne]
- f_in = scipy.arange(-tb._fs/2.0, tb._fs/2.0, tb._fs/float(len(d)))
- X_in = 10.0*scipy.log10(fftpack.fftshift(fftpack.fft(d, f_in.size)))
- sp1_in = fig1.add_subplot(4, 3, 1)
- p1_in = sp1_in.plot(f_in, X_in)
+ spin_f = fig_in.add_subplot(2, 1, 1)
+
+ X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
+ window = lambda d: d*winfunc(fftlen),
+ scale_by_freq=True)
+ X_in = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
+ f_in = scipy.arange(-fs/2.0, fs/2.0, fs/float(X_in.size))
+ pin_f = spin_f.plot(f_in, X_in, "b")
+ spin_f.set_xlim([min(f_in), max(f_in)+1])
+ spin_f.set_ylim([-200.0, 50.0])
+
+ spin_f.set_title("Input Signal", weight="bold")
+ spin_f.set_xlabel("Frequency (Hz)")
+ spin_f.set_ylabel("Power (dBW)")
+
+
+ Ts = 1.0/fs
+ Tmax = len(d)*Ts
- t_in = scipy.arange(0, tb._Tmax, tb._Tmax/float(len(d)))
+ t_in = scipy.arange(0, Tmax, Ts)
x_in = scipy.array(d)
- sp2_in = fig2.add_subplot(4, 3, 1)
- p2_in = sp2_in.plot(t_in, x_in.real, "b")
- p2_in = sp2_in.plot(t_in, x_in.imag, "r")
-
+ spin_t = fig_in.add_subplot(2, 1, 2)
+ pin_t = spin_t.plot(t_in, x_in.real, "b")
+ pin_t = spin_t.plot(t_in, x_in.imag, "r")
+
+ spin_t.set_xlabel("Time (s)")
+ spin_t.set_ylabel("Amplitude")
+
+ Ncols = int(scipy.floor(scipy.sqrt(tb._M)))
+ Nrows = int(scipy.floor(tb._M / Ncols))
+ if(tb._M % Ncols != 0):
+ Nrows += 1
+
+ # Plot each of the channels outputs. Frequencies on Figure 2 and
+ # time signals on Figure 3
fs_o = tb._fs / tb._M
+ Ts_o = 1.0/fs_o
+ Tmax_o = len(d)*Ts_o
for i in xrange(len(tb.snks)):
# remove issues with the transients at the beginning
# also remove some corruption at the end of the stream
# this is a bug, probably due to the corner cases
d = tb.snks[i].data()[Ns:Ne]
- f_o = scipy.arange(-fs_o/2.0, fs_o/2.0, fs_o/float(len(d)))
- x_o = 10.0*scipy.log10(fftpack.fftshift(fftpack.fft(d)))
- sp1_o = fig1.add_subplot(4, 3, 2+i)
- p1_o = sp1_o.plot(f_o, x_o)
- sp1_o.set_ylim([-50.0, 30.0])
-
+
+ sp1_f = fig1.add_subplot(Nrows, Ncols, 1+i)
+ X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs_o,
+ window = lambda d: d*winfunc(fftlen),
+ scale_by_freq=True)
+ X_o = 10.0*scipy.log10(abs(X))
+ f_o = freq
+ p2_f = sp1_f.plot(f_o, X_o, "b")
+ sp1_f.set_xlim([min(f_o), max(f_o)+1])
+ sp1_f.set_ylim([-200.0, 50.0])
+
+ sp1_f.set_title(("Channel %d" % i), weight="bold")
+ sp1_f.set_xlabel("Frequency (Hz)")
+ sp1_f.set_ylabel("Power (dBW)")
+
x_o = scipy.array(d)
- t_o = scipy.arange(0, tb._Tmax, tb._Tmax/float(x_o.size))
- sp2_o = fig2.add_subplot(4, 3, 2+i)
+ t_o = scipy.arange(0, Tmax_o, Ts_o)
+ sp2_o = fig2.add_subplot(Nrows, Ncols, 1+i)
p2_o = sp2_o.plot(t_o, x_o.real, "b")
p2_o = sp2_o.plot(t_o, x_o.imag, "r")
- sp2_o.set_ylim([-1.0, 1.0])
-
+ sp2_o.set_xlim([min(t_o), max(t_o)+1])
+ sp2_o.set_ylim([-2, 2])
+
+ sp2_o.set_title(("Channel %d" % i), weight="bold")
+ sp2_o.set_xlabel("Time (s)")
+ sp2_o.set_ylabel("Amplitude")
+
+
+ sp3 = fig3.add_subplot(1,1,1)
+ p3 = sp3.plot(t_o, x_o.real)
+ sp3.set_xlim([min(t_o), max(t_o)+1])
+ sp3.set_ylim([-2, 2])
+
+ sp3.set_title("All Channels")
+ sp3.set_xlabel("Time (s)")
+ sp3.set_ylabel("Amplitude")
+
pylab.show()
Modified:
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/decimate.py
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/decimate.py
2009-08-11 23:24:29 UTC (rev 11578)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/decimate.py
2009-08-11 23:29:57 UTC (rev 11579)
@@ -1,10 +1,30 @@
#!/usr/bin/env python
+#
+# Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
from gnuradio import gr, blks2
-import math
import os
import scipy, pylab
from scipy import fftpack
+from pylab import mlab
import time
#print os.getpid()
@@ -14,28 +34,38 @@
def __init__(self):
gr.top_block.__init__(self)
- self._N = 10000000
- self._fs = 10000
- self._Tmax = self._N * (1.0/self._fs)
- self._decim = 20
- self._taps = gr.firdes.low_pass_2(1, self._fs, 200, 50,120,5)
+ self._N = 10000000 # number of samples to use
+ self._fs = 10000 # initial sampling rate
+ self._decim = 20 # Decimation rate
+
+ # Generate the prototype filter taps for the decimators with a 200 Hz
bandwidth
+ self._taps = gr.firdes.low_pass_2(1, self._fs, 200, 150,
+ attenuation_dB=120,
window=gr.firdes.WIN_BLACKMAN_hARRIS)
- tpc = math.ceil(float(len(self._taps)) / float(self._decim))
-
+ # Calculate the number of taps per channel for our own information
+ tpc = scipy.ceil(float(len(self._taps)) / float(self._decim))
print "Number of taps: ", len(self._taps)
print "Number of filters: ", self._decim
print "Taps per channel: ", tpc
+ # Build the input signal source
+ # We create a list of freqs, and a sine wave is generated and added to
the source
+ # for each one of these frequencies.
self.signals = list()
self.add = gr.add_cc()
- freqs = [10, 2040]
+ freqs = [10, 20, 2040]
for i in xrange(len(freqs)):
self.signals.append(gr.sig_source_c(self._fs, gr.GR_SIN_WAVE,
freqs[i], 1))
self.connect(self.signals[i], (self.add,i))
self.head = gr.head(gr.sizeof_gr_complex, self._N)
+
+ # Construct a PFB decimator filter
self.pfb = blks2.pfb_decimator_ccf(self._decim, self._taps, 0)
- #self.pfb = gr.fir_filter_ccf(self._decim, self._taps)
+
+ # Construct a standard FIR decimating filter
+ self.dec = gr.fir_filter_ccf(self._decim, self._taps)
+
self.snk_i = gr.vector_sink_c()
# Connect the blocks
@@ -71,9 +101,9 @@
d = tb.snk_i.data()[Ns:Ns+Ne]
sp1_f = fig1.add_subplot(2, 1, 1)
- X,freq = sp1_f.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
- window = lambda d: d*winfunc(fftlen),
- visible=False)
+ X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
+ window = lambda d: d*winfunc(fftlen),
+ scale_by_freq=True)
X_in = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
f_in = scipy.arange(-fs/2.0, fs/2.0, fs/float(X_in.size))
p1_f = sp1_f.plot(f_in, X_in, "b")
@@ -84,7 +114,10 @@
sp1_f.set_xlabel("Frequency (Hz)")
sp1_f.set_ylabel("Power (dBW)")
- t_in = scipy.arange(0, tb._Tmax, tb._Tmax/float(len(d)))
+ Ts = 1.0/fs
+ Tmax = len(d)*Ts
+
+ t_in = scipy.arange(0, Tmax, Ts)
x_in = scipy.array(d)
sp1_t = fig1.add_subplot(2, 1, 2)
p1_t = sp1_t.plot(t_in, x_in.real, "b")
@@ -100,9 +133,9 @@
sp2_f = fig2.add_subplot(2, 1, 1)
d = tb.snk.data()[Ns:Ns+Ne]
- X,freq = sp2_f.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs_o,
- window = lambda d: d*winfunc(fftlen),
- visible=False)
+ X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs_o,
+ window = lambda d: d*winfunc(fftlen),
+ scale_by_freq=True)
X_o = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
f_o = scipy.arange(-fs_o/2.0, fs_o/2.0, fs_o/float(X_o.size))
p2_f = sp2_f.plot(f_o, X_o, "b")
@@ -114,12 +147,15 @@
sp2_f.set_ylabel("Power (dBW)")
+ Ts_o = 1.0/fs_o
+ Tmax_o = len(d)*Ts_o
+
x_o = scipy.array(d)
- t_o = scipy.arange(0, tb._Tmax, tb._Tmax/float(x_o.size))
+ t_o = scipy.arange(0, Tmax_o, Ts_o)
sp2_t = fig2.add_subplot(2, 1, 2)
- p2_t = sp2_t.plot(t_o, x_o.real, "b")
- p2_t = sp2_t.plot(t_o, x_o.imag, "r")
- sp2_t.set_ylim([-1.5, 1.5])
+ p2_t = sp2_t.plot(t_o, x_o.real, "b-o")
+ p2_t = sp2_t.plot(t_o, x_o.imag, "r-o")
+ sp2_t.set_ylim([-2.5, 2.5])
sp2_t.set_xlabel("Time (s)")
sp2_t.set_ylabel("Amplitude")
Added:
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/fmtest.py
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/fmtest.py
(rev 0)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/fmtest.py
2009-08-11 23:29:57 UTC (rev 11579)
@@ -0,0 +1,197 @@
+#!/usr/bin/env python
+#
+
+
+from gnuradio import gr, eng_notation
+from gnuradio import blks2
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+import math, time, sys, scipy, pylab
+from scipy import fftpack
+
+class fmtx(gr.hier_block2):
+ def __init__(self, lo_freq, audio_rate, if_rate):
+
+ gr.hier_block2.__init__(self, "build_fm",
+ gr.io_signature(1, 1, gr.sizeof_float), #
Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) #
Output signature
+
+ fmtx = blks2.nbfm_tx (audio_rate, if_rate, max_dev=5e3, tau=75e-6)
+
+ # Local oscillator
+ lo = gr.sig_source_c (if_rate, # sample rate
+ gr.GR_SIN_WAVE, # waveform type
+ lo_freq, #frequency
+ 1.0, # amplitude
+ 0) # DC Offset
+ mixer = gr.multiply_cc ()
+
+ self.connect (self, fmtx, (mixer, 0))
+ self.connect (lo, (mixer, 1))
+ self.connect (mixer, self)
+
+class fmtest(gr.top_block):
+ def __init__(self):
+ gr.top_block.__init__(self)
+
+ self._nsamples = 1000000
+ self._audio_rate = 8000
+
+ # Set up N channels with their own baseband and IF frequencies
+ self._N = 5
+ chspacing = 16000
+ freq = [10, 20, 30, 40, 50]
+ f_lo = [0, 1*chspacing, -1*chspacing, 2*chspacing, -2*chspacing]
+
+ self._if_rate = 4*self._N*self._audio_rate
+
+ # Create a signal source and frequency modulate it
+ self.sum = gr.add_cc ()
+ for n in xrange(self._N):
+ sig = gr.sig_source_f(self._audio_rate, gr.GR_SIN_WAVE, freq[n],
0.5)
+ fm = fmtx(f_lo[n], self._audio_rate, self._if_rate)
+ self.connect(sig, fm)
+ self.connect(fm, (self.sum, n))
+
+ self.head = gr.head(gr.sizeof_gr_complex, self._nsamples)
+ self.snk_tx = gr.vector_sink_c()
+ self.channel = blks2.channel_model(0.1)
+
+ self.connect(self.sum, self.head, self.channel, self.snk_tx)
+
+
+ # Design the channlizer
+ self._M = 10
+ bw = chspacing/2.0
+ t_bw = chspacing/10.0
+ self._chan_rate = self._if_rate / self._M
+ self._taps = gr.firdes.low_pass_2(1, self._if_rate, bw, t_bw,
+ attenuation_dB=100,
+ window=gr.firdes.WIN_BLACKMAN_hARRIS)
+ tpc = math.ceil(float(len(self._taps)) / float(self._M))
+
+ print "Number of taps: ", len(self._taps)
+ print "Number of channels: ", self._M
+ print "Taps per channel: ", tpc
+
+ self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps)
+
+ self.connect(self.channel, self.pfb)
+
+ # Create a file sink for each of M output channels of the filter and
connect it
+ self.fmdet = list()
+ self.squelch = list()
+ self.snks = list()
+ for i in xrange(self._M):
+ self.fmdet.append(blks2.nbfm_rx(self._audio_rate, self._chan_rate))
+ self.squelch.append(blks2.standard_squelch(self._audio_rate*10))
+ self.snks.append(gr.vector_sink_f())
+ self.connect((self.pfb, i), self.fmdet[i], self.squelch[i],
self.snks[i])
+
+ def num_tx_channels(self):
+ return self._N
+
+ def num_rx_channels(self):
+ return self._M
+
+def main():
+
+ fm = fmtest()
+
+ tstart = time.time()
+ fm.run()
+ tend = time.time()
+
+ if 1:
+ fig1 = pylab.figure(1, figsize=(12,10), facecolor="w")
+ fig2 = pylab.figure(2, figsize=(12,10), facecolor="w")
+ fig3 = pylab.figure(3, figsize=(12,10), facecolor="w")
+
+ Ns = 10000
+ Ne = 100000
+
+ fftlen = 8192
+ winfunc = scipy.blackman
+
+ # Plot transmitted signal
+ fs = fm._if_rate
+
+ d = fm.snk_tx.data()[Ns:Ns+Ne]
+ sp1_f = fig1.add_subplot(2, 1, 1)
+
+ X,freq = sp1_f.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
+ window = lambda d: d*winfunc(fftlen),
+ visible=False)
+ X_in = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
+ f_in = scipy.arange(-fs/2.0, fs/2.0, fs/float(X_in.size))
+ p1_f = sp1_f.plot(f_in, X_in, "b")
+ sp1_f.set_xlim([min(f_in), max(f_in)+1])
+ sp1_f.set_ylim([-120.0, 20.0])
+
+ sp1_f.set_title("Input Signal", weight="bold")
+ sp1_f.set_xlabel("Frequency (Hz)")
+ sp1_f.set_ylabel("Power (dBW)")
+
+ Ts = 1.0/fs
+ Tmax = len(d)*Ts
+
+ t_in = scipy.arange(0, Tmax, Ts)
+ x_in = scipy.array(d)
+ sp1_t = fig1.add_subplot(2, 1, 2)
+ p1_t = sp1_t.plot(t_in, x_in.real, "b-o")
+ #p1_t = sp1_t.plot(t_in, x_in.imag, "r-o")
+ sp1_t.set_ylim([-5, 5])
+
+ # Set up the number of rows and columns for plotting the subfigures
+ Ncols = int(scipy.floor(scipy.sqrt(fm.num_rx_channels())))
+ Nrows = int(scipy.floor(fm.num_rx_channels() / Ncols))
+ if(fm.num_rx_channels() % Ncols != 0):
+ Nrows += 1
+
+ # Plot each of the channels outputs. Frequencies on Figure 2 and
+ # time signals on Figure 3
+ fs_o = fm._audio_rate
+ for i in xrange(len(fm.snks)):
+ # remove issues with the transients at the beginning
+ # also remove some corruption at the end of the stream
+ # this is a bug, probably due to the corner cases
+ d = fm.snks[i].data()[Ns:Ne]
+
+ sp2_f = fig2.add_subplot(Nrows, Ncols, 1+i)
+ X,freq = sp2_f.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs_o,
+ window = lambda d: d*winfunc(fftlen),
+ visible=False)
+ #X_o = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
+ X_o = 10.0*scipy.log10(abs(X))
+ #f_o = scipy.arange(-fs_o/2.0, fs_o/2.0, fs_o/float(X_o.size))
+ f_o = scipy.arange(0, fs_o/2.0, fs_o/2.0/float(X_o.size))
+ p2_f = sp2_f.plot(f_o, X_o, "b")
+ sp2_f.set_xlim([min(f_o), max(f_o)+0.1])
+ sp2_f.set_ylim([-120.0, 20.0])
+ sp2_f.grid(True)
+
+ sp2_f.set_title(("Channel %d" % i), weight="bold")
+ sp2_f.set_xlabel("Frequency (kHz)")
+ sp2_f.set_ylabel("Power (dBW)")
+
+
+ Ts = 1.0/fs_o
+ Tmax = len(d)*Ts
+ t_o = scipy.arange(0, Tmax, Ts)
+
+ x_t = scipy.array(d)
+ sp2_t = fig3.add_subplot(Nrows, Ncols, 1+i)
+ p2_t = sp2_t.plot(t_o, x_t.real, "b")
+ p2_t = sp2_t.plot(t_o, x_t.imag, "r")
+ sp2_t.set_xlim([min(t_o), max(t_o)+1])
+ sp2_t.set_ylim([-1, 1])
+
+ sp2_t.set_xlabel("Time (s)")
+ sp2_t.set_ylabel("Amplitude")
+
+
+ pylab.show()
+
+
+if __name__ == "__main__":
+ main()
Property changes on:
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/fmtest.py
___________________________________________________________________
Added: svn:executable
+ *
Modified:
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/interpolate.py
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/interpolate.py
2009-08-11 23:24:29 UTC (rev 11578)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/interpolate.py
2009-08-11 23:29:57 UTC (rev 11579)
@@ -1,10 +1,30 @@
#!/usr/bin/env python
+#
+# Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
from gnuradio import gr, blks2
-import math
import os
import scipy, pylab
from scipy import fftpack
+from pylab import mlab
import time
#print os.getpid()
@@ -14,36 +34,52 @@
def __init__(self):
gr.top_block.__init__(self)
+ self._N = 100000 # number of samples to use
+ self._fs = 2000 # initial sampling rate
+ self._interp = 5 # Interpolation rate for PFB interpolator
+ self._ainterp = 5.5 # Resampling rate for the PFB arbitrary
resampler
+
+ # Frequencies of the signals we construct
freq1 = 100
- freq2 = 500
+ freq2 = 200
- self._N = 100000
- self._fs = 2000
- self._Tmax = self._N * (1.0/self._fs)
- self._interp = 8
- self._ainterp = 8
+ # Create a set of taps for the PFB interpolator
+ # This is based on the post-interpolation sample rate
+ self._taps = gr.firdes.low_pass_2(self._interp, self._interp*self._fs,
freq2+50, 50,
+ attenuation_dB=120,
window=gr.firdes.WIN_BLACKMAN_hARRIS)
- self._taps = gr.firdes.low_pass_2(self._interp, self._interp*self._fs,
freq2+50, 150,120,5)
- self._taps2 = gr.firdes.low_pass_2(32.0, 1,
- 0.4 / (32.0), 0.1/(32.0),100,5)
+ # Create a set of taps for the PFB arbitrary resampler
+ # The filter size is the number of filters in the filterbank; 32 will
give very low side-lobes,
+ # and larger numbers will reduce these even farther
+ # The taps in this filter are based on a sampling rate of the filter
size since it acts
+ # internally as an interpolator.
+ flt_size = 32
+ self._taps2 = gr.firdes.low_pass_2(flt_size, flt_size*self._fs,
freq2+50, 150,
+ attenuation_dB=120,
window=gr.firdes.WIN_BLACKMAN_hARRIS)
- tpc = math.ceil(float(len(self._taps)) / float(self._interp))
-
+ # Calculate the number of taps per channel for our own information
+ tpc = scipy.ceil(float(len(self._taps)) / float(self._interp))
print "Number of taps: ", len(self._taps)
print "Number of filters: ", self._interp
print "Taps per channel: ", tpc
-
+
+ # Create a couple of signals at different frequencies
self.signal1 = gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freq1, 0.5)
self.signal2 = gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freq2, 0.5)
self.signal = gr.add_cc()
self.head = gr.head(gr.sizeof_gr_complex, self._N)
+
+ # Construct the PFB interpolator filter
self.pfb = blks2.pfb_interpolator_ccf(self._interp, self._taps)
- self.pfb_ar = blks2.pfb_arb_resampler_ccf(self._ainterp, self._taps2)
+
+ # Construct the PFB arbitrary resampler filter
+ self.pfb_ar = blks2.pfb_arb_resampler_ccf(self._ainterp, self._taps2,
flt_size)
self.snk_i = gr.vector_sink_c()
#self.pfb_ar.pfb.print_taps()
-
+ #self.pfb.pfb.print_taps()
+
# Connect the blocks
self.connect(self.signal1, self.head, (self.signal,0))
self.connect(self.signal2, (self.signal,1))
@@ -51,7 +87,7 @@
self.connect(self.signal, self.pfb_ar)
self.connect(self.signal, self.snk_i)
- # Create the sink for the interpolated siganl
+ # Create the sink for the interpolated signals
self.snk1 = gr.vector_sink_c()
self.snk2 = gr.vector_sink_c()
self.connect(self.pfb, self.snk1)
@@ -84,9 +120,9 @@
d = tb.snk_i.data()[Ns:Ns+Ne]
sp1_f = fig1.add_subplot(2, 1, 1)
- X,freq = sp1_f.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
- window = lambda d: d*winfunc(fftlen),
- visible=False)
+ X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
+ window = lambda d: d*winfunc(fftlen),
+ scale_by_freq=True)
X_in = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
f_in = scipy.arange(-fs/2.0, fs/2.0, fs/float(X_in.size))
p1_f = sp1_f.plot(f_in, X_in, "b")
@@ -118,9 +154,9 @@
sp2_f = fig2.add_subplot(2, 1, 1)
d = tb.snk1.data()[Ns:Ns+(tb._interp*Ne)]
- X,freq = sp2_f.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
- window = lambda d: d*winfunc(fftlen),
- visible=False)
+ X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
+ window = lambda d: d*winfunc(fftlen),
+ scale_by_freq=True)
X_o = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
f_o = scipy.arange(-fs_int/2.0, fs_int/2.0, fs_int/float(X_o.size))
p2_f = sp2_f.plot(f_o, X_o, "b")
@@ -151,20 +187,15 @@
sp3_f = fig3.add_subplot(2, 1, 1)
d = tb.snk2.data()[Ns:Ns+(tb._interp*Ne)]
- X,freq = sp3_f.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
- window = lambda d: d*winfunc(fftlen),
- visible=False)
+ X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs,
+ window = lambda d: d*winfunc(fftlen),
+ scale_by_freq=True)
X_o = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
f_o = scipy.arange(-fs_aint/2.0, fs_aint/2.0, fs_aint/float(X_o.size))
p3_f = sp3_f.plot(f_o, X_o, "b")
sp3_f.set_xlim([min(f_o), max(f_o)+1])
sp3_f.set_ylim([-200.0, 50.0])
- #f_o = scipy.arange(-fs_int/2.0, fs_int/2.0, fs_int/float(len(d)))
- #X_o = 10.0*scipy.log10(fftpack.fftshift(fftpack.fft(d)))
- #p3_f = sp3_f.plot(f_o, X_o)
- #sp3_f.set_ylim([-50.0, 50.0])
-
sp3_f.set_title("Output Signal from PFB Arbitrary Resampler",
weight="bold")
sp3_f.set_xlabel("Frequency (Hz)")
sp3_f.set_ylabel("Power (dBW)")
@@ -173,10 +204,11 @@
Tmax = len(d)*Ts_aint
t_o = scipy.arange(0, Tmax, Ts_aint)
- x_o1 = scipy.array(d)
+ x_o2 = scipy.array(d)
sp3_f = fig3.add_subplot(2, 1, 2)
- p3_f = sp3_f.plot(t_o, x_o1.real, "b-o")
- #p3_f = sp3_f.plot(t_o, x_o.imag, "r-o")
+ p3_f = sp3_f.plot(t_o, x_o2.real, "b-o")
+ p3_f = sp3_f.plot(t_o, x_o1.real, "m-o")
+ #p3_f = sp3_f.plot(t_o, x_o2.imag, "r-o")
sp3_f.set_ylim([-2.5, 2.5])
sp3_f.set_title("Output Signal from PFB Arbitrary Resampler",
weight="bold")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r11579 - in gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python: . pfb,
trondeau <=