Modelling air absorption (multiple bandpass filters?)

View: New views
19 Messages — Rating Filter:   Alert me  

Modelling air absorption (multiple bandpass filters?)

by e deleflie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

All,

I'm just trying to work out the best way to model air absorption. Its
a relatively simple operation (modeled in the chart on this page:
http://www.tonmeister.ca/main/textbook/node219.html)

For a certain frequency, I need to reduce the signal by a certain db amount.

One way would be to have lots of band passes, and for each one reduce
the signal by a certain amount, then add them all up again.

... but it just feels like the kind of DSP operation that might have
some out-of-the-box filter that has the right logic ... can anyone
help?

Etienne

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by Alberto de Campo-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,

I think you should be able get a very simple first approximation with
a OnePole,
with coefficients starting slightly above 0; I don't have a formula
at hand ATM.

do you need that for lots of reflections, or to model single sources
that are far away? how precise does should it be?

best, a

>All,
>
>I'm just trying to work out the best way to model air absorption. Its
>a relatively simple operation (modeled in the chart on this page:
>http://www.tonmeister.ca/main/textbook/node219.html)
>
>For a certain frequency, I need to reduce the signal by a certain db amount.
>
>One way would be to have lots of band passes, and for each one reduce
>the signal by a certain amount, then add them all up again.
>
>... but it just feels like the kind of DSP operation that might have
>some out-of-the-box filter that has the right logic ... can anyone
>help?
>
>Etienne
>
>_______________________________________________
>sc-users mailing list
>
>info (subscription, etc.):
>http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
>archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
>search: http://www.listarc.bham.ac.uk/lists/sc-users/search/


--
--
Alberto de Campo
Bergstrasse 59/33
A-8020 Graz, Austria
e-mail : adc@...
--

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by andersvi-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "e" == e deleflie <edeleflie@...> writes:

    e> All, I'm just trying to work out the best way to model air
    e> absorption. Its a relatively simple operation (modeled in the
    e> chart on this page:
    e> http://www.tonmeister.ca/main/textbook/node219.html)

If you've got the frequency-response at a given distance you can design
coeffs for a FIR-filter of a given order.  I guess in SC3 that would
mean using a Convolution ugen with a buffer holding the filter-coeffs
for as many zeros you want (the higher order filter the more close to
the frequency-response you get).

Or you could multiply the spectra by some PVMul or something, but it
would presumably distort phase.

Getting the coeffs for a FIR-filter involves some tricky maths.  Maybe
theres a method for Buffer to fill a buffer with nth-order fir-filter
coeffs based on an Env?

If not, it shouldnt be too hard.  The structure would be drawing an Env
representing the freq-envelope - getting the n y-values by passing it to
.asSignal - apply the maths to get the x-coeffs - and plugging that into
Convolution.

There are algorithms for this available in other tools - clm/snd for
instance.  Ill see if i can put something together if nobody else comes
up with anything.

-anders

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by Don Craig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Attached is an example of how to do what Anders describes here.
It writes out an aiff file that be loaded into a buffer for  
Convolution2.

There may be a more direct way to do this. Anybody?


[fir_from_fft.rtf]

{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf430
{\fonttbl\f0\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue191;\red191\green0\blue0;\red96\green96\blue96;
}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural

\f0\fs18 \cf0 (\
\cf2 var\cf0  env, index, val, spectrum, coeffs, sig, tab, re, im, file, size, ksize, out;\
\
size = 8192;\
ksize = 4411;\cf3 //odd number smaller than size\cf0 \
\
tab = \cf2 Signal\cf0 .fftCosTable(size);\
re = \cf2 Signal\cf0 .newClear(size);\
im = \cf2 Signal\cf0 .newClear(size);\
\
\cf3 //roll your own spectrum! this is a vowel: bass, "a", x, y pairs where x is frequency and y is amplitude\
//take the attenuation graph from the book and build an array like this one\cf0 \
spectrum = [ 0.0, 0.0, 570.0, 0.0, 600.0, 1.0, 630.0, 0.0, 1005.0, 0.0, 1040.0, 0.44668359215096315, 1075.0, 0.0, 2195.0,\
           0.0, 2250.0, 0.35481338923357547, 2305.0, 0.0, 2390.0, 0.0, 2450.0, 0.35481338923357547, 2510.0, 0.0, 2685.0,\
           0.0, 2750.0, 0.1, 2815.0, 0.0, 22050.0, 0.0 ];\
\
env = \cf2 InterplPairs\cf0 (spectrum);\
\
(size/2).do(\{ \cf2 arg\cf0  i;\
                \cf2 var\cf0  mag, df, phase;\
                df = 44100.0/size;\
                mag = env.at(i*df);\
                phase = 0.0;\
                re[i] = cos(phase)*mag;\
                im[i] = sin(phase)*mag;\
                \});\
(size/2-1).do(\{ \cf2 arg\cf0  i;\
                re[i+(size/2)] = re[(size/2)-i];\
                im[i+(size/2)] = im[(size/2)-i].neg;\
                \});\
\
\cf3 //re.plot;\cf0 \
\cf3 //im.plot;\cf0 \
re = ifft(re, im, tab);\
out = re.real;\
\cf3 //out.plot;\cf0 \
\
coeffs = \cf2 Signal\cf0 .newClear(size);\
(ksize-1).do(\{ \cf2 arg\cf0  i;\
                \cf2 var\cf0  ind, val;\
                ind = i - ((ksize-1)/2);\
                if(ind < 0, \{ ind = ind + size; \});\
                val = out[ind];\
                coeffs[i] = val * (0.5 - (0.5*cos(2pi*i/(ksize-1))));\
                \});\
coeffs.normalize;\
coeffs.plot;\
\
file = \cf2 SoundFile\cf0 .new.headerFormat_(\cf4 "AIFF"\cf0 ).sampleFormat_(\cf4 "fl32"\cf0 ).numChannels_(1);\
file.openWrite(\cf4 "~/Desktop/test.aif"\cf0 .standardizePath);\
file.writeData(coeffs);\
file.close;\
\
)\
\
\
\cf3 //simple example of use\cf0 \
\pard\pardeftab560\ql\qnatural
\cf0 b = \cf2 Buffer\cf0 .read(s,\cf4 "~/Desktop/test.aif"\cf0 .standardizePath);\
\
(\
        \{ \cf2 var\cf0  input, kernel;\
                \
        input= \cf2 WhiteNoise\cf0 .ar(0.1);\cf3 //sensitive to input amplitude\cf0 \
        \cf3 //input= Dust.ar(5.0);\cf0 \
\
        \cf3 //must have power of two framesize\cf0 \
        \cf2 Out\cf0 .ar(0,\cf2 Convolution2\cf0 .ar(input, b, 0, 8192, 0.5));\
        \}.play;\
\
)}





Don

On Apr 15, 2009, at 6:22 AM, andersvi@... wrote:

>>>>>> "e" == e deleflie <edeleflie@...> writes:
>
>    e> All, I'm just trying to work out the best way to model air
>    e> absorption. Its a relatively simple operation (modeled in the
>    e> chart on this page:
>    e> http://www.tonmeister.ca/main/textbook/node219.html)
>
> If you've got the frequency-response at a given distance you can  
> design
> coeffs for a FIR-filter of a given order.  I guess in SC3 that would
> mean using a Convolution ugen with a buffer holding the filter-coeffs
> for as many zeros you want (the higher order filter the more close to
> the frequency-response you get).
>
> Or you could multiply the spectra by some PVMul or something, but it
> would presumably distort phase.
>
> Getting the coeffs for a FIR-filter involves some tricky maths.  Maybe
> theres a method for Buffer to fill a buffer with nth-order fir-filter
> coeffs based on an Env?
>
> If not, it shouldnt be too hard.  The structure would be drawing an  
> Env
> representing the freq-envelope - getting the n y-values by passing  
> it to
> .asSignal - apply the maths to get the x-coeffs - and plugging that  
> into
> Convolution.
>
> There are algorithms for this available in other tools - clm/snd for
> instance.  Ill see if i can put something together if nobody else  
> comes
> up with anything.
>
> -anders
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/


Re: Modelling air absorption (multiple bandpass filters?)

by Dan Stowell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick Collins wrote an "LTI" ugen that can provide an arbitrary LTI
filter, so as long as you can solve for the filter coefficients, that
might be a good way to do it.

Dan



2009/4/15, Donald Craig <rhomboid@...>:

>
>  Attached is an example of how to do what Anders describes here.
>  It writes out an aiff file that be loaded into a buffer for Convolution2.
>
>  There may be a more direct way to do this. Anybody?
>
>
>
>
>
>  Don
>
>  On Apr 15, 2009, at 6:22 AM, andersvi@... wrote:
>
>
> >
> > >
> > > >
> > > > >
> > > > > >
> > > > > > > "e" == e deleflie <edeleflie@...> writes:
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> >   e> All, I'm just trying to work out the best way to model air
> >   e> absorption. Its a relatively simple operation (modeled in the
> >   e> chart on this page:
> >   e> http://www.tonmeister.ca/main/textbook/node219.html)
> >
> > If you've got the frequency-response at a given distance you can design
> > coeffs for a FIR-filter of a given order.  I guess in SC3 that would
> > mean using a Convolution ugen with a buffer holding the filter-coeffs
> > for as many zeros you want (the higher order filter the more close to
> > the frequency-response you get).
> >
> > Or you could multiply the spectra by some PVMul or something, but it
> > would presumably distort phase.
> >
> > Getting the coeffs for a FIR-filter involves some tricky maths.  Maybe
> > theres a method for Buffer to fill a buffer with nth-order fir-filter
> > coeffs based on an Env?
> >
> > If not, it shouldnt be too hard.  The structure would be drawing an Env
> > representing the freq-envelope - getting the n y-values by passing it to
> > .asSignal - apply the maths to get the x-coeffs - and plugging that into
> > Convolution.
> >
> > There are algorithms for this available in other tools - clm/snd for
> > instance.  Ill see if i can put something together if nobody else comes
> > up with anything.
> >
> > -anders
> >
> > _______________________________________________
> > sc-users mailing list
> >
> > info (subscription, etc.):
> http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
> > archive:
> http://www.listarc.bham.ac.uk/marchives/sc-users/
> > search:
> http://www.listarc.bham.ac.uk/lists/sc-users/search/
> >
>
>
>
>


--
http://www.mcld.co.uk

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by andersvi-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "D" == Dan Stowell <danstowell@...> writes:

    D> Nick Collins wrote an "LTI" ugen that can provide an arbitrary
    D> LTI filter, so as long as you can solve for the filter
    D> coefficients, that might be a good way to do it.

I think the code below returns x-coeffs for an nth-order FIR-filter
based on an arbitrary Env shape.  Its just a translation from clm's
#'envelope->coeffs.

Where is Nicks filter ugen?

(
{
        arg order = 4, envelope = Env.new([1,0],[1]), dc = 0.0;
        var
        x = Array.fill(order+1, 0),
        a = Array.fill(order+1, 0),
        n = order,
        lastX = envelope.times.sum,
        freqScl = lastX/order,
        m = ((n+1)/2).floor,
        am = (n+1)/2,
        m1 = ((n/2)+1).floor,
        q = 2pi/n,
        n2 = (n/2).floor,
        len = n2;

        m1.do({|j| put(a, j+1, envelope.at(freqScl*j))});

        if(dc == 0,
                {(1..m).do({|j|
                        var xt = a.at(1)/2;
                        (2..m).do({|i|
                                xt = xt+(a.at(i)*cos(q*(am-j)*(i-1)));
                        });
                        put(x, j, (2*xt)/n);
                })},
                {(1..m).do({|j|
                        var xt = 0.0;
                        (1..n2).do({|i|
                                xt = xt+(a.at(i)*cos(q*(am-j)*(i-0.5)));
                        });

                        if(am != m, {xt = xt+(a.at(m)*0.5*cos(pi*(am-j)))});
                        put(x, j, (2*xt)/n)
                });
                }); // end if
       
        (1..len).collect({|i| x.at(i)})
        ++
        if(odd(order),
                {((1+len)..1).collect({|i| x.at(i)})},
                {(len..1).collect({|i| x.at(i)})}
        );
}.value
)

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Parent Message unknown Re: Modelling air absorption (multiple bandpass filters?)

by e deleflie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Alberto,

> I think you should be able get a very simple first approximation with a
> OnePole,
> with coefficients starting slightly above 0; I don't have a formula at hand
> ATM.
>
> do you need that for lots of reflections, or to model single sources that
> are far away? how precise does should it be?

Currently just for a single source that is far away. Doesn't need to
be hugely precise, its not for scientific modelling, just for
composition ... I'm after the perception of distance.

a few steps down the line would be diffuse reflections ... but havn't
thought about that yet.

question is how to come up with the correct OnePoll coefficients!

Etienne

> best, a
>
>> All,
>>
>> I'm just trying to work out the best way to model air absorption. Its
>> a relatively simple operation (modeled in the chart on this page:
>> http://www.tonmeister.ca/main/textbook/node219.html)
>>
>> For a certain frequency, I need to reduce the signal by a certain db
>> amount.
>>
>> One way would be to have lots of band passes, and for each one reduce
>> the signal by a certain amount, then add them all up again.
>>
>> ... but it just feels like the kind of DSP operation that might have
>> some out-of-the-box filter that has the right logic ... can anyone
>> help?
>>
>> Etienne
>>
>> _______________________________________________
>> sc-users mailing list
>>
>> info (subscription, etc.):
>> http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
>> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
>> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>
>
> --
> --
> Alberto de Campo
> Bergstrasse 59/33
> A-8020 Graz, Austria
> e-mail : adc@...
> --
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.):
> http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by e deleflie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

thanks everyone for all the responses ... to be honest, I'm not that
'educated' when it comes to DSP techniques. So I'm a bit confused.

how do I translate a specific dB drop, for a specific bandwidth into
an envelope that can be used for convolution (or for an FIR filter)?

arghh... I'm still studying those examples ....

Etienne

On Thu, Apr 16, 2009 at 4:13 AM,  <andersvi@...> wrote:

>>>>>> "D" == Dan Stowell <danstowell@...> writes:
>
>    D> Nick Collins wrote an "LTI" ugen that can provide an arbitrary
>    D> LTI filter, so as long as you can solve for the filter
>    D> coefficients, that might be a good way to do it.
>
> I think the code below returns x-coeffs for an nth-order FIR-filter
> based on an arbitrary Env shape.  Its just a translation from clm's
> #'envelope->coeffs.
>
> Where is Nicks filter ugen?
>
> (
> {
>        arg order = 4, envelope = Env.new([1,0],[1]), dc = 0.0;
>        var
>        x = Array.fill(order+1, 0),
>        a = Array.fill(order+1, 0),
>        n = order,
>        lastX = envelope.times.sum,
>        freqScl = lastX/order,
>        m = ((n+1)/2).floor,
>        am = (n+1)/2,
>        m1 = ((n/2)+1).floor,
>        q = 2pi/n,
>        n2 = (n/2).floor,
>        len = n2;
>
>        m1.do({|j| put(a, j+1, envelope.at(freqScl*j))});
>
>        if(dc == 0,
>                {(1..m).do({|j|
>                        var xt = a.at(1)/2;
>                        (2..m).do({|i|
>                                xt = xt+(a.at(i)*cos(q*(am-j)*(i-1)));
>                        });
>                        put(x, j, (2*xt)/n);
>                })},
>                {(1..m).do({|j|
>                        var xt = 0.0;
>                        (1..n2).do({|i|
>                                xt = xt+(a.at(i)*cos(q*(am-j)*(i-0.5)));
>                        });
>
>                        if(am != m, {xt = xt+(a.at(m)*0.5*cos(pi*(am-j)))});
>                        put(x, j, (2*xt)/n)
>                });
>                }); // end if
>
>        (1..len).collect({|i| x.at(i)})
>        ++
>        if(odd(order),
>                {((1+len)..1).collect({|i| x.at(i)})},
>                {(len..1).collect({|i| x.at(i)})}
>        );
> }.value
> )
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by andersvi-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "e" == e deleflie <edeleflie@...> writes:

    e> thanks everyone for all the responses ... to be honest, I'm not
    e> that 'educated' when it comes to DSP techniques. So I'm a bit
    e> confused.

Sorry for the confusion, but its more or less simple questions like this
which triggers fixing of holes in continuing development-processes like
SC3.  (I guess answers involving adding methods and such should be moved
or cc'ed to sc-dev...)

Simple interfaces to arbitrary-order FIR-filters are extremely useful,
and are available in other good tools for DSP.  It would be nice to have
them in SC as well.

    e> how do I translate a specific dB drop, for a specific bandwidth
    e> into an envelope that can be used for convolution (or for an FIR
    e> filter)?

The 'dbamp' message can be used to convert from db to linear amplitude:

passing db-values to dbamp:

   [0,-6,-12].dbamp

gives you linear amplitudes (values to multiply soundwaves with):

   [ 1, 0.50118723362727, 0.25118864315096 ]

If you want a certain dB drop in the center of a specific frequency
range you can try BRF or BPeakEQ filter or other such things.

-a

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by Dan Stowell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/4/15  <andersvi@...>:

>>>>>> "D" == Dan Stowell <danstowell@...> writes:
>
>    D> Nick Collins wrote an "LTI" ugen that can provide an arbitrary
>    D> LTI filter, so as long as you can solve for the filter
>    D> coefficients, that might be a good way to do it.
>
> I think the code below returns x-coeffs for an nth-order FIR-filter
> based on an arbitrary Env shape.  Its just a translation from clm's
> #'envelope->coeffs.
>
> Where is Nicks filter ugen?

The LTI ugen is in the sc3-plugins pack, http://sc3-plugins.sourceforge.net/

Here's your code hooked up to it:

(
~bcoefs = {
       arg order = 4, envelope = Env.new([1,0],[1]).plot, dc = 0.0;
       var
       x = Array.fill(order+1, 0),
       a = Array.fill(order+1, 0),
       n = order,
       lastX = envelope.times.sum,
       freqScl = lastX/order,
       m = ((n+1)/2).floor,
       am = (n+1)/2,
       m1 = ((n/2)+1).floor,
       q = 2pi/n,
       n2 = (n/2).floor,
       len = n2;

       m1.do({|j| put(a, j+1, envelope.at(freqScl*j))});

       if(dc == 0,
               {(1..m).do({|j|
                       var xt = a.at(1)/2;
                       (2..m).do({|i|
                               xt = xt+(a.at(i)*cos(q*(am-j)*(i-1)));
                       });
                       put(x, j, (2*xt)/n);
               })},
               {(1..m).do({|j|
                       var xt = 0.0;
                       (1..n2).do({|i|
                               xt = xt+(a.at(i)*cos(q*(am-j)*(i-0.5)));
                       });

                       if(am != m, {xt = xt+(a.at(m)*0.5*cos(pi*(am-j)))});
                       put(x, j, (2*xt)/n)
               });
               }); // end if

       (1..len).collect({|i| x.at(i)})
       ++
       if(odd(order),
               {((1+len)..1).collect({|i| x.at(i)})},
               {(len..1).collect({|i| x.at(i)})}
       );
}.value
)

s.boot;

// Load the coefficients to the server:
a = Buffer.sendCollection(s, [0], 1);
b = Buffer.sendCollection(s, ~bcoefs, 1);

// Plot the impulse response generated by using the LTI ugen:
{LTI.ar(Impulse.ar, a, b)}.plot(0.002)



I don't get very satisfactory results, even if I use an order of 100 I
get nowhere near the Env you use as a template... I just get a kind of
sinc-curve-shaped response with symmetrical ripples. Is the code
correct, and does the clm method replicate that particular env shape
nicely?

Dan

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by curt-21 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Thu, Apr 16, 2009 at 9:51 AM, Dan Stowell <danstowell@...> wrote:
2009/4/15  <andersvi@...>:
>>>>>> "D" == Dan Stowell <danstowell@...> writes:
>
>    D> Nick Collins wrote an "LTI" ugen that can provide an arbitrary
>    D> LTI filter, so as long as you can solve for the filter
>    D> coefficients, that might be a good way to do it.
>
> I think the code below returns x-coeffs for an nth-order FIR-filter
> based on an arbitrary Env shape.  Its just a translation from clm's
> #'envelope->coeffs.
>
> Where is Nicks filter ugen?

The LTI ugen is in the sc3-plugins pack, http://sc3-plugins.sourceforge.net/

Here's your code hooked up to it:

(
~bcoefs = {
       arg order = 4, envelope = Env.new([1,0],[1]).plot, dc = 0.0;
       var
       x = Array.fill(order+1, 0),
       a = Array.fill(order+1, 0),
       n = order,
       lastX = envelope.times.sum,
       freqScl = lastX/order,
       m = ((n+1)/2).floor,
       am = (n+1)/2,
       m1 = ((n/2)+1).floor,
       q = 2pi/n,
       n2 = (n/2).floor,
       len = n2;

       m1.do({|j| put(a, j+1, envelope.at(freqScl*j))});

       if(dc == 0,
               {(1..m).do({|j|
                       var xt = a.at(1)/2;
                       (2..m).do({|i|
                               xt = xt+(a.at(i)*cos(q*(am-j)*(i-1)));
                       });
                       put(x, j, (2*xt)/n);
               })},
               {(1..m).do({|j|
                       var xt = 0.0;
                       (1..n2).do({|i|
                               xt = xt+(a.at(i)*cos(q*(am-j)*(i-0.5)));
                       });

                       if(am != m, {xt = xt+(a.at(m)*0.5*cos(pi*(am-j)))});
                       put(x, j, (2*xt)/n)
               });
               }); // end if

       (1..len).collect({|i| x.at(i)})
       ++
       if(odd(order),
               {((1+len)..1).collect({|i| x.at(i)})},
               {(len..1).collect({|i| x.at(i)})}
       );
}.value
)

s.boot;

// Load the coefficients to the server:
a = Buffer.sendCollection(s, [0], 1);
b = Buffer.sendCollection(s, ~bcoefs, 1);

// Plot the impulse response generated by using the LTI ugen:
{LTI.ar(Impulse.ar, a, b)}.plot(0.002)



I don't get very satisfactory results, even if I use an order of 100 I
get nowhere near the Env you use as a template... I just get a kind of
sinc-curve-shaped response with symmetrical ripples. Is the code
correct, and does the clm method replicate that particular env shape
nicely?

Dan

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/


Re: Modelling air absorption (multiple bandpass filters?)

by curt-21 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

you can get a freq response a bit like that with

{
var sig = WhiteNoise.ar;
OnePole.ar(sig, 0.45) - sig }.play




is THAT what LTI filter is for!! i was dreaming of something like that
btw, there is code on musicdsp to plot phase+freq responses for filter, nth order afair




Re: Modelling air absorption (multiple bandpass filters?)

by e deleflie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>    e> thanks everyone for all the responses ... to be honest, I'm not
>    e> that 'educated' when it comes to DSP techniques. So I'm a bit
>    e> confused.
>
> Sorry for the confusion, but its more or less simple questions like this
> which triggers fixing of holes in continuing development-processes like
> SC3.  (I guess answers involving adding methods and such should be moved
> or cc'ed to sc-dev...)

ah, good to know that my question can have a little bit of contribution.

> The 'dbamp' message can be used to convert from db to linear amplitude:
>
> passing db-values to dbamp:
>
>   [0,-6,-12].dbamp
>
> gives you linear amplitudes (values to multiply soundwaves with):
>
>   [ 1, 0.50118723362727, 0.25118864315096 ]

Ok, translating from dB to fractions is easy ... and I guess I can
create an interpolation of those values into an envelope. ... its the
rest where I'm lost (applying that envelope over the different
frequencies).

... well I guess that's what the discussion is about (I'm just not
following it very well)

Etienne

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by e deleflie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> you can get a freq response a bit like that with
>
> {
> var sig = WhiteNoise.ar;
> OnePole.ar(sig, 0.45) - sig }.play

yes except that air absorption will kill the high frequencies.... so
it would be just OnePole.ar(sig, 0.45)

but the complexity is in the fact that the effect changes over
distance. So that coefficient of 0.45 needs to change over time .....
question is how to calculate that.

Etienne

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by curt-21 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Fri, Apr 17, 2009 at 7:48 AM, e deleflie <edeleflie@...> wrote:
> you can get a freq response a bit like that with
>
> {
> var sig = WhiteNoise.ar;
> OnePole.ar(sig, 0.45) - sig }.play

yes except that air absorption will kill the high frequencies.... so
it would be just OnePole.ar(sig, 0.45)

but the complexity is in the fact that the effect changes over
distance. So that coefficient of 0.45 needs to change over time .....
question is how to calculate that.
 
erm so its the opposite of the graph on the page u posted and it changes over time..ok, dunno then


Re: Modelling air absorption (multiple bandpass filters?)

by e deleflie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Curt,

On Sat, Apr 18, 2009 at 9:50 AM, curt <scitotils@...> wrote:

>
>
> On Fri, Apr 17, 2009 at 7:48 AM, e deleflie <edeleflie@...> wrote:
>>
>> > you can get a freq response a bit like that with
>> >
>> > {
>> > var sig = WhiteNoise.ar;
>> > OnePole.ar(sig, 0.45) - sig }.play
>>
>> yes except that air absorption will kill the high frequencies.... so
>> it would be just OnePole.ar(sig, 0.45)
>>
>> but the complexity is in the fact that the effect changes over
>> distance. So that coefficient of 0.45 needs to change over time .....
>> question is how to calculate that.
>
>
> erm so its the opposite of the graph on the page u posted and it changes
> over time..ok, dunno then

I think you misread the graph ... the left column is Attenuation in
dB/m. Low frequencies have low attenuation dB/m.

http://www.tonmeister.ca/main/textbook/node219.html

But all I need to do is work out how the OnePole coefficients need to
move to give me kinda what I want... and I reckon it would work.

Is there any way that I can work out by how much a particular
frequency is attenuated by: OnePole.ar(sig, 0.45) ?

Etienne

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by Dan Stowell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/4/20, e deleflie <edeleflie@...>:

> Hi Curt,
>
>
>  On Sat, Apr 18, 2009 at 9:50 AM, curt <scitotils@...> wrote:
>  >
>  >
>  > On Fri, Apr 17, 2009 at 7:48 AM, e deleflie <edeleflie@...> wrote:
>  >>
>  >> > you can get a freq response a bit like that with
>  >> >
>  >> > {
>  >> > var sig = WhiteNoise.ar;
>  >> > OnePole.ar(sig, 0.45) - sig }.play
>  >>
>  >> yes except that air absorption will kill the high frequencies.... so
>  >> it would be just OnePole.ar(sig, 0.45)
>  >>
>  >> but the complexity is in the fact that the effect changes over
>  >> distance. So that coefficient of 0.45 needs to change over time .....
>  >> question is how to calculate that.
>  >
>  >
>  > erm so its the opposite of the graph on the page u posted and it changes
>  > over time..ok, dunno then
>
>
> I think you misread the graph ... the left column is Attenuation in
>  dB/m. Low frequencies have low attenuation dB/m.
>
>
>  http://www.tonmeister.ca/main/textbook/node219.html
>
>
> But all I need to do is work out how the OnePole coefficients need to
>  move to give me kinda what I want... and I reckon it would work.
>
>  Is there any way that I can work out by how much a particular
>  frequency is attenuated by: OnePole.ar(sig, 0.45) ?

If you have 3.3, you can get an overview of the frequency response:

Server.default = s = Server.internal;
s.boot;
{|sig| OnePole.ar(sig, MouseX.kr(0.45, 0.9))}.scopeResponse

Dan

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by andersvi-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "e" == e deleflie <edeleflie@...> writes:

    e> Is there any way that I can work out by how much a particular
    e> frequency is attenuated by: OnePole.ar(sig, 0.45) ?

(
{
        var sig, fr;
        fr = MouseY.kr(1, 22050, 1);
        sig = OnePole.ar(SinOsc.ar(fr,0,1.0), 0.45);
        [fr, Amplitude.kr(sig).ampdb].poll(Impulse.kr(1));
}.play(s);

)

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Modelling air absorption (multiple bandpass filters?)

by e deleflie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

great, thanks.

Etienne

On Mon, Apr 20, 2009 at 7:51 PM,  <andersvi@...> wrote:

>>>>>> "e" == e deleflie <edeleflie@...> writes:
>
>    e> Is there any way that I can work out by how much a particular
>    e> frequency is attenuated by: OnePole.ar(sig, 0.45) ?
>
> (
> {
>        var sig, fr;
>        fr = MouseY.kr(1, 22050, 1);
>        sig = OnePole.ar(SinOsc.ar(fr,0,1.0), 0.45);
>        [fr, Amplitude.kr(sig).ampdb].poll(Impulse.kr(1));
> }.play(s);
>
> )
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/