Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8842731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:02:13+00:00 2026-06-14T11:02:13+00:00

I got this example code for 1D Deconvolution from http://rosettacode.org/wiki/Deconvolution/1D#C , and it doesn’t

  • 0

I got this example code for 1D Deconvolution from http://rosettacode.org/wiki/Deconvolution/1D#C, and it doesn’t seem to work right. When trying to build this project, I am first getting this error, ‘_fft’ : illegal use of type ‘void’. If it helps, this code was initially meant for C, and I had to make some changes like changing the include from complex.h to complex, and using namespace std. Thanks for the help

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <complex>
using namespace std;

double PI;
complex<double> cplx;




void _fft(cplx buf[], cplx out[], int n, int step)
 {
if (step < n) {
    _fft(out, buf, n, step * 2);
    _fft(out + step, buf + step, n, step * 2);

    for (int i = 0; i < n; i += 2 * step) {
        cplx t = cexp(-I * PI * i / n) * out[i + step];
        buf[i / 2]     = out[i] + t;
        buf[(i + n)/2] = out[i] - t;
    }
}
}

void fft(cplx buf[], int n)
{
cplx out[n];
for (int i = 0; i < n; i++) out[i] = buf[i];
_fft(buf, out, n, 1);
}

cplx *pad_two(double g[], int len, int *ns)
{
int n = 1;
if (*ns) n = *ns;
else while (n < len) n *= 2;

cplx *buf = calloc(sizeof(cplx), n);
for (int i = 0; i < len; i++) buf[i] = g[i];
*ns = n;
return buf;
}

void deconv(double g[], int lg, double f[], int lf, double out[]) {
int ns = 0;
cplx *g2 = pad_two(g, lg, &ns);
cplx *f2 = pad_two(f, lf, &ns);

fft(g2, ns);
fft(f2, ns);

cplx h[ns];
for (int i = 0; i < ns; i++) h[i] = g2[i] / f2[i];
fft(h, ns);

for (int i = 0; i >= lf - lg; i--)
    out[-i] = h[(i + ns) % ns]/32;
free(g2);
free(f2);
}

int main()
{
PI = atan2(1,1) * 4;
double g[] = {24,75,71,-34,3,22,-45,23,245,25,52,25,-67,-96,96,31,55,36,29,-43,-7};
double f[] = { -3,-6,-1,8,-6,3,-1,-9,-9,3,-2,5,2,-2,-7,-1 };
double h[] = { -8,-9,-3,-1,-6,7 };

int lg = sizeof(g)/sizeof(double);
int lf = sizeof(f)/sizeof(double);
int lh = sizeof(h)/sizeof(double);

double h2[lh];
double f2[lf];

printf("f[] data is : ");
for (int i = 0; i < lf; i++) printf(" %g", f[i]);
printf("\n");

printf("deconv(g, h): ");
deconv(g, lg, h, lh, f2);
for (int i = 0; i < lf; i++) printf(" %g", f2[i]);
printf("\n");

printf("h[] data is : ");
for (int i = 0; i < lh; i++) printf(" %g", h[i]);
printf("\n");

printf("deconv(g, f): ");
deconv(g, lg, f, lf, h2);
for (int i = 0; i < lh; i++) printf(" %g", h2[i]);
printf("\n");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:02:14+00:00Added an answer on June 14, 2026 at 11:02 am

    Without running this, cplx is being used as a class, when it is actually a variable. Can you change this line:

    complex<double> cplx;
    

    like this

    typedef complex<double> cplx;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've placed panel from this example http://docs.sencha.com/ext-js/4-0/#!/example/dd/dnd_grid_to_grid.html to Ext.window.Window and got an issue: proxy
thank you for looking i got this example from my book but i cant
This is an example code from a book. I assume it's for Ruby 1.8.
I got this error when I ran my very first spring example code. It
I got this example from one StackOverflow question that was asked but I couldn't
Previously I asked this question and got back this BeautifulSoup example code, which after
I got this example demonstrating AJAX from Stoyan Stefanovs Object Oriented JavaScript at page
So far i got this code: function toplist() {$sql = SELECT * FROM list
I've got this piece of code to toggle a side panel: $(.example_wrapper_panel_link).click(function() { $(.example_wrapper).addClass('example_wrapper_active');
GridView CurrentGrid =Grd_UserList; Grd_UserList.Columns.Clear(); ı have got this example, ı use Columns.Clear(); fonc. with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.