-
Notifications
You must be signed in to change notification settings - Fork 1
/
Calcs.h
136 lines (111 loc) · 2.67 KB
/
Calcs.h
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
/******************************************************************************
Calcs.h
Copyright (c) Roger Burghall 2014..2017
******************************************************************************/
#ifndef CALCSH
#define CALCSH
/*! \file Calcs.h
*/
#include <string>
using std::string;
#include <complex>
#include <stdio.h>
#include <math.h>
#include <fstream>
#include <sstream>
#include "Enums.h"
#include "Discrete.h"
#define FSTEPS 1000
#define TSTEPS 1000
#define IMAX 19
#define MAXS 19
#define T_MULTIPLE_LP 5.0
#define T_MULTIPLE_BP 5.0
#define T_MULTIPLE_HP 2.0
#define F_MULTIPLE 0.1
#define LINEAR_FREQ true
#define LOG true
#define NORMALISE
#define VERBOSE false
// Shall we show detailed response data?
// #define SHOW_STAGES
using namespace std;
/*! \class stage
Describes one stage of a cascaded continuous filter.
*/
class stage {
public:
filter_class fclass;
circuit_class cclass;
double T, q;
std::complex<double> pole, zero;
// double t, q;
double R1, R2, R3, C1, C2, C3;
double gain;
std::complex<double> z;
iir iir1;
void R_low_pass(void);
void R_high_pass(void);
void R_band_pass(void);
void synthesise_R_low(void);
void synthesise_R_band(void);
void synthesise_R_high(void);
void synthesise_SK_low(void);
void synthesise_SK_band(void);
void synthesise_SK_high(void);
void bilinear(void);
stage& operator= (stage& f1);
};
class TFilter {
// private:
public:
filter_class fclass;
circuit_class cclass;
shape_class sclass;
double frequency;
double gain;
unsigned int poles, zeroes;
// std::complex<double> pole[20], zero[20];
double /* t[10], q[10],*/ tau; // TODO: use tau for single pole.
char type;
double fmax, tmax;
double ripple;
double bandwidth;
double samplingfreq;
double freq_resp[FSTEPS];
double step_resp[TSTEPS];
stage st[10];
void Proto_normalise(void);
double fgain(double f);
double a0;
public:
TFilter( );
// ~TFilter( );
void Calculate(void);
void log(string);
void log(string, double);
void log(string, double *);
void log(string, double *, int);
void log(string, std::complex<double>);
void _pole(double a, double w);
void transform(void);
void print_T_q(void);
void ts_and_qs(void);
void show_filter(void);
void show_filter(string title);
void bessel(void);
void sort(void);
void butterworth(void);
void chebyshev(void);
void lowpass(void);
void highpass(void);
void bandpass(void);
void Synth_Rauch(void);
void Synth_SallKey(void);
void step_calc(void);
void bilinear(void);
};
double tq(std::complex<double> p, double &t, double &q);
void bode_calc(TFilter& filter);
void step_calc(TFilter& filter);
#endif