You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.5 KiB
78 lines
1.5 KiB
10 years ago
|
//
|
||
|
// FFTTest.m
|
||
|
// SpectogramPrototype
|
||
|
//
|
||
|
// Created by Joshua Moerman on 24/12/13.
|
||
|
// Copyright (c) 2013 Joshua Moerman. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "FFTTest.h"
|
||
|
#import <Accelerate/Accelerate.h>
|
||
|
|
||
|
@interface FFTTest () {
|
||
|
FFTSetup setup;
|
||
|
float * window;
|
||
|
float * buffer;
|
||
|
}
|
||
|
|
||
|
@end
|
||
|
|
||
|
const int logN = 3;
|
||
|
const int N = 1 << logN;
|
||
|
const float scaling = 1.0 / N;
|
||
|
|
||
|
@implementation FFTTest
|
||
|
@synthesize acceptedSize;
|
||
|
|
||
|
- (id)init{
|
||
|
if(self = [super init]){
|
||
|
acceptedSize = N;
|
||
|
|
||
|
setup = vDSP_create_fftsetup(logN, kFFTRadix2);
|
||
|
window = calloc(N, sizeof(float));
|
||
|
buffer = calloc(N, sizeof(float));
|
||
|
|
||
|
assert(setup && window && buffer);
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)dealloc{
|
||
|
free(buffer);
|
||
|
free(window);
|
||
|
vDSP_destroy_fftsetup(setup);
|
||
|
}
|
||
|
|
||
|
- (void)inPlaceFFT:(float *)data forSize:(unsigned int)n{
|
||
|
assert(n == N);
|
||
|
|
||
|
// Output the source data
|
||
|
for(int i = 0; i < N; ++i){
|
||
|
printf("%f, ", data[i]);
|
||
|
}
|
||
|
printf("\n");
|
||
|
|
||
|
// Window our time - slice
|
||
|
// vDSP_blkman_window(window, N, 0);
|
||
|
// vmul(data, 1, window, 1, data, 1, N);
|
||
|
|
||
|
// Rearrange data
|
||
|
DSPSplitComplex split_buffer = { buffer, buffer + N/2 };
|
||
|
vDSP_ctoz((DSPComplex *)data, 2, &split_buffer, 1, N/2);
|
||
|
|
||
|
// DO IT!
|
||
|
vDSP_fft_zrip(setup, &split_buffer, 1, logN, FFT_FORWARD);
|
||
|
|
||
|
// Calculates magnitudes (so ignores phases)
|
||
|
vDSP_zvabs(&split_buffer, 1, data, 1, N/2);
|
||
|
vDSP_vsmul(data, 1, &scaling, data, 1, N/2);
|
||
|
|
||
|
// Output results:
|
||
|
for(int i = 0; i < N/2; ++i){
|
||
|
printf("%f, ", data[i]);
|
||
|
}
|
||
|
printf("\n");
|
||
|
|
||
|
}
|
||
|
@end
|