Array of Array Initialisation

O

Olaf P.

Hi,

I'm writing an FIR filter. The coeffs for low/high/band pass and band
stop (LP,HP,BP,BS) are calculated by matlab and exported as header, e.g.

const int LP_SZ = 33;
const real64_T LP_H[33] = { ... };

const int HP_SZ = 33;
const real64_T HP_H[33] = { ... };

const int BP_SZ = 33;
const real64_T BP_H[33] = { ... };

const int BS_SZ = 33;
const real64_T BS_H[33] = { ... };

Now I want to initialize a new array like:

const real64_T H[4][33] = { LP_H, HP_H, BP_H, BS_H };

which doesn't compile; The error is

fir.h:29: error: initializer element is not constant
fir.h:29: error: (near initialization for `H[0]')

How can I get this to compile, is there a way? Writing

const real64_T H[4][33] = { {...}, {...}, {...}, {...} };

would work, but by change some parameters for FIR filter coeffs I have
to copy & paste it each time again.

The goal ist to use the filter coeffs e.g. in the manner of

int filter_type = 0; // aka LP
filter_fir(H[filter_type], ...);

Thanks
Olaf
 
C

Christopher Benson-Manica

Olaf P. said:
const real64_T H[4][33] = { LP_H, HP_H, BP_H, BS_H };
which doesn't compile; The error is
fir.h:29: error: initializer element is not constant

Right; "const" isn't good enough here. Depending on what you need to
do, the following may be what you want:

const real64_T *H[4] = { LP_H, HP_H, BP_H, BS_H };
 
D

Duncan Muirhead

Hi,

I'm writing an FIR filter. The coeffs for low/high/band pass and band
stop (LP,HP,BP,BS) are calculated by matlab and exported as header, e.g.

const int LP_SZ = 33;
const real64_T LP_H[33] = { ... };
Now I want to initialize a new array like:

const real64_T H[4][33] = { LP_H, HP_H, BP_H, BS_H };
How about
const real64_T* H[4] = { LP_H, HP_H, BP_H, BS_H };
(a 4 element array of pointers)

If you had
void filter( const real64_T* coeff, real64_T x);
you could call it like
filter( H[0], x);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top