Article View: comp.dsp
Article #480Re: Looking for 2D FFT code...
From: Malcolm Slaney
Date: Wed, 25 Oct 1989 23:17
Date: Wed, 25 Oct 1989 23:17
54 lines
2437 bytes
2437 bytes
In article <2576@uceng.UC.EDU> mfinegan@uceng.UC.EDU (michael k finegan) writes:
>>Try "Numerical Recipies in C" page 467 for the complete code.
>But don't plan to compile it on a 16 bit machine, and don't mind
>wasting M+N elements of your N+1 by M+1 array ... Anyone actually
>translate all the indices from 1 <= j <= N, to 0 <= j < N ?
No, Numerical Recipies does not waste elements in the array. The vector
and the matrix routines all allocate arrays where the first element is
indexed by 1, just like Fortran. They do this by carefully subtracting
an offset (generally 1) from the value returned by malloc. Then the user
(the 2d fft routine, for example) can do things just like Fortran. See
the vector() and matrix() routines described in the appendix.
If you are going to complain about wasted space you should talk about the
double indirection they do for all two dimensional arrays. But, this is a
pretty good way to get around the inability to dimension two dimensional
arrays at run time in C but it does cost N elements of storage.
All in all I recommend the Numerical Recipies book. I wish I had the book
back when I was doing my thesis.
Malcolm
/* nrl is number of rows (low index)
nrh is number of rows (high index), etc.
*/
float **matrix(nrl, nrh, ncl, nch)
int nrl, nrh, ncl, nch;
{
int i;
float **m;
m = (float **)malloc((unsigned int) (nch-ncl+1)*sizeof(float *));
if (!m) nrerror("Allocation failure in matrix()");
m -= nrl;
for (i=nrl;i<=nrh;i++) {
m[i] = (float *) malloc((unsigned) (nch-ncl+1)*sizeof(float));
if (!m[i]) nrerror("Allocation failure in matrix()");
m[i] -= ncl;
}
return m;
}
void free_matrix(m, nrl, nrh, ncl, nch)
float **m;
int nrl, nrh, ncl, nch;
{
int i;
for (i=nrh;i>=nrl;i--) free((char *) (m[i] + ncl));
free((char *) (m+nrl));
}
Technical Details
Message-ID:
<35926@apple.Apple.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!apple!malcolmReferences:
<5047@orca.WV.TEK.COM> <9520008@hpsad.HP.COM> <2576@uceng.UC.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!apple!malcolm From: malcolm@Apple.COM (Malcolm Slaney) Newsgroups: comp.dsp Subject: Re: Looking for 2D FFT code... Message-ID: <35926@apple.Apple.COM> Date: 25 Oct 89 23:17:05 GMT References: <5047@orca.WV.TEK.COM> <9520008@hpsad.HP.COM> <2576@uceng.UC.EDU> Organization: Apple Computer Inc, Cupertino, CA Lines: 54