Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/filter.cc @ 12566:3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Revamp test vectors.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 01 Apr 2011 18:53:14 -0700 |
parents | 7a5aacf65f81 |
children | d02798e9eeae |
comparison
equal
deleted
inserted
replaced
12565:0f71b9639207 | 12566:3b0eb443c519 |
---|---|
61 | 61 |
62 octave_idx_type a_len = a.length (); | 62 octave_idx_type a_len = a.length (); |
63 octave_idx_type b_len = b.length (); | 63 octave_idx_type b_len = b.length (); |
64 | 64 |
65 octave_idx_type ab_len = a_len > b_len ? a_len : b_len; | 65 octave_idx_type ab_len = a_len > b_len ? a_len : b_len; |
66 | |
67 b.resize (dim_vector (ab_len, 1), 0.0); | |
68 if (a_len > 1) | |
69 a.resize (dim_vector (ab_len, 1), 0.0); | |
70 | 66 |
71 T norm = a (0); | 67 T norm = a (0); |
72 | 68 |
73 if (norm == static_cast<T>(0.0)) | 69 if (norm == static_cast<T>(0.0)) |
74 { | 70 { |
462 } | 458 } |
463 | 459 |
464 si = args(3).float_complex_array_value (); | 460 si = args(3).float_complex_array_value (); |
465 | 461 |
466 if (si_is_vector) | 462 if (si_is_vector) |
467 si = si.reshape (dim_vector (si.numel (), 1)); | 463 si = si.reshape (dim_vector (1, si.numel ())); |
468 } | 464 } |
469 | 465 |
470 if (! error_state) | 466 if (! error_state) |
471 { | 467 { |
472 FloatComplexNDArray y (filter (b, a, x, si, dim)); | 468 FloatComplexNDArray y (filter (b, a, x, si, dim)); |
519 } | 515 } |
520 | 516 |
521 si = args(3).complex_array_value (); | 517 si = args(3).complex_array_value (); |
522 | 518 |
523 if (si_is_vector) | 519 if (si_is_vector) |
524 si = si.reshape (dim_vector (si.numel (), 1)); | 520 si = si.reshape (dim_vector (1, si.numel ())); |
525 } | 521 } |
526 | 522 |
527 if (! error_state) | 523 if (! error_state) |
528 { | 524 { |
529 ComplexNDArray y (filter (b, a, x, si, dim)); | 525 ComplexNDArray y (filter (b, a, x, si, dim)); |
579 } | 575 } |
580 | 576 |
581 si = args(3).float_array_value (); | 577 si = args(3).float_array_value (); |
582 | 578 |
583 if (si_is_vector) | 579 if (si_is_vector) |
584 si = si.reshape (dim_vector (si.numel (), 1)); | 580 si = si.reshape (dim_vector (1, si.numel ())); |
585 } | 581 } |
586 | 582 |
587 if (! error_state) | 583 if (! error_state) |
588 { | 584 { |
589 FloatNDArray y (filter (b, a, x, si, dim)); | 585 FloatNDArray y (filter (b, a, x, si, dim)); |
636 } | 632 } |
637 | 633 |
638 si = args(3).array_value (); | 634 si = args(3).array_value (); |
639 | 635 |
640 if (si_is_vector) | 636 if (si_is_vector) |
641 si = si.reshape (dim_vector (si.numel (), 1)); | 637 si = si.reshape (dim_vector (1, si.numel ())); |
642 } | 638 } |
643 | 639 |
644 if (! error_state) | 640 if (! error_state) |
645 { | 641 { |
646 NDArray y (filter (b, a, x, si, dim)); | 642 NDArray y (filter (b, a, x, si, dim)); |
692 /* | 688 /* |
693 %!shared a, b, x, r | 689 %!shared a, b, x, r |
694 %!test | 690 %!test |
695 %! a = [1 1]; | 691 %! a = [1 1]; |
696 %! b = [1 1]; | 692 %! b = [1 1]; |
697 %! x = zeros(1,10); x(1) = 1; | 693 %! x = zeros (1,10); x(1) = 1; |
698 %! assert(all(filter(b, [1], x ) == [1 1 0 0 0 0 0 0 0 0] )) | 694 %! assert(filter(b, [1], x ), [1 1 0 0 0 0 0 0 0 0]); |
699 %! assert(all(filter(b, [1], x.') == [1 1 0 0 0 0 0 0 0 0].')) | 695 %! assert(filter(b, [1], x.'), [1 1 0 0 0 0 0 0 0 0].'); |
700 %! assert(all(filter(b.', [1], x ) == [1 1 0 0 0 0 0 0 0 0] )) | 696 %! assert(filter(b.', [1], x ), [1 1 0 0 0 0 0 0 0 0] ); |
701 %! assert(all(filter(b.', [1], x.') == [1 1 0 0 0 0 0 0 0 0].')) | 697 %! assert(filter(b.', [1], x.'), [1 1 0 0 0 0 0 0 0 0].'); |
702 %! assert(all(filter([1], a, x ) == [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1] )) | 698 %! assert(filter([1], a, x ), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1] ); |
703 %! assert(all(filter([1], a, x.') == [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].')) | 699 %! assert(filter([1], a, x.'), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].'); |
704 %! assert(all(filter([1], a.', x ) == [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1] )) | 700 %! assert(filter([1], a.', x ), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1] ); |
705 %! assert(all(filter([1], a.', x.') == [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].')) | 701 %! assert(filter([1], a.', x.'), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].'); |
706 %! assert(all(filter(b, a, x ) == [1 0 0 0 0 0 0 0 0 0] )) | 702 %! assert(filter(b, a, x ), [1 0 0 0 0 0 0 0 0 0] ); |
707 %! assert(all(filter(b.', a, x ) == [1 0 0 0 0 0 0 0 0 0] )) | 703 %! assert(filter(b.', a, x ), [1 0 0 0 0 0 0 0 0 0] ); |
708 %! assert(all(filter(b, a.', x ) == [1 0 0 0 0 0 0 0 0 0] )) | 704 %! assert(filter(b, a.', x ), [1 0 0 0 0 0 0 0 0 0] ); |
709 %! assert(all(filter(b.', a, x ) == [1 0 0 0 0 0 0 0 0 0] )) | 705 %! assert(filter(b.', a, x ), [1 0 0 0 0 0 0 0 0 0] ); |
710 %! assert(all(filter(b, a, x.') == [1 0 0 0 0 0 0 0 0 0].')) | 706 %! assert(filter(b, a, x.'), [1 0 0 0 0 0 0 0 0 0].'); |
711 %! assert(all(filter(b.', a, x.') == [1 0 0 0 0 0 0 0 0 0].')) | 707 %! assert(filter(b.', a, x.'), [1 0 0 0 0 0 0 0 0 0].'); |
712 %! assert(all(filter(b, a.', x.') == [1 0 0 0 0 0 0 0 0 0].')) | 708 %! assert(filter(b, a.', x.'), [1 0 0 0 0 0 0 0 0 0].'); |
713 %! assert(all(filter(b.', a, x.') == [1 0 0 0 0 0 0 0 0 0].')) | 709 %! assert(filter(b.', a, x.'), [1 0 0 0 0 0 0 0 0 0].'); |
714 %! | 710 %! |
715 %!test | 711 %!test |
716 %! r = sqrt(1/2)*(1+i); | 712 %! r = sqrt(1/2)*(1+i); |
717 %! a = a*r; | 713 %! a = a*r; |
718 %! b = b*r; | 714 %! b = b*r; |
719 %! assert(all(filter(b, [1], x ) == r*[1 1 0 0 0 0 0 0 0 0] )) | 715 %! assert(filter(b, [1], x ), r*[1 1 0 0 0 0 0 0 0 0] ); |
720 %! assert(all(filter(b, [1], r*x ) == r*r*[1 1 0 0 0 0 0 0 0 0] )) | 716 %! assert(filter(b, [1], r*x ), r*r*[1 1 0 0 0 0 0 0 0 0] ); |
721 %! assert(all(filter(b, [1], x.' ) == r*[1 1 0 0 0 0 0 0 0 0].' )) | 717 %! assert(filter(b, [1], x.' ), r*[1 1 0 0 0 0 0 0 0 0].' ); |
722 %! assert(all(filter(b, a, x ) == [1 0 0 0 0 0 0 0 0 0] )) | 718 %! assert(filter(b, a, x ), [1 0 0 0 0 0 0 0 0 0] ); |
723 %! assert(all(filter(b, a, r*x ) == r*[1 0 0 0 0 0 0 0 0 0] )) | 719 %! assert(filter(b, a, r*x ), r*[1 0 0 0 0 0 0 0 0 0] ); |
724 %! | 720 %! |
725 %!shared a, b, x, y, so | 721 %!shared a, b, x, y, so |
726 %!test | 722 %!test |
727 %! a = [1,1]; b=[1,1]; | 723 %! a = [1,1]; b = [1,1]; |
728 %! x = zeros(1,10); x(1) = 1; | 724 %! x = zeros (1,10); x(1) = 1; |
729 %! [y, so] = filter(b, [1], x, [-1]); | 725 %! [y, so] = filter (b, [1], x, [-1]); |
730 %! assert(all(y == [0 1 0 0 0 0 0 0 0 0])) | 726 %! assert(y, [0 1 0 0 0 0 0 0 0 0]); |
731 %! assert(so,0) | 727 %! assert(so,0); |
732 %! | 728 %! |
733 %!test | 729 %!test |
734 %! x = zeros(10,3); x(1,1)=-1; x(1,2)=1; | 730 %! x = zeros (10,3); x(1,1)=-1; x(1,2)=1; |
735 %! y0 = zeros(10,3); y0(1:2,1)=-1; y0(1:2,2)=1; | 731 %! y0 = zeros (10,3); y0(1:2,1)=-1; y0(1:2,2)=1; |
736 %! y = filter(b,[1],x); | 732 %! y = filter (b, [1], x); |
737 %! assert(all(all(y==y0))) | 733 %! assert(y,y0); |
738 %! | 734 %! |
739 %!test | 735 %!test |
740 %! a = [1,1]; b=[1,1]; | 736 %! a = [1,1]; b=[1,1]; |
741 %! x = zeros(4,4,2); x(1,1:4,1) = +1; x(1,1:4,2) = -1; | 737 %! x = zeros (4,4,2); x(1,1:4,1) = +1; x(1,1:4,2) = -1; |
742 %! y0 = zeros(4,4,2); y0(1:2,1:4,1) = +1; y0(1:2,1:4,2) = -1; | 738 %! y0 = zeros (4,4,2); y0(1:2,1:4,1) = +1; y0(1:2,1:4,2) = -1; |
743 %! y = filter(b, [1], x); | 739 %! y = filter (b, [1], x); |
744 %! assert(all(all(all(y==y0)))) | 740 %! assert(y, y0); |
745 %! | 741 %! |
746 %!assert(filter(1,ones(10,1)/10,[]), []) | 742 %!assert(filter (1, ones(10,1)/10, []), []); |
747 %!assert(filter(1,ones(10,1)/10,zeros(0,10)), zeros(0,10)) | 743 %!assert(filter (1, ones(10,1)/10, zeros(0,10)), zeros(0,10)); |
748 | 744 %!assert(filter([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]), [5 7; 6 10; 14 18]); |
745 %!assert(filter (1, ones(10,1)/10, single (1:5)), repmat (single (10), 1, 5)); | |
749 %% Should put some tests of the "DIM" parameter in here. | 746 %% Should put some tests of the "DIM" parameter in here. |
750 | 747 |
751 */ | 748 */ |