Hi I'm new around here, I've been working on a project on Qt and I'm mostly selftaught and also I'm no master of c++ whatsoever
Well I am stuck with a problem and I haven't been able to understand it. I am working on a c++ class that will be part of the Qt project, I'm using the fftw3 header so here is my code:
.h

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#ifndef FFT_H
#define FFT_H
#include <QObject>
#include <QTimer>
#include <QVector>
class fft : public QObject
{
public:
fft();
void changeindx();
void estimule();
void Nestimule();
void dofft();
QTimer *twosec;
QVector <double> *select;
public slots:
void timeout();
};
#endif // FFT_H

.cpp

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#include "fft.h"
#include "complex.h"
#include "math.h"
#include <fftw3.h>
#include <QTimer>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
int indx, N;
double a, noise;
fftw_complex *in, *out;
fftw_plan p;
fft::fft()
{
N = 256;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_MEASURE);
twosec = new QTimer(this);
twosec>start(2000);
QObject::connect(twosec,SIGNAL(timeout()),this,SLOT(timeout()));
}

when a timeout happens it calls this part:

Source code

1
2
3
4
5
6
7
8
9

void fft::estimule()
{
for (int i = 0; i < N; ++i) {
a = (1/128) * i;
noise = (2*static_cast<double>(rand())/static_cast<double>(RAND_MAX))1;
in[i][0] = 6*sin(2*M_PI*7*a) + 3*sin(2*M_PI*14*a) + 2*sin(2*M_PI*3*a) + sin(2*M_PI*60*a) + noise;
in[i][1] = 0.0;
}
}

I get the following error at lines 6 and 7 of the second part of the code:
error: invalid types ‘double __complex__[int]’ for array subscript
I don't understand what's wrong...
Thanks!