energy :: VU.Vector Int -> Int -> VU.Vector Double
energy signal win_sz = VU.map e $ VU.fromList [0..(numSamples - 1)]
    
  where e :: Int -> Double
        -- sum(s[k]^2 * w[n-k])/N
        e n = (fromIntegral $ sumRes n) / (fromIntegral win_sz_samples) 
        
        sumRes :: Int -> Int
        sumRes n = 
            VU.foldl'(+) 0 $ -- Sum results
                -- s[k]^2 * w[n-k]
                VU.map (\k -> ((signal VU.! k) ^ 2) * 
                       (rectWindow win_sz_samples (n - k))) $ 
                        -- k values
                        VU.fromList [(max (n - win_sz_samples + 1) 0) .. 
                                              (min n (numSamples - 1))] 

        -- Number of samples in the Window of win_sz milliseconds 
        win_sz_samples = (numSamples `div` samplingTime) * win_sz
        -- Total number of samples supplied to the convolution function
        numSamples = VU.length signal    


-- Calculate magnitude for a given signal with a window
-- of given length in milliseconds
energy :: VU.Vector Int -> Int -> VU.Vector Double
energy signal win_sz = VU.map e $ VU.fromList [0..(numSamples - 1)]
    
  where e :: Int -> Double
        -- sum(s[k]^2 * w[n-k])/N
        e n = (fromIntegral $ sumRes n) / (fromIntegral win_sz_samples) 
        
        sumRes :: Int -> Int
        sumRes n = 
            VU.foldl'(+) 0 $ -- Sum results
                -- s[k]^2 * w[n-k]
                VU.map (\k -> ((signal VU.! k) ^ 2) * 
                       (rectWindow win_sz_samples (n - k))) $ 
                        -- k values
                        VU.fromList [(max (n - win_sz_samples + 1) 0) .. 
                                              (min n (numSamples - 1))] 

        -- Number of samples in the Window of win_sz milliseconds 
        win_sz_samples = (numSamples `div` samplingTime) * win_sz
        -- Total number of samples supplied to the convolution function
        numSamples = VU.length signal    


-- Calculate magnitude for a given signal with a window
-- of given length in milliseconds
energy signal win_sz = VU.map e $ VU.fromList [0..(numSamples - 1)]
    
  where e :: Int -> Double
        -- sum(s[k]^2 * w[n-k])/N
        e n = (fromIntegral $ sumRes n) / (fromIntegral win_sz_samples) 
        
        sumRes :: Int -> Int
        sumRes n = 
            VU.foldl'(+) 0 $ -- Sum results
                -- s[k]^2 * w[n-k]
                VU.map (\k -> ((signal VU.! k) ^ 2) * 
                       (rectWindow win_sz_samples (n - k))) $ 
                        -- k values
                        VU.fromList [(max (n - win_sz_samples + 1) 0) .. 
                                              (min n (numSamples - 1))] 

        -- Number of samples in the Window of win_sz milliseconds 
        win_sz_samples = (numSamples `div` samplingTime) * win_sz
        -- Total number of samples supplied to the convolution function
        numSamples = VU.length signal    


-- Calculate magnitude for a given signal with a window
-- of given length in milliseconds