diff options
author | Marcus Müller <marcus@hostalia.de> | 2018-06-25 19:28:29 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-06-25 19:28:29 +0200 |
commit | 03ae7938351f01313d30a41927ffb77670fcca14 (patch) | |
tree | 586744f0e2b7560dc161f2a7a60030155d43ce8a /gr-fft | |
parent | d78f7fcd0dadd362fcdc99194da5343a506eb519 (diff) | |
parent | c66aec4dfae559004e88da968d1ce57584e144ee (diff) |
Merge branch 'next_python3' into next
This brings Python3 to `next`.
It also brings
* a bump in SWIG dependency version
* various GRC improvements,
* YAML instead of XML in GRC
* a lot of broken unit tests
Diffstat (limited to 'gr-fft')
-rw-r--r-- | gr-fft/grc/CMakeLists.txt | 10 | ||||
-rw-r--r-- | gr-fft/grc/fft.tree.yml | 7 | ||||
-rw-r--r-- | gr-fft/grc/fft_block_tree.xml | 41 | ||||
-rw-r--r-- | gr-fft/grc/fft_ctrlport_probe_psd.block.yml | 31 | ||||
-rw-r--r-- | gr-fft/grc/fft_ctrlport_probe_psd.xml | 63 | ||||
-rw-r--r-- | gr-fft/grc/fft_fft_vxx.block.yml | 60 | ||||
-rw-r--r-- | gr-fft/grc/fft_fft_vxx.xml | 88 | ||||
-rw-r--r-- | gr-fft/grc/fft_goertzel_fc.block.yml | 30 | ||||
-rw-r--r-- | gr-fft/grc/fft_goertzel_fc.xml | 37 | ||||
-rw-r--r-- | gr-fft/grc/fft_logpwrfft_x.block.yml | 59 | ||||
-rw-r--r-- | gr-fft/grc/fft_logpwrfft_x.xml | 90 | ||||
-rw-r--r-- | gr-fft/python/fft/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-fft/python/fft/__init__.py | 8 | ||||
-rw-r--r-- | gr-fft/python/fft/logpwrfft.py | 13 | ||||
-rw-r--r--[-rwxr-xr-x] | gr-fft/python/fft/qa_fft.py | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | gr-fft/python/fft/qa_goertzel.py | 40 |
16 files changed, 229 insertions, 352 deletions
diff --git a/gr-fft/grc/CMakeLists.txt b/gr-fft/grc/CMakeLists.txt index 8eeb431c3e..d0432c4281 100644 --- a/gr-fft/grc/CMakeLists.txt +++ b/gr-fft/grc/CMakeLists.txt @@ -18,10 +18,10 @@ # Boston, MA 02110-1301, USA. install(FILES - fft_block_tree.xml - fft_fft_vxx.xml - fft_goertzel_fc.xml - fft_logpwrfft_x.xml - fft_ctrlport_probe_psd.xml + fft.tree.yml + fft_fft_vxx.block.yml + fft_goertzel_fc.block.yml + fft_logpwrfft_x.block.yml + fft_ctrlport_probe_psd.block.yml DESTINATION ${GRC_BLOCKS_DIR} ) diff --git a/gr-fft/grc/fft.tree.yml b/gr-fft/grc/fft.tree.yml new file mode 100644 index 0000000000..c198bc4573 --- /dev/null +++ b/gr-fft/grc/fft.tree.yml @@ -0,0 +1,7 @@ +'[Core]': +- Fourier Analysis: + - fft_vxx + - goertzel_fc + - logpwrfft_x +- Control Port: + - fft_ctrlport_probe_psd diff --git a/gr-fft/grc/fft_block_tree.xml b/gr-fft/grc/fft_block_tree.xml deleted file mode 100644 index e844d837b4..0000000000 --- a/gr-fft/grc/fft_block_tree.xml +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0"?> - -<!-- - Copyright 2012 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. ---> - -<!-- -################################################### -##Block Tree for GR FFT blocks. -################################################### - --> -<cat> - <name>[Core]</name> <!-- Blank for Root Name --> - <cat> - <name>Fourier Analysis</name> - <block>fft_vxx</block> - <block>goertzel_fc</block> - <block>logpwrfft_x</block> - </cat> - <cat> - <name>Control Port</name> - <block>fft_ctrlport_probe_psd</block> - </cat> -</cat> diff --git a/gr-fft/grc/fft_ctrlport_probe_psd.block.yml b/gr-fft/grc/fft_ctrlport_probe_psd.block.yml new file mode 100644 index 0000000000..3349f42639 --- /dev/null +++ b/gr-fft/grc/fft_ctrlport_probe_psd.block.yml @@ -0,0 +1,31 @@ +id: fft_ctrlport_probe_psd +label: Ctrlport Probe PSD + +parameters: +- id: name + label: Name + dtype: string + default: psd +- id: desc + label: Description + dtype: string + default: PSD Plot +- id: len + label: Length + dtype: int + default: '1024' + +inputs: +- domain: stream + dtype: complex + +templates: + imports: from gnuradio import fft + make: fft.ctrlport_probe_psd(${name}, ${desc}, ${len}) + callbacks: + - set_length(${len}) + +documentation: |- + Place this in a graph to export PSD values to a GRCP port probe. + +file_format: 1 diff --git a/gr-fft/grc/fft_ctrlport_probe_psd.xml b/gr-fft/grc/fft_ctrlport_probe_psd.xml deleted file mode 100644 index f50144ba92..0000000000 --- a/gr-fft/grc/fft_ctrlport_probe_psd.xml +++ /dev/null @@ -1,63 +0,0 @@ -<?xml version="1.0"?> - -<!-- - Copyright 2012 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. ---> - -<block> - <name>Ctrlport Probe PSD</name> - <key>fft_ctrlport_probe_psd</key> - <import>from gnuradio import fft</import> - <make>fft.ctrlport_probe_psd($name, $desc, $len)</make> - <callback>set_length($len)</callback> - - <param> - <name>Name</name> - <key>name</key> - <value>psd</value> - <type>string</type> - </param> - - <param> - <name>Description</name> - <key>desc</key> - <value>PSD Plot</value> - <type>string</type> - </param> - - <param> - <name>Length</name> - <key>len</key> - <value>1024</value> - <type>int</type> - </param> - - - <sink> - <name>in</name> - <type>complex</type> - </sink> - - <doc> - Place this in a graph to export PSD values to a GRCP port probe. - </doc> - -</block> - diff --git a/gr-fft/grc/fft_fft_vxx.block.yml b/gr-fft/grc/fft_fft_vxx.block.yml new file mode 100644 index 0000000000..33143f688a --- /dev/null +++ b/gr-fft/grc/fft_fft_vxx.block.yml @@ -0,0 +1,60 @@ +id: fft_vxx +label: FFT + +parameters: +- id: type + label: Input Type + dtype: enum + options: [complex, float] + option_attributes: + hide_shift: ['', all] + hide: part +- id: fft_size + label: FFT Size + dtype: int + default: '1024' + hide: ${ 'part' if vlen == 1 else 'none' } +- id: forward + label: Forward/Reverse + dtype: enum + options: ['True', 'False'] + option_labels: [Forward, Reverse] +- id: window + label: Window + dtype: real_vector + default: window.blackmanharris(1024) +- id: shift + label: Shift + dtype: enum + options: ['True', 'False'] + option_labels: ['Yes', 'No'] + hide: ${ type.hide_shift } +- id: nthreads + label: Num. Threads + dtype: int + default: '1' + +inputs: +- domain: stream + dtype: ${ type } + vlen: ${ fft_size } + +outputs: +- domain: stream + dtype: complex + vlen: ${ fft_size } + +templates: + imports: |- + from gnuradio import fft + from gnuradio.fft import window + make: |- + % if type == "complex": + fft.fft_vcc(${fft_size}, ${forward}, ${window}, ${shift}, ${nthreads}) + % else: + fft.fft_vfc(${fft_size}, ${forward}, ${window}, ${nthreads}) + % endif + callbacks: + - set_nthreads(${nthreads}) + +file_format: 1 diff --git a/gr-fft/grc/fft_fft_vxx.xml b/gr-fft/grc/fft_fft_vxx.xml deleted file mode 100644 index 028721fe25..0000000000 --- a/gr-fft/grc/fft_fft_vxx.xml +++ /dev/null @@ -1,88 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##FFT -################################################### - --> -<block> - <name>FFT</name> - <key>fft_vxx</key> - <import>from gnuradio import fft</import> - <import>from gnuradio.fft import window</import> - <make>#if $type() == "complex" -fft.fft_vcc($fft_size, $forward, $window, $shift, $nthreads) -#else -fft.fft_vfc($fft_size, $forward, $window, $nthreads) -#end if</make> - <callback>set_nthreads($nthreads)</callback> - <param> - <name>Input Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Complex</name> - <key>complex</key> - <opt>hide_shift:</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>hide_shift:all</opt> - </option> - </param> - <param> - <name>FFT Size</name> - <key>fft_size</key> - <value>1024</value> - <type>int</type> - </param> - <param> - <name>Forward/Reverse</name> - <key>forward</key> - <type>enum</type> - <option> - <name>Forward</name> - <key>True</key> - </option> - <option> - <name>Reverse</name> - <key>False</key> - </option> - </param> - <param> - <name>Window</name> - <key>window</key> - <value>window.blackmanharris(1024)</value> - <type>real_vector</type> - </param> - <param> - <name>Shift</name> - <key>shift</key> - <type>enum</type> - <hide>$type.hide_shift</hide> - <option> - <name>Yes</name> - <key>True</key> - </option> - <option> - <name>No</name> - <key>False</key> - </option> - </param> - <param> - <name>Num. Threads</name> - <key>nthreads</key> - <value>1</value> - <type>int</type> - </param> - <sink> - <name>in</name> - <type>$type</type> - <vlen>$fft_size</vlen> - </sink> - <source> - <name>out</name> - <type>complex</type> - <vlen>$fft_size</vlen> - </source> -</block> diff --git a/gr-fft/grc/fft_goertzel_fc.block.yml b/gr-fft/grc/fft_goertzel_fc.block.yml new file mode 100644 index 0000000000..6ea74e7f53 --- /dev/null +++ b/gr-fft/grc/fft_goertzel_fc.block.yml @@ -0,0 +1,30 @@ +id: goertzel_fc +label: Goertzel + +parameters: +- id: rate + label: Rate + dtype: int +- id: len + label: Length + dtype: int +- id: freq + label: Frequency + dtype: real + +inputs: +- domain: stream + dtype: float + +outputs: +- domain: stream + dtype: complex + +templates: + imports: from gnuradio import fft + make: fft.goertzel_fc(${rate}, ${len}, ${freq}) + callbacks: + - set_freq(${freq}) + - set_rate(${rate}) + +file_format: 1 diff --git a/gr-fft/grc/fft_goertzel_fc.xml b/gr-fft/grc/fft_goertzel_fc.xml deleted file mode 100644 index 3712843586..0000000000 --- a/gr-fft/grc/fft_goertzel_fc.xml +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Goertzel -################################################### - --> -<block> - <name>Goertzel</name> - <key>goertzel_fc</key> - <import>from gnuradio import fft</import> - <make>fft.goertzel_fc($rate, $len, $freq)</make> - <callback>set_freq($freq)</callback> - <callback>set_rate($rate)</callback> - <param> - <name>Rate</name> - <key>rate</key> - <type>int</type> - </param> - <param> - <name>Length</name> - <key>len</key> - <type>int</type> - </param> - <param> - <name>Frequency</name> - <key>freq</key> - <type>real</type> - </param> - <sink> - <name>in</name> - <type>float</type> - </sink> - <source> - <name>out</name> - <type>complex</type> - </source> -</block> diff --git a/gr-fft/grc/fft_logpwrfft_x.block.yml b/gr-fft/grc/fft_logpwrfft_x.block.yml new file mode 100644 index 0000000000..1046fe81aa --- /dev/null +++ b/gr-fft/grc/fft_logpwrfft_x.block.yml @@ -0,0 +1,59 @@ +id: logpwrfft_x +label: Log Power FFT + +parameters: +- id: type + label: Input Type + dtype: enum + options: [complex, float] + option_attributes: + fcn: [c, f] + hide: part +- id: sample_rate + label: Sample Rate + dtype: real + default: samp_rate +- id: fft_size + label: FFT Size + dtype: int + default: '1024' + hide: ${ 'part' if vlen == 1 else 'none' } +- id: ref_scale + label: Reference Scale + dtype: real + default: '2' +- id: frame_rate + label: Frame Rate + dtype: real + default: '30' +- id: average + label: Average + dtype: bool + default: 'False' + options: ['True', 'False'] + option_labels: ['On', 'Off'] +- id: avg_alpha + label: Average Alpha + dtype: real + default: '1.0' + +inputs: +- domain: stream + dtype: ${ type } + +outputs: +- domain: stream + dtype: float + vlen: ${ fft_size } + +templates: + imports: from gnuradio.fft import logpwrfft + make: "logpwrfft.logpwrfft_${type.fcn}(\n\tsample_rate=${sample_rate},\n\tfft_size=${fft_size},\n\ + \tref_scale=${ref_scale},\n\tframe_rate=${frame_rate},\n\tavg_alpha=${avg_alpha},\n\ + \taverage=${average},\n)" + callbacks: + - set_sample_rate(${sample_rate}) + - set_avg_alpha(${avg_alpha}) + - set_average(${average}) + +file_format: 1 diff --git a/gr-fft/grc/fft_logpwrfft_x.xml b/gr-fft/grc/fft_logpwrfft_x.xml deleted file mode 100644 index ee45b577d8..0000000000 --- a/gr-fft/grc/fft_logpwrfft_x.xml +++ /dev/null @@ -1,90 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Log Power FFT -################################################### - --> -<block> - <name>Log Power FFT</name> - <key>logpwrfft_x</key> - <import>from gnuradio.fft import logpwrfft</import> - <make>logpwrfft.logpwrfft_$(type.fcn)( - sample_rate=$sample_rate, - fft_size=$fft_size, - ref_scale=$ref_scale, - frame_rate=$frame_rate, - avg_alpha=$avg_alpha, - average=$average, -)</make> - <callback>set_sample_rate($sample_rate)</callback> - <callback>set_avg_alpha($avg_alpha)</callback> - <callback>set_average($average)</callback> - <param> - <name>Input Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Complex</name> - <key>complex</key> - <opt>fcn:c</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>fcn:f</opt> - </option> - </param> - <param> - <name>Sample Rate</name> - <key>sample_rate</key> - <value>samp_rate</value> - <type>real</type> - </param> - <param> - <name>FFT Size</name> - <key>fft_size</key> - <value>1024</value> - <type>int</type> - </param> - <param> - <name>Reference Scale</name> - <key>ref_scale</key> - <value>2</value> - <type>real</type> - </param> - <param> - <name>Frame Rate</name> - <key>frame_rate</key> - <value>30</value> - <type>real</type> - </param> - <param> - <name>Average</name> - <key>average</key> - <value>False</value> - <type>bool</type> - <option> - <name>On</name> - <key>True</key> - </option> - <option> - <name>Off</name> - <key>False</key> - </option> - </param> - <param> - <name>Average Alpha</name> - <key>avg_alpha</key> - <value>1.0</value> - <type>real</type> - </param> - <sink> - <name>in</name> - <type>$type</type> - </sink> - <source> - <name>out</name> - <type>float</type> - <vlen>$fft_size</vlen> - </source> -</block> diff --git a/gr-fft/python/fft/CMakeLists.txt b/gr-fft/python/fft/CMakeLists.txt index 016c76d27d..f08aebc11d 100644 --- a/gr-fft/python/fft/CMakeLists.txt +++ b/gr-fft/python/fft/CMakeLists.txt @@ -40,6 +40,6 @@ if(ENABLE_TESTING) file(GLOB py_qa_test_files "qa_*.py") foreach(py_qa_test_file ${py_qa_test_files}) get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) - GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file}) + GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} -B ${py_qa_test_file}) endforeach(py_qa_test_file) endif(ENABLE_TESTING) diff --git a/gr-fft/python/fft/__init__.py b/gr-fft/python/fft/__init__.py index 1864353ed1..2e110f5371 100644 --- a/gr-fft/python/fft/__init__.py +++ b/gr-fft/python/fft/__init__.py @@ -22,11 +22,15 @@ ''' Fourier-transform blocks and related functions. ''' + +from __future__ import absolute_import +from __future__ import unicode_literals + import os try: - from fft_swig import * + from .fft_swig import * except ImportError: dirname, filename = os.path.split(os.path.abspath(__file__)) __path__.append(os.path.join(dirname, "..", "..", "swig")) - from fft_swig import * + from .fft_swig import * diff --git a/gr-fft/python/fft/logpwrfft.py b/gr-fft/python/fft/logpwrfft.py index 1ed9d6cacb..3c568b67e4 100644 --- a/gr-fft/python/fft/logpwrfft.py +++ b/gr-fft/python/fft/logpwrfft.py @@ -1,3 +1,5 @@ +from __future__ import division +from __future__ import unicode_literals # # Copyright 2008 Free Software Foundation, Inc. # @@ -23,8 +25,8 @@ from gnuradio import gr from gnuradio import blocks import sys, math -import fft_swig as fft -from fft_swig import window +from . import fft_swig as fft +from .fft_swig import window try: from gnuradio import filter @@ -63,14 +65,14 @@ class _logpwrfft_base(gr.hier_block2): if win is None: win = window.blackmanharris fft_window = win(fft_size) fft = self._fft_block[0](fft_size, True, fft_window) - window_power = sum(map(lambda x: x*x, fft_window)) + window_power = sum([x*x for x in fft_window]) c2magsq = blocks.complex_to_mag_squared(fft_size) self._avg = filter.single_pole_iir_filter_ff(1.0, fft_size) self._log = blocks.nlog10_ff(10, fft_size, -20*math.log10(fft_size) # Adjust for number of bins - -10*math.log10(float(window_power)/fft_size) # Adjust for windowing loss - -20*math.log10(float(ref_scale)/2)) # Adjust for reference scale + -10*math.log10(float(window_power) / fft_size) # Adjust for windowing loss + -20*math.log10(float(ref_scale) / 2)) # Adjust for reference scale self.connect(self, self._sd, fft, c2magsq, self._avg, self._log, self) self._average = average @@ -173,4 +175,3 @@ class logpwrfft_c(_logpwrfft_base): _name = "logpwrfft_c" _item_size = gr.sizeof_gr_complex _fft_block = (fft.fft_vcc, ) - diff --git a/gr-fft/python/fft/qa_fft.py b/gr-fft/python/fft/qa_fft.py index db3ca7778d..b1c44f2809 100755..100644 --- a/gr-fft/python/fft/qa_fft.py +++ b/gr-fft/python/fft/qa_fft.py @@ -19,6 +19,8 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # +from __future__ import division + from gnuradio import gr, gr_unittest, fft, blocks # Note: Octave code to verify these results: diff --git a/gr-fft/python/fft/qa_goertzel.py b/gr-fft/python/fft/qa_goertzel.py index c2c5c565e7..ebd272cb22 100755..100644 --- a/gr-fft/python/fft/qa_goertzel.py +++ b/gr-fft/python/fft/qa_goertzel.py @@ -20,6 +20,8 @@ # Boston, MA 02110-1301, USA. # +from __future__ import division + from math import pi, cos from gnuradio import gr, gr_unittest, fft, blocks @@ -36,30 +38,30 @@ class test_goertzel(gr_unittest.TestCase): return [cos(2*pi*x*freq/rate) for x in range(rate)] def transform(self, src_data, rate, freq): - src = blocks.vector_source_f(src_data, False) + src = blocks.vector_source_f(src_data, False) dft = fft.goertzel_fc(rate, rate, freq) - dst = blocks.vector_sink_c() - self.tb.connect(src, dft, dst) - self.tb.run() - return dst.data() + dst = blocks.vector_sink_c() + self.tb.connect(src, dft, dst) + self.tb.run() + return dst.data() def test_001(self): # Measure single tone magnitude - rate = 8000 - freq = 100 - bin = freq - src_data = self.make_tone_data(rate, freq) - expected_result = 0.5 - actual_result = abs(self.transform(src_data, rate, bin)[0]) - self.assertAlmostEqual(expected_result, actual_result, places=4) + rate = 8000 + freq = 100 + bin = freq + src_data = self.make_tone_data(rate, freq) + expected_result = 0.5 + actual_result = abs(self.transform(src_data, rate, bin)[0]) + self.assertAlmostEqual(expected_result, actual_result, places=4) def test_002(self): # Measure off frequency magnitude - rate = 8000 - freq = 100 - bin = freq/2 - src_data = self.make_tone_data(rate, freq) - expected_result = 0.0 - actual_result = abs(self.transform(src_data, rate, bin)[0]) - self.assertAlmostEqual(expected_result, actual_result, places=4) + rate = 8000 + freq = 100 + bin = freq / 2 + src_data = self.make_tone_data(rate, freq) + expected_result = 0.0 + actual_result = abs(self.transform(src_data, rate, bin)[0]) + self.assertAlmostEqual(expected_result, actual_result, places=4) if __name__ == '__main__': gr_unittest.run(test_goertzel, "test_goertzel.xml") |