# Polyphase filter questions

Started by March 12, 2007
```Hi,

Hoping some of you experts can shine some light on the following
regarding polyphase filtering

1...I created a polyphase FIR interpolator, sampling frequency is
upsampled by 10 from 10KHz to 100KHz. It works fine and I get the
required frequencies output on the scope. I notice however, that the
output gain is much lower than that with a standard FIR sampled at 100
KHz with the same coefficients. Is there a gain issue with the
polyphase structure?

2...I tried to create a polyphase FIR decimator, downsampling by 10
from 100KHz to 10KHz. I cannot get it to work. Should the coefficients
be exactly the same as the interpolator?

3...Should the input to each filter in the polyphase filter structure
of the decimator be a data sample from the ADC followed by zeros, as
the other samples from the ADC are being input to the other filters in
the structure?

4...Anybody got any C code for a polyphase decimator? Would be much
appreciated.

Thank you
Duncan

P.S. Back to the lab to try to figure this out, before you all prove
my ignorance. Lets see who wins!!

```
```
redpathdu@yahoo.co.uk wrote:

> 1...I created a polyphase FIR interpolator, sampling frequency is
> upsampled by 10 from 10KHz to 100KHz. It works fine and I get the
> required frequencies output on the scope. I notice however, that the
> output gain is much lower than that with a standard FIR sampled at 100
> KHz with the same coefficients. Is there a gain issue with the
> polyphase structure?

When you are upsampling the signal by a factor of N, the gain of the
filter is N times lower compared to the filter design value. That
happens because you are using only every Nth coefficient of the filter
when calculating the output sample.

>
> 2...I tried to create a polyphase FIR decimator, downsampling by 10
> from 100KHz to 10KHz. I cannot get it to work.

Look for bugs.

> Should the coefficients
> be exactly the same as the interpolator?

They can be the same, but they don't have to be the same.

>
> 3...Should the input to each filter in the polyphase filter structure
> of the decimator be a data sample from the ADC followed by zeros, as
> the other samples from the ADC are being input to the other filters in
> the structure?

You are missing the basics. There is absolutely no need to stuff zeroes
for the decimator.

> 4...Anybody got any C code for a polyphase decimator? Would be much
> appreciated.

for(i = 0; i < N; i++) acc += x[i]*k[i];

DSP and Mixed Signal Design Consultant

http://www.abvolt.com
```
```On 12 Mar, 15:24, Vladimir Vassilevsky <antispam_bo...@hotmail.com>
wrote:
> redpat...@yahoo.co.uk wrote:
> > 1...I created a polyphase FIR interpolator, sampling frequency is
> > upsampled by 10 from 10KHz to 100KHz. It works fine and I get the
> > required frequencies output on the scope. I notice however, that the
> > output gain is much lower than that with a standard FIR sampled at 100
> > KHz with the same coefficients. Is there a gain issue with the
> > polyphase structure?
>
> When you are upsampling the signal by a factor of N, the gain of the
> filter is N times lower compared to the filter design value. That
> happens because you are using only every Nth coefficient of the filter
> when calculating the output sample.
>
>
>
> > 2...I tried to create a polyphase FIR decimator, downsampling by 10
> > from 100KHz to 10KHz. I cannot get it to work.
>
> Look for bugs.
>
> > Should the coefficients
> > be exactly the same as the interpolator?
>
> They can be the same, but they don't have to be the same.
>
>
>
> > 3...Should the input to each filter in the polyphase filter structure
> > of the decimator be a data sample from the ADC followed by zeros, as
> > the other samples from the ADC are being input to the other filters in
> > the structure?
>
> You are missing the basics. There is absolutely no need to stuff zeroes
> for the decimator.
>
> > 4...Anybody got any C code for a polyphase decimator? Would be much
> > appreciated.
>
> for(i = 0; i < N; i++) acc += x[i]*k[i];
>
>
> DSP and Mixed Signal Design Consultant
>
> http://www.abvolt.com

That was much to quick. You didn't give me time to get the scope
switched on.

Thank you
Duncan

```
```"Vladimir Vassilevsky" <antispam_bogus@hotmail.com> wrote in message
news:tgeJh.3750\$JZ3.3413@newssvr13.news.prodigy.net...
>
>
> redpathdu@yahoo.co.uk wrote:
>
>
>> 1...I created a polyphase FIR interpolator, sampling frequency is
>> upsampled by 10 from 10KHz to 100KHz. It works fine and I get the
>> required frequencies output on the scope. I notice however, that the
>> output gain is much lower than that with a standard FIR sampled at 100
>> KHz with the same coefficients. Is there a gain issue with the
>> polyphase structure?
>
> When you are upsampling the signal by a factor of N, the gain of the
> filter is N times lower compared to the filter design value. That happens
> because you are using only every Nth coefficient of the filter when
> calculating the output sample.
>

I understand what you say here but I'm puzzled by it.  I think my confusion
is because we don't have a filter reference defined.

In this case the filter will be a lowpass with cutoff at fs/(2*10) and where
fs is the new sampling frequency.  Presuming that the gain is 1.0 in the
passband then 1/N of the energy of the original signal will remain.

By the "original signal" I mean the zero-stuffed version of the signal.
This one can be viewed as the original signal replicated N times in
frequency.  That seems a reasonable starting point for talking about the
filter.

Otherwise, if we define the "original signal" as the one at the original
sample rate then the zero stuffing step does something doesn't it?  It
reduces the average energy per sample by N.

So, I think this "loss" is more about the signal and not about the filter.

Fred

```
```"Vladimir Vassilevsky" <antispam_bogus@hotmail.com> wrote in message
news:tgeJh.3750\$JZ3.3413@newssvr13.news.prodigy.net...
>
>
> redpathdu@yahoo.co.uk wrote:
>
>
>> 1...I created a polyphase FIR interpolator, sampling frequency is
>> upsampled by 10 from 10KHz to 100KHz. It works fine and I get the
>> required frequencies output on the scope. I notice however, that the
>> output gain is much lower than that with a standard FIR sampled at 100
>> KHz with the same coefficients. Is there a gain issue with the
>> polyphase structure?
>
> When you are upsampling the signal by a factor of N, the gain of the
> filter is N times lower compared to the filter design value. That happens
> because you are using only every Nth coefficient of the filter when
> calculating the output sample.
>

I understand what you say here but I'm puzzled by it.  I think my confusion
is because we don't have a filter reference defined.

In this case the filter will be a lowpass with cutoff at fs/(2*10) and where
fs is the new sampling frequency.  Presuming that the gain is 1.0 in the
passband then 1/N of the energy of the original signal will remain.

By the "original signal" I mean the zero-stuffed version of the signal.
This one can be viewed as the original signal replicated N times in
frequency.  That seems a reasonable starting point for talking about the
filter.

Otherwise, if we define the "original signal" as the one at the original
sample rate then the zero stuffing step does something doesn't it?  It
reduces the average energy per sample by N.

So, I think this "loss" is more about the signal and not about the filter.

Fred

```
```On 12 Mar, 17:00, "Fred Marshall" <fmarshallx@remove_the_x.acm.org>
wrote:
> "Vladimir Vassilevsky" <antispam_bo...@hotmail.com> wrote in message
>
> news:tgeJh.3750\$JZ3.3413@newssvr13.news.prodigy.net...
>
>
>
>
>
>
>
> > redpat...@yahoo.co.uk wrote:
>
> >> 1...I created a polyphase FIR interpolator, sampling frequency is
> >> upsampled by 10 from 10KHz to 100KHz. It works fine and I get the
> >> required frequencies output on the scope. I notice however, that the
> >> output gain is much lower than that with a standard FIR sampled at 100
> >> KHz with the same coefficients. Is there a gain issue with the
> >> polyphase structure?
>
> > When you are upsampling the signal by a factor of N, the gain of the
> > filter is N times lower compared to the filter design value. That happens
> > because you are using only every Nth coefficient of the filter when
> > calculating the output sample.
>
>
> I understand what you say here but I'm puzzled by it.  I think my confusion
> is because we don't have a filter reference defined.
>
> In this case the filter will be a lowpass with cutoff at fs/(2*10) and where
> fs is the new sampling frequency.  Presuming that the gain is 1.0 in the
> passband then 1/N of the energy of the original signal will remain.
>
> By the "original signal" I mean the zero-stuffed version of the signal.
> This one can be viewed as the original signal replicated N times in
> frequency.  That seems a reasonable starting point for talking about the
> filter.
>
> Otherwise, if we define the "original signal" as the one at the original
> sample rate then the zero stuffing step does something doesn't it?  It
> reduces the average energy per sample by N.
>
> So, I think this "loss" is more about the signal and not about the filter.
>
> Fred- Hide quoted text -
>
> - Show quoted text -

Hi,

I think you've shown up my ignorance. Still having problems...here is
my decimator filter.
Lowpass filter
Cut off freq = 1KHz
Stop freq = 2KHz
Fsample = 100KHz
No of samples = 360
and I want to downsample by 10 to 10 KHz

My input signal is a composite of 500Hz + 1800Hz + 3KHz and I see
these on the spec analyser when the sampling freq is 100KHz.

With regard to the polyphase structure..the coefficients are
calculated based on the 100 KHz sample rate and arranged as for the
polyphase structure. I mux the data into the filters at the 100 KHz
sample rate...is this correct or should it be 10Khz?

I sum the output of all the filters and output them at 10KHz,  but I
am getting nothing like what I expect. When I set the sample rate of
the spec analyser to 10 Khz, I would expect to see a peak at 500Hz.

I know there is a gap in my understanding, but I cannot figure it out.
The polyphase decimator structure seems to be what is shown in the
literature.

Hope you can help
duncan

```
```<redpathdu@yahoo.co.uk> wrote in message > my decimator filter.
> Lowpass filter
> Cut off freq = 1KHz
> Stop freq = 2KHz
> Fsample = 100KHz
> No of samples = 360
> and I want to downsample by 10 to 10 KHz
>
> My input signal is a composite of 500Hz + 1800Hz + 3KHz and I see
> these on the spec analyser when the sampling freq is 100KHz.
>
> With regard to the polyphase structure..the coefficients are
> calculated based on the 100 KHz sample rate and arranged as for the
> polyphase structure. I mux the data into the filters at the 100 KHz
> sample rate...is this correct or should it be 10Khz?
>
> I sum the output of all the filters and output them at 10KHz,  but I
> am getting nothing like what I expect. When I set the sample rate of
> the spec analyser to 10 Khz, I would expect to see a peak at 500Hz.
>
> I know there is a gap in my understanding, but I cannot figure it out.
> The polyphase decimator structure seems to be what is shown in the
> literature.
>
> Hope you can help
> duncan

Let me see if I can play back what you're saying:

The signal has *additive / summed* (and not multiplied/modulated) components
at 500Hz + 1800Hz + 3KHz.

The sample rate is 100kHz.
The desired decimated sample rate is 10kHz.

The length of the lowpass filter is 360 [at 100kHz / 10usec] or nearly 3.6
msec long.  So, roughly it should be capable of a transition band width of
277 Hz or greater.

The lowpass filter transition is from 1kHz to 2kHz so the length makes sense
if the specs are tight.
But, this makes one wonder what you expect to have happen to the 3kHz
component... ??

In view of the numbers it makes one wonder why you aren't filtering more
like 3 kHz band edge and 5kHz stop since all you need is to filter out
everything above 5kHz to support the desired 10kHz sample rate.  That would
allow for a shorter filter - if that matters - possibly as short as 50 if
the requirements are modest and length 100 if the requirements are
"typical".

Polyphase filters are just a way of implementing a FIR filter.  So, I would
think that one might implement a simple FIR filter first if there are system
problems to consider.  You may well be in that mode.

Then, if the system works with a simple FIR you can change to a polyphase
implementation to see if it's the fundamental filter (or something else) or
the polyphase implementation that's the problem.

As long as the processing time isn't too great with the simple FIR
implementation then this approach could make sense for you.

Fred

```
```> - Show quoted text -
Hi Fred,

created an upsampler to go from 10KHz to 100KHz using basically the
same spec in a polyphase structure...worked perfectly. I then created
the polyphase downsampler, thinking it would be as easy!!!

Regards
Duncan

```
```redpathdu@yahoo.co.uk wrote:
> 4...Anybody got any C code for a polyphase decimator? Would be much
> appreciated.

This site has a nice tutorial for multirate filters, as well as source
code written in C.

http://www.dspguru.com/info/faqs/mrfaq.htm

Enjoy.

--
Jim Thomas            Principal Applications Engineer  Bittware, Inc
jthomas@bittware.com  http://www.bittware.com    (603) 226-0404 x536
Build a man a fire and he is warm for a day.
Set a man on fire and he is warm for the rest of his life.
```
```I just wanted to clarify some decimation issues with you in regards to
the polyphase decimator I created. As stated earlier, my specification
is as follows

Lowpass filter
Cut off freq = 1KHz
Stop freq = 2KHz
Fsample = 100KHz
No of samples = 360

and I want to downsample by 10 to 10 KHz

My input signal is a composite of 500Hz + 1800Hz + 3KHz and I see them
correctly on the analyzer when sampling at 100 KHz. At the output of
the filter, I would expect to see the 500 Hz signal while the 1.8KHz
and 3KHz would be attenuated.

Here are a few questions. I just want to verify my understanding is
correct.

If I downsample by 10....

1...Will the cut off freq be 100 Hz and Stop freq 200 Hz ?
2...Will the input signal now be 50Hz + 180Hz + 300Hz

My understanding is that fcut and fstop will remain 1 Khz and 2 KHz
respectively and that the input signal spectrum shouldn't change, but
I am no expert.

Best Regards
Duncan

```