Skip to content

Commit

Permalink
new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dprn committed Oct 19, 2020
1 parent 53bafc0 commit c565f01
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 91 deletions.
66 changes: 0 additions & 66 deletions experiments/bars.jl

This file was deleted.

58 changes: 58 additions & 0 deletions experiments/interrupted_chirp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

# Input sound

rate = 16000.
duration = 2
samples = round(Int,duration*rate)

x1 = [ samples/7 <= t <= 2.5*samples/7 ? sin(2000*2*π*t/rate+1000*t/rate*2*π*t/rate) : 0. for t in 1:samples ]
x2= [ 3*samples/7 <= t <= 4.5*samples/7 ? sin(2000*2*π*t/rate+1000*t/rate*2*π*t/rate) : 0. for t in 1:samples ]

x = x1+x2

## Short time Fourier transform

m =stft(x, 500, 450, fs = rate, window = hanning)


## smoothing

using ImageFiltering

λ=2

M = STFT(0.01.*ComplexF64.(imfilter(abs.(m.stft),ImageFiltering.Kernel.gaussian((λ,2λ)))), m.freq, m.time, m.width)


## Lift

Lm = lift(M; νMin=-0.5, νMax=1.5, N=100)

## WC evolution

χ = 20

α = 55
β = 1
γ = 55

τ = χ * step(time(Lm))

b = .05

k = Kern(normalize(freq(Lm)), slopes(Lm), KernParams(τ, b, 1e-6));

W = wc_delay(Lm, α, β, γ, K=k,τdx = χ) |> project

## Save results

try
mkpath("interrupted-chirp-results")
catch
end

cd("interrupted-chirp-results")

save_result(M, W, α, β, γ, χ)

cd("..")
58 changes: 58 additions & 0 deletions experiments/intersecting_chirps.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Input sound

rate = 16000.
duration = 2
samples = round(Int,duration*rate)

x1 = [ samples/7 <= t <= 6*samples/14 ? sin(2000*2*π*t/rate + 1000*t/rate*2*π*t/rate) : 0. for t in 1:samples ]
x2 = [ samples/7 <= t <= 6*samples/14 ? sin(6000*2*π*t/rate - 1000*t/rate*2*π*t/rate) : 0. for t in 1:samples ]


x = x1+x2

## Short time Fourier transform

m =stft(x, 500, 450, fs = rate, window = hanning)


## smoothing

using ImageFiltering

λ=2

M = STFT(0.01.*ComplexF64.(imfilter(abs.(m.stft),ImageFiltering.Kernel.gaussian((λ,2λ)))), m.freq, m.time, m.width)


## Lift

Lm = lift(M; νMin=-1, νMax=1, N=100)

## WC evolution

χ = 20

α = 53
β = 1
γ = 55

τ = χ * step(time(Lm))

b = .01

k = Kern(normalize(freq(Lm)), slopes(Lm), KernParams(τ, b, 1e-6));

W = wc_delay(Lm, α, β, γ, K=k,τdx = χ) |> project

## Save results

try
mkpath("intersecting-chirps-results")
catch
end

cd("intersecting-chirps-results")

save_result(M, W, α, β, γ, χ)

cd("..")
57 changes: 42 additions & 15 deletions experiments/linear_chirp.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
# Test with linear chirp
# Input sound

rate = 16000.
duration = 2
samples = round(Int,duration*rate)
y = [ t <= 8*samples/14 ? sin(1000*2*π*t/rate+1000*t/rate*2*π*t/rate) : 0. for t in 1:samples ]

mkpath("linear-chirp-results")
cd("linear-chirp-results")
wavwrite(y, "linear_chirp.wav", Fs = rate)
x = [ samples/7 <= t <= 8*samples/14 ? sin(2000*2*π*t/rate+1000*t/rate*2*π*t/rate) : 0. for t in 1:samples ]


## Short time Fourier transform

m =stft(x, 500, 450, fs = rate, window = hanning)


## smoothing

using ImageFiltering

λ=2

@time SS = stft(y, 500, 450, fs = rate)
M = STFT(0.01.*ComplexF64.(imfilter(abs.(m.stft),ImageFiltering.Kernel.gaussian((λ,2λ)))), m.freq, m.time, m.width)


@time Lm = lift(SS, threshold = 10, N=30)
## Lift

KK=20
AA=110
BB=50
CC=250
Lm = lift(M; νMin=-0.5, νMax=1.5, N=100)

## WC evolution

τ = KK*step(time(Lm))
@time k = kernel_computation(normalize(freq(Lm)), slopes(Lm), τ, n = 20);
χ = 20

@time W = wc_delay(Lm, AA, BB, CC, K=k)
α = 55
β = 1
γ = 55

τ = χ * step(time(Lm))

b = .05

k = Kern(normalize(freq(Lm)), slopes(Lm), KernParams(τ, b, 1e-6));

W = wc_delay(Lm, α, β, γ, K=k,τdx = χ) |> project

## Save results

try
mkpath("linear-chirp-results")
catch
end

cd("linear-chirp-results")

save_result(W, AA, BB, CC, KK)
save_result(M, W, α, β, γ, χ)

cd("..")
56 changes: 56 additions & 0 deletions experiments/nonlinear_chirp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

# Input sound

rate = 16000.
duration = 2
samples = round(Int,duration*rate)

x = [ samples/7 <= t <= 8*samples/14 ? sin(3000*2*π*t/rate+2pi*150*sin(2*pi*t/rate)) : 0. for t in 1:samples ]

## Short time Fourier transform

m =stft(x, 500, 450, fs = rate, window = hanning)


## smoothing

using ImageFiltering

λ=2

M = STFT(0.01.*ComplexF64.(imfilter(abs.(m.stft),ImageFiltering.Kernel.gaussian((λ,2λ)))), m.freq, m.time, m.width)


## Lift

Lm = lift(M; νMin=-1.5, νMax=1.5, N=100)

## WC evolution

χ = 20

α = 53
β = 1
γ = 55

τ = χ * step(time(Lm))

b = .2

k = Kern(normalize(freq(Lm)), slopes(Lm), KernParams(τ, b, 1e-6));

W = wc_delay(Lm, α, β, γ, K=k,τdx = χ) |> project

## Save results

try
mkpath("nonlinear-chirp-results")
catch
end

cd("nonlinear-chirp-results")

save_result(M, W, α, β, γ, χ)

cd("..")

46 changes: 36 additions & 10 deletions experiments/run_experiments.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
using Dates

function save_result(m, α, β, γ, τdx; rate = 16000.)
function save_result(m_in, m_out, α, β, γ, τdx; rate = 16000.)
str = string(Dates.format(now(),"yyyy-mm-dd"), " at ", Dates.format(now(),"HH"),"h",Dates.format(now(),"MM")," - a=",α,", b=",β,", g=",γ,", tdx=",τdx)

save(string(str," - STFT.png"), show_stft(m))
save(string(str," - Wave.png"), show_istft(m))
save(string(str," - input - STFT.png"), show_stft(m_in))
save(string(str," - input - Wave.png"), show_istft(m_in))

sound = istft(project(m))
sound = 2*(sound .- minimum(sound))/(maximum(sound)-minimum(sound)).-1
wavwrite(sound, string(str," - sound.wav"), Fs = rate)
save(string(str," - output - STFT.png"), show_stft(m_out))
save(string(str," - output - Wave.png"), show_istft(m_out))

normalize(sound) = 2*(sound .- minimum(sound))/(maximum(sound)-minimum(sound)).-1

sound_in = istft(m_in) |> normalize
wavwrite(sound_in, string(str," - input - sound.wav"), Fs = rate)

sound_out = istft(m_out) |> normalize
wavwrite(sound_out, string(str," - output - sound.wav"), Fs = rate)
end

using WAV
using DSP.Windows

import Pkg
Pkg.activate("../../WCA1")
using WCA1

# There is some kind of bug, for which we need to
# precompile `WCA1` before loading `Images`
using Images

# include("linear_chirp.jl")
include("bars.jl")
# TESTS

try
mkpath("results")
catch
end

cd("results")

println("=== LINEAR CHIRP ===")
include("linear_chirp.jl")

println("=== INTERRUPTED CHIRP ===")
include("interrupted_chirp.jl")

println("=== INTERSECTING CHIRPS ===")
include("intersecting_chirps.jl")

println("=== NON-LINEAR CHIRP ===")
include("nonlinear_chirp.jl")

cd("..")

0 comments on commit c565f01

Please sign in to comment.