| 1 |
# test_MultiSampledSpectropgram.praat |
| 2 |
# djmw 20220510 |
| 3 |
|
| 4 |
appendInfoLine: "test_MultiSampledSpectrogram.praat" |
| 5 |
@test_GaborSpectrogram |
| 6 |
@test_ConstantQLog2FSpectrogram |
| 7 |
appendInfoLine: "test_MultiSampledSpectrogram.praat OK" |
| 8 |
|
| 9 |
procedure test_GaborSpectrogram |
| 10 |
appendInfoLine: tab$, "GaborSpectrogram: windows:" |
| 11 |
.windows$# = { "rectangular", "triangular", "parabolic", "Hanning", "Hamming", "Gaussian1", "Kaiser1" } |
| 12 |
.sound = Create Sound from formula: "s", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 13 |
for iwindow to size (.windows$#) |
| 14 |
selectObject: .sound |
| 15 |
appendInfoLine: tab$, tab$, .windows$# [iwindow] |
| 16 |
.gabor = To GaborSpectrogram: 0, 40, 20, 1, .windows$# [iwindow] |
| 17 |
.resynthesis = To Sound |
| 18 |
Formula: ~ self - object [.sound] |
| 19 |
.extremum = Get absolute extremum: 0, 0, "none" |
| 20 |
assert .extremum < 1e-14 |
| 21 |
removeObject: .gabor, .resynthesis |
| 22 |
endfor |
| 23 |
appendInfoLine: tab$, "GaborSpectrogram: bandwidth, stepSize" |
| 24 |
.numberOfAnalysis = 10 |
| 25 |
.bandwidths# = randomUniform# (.numberOfAnalysis, 10, 500) |
| 26 |
for .ianal to .numberOfAnalysis |
| 27 |
selectObject: .sound |
| 28 |
.bandwidth = .bandwidths# [.ianal] |
| 29 |
.stepSize = randomUniform (1, 0.98 * .bandwidth) |
| 30 |
appendInfoLine: tab$, tab$, fixed$ (.bandwidth, 3), " ", fixed$ (.stepSize, 3) |
| 31 |
.gabor = To GaborSpectrogram: 0, .bandwidth, .stepSize, 1, "Hanning" |
| 32 |
.resynthesis = To Sound |
| 33 |
Formula: ~ self - object [.sound] |
| 34 |
.extremum = Get absolute extremum: 0, 0, "none" |
| 35 |
assert .extremum < 1e-14 ; '.extremum' |
| 36 |
removeObject: .gabor, .resynthesis |
| 37 |
endfor |
| 38 |
appendInfoLine: tab$, "GaborSpectrogram: oversampling" |
| 39 |
.oversampling# = randomUniform# (5, 1, 5) |
| 40 |
for .ianal to size (.oversampling#) |
| 41 |
selectObject: .sound |
| 42 |
.oversampling = .oversampling# [.ianal] |
| 43 |
appendInfoLine: tab$, tab$, fixed$ (.oversampling, 3) |
| 44 |
.gabor = To GaborSpectrogram: 0, 40, 20, .oversampling, "Hanning" |
| 45 |
.resynthesis = To Sound |
| 46 |
Formula: ~ self - object [.sound] |
| 47 |
.extremum = Get absolute extremum: 0, 0, "none" |
| 48 |
assert .extremum < 1e-14 ; '.extremum' |
| 49 |
removeObject: .gabor, .resynthesis |
| 50 |
endfor |
| 51 |
removeObject: .sound |
| 52 |
endproc |
| 53 |
|
| 54 |
procedure test_ConstantQLog2FSpectrogram |
| 55 |
appendInfoLine: tab$, "ConstantQLog2FSpectrogram: windows:" |
| 56 |
.windows$# = { "rectangular", "triangular", "parabolic", "Hanning", "Hamming", "Gaussian1", "Kaiser1" } |
| 57 |
.sound = Create Sound from formula: "s", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 58 |
for iwindow to size (.windows$#) |
| 59 |
selectObject: .sound |
| 60 |
appendInfoLine: tab$, tab$, .windows$# [iwindow] |
| 61 |
.cq = To ConstantQLog2FSpectrogram: 110, 0.0, 24, 1.0, 1, .windows$# [iwindow] |
| 62 |
.resynthesis = To Sound |
| 63 |
Formula: ~ self - object [.sound] |
| 64 |
.extremum = Get absolute extremum: 0, 0, "none" |
| 65 |
assert .extremum < 1e-14 |
| 66 |
removeObject: .cq, .resynthesis |
| 67 |
endfor |
| 68 |
appendInfoLine: tab$, "ConstantQLog2FSpectrogram: numberOfFrequencyBins, frequencyResolution" |
| 69 |
.numberOfAnalysis = 10 |
| 70 |
.numberOfFrequencyBins# = randomInteger# (.numberOfAnalysis, 5, 50) |
| 71 |
for .ianal to .numberOfAnalysis |
| 72 |
selectObject: .sound |
| 73 |
.numberOfFrequencyBins = .numberOfFrequencyBins# [.ianal] |
| 74 |
.frequencyResolution = randomUniform (1, 5) |
| 75 |
appendInfoLine: tab$, tab$, .numberOfFrequencyBins, " ", fixed$ (.frequencyResolution, 3) |
| 76 |
.cq = To ConstantQLog2FSpectrogram: 110, 0.0, .numberOfFrequencyBins, .frequencyResolution, 1, "Hanning" |
| 77 |
.resynthesis = To Sound |
| 78 |
Formula: ~ self - object [.sound] |
| 79 |
.extremum = Get absolute extremum: 0, 0, "none" |
| 80 |
assert .extremum < 1e-14 ; '.extremum' |
| 81 |
removeObject: .cq, .resynthesis |
| 82 |
endfor |
| 83 |
appendInfoLine: tab$, "ConstantQLog2FSpectrogram: oversampling" |
| 84 |
.oversampling# = randomUniform# (5, 1, 5) |
| 85 |
for .ianal to size (.oversampling#) |
| 86 |
selectObject: .sound |
| 87 |
.oversampling = .oversampling# [.ianal] |
| 88 |
appendInfoLine: tab$, tab$, fixed$ (.oversampling, 3) |
| 89 |
.cq = To ConstantQLog2FSpectrogram: 110, 0.0, 24, 1.0, .oversampling, "Hanning" |
| 90 |
.resynthesis = To Sound |
| 91 |
Formula: ~ self - object [.sound] |
| 92 |
.extremum = Get absolute extremum: 0, 0, "none" |
| 93 |
assert .extremum < 1e-14 ; '.extremum' |
| 94 |
removeObject: .cq, .resynthesis |
| 95 |
endfor |
| 96 |
removeObject: .sound |
| 97 |
endproc |