Calculating the energy of a signal I have a program to read signal data from 120 files in a folder and performing the energy of the signal.

It works correctly, but execution time is more than 20 mins, so there may be a problem with the code.  Can someone look into it and suggest possible methods to reduce the execution time?

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class myclass {
  static int total = 1;
  static int r = 0;

  public static void main(String[] args) {

    ArrayList&lt;Double&gt; mysignal = new ArrayList&lt;Double&gt;();
    ArrayList&lt;Double&gt; mylist = new ArrayList&lt;Double&gt;();

    double x;
    double a;
    myclass obj = new myclass();
    String target_dir = "path for folder";
    File dir = new File(target_dir);
    File[] files = dir.listFiles();

    for (File f : files) {
      if (f.isFile()) {
        BufferedReader inputStream = null;

        try {
          inputStream = new BufferedReader(new FileReader(f));
          String line;

          while ((line = inputStream.readLine()) != null) {

            mysignal.add(Double.valueOf(line));
            total++;

          }
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        a = obj.funtioneg(mysignal, total);
        mylist.add(r, a);
        System.out.println(mylist.get(r));
        r++;

      }
    }
  }

  public double functioneg(ArrayList&lt;Double&gt; s, int N) {

    ArrayList&lt;Double&gt; y = new ArrayList&lt;Double&gt;();
    double sum = 0, a1 = 0;
    double[] o1 = new double[N - 1];// processed signal

    for (int n = 0; n &lt; N - 1; n++) {
      for (int k = 0; k &lt; 40; k++) {

        if (n - k &gt;= 0) {
          a1 = s.get(n - k);
          sum = sum + (a1 * a1);// energy

        } else
          sum = sum + 0;
      }

      o1[n] = sum;

      sum = 0;

    }
    double sum1 = 0;
    double avg;
    for (int t = 0; t &lt; N- 1; t++) {

      sum1 = sum1 + o1[t];
    }

    avg = sum1 / N - 1;

    return (avg);
  }
}
Avoid recomputations

You compute the energy accumulated in a sliding window. When a window slides by 1, one sample shifts out, and one sample shifts in. The accumulated energy changes by s[n]^2 - s[n-40]^2. Therefore the inner loop is superficial. This alone will give you a 40-fold improvement.
Quadratic complexity

mysignal is only getting more signals appended to it, that is its initial parts are fed to functioneg over and over again, mostly producing the same result. In fact you only need 40 last of the processed samples to ramp up the new file.
Avoid reallocations

You don't really need the o1 array. sum1 can be computed on the fly.