My job unfortunatly just got rid of some really talented programmers, and i am left to do this. We are working with a new system we are developing which takes an input (stock quotes) from a database (could even be excel file) and returns a specific answers based on the following function:

The function to be evaluated is this: P.S. the 'E' means Summation (Sigma).

N-1 L-1 M-1

y(n) = E a(k) x(n-k) + E + E b(l,m) x(n-1) x(n-m)

K=0 I=0 m=0

Now, i have no idea why the algorithm has to be based on the above function, (remember, i am taking over a half completed job and im not even a real programmer) but this is what was in the old programmers notes. I need some sort of java or c++ code to evaluate the above function. I know that we are going to be working with 200 stock quotes at a time, so let x(n) be 200 values, choosing some variable (a and b) to be real constant coefficiants.

The function to be evaluated is this: P.S. the 'E' means Summation (Sigma).

N-1 L-1 M-1

y(n) = E a(k) x(n-k) + E + E b(l,m) x(n-1) x(n-m)

K=0 I=0 m=0

Now, i have no idea why the algorithm has to be based on the above function, (remember, i am taking over a half completed job and im not even a real programmer) but this is what was in the old programmers notes. I need some sort of java or c++ code to evaluate the above function. I know that we are going to be working with 200 stock quotes at a time, so let x(n) be 200 values, choosing some variable (a and b) to be real constant coefficiants.

http://www.dspguru.com/sw/lib/fir_algs_1-0.c

It is an implementation in C and the fir_basic() function is pretty straight forward to re-implement in Java, like so:

public class FIR {

/** These functions use most or all of the following input parameters:

*

* input - the input sample data

* ntaps - the number of taps in the filter

* h[] - the FIR coefficient array

* z[] - the FIR delay line array

*/

/*************************

* fir_basic: Does the basic FIR algorithm: store input sample, calculate

* output sample, move delay line

**************************

public static double firBasic(double input, int ntaps, doubleh[], double z[])

{

int ii;

double accum;

/* store input at the beginning of the delay line */

z[0] = input;

/* calc FIR */

accum = 0;

for (ii = 0; ii < ntaps; ii++) {

accum += h[ii] * z[ii];

}

/* shift delay line */

for (ii = ntaps - 2; ii >= 0; ii--) {

z[ii + 1] = z[ii];

}

return accum;

}

}

You then call the method by: FIR.firBasic(startValue, numTaps, doubleArray1, doubleArray2);

Replace "startValue", "numTaps", "doubleArray1", "doubleArray2" with the appropriate variables.

Random example not based on anything:

a(k)

public float a(k)

{

\\does some work

returns n;

}

do that for each function, then make a function to handle the entire summation.

You probably want to research the function to understand what it does in order to code it

this value is returned after the final calcuation is done

Btw, the reason why you're getting an ArrayIndexOutOfBoundsExcep

t1=t1+a[k]*x[n-k];

break when n is larger than the size of a. Also, x is only 3 in size and the index in the earlier referenced line will go from n to n-k, which in your code is from 100 to 0, which is way outside the bounds of that array.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.