COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

Reply
 
Thread Tools Display Modes
Old 10-24-2015, 08:06 AM   #1
Daxx
Human being with feelings
 
Join Date: Oct 2015
Posts: 3
Default What filter are used for Downsampling?

Hi folks.

I'm using NAudio in WPF Project for downsampling some audiodata. I have to compare the results with matlab. But for that I need to know which filter is applied befor I can rebuild it on Matlab. I asked the guy from NAudio and he said that the resampler is only a port from WDL Resample. So my question is, can anyone tell me what kind of filter (Typ,Order) I have to use in Matlab?

Thx for any help
Daxx is offline   Reply With Quote
Old 10-24-2015, 04:09 PM   #2
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,652
Default

Well, the WDL resampler can do anything from simple linear resampling, to fast IIR filter resamplng, to HQ sinc resampling using up to a 8192 point FIR kernel at 8192x oversampling.
Tale is offline   Reply With Quote
Old 10-25-2015, 02:48 AM   #3
Daxx
Human being with feelings
 
Join Date: Oct 2015
Posts: 3
Default

Ok, thx. When I look at the sourcecode, I think NAudio only uses IIR Filters at the moment.

resampler = new WdlResampler();
resampler.SetMode(bool interp = true, int filtercnt = 2, bool sinc = false);


At ResampleOut-Method a WDL_Resampler_IIRFilter is created and filtercnt-times applied.

So that would be an IIR-Filter of order 2 right?


SetFilterParms(float filterpos = 0.693f, float filterq = 0.707f);
I don't know exactly how to use this parameters when designing the filter in Matlab. And I think, I also have to know the design-pattern like Chebyshev, or do I understand something wrong?
Daxx is offline   Reply With Quote
Old 10-25-2015, 12:41 PM   #4
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,652
Default

Quote:
Originally Posted by Daxx View Post
Ok, thx. When I look at the sourcecode, I think NAudio only uses IIR Filters at the moment.

resampler = new WdlResampler();
resampler.SetMode(bool interp = true, int filtercnt = 2, bool sinc = false);
Yeah, that means it uses linear interpolation with IIR filtering.

Quote:
Originally Posted by Daxx View Post
At ResampleOut-Method a WDL_Resampler_IIRFilter is created and filtercnt-times applied.

So that would be an IIR-Filter of order 2 right?
Each filter is order 2, so 2 filters would be order 4.


Quote:
Originally Posted by Daxx View Post
SetFilterParms(float filterpos = 0.693f, float filterq = 0.707f);
I don't know exactly how to use this parameters when designing the filter in Matlab. And I think, I also have to know the design-pattern like Chebyshev, or do I understand something wrong?
Well, I can't help you with Matlab, but I do know that the filter is a standard 2nd order low-pass filter as described here:

http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt

I think the cutoff frequency is at filterpos*srateout/2.
Tale is offline   Reply With Quote
Old 10-27-2015, 08:52 AM   #5
Daxx
Human being with feelings
 
Join Date: Oct 2015
Posts: 3
Default

Thx Tale, you helped me a lot.

I've managed to figure it out. Here is the code if someone is interested:

function [xDown] = WDL_DownSample(x,Fs,FsDown)

%% model filter like WDL-Resampler
m_filterpos = 0.693;
m_filterq = 0.707;

fpos = 1/ (Fs/FsDown) * m_filterpos;
pos = fpos * pi;
cpos = cos(pos);
spos = sin(pos);

alpha = spos / (2.0 * m_filterq);

sc = 1.0 / (1 + alpha);
m_b1 = (1 - cpos) * sc;
m_b0 = m_b1 * 0.5;
m_b2 = m_b1 * 0.5;
m_a1 = -2 * cpos * sc;
m_a2 = (1 - alpha) * sc;

num = [m_b0,m_b1,m_b2];
denom = [1,m_a1,m_a2];
sos = tf2sos(num,denom);

%% DownSampling
step = Fs / FsDown;

xFiltered = sosfilt(sos,x);
xFiltered = sosfilt(sos,xFiltered);

xDown = downsample(xFiltered,step);

end
Daxx is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.