| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2005,2006 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE Decimator. |
|---|
| 6 | |
|---|
| 7 | OSSIE Decimator is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE Decimator is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the GNU General Public License |
|---|
| 18 | along with OSSIE Decimator; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | ****************************************************************************/ |
|---|
| 23 | |
|---|
| 24 | #ifndef SIG_PROC_H |
|---|
| 25 | #define SIG_PROC_H |
|---|
| 26 | |
|---|
| 27 | #include <iostream> |
|---|
| 28 | #include <fstream> |
|---|
| 29 | #include <string> |
|---|
| 30 | |
|---|
| 31 | #ifdef FPM |
|---|
| 32 | #include "fixed.h" |
|---|
| 33 | #endif |
|---|
| 34 | |
|---|
| 35 | namespace SigProc { |
|---|
| 36 | |
|---|
| 37 | class phase_detect { |
|---|
| 38 | |
|---|
| 39 | public: |
|---|
| 40 | phase_detect(float scale_factor); |
|---|
| 41 | |
|---|
| 42 | void do_work(short I_in, short Q_in, short I_nco, short Q_nco, short &out); |
|---|
| 43 | |
|---|
| 44 | private: |
|---|
| 45 | phase_detect(const phase_detect &); |
|---|
| 46 | |
|---|
| 47 | float scale_factor; |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | class nco { |
|---|
| 52 | public: |
|---|
| 53 | nco(); |
|---|
| 54 | nco(unsigned int max_out); |
|---|
| 55 | |
|---|
| 56 | void do_work(short control_voltage, short &sine, short &cosine); |
|---|
| 57 | |
|---|
| 58 | private: |
|---|
| 59 | nco(const nco &); |
|---|
| 60 | |
|---|
| 61 | int freq_index; |
|---|
| 62 | int max_out; |
|---|
| 63 | }; |
|---|
| 64 | |
|---|
| 65 | class gain { |
|---|
| 66 | public: |
|---|
| 67 | gain(); |
|---|
| 68 | |
|---|
| 69 | void do_work(float gain, short data_in, short &out); |
|---|
| 70 | |
|---|
| 71 | private: |
|---|
| 72 | gain(const gain &); |
|---|
| 73 | |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | class iir_filter { |
|---|
| 77 | public: |
|---|
| 78 | iir_filter(float a[], unsigned int len_a, float b[], unsigned int len_b); |
|---|
| 79 | |
|---|
| 80 | void do_work(short x, short &y); |
|---|
| 81 | |
|---|
| 82 | private: |
|---|
| 83 | iir_filter(const iir_filter &); |
|---|
| 84 | |
|---|
| 85 | float *A; |
|---|
| 86 | float *B; |
|---|
| 87 | unsigned int len_A, len_B; |
|---|
| 88 | |
|---|
| 89 | float *v; |
|---|
| 90 | unsigned int len_v; |
|---|
| 91 | unsigned int next_v; |
|---|
| 92 | }; |
|---|
| 93 | |
|---|
| 94 | class fir_filter { |
|---|
| 95 | public: |
|---|
| 96 | fir_filter(float a[], unsigned int len_a); |
|---|
| 97 | |
|---|
| 98 | void do_work(bool run_filter, short in_sample, short &out_sample); |
|---|
| 99 | |
|---|
| 100 | private: |
|---|
| 101 | fir_filter(const fir_filter &); |
|---|
| 102 | |
|---|
| 103 | #ifdef FPM |
|---|
| 104 | mad_fixed_t *A; |
|---|
| 105 | mad_fixed_t *v; |
|---|
| 106 | #else |
|---|
| 107 | float *A; |
|---|
| 108 | short *v; |
|---|
| 109 | #endif |
|---|
| 110 | unsigned int len_A; |
|---|
| 111 | |
|---|
| 112 | unsigned int len_v; |
|---|
| 113 | unsigned int next_v; |
|---|
| 114 | }; |
|---|
| 115 | |
|---|
| 116 | class dump_data { |
|---|
| 117 | public: |
|---|
| 118 | dump_data(const char *filename, long start_sample, long number_of_samples); |
|---|
| 119 | ~dump_data(); |
|---|
| 120 | |
|---|
| 121 | void write_data(float data, const char *msg = ""); |
|---|
| 122 | void write_data(float a, float b, const char *msg = ""); |
|---|
| 123 | |
|---|
| 124 | private: |
|---|
| 125 | dump_data(); |
|---|
| 126 | dump_data(const dump_data &); |
|---|
| 127 | |
|---|
| 128 | std::ofstream *out_file; |
|---|
| 129 | |
|---|
| 130 | long start_sample, stop_sample; |
|---|
| 131 | long current_sample; |
|---|
| 132 | |
|---|
| 133 | }; |
|---|
| 134 | |
|---|
| 135 | class dc_block { |
|---|
| 136 | public: |
|---|
| 137 | dc_block(const float forget_factor); |
|---|
| 138 | ~dc_block(); |
|---|
| 139 | |
|---|
| 140 | void do_work(short in, short &out); |
|---|
| 141 | |
|---|
| 142 | private: |
|---|
| 143 | dc_block(); |
|---|
| 144 | dc_block(const dc_block &); |
|---|
| 145 | |
|---|
| 146 | float forget_factor; |
|---|
| 147 | int prev_input, prev_output; |
|---|
| 148 | |
|---|
| 149 | }; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | #endif |
|---|