Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -*- c++ -*- */
- /*
- * Copyright 2014 Carlos Alberto Ruiz Naranjo,
- * Center for Advanced Aerospace Technologies (CATEC).
- *
- * 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 "fractional_delay_impl.h"
- #include <math.h>
- #include <gnuradio/blocks/complex_to_float.h>
- namespace gr {
- namespace howto {
- fractional_delay::sptr
- fractional_delay::make(float delay)
- {
- return gnuradio::get_initial_sptr
- (new fractional_delay_impl(delay));
- }
- /*
- * The private constructor
- */
- fractional_delay_impl::fractional_delay_impl(float delay)
- : gr::block("fractional_delay",
- gr::io_signature::make(2,2, sizeof(float)),
- gr::io_signature::make(2,2, sizeof(float)))
- {
- this->delay=delay;
- k=0;
- }
- /*
- * Our virtual destructor.
- */
- fractional_delay_impl::~fractional_delay_impl()
- {
- }
- void
- fractional_delay_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
- {
- ninput_items_required[0] = noutput_items;
- ninput_items_required[1] = noutput_items;
- }
- int
- fractional_delay_impl::general_work (int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
- {
- int fft_length = 1024*10;
- const float *in_real = (const float *) input_items[0];
- const float *in_img = (const float *) input_items[1];
- float *out_real = (float *) output_items[0];
- float *out_img = (float *) output_items[1];
- for(int i=0;i<noutput_items;++i){
- //float argumento = ( (2*M_PI/fft_length)*delay*k );
- //out_real[i] = in_real[i]*cos(argumento) + in_img[i]*sin(argumento);
- //out_img[i] = -in_real[i]*sin(argumento) + in_img[i]*cos(argumento);
- if(k==0){
- out_real[i] = in_real[i];
- out_img[i] = in_img[i];
- }
- else if( (k>0) && (k<(fft_length/2)) ){
- float argumento = ( (2*M_PI/fft_length)*delay*k );
- out_real[i] = in_real[i]*cos(argumento) + in_img[i]*sin(argumento);
- out_img[i] = -in_real[i]*sin(argumento) + in_img[i]*cos(argumento);
- }
- else if(k==fft_length/2){
- out_real[i] = in_real[i]*cos(M_PI*delay);
- out_img[i] = in_img[i]*cos(M_PI*delay);
- }
- else if(k>(fft_length/2) ){
- float argumento = ( (2*M_PI/fft_length)*delay*(fft_length-k) );
- out_real[i] = in_real[i]*cos(argumento) - in_img[i]*sin(argumento);
- out_img[i] = in_real[i]*sin(argumento) + in_img[i]*cos(argumento);
- }
- ++k;
- if(k==fft_length){
- k=0;
- }
- }
- // Tell runtime system how many input items we consumed on
- // each input stream.
- consume_each (noutput_items);
- // Tell runtime system how many output items we produced.
- return noutput_items;
- }
- void fractional_delay_impl::set_delay(float delay)
- {
- this->delay=delay;
- }
- } /* namespace howto */
- } /* namespace gr */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement