Plug-ins, Hosts, Apps,
Hardware, Soundware
Developers
(Brands)
Videos Groups
Whats's in?
Banks & Patches
Download & Upload
Music Search
KVR
   
KVR Forum » DSP and Plug-in Development
Thread Read
Correct way to oversample?
zckumling
KVRer
- profile
- pm
PostPosted: Tue Jun 29, 2010 10:22 pm reply with quote
I'm not sure if I'm doing the polyphase oversampling right..
I use the polyphase filters from the musicdsp.org archive..

here is the code for 4x oversampling as it is atm:



   inline void process4x(double& sample)
   {
       a = halfband[0]->process( sample );
         a = halfband[2]->process( a );
         a = effect.process ( a * 4.0);
         a = halfband[3]->process ( a );
         a = halfband[2]->process ( null );
         a = effect.process ( a * 4.0);
         a = halfband[3]->process ( a );
      a = halfband[1]->process( a );
      sample = a; //Decimate
      a = halfband[0]->process( null );
         a = halfband[2]->process( a );
         a = effect.process ( a * 4.0);
         a = halfband[3]->process ( a );
         a = halfband[2]->process ( null );
         a = effect.process ( a * 4.0);
         a = halfband[3]->process ( a );
      a = halfband[1]->process( a );
   }


The 4.0 multiplier is for normalizing the gain for the effects input..
Is this a correct way to do it?
^ Joined: 07 Feb 2010  Member: #225447  
nollock
KVRian
- profile
- pm
PostPosted: Wed Jun 30, 2010 12:22 pm reply with quote
To upsample 2x you zero stuff the source sample, place a zero after every sample (so it's twice as long and every other sample is zero) and feed that through a half band filter.

To downsample by 1/2 you filter by the half band filter and throw away every other sample.

So to upsample 2x you alternately feed the half band filter a sample, then a zero, a sample, a zero, and so on...

To up sample 4x you do that twice. You zero stuff the sample, filter it, then you zero stuff it again, and filter it again.

eg...

a = halfband1(input);
b = halfband1(0);

output0 = halfband2(a);
output1 = halfband2(0);
output2 = halfband2(b);
output3 = halfband2(0);

(4 output samples from 1 input)

To down sample 4 times you half band filter it, throw away every other sample, half band filter it again, and throw away every other sample again.

eg...

a = halfband1(input0);
halfband1(input1);
b = halfband1(input2);
halfband1(input3);

output = halfband2(a);
halfband2(b);

(1 output from 4 input samples)

HTH.
^ Joined: 09 Dec 2003  Member: #10919  
jupiter8
KVRAF
- profile
- pm
- e-mail
PostPosted: Wed Jun 30, 2010 12:51 pm reply with quote
I have an idea i might try in the next few days that involves oversampling.
It's an offline process so performance doesn't matter much. I was thinking of using a much higher quality interpolator when upsampling to avoid the filtering. Is this false DSP? Am i just fooling myself ? Intuitively it feels right but there's a nagging voice in the back of my head that tells me:"That's not how it's done".
----
At school they taught me how to be.
So pure in thought and word and deed.
They didn't quite succeed.
^ Joined: 17 Sep 2002  Member: #3863  Location: Gothenburg Sweden
zckumling
KVRer
- profile
- pm
PostPosted: Wed Jun 30, 2010 2:40 pm reply with quote
nollock:

Thanks, I think I understand it now...

(Does that hold for a recursive filter? Since I've heard of routines for memorlyless filters and recursive ones... )

So, if I understand this correct, this is for a recursive filter:


//effect.setSamplerate(4.0 * samplerate);

a = halfband1(input);
b = halfband1(0);

output0 = halfband2(a);
output1 = halfband2(0);
output2 = halfband2(b);
output3 = halfband2(0);

output0 = effect.process(output0);
output1 = effect.process(output1);
output2 = effect.process(output2);
output4 = effect.process(output3);

a = halfband1(output0);
halfband1(output1);
b = halfband1(output2);
halfband1(output3);

output = halfband2(a);
halfband2(b);


Have I understood it?
And should I upsample and downsample with the same halfband filter?
I don't know where I got the idea that I had to use one halfband filter for each time I upsampled by 2.. and one filter for each decimation..
^ Joined: 07 Feb 2010  Member: #225447  
nollock
KVRian
- profile
- pm
PostPosted: Wed Jun 30, 2010 2:53 pm reply with quote
jupiter8 wrote:
I have an idea i might try in the next few days that involves oversampling.
It's an offline process so performance doesn't matter much. I was thinking of using a much higher quality interpolator when upsampling to avoid the filtering. Is this false DSP? Am i just fooling myself ? Intuitively it feels right but there's a nagging voice in the back of my head that tells me:"That's not how it's done".


It's the same thing. An interpolator is a lowpass filter.

If for example you take a hermite interpolator. you can rearange the equation so it's in the form...

y = f1(x)*in[-1] + f2(x)*in[0] + f3(x)*in[1] + f4(x)*in[2]

Where x is subsample position and each of those f(x) parts is just a polynomial in x. So when you specify 'x' in the equation each of the f(x) parts becomes a constant, and you have a plane old FIR.

So if you're upsampling 4x then X is only ever [0, 0.25, 0.5, 0.75], so you have a set of 4 FIRS. Which is just a polyphase FIR.

Basicaly a polynomial interpolator and FIR are the same thing. The polynomial interpolator is just stored in a continuous form and allows random access.
Last edited by nollock on Wed Jun 30, 2010 3:00 pm; edited 2 times in total
^ Joined: 09 Dec 2003  Member: #10919  
nollock
KVRian
- profile
- pm
PostPosted: Wed Jun 30, 2010 2:58 pm reply with quote

//effect.setSamplerate(4.0 * samplerate);

a = halfband1(input);
b = halfband1(0);

output0 = halfband2(a);
output1 = halfband2(0);
output2 = halfband2(b);
output3 = halfband2(0);

output0 = effect.process(output0);
output1 = effect.process(output1);
output2 = effect.process(output2);
output4 = effect.process(output3);

a = halfband3(output0);
halfband3(output1);
b = halfband3(output2);
halfband3(output3);

output = halfband4(a);
halfband4(b);


You need to use seeperate filters for each step either up or down.

Otherwise you should be good to go.
^ Joined: 09 Dec 2003  Member: #10919  
zckumling
KVRer
- profile
- pm
PostPosted: Wed Jun 30, 2010 3:08 pm reply with quote
Thank you nollock, you have been very helpful! Smile
^ Joined: 07 Feb 2010  Member: #225447  
All times are GMT - 8 Hours

Printable version
Page 1 of 1
Display posts from previous:   
ReplyNew TopicPrevious TopicNext Topic
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
Username: Password:  
KVR Developer Challenge 2012