electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
Simple resonant low pass filter
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
synaesthesia



Joined: May 27, 2014
Posts: 275
Location: Germany
Audio files: 85

PostPosted: Sat Mar 11, 2017 10:12 am    Post subject: Simple resonant low pass filter
Subject description: using only 16-bit integer arithmetic
Reply with quote  Mark this post and the followings unread

Does anybody know a good resonant low-pass filter using only 16-bit integer arithmetic? The code below is what I currently use.
It sounds quite good already, but it needs a bit of taming (the division by 3) because it otherwise easily overflows during 16-bit calculations.
Code:

// in the main loop
// get unsigned values for fcut and qfilter in range 25..250
feedback = qfilter + ((qfilter*128)/(256-fcut));

// in the interrupt, use input value in range 0..255
int sample = (input-128)/3; // shift to -128..127 and scale by /3
// buf0 and buf1 are static integers
buf0 = buf0 + (fcut*((sample-buf0) + (feedback*(buf0-buf1)/256))/256);
buf1 = buf1 + (fcut*(buf0-buf1)/256);
int output = (buf1+128)&255; // shift signed result back into range 0..255
 

Instead of the division by 256, a shift right by 8 bits can be used of course, but it must be an arithmetic shift to preserve the sign bit.
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1691
Location: West Red Spot, Jupiter
Audio files: 194

PostPosted: Sat Mar 11, 2017 3:00 pm    Post subject: Reply with quote  Mark this post and the followings unread

What CPU?

Take a look at dspic33FJ128GP802. It's a 16 bit CPU that runs as fast as 40 MIPS. That particular part number is for the 28 pin DIP package, so it's quite DIY friendly. I've written a state variable filter for it in assembly language and it works wonderfully well. The filter I wrote also uses the full 16 bits of range for data which is -32768 to +32767. Using Q values higher than 1.0 requires some attenuation of the input signal. There is information about this filter here: http://www.earlevel.com/main/2003/03/02/the-digital-state-variable-filter/

_________________
FPGA, dsPIC and Fatman Synth Stuff

Time flies like a banana.
Fruit flies when you're having fun.
BTW, Do these genes make my ass look fat?
corruptio optimi pessima
Back to top
View user's profile Send private message Visit poster's website
synaesthesia



Joined: May 27, 2014
Posts: 275
Location: Germany
Audio files: 85

PostPosted: Tue Mar 21, 2017 11:28 am    Post subject: Reply with quote  Mark this post and the followings unread

I am using a PIC24FJ64GA002 right now, but I am looking for generic code that can run on any controller without foating point support.
By the way, I had to change the scaling to /4 because even with an input scaled by /3 the filter sometimes overflows the internal values, for example when an envelope with a very steep attack phase is used.
Back to top
View user's profile Send private message
VA1



Joined: Aug 20, 2018
Posts: 59
Location: Nederland

PostPosted: Wed Aug 29, 2018 3:02 am    Post subject: Reply with quote  Mark this post and the followings unread

You mean with resonance the overflow occurs.
I heard a FIR filter will stay in limit, IIR is problems.
FIR has more delay and more CPU.
i dont know how FIR behaves with resonance ?
this is always a big problem, some filters has it covered somehow, still finding out how.
i am no filter expert.

You should adjust levels per project, lower the max reso and so on to get some results.
My filter adjust levels per waveform, i have the same problem.
Maybe you can try http://www.microchip.com/forums/m1003759.aspx
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1691
Location: West Red Spot, Jupiter
Audio files: 194

PostPosted: Wed Aug 29, 2018 8:39 am    Post subject: Reply with quote  Mark this post and the followings unread

IIR filters like the SVF have a property called "Q enhancement". This means that as the Q is raised, the amplitude of the signal at Fc also increases. The gain of the system at Fc becomes greater than 1.0 as Q is increased. This can easily cause overflow. Attenuation is the only way to handle this. You may be able to handle this automatically with a table that relates Q values back to an attentuation value. This can be tricky to handle with fixed point (integer based) arithmetic and still maintain a signal that is close to saturation.
_________________
FPGA, dsPIC and Fatman Synth Stuff

Time flies like a banana.
Fruit flies when you're having fun.
BTW, Do these genes make my ass look fat?
corruptio optimi pessima
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
Jump to:  

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
You cannot attach files in this forum
You can download files in this forum
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use