spcore 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/ChangeLog.rdoc +14 -1
  2. data/README.rdoc +10 -2
  3. data/lib/spcore.rb +45 -14
  4. data/lib/spcore/{lib → core}/circular_buffer.rb +28 -1
  5. data/lib/spcore/core/constants.rb +7 -1
  6. data/lib/spcore/{lib → core}/delay_line.rb +15 -5
  7. data/lib/spcore/{lib → core}/envelope_detector.rb +13 -1
  8. data/lib/spcore/{lib → core}/oscillator.rb +33 -3
  9. data/lib/spcore/core/signal.rb +350 -0
  10. data/lib/spcore/filters/fir/dual_sinc_filter.rb +84 -0
  11. data/lib/spcore/filters/fir/fir.rb +87 -0
  12. data/lib/spcore/filters/fir/sinc_filter.rb +68 -0
  13. data/lib/spcore/{lib → filters/iir}/biquad_filter.rb +7 -0
  14. data/lib/spcore/{lib → filters/iir}/cookbook_allpass_filter.rb +2 -0
  15. data/lib/spcore/{lib → filters/iir}/cookbook_bandpass_filter.rb +2 -0
  16. data/lib/spcore/{lib → filters/iir}/cookbook_highpass_filter.rb +2 -0
  17. data/lib/spcore/{lib → filters/iir}/cookbook_lowpass_filter.rb +2 -0
  18. data/lib/spcore/{lib → filters/iir}/cookbook_notch_filter.rb +2 -0
  19. data/lib/spcore/interpolation/interpolation.rb +64 -0
  20. data/lib/spcore/resampling/discrete_resampling.rb +78 -0
  21. data/lib/spcore/resampling/hybrid_resampling.rb +30 -0
  22. data/lib/spcore/resampling/polynomial_resampling.rb +56 -0
  23. data/lib/spcore/transforms/dft.rb +47 -0
  24. data/lib/spcore/transforms/fft.rb +125 -0
  25. data/lib/spcore/{lib → util}/gain.rb +3 -0
  26. data/lib/spcore/{core → util}/limiters.rb +10 -1
  27. data/lib/spcore/util/plotter.rb +91 -0
  28. data/lib/spcore/{lib → util}/saturation.rb +2 -9
  29. data/lib/spcore/util/scale.rb +41 -0
  30. data/lib/spcore/util/signal_generator.rb +48 -0
  31. data/lib/spcore/version.rb +2 -1
  32. data/lib/spcore/windows/bartlett_hann_window.rb +15 -0
  33. data/lib/spcore/windows/bartlett_window.rb +13 -0
  34. data/lib/spcore/windows/blackman_harris_window.rb +14 -0
  35. data/lib/spcore/windows/blackman_nuttall_window.rb +14 -0
  36. data/lib/spcore/windows/blackman_window.rb +18 -0
  37. data/lib/spcore/windows/cosine_window.rb +13 -0
  38. data/lib/spcore/windows/flat_top_window.rb +27 -0
  39. data/lib/spcore/windows/gaussian_window.rb +15 -0
  40. data/lib/spcore/windows/hamming_window.rb +16 -0
  41. data/lib/spcore/windows/hann_window.rb +13 -0
  42. data/lib/spcore/windows/lanczos_window.rb +15 -0
  43. data/lib/spcore/windows/nuttall_window.rb +14 -0
  44. data/lib/spcore/windows/rectangular_window.rb +10 -0
  45. data/lib/spcore/windows/triangular_window.rb +14 -0
  46. data/spcore.gemspec +11 -3
  47. data/spec/{lib → core}/circular_buffer_spec.rb +0 -0
  48. data/spec/{lib → core}/delay_line_spec.rb +1 -1
  49. data/spec/{lib → core}/envelope_detector_spec.rb +3 -3
  50. data/spec/{lib → core}/oscillator_spec.rb +0 -0
  51. data/spec/filters/fir/dual_sinc_filter_spec.rb +64 -0
  52. data/spec/filters/fir/sinc_filter_spec.rb +57 -0
  53. data/spec/filters/iir/cookbook_filter_spec.rb +30 -0
  54. data/spec/interpolation/interpolation_spec.rb +49 -0
  55. data/spec/resampling/discrete_resampling_spec.rb +81 -0
  56. data/spec/resampling/hybrid_resampling_spec.rb +31 -0
  57. data/spec/resampling/polynomial_resampling_spec.rb +30 -0
  58. data/spec/transforms/dft_spec.rb +71 -0
  59. data/spec/transforms/fft_spec.rb +84 -0
  60. data/spec/{lib → util}/gain_spec.rb +2 -2
  61. data/spec/{core → util}/limiters_spec.rb +0 -0
  62. data/spec/{lib → util}/saturate_spec.rb +0 -0
  63. data/spec/util/signal_generator_spec.rb +54 -0
  64. data/spec/windows/window_spec.rb +33 -0
  65. metadata +90 -42
  66. data/lib/spcore/lib/interpolation.rb +0 -15
  67. data/spec/lib/cookbook_filter_spec.rb +0 -44
  68. data/spec/lib/interpolation_spec.rb +0 -21
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe 'windows' do
4
+ it 'should produce a window that looks like...' do
5
+ size = 512
6
+
7
+ window_classes = [
8
+ #SPCore::RectangularWindow,
9
+ #SPCore::HannWindow,
10
+ #SPCore::HammingWindow,
11
+ #SPCore::CosineWindow,
12
+ #SPCore::LanczosWindow,
13
+ #SPCore::TriangularWindow,
14
+ #SPCore::BartlettWindow,
15
+ #SPCore::GaussianWindow,
16
+ #SPCore::BartlettHannWindow,
17
+ #SPCore::BlackmanWindow,
18
+ #SPCore::NuttallWindow,
19
+ #SPCore::BlackmanHarrisWindow,
20
+ #SPCore::BlackmanNuttallWindow,
21
+ #SPCore::FlatTopWindow
22
+ ]
23
+
24
+ windows = {}
25
+ window_classes.each do |window_class|
26
+ windows[window_class.to_s] = window_class.new(size).data
27
+ end
28
+
29
+ if windows.any?
30
+ Plotter.new(:title => "windows").plot_1d windows
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spcore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-05 00:00:00.000000000 Z
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashmake
@@ -123,10 +123,15 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
- description: ! "Contains core signal processing functions, including:\n Delay line\n
127
- \ Biquad filters\n Envelope detector\n Conversion from dB-linear and linear-dB\n
128
- \ Linear interpolation\n Oscillator with selectable wave type (sine, square, triangle,
129
- sawtooth)\n\n"
126
+ description: ! "Contains core signal processing methods and classes, including:\n
127
+ \ Resampling (discrete up, down and up/down, polynomial up, and hybrid up/down)\n
128
+ \ FFT transform (forward and inverse)\n DFT transform (forward and inverse)\n Windows
129
+ (Blackman, Hamming, etc.)\n Windowed sinc filter for lowpass and highpass.\n Dual
130
+ windowed sinc filter for bandpass and bandstop.\n Interpolation (linear and polynomial)\n
131
+ \ Data plotting via gnuplot (must be installed to use).\n Delay line\n Biquad
132
+ filters\n Envelope detector\n Conversion from dB-linear and linear-dB\n Oscillator
133
+ with selectable wave type (sine, square, triangle, sawtooth)\n Signal abstraction
134
+ class.\n\n"
130
135
  email: jamestunnell@lavabit.com
131
136
  executables: []
132
137
  extensions: []
@@ -142,34 +147,69 @@ files:
142
147
  - README.rdoc
143
148
  - Rakefile
144
149
  - lib/spcore.rb
150
+ - lib/spcore/core/circular_buffer.rb
145
151
  - lib/spcore/core/constants.rb
146
- - lib/spcore/core/limiters.rb
147
- - lib/spcore/lib/biquad_filter.rb
148
- - lib/spcore/lib/circular_buffer.rb
149
- - lib/spcore/lib/cookbook_allpass_filter.rb
150
- - lib/spcore/lib/cookbook_bandpass_filter.rb
151
- - lib/spcore/lib/cookbook_highpass_filter.rb
152
- - lib/spcore/lib/cookbook_lowpass_filter.rb
153
- - lib/spcore/lib/cookbook_notch_filter.rb
154
- - lib/spcore/lib/delay_line.rb
155
- - lib/spcore/lib/envelope_detector.rb
156
- - lib/spcore/lib/gain.rb
157
- - lib/spcore/lib/interpolation.rb
158
- - lib/spcore/lib/oscillator.rb
159
- - lib/spcore/lib/saturation.rb
152
+ - lib/spcore/core/delay_line.rb
153
+ - lib/spcore/core/envelope_detector.rb
154
+ - lib/spcore/core/oscillator.rb
155
+ - lib/spcore/core/signal.rb
156
+ - lib/spcore/filters/fir/dual_sinc_filter.rb
157
+ - lib/spcore/filters/fir/fir.rb
158
+ - lib/spcore/filters/fir/sinc_filter.rb
159
+ - lib/spcore/filters/iir/biquad_filter.rb
160
+ - lib/spcore/filters/iir/cookbook_allpass_filter.rb
161
+ - lib/spcore/filters/iir/cookbook_bandpass_filter.rb
162
+ - lib/spcore/filters/iir/cookbook_highpass_filter.rb
163
+ - lib/spcore/filters/iir/cookbook_lowpass_filter.rb
164
+ - lib/spcore/filters/iir/cookbook_notch_filter.rb
165
+ - lib/spcore/interpolation/interpolation.rb
166
+ - lib/spcore/resampling/discrete_resampling.rb
167
+ - lib/spcore/resampling/hybrid_resampling.rb
168
+ - lib/spcore/resampling/polynomial_resampling.rb
169
+ - lib/spcore/transforms/dft.rb
170
+ - lib/spcore/transforms/fft.rb
171
+ - lib/spcore/util/gain.rb
172
+ - lib/spcore/util/limiters.rb
173
+ - lib/spcore/util/plotter.rb
174
+ - lib/spcore/util/saturation.rb
175
+ - lib/spcore/util/scale.rb
176
+ - lib/spcore/util/signal_generator.rb
160
177
  - lib/spcore/version.rb
178
+ - lib/spcore/windows/bartlett_hann_window.rb
179
+ - lib/spcore/windows/bartlett_window.rb
180
+ - lib/spcore/windows/blackman_harris_window.rb
181
+ - lib/spcore/windows/blackman_nuttall_window.rb
182
+ - lib/spcore/windows/blackman_window.rb
183
+ - lib/spcore/windows/cosine_window.rb
184
+ - lib/spcore/windows/flat_top_window.rb
185
+ - lib/spcore/windows/gaussian_window.rb
186
+ - lib/spcore/windows/hamming_window.rb
187
+ - lib/spcore/windows/hann_window.rb
188
+ - lib/spcore/windows/lanczos_window.rb
189
+ - lib/spcore/windows/nuttall_window.rb
190
+ - lib/spcore/windows/rectangular_window.rb
191
+ - lib/spcore/windows/triangular_window.rb
161
192
  - spcore.gemspec
162
- - spec/core/limiters_spec.rb
163
- - spec/lib/circular_buffer_spec.rb
164
- - spec/lib/cookbook_filter_spec.rb
165
- - spec/lib/delay_line_spec.rb
166
- - spec/lib/envelope_detector_spec.rb
167
- - spec/lib/gain_spec.rb
168
- - spec/lib/interpolation_spec.rb
169
- - spec/lib/oscillator_spec.rb
170
- - spec/lib/saturate_spec.rb
193
+ - spec/core/circular_buffer_spec.rb
194
+ - spec/core/delay_line_spec.rb
195
+ - spec/core/envelope_detector_spec.rb
196
+ - spec/core/oscillator_spec.rb
197
+ - spec/filters/fir/dual_sinc_filter_spec.rb
198
+ - spec/filters/fir/sinc_filter_spec.rb
199
+ - spec/filters/iir/cookbook_filter_spec.rb
200
+ - spec/interpolation/interpolation_spec.rb
201
+ - spec/resampling/discrete_resampling_spec.rb
202
+ - spec/resampling/hybrid_resampling_spec.rb
203
+ - spec/resampling/polynomial_resampling_spec.rb
171
204
  - spec/sigproc_spec.rb
172
205
  - spec/spec_helper.rb
206
+ - spec/transforms/dft_spec.rb
207
+ - spec/transforms/fft_spec.rb
208
+ - spec/util/gain_spec.rb
209
+ - spec/util/limiters_spec.rb
210
+ - spec/util/saturate_spec.rb
211
+ - spec/util/signal_generator_spec.rb
212
+ - spec/windows/window_spec.rb
173
213
  homepage: https://rubygems.org/gems/spcore
174
214
  licenses:
175
215
  - MIT
@@ -185,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
225
  version: '0'
186
226
  segments:
187
227
  - 0
188
- hash: 139506735
228
+ hash: 272931151
189
229
  required_rubygems_version: !ruby/object:Gem::Requirement
190
230
  none: false
191
231
  requirements:
@@ -194,24 +234,32 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
234
  version: '0'
195
235
  segments:
196
236
  - 0
197
- hash: 139506735
237
+ hash: 272931151
198
238
  requirements: []
199
239
  rubyforge_project:
200
240
  rubygems_version: 1.8.23
201
241
  signing_key:
202
242
  specification_version: 3
203
- summary: Perform basic signal processing functions (delay line, filters, envelope
204
- detection, etc...).
243
+ summary: A library of signal processing methods and classes.
205
244
  test_files:
206
- - spec/core/limiters_spec.rb
207
- - spec/lib/circular_buffer_spec.rb
208
- - spec/lib/cookbook_filter_spec.rb
209
- - spec/lib/delay_line_spec.rb
210
- - spec/lib/envelope_detector_spec.rb
211
- - spec/lib/gain_spec.rb
212
- - spec/lib/interpolation_spec.rb
213
- - spec/lib/oscillator_spec.rb
214
- - spec/lib/saturate_spec.rb
245
+ - spec/core/circular_buffer_spec.rb
246
+ - spec/core/delay_line_spec.rb
247
+ - spec/core/envelope_detector_spec.rb
248
+ - spec/core/oscillator_spec.rb
249
+ - spec/filters/fir/dual_sinc_filter_spec.rb
250
+ - spec/filters/fir/sinc_filter_spec.rb
251
+ - spec/filters/iir/cookbook_filter_spec.rb
252
+ - spec/interpolation/interpolation_spec.rb
253
+ - spec/resampling/discrete_resampling_spec.rb
254
+ - spec/resampling/hybrid_resampling_spec.rb
255
+ - spec/resampling/polynomial_resampling_spec.rb
215
256
  - spec/sigproc_spec.rb
216
257
  - spec/spec_helper.rb
258
+ - spec/transforms/dft_spec.rb
259
+ - spec/transforms/fft_spec.rb
260
+ - spec/util/gain_spec.rb
261
+ - spec/util/limiters_spec.rb
262
+ - spec/util/saturate_spec.rb
263
+ - spec/util/signal_generator_spec.rb
264
+ - spec/windows/window_spec.rb
217
265
  has_rdoc:
@@ -1,15 +0,0 @@
1
- module SPCore
2
- class Interpolation
3
- # Linear Interpolation Equation:
4
- #
5
- # (x3 - x1)(y2 - y1)
6
- # y3 = ------------------ + y1
7
- # (x2 - x1)
8
- #
9
- def self.linear x1, y1, x2, y2, x3
10
- y3 = ((x3 - x1) * (y2 - y1)) / (x2 - x1);
11
- y3 += y1;
12
- return y3;
13
- end
14
- end
15
- end
@@ -1,44 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'gnuplot'
3
- require 'pry'
4
-
5
- describe 'cookbook filter' do
6
- #it 'should produce a nice frequency response graph' do
7
- # sample_rate = 44000.0
8
- # crit_freq = 1000.0
9
- # max_test_freq = 10000.0
10
- # bw = 2
11
- # filter = SPCore::CookbookNotchFilter.new sample_rate
12
- # filter.set_critical_freq_and_bw crit_freq, bw
13
- #
14
- # freqs = []
15
- # dbs = []
16
- #
17
- # start_freq = 10.0
18
- # test_freq = start_freq
19
- #
20
- # 200.times do
21
- # mag = filter.get_freq_magnitude_response test_freq
22
- #
23
- # dbs << SPCore::Gain.linear_to_db(mag)
24
- # freqs << test_freq
25
- #
26
- # test_freq *= 1.035
27
- # end
28
- #
29
- # Gnuplot.open do |gp|
30
- # Gnuplot::Plot.new(gp) do |plot|
31
- # plot.title "Frequency Magnitude Response for Lowpass Filter with Critical Freq of #{crit_freq} and BW of #{bw}"
32
- # plot.xlabel "Frequency (f)"
33
- # plot.ylabel "Frequency Magnitude Response (dB) at f"
34
- # plot.logscale 'x'
35
- #
36
- # plot.data << Gnuplot::DataSet.new( [freqs, dbs] ) do |ds|
37
- # ds.with = "linespoints"
38
- # #ds.linewidth = 4
39
- # end
40
- # end
41
- # end
42
- #
43
- #end
44
- end
@@ -1,21 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe SPCore::Interpolation do
4
- context '.interpolate_linear' do
5
- it 'should interpolate floating-point values' do
6
- x1, y1 = 0.0, 2.0
7
- x2, y2 = 1.0, 4.0
8
- x3, y3 = 0.5, 3.0
9
- result = SPCore::Interpolation.linear x1, y1, x2, y2, x3
10
- result.should eq(y3)
11
- end
12
-
13
- it 'should interpolate integer values' do
14
- x1, y1 = 0, 20
15
- x2, y2 = 10, 40
16
- x3, y3 = 5, 30
17
- result = SPCore::Interpolation.linear x1, y1, x2, y2, x3
18
- result.should eq(y3)
19
- end
20
- end
21
- end