/* From: "A SURVEY OF COMPUTATIONAL PHYSICS" by RH Landau, MJ Paez, and CC BORDEIANU Copyright Princeton University Press, Princeton, 2008. Electronic Materials copyright: R Landau, Oregon State Univ, 2008; MJ Paez, Univ Antioquia, 2008; and CC BORDEIANU, Univ Bucharest, 2008. Support by National Science Foundation */ // Filter.java Low-pass windowed - sinc filter import java.io.*; import ptolemy.plot.*; public class Filter { static final int max = 800; static double array[] = new double[max]; static double ps[]=new double[max]; static double y[]=new double[max];//output static double h[]=new double[800];//filter kernel public static void main(String[] argv) { int i, n, k; double step = 2*Math.PI/1000; double dftreal[] = new double[max]; double dftimag[] = new double[max]; function(); fourier(dftreal,dftimag); filter1(h); } public static void filter1(double h[]) { //Low-pass windowed - sinc filter //Filters max samples with a 101 point windowed-sinc filter, //resulting in max 100 samples of filtered data. double step = 2*Math.PI/1000; int i, j; Plot filter = new Plot(); //double fc = .14; // Set the cutoff frequency (between 0 and 0.5) double fc = .07; int m = 100; // Set filter length (101 points) for( i = 0; i<100;i++) { // Calculate the low-pass filter kernel // inverse DFT of rectangular pulse = sinc function sinx/x // h[i]=Math.sin(2.0*Math.PI*fc*i)/i*Math.PI; if ((i-(m/2)) == 0) h[i] = 2*Math.PI*fc; if ((i-(m/2))!= 0) h[i] = Math.sin(2*Math.PI*fc * (i-m/2)) / (i-m/2); h[i] = h[i] * (0.54 - 0.46*Math.cos(2*Math.PI*i/m) );// Hamming window } double sum = 0.0; // Normalize low-pass filter kernel for( i = 0; i< 100; i++) sum = sum + h[i]; for( i = 0; i< 100; i++) h[i] = h[i] / sum; for( j = 100 ;j=0) && (i<500)) f[i]=1.0; if ((i>500) && (i