Sample Rate Conversion (Downsampling)
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
Sample Rate Conversion (Downsampling)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP
Author Message
Jaime Andrés Aranguren Ca
Guest





Posted: Tue Dec 14, 2004 10:40 pm    Post subject: Sample Rate Conversion (Downsampling) Reply with quote

Hello,

For a project which I'm working on, I have a 60Hz sinewave modulated with a
square wave at 0.5Hz, modulation is 2.72%

The signal comes sampled at 8kHz, I should downsample it to 200Hz, so M =
40. I do that in two stages, first with M1 = 10, then with M2 = 4. I
implemented polyphase structure in Simulink, and runs great. By "great" I
mean that the output signal, sampled at 200Hz, preserves the squarewave
shape perfectly.

Ths structure used in Simulink is the one in P.P. Vaidyanathan's book
"Multirate Systems and Filter Banks", figure 4.3-4 (a), page 124.

However, In my C implementation (on SHARC, BTW), the downsampled signal
looks weird. By "weird" I mean that the envelope of the output signal,
instead of being flat (square) as it is expected to be, seems more like a
low frequency sinusoid, still it is noticeable when the amplitude rises and
falls at the same frequency of the original modulating square wave.

Given this information, and the fact that Simulink implementation maps
directly to the figure in Vaidyanathan's book, I am pretty sure that I have
some mistakes in my C implementation, but I can't find them.

Could someone here please give me advice on what mistakes in implementing
the polyphase M-fold decimation filters lead to the sort of "weirdness" that
I got from my C implementation? That would be of much support in finding
what I did wrong.

If someone who desires to help me wants to have a look at the Simulink Model
that I implemented, to the output of my C (for SHARC) implementation, and/or
to my C implementation itself, please let me know, and I will be more than
pleased in sending it to you.

Kindest regards,

--
Jaime Andrés Aranguren Cardona
jaac@nospam.sanjaac.com
SanJaaC Electronics
Soluciones en DSP
www.sanjaac.com

(Remove "nospam" from e-mail address)
Back to top
Jon Harris
Guest





Posted: Tue Dec 14, 2004 11:13 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

Just a quick thought, one difference could be that in the Simulink case, your
8kHz sample rate is probably an _exact_ multiple of the 60Hz waveform, but in
the real-world case, it may not be. Try modifying your Simulink example to use
a slightly different frequency such as 60.37 Hz or something and see what
happens.

You could also try simplifying the problem by downsampling just the 60Hz
waveform without the modulation.

"Jaime Andrés Aranguren Cardona" <jaac@nospam.sanjaac.com> wrote in message
news:1103046565.72fb8397a7036cd0ab33545d0fe7c860@teranews...
Quote:
Hello,

For a project which I'm working on, I have a 60Hz sinewave modulated with a
square wave at 0.5Hz, modulation is 2.72%

The signal comes sampled at 8kHz, I should downsample it to 200Hz, so M =
40. I do that in two stages, first with M1 = 10, then with M2 = 4. I
implemented polyphase structure in Simulink, and runs great. By "great" I
mean that the output signal, sampled at 200Hz, preserves the squarewave
shape perfectly.

Ths structure used in Simulink is the one in P.P. Vaidyanathan's book
"Multirate Systems and Filter Banks", figure 4.3-4 (a), page 124.

However, In my C implementation (on SHARC, BTW), the downsampled signal
looks weird. By "weird" I mean that the envelope of the output signal,
instead of being flat (square) as it is expected to be, seems more like a
low frequency sinusoid, still it is noticeable when the amplitude rises and
falls at the same frequency of the original modulating square wave.

Given this information, and the fact that Simulink implementation maps
directly to the figure in Vaidyanathan's book, I am pretty sure that I have
some mistakes in my C implementation, but I can't find them.

Could someone here please give me advice on what mistakes in implementing
the polyphase M-fold decimation filters lead to the sort of "weirdness" that
I got from my C implementation? That would be of much support in finding
what I did wrong.
Back to top
David Kirkland
Guest





Posted: Tue Dec 14, 2004 11:22 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

Jaime Andrés Aranguren Cardona wrote:
Quote:
Hello,

For a project which I'm working on, I have a 60Hz sinewave modulated with a
square wave at 0.5Hz, modulation is 2.72%

The signal comes sampled at 8kHz, I should downsample it to 200Hz, so M =
40. I do that in two stages, first with M1 = 10, then with M2 = 4. I
implemented polyphase structure in Simulink, and runs great. By "great" I
mean that the output signal, sampled at 200Hz, preserves the squarewave
shape perfectly.

Ths structure used in Simulink is the one in P.P. Vaidyanathan's book
"Multirate Systems and Filter Banks", figure 4.3-4 (a), page 124.

However, In my C implementation (on SHARC, BTW), the downsampled signal
looks weird. By "weird" I mean that the envelope of the output signal,
instead of being flat (square) as it is expected to be, seems more like a
low frequency sinusoid, still it is noticeable when the amplitude rises and
falls at the same frequency of the original modulating square wave.

Given this information, and the fact that Simulink implementation maps
directly to the figure in Vaidyanathan's book, I am pretty sure that I have
some mistakes in my C implementation, but I can't find them.

Could someone here please give me advice on what mistakes in implementing
the polyphase M-fold decimation filters lead to the sort of "weirdness" that
I got from my C implementation? That would be of much support in finding
what I did wrong.

If someone who desires to help me wants to have a look at the Simulink Model
that I implemented, to the output of my C (for SHARC) implementation, and/or
to my C implementation itself, please let me know, and I will be more than
pleased in sending it to you.

Kindest regards,

--
Jaime Andrés Aranguren Cardona
jaac@nospam.sanjaac.com
SanJaaC Electronics
Soluciones en DSP
www.sanjaac.com

(Remove "nospam" from e-mail address)



You could also try a regular decimation implementation (instead of
polyphase) to see whether of not it's your polyphase filtering code.

Cheers,
David
Back to top
Att
Guest





Posted: Tue Dec 14, 2004 11:27 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

Just another thought. Did you make sure you cycled through the coeffs in
the right order.
Try reversing the sequence in which you use the coeffs.
Although I am as careful as I can be, I can't tell you how many times I end
up experimenting
till I get the sequencing right.

Regards,
Dave Shaw
Quote:

Could someone here please give me advice on what mistakes in implementing
the polyphase M-fold decimation filters lead to the sort of "weirdness"
that
I got from my C implementation? That would be of much support in finding
what I did wrong.

If someone who desires to help me wants to have a look at the Simulink
Model
that I implemented, to the output of my C (for SHARC) implementation,
and/or
to my C implementation itself, please let me know, and I will be more than
pleased in sending it to you.
Back to top
Jon Harris
Guest





Posted: Tue Dec 14, 2004 11:34 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

Good suggestion. For some reason, I usually find the order is backwards from
what I would intuitively think! There was an interesting thread on this a while
back:
http://tinyurl.com/3s6dc

"Att" <david.g.shaw@att.net> wrote in message
news:agGvd.124735$7i4.59110@bgtnsc05-news.ops.worldnet.att.net...
Quote:
Just another thought. Did you make sure you cycled through the coeffs in
the right order.
Try reversing the sequence in which you use the coeffs.
Although I am as careful as I can be, I can't tell you how many times I end
up experimenting
till I get the sequencing right.

Regards,
Dave Shaw

Could someone here please give me advice on what mistakes in implementing
the polyphase M-fold decimation filters lead to the sort of "weirdness"
that
I got from my C implementation? That would be of much support in finding
what I did wrong.

If someone who desires to help me wants to have a look at the Simulink
Model
that I implemented, to the output of my C (for SHARC) implementation,
and/or
to my C implementation itself, please let me know, and I will be more than
pleased in sending it to you.
Back to top
Jaime Andrés Aranguren Ca
Guest





Posted: Wed Dec 15, 2004 8:17 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

"Jon Harris" <goldentully@hotmail.com> escribió en el mensaje
news:328q1cF3k3plsU1@individual.net...
Quote:
Good suggestion. For some reason, I usually find the order is backwards
from
what I would intuitively think!

Hello Sirs,

I tried reversing the coefficients, but that simply didn't work. This was my
original code (please excuse me for posting this long stuff here, but I
don't see any other method to let you know what I did):


// The Sample Rate Conversion Routines - Saving data, stage 1
void SrcSaveStage1 (float sample)
{
int i;
static int sampleCount;
float tmpSample;

// Update the delay line to input to SRC algo
for (i = SRC_STAGE1_N_FILT-1; i > 0; i--) {
srcStage1_Delay[i] = srcStage1_Delay[i-1];
}
srcStage1_Delay[0] = sample;

// Increment sample counter
sampleCount++;
if (sampleCount == SRC_STAGE1_N_FILT) {
// Toggle flag everytime we downsampled by 10
ToggleFlag4_9(8);
tmpSample = SrcProcessStage1(); // Process one of each M1(=10) samples,
SRC algo stage 1
SrcSaveStage2 (tmpSample); // And save for M2(4), stage 2
sampleCount = 0;
}
}

// The Sample Rate Conversion Routines - Saving data, stage 2
void SrcSaveStage2 (float sample)
{
int i;
static int sampleCount;

// Update the delay line to input to SRC algo
for (i = SRC_STAGE2_N_FILT-1; i > 0; i--) {
srcStage2_Delay[i] = srcStage2_Delay[i-1];
}
srcStage2_Delay[0] = sample;

// Increment sample counter
sampleCount++;
if (sampleCount == SRC_STAGE2_N_FILT) {
srcOut = SrcProcessStage2(); // Process one of each M1(=10) samples, SRC
algo stage 1
srcReady = true; // Set the flag
sampleCount = 0; // Restart counter
}
else {
srcReady = false; // Keep flag cleared
}
}

// The Sample Rate Conversion Routines - Processing data, stage 1
float SrcProcessStage1 (void)
{
float outSamples[SRC_STAGE1_N_FILT];
float output;
int i;

output = 0;
outSamples[0] = fir(srcStage1_Delay[0], srcStage1_1Coeffs,
srcStage1_1State, SRC_STAGE1_FILT_LEN);
outSamples[1] = fir(srcStage1_Delay[1], srcStage1_2Coeffs,
srcStage1_2State, SRC_STAGE1_FILT_LEN);
outSamples[2] = fir(srcStage1_Delay[2], srcStage1_3Coeffs,
srcStage1_3State, SRC_STAGE1_FILT_LEN);
outSamples[3] = fir(srcStage1_Delay[3], srcStage1_4Coeffs,
srcStage1_4State, SRC_STAGE1_FILT_LEN);
outSamples[4] = fir(srcStage1_Delay[4], srcStage1_5Coeffs,
srcStage1_5State, SRC_STAGE1_FILT_LEN);
outSamples[5] = fir(srcStage1_Delay[5], srcStage1_6Coeffs,
srcStage1_6State, SRC_STAGE1_FILT_LEN);
outSamples[6] = fir(srcStage1_Delay[6], srcStage1_7Coeffs,
srcStage1_7State, SRC_STAGE1_FILT_LEN);
outSamples[7] = fir(srcStage1_Delay[7], srcStage1_8Coeffs,
srcStage1_8State, SRC_STAGE1_FILT_LEN);
outSamples[8] = fir(srcStage1_Delay[8], srcStage1_9Coeffs,
srcStage1_9State, SRC_STAGE1_FILT_LEN);
outSamples[9] = fir(srcStage1_Delay[9], srcStage1_10Coeffs,
srcStage1_10State, SRC_STAGE1_FILT_LEN);

for (i = 0; i < SRC_STAGE1_N_FILT; i++) {
output += outSamples[i];
}

return output;
}

// The Sample Rate Conversion Routines - Processing data, stage 2
float SrcProcessStage2 (void)
{
float outSamples[SRC_STAGE2_N_FILT];
float output;
int i;

output = 0;
outSamples[0] = fir(srcStage2_Delay[0], srcStage2_1Coeffs,
srcStage2_1State, SRC_STAGE2_FILT_LEN);
outSamples[1] = fir(srcStage2_Delay[1], srcStage2_2Coeffs,
srcStage2_2State, SRC_STAGE2_FILT_LEN);
outSamples[2] = fir(srcStage2_Delay[2], srcStage2_3Coeffs,
srcStage2_3State, SRC_STAGE2_FILT_LEN);
outSamples[3] = fir(srcStage2_Delay[3], srcStage2_4Coeffs,
srcStage2_4State, SRC_STAGE2_FILT_LEN);

for (i = 0; i < SRC_STAGE2_N_FILT; i++) {
output += outSamples[i];
}

return output;
}

--------------------------

Every time a sample arrives (every 125 us, 8kHz sample rate), I execute
SrcSaveStage1(). In this routine I simply put the samples in the 10-tap
delay line, the one at the input of the "Polyphase Iimplementation Stage 1"
in the Simulink model. Once I have 10 samples aquired (and the delay line
full) I do the processing of it. This act of processing only when the 10
samples acquired implements the downsampling by 10 in the simulink model.
The processing is done in the SrcProcessStage1() routine. This one simply
consists on a bank of 10 FIR filters, with coefficients as defined in
Matlab, the same ones for the Simulink simulation. The input for each of the
filters is a tap from the delay line, so the input to the filter is
downsampled by 10, as desired. The output of the filters is summed up.

Once I have a sample out of the stage 1 (every 1250 uS, 800 Hz), I do the
same processing for stage 1, very similar as it was for stage 1, but with
the respective filters and downsampling factor (4).

So the final output is sampled at 200 Hz.

I think I was moving the downsampling blocks of each branch of the structure
(refer to Vaydianathan's book) BEFORE the input delay line. So I modified my
code, here it is:

--------------------------
// The Sample Rate Conversion Routines - Saving data, stage 1
void SrcSaveStage1 (float sample)
{
int i;
static int sampleCount;

// Update the delay line to input to SRC algo
for (i = SRC_STAGE1_N_FILT-1; i > 0; i--) {
srcStage1_Delay[i] = srcStage1_Delay[i-1];
}
srcStage1_Delay[0] = sample;

// Increment sample counter
sampleCount++;
if (sampleCount == SRC_STAGE1_N_FILT) {
sampleCount = 0;
}

SrcProcessStage1(); // Do the downsampling and filtering every 10 samples
}

// The Sample Rate Conversion Routines - Saving data, stage 2
void SrcSaveStage2 (float sample)
{
int i;
static int sampleCount;

// Update the delay line to input to SRC algo
for (i = SRC_STAGE2_N_FILT-1; i > 0; i--) {
srcStage2_Delay[i] = srcStage2_Delay[i-1];
}
srcStage2_Delay[0] = sample;

// Increment sample counter
sampleCount++;
if (sampleCount == SRC_STAGE2_N_FILT) {
sampleCount = 0;
}

SrcProcessStage2(); // Do the downsampling and filtering every 4 samples
}

// The Sample Rate Conversion Routines - Processing data, stage 1
void SrcProcessStage1 (void)
{
float outSamples[SRC_STAGE1_N_FILT];
float output;
int i;

static int sampleCount;

// Store data from input delay line into
// downsampling delay lines
srcStage1_Delay1[sampleCount] = srcStage1_Delay[0];
srcStage1_Delay2[sampleCount] = srcStage1_Delay[1];
srcStage1_Delay3[sampleCount] = srcStage1_Delay[2];
srcStage1_Delay4[sampleCount] = srcStage1_Delay[3];
srcStage1_Delay5[sampleCount] = srcStage1_Delay[4];
srcStage1_Delay6[sampleCount] = srcStage1_Delay[5];
srcStage1_Delay7[sampleCount] = srcStage1_Delay[6];
srcStage1_Delay8[sampleCount] = srcStage1_Delay[7];
srcStage1_Delay9[sampleCount] = srcStage1_Delay[8];
srcStage1_Delay10[sampleCount] = srcStage1_Delay[9];

sampleCount++; //Increment counter

// Once every delay line for downsampling has M1 = 10 samples,
// filter with the oldest sample on each delay line
if (sampleCount == SRC_STAGE1_N_FILT) {
// Toggle flag everytime we downsampled by 10
ToggleFlag4_9(8);

// Do the filtering
output = 0;
outSamples[0] = fir(srcStage1_Delay1[0], srcStage1_1Coeffs,
srcStage1_1State, SRC_STAGE1_FILT_LEN);
outSamples[1] = fir(srcStage1_Delay2[0], srcStage1_2Coeffs,
srcStage1_2State, SRC_STAGE1_FILT_LEN);
outSamples[2] = fir(srcStage1_Delay3[0], srcStage1_3Coeffs,
srcStage1_3State, SRC_STAGE1_FILT_LEN);
outSamples[3] = fir(srcStage1_Delay4[0], srcStage1_4Coeffs,
srcStage1_4State, SRC_STAGE1_FILT_LEN);
outSamples[4] = fir(srcStage1_Delay5[0], srcStage1_5Coeffs,
srcStage1_5State, SRC_STAGE1_FILT_LEN);
outSamples[5] = fir(srcStage1_Delay6[0], srcStage1_6Coeffs,
srcStage1_6State, SRC_STAGE1_FILT_LEN);
outSamples[6] = fir(srcStage1_Delay7[0], srcStage1_7Coeffs,
srcStage1_7State, SRC_STAGE1_FILT_LEN);
outSamples[7] = fir(srcStage1_Delay8[0], srcStage1_8Coeffs,
srcStage1_8State, SRC_STAGE1_FILT_LEN);
outSamples[8] = fir(srcStage1_Delay9[0], srcStage1_9Coeffs,
srcStage1_9State, SRC_STAGE1_FILT_LEN);
outSamples[9] = fir(srcStage1_Delay10[0], srcStage1_10Coeffs,
srcStage1_10State, SRC_STAGE1_FILT_LEN);

// Final sum of filter outputs
for (i = 0; i < SRC_STAGE1_N_FILT; i++) {
output += outSamples[i];
}

sampleCount = 0; // Restart counter (index)

SrcSaveStage2 (output); // And save for M2 = 4, stage 2
}
}

// The Sample Rate Conversion Routines - Processing data, stage 2
void SrcProcessStage2 (void)
{
float outSamples[SRC_STAGE2_N_FILT];
float output;
int i;

static int sampleCount;

// Store data from input delay line into
// downsampling delay lines
srcStage2_Delay1[sampleCount] = srcStage2_Delay[0];
srcStage2_Delay2[sampleCount] = srcStage2_Delay[1];
srcStage2_Delay3[sampleCount] = srcStage2_Delay[2];
srcStage2_Delay4[sampleCount] = srcStage2_Delay[3];

sampleCount++; //Increment counter

// Once every delay line for downsampling has M2 = 4 samples,
// filter with the oldest sample on each delay line
if (sampleCount == SRC_STAGE2_N_FILT) {
// Toggle flag everytime we downsampled by 4 (this means, by 40)
ToggleFlag4_9(7);

// Do the filtering
output = 0;
outSamples[0] = fir(srcStage2_Delay1[0], srcStage1_1Coeffs,
srcStage1_1State, SRC_STAGE1_FILT_LEN);
outSamples[1] = fir(srcStage2_Delay2[0], srcStage1_2Coeffs,
srcStage1_2State, SRC_STAGE1_FILT_LEN);
outSamples[2] = fir(srcStage2_Delay3[0], srcStage1_3Coeffs,
srcStage1_3State, SRC_STAGE1_FILT_LEN);
outSamples[3] = fir(srcStage2_Delay4[0], srcStage1_4Coeffs,
srcStage1_4State, SRC_STAGE1_FILT_LEN);

// Final sum of filter outputs
for (i = 0; i < SRC_STAGE1_N_FILT; i++) {
output += outSamples[i];
}

sampleCount = 0; // Restart counter (index)
srcReady = true; // Set the flag

srcOut = output; // Save the oufinal output data
}
else {
srcReady = false; // Clear the flag
}
}

--------------------------

Now, every 125 us I update the input delay line, and store the data from
each tap on this delay line into a delay line for downsampling. Once I have
M1 = 10 samples in the downsampling delay lines, I run my M1 = 10 filters,
taking only the oldest sample of the downsampling delay lines as input, and
sum up the result.

Then I trigger the corresponding process for the second stage, but I get the
same results as from the very beginning. Reversing the filter coefficients
does not help at all.

What else could I try, guys? I'd really appreciate if you can take a look at
my code, and help me find out where the mistakes can be, or provide me with
some reference C code.

Thanks you very much in advance,

--
Jaime Andrés Aranguren Cardona
jaac@nospam.sanjaac.com
SanJaaC Electronics
Soluciones en DSP
www.sanjaac.com

(Remove "nospam" from e-mail address)
Back to top
Jim Thomas
Guest





Posted: Wed Dec 15, 2004 9:26 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

Jaime Andrés Aranguren Cardona wrote:
Quote:
What else could I try, guys? I'd really appreciate if you can take a look at
my code, and help me find out where the mistakes can be, or provide me with
some reference C code.

Thanks you very much in advance,

Did you see Grant's multirate code on dspguru.com?


--
Jim Thomas Principal Applications Engineer Bittware, Inc
jthomas@bittware.com http://www.bittware.com (603) 226-0404 x536
Failure is always an option
Back to top
Jaime Andrés Aranguren Ca
Guest





Posted: Wed Dec 15, 2004 9:43 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

"Jim Thomas" <jthomas@bittware.com> escribió en el mensaje
news:10s0pegaj0r88e9@corp.supernews.com...
Quote:
Jaime Andrés Aranguren Cardona wrote:
What else could I try, guys? I'd really appreciate if you can take a
look at
my code, and help me find out where the mistakes can be, or provide me
with
some reference C code.

Thanks you very much in advance,

Did you see Grant's multirate code on dspguru.com?


Hi Jim,

Yes I did. It is not polyphase, right? I'd love it was... Any example in C
with ployphase implementation?

--
Jaime Andrés Aranguren Cardona
jaac@nospam.sanjaac.com
SanJaaC Electronics
Soluciones en DSP
www.sanjaac.com

(Remove "nospam" from e-mail address)
Back to top
Bhaskar Thiagarajan
Guest





Posted: Wed Dec 15, 2004 11:19 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

"Jaime Andrés Aranguren Cardona" <jaac@nospam.sanjaac.com> wrote in message
news:1103129550.7987b75918af9ea133251f5237596ac2@teranews...
Quote:
"Jim Thomas" <jthomas@bittware.com> escribió en el mensaje
news:10s0pegaj0r88e9@corp.supernews.com...
Jaime Andrés Aranguren Cardona wrote:
What else could I try, guys? I'd really appreciate if you can take a
look at
my code, and help me find out where the mistakes can be, or provide me
with
some reference C code.

Thanks you very much in advance,

Did you see Grant's multirate code on dspguru.com?


Hi Jim,

Yes I did. It is not polyphase, right? I'd love it was... Any example in C
with ployphase implementation?

Yes - from what I remember it is a polyphase implementation.
Cheers
Bhaskar

Quote:
--
Jaime Andrés Aranguren Cardona
jaac@nospam.sanjaac.com
SanJaaC Electronics
Soluciones en DSP
www.sanjaac.com

(Remove "nospam" from e-mail address)

Back to top
Jon Harris
Guest





Posted: Wed Dec 15, 2004 11:24 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

Try this:
http://www.mega-nerd.com/SRC/
It includes source.

"Jaime Andrés Aranguren Cardona" <jaac@nospam.sanjaac.com> wrote in message
news:1103129550.7987b75918af9ea133251f5237596ac2@teranews...
Quote:
"Jim Thomas" <jthomas@bittware.com> escribió en el mensaje
news:10s0pegaj0r88e9@corp.supernews.com...
Jaime Andrés Aranguren Cardona wrote:
What else could I try, guys? I'd really appreciate if you can take a
look at
my code, and help me find out where the mistakes can be, or provide me
with
some reference C code.

Thanks you very much in advance,

Did you see Grant's multirate code on dspguru.com?

Hi Jim,

Yes I did. It is not polyphase, right? I'd love it was... Any example in C
with ployphase implementation?
Back to top
Ronald H. Nicholson Jr.
Guest





Posted: Thu Dec 16, 2004 4:58 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

In article <10s36eofav28raa@corp.supernews.com>,
Jim Thomas <jthomas@bittware.com> wrote:
Quote:
The interpolation code on dspguru is most definitely polyphase.

My understanding is that polyphase only comes into play during interpolation.
It's only during interpolation that you get the opportunity to skip through
the coefs - essentially choosing a phase of the impulse response.

Why choose a phase with one can calculate the coefficients of the
precise phase?

I prefer to think of both upsampling, interpolation and decimation as
identical processes, consisting of a filter plus an interpolator. If the
decimation results line up with the input, the the interpolator become
trivial (constant phase 0). The lowpass filter usually changes to cut at
near or under half the minima of the input and output sample frequencies.
The filter+interpolator (usually a windowed sync) coefficients can
sometimes be calculated directly, per sample, even in real-time on
a fast PC, no precalculated phase table lookup required except for
efficiency reasons (and the sin/cos routines can be more cache friendly
than large lookup tables on embedded systems with tiny caches). This,
of course, depends on the choice of window function (which can be much
more expensive than calculating a cosine or three).

The upsample-decimate and polyphase table method are merely opaque
optimizations, needed for systems with various performance or power
limitations. How often does one write their own sin/cos routines
for any other generic program?


IMHO. YMMV.
--
Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/
#include <canonical.disclaimer> // only my own opinions, etc.
Back to top
Jim Thomas
Guest





Posted: Thu Dec 16, 2004 7:21 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

Jaime Andrés Aranguren Cardona wrote:
Quote:
"Jim Thomas" <jthomas@bittware.com> escribió en el mensaje
news:10s0pegaj0r88e9@corp.supernews.com...

Jaime Andrés Aranguren Cardona wrote:

What else could I try, guys? I'd really appreciate if you can take a

look at

my code, and help me find out where the mistakes can be, or provide me

with

some reference C code.

Thanks you very much in advance,

Did you see Grant's multirate code on dspguru.com?



Hi Jim,

Yes I did. It is not polyphase, right? I'd love it was... Any example in C
with ployphase implementation?

The interpolation code on dspguru is most definitely polyphase.

My understanding is that polyphase only comes into play during interpolation.
It's only during interpolation that you get the opportunity to skip through the
coefs - essentially choosing a phase of the impulse response. In decimation you
work on contiguous samples, but only calculate the outputs you're going to keep.

Am I wrong?

--
Jim Thomas Principal Applications Engineer Bittware, Inc
jthomas@bittware.com http://www.bittware.com (603) 226-0404 x536
Hope springs occasionally.
Back to top
Randy Yates
Guest





Posted: Thu Dec 16, 2004 8:36 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

Jim Thomas <jthomas@bittware.com> writes:

Quote:
Jaime Andrés Aranguren Cardona wrote:
"Jim Thomas" <jthomas@bittware.com> escribió en el mensaje
news:10s0pegaj0r88e9@corp.supernews.com...


Jaime Andrés Aranguren Cardona wrote:

What else could I try, guys? I'd really appreciate if you can take a
look at



my code, and help me find out where the mistakes can be, or provide me
with



some reference C code.

Thanks you very much in advance,

Did you see Grant's multirate code on dspguru.com?

Hi Jim,

Yes I did. It is not polyphase, right? I'd love it was... Any
example in C

with ployphase implementation?

The interpolation code on dspguru is most definitely polyphase.

My understanding is that polyphase only comes into play during interpolation.
It's only during interpolation that you get the opportunity to skip
through the coefs - essentially choosing a phase of the impulse
response. In decimation you work on contiguous samples, but only
calculate the outputs you're going to keep.


Am I wrong?

Well, I hate to say wrong because I see exactly where you're coming
from and I like to view it your way, but according to Mitra [1] the
term "polyphase," and the corresponding partitioning of filter
coefficients, can be applied to both interpolators and decimators.

In a polyphase M-fold interpolator, you have M polyphase filter coefficient sets
E_0 through E_{M-1} that each operate at the incoming sample rate. Each are then
upsampled by M, delayed, and then summed. The end result is that, assuming the total
filter length is M*K (so that each polyphase section is K coefficients long),
your computations require M*K*Fs multiplications/second instead of M^2*K*Fs,
where Fs is the input sample rate.

In a polyphase M-fold decimator, you have M polyphase filter coefficient sets
E_0 through E_{M-1} that each operate at the outgoing sample rate. Each section
is fed from an M-fold downsampler. M phases of the input signal are obtained
at the M downsampler outputs by delaying the input of each by a sample. Then
each polyphase section is convolved and the results summed. Again
your computations require M*K*Fs multiplications/second instead of M^2*K*Fs,
where Fs is the output sample rate.
--
Randy Yates
Sony Ericsson Mobile Communications
Research Triangle Park, NC, USA
randy.yates@sonyericsson.com, 919-472-1124
Back to top
Jaime Andrés Aranguren Ca
Guest





Posted: Thu Dec 16, 2004 8:38 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

Quote:
Yes - from what I remember it is a polyphase implementation.
Cheers
Bhaskar

Hi,

Thanks Jim, thanks Bhaskar, thank you everybody.

Yes, it definitely is polyphase implementation. To be honest, I was
expecting to see some code similar to mine, with a "viewable" input delay
line, and additional delay lines for the decimation of the samples, prior to
filtering, one filter per branch.

After a thorough study of the code and actually running (and debugging) it
on MSVC++ (which I couldn't do when I first replied to Jim), I could really
understand it... What a clean and beautiful implementation of decimation
filters, the polyphase way!

Although I am just up to integrate and test it with my SHARC code, it looks
like it won't be a source of confusion anymore!

I'll let you know how does it go.

Kindest regards,

--
Jaime Andrés Aranguren Cardona
jaac@nospam.sanjaac.com
SanJaaC Electronics
Soluciones en DSP
www.sanjaac.com

(Remove "nospam" from e-mail address)
Back to top
Jaime Andrés Aranguren Ca
Guest





Posted: Thu Dec 16, 2004 8:45 pm    Post subject: Re: Sample Rate Conversion (Downsampling) Reply with quote

Quote:
My understanding is that polyphase only comes into play during
interpolation.
It's only during interpolation that you get the opportunity to skip
through the coefs - essentially choosing a phase of the impulse
response. In decimation you work on contiguous samples, but only
calculate the outputs you're going to keep.


Am I wrong?


In a polyphase M-fold decimator, you have M polyphase filter coefficient
sets
E_0 through E_{M-1} that each operate at the outgoing sample rate. Each
section
is fed from an M-fold downsampler. M phases of the input signal are
obtained
at the M downsampler outputs by delaying the input of each by a sample.
Then
each polyphase section is convolved and the results summed. Again
your computations require M*K*Fs multiplications/second instead of
M^2*K*Fs,
where Fs is the output sample rate.

This is how I understand it is, too... Don't see the reason for Jim to say
that polyphase only comes into play during interpolation. Could you Jim
please explain me your point of view?

As I see on most diagrams, you have the filter splitted in branches, each
one having a different phase response, thus the term "polyphase", both in
interpolation and decimation filters.

I ask too, "Am I wrong?".

Regards,

--
Jaime Andrés Aranguren Cardona
jaac@nospam.sanjaac.com
SanJaaC Electronics
Soluciones en DSP
www.sanjaac.com

(Remove "nospam" from e-mail address)
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB