forked from FieldDB/Praat-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_histogram_from_numeric_data_file.praat
127 lines (102 loc) · 3.16 KB
/
draw_histogram_from_numeric_data_file.praat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# This script opens a text file containing one number per line and draws a histogram of the data.
#
# This script is distributed under the GNU General Public License.
# Copyright 22.5.2003 Mietta Lennes
form Draw histogram from numeric data in a text file
comment Give the path of the text file:
text Input_file /home/lennes/durations.txt
comment Save picture file as:
text Output_file /home/lennes/durations.prapic
comment Log file:
text Logfile /home/lennes/log.txt
sentence Title Distribution
sentence X_axis_label
real Bin_size 0.01
real Minimum_value 0
real Maximum_value 0.3
real Maximum_frequency 400
positive Multiply_numbers_by_factor 1000
endform
if fileReadable(input_file$)
Read Matrix from raw text file... 'input_file$'
Rename... temp
call CalculateStatisticsFromSimpleMatrix
select Matrix temp
call DrawHistogramFromSimpleMatrix
# Log some data
fileappend 'logfile$' (N = 'numberOfRows')'newline$'
fileappend 'logfile$' File = 'input_file$''newline$'
fileappend 'logfile$' Mean = 'mean''newline$'
fileappend 'logfile$' Stdev = 'stdev''newline$'
fileappend 'logfile$' Min = 'min''newline$'
fileappend 'logfile$' Max = 'max''newline$'
endif
#-------
procedure CalculateStatisticsFromSimpleMatrix
To TableOfReal
mean = Get column mean (index)... 1
stdev = Get column stdev (index)... 1
# Calculate maximum and minimum
numberOfRows = Get number of rows
min = undefined
next = 0
while min = undefined and next < numberOfRows
next = next + 1
min = Get value... next 1
endwhile
max = undefined
next = 0
while max = undefined and next < numberOfRows
next = next + 1
max = Get value... next 1
endwhile
for row to numberOfRows
val = Get value... row 1
if val > max
max = val
endif
if val < min
min = val
endif
endfor
range = max - min
Remove
endproc
#--------
procedure DrawHistogramFromSimpleMatrix
Erase all
Font size... 14
Black
drawrange = maximum_value - minimum_value
binnumber = drawrange / bin_size
if binnumber <= 0
binnumber = 1
endif
Draw distribution... 0 0 0 0 minimum_value maximum_value binnumber 0 maximum_frequency no
Draw inner box
One mark left... maximum_frequency yes yes no
One mark left... 0 yes yes no
Text top... yes 'title$'
Text top... no N = 'numberOfRows'
Text bottom... yes 'x_axis_label$'
x_axis_numbers_at = (bin_size * (binnumber / 5)) * multiply_numbers_by_factor
scaler = 1 / multiply_numbers_by_factor
Marks bottom every... scaler x_axis_numbers_at yes yes no
minimum_value_draw = minimum_value * multiply_numbers_by_factor
maximum_value_draw = maximum_value * multiply_numbers_by_factor
One mark bottom... minimum_value no yes yes 'minimum_value_draw'
One mark bottom... maximum_value no yes yes 'maximum_value_draw'
# Draw a dotted line at the mean
One mark bottom... mean no yes yes
# Draw dotted lines at stdev from mean
Red
stdevup = mean + stdev
stdevdown = mean - stdev
if stdevup >= minimum_value and stdevup <= maximum_value
One mark bottom... stdevup no yes yes
endif
if stdevdown >= minimum_value and stdevdown <= maximum_value
One mark bottom... stdevdown no yes yes
endif
Write to praat picture file... 'output_file$'
endproc