1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
//
// PRCDFTLowPass.m
// PRICE
// DFT based LowPass filter controller
//
// Created by Riccardo Mottola on Sat Sep 13 2003.
// Copyright (c) 2003-2010 Carduus. All rights reserved.
//
// This application is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#import "PRCDFTLowPass.h"
#import "MyDocument.h"
#include "math.h"
#import "PRDFTLowPass.h"
@implementation PRCDFTLowPass
- (id)init
{
if ((self = [super init]))
{
filter = [[PRDFTLowPass alloc] init];
}
return self;
}
- (IBAction)showFilter:(id)sender
{
[super showFilter:sender];
if (!filterWindow)
[NSBundle loadNibNamed:@"DFTLowPass" owner:self];
[filterWindow makeKeyAndOrderFront:nil];
/* now we read the default values and initialize all fields */
if ([autoRangeCheck state] == NSOnState)
autoRange = YES;
else
autoRange = NO;
passBandFreq = [passBandSlider floatValue];
[passBandVal setFloatValue:passBandFreq];
[passBandValPi setFloatValue:(passBandFreq*M_PI)];
stopBandFreq = [stopBandSlider floatValue];
[stopBandVal setFloatValue:stopBandFreq];
[stopBandValPi setFloatValue:(stopBandFreq*M_PI)];
[self parametersChanged:self];
}
- (NSArray *)encodeParameters
{
NSArray *parameters;
/* encode parameters */
parameters = [NSArray arrayWithObjects:
[NSNumber numberWithBool:autoRange],
[NSNumber numberWithFloat:passBandFreq],
[NSNumber numberWithFloat:stopBandFreq],
nil];
return parameters;
}
- (void)closeFilterPanel
{
[filterWindow performClose:nil];
}
- (IBAction)dftLPAutoRange:(id)sender
{
if ([autoRangeCheck state] == NSOnState)
autoRange = YES;
else
autoRange = NO;
[self parametersChanged:sender];
}
- (IBAction)changeStopBand:(id)sender
{
if (sender == stopBandValPi)
{
stopBandFreq = [sender floatValue] / M_PI;
if (stopBandFreq > 1)
{
stopBandFreq = 1;
[stopBandValPi setFloatValue:(stopBandFreq*M_PI)];
} else if (stopBandFreq < 0)
{
stopBandFreq = 0;
[stopBandValPi setFloatValue:(stopBandFreq*M_PI)];
}
[stopBandVal setFloatValue:stopBandFreq];
[stopBandSlider setFloatValue:stopBandFreq];
} else if (sender == stopBandVal)
{
stopBandFreq = [sender floatValue];
if (stopBandFreq > 1)
{
stopBandFreq = 1;
[stopBandVal setFloatValue:stopBandFreq];
} else if (passBandFreq < 0)
{
stopBandFreq = 0;
[stopBandVal setFloatValue:stopBandFreq];
}
[stopBandValPi setFloatValue:(stopBandFreq*M_PI)];
[stopBandSlider setFloatValue:stopBandFreq];
} else
{
stopBandFreq = [sender floatValue];
[stopBandVal setFloatValue:stopBandFreq];
[stopBandValPi setFloatValue:(stopBandFreq*M_PI)];
}
if (passBandFreq > stopBandFreq)
{
passBandFreq = stopBandFreq;
[passBandVal setFloatValue:passBandFreq];
[passBandValPi setFloatValue:(passBandFreq*M_PI)];
[passBandSlider setFloatValue:passBandFreq];
}
[self parametersChanged:sender];
}
- (IBAction)changePassBand:(id)sender
{
if (sender == passBandValPi)
{
passBandFreq = [sender floatValue] / M_PI;
if (passBandFreq > 1)
{
passBandFreq = 1;
[passBandValPi setFloatValue:(passBandFreq*M_PI)];
} else if (passBandFreq < 0)
{
passBandFreq = 0;
[passBandValPi setFloatValue:(passBandFreq*M_PI)];
}
[passBandVal setFloatValue:passBandFreq];
[passBandSlider setFloatValue:passBandFreq];
} else if (sender == passBandVal)
{
passBandFreq = [sender floatValue];
if (passBandFreq > 1)
{
passBandFreq = 1;
[passBandVal setFloatValue:passBandFreq];
} else if (passBandFreq < 0)
{
passBandFreq = 0;
[passBandVal setFloatValue:passBandFreq];
}
[passBandValPi setFloatValue:(passBandFreq*M_PI)];
[passBandSlider setFloatValue:passBandFreq];
} else
{
passBandFreq = [sender floatValue];
[passBandVal setFloatValue:passBandFreq];
[passBandValPi setFloatValue:(passBandFreq*M_PI)];
}
if (stopBandFreq < passBandFreq)
{
stopBandFreq = passBandFreq;
[stopBandVal setFloatValue:stopBandFreq];
[stopBandValPi setFloatValue:(stopBandFreq*M_PI)];
[stopBandSlider setFloatValue:stopBandFreq];
}
[self parametersChanged:sender];
}
@end
|