Butterworth Filter Implementation
| Date | 2016-07-09 06:47 |
| From | Emmett Palaima |
| Subject | Butterworth Filter Implementation |
Hi, I was doing some research on filter programming and was trying to implement a butterworth lowpass filter in Csound based on the instructions given on page 484 of the Audio Programming Book in order to better understand the concept. I am running into some trouble in my implementation.
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
The feedback lines, which I have tried to implement in 2 different ways have given negative results. When I used the delay1 opcode it creates extreme uncontrolled feedback which almost blew up my speakers, and when I use afeedback2 = afeedback 1, afeedback1 = aout, it creates a lot of resonance. I tried leaving out the feedback, and it seems that changing the cutoff no longer has anything to do with frequency, but instead changes output level. I double checked the formula, so perhaps it is something with my implementation in Csound? Is there a problem with my method of setting aout via an equation like I do? Here is the instrument: instr 3 icutoff = 5000 ilambda = 1 / (tan(3.14159 * icutoff / sr)) icoef = 1 / (1 + (2 * ilambda) + ilambda^2) ifb1coef = 2 * icoef * (1 - (ilambda^2)) ifb2coef = icoef * (1 + (-2 * ilambda) + (ilambda^2)) aout init 0 afeedback1 init 0 afeedback2 init 0 ain, ain2 diskin "purple.wav", 1 adelay1 delay1 ain adelay2 delay1 adelay1 ;afeedback1 delay1 aout ;afeedback2 delay1 afeedback1 aout = (ain * icoef) + (2 * icoef * adelay1) + (icoef * adelay2) - (ifb1coef * afeedback1) - (ifb2coef * afeedback2) afeedback2 = afeedback1 afeedback1 = aout outs aout, aout endin |
| Date | 2016-07-09 09:35 |
| From | Victor Lazzarini |
| Subject | Re: Butterworth Filter Implementation |
did you set ksmps=1? Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland
|
| Date | 2016-07-09 19:43 |
| From | Emmett Palaima |
| Subject | Re: Butterworth Filter Implementation |
No, I had not. That fixed the problem. Is it the case that = statements will run at krate in Csound? Very good to know. I also fixed the delay problem by switching the order of the delay1 opcodes, the way I had it set up before they were both being set to aout. I also think the way it things were ordered in that method delayed the output by an extra sample anyway, leading to a steeper cutoff and a duller sound. If I use afeedback2 delay1 aout aout = (ain * icoef) + (2 * icoef * adelay1) + (icoef * adelay2) - (ifb1coef * aout) - (ifb2coef * afeedback2) it fixes the cutoff. Thanks for your help! On Sat, Jul 9, 2016 at 3:35 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
|
| Date | 2016-07-09 20:25 |
| From | Victor Lazzarini |
| Subject | Re: Butterworth Filter Implementation |
yes, if you want a 1-sample feedback delay you need to run at ksmps=1. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland
|