Hi, I designed a FIR filter using Mathwork's fdatool. The normalized frequencies are Fp=0.1944 and Fstop=0.25 and a stop band attenuation of 80 dB, resulting in a 91 taps filter. This filter has been implemented for a Xilinx FPGA using the core generator with 18 bits data width, 16 bits coefficient width, 40 bits accumulator width. I've scaled up the coefficients to fit the coefficient's range, simply by multiplying the coeffs by 2^17. Two problems emerge: 1. the overall gain is not one, not at least if I use the floating point coefficients in a simulation 2. and more important, the attenuation I obtain is only less more than 20 dB. I fed the design with different sine signals (different frequencies) to determine the attenuation. Additionally, I tried another filter implementation for verification, and obtained the same result. Furthermore I simulated the filter using both floating point and the scaled and rounded coeffs, the attenuation was ok. Of course, the real attenuation will be smaller than the expected, since round-off errors, but I had never expected such a big difference. What I'mdoing wrong:-). Bye Tom.
Attenuation of an implemented filter
Started by ●September 28, 2006
Reply by ●September 28, 20062006-09-28
"tom" <tom.reinemann@gmx.net> wrote in message news:1159448892.976449.157970@m7g2000cwm.googlegroups.com...> Hi, > > I designed a FIR filter using Mathwork's fdatool. > The normalized frequencies are Fp=0.1944 and Fstop=0.25 and a stop band > attenuation of 80 dB, resulting in a 91 taps filter. This filter has > been implemented for a Xilinx FPGA using the core generator with 18 > bits data width, 16 bits coefficient width, 40 bits accumulator width. > I've scaled up the coefficients to fit the coefficient's range, simply > by multiplying the coeffs by 2^17. > > Two problems emerge: > 1. the overall gain is not one, not at least if I use the floating > point coefficients in a simulation > 2. and more important, the attenuation I obtain is only less more than > 20 dB. > I fed the design with different sine signals (different frequencies) to > determine the attenuation. > > Additionally, I tried another filter implementation for verification, > and obtained the same result. Furthermore I simulated the filter using > both floating point and the scaled and rounded coeffs, the attenuation > was ok. > > Of course, the real attenuation will be smaller than the expected, > since round-off errors, but I had never expected such a big difference. > What I'mdoing wrong:-). >Tom, You didn't completely reveal how you're determining attenuation. Compared to the input? (a typical way) or comparing one frequency gain vs. another at the output? (less typical) It rather sounds like the latter - in which case I'm not sure about what's going on. I would look at the input/output relationships in any case. If you scale the coefficients equally then the filter gain will be scaled by the same amount times N (the filter length). The frequency response stays the same otherwise. Here's an example: Filter: [1 1 1 1] Gain at f=0 is the sum of the coefficients =4 and is the maximum gain of the filter. Scale the coefficients by 4: Filter [4 4 4 4] Gain at f=0 is 16 or N*4 where N=4. So, the stopband gain in your case would have been increased by 91*2^17 and the output for a sinusoid in the stopband may appear to be "large". However, when compared to the output in the passband, the ratio will be the same as it would be without having done the scaling. I suspect that's where the problem lies..... Fred
Reply by ●September 28, 20062006-09-28
Hi Fred Fred Marshall wrote:> > You didn't completely reveal how you're determining attenuation. Compared > to the input? (a typical way) or comparing one frequency gain vs. another at > the output? (less typical) It rather sounds like the latter - in which case > I'm not sure about what's going on. I would look at the input/output > relationships in any case. > > If you scale the coefficients equally then the filter gain will be scaled by > the same amount times N (the filter length). The frequency response stays > the same otherwise. > > Here's an example: > > Filter: [1 1 1 1] > Gain at f=0 is the sum of the coefficients =4 and is the maximum gain of the > filter. > Scale the coefficients by 4: > Filter [4 4 4 4] > Gain at f=0 is 16 or N*4 where N=4. > > So, the stopband gain in your case would have been increased by 91*2^17 and > the output for a sinusoid in the stopband may appear to be "large". > However, when compared to the output in the passband, the ratio will be the > same as it would be without having done the scaling. > I suspect that's where the problem lies..... >Thanks for your answer. I compared one frequency gain to the another at the output. Before, I divided the output by 2^17, by truncating the 17 LSBs. I expect an attenuation of a pass band frequency of about 0dB and of a stop band frequency of about 80 dB. But this is related to the input How I have to scale the coefficients to avoid this problem? Tom
Reply by ●September 28, 20062006-09-28
> I fed the design with different sine signals (different frequencies) to > determine the attenuation. > >does that mean in the analog domain via A/D and D/A converters? if so, what is the isolation between the input and ouput in the analog domain? what frequency range are you working in? do you have overflow problems? Mark
Reply by ●September 28, 20062006-09-28
"tom" <tom.reinemann@gmx.net> wrote in message news:1159476591.552102.108440@i42g2000cwa.googlegroups.com...> Hi Fred > > Fred Marshall wrote: >> >> You didn't completely reveal how you're determining attenuation. >> Compared >> to the input? (a typical way) or comparing one frequency gain vs. another >> at >> the output? (less typical) It rather sounds like the latter - in which >> case >> I'm not sure about what's going on. I would look at the input/output >> relationships in any case. >> >> If you scale the coefficients equally then the filter gain will be scaled >> by >> the same amount times N (the filter length). The frequency response >> stays >> the same otherwise. >> >> Here's an example: >> >> Filter: [1 1 1 1] >> Gain at f=0 is the sum of the coefficients =4 and is the maximum gain of >> the >> filter. >> Scale the coefficients by 4: >> Filter [4 4 4 4] >> Gain at f=0 is 16 or N*4 where N=4. >> >> So, the stopband gain in your case would have been increased by 91*2^17 >> and >> the output for a sinusoid in the stopband may appear to be "large". >> However, when compared to the output in the passband, the ratio will be >> the >> same as it would be without having done the scaling. >> I suspect that's where the problem lies..... >> > Thanks for your answer. I compared one frequency gain to the another at > the output. Before, I divided the output by 2^17, by truncating the 17 > LSBs. I expect an attenuation of a pass band frequency of about 0dB and > of a stop band frequency of about 80 dB. But this is related to the > input > > How I have to scale the coefficients to avoid this problem? > > Tom >I'm still not sure what you're doing.... And, I was incorrect about the gain going up as the length of the filter if you scale the coefficients. See below. If you put in a sinusoid of amplitude 1.0 in the pass band then you will get a sinusoid of amplitude "y" at the output. Use "y" as a reference. Now put in a sinusoid of amplitude 1.0 in the stop band and measure the output amplitude. Take the ratio of the amplitudes. Take 20*log10(ratio) and that will be the difference in band gain/attenuation. If the ratio is pass/stop then it will be +80dB. If the ratio is stop/pass then it will be -80dB if the filter is properly implemented. Multiplying or dividing the input or output samples by a constant should have no affect on the ratio of two outputs. So, if the input is not a sinusoid of amplitude 1.0 but rather 2^8 or whatever, the output ratios should remain the same - subject to roundoff errors. If the output/input ratio in the passband (the "passband gain") is, as often is, 1.0 then scaling either the input or the output or both or the coefficients will affect the gain. However, the gain should be the same relatively across the entire range of 0 to fs/2. Examples: A filter has a passband gain of 1.0 (0dB) and a stopband attenuation of 80dB (a gain of -80dB) and the filter input is scaled by +20dB. Then the apparent passband gain will be +20dB and the stopband gain will be -60dB. A filter has a passband gain of 1.0 (0dB) and a stopband attenuation of 80dB (a gain of -80dB) and the filter coefficients are scaled by a factor of 2 and the filter is of length 8. Then, for a lowpass filter, the apparent passband gain at f=0 will be 2*8=16 == +24dB and the stopband gain will be -56dB. Another "picture": Put a +20dB amplifier in front of the filter. The output goes up by +20dB. Put the same amplifier after the filter. The output goes up by +20dB. A property of linear systems. Put a +20dB amplifier in front of each filter coefficient (same as scaling the coefficients). The output goes up by the same factor. It's easiest to determine what happens at dc or f=0 because the output is the sum of the coefficients. So: gain [f=0] = a0*10 + a2*10 + a3*10 .... = 10*[a0 + a1 + a2] I hope that clarifies. Sorry for the error earlier. Fred
Reply by ●September 29, 20062006-09-29
Mark wrote:> > I fed the design with different sine signals (different frequencies) to > > determine the attenuation. > > > > > does that mean in the analog domain via A/D and D/A converters? > > if so, what is the isolation between the input and ouput in the analog > domain? > > what frequency range are you working in? > > do you have overflow problems?It's all simulation (VHDL). Therefore the ADC is simulated too, no real world effects can take place:-). I suppose, the core I generated using Xilinx' core generator will not introduce overflows. Tom
Reply by ●September 29, 20062006-09-29
Fred Marshall wrote:> > I hope that clarifies. Sorry for the error earlier.Not a problem, at all. I'm experienced in these things, but it ist the first time I run in such serious trouble implementing a filter. Ok my tries: Since my first posting I changed the coeff's witdh to 18, to reduce round-off errrors, furthermore support the multipliers 18x18 multiplication. filter characteristic low pass fpass=70kHz fstop=90kHz fsampling=720kHz step input f=0 x=128,000 y=128,370 sinusodial input f=70kHz xmax=128,000 ymax=115,209 sinusodial input f=100 xmax=128,000 ymax=9,780 Furthermore I spot checked the coefficients by applying an impulse (Dirac). Tom
Reply by ●September 29, 20062006-09-29
sorry the stop band sinusodial has a frequency of 100kHz sinusodial input f=100kHz xmax=128,000 ymax=9,780
Reply by ●September 29, 20062006-09-29
Sorry, but I made to a victim of quantization noise. My sampled sinusoid input signal wasn't really a sinusoid.
Reply by ●September 29, 20062006-09-29
Hi Tom, For such applications Mathworks do provide a tool to generate HDL code directly from MATLAB/ fdatool. The code gives you bit and cycle true results along with testbenches. To port this into X-sysgen flow you will perhaps have to use the X-sysgen black box to encapsulate the generated code. http://www.mathworks.com/products/filterhdl/ Thanks, - Mukesh. Thomas Reinemann wrote:> Mark wrote: > > > > I fed the design with different sine signals (different frequencies) to > > > determine the attenuation. > > > > > > > > does that mean in the analog domain via A/D and D/A converters? > > > > if so, what is the isolation between the input and ouput in the analog > > domain? > > > > what frequency range are you working in? > > > > do you have overflow problems? > > It's all simulation (VHDL). Therefore the ADC is simulated too, no real > world effects can take place:-). I suppose, the core I generated using > Xilinx' core generator will not introduce overflows. > > Tom






