2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -27,23 +27,24 @@ void fft(cplx buf[], int n)
|
|||
_fft(buf, out, n, 1);
|
||||
}
|
||||
|
||||
|
||||
void show(const char * s, cplx buf[]) {
|
||||
printf("%s", s);
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (!cimag(buf[i]))
|
||||
printf("%g ", creal(buf[i]));
|
||||
else
|
||||
printf("(%g, %g) ", creal(buf[i]), cimag(buf[i]));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
PI = atan2(1, 1) * 4;
|
||||
cplx buf[] = {1, 1, 1, 1, 0, 0, 0, 0};
|
||||
|
||||
void show(const char * s) {
|
||||
printf("%s", s);
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (!cimag(buf[i]))
|
||||
printf("%g ", creal(buf[i]));
|
||||
else
|
||||
printf("(%g, %g) ", creal(buf[i]), cimag(buf[i]));
|
||||
}
|
||||
|
||||
show("Data: ");
|
||||
show("Data: ", buf);
|
||||
fft(buf, 8);
|
||||
show("\nFFT : ");
|
||||
show("\nFFT : ", buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,41 @@
|
|||
Data: 1 1 1 1 0 0 0 0
|
||||
FFT : 4 (1, -2.41421) 0 (1, -0.414214) 0 (1, 0.414214) 0 (1, 2.41421)
|
||||
#include <stdio.h>
|
||||
#include <Accelerate/Accelerate.h>
|
||||
|
||||
void fft(DSPComplex buf[], int n) {
|
||||
float inputMemory[2*n];
|
||||
float outputMemory[2*n];
|
||||
// half for real and half for complex
|
||||
DSPSplitComplex inputSplit = {inputMemory, inputMemory + n};
|
||||
DSPSplitComplex outputSplit = {outputMemory, outputMemory + n};
|
||||
|
||||
vDSP_ctoz(buf, 2, &inputSplit, 1, n);
|
||||
|
||||
vDSP_DFT_Setup setup = vDSP_DFT_zop_CreateSetup(NULL, n, vDSP_DFT_FORWARD);
|
||||
|
||||
vDSP_DFT_Execute(setup,
|
||||
inputSplit.realp, inputSplit.imagp,
|
||||
outputSplit.realp, outputSplit.imagp);
|
||||
|
||||
vDSP_ztoc(&outputSplit, 1, buf, 2, n);
|
||||
}
|
||||
|
||||
|
||||
void show(const char *s, DSPComplex buf[], int n) {
|
||||
printf("%s", s);
|
||||
for (int i = 0; i < n; i++)
|
||||
if (!buf[i].imag)
|
||||
printf("%g ", buf[i].real);
|
||||
else
|
||||
printf("(%g, %g) ", buf[i].real, buf[i].imag);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main() {
|
||||
DSPComplex buf[] = {{1,0}, {1,0}, {1,0}, {1,0}, {0,0}, {0,0}, {0,0}, {0,0}};
|
||||
|
||||
show("Data: ", buf, 8);
|
||||
fft(buf, 8);
|
||||
show("FFT : ", buf, 8);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
double PI;
|
||||
typedef double complex 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);
|
||||
}
|
||||
|
||||
|
||||
void show(const char * s, cplx buf[]) {
|
||||
printf("%s", s);
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (!cimag(buf[i]))
|
||||
printf("%g ", creal(buf[i]));
|
||||
else
|
||||
printf("(%g, %g) ", creal(buf[i]), cimag(buf[i]));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
PI = atan2(1, 1) * 4;
|
||||
cplx buf[] = {1, 1, 1, 1, 0, 0, 0, 0};
|
||||
|
||||
show("Data: ", buf);
|
||||
fft(buf, 8);
|
||||
show("\nFFT : ", buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue