import java.awt.*; import java.lang.*; import java.util.*; import java.io.*; import corejava.*; import java.net.*; import java.applet.*; // This class responsible for all the computation, am modulation, and sound control // public class Signal { static final double PI = Math.PI; double dx = (2.0*PI)/400.0; int Twidth = 0; int LENGTH = 400; // returns : a + b// Graph add( Graph a, Graph b) { Graph g = new Graph(); double len = a.numPoints(); for (int i=0; i 60.0 ) { //System.out.println("Sound is over saturated"); factor1 = 60.0/(in.ymax()+factor2); } int j=0; int once = 1; double max = in.numPoints(); // System.out.println("in.avg="+avg+"Max="+(in.ymax()+factor2)+ // "Min="+(in.ymin()+tmp)); for( int i=0; i < 400; i++) { sample[i] = (byte)( (in.Y(i)+ factor2)*factor1 ); if ( sample[i] < 0) { System.out.println("AU is below zero"); sample[i]=(byte)0; } else if (sample[i] >= Double.POSITIVE_INFINITY) sample[i] = (byte)0; else if (sample[i] <= Double.NEGATIVE_INFINITY) sample[i] = (byte)0; } } // am decoding of the Transmitted signal x and the filter. // // returns z = recovered signal // // x = transmitted signal, info = specification of the filter // Graph decode( Graph x, Input info) { Graph z= new Graph(); Graph filter = new Graph(); z = x.abs(); filter = makelowpass(info.amp, info.bandwidth); z = convolute(z,filter); z = z.divide(Twidth/2.0); z = z.setsize(0,x.numPoints()); System.out.println("Twidth="+Twidth); System.out.println("Done Detection"); return z; } // bandpass filtering. // // returns the filtered component // // a = function being filtered, fil = specification of the filter // Graph filter(Graph a, Input fil ) { Graph g = new Graph(); Graph f = new Graph(); if ( fil.waveform.equals("BandPass") ) f = makebandpass(fil.amp,fil.bandwidth,fil.freq); else f = makelowpass(fil.amp,fil.bandwidth); g = convolute(a, f); g = g.setsize(0,a.numPoints()); return g; } // convolution of transmitted signal and the lowpass filter // // x = transmitted signal, filter = filter. // // returns convolution of x and filter// Graph convolute(Graph x, Graph filter) { double flen= filter.numPoints(); double xlen = x.numPoints(); Graph g = new Graph(); double [] temp = new double[(int)(flen+xlen)]; // convolution with filter // for ( int i=0; i