A brief introduction on how the Polyphase filter works.
Say you had raw samples, at a rate of 1kHz, and you want to move them to 1.5kHz.
To do this you can
1. 'Upsample' to 3kHz sample rates
2. 'Downsample to 1.5kHz.
This is at the same time easier than it sounds and harder than it sounds.
The second step is easy. If the 3kHz stream of samples contains no frequencies over 750Hz, then we can just discard every other sample and not loose information.
So the hard bit is how to upsample.... and it isn't too hard either
We can just put two zeros between every sample, then run that through a low pass filter (with a cut-off below 750Hz) and we have our 3kHz stream
Getting the ideal low-pass FIR filter kernel is very complex, but here's one I made earlier:
n filter[n]
-12 0.0517
-11 0.0641
-10 0.0460
-9 0.0000
-8 -0.0575
-7 -0.1008
-6 -0.1034
-5 -0.0490
-4 0.0612
-3 0.2067
-2 0.3527
-1 0.4604
0 0.5000
1 0.4604
2 0.3527
3 0.2067
4 0.0612
5 -0.0490
6 -0.1034
7 -0.1008
8 -0.0575
9 0.0000
10 0.0460
11 0.0641
12 0.0517
it is not ideal, just =SIN(n*PI()/4.5)/(n*PI()/4.5)*0.5, but is close enough.
To apply the kernel you multiple the stream of samples with filter coefficients, and then sum the result - e.g.
total = 0;
for(f = -12; f < 13; f++) {
total += sample_in[n+f] * filter[f];
}
sample_out[n] = total;
So that is how to get a 3kHz sample stream, and then just throw away every other sample.
Great this is all standard FIR DSP. So what is a polyphase filter?
It is just an optimization of that process, by not calculating the values of sample[n] that you will throw away during decimation, and by understanding that due to the upsampling, most of the input samples will be zero.
Here are the MACs used to generate one of the output samples:
0.0517 * 0
0.0641 * 0
0.0460 * 1.0000
0.0000 * 0
-0.0575 * 0
-0.1008 * 0.8660
-0.1034 * 0
-0.0490 * 0
0.0612 * -0.8660
0.2067 * 0
0.3527 * 0
0.4604 * -1.0000
0.5000 * 0
0.4604 * 0
0.3527 * -0.8660
0.2067 * 0
0.0612 * 0
-0.0490 * 0.8660
-0.1034 * 0
-0.1008 * 0
-0.0575 * 1.0000
0.0000 * 0
0.0460 * 0
0.0641 * 0.8660
0.0517 * 0
Because of the ratio of input sample rate to output sample rates, there are three different phases, and each requires around 9 MAC operations to generate an output value.
If we were not using a polyphase filter, it would require 25 MACs per sample, and we would calculate twice as many samples before d(so 50 MACs per output sample). As the upsampled sample rate goes up, using polyphase gets more and more efficient.
When the input and output sample rates are very close to each other e.g. 48,000Hz and 48,005Hz you can fudge it to be very close to ideal (e.g. with maybe 1024 different phase alignments to choose from).