Created
May 19, 2012 22:20
-
-
Save bartolsthoorn/2732569 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NVHighpassFilter.m | |
// NVDSP | |
// | |
// Created by Bart Olsthoorn on 18/05/2012. | |
// Copyright (c) 2012 Bart Olsthoorn. All rights reserved. | |
// | |
#import "NVHighpassFilter.h" | |
@implementation NVHighpassFilter | |
@synthesize Q; | |
@synthesize cornerFrequency; | |
- (id) init { | |
[self addObserver:self forKeyPath:@"Q" options:0 context:nil]; | |
[self addObserver:self forKeyPath:@"cornerFrequency" options:0 context:nil]; | |
return self; | |
} | |
- (void)observeValueForKeyPath:(NSString*)keyPath | |
ofObject:(id)object | |
change:(NSDictionary*)change | |
context:(void*)context | |
{ | |
if ( | |
[keyPath isEqualToString:@"Q"] || | |
[keyPath isEqualToString:@"cornerFrequency"] | |
) { | |
[self calculateCoefficients]; | |
} | |
else { | |
[super observeValueForKeyPath:keyPath | |
ofObject:object | |
change:change | |
context:context]; | |
} | |
} | |
- (void) calculateCoefficients { | |
if (cornerFrequency !== nil) { | |
[self intermediateVariables:cornerFrequency Q:Q]; | |
a0 = 1 + alpha; | |
b0 = ((1 + omegaC)/2) / a0; | |
b1 = (-1*(1 + omegaC)) / a0; | |
b2 = ((1 + omegaC)/2) / a0; | |
a1 = (-2 * omegaC) / a0; | |
a2 = (1 - alpha) / a0; | |
} | |
} | |
- (void) dealloc | |
{ | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment