Debian Codegraph @

test/fon/fourier.praat

raw
1 # fourier.praat
2 # Paul Boersma, 2004,2025
3 # Checks "Sound: To Spectrum..."
4
5 writeInfoLine: "Fourier test"
6 appendInfoLine: "Low sampling frequencies:"
7 for itest from 1 to 50
8 @test: 1, itest
9 endfor
10 appendInfoLine()
11 appendInfoLine: "Random sampling frequencies:"
12 @test: 1, 22049
13 @test: 1, 22050
14 for itest to 48
15 duration = randomUniform (0.2, 3.0)
16 samplingFrequency = randomInteger (10, 10000)
17 @test: duration, samplingFrequency
18 endfor
19 appendInfoLine()
20 appendInfoLine: "Fourier test SUCCEEDED."
21
22 procedure test: duration, samplingFrequency
23 appendInfo: "."
24 original.Sound = Create Sound: "sound", 0.0, duration, samplingFrequency, ~ randomGauss (0, 1)
25 Shift times to between zero and physical duration
26 energy1 = Get energy: 0, 0
27 fft.Spectrum = To Spectrum: "yes"
28 energy2 = Get band energy: 0, 0
29 assert abs (energy1 - energy2) < 1e-6 ; 'duration' 'samplingFrequency'
30 loop.Sound = To Sound
31 energy3 = Get energy: 0, 0
32 assert abs (energy3 - energy1) < 1e-6 ; 'duration' 'samplingFrequency'
33 Formula: ~ self - Sound_sound [ ]
34 extremum = Get absolute extremum: 0, 0, "none"
35 assert extremum < 1e-6 ; 'duration' 'samplingFrequency'
36 removeObject: fft.Spectrum, loop.Sound
37 selectObject: original.Sound
38 dft.Spectrum = To Spectrum: "no"
39 energy2 = Get band energy: 0, 0
40 assert abs (energy1 - energy2) < 1e-6 ; 'duration' 'samplingFrequency' 'energy1' 'energy2'
41 loop.Sound = To Sound
42 energy3 = Get energy: 0, 0
43 assert abs (energy3 - energy1) < 1e-6 ; 'duration' 'samplingFrequency' 'energy1' 'energy3'
44 Formula: ~ self - Sound_sound [ ]
45 extremum = Get absolute extremum: 0, 0, "none"
46 assert extremum < 1e-4 ; 'duration' 'samplingFrequency'
47 removeObject: loop.Sound, dft.Spectrum, original.Sound
48 endproc