Permalink
Browse files

Fixed some symbolic links. Made FFTs take a max frequency parameter.

  • Loading branch information...
1 parent a249e6e commit b641f87e1e510ac06d5a1dfdd354b0b37bd51355 @xuancongwen committed Jul 26, 2010
Showing with 16 additions and 366 deletions.
  1. +3 −3 Makefile
  2. +0 −91 xscomplex.m
  3. +1 −0 xscomplex.m
  4. +9 −9 xsfft.c
  5. +2 −2 xsfft.h
  6. +0 −261 xsfft.m
  7. +1 −0 xsfft.m
  8. BIN xsfftdemo
  9. BIN xsunittests
View
@@ -1,8 +1,8 @@
all: xscomplex.c xsfft.c xsfftdemo.c
- gcc -O xscomplex.c xsfft.c xsfftdemo.c -o xsfftdemo
+ gcc -O -std=c99 xscomplex.c xsfft.c xsfftdemo.c -o xsfftdemo
tests: xscomplex.c xsfft.c xsunittests.c
- gcc -O xscomplex.c xsfft.c xsunittests.c -o xsunittests
+ gcc -O -std=c99 xscomplex.c xsfft.c xsunittests.c -o xsunittests
clean:
- rm xsfftdemo
+ rm xsfftdemo xsunittests
View
@@ -1,91 +0,0 @@
-#include <math.h>
-#include "xscomplex.h"
-
-// Initialization
-
-xsComplex xsComplexCreate()
-{
- return xsComplexFromComponents(0.0, 0.0);
-}
-
-xsComplex xsComplexFromComponents(const double real, const double imaginary)
-{
- xsComplex newComplex;
- newComplex.real = real;
- newComplex.imaginary = imaginary;
- return newComplex;
-}
-
-xsComplex xsComplexFromReal(const double real)
-{
- return xsComplexFromComponents(real, 0.0);
-}
-
-xsComplex xsComplexFromImaginary(const double imaginary)
-{
- return xsComplexFromComponents(0.0, imaginary);
-}
-
-xsComplex xsComplexFromPolar(const double r, const double theta)
-{
- return xsComplexFromComponents(r * cos(theta), r * sin(theta));
-}
-
-xsComplex xsComplexFromComplex(const xsComplex complex)
-{
- return xsComplexFromComponents(complex.real, complex.imaginary);
-}
-
-// Comparison
-
-int xsComplexEqual(const xsComplex lhs, const xsComplex rhs)
-{
- return lhs.real == rhs.real && lhs.imaginary == rhs.imaginary;
-}
-
-// Computed Values
-
-xsComplex xsComplexConjugate(const xsComplex complex)
-{
- return xsComplexFromComponents(complex.real, -complex.imaginary);
-}
-
-double xsComplexNorm(const xsComplex complex)
-{
- return complex.real * complex.real + complex.imaginary * complex.imaginary;
-}
-
-double xsComplexMagnitude(const xsComplex complex)
-{
- return sqrt(xsComplexNorm(complex));
-}
-
-xsComplex xsComplexScale(xsComplex complex, const double scaleFactor)
-{
- return xsComplexFromComponents(complex.real * scaleFactor, complex.imaginary * scaleFactor);
-}
-
-// Commutative operations
-
-xsComplex xsComplexSum(const xsComplex lhs, const xsComplex rhs)
-{
- return xsComplexFromComponents(lhs.real + rhs.real, lhs.imaginary + rhs.imaginary);
-}
-
-xsComplex xsComplexProduct(const xsComplex lhs, const xsComplex rhs)
-{
- return xsComplexFromComponents(lhs.real * rhs.real - lhs.imaginary * rhs.imaginary, lhs.real * rhs.imaginary + lhs.imaginary * rhs.real);
-}
-
-// Non-Commutative operations
-
-xsComplex xsComplexDifference(const xsComplex minuend, const xsComplex subtrahend)
-{
- return xsComplexFromComponents(minuend.real - subtrahend.real, minuend.imaginary - subtrahend.imaginary);
-}
-
-xsComplex xsComplexQuotient(const xsComplex dividend, const xsComplex divisor)
-{
- const double denominator = divisor.real * divisor.real + divisor.imaginary * divisor.imaginary;
- return xsComplexFromComponents((dividend.real * divisor.real + dividend.imaginary * divisor.imaginary) / denominator, (dividend.imaginary * divisor.real - dividend.real * divisor.imaginary) / denominator);
-}
View
View
18 xsfft.c
@@ -5,7 +5,7 @@
// Private functions
void _xsFormatInput(xsComplex *data, const unsigned long dataLength);
-void _xsTransformHelper(xsComplex *data, const unsigned long dataLength, const double signedPI);
+void _xsTransformHelper(xsComplex *data, const unsigned long dataLength, const double signedPI, const unsigned long maxFrequency);
void _xsScaleIFFT(xsComplex *data, const unsigned long dataLength);
xsComplex *_xsReverseCopy(xsComplex *data, const unsigned long dataLength);
@@ -125,26 +125,26 @@ xsComplex *xsCoerceDataRadix2(xsComplex *data, unsigned long *dataLength)
return data;
}
-int xsFFT(xsComplex *data, const unsigned long dataLength)
+int xsFFT(xsComplex *data, const unsigned long dataLength, const unsigned long maxFrequency)
{
if (!data || dataLength < 1 || dataLength & (dataLength - 1)) {
return 0;
}
_xsFormatInput(data, dataLength);
- _xsTransformHelper(data, dataLength, -xsPI);
+ _xsTransformHelper(data, dataLength, -xsPI, maxFrequency);
return 1;
}
-int xsIFFT(xsComplex *data, const unsigned long dataLength)
+int xsIFFT(xsComplex *data, const unsigned long dataLength, const unsigned long maxFrequency)
{
if (!data || dataLength < 1 || dataLength & (dataLength - 1)) {
return 0;
}
_xsFormatInput(data, dataLength);
- _xsTransformHelper(data, dataLength, xsPI);
+ _xsTransformHelper(data, dataLength, xsPI, maxFrequency);
_xsScaleIFFT(data, dataLength);
return 1;
@@ -161,7 +161,7 @@ xsComplex *xsInterpolateWithFactor2(xsComplex *data, unsigned long *dataLength)
unsigned long newLength = oldLength << 1;
// FFT
- xsFFT(data, oldLength);
+ xsFFT(data, oldLength, oldLength);
// Zero pad
data = (xsComplex *)realloc(data, sizeof(xsComplex) * newLength);
@@ -191,7 +191,7 @@ xsComplex *xsInterpolateWithFactor2(xsComplex *data, unsigned long *dataLength)
}
// IFFT
- xsIFFT(data, newLength);
+ xsIFFT(data, newLength, 301584);
return data;
}
@@ -218,10 +218,10 @@ void _xsFormatInput(xsComplex *data, const unsigned long dataLength)
}
}
-void _xsTransformHelper(xsComplex *data, const unsigned long dataLength, const double signedPI)
+void _xsTransformHelper(xsComplex *data, const unsigned long dataLength, const double signedPI, const unsigned long maxFrequency)
{
// Perform butterflies...
- for (unsigned long step = 1; step < dataLength; step <<= 1) {
+ for (unsigned long step = 1; step < maxFrequency; step <<= 1) {
double sine = sin(signedPI / (double)step * 0.5);
xsComplex twiddleMultiplier = xsComplexFromComponents(-2.0 * sine * sine, sin(signedPI / (double)step));
xsComplex twiddleFactor = xsComplexFromReal(1.0);
View
@@ -34,8 +34,8 @@ xsComplex *xsCoerceDataRadix2(xsComplex *data, unsigned long *dataLength);
// FFT and IFFT
-int xsFFT(xsComplex *data, const unsigned long dataLength);
-int xsIFFT(xsComplex *data, const unsigned long dataLength);
+int xsFFT(xsComplex *data, const unsigned long dataLength, const unsigned long maxFrequency);
+int xsIFFT(xsComplex *data, const unsigned long dataLength, const unsigned long maxFrequency);
// Useful functions that utilize FFTs
Oops, something went wrong.

0 comments on commit b641f87

Please sign in to comment.