Skip to content

Instantly share code, notes, and snippets.

@pieterjongsma
Created July 27, 2012 11:38
Show Gist options
  • Save pieterjongsma/3187515 to your computer and use it in GitHub Desktop.
Save pieterjongsma/3187515 to your computer and use it in GitHub Desktop.
Parabolic Fit Test
#import "ParabolicFitTest.h"
@interface ParabolicFitTest ()
- (NSInteger)functionOne:(NSInteger)index;
- (NSInteger)functionTwo:(NSInteger)index;
@end
@implementation ParabolicFitTest {
// Function variables
NSInteger _maxPeakHeight;
NSInteger _numberOfFrames;
}
- (id)init
{
if ((self = [super init])) {
self.repetitions = 1000; // Default number of repetitions
_maxPeakHeight = 32768;
_numberOfFrames = 1000;
}
return self;
}
- (void)runBatch
{
for (NSInteger r=0; r < self.repetitions; r++) {
[self runSingle];
}
}
- (void)runSingle
{
for (NSInteger i=0; i < _numberOfFrames; i++) {
[self functionOne:i];
[self functionTwo:i];
}
}
#pragma mark - Actual to-test functions
- (NSInteger)functionOne:(NSInteger)index
{
NSInteger result = -(index - _numberOfFrames/2)^2 / (_numberOfFrames/2)^2*_maxPeakHeight +
_maxPeakHeight;
return result;
}
- (NSInteger)functionTwo:(NSInteger)index
{
NSInteger result = sinf((float)index/_numberOfFrames*M_PI)*_maxPeakHeight;
return result;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment