/*
 * This Java source file was generated by the Gradle 'init' task.
 */
package elliptic;

import uk.me.berndporr.iirj.*;
import java.io.*;

public class App {

	/**
	 * elliptic_design.py:
	 *
	 * from scipy import signal
	 * # sampling rate
	 * fs = 1000
	 * # cutoff
	 * f0 = 100
	 * # order
	 * order = 4
	 * # passband ripple
	 * pr = 5
	 * # minimum stopband rejection
	 * sr = 40
	 * coeff = signal.ellip(order, pr, sr, f0/fs*2, 'low', output='sos')
	 * 
	 * The contents of coeff have been copied into coeff2 below.
	 **/
	
	final double[][] coeff2 =
	{
		{1.665778210826693306e-02,
		 -3.926235536821644570e-03,
		 1.665778210826693653e-02,
		 1.000000000000000000e+00,
		 -1.715406458784182631e+00,
		 8.100524568939508896e-01},
		{1.000000000000000000e+00,
		 -1.369802526921778174e+00,
		 9.999999999999997780e-01,
		 1.000000000000000000e+00,
		 -1.605880898184007588e+00,
		 9.538687377533192624e-01}
	};

	/**
	 * Calculates the impulse response of the filter and writes it to elliptic.dat.
	 **/
	public void calcImpulse() {
		try {
			FileOutputStream os = new FileOutputStream("elliptic.dat");
			SOSCascade cust = new SOSCascade();
			cust.setup(coeff2);
			PrintStream bp = new PrintStream(os);
			// let's do an impulse response
			for (int i = 0; i < 500; i++) {
				double v = 0;
				if (i == 10)
					v = 1;
				v = cust.filter(v);
				bp.println("" + v);
			}
			os.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e){
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		new App().calcImpulse();
	}
}
