function test_energy = energy_per_frame(file)

[input fs] = wavread(file);
    
    fn = fs/2;
    bins = 512; %useable bins
    frame_length = bins;
    window = hamming(frame_length);
    overlap = .5;
    number_of_frames = (length(input)/(frame_length)/overlap) - 1;
    
    for k=1:number_of_frames

            windowed_frame = window.*input(((k-1)*bins*overlap)+1:(((k-1))*bins*overlap)+1+bins-1);

            fft_window = fft(windowed_frame,bins*2);
            fft_window = abs(fft_window(1:bins));
            fft_energy = fft_window.^2;
            freq_vector = [fn/bins:fn/bins:fn];

            %map bark (z) to bins (1-512) and frequency (freq_vector)
            for i=1:length(freq_vector)
                z(i) = 13*atan(0.76*(freq_vector(i)/1000)) + 3.5*atan(((freq_vector(i)/1000)/7.5).^2);    
            end

            z = floor(z);

            for j=1:length(z);
                if z(j) == 17
                    z(j)=16;
                end
            end

            temp = 0;
            temp_sum = 0;
            count = 0;

            %calculate the energy per bark band
            for i=1:length(z)
               if temp == z(i)
                   temp_sum = fft_energy(i)+ temp_sum;
                   test_energy(k,temp+1) = temp_sum; 
                   count = count+1;
               end

               if temp ~= z(i)   
                  test_energy(k,temp+1) = temp_sum/count;
                  temp = temp+1;
                  temp_sum = fft_energy(i);
                  count = 1;
               end  
            end  

    end