Skip to content

Instantly share code, notes, and snippets.

@bartolsthoorn
Created May 19, 2012 22:20
Show Gist options
  • Save bartolsthoorn/2732569 to your computer and use it in GitHub Desktop.
Save bartolsthoorn/2732569 to your computer and use it in GitHub Desktop.
//
// 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