Speciaal voor FElix
Dependencies: biquadFilter mbed
main.cpp@0:97b158e017b8, 2018-10-22 (annotated)
- Committer:
- gastongab
- Date:
- Mon Oct 22 13:07:40 2018 +0000
- Revision:
- 0:97b158e017b8
Dit is speciaal voor Felix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gastongab | 0:97b158e017b8 | 1 | /** |
gastongab | 0:97b158e017b8 | 2 | * Demo program for BiQuad and BiQuadChain classes |
gastongab | 0:97b158e017b8 | 3 | * author: T.J.W. Lankhorst <t.j.w.lankhorst@student.utwente.nl> |
gastongab | 0:97b158e017b8 | 4 | */ |
gastongab | 0:97b158e017b8 | 5 | |
gastongab | 0:97b158e017b8 | 6 | #include <stdlib.h> |
gastongab | 0:97b158e017b8 | 7 | #include <iostream> |
gastongab | 0:97b158e017b8 | 8 | #include <iomanip> |
gastongab | 0:97b158e017b8 | 9 | #include <complex> |
gastongab | 0:97b158e017b8 | 10 | #include "BiQuad.h" |
gastongab | 0:97b158e017b8 | 11 | |
gastongab | 0:97b158e017b8 | 12 | // Example: 3th order Butterworth LP (w_c = 0.1*f_nyquist) |
gastongab | 0:97b158e017b8 | 13 | BiQuadChain bqc; |
gastongab | 0:97b158e017b8 | 14 | |
gastongab | 0:97b158e017b8 | 15 | BiQuad bq1( 9.20511e-02, -1.84501e-01, 9.24506e-02, -1.99997e+00, 9.99976e-01 ); |
gastongab | 0:97b158e017b8 | 16 | BiQuad bq2( 1.00000e+00, -2.00367e+00, 1.00368e+00, -1.99998e+00, 9.99983e-01 ); |
gastongab | 0:97b158e017b8 | 17 | |
gastongab | 0:97b158e017b8 | 18 | bqc.add( &bq1 ).add( &bq2 ); |
gastongab | 0:97b158e017b8 | 19 | int main() |
gastongab | 0:97b158e017b8 | 20 | { |
gastongab | 0:97b158e017b8 | 21 | |
gastongab | 0:97b158e017b8 | 22 | bqc = bq1 * bq2; |
gastongab | 0:97b158e017b8 | 23 | |
gastongab | 0:97b158e017b8 | 24 | // Find the poles of the filter |
gastongab | 0:97b158e017b8 | 25 | std::cout << "Filter poles" << std::endl; |
gastongab | 0:97b158e017b8 | 26 | std::vector< std::complex<double> > poles = bqc.poles(); |
gastongab | 0:97b158e017b8 | 27 | for( size_t i = 0; i < poles.size(); i++ ) |
gastongab | 0:97b158e017b8 | 28 | std::cout << "\t" << poles[i] << std::endl; |
gastongab | 0:97b158e017b8 | 29 | |
gastongab | 0:97b158e017b8 | 30 | // Find the zeros of the filter |
gastongab | 0:97b158e017b8 | 31 | std::cout << "Filter zeros" << std::endl; |
gastongab | 0:97b158e017b8 | 32 | std::vector< std::complex<double> > zeros = bqc.zeros(); |
gastongab | 0:97b158e017b8 | 33 | for( size_t i = 0; i < poles.size(); i++ ) |
gastongab | 0:97b158e017b8 | 34 | std::cout << "\t" << zeros[i] << std::endl; |
gastongab | 0:97b158e017b8 | 35 | |
gastongab | 0:97b158e017b8 | 36 | // Is the filter stable? |
gastongab | 0:97b158e017b8 | 37 | std::cout << "This filter is " << (bqc.stable() ? "stable" : "instable") << std::endl; |
gastongab | 0:97b158e017b8 | 38 | |
gastongab | 0:97b158e017b8 | 39 | // Output the step-response of 20 samples |
gastongab | 0:97b158e017b8 | 40 | std::cout << "Step response 20 samples" << std::endl; |
gastongab | 0:97b158e017b8 | 41 | for( int i = 0; i < 20; i++ ) |
gastongab | 0:97b158e017b8 | 42 | std::cout << "\t" << bqc.step( 1.0 ) << std::endl; |
gastongab | 0:97b158e017b8 | 43 | |
gastongab | 0:97b158e017b8 | 44 | // Done0 |
gastongab | 0:97b158e017b8 | 45 | return EXIT_SUCCESS; |
gastongab | 0:97b158e017b8 | 46 | |
gastongab | 0:97b158e017b8 | 47 | } |