fdatool, how to use generated C header file
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I used to fdatool in MATLAB to generate a digital lowpass filter and exported it as a C header file but I am not sure how to exactly incorporate it into my project. I need it to filter readings from a digital gyroscope, and we are using MPIDE to talk to it (MPIDE is similar to the arduino platform). I was wondering if anyone had any advice, or sample .cpp files I could go off of to get a start on trying to use the filter. The output file is below:
Thanks! David
//////
/*
* Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool
*
* Generated by MATLAB(R) 7.14 and the Signal Processing Toolbox 6.17.
*
* Generated on: 24-Sep-2012 10:49:22
*
*/
/*
* Discrete-Time IIR Filter (real)
* -------------------------------
* Filter Structure : Direct-Form II, Second-Order Sections
* Number of Sections : 5
* Stable : Yes
* Linear Phase : No
*/
/* General type conversion for MATLAB generated C-code */
#include "tmwtypes.h"
/*
* Expected path to tmwtypes.h
* C:\Program Files\MATLAB\R2012a\extern\include\tmwtypes.h
*/
/*
* Warning - Filter coefficients were truncated to fit specified data type.
* The resulting response may not match generated theoretical response.
* Use the Filter Design & Analysis Tool to design accurate
* single-precision filter coefficients.
*/
#define MWSPT_NSEC 11
const int NUM_LENGTH[MWSPT_NSEC] = { 1,3,1,3,1,3,1,3,1,3,1 };
const real32_T NUM[MWSPT_NSEC][3] = {
{
0.006008784287, 0, 0
},
{
1, 2, 1
},
{
0.005747633986, 0, 0
},
{
1, 2, 1
},
{
0.005542717408, 0, 0
},
{
1, 2, 1
},
{
0.005402769428, 0, 0
},
{
1, 2, 1
},
{
0.005331991706, 0, 0
},
{
1, 2, 1
},
{
1, 0, 0
}
};
const int DOM_LENGTH[MWSPT_NSEC] = { 1,3,1,3,1,3,1,3,1,3,1 };
const real32_T DEN[MWSPT_NSEC][3] = {
{
1, 0, 0
},
{
1, -1.92819047, 0.9522256255
},
{
1, 0, 0
},
{
1, -1.844388604, 0.8673791885
},
{
1, 0, 0
},
{
1, -1.778631806, 0.8008026481
},
{
1, 0, 0
},
{
1, -1.733723164, 0.7553342581
},
{
1, 0, 0
},
{
1, -1.711010933, 0.7323389053
},
{
1, 0, 0
}
};
0 comentarios
Respuestas (2)
Ahmad
el 5 de Sept. de 2013
Hi David,
I am doing a project where I have to use filters, and was having the same question you did. Here is a link to a PDF that graphically shows what coefficients are used where.
Ahmad
1 comentario
Andrea Bettati
el 20 de Mayo de 2016
Hi, I have the same exact problem! Could you please provide any link or reference on how understand the FDATools' representation of the coeffs? I'd like to use them to describe the Transfer Function of 4 order Butterworth filter so I need something like a1, a2, a3, a4 and b1, b2, b3, b4. Any help would be higly appreciated!!
Wayne King
el 24 de Sept. de 2012
Editada: Wayne King
el 24 de Sept. de 2012
It's giving you the filter coefficients declared as constants so that you can use them in a C program to filter data. Did you write the C code to actually implement the filter? Presumably you would have some for loop in your C code that actually implements the filter. In that for loop you need the filter coefficients.
So you need to include the fdacoefs.h file in your project so that your C filtering program knows how the filter coefficients are defined when you use Num and Den
Ver también
Categorías
Más información sobre C Code Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!