magnitude :: VU.Vector Int -> Int -> VU.Vector Double
magnitude signal win_sz = VU.map m $ VU.fromList [0..(numSamples - 1)]
    
  where m :: Int -> Double
        -- sum(|s[k]| * w[n-k])/N
        m n = (fromIntegral $ sumRes n) / (fromIntegral win_sz_samples) 
        
        sumRes n = VU.foldl'(+) 0 $ -- Sum results
                      -- |s[k]| * w[n-k]
                      VU.map (\k -> ((abs (signal VU.! k))) * 
                             (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 zero crossing rate for a given signal with a window
-- of given length in milliseconds
magnitude :: VU.Vector Int -> Int -> VU.Vector Double
magnitude signal win_sz = VU.map m $ VU.fromList [0..(numSamples - 1)]
    
  where m :: Int -> Double
        -- sum(|s[k]| * w[n-k])/N
        m n = (fromIntegral $ sumRes n) / (fromIntegral win_sz_samples) 
        
        sumRes n = VU.foldl'(+) 0 $ -- Sum results
                      -- |s[k]| * w[n-k]
                      VU.map (\k -> ((abs (signal VU.! k))) * 
                             (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 zero crossing rate for a given signal with a window
-- of given length in milliseconds
magnitude signal win_sz = VU.map m $ VU.fromList [0..(numSamples - 1)]
    
  where m :: Int -> Double
        -- sum(|s[k]| * w[n-k])/N
        m n = (fromIntegral $ sumRes n) / (fromIntegral win_sz_samples) 
        
        sumRes n = VU.foldl'(+) 0 $ -- Sum results
                      -- |s[k]| * w[n-k]
                      VU.map (\k -> ((abs (signal VU.! k))) * 
                             (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 zero crossing rate for a given signal with a window
-- of given length in milliseconds