普通网友 2015-08-10 08:24 采纳率: 66.7%
浏览 2648
已采纳

c++ 利用fftw做傅里叶变换报错 linux系统下运行

报错信息 fftw: alloc.c:269: assertion failed: p

#include <fftw3.h>

namespace gr {
  namespace howto {


    peak_extract::sptr
    peak_extract::make(int upper_limit,int lower_limit,int samp_rate,bool boolean_timer)
    {
      return gnuradio::get_initial_sptr
        (new peak_extract_impl(upper_limit,lower_limit,samp_rate,boolean_timer));
    }

    /*
     * The private constructor
     */
    peak_extract_impl::peak_extract_impl(int upper_limit,int lower_limit,int samp_rate,bool boolean_timer)
      : gr::block("peak_extract",
              gr::io_signature::make(1, 1, sizeof(gr_complex)),
              gr::io_signature::make(1, 1, sizeof(int))),
          d_upper_limit(upper_limit),
          d_lower_limit(lower_limit),
              d_samp_rate(samp_rate),
          d_boolean_timer(boolean_timer),
          d_packet_len(packet_len),
          d_buffer((fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex)*d_packet_len)),           
          d_fft_plan(fftwf_plan_dft_1d(d_packet_len, d_buffer, d_buffer, FFTW_FORWARD, FFTW_ESTIMATE))

    {}

    /*
     * Our virtual destructor.
     */
    peak_extract_impl::~peak_extract_impl()
    {
    fftwf_destroy_plan(d_fft_plan);
    fftwf_free(d_buffer);
    }

    void
    peak_extract_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
    {
        /* <+forecast+> e.g. ninput_items_required[0] = noutput_items */
        ninput_items_required[0] = noutput_items;
    }

    int
    peak_extract_impl::general_work (int noutput_items,
                       gr_vector_int &ninput_items,
                       gr_vector_const_void_star &input_items,
                       gr_vector_void_star &output_items)
    {
        const gr_complex *in = (const gr_complex *) input_items[0];
        int *out = (int *) output_items[0];

    memcpy(d_buffer,in,d_packet_len*sizeof(fftwf_complex));
    fftwf_execute(d_fft_plan);
    int i,index,N;
        N=d_packet_len;
    //M=sizeof(in) / sizeof(in[0]);
    double max,magnitude[N];
    double real[N],imag[N];


    for(i=0;i<d_packet_len;i++)
    {
        real[i]=d_buffer[i][0];
        imag[i]=d_buffer[i][1];
        magnitude[i]=sqrt((real[i]*real[i])+(imag[i]*imag[i]));
    }


        max=magnitude[0];
        for (i=0;i<d_packet_len;i++)
        {
            if(magnitude[i]>max)
                {
                   max=magnitude[i];
                   index=i;
                }
        }

         *out=index*d_samp_rate/d_packet_len;

        // Do <+signal processing+>
        // 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;
    }

  } /* namespace howto */
} /* namespace gr */


  • 写回答

3条回答 默认 最新

  • 普通网友 2015-08-11 05:38
    关注

    分配空间的问题。。。发现只要去掉FFTblock就可以了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler