I’m trying to measure reactive energy with MSP430F47187 and its SD16_A module. To calculate reactive energy I need a 90 degree phase shifter known as hilbert filter. If I use FIR filter, matlab says It requires 106 tabs(Transition Width 35 Hz, Passband Ripple 0.02dB/0.1% and Sampling Frequency 1024). I don’t know MSP430 can do this job at that frequency by using Q1.15 style fixed point arithmetic for each phase which is totally three.
Here are my questions:
1. In SLAA409A software code there are some coefficients for 90 degree phase shift. But they are for 4096 Hz sampling frequency and totally 128 tabs. In that C file (emeter-fir-table.c), it is written “This file was generated automatically by generate-fir-table”. Where can I find this “generate-fir-table” software? (I think it is software¿)
2. Can I do same job by using IIR filter instead of FIR which requires too much processing power?
3. Does TI have a filtering library for MSP430 series?
4. In same application note, there is a dc filter function which I didn’t understand how it works.
// A routine to filter away the DC content from an AC mains waveform
// signal. It does this my using a heavily damped integrator to estimate
// the DC level. The current DC level is then subtracted from the signal.
int16_t dc_filter(register int32_t *p, register int16_t x)
*p += ((((int32_t) x << 16) - *p) >> 14);
x -= (*p >> 16);
I think it was designed for 4Khz sampling frequency, because for me it becomes stabile after 40 seconds. I need something faster, is it possible?
In reply to C. Hayes:
Thanks for useful information. For the DC Filter I found this trick:
I can attenuate signals under 20Hz which we can say DC for this application.
MSP430F471xx series has 32 bit hardware multiplier module with fixed point support which is good news for me. But SLAA409A uses only Q15 style multiplication, while the module support Q31 style multiplication and accumulation (MACS32). May be it is highly enough for this application.
Is his mean with ‘standard cascaded biquad sections’ this one?
Second-order (biquadratic) IIR digital filtering
Another question, when I design Hilbert by using FIR (linear-phase, odd symmetry, type 3), it also produces a fixed delay. Let say it has 128+1 tabs, 90 degree shifted signal comes after 64th sample. I already have a buffer for inputs. Because of that, I need another circular buffer for also output. Isn’t there a way to prevent this lag?
In reply to BasePointer:
Hi,That DC blocking algorithm looks good. Thanks for mentioning it.
BasePointerIs his mean with ‘standard cascaded biquad sections’ this one?Second-order (biquadratic) IIR digital filteringhttp://www.mathworks.com/access/helpdesk/help/toolbox/signal/sosfilt.html
You are correct, that is the type of biquadratic IIR filter section he meant in the message you read. You can cascade a combination of 1st, 2nd, other order filter stages to produce a composite filter which is of more stringent performance specification in the composite effect of all the individual stages. So a 4th order could be a couple of 2nd order sections acting in conjunction, et. al. depending on the particular design of your filter and its sections. I believe the 'ellip' function in MATLAB can be used to design an elliptical type filter according to a specified performance characteristic and produce the pole/zero locations that of that filter as a result. These could be modulated or rotated to produce an IIR or FIR filter which works similarly to a Hilbert transformer as various thread posts and articles suggest may be done. Some alternatively cited references suggest 'firpm' or the older 'remez' functions to design an optimized FIR filter via the Remez Exchange / Parks-McClellan algorithms. There are other approaches to both FIR and IIR hilbert transform like impelemntations also listed in various of the below links.
BasePointerMSP430F471xx series has 32 bit hardware multiplier module with fixed point support which is good news for me. But SLAA409A uses only Q15 style multiplication, while the module support Q31 style multiplication and accumulation (MACS32). May be it is highly enough for this application.
That is a good resource to have. You might well be able to use it for a 12, 14, 15, or 16 bit precision implementation of the filtering coefficients. You just have to watch out for possible overflow or underflow or rounding errors since these can be problems when operating with even 16 or 32 bit precision depending on the calculations you are conducting.The most commonly recommended implementation for digital filtering on the more common MSP430 models (without such a hardware multiplier) is to use the CSD scheme of filter arithmetic and encoding and that seems to work well. Especially commended by TI's application notes and in other sources is the lattice wave digital filter LWDF / WDF / lattice filter type of realization of IIR filters as the combination of simple 1st and 2nd order sections since they can be calculated with less problems due to arithmetic precision on a fixed point processor especially one without floating point or fixed point hardware multiplication capability. I suspect if you did an IIR implementation it might be OK to just use the CSD reference code for a LWDF type filter since it shouldn't be too many dozen operations long in many cases. Whereas a FIR implementation would likely benefit very much from using the HW multiplier since you'll be doing many MACs over a long filter, though still you may end up with performance / resource concerns if you have 100+ FIR taps.It will be easier to get a more linear phase and less ripple magnitude response with the FIR implementation, though to a given precision you can approximate those with an IIR (LWDF type or not) implementation if that seems beneficial.
BasePointerAnother question, when I design Hilbert by using FIR (linear-phase, odd symmetry, type 3), it also produces a fixed delay. Let say it has 128+1 tabs, 90 degree shifted signal comes after 64th sample. I already have a buffer for inputs. Because of that, I need another circular buffer for also output. Isn’t there a way to prevent this lag?
I don't think you can get around filtering either the voltage (or the current) signal to produce a phase shift of 90 degrees to correlate with the other signal based on the architecture you seem to be following. If the resulting filtered output of one channel has not only the desired phase shift but also a significant delay then you must buffer the other signal with a matched delay such that you can multiply the equally delayed signals with one channel quadrature phase shifted and the other not. I'm not sure if these considerations are what you're referring to as an 'output' delay -- really it would seem like it is a matching delay one branch for the V channel and another one for the I channel but I would think at that point those outputs are all you would need and there would be no significant additional delays needed.
At some length it is theoretically more efficient to calculate FIR filters via a forward and inverse FFT, but I think that is not so practical on the MSP430 if it has very limited RAM and also the fixed point precision limitations it has et. al. and you're only filtering with an impulse response of 130 or so length, and, anyway it doesn't reduce the delay intrinsic to the z^-1 storage needed for the causal filter, it just reduces the arithmetic complexity of the implementation of the filtering, so it doesn't solve the problem entirely.
If you used a 'complex' filter type implementation where you'd filter both the V channel and the I channel into a pair of filters which generated relative outputs in quadrature then you'd process each channel in a corresponding fashion and then you'd directly be able to multiply the outputs of the V and I filters without (as far as I know) adding additional large delays to either branch.It is possible that using a smaller state / order IIR approximation of a Hilbert transformer would reduce your arithmetic processing and your tap / state memory storage needs substantially and alleviate the problems in those areas with long high delay high MAC count FIR implementations.If there's some other aspect of 'output' delay that you're concerned about, I don't quite understand how it arised based on a limited understanding of your application's architecture. SLAA409 page 12's diagram doesn't seem to show any additional large delays other than that which is needed to shift the phase of one channel by 90 degrees.Here's more references which may or may not be useful...http://www.student.oulu.fi/~oniemita/dsp/hilbert/http://www.dsprelated.com/showmessage/21946/1.php"Hilbert IIR filter implementation"http://www.dsprelated.com/showmessage/24752/1.php"Designing IIR hilbert transform pair"http://www.dsprelated.com/showmessage/88412/1.php"High Speed IIR"http://www.dsprelated.com/showmessage/22749/1.php"Hilbert transform & analytic signals"http://newsgroups.derkeiler.com/Archive/Comp/comp.dsp/2009-03/msg01457.htmlhttp://www.ti.com/sc/docs/products/micro/msp430/wave.pdf"Wave digital filtering for TI's sensor signal processor MSP430"http://focus.ti.com/lit/ml/slap108/slap108.pdf"Optimized Digital Filtering for the MSP430 "http://focus.ti.com/mcu/docs/litabsmultiplefilelist.tsp?sectionId=96&tabId=1502&literatureNumber=slaa331&docCategoryId=1&familyId=342"Wave Digital Filtering using the MSP430"http://focus.ti.com/general/docs/litabsmultiplefilelist.tsp?literatureNumber=slaa357"Efficient MSP430 Code Synthesis for an FIR filter"http://www.bdti.com/faq/2.htm#210"How do I calculate the coefficients for a Hilbert transformer?""Synthesis of very sharp Hilbert transformer using the frequency-response masking technique"Y.C. Lim, Y.J.Yu"Wave digital filters with minimum multiplier for discrete Hilbert transformer realization"S.A. Samad, A. Hussain, D. Isa"Analytic signal generation---tips and traps", Andrew Reilly and Gordon Frazer and Boualem Boashash, IEEE Transactions on Signal Processing, no. 11, vol. 42, Nov. 1994, pp. 3241-3245."Optimal FIR and IIR Hilbert transformer design via LS and minimax fitting" - Instrumentation and Measurement, IEEE Transactions on; Istvan Kollar, Rik Pintelon, Johan Schoukens."Design of multiplierless elliptic IIR halfband filters and hilbert transformers", Miroslav D. Lutovac, Ljiljana D. Milic"A Uniformly Convergent Approximation for Ideal Complex Half-Band Filters", Gagan Mirchandani, Mohamed Elfataui"Approximate linear phase Hilbert transformer" Ljiljana D. Milic, Miroslav D. Lutovac"Design of Hilbert transformer for solid-state energy meter"Bojan Anđelković, Milunka Damnjanović"Elliptic half-band IIR filters" Miroslav D. Lutovac, Ljiljana D. Milichttp://metalab.uniten.edu.my/~farrukh/DSP/DSP%205%20-%20IIR%20Filter%20Design.ppthttp://metalab.uniten.edu.my/~farrukh/DSP/DSP%206%20-%20FIR%20Filter%20Design.ppthttps://ccrma.stanford.edu/~jos/sasp/Matlab_Support_Least_Squares_FIR.html
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.