001: /*
002: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: */
032:
033: // This code is repackaged after the code from Craig A. Lindley, from Digital Audio with Java
034: // Site ftp://ftp.prenhall.com/pub/ptr/professional_computer_science.w-022/digital_audio/
035: // Email
036: package com.db.media.audio.dsp.filter;
037:
038: // Base class for all IIR filters
039: public abstract class IIRFilterDesignBase {
040:
041: // Private class data
042: protected int frequency;
043: protected int sampleRate;
044: protected double parameter;
045: protected double alpha;
046: protected double beta;
047: protected double gamma;
048:
049: public IIRFilterDesignBase(int frequency, int sampleRate,
050: double parameter) {
051:
052: // Save incoming
053: this .frequency = frequency;
054: this .sampleRate = sampleRate;
055:
056: // Damping factor for highpass and lowpass, q for bandpass
057: this .parameter = parameter;
058:
059: }
060:
061: // Given a frequency of interest, calculate radians/sample
062: protected double calcRadiansPerSample(double freq) {
063:
064: return (2.0 * Math.PI * freq) / sampleRate;
065:
066: }
067:
068: // Return the radians per sample at the frequency of interest
069: protected double getThetaZero() {
070:
071: return calcRadiansPerSample(frequency);
072:
073: }
074:
075: // Do the design of the filter. Filter response controlled by
076: // just three coefficients: alpha, beta and gamma.
077: public abstract void doFilterDesign();
078:
079: // Print all three IIR coefficients
080: public void printCoefficients() {
081:
082: System.out.println("Filter Specifications:");
083: System.out.println("\tSample Rate: " + sampleRate
084: + ", Frequency: " + frequency + ", d/q: " + parameter);
085:
086: System.out.println("\tAlpha: " + alpha);
087: System.out.println("\tBeta: " + beta);
088: System.out.println("\tGamma: " + gamma);
089:
090: }
091:
092: // Return alpha coefficient
093: public double getAlpha() {
094:
095: return alpha;
096:
097: }
098:
099: // Return beta coefficient
100: public double getBeta() {
101:
102: return beta;
103:
104: }
105:
106: // Return gamma coefficient
107: public double getGamma() {
108:
109: return gamma;
110:
111: }
112:
113: }
|