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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 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 409 410 411 412 413 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 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 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 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
use std::result; use num::complex::Complex; use super::super::RealNumber; use super::{ ComplexTimeVector, RealTimeVector, GenericDataVector, RealFreqVector, ComplexFreqVector }; /// DataVector gives access to the basic properties of all data vectors /// /// A DataVector allocates memory if necessary. It will however never shrink/free memory unless it's /// deleted and dropped. pub trait DataVector<T> : Sized where T : RealNumber { /// Gives direct access to the underlying data sequence. It's recommended to use the `Index functions . /// For users outside of Rust: It's discouraged to hold references to this array while executing operations on the vector, /// since the vector may decide at any operation to invalidate the array. fn data(&self) -> &[T]; /// The x-axis delta. If `domain` is time domain then `delta` is in `[s]`, in frequency domain `delta` is in `[Hz]`. fn delta(&self) -> T; /// The domain in which the data vector resides. Basically specifies the x-axis and the type of operations which /// are valid on this vector. fn domain(&self) -> DataVectorDomain; /// Indicates whether the vector contains complex data. This also specifies the type of operations which are valid /// on this vector. fn is_complex(&self) -> bool; /// The number of valid elements in the the vector. fn len(&self) -> usize; /// Sets the vector length to the given length. /// If `self.len() < len` then the value of the new elements is undefined. fn set_len(&mut self, len: usize); /// The number of valid points. If the vector is complex then every valid point consists of two floating point numbers, /// while for real vectors every point only consists of one floating point number. fn points(&self) -> usize; /// Gets the number of allocated elements in the underlying vector. /// The allocated length may be larger than the length of valid points. /// In most cases you likely want to have `len`or `points` instead. fn allocated_len(&self) -> usize; } /// The domain of a data vector #[derive(Copy)] #[derive(Clone)] #[derive(PartialEq)] #[derive(Debug)] pub enum DataVectorDomain { /// Time domain, the x-axis is in [s] Time, /// Frequency domain, the x-axis in in [Hz] Frequency } /// This trait allows to change a vector type. The operations will /// convert a vector to a different type and set `self.len()` to zero. /// However `self.allocated_len()` will remain unchanged. The use case for this /// is to allow to reuse the memory of a vector for different operations. pub trait RededicateVector<T> : DataVector<T> where T: RealNumber { /// Make `self` a complex time vector /// # Example /// /// ``` /// use basic_dsp::{ComplexFreqVector32, ComplexVectorOperations, RededicateVector, DataVector, DataVectorDomain}; /// let complex = ComplexFreqVector32::from_interleaved(&[1.0, 2.0, 3.0, 4.0]); /// let real = complex.phase().expect("Ignoring error handling in examples"); /// let complex = real.rededicate_as_complex_time_vector(2.0); /// assert_eq!(true, complex.is_complex()); /// assert_eq!(DataVectorDomain::Time, complex.domain()); /// assert_eq!(0, complex.len()); /// assert_eq!(2, complex.allocated_len()); /// ``` fn rededicate_as_complex_time_vector(self, delta: T) -> ComplexTimeVector<T>; /// Make `self` a complex frequency vector fn rededicate_as_complex_freq_vector(self, delta: T) -> ComplexFreqVector<T>; /// Make `self` a real time vector fn rededicate_as_real_time_vector(self, delta: T) -> RealTimeVector<T>; /// Make `self` a real freq vector fn rededicate_as_real_freq_vector(self, delta: T) -> RealFreqVector<T>; /// Make `self` a generic vector fn rededicate_as_generic_vector(self, is_complex: bool, domain: DataVectorDomain, delta: T) -> GenericDataVector<T>; } /// An operation which multiplies each vector element with a constant pub trait Scale<T> : Sized where T: Sized { /// Multiplies the vector element with a scalar. fn scale(self, offset: T) -> VecResult<Self>; } /// An operation which adds a constant to each vector element pub trait Offset<T> : Sized where T: Sized { /// Adds a scalar to each vector element. fn offset(self, offset: T) -> VecResult<Self>; } /// Defines all operations which are valid on all `DataVectors`. pub trait GenericVectorOperations<T>: DataVector<T> where T : RealNumber { /// Calculates the sum of `self + summand`. It consumes self and returns the result. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `VectorsMustHaveTheSameSize`: `self` and `summand` must have the same size /// 2. `VectorMetaDataMustAgree`: `self` and `summand` must be in the same domain and number space /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector1 = RealTimeVector32::from_array(&[1.0, 2.0]); /// let vector2 = RealTimeVector32::from_array(&[10.0, 11.0]); /// let result = vector1.add_vector(&vector2).expect("Ignoring error handling in examples"); /// assert_eq!([11.0, 13.0], result.data()); /// ``` fn add_vector(self, summand: &Self) -> VecResult<Self>; /// Calculates the sum of `self + summand`. `summand` may be smaller than `self` as long /// as `self.len() % summand.len() == 0`. THe result is the same as it would be if /// you would repeat `summand` until it has the same length as `self`. /// It consumes self and returns the result. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `InvalidArgumentLength`: `self.points()` isn't dividable by `summand.points()` /// 2. `VectorMetaDataMustAgree`: `self` and `summand` must be in the same domain and number space /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector1 = RealTimeVector32::from_array(&[10.0, 11.0, 12.0, 13.0]); /// let vector2 = RealTimeVector32::from_array(&[1.0, 2.0]); /// let result = vector1.add_smaller_vector(&vector2).expect("Ignoring error handling in examples"); /// assert_eq!([11.0, 13.0, 13.0, 15.0], result.data()); /// ``` fn add_smaller_vector(self, summand: &Self) -> VecResult<Self>; /// Calculates the difference of `self - subtrahend`. It consumes self and returns the result. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `VectorsMustHaveTheSameSize`: `self` and `subtrahend` must have the same size /// 2. `VectorMetaDataMustAgree`: `self` and `subtrahend` must be in the same domain and number space /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector1 = RealTimeVector32::from_array(&[1.0, 2.0]); /// let vector2 = RealTimeVector32::from_array(&[10.0, 11.0]); /// let result = vector1.subtract_vector(&vector2).expect("Ignoring error handling in examples"); /// assert_eq!([-9.0, -9.0], result.data()); /// ``` fn subtract_vector(self, subtrahend: &Self) -> VecResult<Self>; /// Calculates the sum of `self - subtrahend`. `subtrahend` may be smaller than `self` as long /// as `self.len() % subtrahend.len() == 0`. THe result is the same as it would be if /// you would repeat `subtrahend` until it has the same length as `self`. /// It consumes self and returns the result. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `InvalidArgumentLength`: `self.points()` isn't dividable by `subtrahend.points()` /// 2. `VectorMetaDataMustAgree`: `self` and `subtrahend` must be in the same domain and number space /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector1 = RealTimeVector32::from_array(&[10.0, 11.0, 12.0, 13.0]); /// let vector2 = RealTimeVector32::from_array(&[1.0, 2.0]); /// let result = vector1.subtract_smaller_vector(&vector2).expect("Ignoring error handling in examples"); /// assert_eq!([9.0, 9.0, 11.0, 11.0], result.data()); /// ``` fn subtract_smaller_vector(self, summand: &Self) -> VecResult<Self>; /// Calculates the product of `self * factor`. It consumes self and returns the result. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `VectorsMustHaveTheSameSize`: `self` and `factor` must have the same size /// 2. `VectorMetaDataMustAgree`: `self` and `factor` must be in the same domain and number space /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector1 = RealTimeVector32::from_array(&[1.0, 2.0]); /// let vector2 = RealTimeVector32::from_array(&[10.0, 11.0]); /// let result = vector1.multiply_vector(&vector2).expect("Ignoring error handling in examples"); /// assert_eq!([10.0, 22.0], result.data()); /// ``` fn multiply_vector(self, factor: &Self) -> VecResult<Self>; /// Calculates the sum of `self - factor`. `factor` may be smaller than `self` as long /// as `self.len() % factor.len() == 0`. THe result is the same as it would be if /// you would repeat `factor` until it has the same length as `self`. /// It consumes self and returns the result. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `InvalidArgumentLength`: `self.points()` isn't dividable by `factor.points()` /// 2. `VectorMetaDataMustAgree`: `self` and `factor` must be in the same domain and number space /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector1 = RealTimeVector32::from_array(&[10.0, 11.0, 12.0, 13.0]); /// let vector2 = RealTimeVector32::from_array(&[1.0, 2.0]); /// let result = vector1.multiply_smaller_vector(&vector2).expect("Ignoring error handling in examples"); /// assert_eq!([10.0, 22.0, 12.0, 26.0], result.data()); /// ``` fn multiply_smaller_vector(self, factor: &Self) -> VecResult<Self>; /// Calculates the quotient of `self / summand`. It consumes self and returns the result. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `VectorsMustHaveTheSameSize`: `self` and `divisor` must have the same size /// 2. `VectorMetaDataMustAgree`: `self` and `divisor` must be in the same domain and number space /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector1 = RealTimeVector32::from_array(&[10.0, 22.0]); /// let vector2 = RealTimeVector32::from_array(&[2.0, 11.0]); /// let result = vector1.divide_vector(&vector2).expect("Ignoring error handling in examples"); /// assert_eq!([5.0, 2.0], result.data()); /// ``` fn divide_vector(self, divisor: &Self) -> VecResult<Self>; /// Calculates the sum of `self - divisor`. `divisor` may be smaller than `self` as long /// as `self.len() % divisor.len() == 0`. THe result is the same as it would be if /// you would repeat `divisor` until it has the same length as `self`. /// It consumes self and returns the result. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `InvalidArgumentLength`: `self.points()` isn't dividable by `divisor.points()` /// 2. `VectorMetaDataMustAgree`: `self` and `divisor` must be in the same domain and number space /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector1 = RealTimeVector32::from_array(&[10.0, 12.0, 12.0, 14.0]); /// let vector2 = RealTimeVector32::from_array(&[1.0, 2.0]); /// let result = vector1.divide_smaller_vector(&vector2).expect("Ignoring error handling in examples"); /// assert_eq!([10.0, 6.0, 12.0, 7.0], result.data()); /// ``` fn divide_smaller_vector(self, divisor: &Self) -> VecResult<Self>; /// Appends zeros add the end of the vector until the vector has the size given in the points argument. /// If `points` smaller than the `self.len()` then this operation won't do anything. /// /// Note: Each point is two floating point numbers if the vector is complex. /// # Example /// /// ``` /// use basic_dsp::{PaddingOption, RealTimeVector32, ComplexTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0]); /// let result = vector.zero_pad(4, PaddingOption::End).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 2.0, 0.0, 0.0], result.data()); /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 2.0]); /// let result = vector.zero_pad(2, PaddingOption::End).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 2.0, 0.0, 0.0], result.data()); /// ``` fn zero_pad(self, points: usize, option: PaddingOption) -> VecResult<Self>; /// Reverses the data inside the vector. fn reverse(self) -> VecResult<Self>; /// Ineterleaves zeros `factor - 1`times after every vector element, so that the resulting /// vector will have a length of `self.len() * factor`. /// /// Note: Remember that each complex number consists of two floating points and interleaving /// will take that into account. /// /// If factor is 0 (zero) then `self` will be returned. /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, ComplexTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0]); /// let result = vector.zero_interleave(2).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 0.0, 2.0, 0.0], result.data()); /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 2.0, 3.0, 4.0]); /// let result = vector.zero_interleave(2).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0], result.data()); /// ``` fn zero_interleave(self, factor: u32) -> VecResult<Self>; /// Calculates the delta of each elements to its previous element. This will decrease the vector length by one point. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[2.0, 3.0, 2.0, 6.0]); /// let result = vector.diff().expect("Ignoring error handling in examples"); /// assert_eq!([1.0, -1.0, 4.0], result.data()); /// ``` fn diff(self) -> VecResult<Self>; /// Calculates the delta of each elements to its previous element. The first element /// will remain unchanged. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[2.0, 3.0, 2.0, 6.0]); /// let result = vector.diff_with_start().expect("Ignoring error handling in examples"); /// assert_eq!([2.0, 1.0, -1.0, 4.0], result.data()); /// ``` fn diff_with_start(self) -> VecResult<Self>; /// Calculates the cumulative sum of all elements. This operation undoes the `diff_with_start`operation. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[2.0, 1.0, -1.0, 4.0]); /// let result = vector.cum_sum().expect("Ignoring error handling in examples"); /// assert_eq!([2.0, 3.0, 2.0, 6.0], result.data()); /// ``` fn cum_sum(self) -> VecResult<Self>; /// Gets the square root of all vector elements. /// /// The sqrt of a negative number gives NaN and not a complex vector. /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// # use std::f32; /// let vector = RealTimeVector32::from_array(&[1.0, 4.0, 9.0, 16.0, 25.0]); /// let result = vector.sqrt().expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 2.0, 3.0, 4.0, 5.0], result.data()); /// let vector = RealTimeVector32::from_array(&[-1.0]); /// let result = vector.sqrt().expect("Ignoring error handling in examples"); /// assert!(result[0].is_nan()); /// ``` fn sqrt(self) -> VecResult<Self>; /// Squares all vector elements. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 4.0, 5.0]); /// let result = vector.square().expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 4.0, 9.0, 16.0, 25.0], result.data()); /// ``` fn square(self) -> VecResult<Self>; /// Calculates the n-th root of every vector element. /// /// If the result would be a complex number then the vector will contain a NaN instead. So the vector /// will never convert itself to a complex vector during this operation. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 8.0, 27.0]); /// let result = vector.root(3.0).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 2.0, 3.0], result.data()); /// ``` fn root(self, degree: T) -> VecResult<Self>; /// Raises every vector element to the given power. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0]); /// let result = vector.power(3.0).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 8.0, 27.0], result.data()); /// ``` fn power(self, exponent: T) -> VecResult<Self>; /// Calculates the natural logarithm to the base e for every vector element. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[2.718281828459045 , 7.389056, 20.085537]); /// let result = vector.logn().expect("Ignoring error handling in examples"); /// let actual = result.data(); /// let expected = &[1.0, 2.0, 3.0]; /// assert_eq!(actual.len(), expected.len()); /// for i in 0..actual.len() { /// assert!((actual[i] - expected[i]).abs() < 1e-4); /// } /// ``` fn logn(self) -> VecResult<Self>; /// Calculates the natural exponential to the base e for every vector element. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0]); /// let result = vector.expn().expect("Ignoring error handling in examples"); /// assert_eq!([2.71828182846, 7.389056, 20.085537], result.data()); /// ``` fn expn(self) -> VecResult<Self>; /// Calculates the logarithm to the given base for every vector element. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[10.0, 100.0, 1000.0]); /// let result = vector.log_base(10.0).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 2.0, 3.0], result.data()); /// ``` fn log_base(self, base: T) -> VecResult<Self>; /// Calculates the exponential to the given base for every vector element. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0]); /// let result = vector.exp_base(10.0).expect("Ignoring error handling in examples"); /// assert_eq!([10.0, 100.0, 1000.0], result.data()); /// ``` fn exp_base(self, base: T) -> VecResult<Self>; /// Calculates the sine of each element in radians. /// /// # Example /// /// ``` /// use std::f32; /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[f32::consts::PI/2.0, -f32::consts::PI/2.0]); /// let result = vector.sin().expect("Ignoring error handling in examples"); /// assert_eq!([1.0, -1.0], result.data()); /// ``` fn sin(self) -> VecResult<Self>; /// Calculates the cosine of each element in radians. /// /// # Example /// /// ``` /// use std::f32; /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[2.0 * f32::consts::PI, f32::consts::PI]); /// let result = vector.cos().expect("Ignoring error handling in examples"); /// assert_eq!([1.0, -1.0], result.data()); /// ``` fn cos(self) -> VecResult<Self>; /// Calculates the tangent of each element in radians. fn tan(self) -> VecResult<Self>; /// Calculates the principal value of the inverse sine of each element in radians. fn asin(self) -> VecResult<Self>; /// Calculates the principal value of the inverse cosine of each element in radians. fn acos(self) -> VecResult<Self>; /// Calculates the principal value of the inverse tangent of each element in radians. fn atan(self) -> VecResult<Self>; /// Calculates the hyperbolic sine each element in radians. fn sinh(self) -> VecResult<Self>; /// Calculates the hyperbolic cosine each element in radians. fn cosh(self) -> VecResult<Self>; /// Calculates the hyperbolic tangent each element in radians. fn tanh(self) -> VecResult<Self>; /// Calculates the principal value of the inverse hyperbolic sine of each element in radians. fn asinh(self) -> VecResult<Self>; /// Calculates the principal value of the inverse hyperbolic cosine of each element in radians. fn acosh(self) -> VecResult<Self>; /// Calculates the principal value of the inverse hyperbolic tangent of each element in radians. fn atanh(self) -> VecResult<Self>; /// This function swaps both halves of the vector. This operation is also called fft shift /// Use it after a `plain_fft` to get a spectrum which is centered at `0 Hz`. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]); /// let result = vector.swap_halves().expect("Ignoring error handling in examples"); /// assert_eq!([5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0], result.data()); /// ``` fn swap_halves(self) -> VecResult<Self>; /// Splits the vector into several smaller vectors. `self.len()` must be dividable by /// `targets.len()` without a remainder and this conidition must be true too `targets.len() > 0`. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `InvalidArgumentLength`: `self.points()` isn't dividable by `targets.len()` /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let a = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]; /// let merge = RealTimeVector32::from_array(&a); /// let mut split = &mut /// [Box::new(RealTimeVector32::empty()), /// Box::new(RealTimeVector32::empty())]; /// merge.split_into(split).unwrap(); /// assert_eq!([1.0, 3.0, 5.0, 7.0, 9.0], split[0].data()); /// ``` fn split_into(&self, targets: &mut [Box<Self>]) -> VoidResult; /// Merges several vectors into `self`. All vectors must have the same size and /// at least one vector must be provided. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `InvalidArgumentLength`: if `sources.len() == 0` /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::empty(); /// let parts = &[ /// Box::new(RealTimeVector32::from_array(&[1.0, 2.0])), /// Box::new(RealTimeVector32::from_array(&[1.0, 2.0]))]; /// let merged = vector.merge(parts).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 1.0, 2.0, 2.0], merged.data()); /// ``` fn merge(self, sources: &[Box<Self>]) -> VecResult<Self>; /// Overrides the data in the vector with the given data. This may also change /// the vectors length (however not the allocated length). /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, GenericVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 4.0]); /// let result = vector.override_data(&[5.0, 7.0]).expect("Ignoring error handling in examples"); /// assert_eq!(&[5.0, 7.0], result.data()); /// ``` fn override_data(self, data: &[T]) -> VecResult<Self>; } /// Defines all operations which are valid on `DataVectors` containing real data. /// # Failures /// All operations in this trait fail with `VectorMustBeReal` if the vector isn't in the real number space. pub trait RealVectorOperations<T> : DataVector<T> where T : RealNumber { type ComplexPartner; /// Adds a scalar to the vector. /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0]); /// let result = vector.real_offset(2.0).expect("Ignoring error handling in examples"); /// assert_eq!([3.0, 4.0], result.data()); /// ``` fn real_offset(self, offset: T) -> VecResult<Self>; /// Multiplies the vector with a scalar. /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0]); /// let result = vector.real_scale(4.0).expect("Ignoring error handling in examples"); /// assert_eq!([4.0, 8.0], result.data()); /// ``` fn real_scale(self, offset: T) -> VecResult<Self>; /// Gets the absolute value of all vector elements. /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, -2.0]); /// let result = vector.abs().expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 2.0], result.data()); /// ``` fn abs(self) -> VecResult<Self>; /// Converts the real vector into a complex vector. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0]); /// let result = vector.to_complex().expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 0.0, 2.0, 0.0], result.data()); /// ``` fn to_complex(self) -> VecResult<Self::ComplexPartner>; /// Each value in the vector is devided by the divisor and the remainder is stored in the resulting /// vector. This the same a modulo operation or to phase wrapping. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]); /// let result = vector.wrap(4.0).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0], result.data()); /// ``` fn wrap(self, divisor: T) -> VecResult<Self>; /// This function corrects the jumps in the given vector which occur due to wrap or modulo operations. /// This will undo a wrap operation only if the deltas are smaller than half the divisor. /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0]); /// let result = vector.unwrap(4.0).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], result.data()); /// ``` fn unwrap(self, divisor: T) -> VecResult<Self>; /// Calculates the dot product of self and factor. Self and factor remain unchanged. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `VectorMetaDataMustAgree`: `self` and `factor` must be in the same domain and number space /// /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, RealVectorOperations}; /// let vector1 = RealTimeVector32::from_array(&[9.0, 2.0, 7.0]); /// let vector2 = RealTimeVector32::from_array(&[4.0, 8.0, 10.0]); /// let result = vector1.real_dot_product(&vector2).expect("Ignoring error handling in examples"); /// assert_eq!(122.0, result); /// ``` fn real_dot_product(&self, factor: &Self) -> ScalarResult<T>; /// Calculates the statistics of the data contained in the vector. /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, RealVectorOperations}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 4.0, 5.0]); /// let result = vector.real_statistics(); /// assert_eq!(result.sum, 15.0); /// assert_eq!(result.count, 5); /// assert_eq!(result.average, 3.0); /// assert!((result.rms - 3.3166).abs() < 1e-4); /// assert_eq!(result.min, 1.0); /// assert_eq!(result.min_index, 0); /// assert_eq!(result.max, 5.0); /// assert_eq!(result.max_index, 4); /// ``` fn real_statistics(&self) -> Statistics<T>; /// Calculates the statistics of the data contained in the vector as if the vector would /// have been split into `len` pieces. `self.len` should be devisable by `len` without a remainder, /// but this isn't enforced by the implementation. /// # Example /// /// ``` /// use basic_dsp::{RealTimeVector32, RealVectorOperations}; /// let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 4.0]); /// let result = vector.real_statistics_splitted(2); /// assert_eq!(result[0].sum, 4.0); /// assert_eq!(result[1].sum, 6.0); /// ``` fn real_statistics_splitted(&self, len: usize) -> Vec<Statistics<T>>; } /// Defines all operations which are valid on `DataVectors` containing complex data. /// # Failures /// All operations in this trait fail with `VectorMustBeComplex` if the vector isn't in the complex number space. pub trait ComplexVectorOperations<T> : DataVector<T> where T : RealNumber { type RealPartner; /// Gets `self.data()` as complex array. fn complex_data(&self) -> &[Complex<T>]; /// Adds a scalar to the vector. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// use num::complex::Complex32; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 2.0, 3.0, 4.0]); /// let result = vector.complex_offset(Complex32::new(-1.0, 2.0)).expect("Ignoring error handling in examples"); /// assert_eq!([0.0, 4.0, 2.0, 6.0], result.data()); /// # } /// ``` fn complex_offset(self, offset: Complex<T>) -> VecResult<Self>; /// Multiplies the vector with a scalar. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// use num::complex::Complex32; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 2.0, 3.0, 4.0]); /// let result = vector.complex_scale(Complex32::new(-1.0, 2.0)).expect("Ignoring error handling in examples"); /// assert_eq!([-5.0, 0.0, -11.0, 2.0], result.data()); /// # } /// ``` fn complex_scale(self, factor: Complex<T>) -> VecResult<Self>; /// Multiplies each vector element with `exp(j*(a*idx*self.delta() + b))` /// where `a` and `b` are arguments and `idx` is the index of the data points /// in the vector ranging from `0 to self.points() - 1`. `j` is the imaginary number and /// `exp` the exponential function. /// /// This method can be used to perform a frequency shift in time domain. /// /// # Example /// /// ``` /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 2.0, 3.0, 4.0]); /// let result = vector.multiply_complex_exponential(2.0, 3.0).expect("Ignoring error handling in examples"); /// let expected = [-1.2722325, -1.838865, 4.6866837, -1.7421241]; /// let result = result.data(); /// for i in 0..expected.len() { /// assert!((result[i] - expected[i]).abs() < 1e-4); /// } /// ``` fn multiply_complex_exponential(mut self, a: T, b: T) -> VecResult<Self>; /// Gets the absolute value or magnitude of all vector elements. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// use num::complex::Complex32; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[3.0, -4.0, -3.0, 4.0]); /// let result = vector.magnitude().expect("Ignoring error handling in examples"); /// assert_eq!([5.0, 5.0], result.data()); /// # } /// ``` fn magnitude(self) -> VecResult<Self::RealPartner>; /// Copies the absolute value or magnitude of all vector elements into the given target vector. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{ComplexTimeVector32, RealTimeVector32, ComplexVectorOperations, DataVector}; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[3.0, -4.0, -3.0, 4.0]); /// let mut result = RealTimeVector32::from_array(&[0.0]); /// vector.get_magnitude(&mut result).expect("Ignoring error handling in examples"); /// assert_eq!([5.0, 5.0], result.data()); /// # } /// ``` fn get_magnitude(&self, destination: &mut Self::RealPartner) -> VoidResult; /// Gets the square root of the absolute value of all vector elements. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// use num::complex::Complex32; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[3.0, -4.0, -3.0, 4.0]); /// let result = vector.magnitude_squared().expect("Ignoring error handling in examples"); /// assert_eq!([25.0, 25.0], result.data()); /// # } /// ``` fn magnitude_squared(self) -> VecResult<Self::RealPartner>; /// Calculates the complex conjugate of the vector. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 2.0, 3.0, 4.0]); /// let result = vector.complex_conj().expect("Ignoring error handling in examples"); /// assert_eq!([1.0, -2.0, 3.0, -4.0], result.data()); /// # } /// ``` fn complex_conj(self) -> VecResult<Self>; /// Gets all real elements. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 2.0, 3.0, 4.0]); /// let result = vector.to_real().expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 3.0], result.data()); /// # } /// ``` fn to_real(self) -> VecResult<Self::RealPartner>; /// Gets all imag elements. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 2.0, 3.0, 4.0]); /// let result = vector.to_imag().expect("Ignoring error handling in examples"); /// assert_eq!([2.0, 4.0], result.data()); /// # } /// ``` fn to_imag(self) -> VecResult<Self::RealPartner>; /// Copies all real elements into the given vector. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{RealTimeVector32, ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// # fn main() { /// let mut result = RealTimeVector32::from_array(&[0.0, 0.0]); /// let vector = ComplexTimeVector32::from_real_imag(&[1.0, 3.0], &[2.0, 4.0]); /// vector.get_real(&mut result).expect("Ignoring error handling in examples"); /// assert_eq!([1.0, 3.0], result.data()); /// # } /// ``` fn get_real(&self, destination: &mut Self::RealPartner) -> VoidResult; /// Copies all imag elements into the given vector. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{RealTimeVector32, ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// # fn main() { /// let mut result = RealTimeVector32::from_array(&[0.0, 0.0]); /// let vector = ComplexTimeVector32::from_real_imag(&[1.0, 3.0], &[2.0, 4.0]); /// vector.get_imag(&mut result).expect("Ignoring error handling in examples"); /// assert_eq!([2.0, 4.0], result.data()); /// # } /// ``` fn get_imag(&self, destination: &mut Self::RealPartner) -> VoidResult; /// Gets the phase of all elements in [rad]. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 0.0, 0.0, 4.0, -2.0, 0.0, 0.0, -3.0, 1.0, 1.0]); /// let result = vector.phase().expect("Ignoring error handling in examples"); /// assert_eq!([0.0, 1.5707964, 3.1415927, -1.5707964, 0.7853982], result.data()); /// # } /// ``` fn phase(self) -> VecResult<Self::RealPartner>; /// Copies the phase of all elements in [rad] into the given vector. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// use basic_dsp::{RealTimeVector32, ComplexTimeVector32, ComplexVectorOperations, DataVector}; /// # fn main() { /// let mut result = RealTimeVector32::from_array(&[0.0, 0.0]); /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 0.0, 0.0, 4.0, -2.0, 0.0, 0.0, -3.0, 1.0, 1.0]); /// vector.get_phase(&mut result).expect("Ignoring error handling in examples"); /// assert_eq!([0.0, 1.5707964, 3.1415927, -1.5707964, 0.7853982], result.data()); /// # } /// ``` fn get_phase(&self, destination: &mut Self::RealPartner) -> VoidResult; /// Calculates the dot product of self and factor. Self and factor remain unchanged. /// # Failures /// VecResult may report the following `ErrorReason` members: /// /// 1. `VectorMetaDataMustAgree`: `self` and `factor` must be in the same domain and number space /// /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// # use num::complex::Complex32; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations}; /// # fn main() { /// let vector1 = ComplexTimeVector32::from_interleaved(&[9.0, 2.0, 7.0, 1.0]); /// let vector2 = ComplexTimeVector32::from_interleaved(&[4.0, 0.0, 10.0, 0.0]); /// let result = vector1.complex_dot_product(&vector2).expect("Ignoring error handling in examples"); /// assert_eq!(Complex32::new(106.0, 18.0), result); /// } /// ``` fn complex_dot_product(&self, factor: &Self) -> ScalarResult<Complex<T>>; /// Calculates the statistics of the data contained in the vector. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// # use num::complex::Complex32; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations}; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]); /// let result = vector.complex_statistics(); /// assert_eq!(result.sum, Complex32::new(9.0, 12.0)); /// assert_eq!(result.count, 3); /// assert_eq!(result.average, Complex32::new(3.0, 4.0)); /// assert!((result.rms - Complex32::new(3.4027193, 4.3102784)).norm() < 1e-4); /// assert_eq!(result.min, Complex32::new(1.0, 2.0)); /// assert_eq!(result.min_index, 0); /// assert_eq!(result.max, Complex32::new(5.0, 6.0)); /// assert_eq!(result.max_index, 2); /// } /// ``` fn complex_statistics(&self) -> Statistics<Complex<T>>; /// Calculates the statistics of the data contained in the vector as if the vector would /// have been split into `len` pieces. `self.len` should be devisable by `len` without a remainder, /// but this isn't enforced by the implementation. /// # Example /// /// ``` /// # extern crate num; /// # extern crate basic_dsp; /// # use num::complex::Complex32; /// use basic_dsp::{ComplexTimeVector32, ComplexVectorOperations}; /// # fn main() { /// let vector = ComplexTimeVector32::from_interleaved(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]); /// let result = vector.complex_statistics_splitted(2); /// assert_eq!(result[0].sum, Complex32::new(6.0, 8.0)); /// assert_eq!(result[1].sum, Complex32::new(10.0, 12.0)); /// } /// ``` fn complex_statistics_splitted(&self, len: usize) -> Vec<Statistics<Complex<T>>>; /// Gets the real and imaginary parts and stores them in the given vectors. /// See [`get_phase`](trait.ComplexVectorOperations.html#tymethod.get_phase) and /// [`get_complex_abs`](trait.ComplexVectorOperations.html#tymethod.get_complex_abs) for further /// information. fn get_real_imag(&self, real: &mut Self::RealPartner, imag: &mut Self::RealPartner) -> VoidResult; /// Gets the magnitude and phase and stores them in the given vectors. /// See [`get_real`](trait.ComplexVectorOperations.html#tymethod.get_real) and /// [`get_imag`](trait.ComplexVectorOperations.html#tymethod.get_imag) for further /// information. fn get_mag_phase(&self, mag: &mut Self::RealPartner, phase: &mut Self::RealPartner) -> VoidResult; /// Overrides the `self` vectors data with the real and imaginary data in the given vectors. /// `real` and `imag` must have the same size. fn set_real_imag(self, real: &Self::RealPartner, imag: &Self::RealPartner) -> VecResult<Self>; /// Overrides the `self` vectors data with the magnitude and phase data in the given vectors. /// Note that `self` vector will immediately convert the data into a real and imaginary representation /// of the complex numbers which is its default format. /// `mag` and `phase` must have the same size. fn set_mag_phase(self, mag: &Self::RealPartner, phase: &Self::RealPartner) -> VecResult<Self>; } /// Enumeration of all error reasons #[derive(Copy)] #[derive(Clone)] #[derive(PartialEq)] #[derive(Debug)] pub enum ErrorReason { /// The operations requires all vectors to have the same size, /// in most cases this means that the following must be true: /// `self.len()` == `argument.len()` VectorsMustHaveTheSameSize, /// The operations requires all vectors to have the same meta data /// in most cases this means that the following must be true: /// `self.is_complex()` == `argument.is_complex()` && /// `self.domain()` == `argument.domain()` && /// `self.delta()`== `argument.domain()`; /// Consider to convert one of the vectors so that this conidition is true. /// The necessary operations may include FFT/IFFT, complex/real conversion and resampling. VectorMetaDataMustAgree, /// The operation requires the vector to be complex. VectorMustBeComplex, /// The operation requires the vector to be real. VectorMustBeReal, /// The operation requires the vector to be in time domain. VectorMustBeInTimeDomain, /// The operation requires the vector to be in frequency domain. VectorMustBeInFrquencyDomain, /// The arguments have an invalid length to perform the operation. The /// operations documentation should have more information about the requirements. /// Please open a defect if this isn't the case. InvalidArgumentLength, /// The operations is only valid if the data vector contains half of a symmetric spectrum. /// The symmetry definition follows soon however more important is that the element at 0 Hz /// which happens to be the first vector element must be real. This is actually violated /// if this error message appears and the rest of the definition is only listed here for /// completness. /// The required symmetry is that for every point `vector[x].conj() == vector[-x]`(pseudocode) /// where `x` is the x-axis position relativ to 0Hz and `conj` is the complex conjungate. VectorMustBeConjSymmetric, /// `self.points()` must be an odd number. VectorMustHaveAnOddLength, /// The function passed as argument must be symmetric ArgumentFunctionMustBeSymmetric } /// Result contains on success the vector. On failure it contains an error reason and an vector with invalid data /// which still can be used in order to avoid memory allocation. pub type VecResult<T> = result::Result<T, (ErrorReason, T)>; /// Void/nothing in case of success or a reason in case of an error. pub type VoidResult = result::Result<(), ErrorReason>; /// Scalar result or a reason in case of an error. pub type ScalarResult<T> = result::Result<T, ErrorReason>; /// Statistics about the data in a vector #[repr(C)] #[derive(Copy)] #[derive(Clone)] #[derive(PartialEq)] #[derive(Debug)] pub struct Statistics<T> { pub sum: T, pub count: usize, pub average: T, pub rms: T, pub min: T, pub min_index: usize, pub max: T, pub max_index: usize } /// An option which defines how a vector should be padded #[derive(Copy)] #[derive(Clone)] #[derive(PartialEq)] #[derive(Debug)] pub enum PaddingOption { /// Appends zeros to the end of the vector. End, /// Surrounds the vector with zeros at the beginning and at the end. Surround, /// Inserts zeros in the center of the vector Center, }