From: WANG Date: Thu, 29 Aug 2013 16:19:18 +0000 (+0200) Subject: Add fft, 2d_fft and sinwave to examples. X-Git-Url: https://scm.cri.ensmp.fr/git/Faustine.git/commitdiff_plain/cc8ed2bd6bd5a60156d63040b2d352ad5b1a3095 Add fft, 2d_fft and sinwave to examples. --- diff --git a/examples/2d_fft/fft2d.dsp b/examples/2d_fft/fft2d.dsp new file mode 100644 index 0000000..c77a660 --- /dev/null +++ b/examples/2d_fft/fft2d.dsp @@ -0,0 +1,51 @@ +import ( "../../architecture/fft.lib" ) ; +import ( "../../architecture/complex.lib" ) ; + +GREY_MAX = 256; + +//fft2d(x,y) = vectorize(x) : vectorize(y) <: picks(n) : real2complex(n) : fft(n) : stops(n/2), pcplx_moduls(n/2) : modules_vector(n/2); +//fft2d(x,y) = vectorize(x) : vectorize(y) : fft(x) : fftc(y) : pcplx_moduls(y) : modules_vector(y); +//fft2d(x,y) = vectorize(x) : fft(x) : fftc(y) : pcplx_moduls(y) : modules_vector(y); + +matricize(x, y) = vectorize(y) : vectorize(x); + +ffts(n, m) = par(i, n, (fft(m) : nconcat(m))); + +fftcs(n, m) = par(i, n, (fftc(m) : nconcat(m))); + +lines_fft(n, m) = _ <: picks(n) : ffts(n, m) : nconcat(n); + +lines_fftc(n, m) = _ <: picks(n) : fftcs(n, m) : nconcat(n); + +take_column(n, m) = par(i, n, [m]) : nconcat(n); + +matrix_transpose(n, m) = _ <: picks(n) <: par(i, m, take_column(n, i)) : nconcat(m); + +matrix_pcplx2modul(n, m) = _ <: picks(n) : par(i, n, ( _ <: picks(m) : pcplx_moduls(m) : nconcat(m))) : nconcat(n); + +matrix_real2pcplx(n, m) = _ <: picks(n) : par(i, n, ( _ <: picks(m) : real2pcplx(m) : nconcat(m))) : nconcat(n); + +//normalize(n) = _ , n : /; +normalize(n, m) = _, (m : vectorize(n)) : /; + +unnormalize(n) = par(i, n, ( _ , GREY_MAX : *)); + +norm_out(n, m) = _ <: picks(n) : par(i, n, ( _ <: picks(m) : unnormalize(m) : nconcat(m))) : nconcat(n) : serialize; + +output(n, m) = serialize; + +//fft2d(x, y) = matricize(x, y) : lines_fft(x, y) : matrix_transpose(x, y) : lines_fftc(y, x) : matrix_transpose(y, x) : output(x, y); +//fft2d(x, y) = normalize(GREY_MAX) : matricize(x, y) : lines_fft(x, y) : matrix_transpose(x, y) : lines_fftc(y, x) : matrix_transpose(y, x) : norm_out(x, y); +//fft2d(x, y) = matricize(x, y) : matrix_real2pcplx(x, y) : matrix_pcplx2modul(x, y) : output(x, y); +//fft2d(x, y) = matricize(x, y) : output(x, y); +fft2d(x, y) = normalize(GREY_MAX) : matricize(x, y) : lines_fft(x, y) : matrix_transpose(x, y) : lines_fftc(y, x) : matrix_transpose(y, x) : norm_out(x, y); + +new_fft2d(x, y) = normalize(y, GREY_MAX) : vectorize(x) : lines_fft(x, y) : matrix_transpose(x, y) : lines_fftc(y, x) : matrix_transpose(y, x) : norm_out(x, y); + +//safer with x=y because tests and zero padding are still to implement +//process = fft2d(32,32); + +process = new_fft2d(32,32); + + + diff --git a/examples/2d_fft/fft2d.sh b/examples/2d_fft/fft2d.sh new file mode 100644 index 0000000..b77b205 --- /dev/null +++ b/examples/2d_fft/fft2d.sh @@ -0,0 +1,2 @@ +../../interpretor/faustine -d fft2d.dsp -i hcosine-32.csv --oformat csv + diff --git a/examples/2d_fft/hcosine-32.csv b/examples/2d_fft/hcosine-32.csv new file mode 100644 index 0000000..14d3ba6 --- /dev/null +++ b/examples/2d_fft/hcosine-32.csv @@ -0,0 +1,32 @@ +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 +217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217,217,38,38,217 diff --git a/examples/2d_fft/output1.csv b/examples/2d_fft/output1.csv new file mode 100644 index 0000000..9112295 --- /dev/null +++ b/examples/2d_fft/output1.csv @@ -0,0 +1,32 @@ +130560.,0.,0.,0.,0.,0.,0.,0.,64804.9222822,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,64804.9222822,0.,0.,0.,0.,0.,0.,0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,18 @@ +import ( "../../architecture/fft.lib" ) ; +import ( "../../architecture/complex.lib" ) ; + + + +//fft_test(n,m) = _ : overlap(n,m) <: picks(n) : real2complex(n) : fft(n) : stops(n/2), pcplx_moduls(n/2) : modules_vector(n/2); +//fft_test(n,m) = _ : overlap(n,m) : fft(n) : stops(n/2), pcplx_moduls(n/2) : nconcat(n/2); +fft_test(n,m) = vectorize(n) : fft(n) : pcplx_moduls(n) : nconcat(n); + +//process = +, _ : + : fft_test(128,128); +process = fft_test(128,128) : serialize; +//process = (0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7) <: shuffle(8); + + + + + + diff --git a/examples/fft/fft.sh b/examples/fft/fft.sh new file mode 100644 index 0000000..03de52b --- /dev/null +++ b/examples/fft/fft.sh @@ -0,0 +1 @@ +../../interpretor/faustine -d fft.dsp -i sin_22000Hz_0.005_ampli_128samples.wav diff --git a/examples/fft/sin_1378Hz_0.005_ampli_128samples.wav b/examples/fft/sin_1378Hz_0.005_ampli_128samples.wav new file mode 100644 index 0000000..7d4c896 Binary files /dev/null and b/examples/fft/sin_1378Hz_0.005_ampli_128samples.wav differ diff --git a/examples/fft/sin_16536Hz_0.005_ampli_128samples.wav b/examples/fft/sin_16536Hz_0.005_ampli_128samples.wav new file mode 100644 index 0000000..e48ffb6 Binary files /dev/null and b/examples/fft/sin_16536Hz_0.005_ampli_128samples.wav differ diff --git a/examples/fft/sin_2067Hz_0.005_ampli_128samples.wav b/examples/fft/sin_2067Hz_0.005_ampli_128samples.wav new file mode 100644 index 0000000..a8524b7 Binary files /dev/null and b/examples/fft/sin_2067Hz_0.005_ampli_128samples.wav differ diff --git a/examples/fft/sin_22000Hz_0.005_ampli_128samples.wav b/examples/fft/sin_22000Hz_0.005_ampli_128samples.wav new file mode 100644 index 0000000..93556f1 Binary files /dev/null and b/examples/fft/sin_22000Hz_0.005_ampli_128samples.wav differ diff --git a/examples/sinwave/output1.wav b/examples/sinwave/output1.wav new file mode 100644 index 0000000..5a728e2 Binary files /dev/null and b/examples/sinwave/output1.wav differ diff --git a/examples/sinwave/sin.dsp b/examples/sinwave/sin.dsp new file mode 100644 index 0000000..b1650f2 --- /dev/null +++ b/examples/sinwave/sin.dsp @@ -0,0 +1,19 @@ +//sin = ffunction(float sin(float), , ""); +//floor = ffunction(float floor(float), , ""); +PI = 3.141592653589; + +tablesize = 40000; +samplingfreq = 44100.; + +time = (+(1)~_) - 1; +sinwavform = time * (2 * PI)/tablesize : sin; + +decimal = _ <: -(floor); +phase(freq) = freq / samplingfreq : mem : ( + : decimal) ~ _ : * (tablesize) : int; +osc(freq) = phase(freq) : rdtable(tablesize, sinwavform); + +vol = 1; +freq = 1000; + +process = osc(freq) * vol; +//process = freq / samplingfreq : @(1): ( + : decimal) ~ _ : * (tablesize) : int ; diff --git a/examples/sinwave/sin.sh b/examples/sinwave/sin.sh new file mode 100644 index 0000000..3a4b202 --- /dev/null +++ b/examples/sinwave/sin.sh @@ -0,0 +1 @@ +../../interpretor/faustine -d sin.dsp