module Sound.SC3.Common.Math.Window where
type Window x = x -> x
type Table x = [x]
window_table :: (Integral n,Fractional a,Enum a) => n -> Window a -> Table a
window_table :: n -> Window a -> Table a
window_table n
n Window a
f =
let k :: a
k = a
1 a -> Window a
forall a. Fractional a => a -> a -> a
/ (n -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral n
n a -> Window a
forall a. Num a => a -> a -> a
- a
1)
in Window a -> Table a -> Table a
forall a b. (a -> b) -> [a] -> [b]
map Window a
f [a
0,a
k..a
1]
square :: Num a => a -> a
square :: a -> a
square a
x = a
x a -> a -> a
forall a. Num a => a -> a -> a
* a
x
gaussian :: Floating a => a -> Window a
gaussian :: a -> Window a
gaussian a
theta a
i = Window a
forall a. Floating a => a -> a
exp (- (a
0.5 a -> Window a
forall a. Num a => a -> a -> a
* Window a
forall a. Num a => a -> a
square ((a
i a -> Window a
forall a. Num a => a -> a -> a
- a
0.5) a -> Window a
forall a. Fractional a => a -> a -> a
/ (a
theta a -> Window a
forall a. Num a => a -> a -> a
* a
0.5))))
hann :: Floating a => Window a
hann :: Window a
hann a
i = a
0.5 a -> Window a
forall a. Num a => a -> a -> a
* (a
1 a -> Window a
forall a. Num a => a -> a -> a
- Window a
forall a. Floating a => a -> a
cos (a
2 a -> Window a
forall a. Num a => a -> a -> a
* a
forall a. Floating a => a
pi a -> Window a
forall a. Num a => a -> a -> a
* a
i))
hamming :: Floating a => Window a
hamming :: Window a
hamming a
i = a
0.54 a -> Window a
forall a. Num a => a -> a -> a
- a
0.46 a -> Window a
forall a. Num a => a -> a -> a
* Window a
forall a. Floating a => a -> a
cos (a
2 a -> Window a
forall a. Num a => a -> a -> a
* a
forall a. Floating a => a
pi a -> Window a
forall a. Num a => a -> a -> a
* a
i)
rectangular :: Window a
rectangular :: Window a
rectangular = Window a
forall a. a -> a
id
sine :: Floating a => Window a
sine :: Window a
sine a
i = Window a
forall a. Floating a => a -> a
sin (a
i a -> Window a
forall a. Num a => a -> a -> a
* a
forall a. Floating a => a
pi)
triangular :: Fractional a => Window a
triangular :: Window a
triangular a
i = a
2 a -> Window a
forall a. Num a => a -> a -> a
* (a
0.5 a -> Window a
forall a. Num a => a -> a -> a
- Window a
forall a. Num a => a -> a
abs (a
i a -> Window a
forall a. Num a => a -> a -> a
- a
0.5))
gaussian_table :: (Integral n, Floating b, Enum b) => n -> b -> [b]
gaussian_table :: n -> b -> [b]
gaussian_table n
n = n -> Window b -> [b]
forall n a.
(Integral n, Fractional a, Enum a) =>
n -> Window a -> Table a
window_table n
n (Window b -> [b]) -> (b -> Window b) -> b -> [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Window b
forall a. Floating a => a -> Window a
gaussian
hamming_table :: Int -> [Double]
hamming_table :: Int -> [Double]
hamming_table Int
n = Int -> Window Double -> [Double]
forall n a.
(Integral n, Fractional a, Enum a) =>
n -> Window a -> Table a
window_table Int
n Window Double
forall a. Floating a => a -> a
hamming
hann_table :: Int -> [Double]
hann_table :: Int -> [Double]
hann_table Int
n = Int -> Window Double -> [Double]
forall n a.
(Integral n, Fractional a, Enum a) =>
n -> Window a -> Table a
window_table Int
n Window Double
forall a. Floating a => a -> a
hann
sine_table :: (Integral n, Floating b, Enum b) => n -> [b]
sine_table :: n -> [b]
sine_table n
n = n -> Window b -> [b]
forall n a.
(Integral n, Fractional a, Enum a) =>
n -> Window a -> Table a
window_table n
n Window b
forall a. Floating a => a -> a
sine
triangular_table :: (Integral n, Fractional b, Enum b) => n -> [b]
triangular_table :: n -> [b]
triangular_table n
n = n -> Window b -> [b]
forall n a.
(Integral n, Fractional a, Enum a) =>
n -> Window a -> Table a
window_table n
n Window b
forall a. Fractional a => Window a
triangular