This example demonstrates how to use the msp_fir_q15 API to filter 16-bit input data. The input signal is the sum of two signals, one that will pass though the filter and one that will be filtered out. The input and result can be compared to see the effect of the filter.
#include "msp430.h"
#include <math.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include "DSPLib.h"
#define FS 8192
#define SIGNAL_LENGTH 256
#define SIGNAL_FREQUENCY1 200
#define SIGNAL_AMPLITUDE1 0.6
#define SIGNAL_FREQUENCY2 2100
#define SIGNAL_AMPLITUDE2 0.15
#define PI 3.1415926536
#ifndef FILTER_COEFFS_EX4
{
.b1By2 =
_Q15(+0.608536/2),
.a1By2 =
_Q15(-0.215187/2),
},
{
.b1By2 =
_Q15(+0.533004/2),
.a1By2 =
_Q15(-0.145445/2),
},
{
.b1By2 =
_Q15(+0.399958/2),
.a1By2 =
_Q15(-0.021883/2),
},
{
.b1By2 =
_Q15(+0.236817/2),
.a1By2 =
_Q15(+0.131385/2),
},
{
.b1By2 =
_Q15(+0.070226/2),
.a1By2 =
_Q15(+0.291215/2),
},
{
.b1By2 =
_Q15(-0.079576/2),
.a1By2 =
_Q15(+0.440602/2),
},
{
.b1By2 =
_Q15(-0.199067/2),
.a1By2 =
_Q15(+0.569203/2),
},
{
.b1By2 =
_Q15(-0.278629/2),
.a1By2 =
_Q15(+0.671286/2),
}
};
#endif
#define FILTER_LENGTH (SIGNAL_LENGTH)
#define FILTER_STAGES (sizeof(FILTER_COEFFS_EX4)/sizeof(msp_biquad_df2_q15_coeffs))
_q15 input[SIGNAL_LENGTH];
_q15 temp[SIGNAL_LENGTH];
_q15 result[SIGNAL_LENGTH];
volatile uint32_t cycleCount = 0;
extern void initSignal(void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
#ifdef __MSP430_HAS_PMM__
PM5CTL0 &= ~LOCKLPM5;
#endif
initSignal();
memcpy(filterCoeffs, FILTER_COEFFS_EX4, sizeof(filterCoeffs));
df2Params.
length = FILTER_LENGTH;
df2Params.
stages = FILTER_STAGES;
df2Params.
coeffs = filterCoeffs;
__no_operation();
}
void initSignal(void)
{
sinParams.
length = SIGNAL_LENGTH;
sinParams.
length = SIGNAL_LENGTH;
addParams.
length = SIGNAL_LENGTH;
}