- added jay_add and jay_peak_detect
git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@431 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
/* -*- c++ -*- */
|
||||
/*
|
||||
* Copyright 2019 Jay Arrowfield.
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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 this software; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include "peak_detect_impl.h"
|
||||
|
||||
namespace gr {
|
||||
namespace jay {
|
||||
|
||||
peak_detect::sptr
|
||||
peak_detect::make(float alpha_s, float alpha_m, int vlen)
|
||||
{
|
||||
return gnuradio::get_initial_sptr
|
||||
(new peak_detect_impl(alpha_s, alpha_m, vlen));
|
||||
}
|
||||
|
||||
/*
|
||||
* The private constructor
|
||||
*/
|
||||
peak_detect_impl::peak_detect_impl(float alpha_s, float alpha_m, int vlen)
|
||||
: gr::sync_block("peak_detect"
|
||||
, gr::io_signature::make(1, 1, vlen*sizeof(float))
|
||||
, gr::io_signature::make(1, 1, vlen*sizeof(float)))
|
||||
, m_alpha_s (alpha_s)
|
||||
, m_alpha_m(alpha_m)
|
||||
, m_vlen(vlen)
|
||||
{
|
||||
m_pPeakCount = new int[vlen];
|
||||
m_pXs = new float[vlen];
|
||||
m_pXm = new float[vlen];
|
||||
|
||||
memset(m_pPeakCount, 0, vlen*sizeof(int));
|
||||
memset(m_pXs, 0, vlen*sizeof(float));
|
||||
memset(m_pXm, 0, vlen*sizeof(float));
|
||||
}
|
||||
|
||||
/*
|
||||
* Our virtual destructor.
|
||||
*/
|
||||
peak_detect_impl::~peak_detect_impl()
|
||||
{
|
||||
delete [] m_pXm;
|
||||
delete [] m_pXs;
|
||||
delete [] m_pPeakCount;
|
||||
}
|
||||
|
||||
int
|
||||
peak_detect_impl::work(int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items)
|
||||
{
|
||||
int k=0;
|
||||
fprintf(stderr, "Peak at");
|
||||
for(int i = 0; i < (noutput_items * m_vlen); i++)
|
||||
{
|
||||
float x = ((float*)input_items[k])[i];
|
||||
m_pXs[i] = (1.f-m_alpha_s)*m_pXs[i] + m_alpha_s*x;
|
||||
int gate = (int)(m_pXs[i] > (10+m_pXm[i]));
|
||||
m_pPeakCount[i] = gate*m_pPeakCount[i] + gate;
|
||||
float peak = (float)(m_pPeakCount[i] > 1);
|
||||
|
||||
m_pXm[i] = (1.f-peak)*((1.f-m_alpha_m)*m_pXm[i] + m_alpha_m*x) + peak*m_pXm[i];
|
||||
|
||||
((float*)output_items[k])[i] = m_pXm[i];
|
||||
|
||||
if (peak > 0.5)
|
||||
{
|
||||
fprintf(stderr, " %d", i);
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
// Tell runtime system how many output items we produced.
|
||||
return noutput_items;
|
||||
}
|
||||
|
||||
} /* namespace jay */
|
||||
} /* namespace gr */
|
||||
|
||||
Reference in New Issue
Block a user