I made a noise canceller filter (get it here)

Discussion in 'Effects and the DSP' started by Tril, Mar 5, 2005.

  1. Tril

    Tril Triple screen racing ftw

    Joined:
    Sep 26, 2004
    Messages:
    1,665
    Likes Received:
    19
    Trophy Points:
    48
    I made a noise canceller. It has two inputs and two outputs. The inputs are called called Primary and Reference. The out puts are called OutCorr and OutUncorr. Corr and Uncorr stands for correlated and uncorrelated.

    This filter uses the LMS algorithm to adapt dynamically the FIR filter coefficients. The FIR filter has 44 taps.

    You input is noise and desired signal to Primary.
    You input noise only to Reference.

    It is best at removing periodic noise. It works best the if the noise in the primary and in the reference are recorded at the same time. It is especially true if the noise isn't much periodic. If the noise is highly periodic, it can be sent delayed to reference and of different amplitude and it will still be removed effectively.

    Example : You record someone talking beside an engine idling. It is the Primary. You record the engine idling. It is the reference. Both were recorded at different times but the noise will still be effectively removed because it is periodic.

    If you recorded someone speaking in the wind and the wind at different times, the wind would not be removed because it is random.

    There are two outputs.
    Correlated output is what you input to Primary minus the noise.
    Uncorrelated output is what was substracted from Primary.

    You can get it here : http://pages.globetrotter.net/samaust/Files/noisecanceller44taps.zip

    Get it and experiment. I am waiting for your feedback. :lol:


    After this plugin, If I have time, I think I'll get to work on the bass booster here : http://www.driverheaven.net/showthread.php?t=66173

    It looks interesting.
     
  2. townkat

    townkat New Member

    Joined:
    Sep 25, 2003
    Messages:
    123
    Likes Received:
    0
    Trophy Points:
    0
    great...i belive its the first noise-cancelation plugin available...i didnt test it already but the ideea is really great. cya
     
  3. BODYPRINT

    BODYPRINT New Member

    Joined:
    Dec 29, 2003
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    0
  4. Tril

    Tril Triple screen racing ftw

    Joined:
    Sep 26, 2004
    Messages:
    1,665
    Likes Received:
    19
    Trophy Points:
    48
    In fact, I started working on this plugin because of your post about making a feedback suppression DSP. I was looking for a way to automatically detect feedback and cancel it. I thought I could maybe use a system of noise cancellation. I finally succeeded in making a noise canceller but it cannot cancel feedback (as far as I know).


    The filter coefficients are dynamically adapted to try to reduce the power of the OutCorr signal. The coefficients adjust themselves automatically. It takes many cycles for the coefficients to stabilize. Once it's done, the filtering is good. If the Reference signal change, the coefficients also change to readapt.

    I thought it might be possible to use the filter to cancel feedback. I tried to delay OutCorr and input that to Reference. That way, you would cancel the periodic part of the signal. It would not cancel much what changed in the signal (the music you play). It does not work, at least for now. I think feedback varies in amplitude and frequency. If it varied only in amplitude and slower, the noise canceller could cancel it.


    If you have any useful links to noise and feedback canceling theory, direct me to it. The plugin could maybe be improved further.
     
    Last edited: Mar 5, 2005
  5. ROBSCIX

    ROBSCIX New Member

    Joined:
    Mar 28, 2004
    Messages:
    1,732
    Likes Received:
    4
    Trophy Points:
    0
    The Bass booster plugin would be great and would be very useful for people with lower end computer speakers..the harmocin modelling using the missing fundememntal priciple is a pretty neat effect, and it is clearly audible..but there is no vibrations, so after ahwile you just want a sub...kinda teases you..lol..I wanted to do it but I am a little busy right now...there is a formula for the function floating around out there that produces the harmonics...good luck, I was talking with Tiger about producing the plugin, but he's busy to...I think it would be a great addition to KX...if done properly.
     
  6. eyagos

    eyagos New Member

    Joined:
    Dec 11, 2002
    Messages:
    259
    Likes Received:
    0
    Trophy Points:
    0
    It works grate.

    About feedback, I made feedback destroyer using a second order IIR notch filter. There are tons of papers in Internet about this topic, some of them very complicated. The idea is that IIR filters do its job better, but has problems of stability and convergence. So a lot of alternative (and more complicated) to LMS algorithms has appeared...

    Here you have a short paper that I used to make a feedback destroyer:

    http://www.aut.ac.nz/research_showc...as/kedri/downloads/pdf/iliev-kas_iconip99.pdf
     
  7. Tril

    Tril Triple screen racing ftw

    Joined:
    Sep 26, 2004
    Messages:
    1,665
    Likes Received:
    19
    Trophy Points:
    48
    I've updated the plugin. I've changed :

    static Mu

    to

    control Mu

    Mu controls the convergence speed. If Mu is high, the plugin adapts faster if the noise source change but at the same time it can cause the adaptation to diverge. If it diverges, the noise will get louder in the filtered signal. You can often set Mu to 100% without problems but sometimes you'll have to set it lower.

    The plugin adapts continuously the coefficients to filter the noise. I would like to know at all times what is the shape of the impulse response of the adaptive filter. To know that, I would need the plugin to read the values of the coefficients stored in static variables and output those values.

    The oscilloscope plugin can make a graph of the signal inputed to it. That means that it is possible to output the value of a variable (the signal) grahically. I would like to output the 44 coefficients as numbers from -1 to 1. So I would convert the hexadecimal numbers to decimal before outputing graphically. I would also like to output those values from -2147483647 to 2147483647 (or -1 to 1, it's the same, it's only the axis values that would change) on a grahic. It would be a little like the oscilloscope plugin except that you would output 44 point on the graphic at every x sample number (or x time) and the curve would not move to the left because of time.

    I've never coded in C++ for kX so I would like some help to get me started on this. I'll look into the SDK to learn but I'll appreciate any help other forum members could give me. Tiger M would probably be able to help get me started and give me some advice on how to proceed since he made the oscilloscope.

    Once It's done, I would like to make an improved version of the noise canceller where the signal goes through to filters. The first one is the same as in the current and the other is a delay. With checkbox unchecked, the plugin would work the same as right now and the delay would be set to zero. With it checked, it would freeze the impulse and adapt the delay to minimize the noise. This new option could be used when you would like the plugin to filter periodic noise made for example by a fan bearings without filtering other noises around. You would input only the bearings noise to reference with the checkbox unchecked. The plugin would adapt to the noise and cancel it well. You would then check the checkbox and the impulse response (the values of the coefficients) would freeze and the automatic adaptation of the delay would then be activated to minimize the noise. In theory it should work. In practice, tests would be needed to know if it works well.

    Tril
     
    Last edited: Mar 7, 2005
  8. Chester01

    Chester01 New Member

    Joined:
    Jan 12, 2004
    Messages:
    492
    Likes Received:
    0
    Trophy Points:
    0
    Good luck working on the bass booster plugin; if you need any help, i will do what I can to assist you. I noticed that I cannot run two noise canclers at once (if I wanted to cancel stereo noise) one "clicks off" and stops outputing (testable by hooking into the removed noise from both plugins, one removes noise, one wont.) I dont know if this is a bug or not. Good work so far!
     
  9. Tril

    Tril Triple screen racing ftw

    Joined:
    Sep 26, 2004
    Messages:
    1,665
    Likes Received:
    19
    Trophy Points:
    48
    I don't know why it does not work with two at the same time for you. I just tested it and it worked with two at the same time. What plugins did you have loaded when you tried? Do you have other plugins loaded that use itram? When you code a plugin that uses itram you must not forget to use : itramsize xx. Where xx is the number of reserved itram for the plugin. Currently, the plugin uses 47 itram so with two plugins you need 94 itram.

    My plugin uses 0 to 68 so I use :
    itramsize 68

    You may be using a plugin where the writer forgot to set it correctly. It's probably unlikely but I've done it myself a few times.


    I'll try to improve the plugin and I'll play with it when I have time. I'd like to see if it's possible to quiet down my pc noise with a well placed speaker and a well placed mic. It won't probably work too well but I want to experiment. The chances are high that It would add even more noise instead of removing it but it would be nice if it worked.
     
    Last edited: Mar 8, 2005
  10. Chester01

    Chester01 New Member

    Joined:
    Jan 12, 2004
    Messages:
    492
    Likes Received:
    0
    Trophy Points:
    0
    did you try conecting the uncorr output to speakers or headphones? on the first plugin loaded (for me) it does not have any output. I have an audigy 2 zs.

    EDIT: I have plenty of Itram and other resources so I do not believe this is the issue.
     
  11. Tiger M

    Tiger M kX user

    Joined:
    Apr 14, 2004
    Messages:
    851
    Likes Received:
    0
    Trophy Points:
    0
    This is strange...
    It might be an issue with multiple use of an 'in' register. Tril, are you using an input reg more than once in the code?
     
  12. Tril

    Tril Triple screen racing ftw

    Joined:
    Sep 26, 2004
    Messages:
    1,665
    Likes Received:
    19
    Trophy Points:
    48
    No. I use the two input only once to put them in the itram. Feel free to browse through the code to see if there are any mistakes.



    I think I made a mistake in the code because I did not understand correctly when I wrote it. I used :

    macwn Error, PrimarydelayedRead, FilterOutput, 1;

    It should be :

    macsn Error, PrimarydelayedRead, FilterOutput, 1;

    When calculating the coefficients, the filter uses the sign of error to choose wich way to go to cancel the noise. As long as error did not overflow the mistake changed nothing. If it overflew, it caused the filter to try to adapt in the wrong direction.
     
  13. stuthemong

    stuthemong New Member

    Joined:
    Feb 16, 2004
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Right. This is very interesting :D

    A year ago i installed a PC in my car to try to create an ANC system for a 4th year engineering project. I did a lot of work, but no actual cancellation in car

    Basically, to summarise my results;

    You need to use a FX-NLMS system

    you ideally want 512 filter taps.

    Can this many taps be implimented on the audigy ZS, when do we hit hardware limits?

    I have a electronic copy of my report that details some simluations, and reasoning behing FXLMS choice - if you are interested, I'd be delighted to email you my report, it should make relitively simple reading on this subject. The report is 3.5megs however.

    I managed to open the .da file with notepad, does a .da just import striaght into KX DSP (i cant test, as I am not on my car PC) - unfortunately I dont understand this machine code :(

    Please do get back to me on this, it sounds very interesting.

    Stu
     
    Last edited: Apr 19, 2005
  14. Tril

    Tril Triple screen racing ftw

    Joined:
    Sep 26, 2004
    Messages:
    1,665
    Likes Received:
    19
    Trophy Points:
    48
    Thank you for your offer.

    I find that subject very interesting.

    What limits you the most is the memory. After that, it's the number of instructions. On a card using the emu10k2 like the audigy 2, I'd say the limit on the number of coefficients is around 200, maybe 250 max (in an adaptive filter at least). The adaptive filter needs a lot of instructions (instr to filter the signal and instr to adapt the filter). I'm interested in finding adaptive filters methods that don't need a lot of coefficients to be able to implement them on my soudblaster soundcard.

    I wanted to test the filter I made with a larger number of coefficients so I decided to make a VST filter. It does not use the soundcard hardware but the computer processor and system memory. With a VST plugin I'm not limited in term of memory but I'm limited on CPU power. I haven't had a lot of time to put on that recently. My VST plugin does not work yet. It's a little more complicated than programming filters for kX. I programmed a ringbuffer (can also be called a circular buffer) in the VST plugin and it is possible that there is a pointer error somewhere.

    I'll have a signal processing class next semester. That will be interesting.
     
    Last edited: Apr 19, 2005
  15. stuthemong

    stuthemong New Member

    Joined:
    Feb 16, 2004
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Tril,


    Awesome stuff. 200 odd taps should get to an interesting stage.

    Ill breifly outline some differences in noise cancellation algorithms from memory.

    LMS - the first, but very brittle, as you have found, the value of Mu is important

    NLMS - normalised LMS, this is very siilar, but automatically updates the Mu parameter, making it large when you are far from a close solution, and low when you are near it. This dynamically updates (it can go both ways if teh system changes), and means you can get fast tracking (high Mu), and high accuracy (low Mu) in the same alogirtm. A *great* improvement over simple LMS, and very simialr.

    FXNLMS (we always use NLMS, never LMS anymore really) is called Filtered normalised LMS. Effectively the filtered part relates to the fact that the model now contains an approximation of the physical system.

    In a ANC system you have to think about what is happening. The DSP does the maths, this is output via buffers to the analog output on S/C (with ASIO, this is a 2.3ms delay), the amplifier is instant, but speakers have a time delay between getting a signal, and outputting a note, a few ms, hten the sound has to travel to your detecting mircrophone. This delay casues havoc with the LMS system, they are not able to deal with delays.

    The FXLMS system inserts an estimate (which is found by a nice little side LMS optimisation, outlined in my report) between the output of the NLMS system, and the responding signal reaching the detector. This makes the system far more robust, and means that effective noise cancellation of harmonics is possilble.

    Ill send you my report when i get back tonight, it should make things a bit clearer.

    In my instance, in car, I can expect significant reductions - 10 Db of engine noise if i can get the system working. Id love to!!!

    Yours

    Stu
     
  16. Tril

    Tril Triple screen racing ftw

    Joined:
    Sep 26, 2004
    Messages:
    1,665
    Likes Received:
    19
    Trophy Points:
    48
    The program as it is now won't work in your car. It uses
    Error = PrimarydelayedRead - FilterOutput
    The error is internal. Basically you add the Primary signal and an inverted filtered Reference signal in the sound card.

    To get it to work in a noise cancellation system, you need to output the inversed Reference signal through speakers.
    You also need to get the error with an error microphone.

    I've done another plugin that does that but it's not posted.

    I did not post it because it does not work very well. I thought that maybe the filter was not long enough to cope with the added delays.

    I said around 200 but it could be more. The maximum memory (you can't because you also need ressources for other plugins) would be 512(GPRS) + 192(iTram) = 704.

    In a FIR filter such as here you need one memory space by coefficient.
    You also need one memory space for each past sample.
    You are now at 704/2 = 352 coefficients.

    But you need some more variables in the noise cancellation plugin and in others plugins used. By having only the noise cancellation loaded plus the minimal number of other plugins loaded I suppose you could reach close to 330 coefficients. That's a guess because I haven't tried and I don't know exactly how much memory is needed without testing.

    I have a soundblaster live! (emu10k1) so I have half that many ressources. The higher number of coefficients I tried was around 100.
     
  17. stuthemong

    stuthemong New Member

    Joined:
    Feb 16, 2004
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    tril,

    understood, though I'm that together we can get something useful out, as you have done most the hard work ;)

    The plan for a decent ANC system is to get some sort of harmonic that is correlated to the noise signal. E.g. in my car I can put a microphone in the engine bay, or even something like an acceleromiter, or even something that logs spark plug firings.

    I then put a seperate microphone by my ear in the car, and it is that signal that the ANC system forces to zero.

    This is the masterplan anyway :D

    http://people.pwf.cam.ac.uk/sbm24/activenoise.doc

    Is a link to my project, please let me know when you have d/led it, and ill remove it. The interesting parts are right at the end where i talk about the ANC.

    Stu
     
  18. Tril

    Tril Triple screen racing ftw

    Joined:
    Sep 26, 2004
    Messages:
    1,665
    Likes Received:
    19
    Trophy Points:
    48
    Downloaded. Thank you for sharing your work. It's appreciated. I've tried before to find some info on the subject but I came empty handed on useful info to implement a system.

    I won't be able to work on the plugin for the next two weeks. It's the last two weeks of the semester and I'm overloaded with work. I'll find some time to read your report and think about the system.

    Tril
     
  19. stuthemong

    stuthemong New Member

    Joined:
    Feb 16, 2004
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    its not a problem.

    I have since read a sticky on DSP programming. My understanding is this .da file can be loaded into KX and that compiles to a .kx file via dane - is this correct?

    I must confess to feeling itchy - bin your work, lets work on this, FAR more fun ;)

    I will have a look at your code, and ask questions on it - perhaps if you can help me understand the code, i can help write it - the only probelm i have is the audigy is in car - so i may well buy another for my home pc :rolleyes: - can i just confirm one thing - does this workin 3587 (IIRC what i am running), or the newest beta version - waht differences are there that changes what you write in compiler?


    All the best,

    Stu

    I will leave the report up for a couple of weeks actually incase anyone else is interested
     
  20. Tril

    Tril Triple screen racing ftw

    Joined:
    Sep 26, 2004
    Messages:
    1,665
    Likes Received:
    19
    Trophy Points:
    48
    da code works on all versions of kX driver. It's simply a .txt file renamed to .da.

    Plugins using .kxl are .dll renamed to .kxl. They are made using C++.

    The advantage of C++ is that you can directly write to the memory of the sound card. You can also read. You can also add a better interface, combo boxes and checkmarks. It is useful to reduce your program code length. You can remove code that changes parameters by the user from the dane code and use c++ instead to change it thus using less instructions and less memory.

    The noise canceller filter was written in .da so it is compatible to all versions. You can use the dane editor or any text writer software like notepad to write .da plugins.

    Writing dane plugins is easy. The hardest part is finding the algorithm (or equations) you need.

    If you have any questions feel free to ask.
     

Share This Page

visited