Class: Roctave::FirFilter
- Inherits:
-
Object
- Object
- Roctave::FirFilter
- Includes:
- Filter
- Defined in:
- lib/roctave/fir.rb,
ext/roctave/fir_filter.c
Class Method Summary collapse
-
.band_pass(*args) ⇒ Roctave::FirFilter
Returns a band-pass FIR filter.
-
.band_stop(*args) ⇒ Roctave::FirFilter
Returns a band-stop FIR filter.
-
.differentiator(*args) ⇒ Roctave::FirFilter
Returns a discriminator FIR filter.
-
.finite_difference_coefficients(*args) ⇒ Roctave::FirFilter
Returns a kind of discriminator FIR filter.
-
.fir1(*args) ⇒ Roctave::FirFilter
Matlab-like
fir1
function to generate a FIR filter. -
.fir2(*args) ⇒ Roctave::FirFilter
Matlab-like
fir2
function to generate a FIR filter. -
.firls(*args) ⇒ Roctave::FirFilter
Least square method to generate a FIR filter.
-
.firpm(*args) ⇒ Roctave::FirFilter
Least Parks-McClellan method to generate a FIR filter.
-
.high_pass(*args) ⇒ Roctave::FirFilter
Returns a high-pass FIR filter.
-
.hilbert(*args) ⇒ Roctave::FirFilter
Returns a Hilbert transformer FIR filter.
-
.low_pass(*args) ⇒ Roctave::FirFilter
Returns a low-pass FIR filter.
Instance Method Summary collapse
- #clone ⇒ Roctave::FirFilter
-
#decimation_factor ⇒ Ingeger?
If the filter is a decimator, returns the decimation factor,
nil
otherwise. -
#decimation_factor=(factor) ⇒ Object
Make the filter a decimator.
-
#decimator? ⇒ Boolean
Whether the filter is a decimator or not.
-
#denominator ⇒ Array<Float>
Return a copy of the filter’s denominator coefficients as an array, allways [1.0].
-
#filter(sample) ⇒ Float, ...
A single or an array of processed samples.
-
#filter_with_delay(sample) ⇒ Array<Float>, Array<Array{Float}>
An array containing the filtered signal, an the input signal delayed by n/2.
- #freqz(*args) ⇒ Object
-
#get_den_coefficient_at(index) ⇒ Float
This method returns 1.0 if
index
= 0, 0.0 otherwise. -
#get_num_coefficient_at(index) ⇒ Float
(also: #get_coefficient_at)
The coefficient at index.
- #initialize(b_or_n) ⇒ Object constructor
-
#interpolation_factor ⇒ Ingeger?
If the filter is an interpolator, returns the interpolation factor,
nil
otherwise. -
#interpolation_factor=(factor) ⇒ Object
Make the filter an interpolator.
-
#interpolator? ⇒ Boolean
Whether the filter is an interpolator or not.
-
#nb_coefficients ⇒ Integer
Number of coefficients (order + 1).
-
#numerator ⇒ Array<Float>
(also: #coefficients)
Return a copy of the filter’s numerator coefficients as an array.
-
#order ⇒ Integer
The filter order.
-
#push(sample) ⇒ Object
(also: #<<)
Push a sample in the filter state.
-
#regular? ⇒ Boolean
Whether the filter is regular or not (not a decimator or interpolator).
-
#reset! ⇒ Object
Reset the filter state.
-
#set_den_coefficient_at(index, coef) ⇒ Float?
This method noes nothing, it is there to be compatible with Roctave::IirFilter.
-
#set_num_coefficient_at(index, coef) ⇒ Float?
(also: #set_coefficient_at)
The coefficient if the index is valid, or nil otherwise.
- #stem(*args) ⇒ Object
- #zplane ⇒ Object
Methods included from Filter
Constructor Details
#initialize(n) ⇒ Object #initialize(b) ⇒ Object
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
# File 'ext/roctave/fir_filter.c', line 555
static VALUE fir_filter_initialize(VALUE self, VALUE b_or_n)
{
struct fir_filter *flt;
int i, len;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
if (rb_class_of(b_or_n) == rb_cInteger) {
flt->nb_coefficients = NUM2INT(b_or_n) + 1;
if (flt->nb_coefficients < 2)
rb_raise(rb_eArgError, "Order cannot be less than 1");
if (flt->nb_coefficients > 1048577)
rb_raise(rb_eArgError, "Order cannot be more than 1048576");
flt->b = calloc(flt->nb_coefficients, sizeof(double));
if (!flt->b)
rb_raise(rb_eRuntimeError, "Failed to allocate %lu bytes of coefficient storage", flt->nb_coefficients*sizeof(double));
}
else if (rb_class_of(b_or_n) == rb_cArray) {
len = rb_array_len(b_or_n);
if (len > 1048577)
rb_raise(rb_eArgError, "Cannot be more than 1048577 coefficients");
if (len < 1)
rb_raise(rb_eArgError, "Coefficient array is empty");
flt->nb_coefficients = len;
flt->b = calloc(flt->nb_coefficients, sizeof(double));
if (!flt->b)
rb_raise(rb_eRuntimeError, "Failed to allocate %lu bytes of coefficient storage", flt->nb_coefficients*sizeof(double));
for (i = 0; i < len; i++)
flt->b[flt->nb_coefficients - 1 - i] = (double)(NUM2DBL(rb_ary_entry(b_or_n, i)));
}
else
rb_raise(rb_eArgError, "Expecting the filter order (Integer) or the filter coefficients (Array<Float>)");
flt->state_length = (int)(pow(2.0, ceil(log2((double)flt->nb_coefficients))));
flt->index_mask = flt->state_length - 1;
flt->index = 0;
flt->state = calloc(flt->state_length, sizeof(double));
if (!flt->state)
rb_raise(rb_eRuntimeError, "Failed to allocate %lu bytes of state storage", flt->state_length*sizeof(double));
flt->stateim = NULL;
flt->push_one_sample_func = &push_one_sample_float;
flt->filter_one_sample_func = &filter_one_sample_float;
return self;
}
|
Class Method Details
.band_pass(*args) ⇒ Roctave::FirFilter
Returns a band-pass FIR filter.
74 75 76 |
# File 'lib/roctave/fir.rb', line 74 def self.band_pass (*args) Roctave::FirFilter.new Roctave.fir_band_pass(*args) end |
.band_stop(*args) ⇒ Roctave::FirFilter
Returns a band-stop FIR filter.
81 82 83 |
# File 'lib/roctave/fir.rb', line 81 def self.band_stop (*args) Roctave::FirFilter.new Roctave.fir_band_stop(*args) end |
.differentiator(*args) ⇒ Roctave::FirFilter
Returns a discriminator FIR filter.
95 96 97 |
# File 'lib/roctave/fir.rb', line 95 def self.differentiator (*args) Roctave::FirFilter.new Roctave.fir_differentiator(*args) end |
.finite_difference_coefficients(*args) ⇒ Roctave::FirFilter
Returns a kind of discriminator FIR filter.
102 103 104 |
# File 'lib/roctave/fir.rb', line 102 def self.finite_difference_coefficients (*args) Roctave::FirFilter.new Roctave.finite_difference_coefficients(*args) end |
.fir1(*args) ⇒ Roctave::FirFilter
Matlab-like fir1
function to generate a FIR filter.
46 47 48 |
# File 'lib/roctave/fir.rb', line 46 def self.fir1 (*args) Roctave::FirFilter.new Roctave.fir1(*args) end |
.fir2(*args) ⇒ Roctave::FirFilter
Matlab-like fir2
function to generate a FIR filter.
53 54 55 |
# File 'lib/roctave/fir.rb', line 53 def self.fir2 (*args) Roctave::FirFilter.new Roctave.fir2(*args) end |
.firls(*args) ⇒ Roctave::FirFilter
Least square method to generate a FIR filter.
109 110 111 |
# File 'lib/roctave/fir.rb', line 109 def self.firls (*args) Roctave::FirFilter.new Roctave.firls(*args) end |
.firpm(*args) ⇒ Roctave::FirFilter
Least Parks-McClellan method to generate a FIR filter.
116 117 118 |
# File 'lib/roctave/fir.rb', line 116 def self.firpm (*args) Roctave::FirFilter.new Roctave.firpm(*args) end |
.high_pass(*args) ⇒ Roctave::FirFilter
Returns a high-pass FIR filter.
67 68 69 |
# File 'lib/roctave/fir.rb', line 67 def self.high_pass (*args) Roctave::FirFilter.new Roctave.fir_high_pass(*args) end |
.hilbert(*args) ⇒ Roctave::FirFilter
Returns a Hilbert transformer FIR filter.
88 89 90 |
# File 'lib/roctave/fir.rb', line 88 def self.hilbert (*args) Roctave::FirFilter.new Roctave.fir_hilbert(*args) end |
.low_pass(*args) ⇒ Roctave::FirFilter
Returns a low-pass FIR filter.
60 61 62 |
# File 'lib/roctave/fir.rb', line 60 def self.low_pass (*args) Roctave::FirFilter.new Roctave.fir_low_pass(*args) end |
Instance Method Details
#clone ⇒ Roctave::FirFilter
39 40 41 |
# File 'lib/roctave/fir.rb', line 39 def clone Roctave::FirFilter.new numerator end |
#decimation_factor ⇒ Ingeger?
Returns if the filter is a decimator, returns the decimation factor, nil
otherwise.
681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'ext/roctave/fir_filter.c', line 681
static VALUE fir_filter_get_decimation_factor(VALUE self)
{
struct fir_filter *flt;
VALUE res = Qnil;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
if (FIR_FILTER_IS_DECIMATOR(flt))
res = INT2NUM(flt->max_counter);
return res;
}
|
#decimation_factor=(factor) ⇒ Object
Make the filter a decimator
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
# File 'ext/roctave/fir_filter.c', line 698
static VALUE fir_filter_set_decimation_factor(VALUE self, VALUE factor)
{
struct fir_filter *flt;
int fctr;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
fctr = NUM2INT(factor);
if (fctr > 1) {
flt->decimator_interpolator = FIR_FILTER_DECIMATOR_FLAG;
flt->max_counter = fctr;
}
else {
flt->decimator_interpolator = 0;
flt->max_counter = 1;
}
flt->counter = 0;
return self;
}
|
#decimator? ⇒ Boolean
Returns whether the filter is a decimator or not.
633 634 635 636 637 638 639 640 641 642 643 644 |
# File 'ext/roctave/fir_filter.c', line 633
static VALUE fir_filter_is_decimator(VALUE self)
{
struct fir_filter *flt;
VALUE res = Qfalse;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
if (FIR_FILTER_IS_DECIMATOR(flt))
res = Qtrue;
return res;
}
|
#denominator ⇒ Array<Float>
Return a copy of the filter’s denominator coefficients as an array, allways [1.0].
231 232 233 234 235 236 |
# File 'ext/roctave/fir_filter.c', line 231
static VALUE fir_filter_denominator(VALUE self)
{
VALUE res = rb_ary_new_capa(1);
rb_ary_store(res, 0, DBL2NUM(1.0));
return res;
}
|
#filter(sample) ⇒ Float, ...
Returns a single or an array of processed samples.
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'ext/roctave/fir_filter.c', line 348
static VALUE fir_filter_filter(VALUE self, VALUE sample)
{
struct fir_filter *flt;
VALUE res = Qnil;
int i, j, len, outlen;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
if (RB_FLOAT_TYPE_P(sample) || rb_obj_is_kind_of(sample, rb_cNumeric)) {
switch (flt->decimator_interpolator) {
case FIR_FILTER_DECIMATOR_FLAG:
if (flt->counter)
(*flt->push_one_sample_func)(flt, sample);
else
res = (*flt->filter_one_sample_func)(flt, sample, NULL, 1.0);
flt->counter = (flt->counter + 1) % flt->max_counter;
break;
case FIR_FILTER_INTERPOLATOR_FLAG:
len = flt->max_counter;
res = rb_ary_new_capa(len);
rb_ary_store(res, 0, (*flt->filter_one_sample_func)(flt, sample, NULL, (double)len));
for (i = 1; i < len; i++)
rb_ary_store(res, i, (*flt->filter_one_sample_func)(flt, flt->zero, NULL, (double)len));
break;
default:
res = (*flt->filter_one_sample_func)(flt, sample, NULL, 1.0);
}
}
else if (rb_class_of(sample) == rb_cArray) {
len = rb_array_len(sample);
switch (flt->decimator_interpolator) {
case FIR_FILTER_DECIMATOR_FLAG:
outlen = (int)ceil((double)(len - ((flt->max_counter - flt->counter) % flt->max_counter)) / (double)flt->max_counter);
res = rb_ary_new_capa(outlen);
for (i = 0, j = 0; i < len; i++) {
if (flt->counter)
(*flt->push_one_sample_func)(flt, rb_ary_entry(sample, i));
else
rb_ary_store(res, j++, (*flt->filter_one_sample_func)(flt, rb_ary_entry(sample, i), NULL, 1.0));
flt->counter = (flt->counter + 1) % flt->max_counter;
}
break;
case FIR_FILTER_INTERPOLATOR_FLAG:
res = rb_ary_new_capa(len*flt->max_counter);
for (i = 0; i < len; i++) {
rb_ary_store(res, i*flt->max_counter, (*flt->filter_one_sample_func)(flt, rb_ary_entry(sample, i), NULL, (double)flt->max_counter));
for (j = 1; j < flt->max_counter; j++)
rb_ary_store(res, i*flt->max_counter+j, (*flt->filter_one_sample_func)(flt, flt->zero, NULL, (double)flt->max_counter));
}
break;
default:
res = rb_ary_new_capa(len);
for (i = 0; i < len; i++)
rb_ary_store(res, i, (*flt->filter_one_sample_func)(flt, rb_ary_entry(sample, i), NULL, 1.0));
}
}
else
rb_raise(rb_eArgError, "Expecting a single Numeric or an Array of Numeric");
return res;
}
|
#filter_with_delay(sample) ⇒ Array<Float>, Array<Array{Float}>
Returns an array containing the filtered signal, an the input signal delayed by n/2.
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'ext/roctave/fir_filter.c', line 414
static VALUE fir_filter_filter_with_delay(VALUE self, VALUE sample)
{
struct fir_filter *flt;
VALUE res = Qnil;
VALUE artwo;
VALUE delayed = Qnil;
VALUE rbval;
int i, j, len, outlen;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
artwo = rb_ary_new_capa(2);
if (RB_FLOAT_TYPE_P(sample) || rb_obj_is_kind_of(sample, rb_cNumeric)) {
switch (flt->decimator_interpolator) {
case FIR_FILTER_DECIMATOR_FLAG:
if (flt->counter)
(*flt->push_one_sample_func)(flt, sample);
else
res = (*flt->filter_one_sample_func)(flt, sample, &delayed, 1.0);
flt->counter = (flt->counter + 1) % flt->max_counter;
break;
case FIR_FILTER_INTERPOLATOR_FLAG:
len = flt->max_counter;
res = rb_ary_new_capa(len);
delayed = rb_ary_new_capa(len);
rb_ary_store(res, 0, (*flt->filter_one_sample_func)(flt, sample, &rbval, (double)len));
rb_ary_store(delayed, 0, rbval);
for (i = 1; i < len; i++) {
rb_ary_store(res, i, (*flt->filter_one_sample_func)(flt, flt->zero, &rbval, (double)len));
rb_ary_store(delayed, i, rbval);
}
break;
default:
res = (*flt->filter_one_sample_func)(flt, sample, &delayed, 1.0);
}
}
else if (rb_class_of(sample) == rb_cArray) {
len = rb_array_len(sample);
switch (flt->decimator_interpolator) {
case FIR_FILTER_DECIMATOR_FLAG:
outlen = (int)ceil((double)(len - ((flt->max_counter - flt->counter) % flt->max_counter)) / (double)flt->max_counter);
res = rb_ary_new_capa(outlen);
delayed = rb_ary_new_capa(outlen);
for (i = 0, j = 0; i < len; i++) {
if (flt->counter)
(*flt->push_one_sample_func)(flt, rb_ary_entry(sample, i));
else {
rb_ary_store(res, j, (*flt->filter_one_sample_func)(flt, rb_ary_entry(sample, i), &rbval, 1.0));
rb_ary_store(delayed, j++, rbval);
}
flt->counter = (flt->counter + 1) % flt->max_counter;
}
break;
case FIR_FILTER_INTERPOLATOR_FLAG:
res = rb_ary_new_capa(len*flt->max_counter);
delayed = rb_ary_new_capa(len*flt->max_counter);
for (i = 0; i < len; i++) {
rb_ary_store(res, i*flt->max_counter, (*flt->filter_one_sample_func)(flt, rb_ary_entry(sample, i), &rbval, (double)flt->max_counter));
rb_ary_store(delayed, i*flt->max_counter, rbval);
for (j = 1; j < flt->max_counter; j++) {
rb_ary_store(res, i*flt->max_counter+j, (*flt->filter_one_sample_func)(flt, flt->zero, &rbval, (double)flt->max_counter));
rb_ary_store(delayed, i*flt->max_counter+j, rbval);
}
}
break;
default:
res = rb_ary_new_capa(len);
delayed = rb_ary_new_capa(len);
for (i = 0; i < len; i++) {
rb_ary_store(res, i, (*flt->filter_one_sample_func)(flt, rb_ary_entry(sample, i), &rbval, 1.0));
rb_ary_store(delayed, i, rbval);
}
}
}
else
rb_raise(rb_eArgError, "Expecting a single Numeric or an Array of Numeric");
rb_ary_store(artwo, 0, res);
rb_ary_store(artwo, 1, delayed);
return artwo;
}
|
#freqz(*args) ⇒ Object
24 25 26 |
# File 'lib/roctave/fir.rb', line 24 def freqz (*args) Roctave.freqz(numerator, *args) end |
#get_den_coefficient_at(index) ⇒ Float
This method returns 1.0 if index
= 0, 0.0 otherwise. It is there to be compatible with Roctave::IirFilter
194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'ext/roctave/fir_filter.c', line 194
static VALUE fir_filter_get_denominator_at(VALUE self, VALUE index)
{
int ind;
VALUE res;
ind = NUM2INT(index);
if (ind == 0)
res = DBL2NUM(1.0);
else
res = DBL2NUM(0.0);
return res;
}
|
#get_num_coefficient_at(index) ⇒ Float Also known as: get_coefficient_at
Returns the coefficient at index.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'ext/roctave/fir_filter.c', line 157
static VALUE fir_filter_get_coefficient_at(VALUE self, VALUE index)
{
struct fir_filter *flt;
int ind;
VALUE res = Qnil;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
ind = NUM2INT(index);
if (ind >= 0 && ind < flt->nb_coefficients)
res = DBL2NUM(flt->b[flt->nb_coefficients - 1 - ind]);
else
res = DBL2NUM(0.0);
return res;
}
|
#interpolation_factor ⇒ Ingeger?
Returns if the filter is an interpolator, returns the interpolation factor, nil
otherwise.
722 723 724 725 726 727 728 729 730 731 732 733 |
# File 'ext/roctave/fir_filter.c', line 722
static VALUE fir_filter_get_interpolation_factor(VALUE self)
{
struct fir_filter *flt;
VALUE res = Qnil;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
if (FIR_FILTER_IS_INTERPOLATOR(flt))
res = INT2NUM(flt->max_counter);
return res;
}
|
#interpolation_factor=(factor) ⇒ Object
Make the filter an interpolator
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
# File 'ext/roctave/fir_filter.c', line 739
static VALUE fir_filter_set_interpolation_factor(VALUE self, VALUE factor)
{
struct fir_filter *flt;
int fctr;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
fctr = NUM2INT(factor);
if (fctr > 1) {
flt->decimator_interpolator = FIR_FILTER_INTERPOLATOR_FLAG;
flt->max_counter = fctr;
}
else {
flt->decimator_interpolator = 0;
flt->max_counter = 1;
}
flt->counter = 0;
return self;
}
|
#interpolator? ⇒ Boolean
Returns whether the filter is an interpolator or not.
649 650 651 652 653 654 655 656 657 658 659 660 |
# File 'ext/roctave/fir_filter.c', line 649
static VALUE fir_filter_is_interpolator(VALUE self)
{
struct fir_filter *flt;
VALUE res = Qfalse;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
if (FIR_FILTER_IS_INTERPOLATOR(flt))
res = Qtrue;
return res;
}
|
#nb_coefficients ⇒ Integer
Returns number of coefficients (order + 1).
120 121 122 123 124 125 126 127 |
# File 'ext/roctave/fir_filter.c', line 120
static VALUE fir_filter_nb_coefficients(VALUE self)
{
struct fir_filter *flt;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
return INT2NUM(flt->nb_coefficients);
}
|
#numerator ⇒ Array<Float> Also known as: coefficients
Return a copy of the filter’s numerator coefficients as an array.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'ext/roctave/fir_filter.c', line 212
static VALUE fir_filter_coefficients(VALUE self)
{
struct fir_filter *flt;
VALUE res;
int i;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
res = rb_ary_new_capa(flt->nb_coefficients);
for (i = 0; i < flt->nb_coefficients; i++)
rb_ary_store(res, i, DBL2NUM(flt->b[flt->nb_coefficients - 1 - i]));
return res;
}
|
#order ⇒ Integer
Returns the filter order.
108 109 110 111 112 113 114 115 |
# File 'ext/roctave/fir_filter.c', line 108
static VALUE fir_filter_order(VALUE self)
{
struct fir_filter *flt;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
return INT2NUM(flt->nb_coefficients - 1);
}
|
#push(sample) ⇒ Object Also known as: <<
Push a sample in the filter state. Similar to filter
, but does not produce an output sample. Used for sample per sample decimators.
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'ext/roctave/fir_filter.c', line 609
static VALUE fir_filter_push(VALUE self, VALUE sample)
{
struct fir_filter *flt;
int i, len;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
if (RB_FLOAT_TYPE_P(sample) || rb_obj_is_kind_of(sample, rb_cNumeric)) {
(*flt->push_one_sample_func)(flt, sample);
}
else if (rb_class_of(sample) == rb_cArray) {
len = rb_array_len(sample);
for (i = 0; i < len; i++)
(*flt->push_one_sample_func)(flt, rb_ary_entry(sample, i));
}
else
rb_raise(rb_eArgError, "Expecting a single Numeric or an Array of Numeric");
return self;
}
|
#regular? ⇒ Boolean
Returns whether the filter is regular or not (not a decimator or interpolator).
665 666 667 668 669 670 671 672 673 674 675 676 |
# File 'ext/roctave/fir_filter.c', line 665
static VALUE fir_filter_is_regular(VALUE self)
{
struct fir_filter *flt;
VALUE res = Qfalse;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
if (FIR_FILTER_IS_REGULAR(flt))
res = Qtrue;
return res;
}
|
#reset! ⇒ Object
Reset the filter state.
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'ext/roctave/fir_filter.c', line 502
static VALUE fir_filter_reset(VALUE self)
{
struct fir_filter *flt;
int i;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
for (i = 0; i < flt->state_length; i++)
flt->state[i] = 0.0f;
if (flt->stateim) {
for (i = 0; i < flt->state_length; i++)
flt->stateim[i] = 0.0f;
}
flt->index = 0;
flt->counter = 0;
flt->push_one_sample_func = &push_one_sample_float;
flt->filter_one_sample_func = &filter_one_sample_float;
return self;
}
|
#set_den_coefficient_at(index, coef) ⇒ Float?
This method noes nothing, it is there to be compatible with Roctave::IirFilter
180 181 182 183 184 185 186 187 |
# File 'ext/roctave/fir_filter.c', line 180
static VALUE fir_filter_set_denominator_at(VALUE self, VALUE index, VALUE coef)
{
(void)self;
(void)index;
(void)coef;
return Qnil;
}
|
#set_num_coefficient_at(index, coef) ⇒ Float? Also known as: set_coefficient_at
Returns the coefficient if the index is valid, or nil otherwise.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'ext/roctave/fir_filter.c', line 134
static VALUE fir_filter_set_coefficient_at(VALUE self, VALUE index, VALUE coef)
{
struct fir_filter *flt;
int ind;
double val;
VALUE res = Qnil;
TypedData_Get_Struct(self, struct fir_filter, &fir_filter_type, flt);
ind = NUM2INT(index);
if (ind >= 0 && ind < flt->nb_coefficients) {
val = NUM2DBL(coef);
flt->b[flt->nb_coefficients - 1 - ind] = val;
res = DBL2NUM(val);
}
return res;
}
|