comparison fft/test.html @ 1:1c027151f7ec

Beginnings of a test script
author Chris Cannam
date Thu, 01 Oct 2015 16:56:01 +0100
parents
children 44f670784d5f
comparison
equal deleted inserted replaced
0:d7c216b6a84f 1:1c027151f7ec
1 <html>
2 <body>
3 <p>If 2150 iterations of real-to-complex FFT of size 2048 takes less than 10 seconds, then we may be able to make a high quality real-time phase vocoder (just).</p>
4
5 <p>A phase-vocoder of course must use overlapped
6 windowed FFT (although you can choose the size, within limits), IFFT,
7 and cartesian-polar conversion to calculate the phase for the
8 instantaneous frequency.</p>
9
10 <p>A reasonable estimate of CPU cost for the whole thing is somewhere
11 around 10x the cost of simple non-overlapping short-time forward
12 Fourier transforms across the signal. </p>
13
14 <p>2150 iterations corresponds to 100 seconds of audio non-overlapped at
15 44.1kHz, so if that takes less than 10 second, then in theory we might
16 be OK.</p>
17 <pre>
18 <script src="nayuki/fft.js"></script>
19 <script>
20
21 /* for a phase vocoder, we probably want 2048-point real-to-complex
22 * FFTs (if available) */
23
24 function inputReals(size) {
25 var result = new Array(size);
26 for (var i = 0; i < result.length; i++)
27 result[i] = (i % 20) / 10.0 - 1.0;
28 return result;
29 }
30
31 function zeroReals(size) {
32 var result = new Array(size);
33 for (var i = 0; i < result.length; i++)
34 result[i] = 0.0;
35 return result;
36 }
37
38 function inputReal64s(size) {
39 var result = new Float64Array(size);
40 for (var i = 0; i < result.length; i++)
41 result[i] = (i % 20) / 10.0 - 1.0;
42 return result;
43 }
44
45 var iterations = 2150;
46 var size = 2048;
47
48 var start = performance.now();
49
50 var total = 0.0;
51
52 for (var i = 0; i < iterations; ++i) {
53 var real = inputReals(size);
54 var imag = zeroReals(size);
55 transform(real, imag);
56 for (var j = 0; j < size; ++j) {
57 total += real[j] + imag[j];
58 }
59 }
60
61 document.write("total = " + total + "<br>");
62
63 var end = performance.now();
64
65 document.write("nayuki fft.js: " + iterations + " iterations at size " + size + " took " + (end - start) + "ms (" + (1000.0 / ((end - start) / iterations)) + " iterations/sec)<br>");
66
67 </script>
68 <script src="fft.js/lib/complex.js"></script>
69 <script>
70
71 var fft = new FFT.complex(size, false);
72
73 start = performance.now();
74
75 total = 0.0;
76
77 for (var i = 0; i < iterations; ++i) {
78 var ri = inputReal64s(size);
79 var co = new Float64Array(2 * size);
80 fft.simple(co, ri, 'real');
81 for (var j = 0; j < 2 * size; ++j) {
82 total += co[j];
83 }
84 }
85
86 document.write("total = " + total + "<br>");
87
88 var end = performance.now();
89
90 document.write("nockert fft.js: " + iterations + " iterations at size " + size + " took " + (end - start) + "ms (" + (1000.0 / ((end - start) / iterations)) + " iterations/sec)<br>");
91
92 </script>
93 </pre>
94 </body>
95