0

I am doing FFT of a signal and storing the transformed data in a list along with the corresponding frequencies in another list. Then, I am selecting a portion of the frequencies and cutting out the data corresponding to that frequency portion and storing both in lists "DataSel" and "Fsel". Now, I need to further do some analysis on this selected portion of data and frequencies. This is my code

        public class Response {
    public static List<> main(String[] args) {
    try{
        float []data= Series1("test1");
        int len = 128;
        double Sr = 20;
        double bin = (double) Sr/len;
        FloatFFT_1D fftDo = new FloatFFT_1D(len);
        float [] fft = new float [len * 2];
        System.arraycopy(data, 0, fft, 0, len);

        fftDo.complexForward(fft);

        List Data = new ArrayList((fft.length+1)/2);                
        List Fr=new ArrayList();

        for(int i = 0; i < len/2; i++){
            double outputfft = (double) Math.sqrt((Math.pow(fft[2*i],2))+(Math.pow(fft[(2*(i))+1], 2)));
            Data.add(i, outputfft);
            double  freq =  bin * i ;
            Fr.add(i, freq);
            }

        double x = 0.5;
        int index_Fr1 = Collections.binarySearch(Fr, x);
        int insertion_point_Fr1 = -(index_Fr1+1);

        double y = 2;
        int index_Fr2 = Collections.binarySearch(Fr, y);
        int insertion_point_Fr2 = -(index_Fr2+1);

        List FSel = Fr.subList(insertion_point_Fr1, insertion_point_Fr2);   
        List DataSel = Data.subList(insertion_point_Fr1, insertion_point_Fr2);
        return DataSel;                 
        }catch (IOException e) {
            e.printStackTrace();
            }

    }

}

But when I try to return these two lists, I get the error on return type.. Please if anyone can help me figure the problem in this code.

Aqua
  • 39
  • 1
  • 1
  • 12
  • The `return DataSel;` line needs to be inside the `try` block; otherwise, the variable is not in scope. Additionally, you should read about raw types. – Andy Turner Aug 02 '16 at 10:14
  • 2
    Also obligatory: [What is a raw type and why shouldn't we use it?](http://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it) – Jorn Vernee Aug 02 '16 at 10:18
  • Thanks for replying..I getting the error "Incorrect number of arguments for type List; it cannot be parameterized with arguments <>" on doing that.. Also, I will not be knowing the length of my list in advance.. – Aqua Aug 02 '16 at 10:23
  • @Andy.. If I put return inside try block..I get error "This method must return a result of type List" on main method and if I put it outside try block, it says "DataSel cannot be resolved to a variable".. I am very new to Java, and these errors are driving me crazy :( – Aqua Aug 02 '16 at 10:45
  • That's because you are printing the stack trace when an `IOException` occurs. You need to do something afterwards: return null, return an empty list, throw a RuntimeException, declare that the method `throws IOException` and just remove the try/catch entirely. – Andy Turner Aug 02 '16 at 11:01

0 Answers0