-- Inside the Window


-- Apply convolution to a signal with a window
-- of given length in milliseconds
convolute :: VU.Vector Int -> Int -> VU.Vector Int
convolute signal win_sz = 
            VU.map y $ VU.fromList [0..(numSamples - 1)]
    
  where y :: Int -> Int
        y n = VU.foldl' (+) 0 $ -- Sum the results
                -- s[k] * w[n - k] 
                VU.map (\k -> (signal VU.! k) * 
                              (rectWindow win_sz_samples (n - k))) $ 
                     -- k values
                     VU.fromList [(max (n - win_sz_samples + 1) 0) .. 
                                  (min n (numSamples - 1))] -- k values
          
        -- 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 energy for a given signal with a window
-- of given length in milliseconds
convolute :: VU.Vector Int -> Int -> VU.Vector Int
convolute signal win_sz = 
            VU.map y $ VU.fromList [0..(numSamples - 1)]
    
  where y :: Int -> Int
        y n = VU.foldl' (+) 0 $ -- Sum the results
                -- s[k] * w[n - k] 
                VU.map (\k -> (signal VU.! k) * 
                              (rectWindow win_sz_samples (n - k))) $ 
                     -- k values
                     VU.fromList [(max (n - win_sz_samples + 1) 0) .. 
                                  (min n (numSamples - 1))] -- k values
          
        -- 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 energy for a given signal with a window
-- of given length in milliseconds
convolute signal win_sz = 
            VU.map y $ VU.fromList [0..(numSamples - 1)]
    
  where y :: Int -> Int
        y n = VU.foldl' (+) 0 $ -- Sum the results
                -- s[k] * w[n - k] 
                VU.map (\k -> (signal VU.! k) * 
                              (rectWindow win_sz_samples (n - k))) $ 
                     -- k values
                     VU.fromList [(max (n - win_sz_samples + 1) 0) .. 
                                  (min n (numSamples - 1))] -- k values
          
        -- 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 energy for a given signal with a window
-- of given length in milliseconds