Csound Csound-dev Csound-tekno Search About

Re: [Csnd] filter design

Date2013-02-03 03:21
Frommichael.gogins@gmail.com
SubjectRe: [Csnd] filter design
AttachmentsNone  None  

Date2013-02-03 03:46
FromAdam Puckett
SubjectRe: [Csnd] filter design
Update: The Wiki articles aren't much help, sorry. Could someone
provide a concrete example using, say, Python's wave module, like
this:

import wave, struct
w = wave.open('file.wav', 'wb')
w.setframerate(44100) # sample rate
w.setsampwidth(2) # 16bit audio
w.setnchannels(2) # stereo
input, output = ([],)*2
# process audio here
packed_output = [struct.pack('h',i) for i in output]
w.writeframes(''.join(packed_output))
w.close()

For those of you who haven't used the wave module, it writes a header
and data to a WAV audio file (as you can probably guess).

On 2/2/13, michael.gogins@gmail.com  wrote:
> No, because a rich waveform has frequencies subtracted from it by filtering.
> But now that I think of it, the filter can be thought of as subtracting all
> or part of some  sinusoids from the signal.
>
> T-Mobile. America’s First Nationwide 4G Network
>
> ----- Reply message -----
> From: "Adam Puckett" 
> To: 
> Subject: [Csnd] filter design
> Date: Sat, Feb 2, 2013 4:48 pm
>
>
> Hi,
>
> Is subtractive synthesis called what it is because sine waves are
> subtracted from a signal? e.g., signal - (sin(2 * pi * t) * amp)? I've
> thought about this for a while, because I've been using Python's wave
> module to create computer music "the hard way" by "drawing" (using
> numbers and functions instead of ugens) different waveforms (sort of
> like a combo of GENs 7 and 2). The algorithms in Csound seem like
> they're optimized, but then again I haven't looked at them closely
> enough to be sure.
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>
>


Date2013-02-03 09:43
FromMartin Huenniger
SubjectRe: [Csnd] filter design
Hi Adam,

understanding and designing a filter involves complex mathematics - in the sense of complex numbers and also in the sense of complexity... ;-) Although its possible to see and implement filters as a finite impulse response system, one won't probably gain much understanding why it is done this way and what it means. Maybe a good point to start is to read about Fourier-transformation and convolution.

Maybe the most common and easiest approach to implement a filter is to use convolution of an array "buffer" (which contains your audio data) with some finite impulse response "filter" (an array of filter coefficients):

for(j = 0;j < size+size_filter;j++)
{
  output[j] = 0;
  for(i = 0;i < size_filter;i++)
  {       
    output[j] += filter[i]*buffer[j-i];
  }
}

This is just the basic implementation of the so called "convolution" operation. This is a mathematical operation that proved to be very useful to model and design filters. Check out the wikipedia link below. The Idea is that you may describe every signal processing system by what it does to each frequency that is send through the system. This is called "impulse response" because you can get this characterization by sending an impulse through the system and analyze or record what the system did to this signal. An Impulse contains all frequencies so you can measure in some way the "fingerprint" of the system in question.

If you have a finite impulse response "filter" then you can use the given algorithm to compute a signal that sounds like it has been processed by the system where the impulse response came from. A common practical use case is the "convolution reverb": You get the fingerprint of some room by recording its sound after some impulse, where the impulse is generated by clapping, finger snap or by popping a balloon etc. Then you convolve any sound with this impulse response and you get the impression of the sound being recorded in this room.

It is possible to mimic certain systems by mathematical models especially subtractive filters are an interesting example, because you don't have one at hand to get its impulse response. and if you want to modulate the filter you need impulse responses for each and every change of the modulating parameters. Unfortunately, it is relatively complicated to understand how to design such a model and how and why you choose the coefficients of the filters. Maybe the wikipedia article on the low-pass filters may give some insight, And, of course, some good book on signal processing ;-)

http://en.wikipedia.org/wiki/Finite_impulse_response
http://en.wikipedia.org/wiki/Convolution
http://en.wikipedia.org/wiki/Discrete_Fourier_transform
http://en.wikipedia.org/wiki/Low-pass_filter

Best,
Martin

Am 03.02.2013 um 04:46 schrieb Adam Puckett:

> Update: The Wiki articles aren't much help, sorry. Could someone
> provide a concrete example using, say, Python's wave module, like
> this:
> 
> import wave, struct
> w = wave.open('file.wav', 'wb')
> w.setframerate(44100) # sample rate
> w.setsampwidth(2) # 16bit audio
> w.setnchannels(2) # stereo
> input, output = ([],)*2
> # process audio here
> packed_output = [struct.pack('h',i) for i in output]
> w.writeframes(''.join(packed_output))
> w.close()
> 
> For those of you who haven't used the wave module, it writes a header
> and data to a WAV audio file (as you can probably guess).
> 
> On 2/2/13, michael.gogins@gmail.com  wrote:
>> No, because a rich waveform has frequencies subtracted from it by filtering.
>> But now that I think of it, the filter can be thought of as subtracting all
>> or part of some  sinusoids from the signal.
>> 
>> T-Mobile. America’s First Nationwide 4G Network
>> 
>> ----- Reply message -----
>> From: "Adam Puckett" 
>> To: 
>> Subject: [Csnd] filter design
>> Date: Sat, Feb 2, 2013 4:48 pm
>> 
>> 
>> Hi,
>> 
>> Is subtractive synthesis called what it is because sine waves are
>> subtracted from a signal? e.g., signal - (sin(2 * pi * t) * amp)? I've
>> thought about this for a while, because I've been using Python's wave
>> module to create computer music "the hard way" by "drawing" (using
>> numbers and functions instead of ugens) different waveforms (sort of
>> like a combo of GENs 7 and 2). The algorithms in Csound seem like
>> they're optimized, but then again I haven't looked at them closely
>> enough to be sure.
>> 
>> 
>> Send bugs reports to the Sourceforge bug tracker
>>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>> csound"
>> 
>> 
>> Send bugs reports to the Sourceforge bug tracker
>>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>> csound"
>> 
>> 
> 
> 
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
> 

_________________________
Martin Hünniger
a_s_tarantoga@yahoo.de
a-s-tarantoga.tumblr.com
soundcloud.com/a_s_tarantoga