digiproc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +8 -0
  7. data/Gemfile.lock +48 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +78 -0
  10. data/Rakefile +37 -0
  11. data/TODO.md +50 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/config/environment.rb +118 -0
  15. data/console_tests.rb +44 -0
  16. data/digiproc.gemspec +49 -0
  17. data/examples/analog_signals/analog_to_digital.rb +31 -0
  18. data/examples/analog_signals/companded-signals.png +0 -0
  19. data/examples/analog_signals/companding.rb +68 -0
  20. data/examples/analog_signals/fft-plot.png +0 -0
  21. data/examples/analog_signals/plot_Digiproc::FFT.png +0 -0
  22. data/examples/analog_signals/plot_Dsp::FFT.png +0 -0
  23. data/examples/analog_signals/quantization-outputs.png +0 -0
  24. data/examples/analog_signals/quantize_compand.rb +69 -0
  25. data/examples/binomial_distribution/bit_error.rb +14 -0
  26. data/examples/binomial_distribution/dice.rb +35 -0
  27. data/examples/digital_signals/_coded_frequency_signal,_ts_=_1_s.png +0 -0
  28. data/examples/digital_signals/_coded_frequency_signal,_ts_=_2_s.png +0 -0
  29. data/examples/digital_signals/coded_power_spectral_density,__ts_=_1_s.png +0 -0
  30. data/examples/digital_signals/coded_power_spectral_density,__ts_=_2_s.png +0 -0
  31. data/examples/digital_signals/coded_time_signal,_ts_=_1_s.png +0 -0
  32. data/examples/digital_signals/coded_time_signal,_ts_=_2_s.png +0 -0
  33. data/examples/digital_signals/freq_sig_from_eqn,_ts_=_1_s.png +0 -0
  34. data/examples/digital_signals/freq_sig_from_eqn,_ts_=_2_s.png +0 -0
  35. data/examples/digital_signals/frequency_signal,_ts_=_1_s.png +0 -0
  36. data/examples/digital_signals/frequency_signal,_ts_=_2_s.png +0 -0
  37. data/examples/digital_signals/modulate_square_pulses.rb +9 -0
  38. data/examples/digital_signals/modulated_sq._pulses.png +0 -0
  39. data/examples/digital_signals/modulated_sq._pulses_alt.png +0 -0
  40. data/examples/digital_signals/power_spectral_density,__ts_=_1_s.png +0 -0
  41. data/examples/digital_signals/power_spectral_density,__ts_=_2_s.png +0 -0
  42. data/examples/digital_signals/square_signals.rb +90 -0
  43. data/examples/digital_signals/time_signal,_ts_=_1_s.png +0 -0
  44. data/examples/digital_signals/time_signal,_ts_=_2_s.png +0 -0
  45. data/examples/encoding/gray_code.rb +22 -0
  46. data/examples/encoding/psk.rb +91 -0
  47. data/examples/encoding/system_2_phase.png +0 -0
  48. data/examples/encoding/system_2_xmit_signal.png +0 -0
  49. data/examples/encoding/system_3_phase.png +0 -0
  50. data/examples/encoding/system_3_xmit_signal.png +0 -0
  51. data/examples/encoding/system_4_xmit_signal.png +0 -0
  52. data/examples/encoding/xor-dpsk-phase-signal-(sys1).png +0 -0
  53. data/examples/encoding/xor-dpsk-xmit-signal-(sys-1).png +0 -0
  54. data/examples/factories/Quickplot Graph.png +0 -0
  55. data/examples/factories/bandpass.rb +6 -0
  56. data/examples/fft/plot_Dsp::FFT.png +0 -0
  57. data/examples/fft/recieved_data_(time_domain).png +0 -0
  58. data/examples/fft/simple_fft_example.rb +47 -0
  59. data/examples/fft/unprocessed_fft.png +0 -0
  60. data/examples/filters/bandpass_filter.png +0 -0
  61. data/examples/filters/filter_a_signal.rb +38 -0
  62. data/examples/filters/white_noise_db_out_of_bp_filter.png +0 -0
  63. data/examples/filters/white_noise_mag_out_of_bp_filter.png +0 -0
  64. data/examples/filters/white_noise_spectra.png +0 -0
  65. data/examples/functions/compute_probability.rb +29 -0
  66. data/examples/functions/gram_schmidt.rb +10 -0
  67. data/examples/functions/minimize_energy.rb +29 -0
  68. data/examples/functions/orthoganalize.rb +18 -0
  69. data/examples/functions/simple_functions.rb +81 -0
  70. data/examples/linear_algebra/diverging_sys.rb +13 -0
  71. data/examples/linear_algebra/iterative_sys_of_eqns_methods.rb +27 -0
  72. data/examples/modulation_schemes/dpsk_2.png +0 -0
  73. data/examples/modulation_schemes/dpsk_256.png +0 -0
  74. data/examples/modulation_schemes/dpsk_freq_domain.rb +119 -0
  75. data/examples/modulation_schemes/psk.rb +36 -0
  76. data/examples/modulation_schemes/psk_2.png +0 -0
  77. data/examples/modulation_schemes/psk_256.png +0 -0
  78. data/examples/modulation_schemes/psksystem_1_xmit_signal.png +0 -0
  79. data/examples/modulation_schemes/psksystem_2_xmit_signal.png +0 -0
  80. data/examples/modulation_schemes/psksystem_3_xmit_signal.png +0 -0
  81. data/examples/modulation_schemes/system_1_xmit_signal.png +0 -0
  82. data/examples/modulation_schemes/system_2_xmit_signal.png +0 -0
  83. data/examples/modulation_schemes/system_3_xmit_signal.png +0 -0
  84. data/examples/quickplot/PlottableClass_plot.png +0 -0
  85. data/examples/quickplot/decorators.rb +13 -0
  86. data/examples/quickplot/direct_gruff.png +0 -0
  87. data/examples/quickplot/plot_PlottableClass.png +0 -0
  88. data/examples/quickplot/quickplot_vs_others.rb +85 -0
  89. data/examples/quickplot/random_data_quickplot,_dark.png +0 -0
  90. data/examples/quickplot/random_data_quickplot.png +0 -0
  91. data/examples/realized_gaussian/norm_dist_plot.png +0 -0
  92. data/examples/realized_gaussian/norm_dist_spectrum.png +0 -0
  93. data/examples/realized_gaussian/realized_gaussian_example.rb +23 -0
  94. data/lib/concerns/convolvable.rb +144 -0
  95. data/lib/concerns/data_properties.rb +223 -0
  96. data/lib/concerns/fourier_transformable.rb +178 -0
  97. data/lib/concerns/initializable.rb +43 -0
  98. data/lib/concerns/multipliable.rb +22 -0
  99. data/lib/concerns/os.rb +36 -0
  100. data/lib/concerns/plottable.rb +248 -0
  101. data/lib/concerns/requires_data.rb +8 -0
  102. data/lib/digiproc/version.rb +8 -0
  103. data/lib/digiproc.rb +2 -0
  104. data/lib/extensions/array_extension.rb +23 -0
  105. data/lib/extensions/core_extensions.rb +117 -0
  106. data/lib/factories/factories.rb +3 -0
  107. data/lib/factories/filter_factory.rb +83 -0
  108. data/lib/factories/window_factory.rb +22 -0
  109. data/lib/fft.rb +255 -0
  110. data/lib/filters/bandpass_filter.rb +43 -0
  111. data/lib/filters/bandstop_filter.rb +44 -0
  112. data/lib/filters/digital_filter.rb +59 -0
  113. data/lib/filters/highpass_filter.rb +27 -0
  114. data/lib/filters/lowpass_filter.rb +27 -0
  115. data/lib/functions.rb +221 -0
  116. data/lib/probability/binomial_distribution.rb +84 -0
  117. data/lib/probability/bit_generator.rb +94 -0
  118. data/lib/probability/gaussian_distribution.rb +29 -0
  119. data/lib/probability/probability.rb +234 -0
  120. data/lib/probability/theoretical_gaussian_distribution.rb +59 -0
  121. data/lib/quick_plot.rb +96 -0
  122. data/lib/rbplot.rb +219 -0
  123. data/lib/signals/analog_signal.rb +143 -0
  124. data/lib/signals/digital_signal.rb +181 -0
  125. data/lib/strategies/code/differential_encoding_strategy.rb +69 -0
  126. data/lib/strategies/code/gray_code.rb +75 -0
  127. data/lib/strategies/code/xor_differential_encoding_strategy.rb +100 -0
  128. data/lib/strategies/code/xor_differential_encoding_zero_angle_strategy.rb +103 -0
  129. data/lib/strategies/companding/custom_companding_strategy.rb +29 -0
  130. data/lib/strategies/convolution/bf_conv.rb +57 -0
  131. data/lib/strategies/fft/brute_force_dft_strategy.rb +31 -0
  132. data/lib/strategies/fft/inverse_fft_conjugate_strategy.rb +44 -0
  133. data/lib/strategies/fft/radix2_strategy.rb +84 -0
  134. data/lib/strategies/gaussian/gaussian_generator.rb +49 -0
  135. data/lib/strategies/linear_algebra/gauss_seidel_strategy.rb +90 -0
  136. data/lib/strategies/linear_algebra/jacobi_strategy.rb +81 -0
  137. data/lib/strategies/linear_algebra/sor2_strategy.rb +98 -0
  138. data/lib/strategies/linear_algebra/sor_strategy.rb +108 -0
  139. data/lib/strategies/modulation/phase_shift_keying_strategy.rb +96 -0
  140. data/lib/strategies/orthogonalize/gram_schmidt.rb +50 -0
  141. data/lib/strategies/strategies.rb +3 -0
  142. data/lib/strategies/window/blackman_window.rb +32 -0
  143. data/lib/strategies/window/hamming_window.rb +31 -0
  144. data/lib/strategies/window/hanning_window.rb +31 -0
  145. data/lib/strategies/window/kaiser_window.rb +27 -0
  146. data/lib/strategies/window/rectangular_window.rb +22 -0
  147. data/lib/strategies/window/window.rb +42 -0
  148. data/lib/systems/custom_system.rb +13 -0
  149. data/lib/systems/hilbert_transform.rb +6 -0
  150. data/lib/systems/matched_filter.rb +21 -0
  151. data/lib/systems/raised_cosine_filter.rb +11 -0
  152. data/lib/systems/system.rb +19 -0
  153. data/lib/systems/systems.rb +3 -0
  154. data/playground.rb +323 -0
  155. data/plots/_coded_frequency_signal,_ts_=_1_s.png +0 -0
  156. data/plots/_coded_frequency_signal,_ts_=_2_s.png +0 -0
  157. data/plots/coded_freq_sig_from_eqn,_ts_=_1_s.png +0 -0
  158. data/plots/coded_freq_sig_from_eqn,_ts_=_2_s.png +0 -0
  159. data/plots/coded_power_spectral_density,__ts_=_1_s.png +0 -0
  160. data/plots/coded_power_spectral_density,__ts_=_2_s.png +0 -0
  161. data/plots/coded_time_signal,_ts_=_1_s.png +0 -0
  162. data/plots/coded_time_signal,_ts_=_2_s.png +0 -0
  163. data/plots/dpsk_2.png +0 -0
  164. data/plots/freq_sig_from_eqn,_ts_=_1_s.png +0 -0
  165. data/plots/freq_sig_from_eqn,_ts_=_2_s.png +0 -0
  166. data/plots/frequency_signal,_ts_=_1_s.png +0 -0
  167. data/plots/frequency_signal,_ts_=_2_s.png +0 -0
  168. data/plots/power_spectral_density,__ts_=_1_s.png +0 -0
  169. data/plots/power_spectral_density,__ts_=_2_s.png +0 -0
  170. data/plots/psk_2.png +0 -0
  171. data/plots/time_signal,_ts_=_1_s.png +0 -0
  172. data/plots/time_signal,_ts_=_2_s.png +0 -0
  173. data/test-title-dark.png +0 -0
  174. data/test-title.png +0 -0
  175. metadata +322 -0
data/playground.rb ADDED
@@ -0,0 +1,323 @@
1
+ plt = Digiproc::QuickPlot
2
+ fns = Digiproc::Functions
3
+ prob = Digiproc::Probability
4
+ norm_dist = Digiproc::Probability::RealizedGaussianDistribution
5
+ factory = Digiproc::Factories::FilterFactory
6
+ e = Math::E
7
+ pi = Math::PI
8
+
9
+ #-------------------------------------------------------------
10
+ #PROBLEM 1
11
+ #---------------------------------------------------------------
12
+ # Create "white" Gaussian noise, 0 mean
13
+ # dist = norm_dist.new(mean: 0, stddev: 1, size: 16384)
14
+
15
+ # # Create a bandpass filter, make FT dimensions match
16
+ # bpfilter = factory.filter_for(type: "bandpass", wo: Math::PI / 2, bw: Math::PI / 5, transition_width: 0.0001, stopband_attenuation: 80)
17
+ # filter_dft = Digiproc::FFT.new(time_data: bpfilter.weights, size: 16384 * 4)
18
+
19
+ # # Get FT of White noise, calculate No
20
+ # dist_fft = Digiproc::FFT.new(time_data: dist.data, size: 16384 * 4)
21
+ # n_o = 2 * (dist_fft.magnitude.map{ |val| val ** 2}.sum.to_f / dist_fft.data.length)
22
+
23
+ # # Multiply freq domain of noise and filter to get output spectra
24
+ # # Calculate output energy
25
+ # filter_out = dist_fft * filter_dft
26
+ # total_noise_out = filter_out.magnitude.map{ |val| (val ** 2) * (1.0/ (4 * 16384)) }.sum
27
+ # time_data_out = fns.ifft(filter_out.data).map(&:real)
28
+ # bw = 1.0 / 10
29
+
30
+ # puts "Normal Dist. Input \n\tMean:#{prob.mean(dist.data)}, Stddev: #{prob.stddev(dist.data)}"
31
+ # puts "No = #{n_o}"
32
+ # puts "Total Noise Energy Out: #{total_noise_out}"
33
+ # puts "Output: \n\tMean: #{prob.mean(time_data_out)}, Stddev: #{prob.stddev(time_data_out)}"
34
+ # puts "Calculated Noise Energy Out: #{ n_o * bw}"
35
+
36
+ # f = fns.linspace(0,1,16384)
37
+
38
+ # plt.plot(x: f, y: filter_dft.dB, title: "Bandpass Filter")
39
+ # plt.plot(x: f, y: dist_fft.magnitude, title: "White Noise Spectra" )
40
+ # plt.plot(x: f, y: filter_out.magnitude, title: "White Noise Mag Out of BP Filter", y_label: "Magnitude")
41
+ # plt.plot(x: f, y: filter_out.dB, title: "White Noise dB Out of BP Filter", y_label: "dB")
42
+
43
+ #--------------------------------------------------------------
44
+ #PROBLEM 2
45
+ #--------------------------------------------------------------
46
+
47
+ # #Generate white noise
48
+ # noise = norm_dist.new(mean: 0, stddev: 1, size: 4096)
49
+ # #Generate signal
50
+ # sys = Digiproc::DigitalSignal.new(data: [1,-2,1])
51
+
52
+ # #Put noise through system, autocorrelate output
53
+ # output = sys.ds_conv noise
54
+ # output_autocorrelation = output.acorr
55
+
56
+ # n_o = 2 * noise.data.dot(noise.data)
57
+ # #Display results
58
+ # expanded_sys = Digiproc::FFT.new(time_data: sys.data, size: 4096)
59
+ # calculated_system_equation = ->(w){ (1 - 2 * e ** (Complex(0,-1) * w) + e ** (Complex(0,-2) * w)).abs}
60
+
61
+ # # f = fns.linspace(0,1,4096)
62
+ # # w = fns.linspace(0,2*pi, 4096)
63
+ # # calculated_system_spectra = w.map{|value| calculated_system_equation.call(value)}
64
+ # # plt.plot(x: f, y: expanded_sys.magnitude, title: "System Spectra")
65
+ # # plt.plot(x: f, y: (Digiproc::FFT.new(time_data: noise.data) * expanded_sys).magnitude, title: "Output Spectra")
66
+ # # plt.plot(x: w, y: calculated_system_spectra, title: "Expected System Spectra", data_name: "1 - 2exp(jw) + exp(j2w)")
67
+ # # plt.plot(data: output_autocorrelation[4093..4101], title: "Autocorrelation of output")
68
+
69
+ # puts n_o
70
+ # puts "Input noise mean: #{prob.mean(noise.data)}"
71
+ # puts "Output mean: #{prob.mean(output.data)}"
72
+
73
+
74
+ #----------------------------------------------------
75
+ #PROBLEM 3
76
+ #----------------------------------------------------
77
+
78
+ # eqn = ->(t){ (t >= 0 and t <= 0.1) ? (100 * t * Math.cos(2*Math::PI*2.5*t)) : 0 }
79
+ # analog_signal = Digiproc::AnalogSignal.new(eqn: eqn, sample_rate: 0.0001, size: 10000)
80
+ # digital_signal = analog_signal.to_ds
81
+
82
+ # sample_time_zero = digital_signal.data.dot digital_signal.data
83
+ # samples_per_unit = 1.0 / analog_signal.sample_rate
84
+ # puts "Output at t = tmax: #{sample_time_zero / samples_per_unit}"
85
+
86
+ #---------------------------------------------------------
87
+ #PROBLEM 4
88
+ #---------------------------------------------------------
89
+ # a_vals = [0,-0.25, 0.25, 0]
90
+ # stddev_vals = [3,1,0.5, 0.5]
91
+
92
+ # for i in 0...a_vals.length do
93
+ # a = a_vals[i]
94
+ # stddev = stddev_vals[i]
95
+ # tgauss = Digiproc::Probability::TheoreticalGaussianDistribution.new(mean: 0, stddev: stddev)
96
+ # #Build system from a gaussian distribution
97
+ # p_b = 0.5 * (0.25 * tgauss.cdf(a - 0.5) + 0.5 * tgauss.cdf(a - 1) + 0.25 * tgauss.cdf(a - 1.5)) + 0.5 * (0.25 * tgauss.q(a + 1.5) + 0.5 * tgauss.q(a + 1) + 0.25 * tgauss.q(a + 0.5))
98
+ # #Test with simplified equation
99
+ # pb_zero_test = 0.25 * prob.normal_q(0.5 / stddev) + 0.5 * prob.normal_q(1.0 / stddev) + 0.25 * prob.normal_q(1.5 / stddev)
100
+ # pb_test = (1.0 / 8) * (prob.normal_q((0.5 - a) / stddev) + prob.normal_q((0.5 + a) / stddev)) + 0.25 * (prob.normal_q((1.0 - a) / stddev) + prob.normal_q((a + 1.0) / stddev)) + (1.0/8) * (prob.normal_q((1.5 - a) / stddev) + prob.normal_q((a + 1.5) / stddev))
101
+ # puts "Test for A = #{a}, Standard Deviation = #{stddev}"
102
+ # puts "Original Eqn: #{p_b.round(4)}, Simplified Eqn: #{pb_test.round(4)}"
103
+ # puts "Equation for a = 0 reads #{pb_zero_test.round(4)}" if a == 0
104
+ # p_b.round(4) == pb_test.round(4) ? puts("Match at #{(p_b * 100).round(2)}%!") : puts("Equations do not match")
105
+ # puts "-----------------------------------------------------"
106
+ # end
107
+
108
+ # #Simulation
109
+
110
+ # def get_im(rand_gen)
111
+ # r = 1 - rand_gen.rand
112
+ # if r < 0.25
113
+ # return 0.5
114
+ # elsif r < 0.5
115
+ # return 0.5
116
+ # else
117
+ # return 0
118
+ # end
119
+ # end
120
+
121
+ # def get_am(rand_gen)
122
+ # rand_gen.rand(2) == 0 ? -1 : 1
123
+ # end
124
+
125
+
126
+
127
+ # r = Random.new
128
+ # a = 0
129
+ # stddev = 0.5
130
+ # total_runs = 500000
131
+ # error_count = 0
132
+ # normal_gen = prob.normal_random_generator(0, stddev)
133
+ # total_runs.times do
134
+ # am, nm, im = get_am(r), normal_gen.rand, get_im(r)
135
+ # ym = am + nm + im
136
+ # error_count += 1 if (am == 1 and ym < a) or (am == -1 and ym > a)
137
+ # end
138
+ # puts "Simulation for A = #{a} and Standard Deviation = #{stddev}"
139
+ # puts "Total erros: #{error_count} out of #{total_runs} trials."
140
+ # puts "Pb = #{((error_count.to_f / total_runs) * 100.0).round(2)}%"
141
+
142
+ # ------------------------------------------------------------------------------
143
+ # PROBLEM 5
144
+ # ------------------------------------------------------------------------------
145
+ # r = 10
146
+ # c = 10
147
+ # impulse_resp = ->(t){ (1.0 / (10*10)) * Math::E ** (-t / (10 * 10).to_f) }
148
+
149
+ # noise = norm_dist.new(mean: 0, stddev: 10, size: 50000)
150
+
151
+ # rc_circuit = Digiproc::DigitalSignal.new_from_eqn(eqn: impulse_resp, size: noise.size)
152
+
153
+ # noise_signal = Digiproc::DigitalSignal.new(data: noise.data)
154
+ # output_spectra = rc_circuit.fft(noise.data.length * 2) * noise_signal.fft(noise.data.length * 2)
155
+
156
+ # output_signal = output_spectra.ifft.map(&:real).take(noise.size - 1)
157
+ # variance = prob.variance(output_signal)
158
+ # puts "Varaince for RC = #{100} and Stddev: #{noise.stddev}, Variance = #{variance.round(2)}"
159
+
160
+
161
+ # total_rolls = 5000000
162
+ # diceProb = Random.new
163
+ # rolls = []
164
+ # total_rolls.times do
165
+ # roll_of_6 = []
166
+ # 5.times do
167
+ # roll_of_6 << (diceProb.rand(6) + 1)
168
+ # end
169
+ # rolls << roll_of_6
170
+ # end
171
+
172
+ # roll_3_of_a_kind = 0
173
+
174
+
175
+ # for roll in rolls do
176
+ # roll_hash = {}
177
+ # for die in roll do
178
+ # if roll_hash[die]
179
+ # roll_hash[die] += 1
180
+ # else
181
+ # roll_hash[die] = 1
182
+ # end
183
+ # end
184
+ # if roll_hash.values.any?{ |r| r >= 3}
185
+ # roll_3_of_a_kind += 1
186
+ # end
187
+ # end
188
+
189
+ # puts roll_3_of_a_kind
190
+ # puts "#{roll_3_of_a_kind / total_rolls.to_f}"
191
+
192
+ def get_individual_scores(rolls)
193
+ score = 0
194
+ remaining = rolls.values.sum
195
+
196
+ rolls.each do |die_num, num_rolls|
197
+ if die_num == 1
198
+ score += (100 * num_rolls)
199
+ remaining -= num_rolls
200
+ elsif die_num == 5
201
+ score += (50 * num_rolls)
202
+ remaining -= num_rolls
203
+ end
204
+ end
205
+ puts "HELP REMAINING IS NIL #{rolls.values}" if remaining.nil?
206
+ return [score, remaining]
207
+ end
208
+
209
+ def remove_if_val_is(val, hash)
210
+ ret_hash = {}
211
+ hash.each do |k,v|
212
+ ret_hash[k] = v unless v == val
213
+ end
214
+ ret_hash
215
+ end
216
+
217
+ def rand_choice
218
+ r = Random.new.rand(2)
219
+ if r == 1
220
+ return 3
221
+ else
222
+ return 3
223
+ end
224
+ end
225
+
226
+ def roll(num_of_dice, prob)
227
+ rolls = []
228
+ num_of_dice.times do
229
+ rolls << (prob.rand(6) + 1)
230
+ end
231
+ rolls
232
+ end
233
+
234
+ total_rolls = 100000
235
+
236
+
237
+
238
+ def turn(leftover_score = 0, num_of_dice = 6, diceProb = Random.new)
239
+ total_score = leftover_score
240
+ my_roll = roll(num_of_dice, diceProb)
241
+ score, leftover_dice = eval_score(my_roll)
242
+ leftover_dice = 6 if leftover_dice == 0
243
+ if leftover_dice <= rand_choice and score > 0
244
+ return [score + total_score, leftover_dice]
245
+ elsif score == 0
246
+ return [0, leftover_dice]
247
+ else
248
+ # binding.pry if leftover_dice.nil?
249
+ return turn(score + total_score, leftover_dice, diceProb)
250
+ end
251
+ end
252
+
253
+ def eval_score(curr_roll)
254
+ score = 0;
255
+ roll_hash = {}
256
+ for die in curr_roll do
257
+ if roll_hash[die]
258
+ roll_hash[die] += 1
259
+ else
260
+ roll_hash[die] = 1
261
+ end
262
+ end
263
+ if roll_hash.values.include?(6)
264
+ score += 2000;
265
+ return [score, 0]
266
+ elsif roll_hash.values.include?(5)
267
+ score += 1500
268
+ leftover = remove_if_val_is(5, roll_hash)
269
+ score_add, leftover_dice = get_individual_scores(leftover)
270
+ score += score_add
271
+ return [score, leftover_dice]
272
+ elsif roll_hash.values.include?(4)
273
+ if roll_hash.values.include?(2)
274
+ score += 2000
275
+ return [score, 0]
276
+ else
277
+ score += 1000
278
+ leftover = remove_if_val_is(4, roll_hash)
279
+ score_add, leftover_dice = get_individual_scores(leftover)
280
+ score += score_add
281
+ return [score, leftover_dice]
282
+ end
283
+ elsif roll_hash.values.include?(3)
284
+ if roll_hash.size == 2
285
+ score += 2500
286
+ return [score, 0]
287
+ else
288
+ if roll_hash[1] == 3
289
+ elsif roll_hash[2] == 3
290
+ score += 200
291
+ elsif roll_hash[3] == 3
292
+ score += 300
293
+ elsif roll_hash[4] == 3
294
+ score += 400
295
+ elsif roll_hash[5] == 3
296
+ score += 500
297
+ elsif roll_hash[6] == 3
298
+ score += 600
299
+ end
300
+
301
+ leftover = remove_if_val_is(3, roll_hash)
302
+ score_add, leftover_dice = get_individual_scores(leftover)
303
+ score += score_add
304
+ return [score, leftover_dice]
305
+ end
306
+ else
307
+ score_add, leftover_dice = get_individual_scores(roll_hash)
308
+ score += score_add
309
+ return [score, leftover_dice]
310
+ end
311
+ end
312
+
313
+ total_score = 0
314
+ total_dice_leftover = 0
315
+ total_rolls.times do
316
+ score, leftover_dice = turn
317
+ total_score += score
318
+ total_dice_leftover += leftover_dice
319
+ end
320
+
321
+
322
+ puts "#{total_score / total_rolls.to_f} avg score"
323
+ puts "#{total_dice_leftover / total_rolls.to_f} avg number of dice leftover"
data/plots/dpsk_2.png ADDED
Binary file
data/plots/psk_2.png ADDED
Binary file
Binary file
Binary file
Binary file
data/test-title.png ADDED
Binary file
metadata ADDED
@@ -0,0 +1,322 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digiproc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - micahshute
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: gruff
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.7.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.7.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: gruff
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.7.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.7.0
111
+ description: Allows design of digital signals using the FFT, design of Digital Filters
112
+ using the Windowing Method, creation of Digital Signals or Analog Signals sampled
113
+ at a certain interval, convolution, cross-correlation, and visualization of the
114
+ data. .
115
+ email:
116
+ - micah.shute@gmail.com
117
+ executables: []
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".gitignore"
122
+ - ".rspec"
123
+ - ".travis.yml"
124
+ - CODE_OF_CONDUCT.md
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - TODO.md
131
+ - bin/console
132
+ - bin/setup
133
+ - config/environment.rb
134
+ - console_tests.rb
135
+ - digiproc.gemspec
136
+ - examples/analog_signals/analog_to_digital.rb
137
+ - examples/analog_signals/companded-signals.png
138
+ - examples/analog_signals/companding.rb
139
+ - examples/analog_signals/fft-plot.png
140
+ - examples/analog_signals/plot_Digiproc::FFT.png
141
+ - examples/analog_signals/plot_Dsp::FFT.png
142
+ - examples/analog_signals/quantization-outputs.png
143
+ - examples/analog_signals/quantize_compand.rb
144
+ - examples/binomial_distribution/bit_error.rb
145
+ - examples/binomial_distribution/dice.rb
146
+ - examples/digital_signals/_coded_frequency_signal,_ts_=_1_s.png
147
+ - examples/digital_signals/_coded_frequency_signal,_ts_=_2_s.png
148
+ - examples/digital_signals/coded_power_spectral_density,__ts_=_1_s.png
149
+ - examples/digital_signals/coded_power_spectral_density,__ts_=_2_s.png
150
+ - examples/digital_signals/coded_time_signal,_ts_=_1_s.png
151
+ - examples/digital_signals/coded_time_signal,_ts_=_2_s.png
152
+ - examples/digital_signals/freq_sig_from_eqn,_ts_=_1_s.png
153
+ - examples/digital_signals/freq_sig_from_eqn,_ts_=_2_s.png
154
+ - examples/digital_signals/frequency_signal,_ts_=_1_s.png
155
+ - examples/digital_signals/frequency_signal,_ts_=_2_s.png
156
+ - examples/digital_signals/modulate_square_pulses.rb
157
+ - examples/digital_signals/modulated_sq._pulses.png
158
+ - examples/digital_signals/modulated_sq._pulses_alt.png
159
+ - examples/digital_signals/power_spectral_density,__ts_=_1_s.png
160
+ - examples/digital_signals/power_spectral_density,__ts_=_2_s.png
161
+ - examples/digital_signals/square_signals.rb
162
+ - examples/digital_signals/time_signal,_ts_=_1_s.png
163
+ - examples/digital_signals/time_signal,_ts_=_2_s.png
164
+ - examples/encoding/gray_code.rb
165
+ - examples/encoding/psk.rb
166
+ - examples/encoding/system_2_phase.png
167
+ - examples/encoding/system_2_xmit_signal.png
168
+ - examples/encoding/system_3_phase.png
169
+ - examples/encoding/system_3_xmit_signal.png
170
+ - examples/encoding/system_4_xmit_signal.png
171
+ - examples/encoding/xor-dpsk-phase-signal-(sys1).png
172
+ - examples/encoding/xor-dpsk-xmit-signal-(sys-1).png
173
+ - examples/factories/Quickplot Graph.png
174
+ - examples/factories/bandpass.rb
175
+ - examples/fft/plot_Dsp::FFT.png
176
+ - examples/fft/recieved_data_(time_domain).png
177
+ - examples/fft/simple_fft_example.rb
178
+ - examples/fft/unprocessed_fft.png
179
+ - examples/filters/bandpass_filter.png
180
+ - examples/filters/filter_a_signal.rb
181
+ - examples/filters/white_noise_db_out_of_bp_filter.png
182
+ - examples/filters/white_noise_mag_out_of_bp_filter.png
183
+ - examples/filters/white_noise_spectra.png
184
+ - examples/functions/compute_probability.rb
185
+ - examples/functions/gram_schmidt.rb
186
+ - examples/functions/minimize_energy.rb
187
+ - examples/functions/orthoganalize.rb
188
+ - examples/functions/simple_functions.rb
189
+ - examples/linear_algebra/diverging_sys.rb
190
+ - examples/linear_algebra/iterative_sys_of_eqns_methods.rb
191
+ - examples/modulation_schemes/dpsk_2.png
192
+ - examples/modulation_schemes/dpsk_256.png
193
+ - examples/modulation_schemes/dpsk_freq_domain.rb
194
+ - examples/modulation_schemes/psk.rb
195
+ - examples/modulation_schemes/psk_2.png
196
+ - examples/modulation_schemes/psk_256.png
197
+ - examples/modulation_schemes/psksystem_1_xmit_signal.png
198
+ - examples/modulation_schemes/psksystem_2_xmit_signal.png
199
+ - examples/modulation_schemes/psksystem_3_xmit_signal.png
200
+ - examples/modulation_schemes/system_1_xmit_signal.png
201
+ - examples/modulation_schemes/system_2_xmit_signal.png
202
+ - examples/modulation_schemes/system_3_xmit_signal.png
203
+ - examples/quickplot/PlottableClass_plot.png
204
+ - examples/quickplot/decorators.rb
205
+ - examples/quickplot/direct_gruff.png
206
+ - examples/quickplot/plot_PlottableClass.png
207
+ - examples/quickplot/quickplot_vs_others.rb
208
+ - examples/quickplot/random_data_quickplot,_dark.png
209
+ - examples/quickplot/random_data_quickplot.png
210
+ - examples/realized_gaussian/norm_dist_plot.png
211
+ - examples/realized_gaussian/norm_dist_spectrum.png
212
+ - examples/realized_gaussian/realized_gaussian_example.rb
213
+ - lib/concerns/convolvable.rb
214
+ - lib/concerns/data_properties.rb
215
+ - lib/concerns/fourier_transformable.rb
216
+ - lib/concerns/initializable.rb
217
+ - lib/concerns/multipliable.rb
218
+ - lib/concerns/os.rb
219
+ - lib/concerns/plottable.rb
220
+ - lib/concerns/requires_data.rb
221
+ - lib/digiproc.rb
222
+ - lib/digiproc/version.rb
223
+ - lib/extensions/array_extension.rb
224
+ - lib/extensions/core_extensions.rb
225
+ - lib/factories/factories.rb
226
+ - lib/factories/filter_factory.rb
227
+ - lib/factories/window_factory.rb
228
+ - lib/fft.rb
229
+ - lib/filters/bandpass_filter.rb
230
+ - lib/filters/bandstop_filter.rb
231
+ - lib/filters/digital_filter.rb
232
+ - lib/filters/highpass_filter.rb
233
+ - lib/filters/lowpass_filter.rb
234
+ - lib/functions.rb
235
+ - lib/probability/binomial_distribution.rb
236
+ - lib/probability/bit_generator.rb
237
+ - lib/probability/gaussian_distribution.rb
238
+ - lib/probability/probability.rb
239
+ - lib/probability/theoretical_gaussian_distribution.rb
240
+ - lib/quick_plot.rb
241
+ - lib/rbplot.rb
242
+ - lib/signals/analog_signal.rb
243
+ - lib/signals/digital_signal.rb
244
+ - lib/strategies/code/differential_encoding_strategy.rb
245
+ - lib/strategies/code/gray_code.rb
246
+ - lib/strategies/code/xor_differential_encoding_strategy.rb
247
+ - lib/strategies/code/xor_differential_encoding_zero_angle_strategy.rb
248
+ - lib/strategies/companding/custom_companding_strategy.rb
249
+ - lib/strategies/convolution/bf_conv.rb
250
+ - lib/strategies/fft/brute_force_dft_strategy.rb
251
+ - lib/strategies/fft/inverse_fft_conjugate_strategy.rb
252
+ - lib/strategies/fft/radix2_strategy.rb
253
+ - lib/strategies/gaussian/gaussian_generator.rb
254
+ - lib/strategies/linear_algebra/gauss_seidel_strategy.rb
255
+ - lib/strategies/linear_algebra/jacobi_strategy.rb
256
+ - lib/strategies/linear_algebra/sor2_strategy.rb
257
+ - lib/strategies/linear_algebra/sor_strategy.rb
258
+ - lib/strategies/modulation/phase_shift_keying_strategy.rb
259
+ - lib/strategies/orthogonalize/gram_schmidt.rb
260
+ - lib/strategies/strategies.rb
261
+ - lib/strategies/window/blackman_window.rb
262
+ - lib/strategies/window/hamming_window.rb
263
+ - lib/strategies/window/hanning_window.rb
264
+ - lib/strategies/window/kaiser_window.rb
265
+ - lib/strategies/window/rectangular_window.rb
266
+ - lib/strategies/window/window.rb
267
+ - lib/systems/custom_system.rb
268
+ - lib/systems/hilbert_transform.rb
269
+ - lib/systems/matched_filter.rb
270
+ - lib/systems/raised_cosine_filter.rb
271
+ - lib/systems/system.rb
272
+ - lib/systems/systems.rb
273
+ - playground.rb
274
+ - plots/_coded_frequency_signal,_ts_=_1_s.png
275
+ - plots/_coded_frequency_signal,_ts_=_2_s.png
276
+ - plots/coded_freq_sig_from_eqn,_ts_=_1_s.png
277
+ - plots/coded_freq_sig_from_eqn,_ts_=_2_s.png
278
+ - plots/coded_power_spectral_density,__ts_=_1_s.png
279
+ - plots/coded_power_spectral_density,__ts_=_2_s.png
280
+ - plots/coded_time_signal,_ts_=_1_s.png
281
+ - plots/coded_time_signal,_ts_=_2_s.png
282
+ - plots/dpsk_2.png
283
+ - plots/freq_sig_from_eqn,_ts_=_1_s.png
284
+ - plots/freq_sig_from_eqn,_ts_=_2_s.png
285
+ - plots/frequency_signal,_ts_=_1_s.png
286
+ - plots/frequency_signal,_ts_=_2_s.png
287
+ - plots/power_spectral_density,__ts_=_1_s.png
288
+ - plots/power_spectral_density,__ts_=_2_s.png
289
+ - plots/psk_2.png
290
+ - plots/time_signal,_ts_=_1_s.png
291
+ - plots/time_signal,_ts_=_2_s.png
292
+ - test-title-dark.png
293
+ - test-title.png
294
+ homepage: https://rubygems.org/gems/digiproc
295
+ licenses:
296
+ - MIT
297
+ metadata:
298
+ allowed_push_host: https://rubygems.org
299
+ homepage_uri: https://rubygems.org/gems/digiproc
300
+ source_code_uri: https://github.com/micahshute/digiproc
301
+ changelog_uri: https://github.com/micahshute/digiproc
302
+ post_install_message:
303
+ rdoc_options: []
304
+ require_paths:
305
+ - lib
306
+ required_ruby_version: !ruby/object:Gem::Requirement
307
+ requirements:
308
+ - - ">="
309
+ - !ruby/object:Gem::Version
310
+ version: '0'
311
+ required_rubygems_version: !ruby/object:Gem::Requirement
312
+ requirements:
313
+ - - ">="
314
+ - !ruby/object:Gem::Version
315
+ version: '0'
316
+ requirements: []
317
+ rubygems_version: 3.0.3
318
+ signing_key:
319
+ specification_version: 4
320
+ summary: Perform basic Digital Signal Processing tasks, including convolution, fft,
321
+ filtering.
322
+ test_files: []