gr-fosphor: Allow to select custom FFT window from the gr::fft:window list

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
Sylvain Munaut 2013-11-10 15:11:49 +01:00
parent ce907419c7
commit fd3d6cf77d
8 changed files with 131 additions and 2 deletions

View File

@ -120,7 +120,7 @@ endif (QT_FOUND)
########################################################################
# Find gnuradio build dependencies
########################################################################
set(GR_REQUIRED_COMPONENTS RUNTIME)
set(GR_REQUIRED_COMPONENTS RUNTIME FFT)
find_package(Gnuradio 3.7 REQUIRED)
find_package(CppUnit)

View File

@ -4,10 +4,44 @@
<key>fosphor_glfw_sink_c</key>
<category>Instrumentation</category>
<import>from gnuradio import fosphor</import>
<import>from gnuradio.fft import window</import>
<make>fosphor.glfw_sink_c()
self.$(id).set_fft_window($wintype)
self.$(id).set_frequency_range($freq_center, $freq_span)
</make>
<callback>set_fft_window($wintype)</callback>
<callback>set_frequency_range($freq_center, $freq_span)</callback>
<param>
<name>Window Type</name>
<key>wintype</key>
<value>window.WIN_BLACKMAN_hARRIS</value>
<type>int</type>
<hide>part</hide>
<option>
<name>Blackman-harris</name>
<key>window.WIN_BLACKMAN_hARRIS</key>
</option>
<option>
<name>Hamming</name>
<key>window.WIN_HAMMING</key>
</option>
<option>
<name>Hann</name>
<key>window.WIN_HANN</key>
</option>
<option>
<name>Blackman</name>
<key>window.WIN_BLACKMAN</key>
</option>
<option>
<name>Rectangular</name>
<key>window.WIN_RECTANGULAR</key>
</option>
<option>
<name>Kaiser</name>
<key>window.WIN_KAISER</key>
</option>
</param>
<param>
<name>Center Frequency (Hz)</name>
<key>freq_center</key>

View File

@ -6,12 +6,46 @@
<import>from PyQt4 import Qt</import>
<import>import sip</import>
<import>from gnuradio import fosphor</import>
<import>from gnuradio.fft import window</import>
<make>#set $win = 'self._%s_win'%$id
fosphor.qt_sink_c()
self.$(id).set_fft_window($wintype)
self.$(id).set_frequency_range($freq_center, $freq_span)
self._$(id)_win = sip.wrapinstance(self.$(id).pyqwidget(), Qt.QWidget)
$(gui_hint()($win))</make>
<callback>set_fft_window($wintype)</callback>
<callback>set_frequency_range($freq_center, $freq_span)</callback>
<param>
<name>Window Type</name>
<key>wintype</key>
<value>window.WIN_BLACKMAN_hARRIS</value>
<type>int</type>
<hide>part</hide>
<option>
<name>Blackman-harris</name>
<key>window.WIN_BLACKMAN_hARRIS</key>
</option>
<option>
<name>Hamming</name>
<key>window.WIN_HAMMING</key>
</option>
<option>
<name>Hann</name>
<key>window.WIN_HANN</key>
</option>
<option>
<name>Blackman</name>
<key>window.WIN_BLACKMAN</key>
</option>
<option>
<name>Rectangular</name>
<key>window.WIN_RECTANGULAR</key>
</option>
<option>
<name>Kaiser</name>
<key>window.WIN_KAISER</key>
</option>
</param>
<param>
<name>Center Frequency (Hz)</name>
<key>freq_center</key>

View File

@ -4,6 +4,7 @@
<key>fosphor_wx_sink_c</key>
<category>Instrumentation/WX</category>
<import>from gnuradio import fosphor</import>
<import>from gnuradio.fft import window</import>
<make>#set $parent = $notebook() and 'self.%s.GetPage(%s)'%$notebook() or 'self'
fosphor.wx_sink_c(
$(parent).GetWin()
@ -11,13 +12,46 @@ fosphor.wx_sink_c(
size=$win_size,
#end if
)
self.$(id).set_fft_window($wintype)
self.$(id).set_frequency_range($freq_center, $freq_span)
#if not $grid_pos()
$(parent).Add(self.$(id).win)
#else
$(parent).GridAdd(self.$(id).win, $(', '.join(map(str, $grid_pos()))))
#end if</make>
<callback>set_fft_window($wintype)</callback>
<callback>set_frequency_range($freq_center, $freq_span)</callback>
<param>
<name>Window Type</name>
<key>wintype</key>
<value>window.WIN_BLACKMAN_hARRIS</value>
<type>int</type>
<hide>part</hide>
<option>
<name>Blackman-harris</name>
<key>window.WIN_BLACKMAN_hARRIS</key>
</option>
<option>
<name>Hamming</name>
<key>window.WIN_HAMMING</key>
</option>
<option>
<name>Hann</name>
<key>window.WIN_HANN</key>
</option>
<option>
<name>Blackman</name>
<key>window.WIN_BLACKMAN</key>
</option>
<option>
<name>Rectangular</name>
<key>window.WIN_RECTANGULAR</key>
</option>
<option>
<name>Kaiser</name>
<key>window.WIN_KAISER</key>
</option>
</param>
<param>
<name>Center Frequency (Hz)</name>
<key>freq_center</key>

View File

@ -25,6 +25,7 @@
#include <gnuradio/fosphor/api.h>
#include <gnuradio/sync_block.h>
#include <gnuradio/fft/window.h>
namespace gr {
namespace fosphor {
@ -53,6 +54,8 @@ namespace gr {
const double span) = 0;
virtual void set_frequency_center(const double center) = 0;
virtual void set_frequency_span(const double span) = 0;
virtual void set_fft_window(const gr::fft::window::win_type win) = 0;
};
} // namespace fosphor

View File

@ -54,7 +54,7 @@ const int base_sink_c_impl::k_db_per_div[] = {1, 2, 5, 10, 20};
base_sink_c_impl::base_sink_c_impl()
: d_db_ref(0), d_db_per_div_idx(3), d_active(false),
d_frequency()
d_frequency(), d_fft_window(gr::fft::window::WIN_BLACKMAN_hARRIS)
{
/* Init FIFO */
this->d_fifo = new fifo(2 * 1024 * 1024);
@ -198,6 +198,12 @@ base_sink_c_impl::settings_apply(uint32_t settings)
this->d_frequency.span
);
}
if (settings & SETTING_FFT_WINDOW) {
std::vector<float> window =
gr::fft::window::build(this->d_fft_window, 1024, 6.76);
fosphor_set_fft_window(this->d_fosphor, window.data());
}
}
@ -258,6 +264,16 @@ base_sink_c_impl::set_frequency_span(const double span)
this->settings_mark_changed(SETTING_FREQUENCY_RANGE);
}
void
base_sink_c_impl::set_fft_window(const gr::fft::window::win_type win)
{
if (win == this->d_fft_window) /* Reloading FFT window takes time */
return; /* avoid doing it if possible */
this->d_fft_window = win;
this->settings_mark_changed(SETTING_FFT_WINDOW);
}
int
base_sink_c_impl::work(

View File

@ -61,6 +61,7 @@ namespace gr {
SETTING_DIMENSIONS = (1 << 0),
SETTING_POWER_RANGE = (1 << 1),
SETTING_FREQUENCY_RANGE = (1 << 2),
SETTING_FFT_WINDOW = (1 << 3),
};
uint32_t d_settings_changed;
@ -83,6 +84,8 @@ namespace gr {
double span;
} d_frequency;
gr::fft::window::win_type d_fft_window;
protected:
base_sink_c_impl();
@ -106,6 +109,8 @@ namespace gr {
void set_frequency_center(const double center);
void set_frequency_span(const double span);
void set_fft_window(const gr::fft::window::win_type win);
/* gr::sync_block implementation */
int work (int noutput_items,
gr_vector_const_void_star &input_items,

View File

@ -13,6 +13,9 @@
#include "gnuradio/fosphor/wx_core_sink_c.h"
%}
%typemap(in) gr::fft::window::win_type {
$1 = (gr::fft::window::win_type)(PyInt_AsLong($input));
}
%include "gnuradio/fosphor/base_sink_c.h"