electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
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 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
poster
 Forum index » DIY Hardware and Software » ChucK programming language
Noise Reduction
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [19 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Thu Jul 09, 2009 9:07 am    Post subject: Noise Reduction
Subject description: by averaging an FFT
Reply with quote  Mark this post and the followings unread

I created an interesting noise reducer for my ChucK Show microphone/guitar controller program. It works by taking the FFT of the input signal, averaging each harmonic individually, and then taking the IFFT of that averaged spectrum. It works pretty well as you can hear in the attached sample. I'm sure it's not a new technique, but anyway I like it.

Les


NoiseReductoin.mp3
 Description:
example of noise reduction

Download
 Filename:  NoiseReductoin.mp3
 Filesize:  293.06 KB
 Downloaded:  1357 Time(s)


_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
TGV



Joined: Jul 03, 2009
Posts: 23
Location: Utrecht, The Netherlands

PostPosted: Fri Jul 10, 2009 12:14 am    Post subject: Reply with quote  Mark this post and the followings unread

What do you mean by "averaging each harmonic individually"? An FFT gives the (complex) amplitude for single frequencies in a period of time. How do you average them? Across multiple time frames?
Back to top
View user's profile Send private message
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Fri Jul 10, 2009 1:43 am    Post subject: Reply with quote  Mark this post and the followings unread

Like this:

Code:
//
// vocal noise remover
fun void remove_noise () {
    1024 => fft.size;
    Windowing.hann(fft.size()) => fft.window;
    complex s[fft.size()/2];
    complex avg[fft.size()/2];
    float alpha;
    while (true) {
        if (button_mute.state()) {
            fft.upchuck();
            fft.spectrum(s);
            slider_alpha.value() => alpha;
            for (int i; i<(fft.size()/2); i++) {
                alpha * avg[i] + (1-alpha) * s[i] => avg[i];
            }
            ifft.transform(avg);
            (fft.size()/2)::samp => now;
        } else {
            100::ms => now;
        }
    }
}
spork ~ remove_noise();


I have found that an alpha value of 0.5 works fairly well. Lower and you get more noise, higher and you get more artifacts. I'm told that this method is used in an audio file editing program, I forget which one. Try it, it works!

Les

_________________
"Let's make noise for peace." - Kijjaz

Last edited by Inventor on Fri Jul 10, 2009 5:21 am; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Jul 10, 2009 5:00 am    Post subject: Reply with quote  Mark this post and the followings unread

I don't get that code at all. Did you make sure to uncheck html?
I have serious doubts about that "for" loop, for a start....

What are you averaging? Averaging in time? In frequency?

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Fri Jul 10, 2009 5:25 am    Post subject: Reply with quote  Mark this post and the followings unread

Kassen wrote:
I don't get that code at all. Did you make sure to uncheck html?
I have serious doubts about that "for" loop, for a start....

What are you averaging? Averaging in time? In frequency?


Yes, I forgot to disable HTML - I fixed it. The less than sign in a for loop looks like HTML to the forum software, as I'm sure you've noticed. I am averaging in time. It's just a low-pass filter done with complex vector addition. You take a fraction of the running average, add in one minus that fraction of the new sample, and then add them and put them into the running average. This is done for each bin of the FFT. I seem to recall that you previously mentioned familiarity with this type of averaging, Kassen, you told me it's a low-pass filter before IIRC.

Les

_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
TGV



Joined: Jul 03, 2009
Posts: 23
Location: Utrecht, The Netherlands

PostPosted: Fri Jul 10, 2009 6:54 am    Post subject: Reply with quote  Mark this post and the followings unread

That's no low-pass filter, at least not a normal one (in the time domain). I think that if you feed it a pure sine wave of any frequency, it will come out identical (in the long run, not in the first iterations of the process, let's say the first second or so). This thing is a low-pass filter for changes in the amplitude of each frequency band.

Say you have a sine wave at 440Hz plus some noise, then the spectrum will show an almost constant amplitude at 440Hz but a varying one at all other frequencies (in particular the higher ones), e.g. 0.01, -0.004, 0.007, -0.009, etc. Then these values get low-pass filtered, so you end up with your original sine wave, but less noise.

Doesn't work for all signals, though. This thing needs several iterations of constant amplitudes to adapt, so if you feed it drums, it will take soften the attack.

If I understand it properly, that is Very Happy
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Sat Jul 11, 2009 5:19 am    Post subject: Reply with quote  Mark this post and the followings unread

I think you are right, TGV, it's a bit like a filter on the analysis signal. We could even have higher order fiters on that, even highpass filters that would only let through the difference in signal, that might give some very unusual effects, I should experiment with it.
_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24075
Location: The Netherlands, Enschede
Audio files: 277
G2 patch files: 320

PostPosted: Sat Jul 11, 2009 5:31 am    Post subject: Reply with quote  Mark this post and the followings unread

Les used this filter on his ChucK show yesterday, or at least that's what I understood. A recording of the show is to be found here, so you can listen to what it does (and for comparison, shows before that don't have the filter).
_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 18195
Location: Durham, NC
Audio files: 211
G2 patch files: 60

PostPosted: Sat Jul 11, 2009 8:39 am    Post subject: Reply with quote  Mark this post and the followings unread

TGV wrote:
That's no low-pass filter, at least not a normal one (in the time domain). I think that if you feed it a pure sine wave of any frequency, it will come out identical (in the long run, not in the first iterations of the process, let's say the first second or so). This thing is a low-pass filter for changes in the amplitude of each frequency band.


Yes, averaging a series of numbers is a low pass filter. I think that's what Inventor said. He didn't say this was a low pass in the time domain, he said it is an adaptive noise reducer, which it is. Quite a good idea, IMHO.

_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 18195
Location: Durham, NC
Audio files: 211
G2 patch files: 60

PostPosted: Sat Jul 11, 2009 9:03 am    Post subject: Reply with quote  Mark this post and the followings unread

I listened to the noise reduced ChucK Show. Great show, Les. Anyway, the noise reducer really removes a lot of noise and the voices sound much better than on previous shows.

Still, there is some whine caused I think from some power main harmonics. Your adaptive filter won't get rid of those constant signals because they are seen as valid inputs signals.

You could get rid of the whine with a fixed equalizer, but an adaptive one would be more fun and useful. What happens if you differentiate the frequency domain coefficients as well?

_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Sat Jul 11, 2009 12:07 pm    Post subject: Reply with quote  Mark this post and the followings unread

What Howard says is even more true than might be apparent. That's because two weeks ago I switched microphones from the Emac's mic which is good for a computer mic to a homemade mic / guitar amp in a little black box, and boy is that mic noisy! All the noise was disguised somewhat last week by the hippy trippy vocoder, so last night's show was really the first clean-channel broadcast with the new mic and the noise reducer.

What I mean to say by this is that not only is the new setup quieter, it's also working with an even noisier input than we've had in the past. So yes to what Howard says, only even more so.

The whine is there at an averaging constant of 0.5, and gets noticeably louder at higher values. The mic is running off of a 9V battery, so I wonder if the whine is actually from the eMac's cooling fan which is near the mic physically, or if it is actually some kind of mathematical artifact. I just don't know really.

Truth be told, I invent or reinvent things like this all the time but I often lack the theoretical knowledge to fully understand how things work. I guess that's why I was speaking kind of analogously when I called it a low pass filter. To be precise it's a low pass filter applied in the frequency domain, which is a rather strange thing to do - but hey it works! Smile

Anyway thanks for the comments all, I appreciate the observations. This kind of stuff is part of what makes my music hobby so much fun!

Cheers,

Les

_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Sat Jul 11, 2009 12:55 pm    Post subject: Reply with quote  Mark this post and the followings unread

Here, attached is a complete self-contained noise reducer test program for anyoone who wishes to experiment with this technique. It adds noise to the microphone input and then alternates every five seconds between "adc + noise => dac" and "adc + noise => NR => dac". The difference is quite noticeable.

There are three parameters at the top of the file that you can adjust to test things out, and you can increase the order of the "filter" by duplicating the filter averaging line inside the for loop.

Enjoy!

Les


NoiseReducer1.ck
 Description:
Noise Reducer Test Program

Download
 Filename:  NoiseReducer1.ck
 Filesize:  1.1 KB
 Downloaded:  553 Time(s)


_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Sat Jul 11, 2009 4:54 pm    Post subject: Reply with quote  Mark this post and the followings unread

I'm now thinking about the differentiation comments that Kassen and mosc made. If there is some whine that is constant, like power supply harmonics, then a differentiator should remove them because they are not changing in time. So it might be good to do both - first reduce the noise with averaging, then reduce the constant terms with some sort of differentiation. I wonder if simply subtracting the new samples would do this?
_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
TGV



Joined: Jul 03, 2009
Posts: 23
Location: Utrecht, The Netherlands

PostPosted: Sun Jul 12, 2009 12:39 am    Post subject: Reply with quote  Mark this post and the followings unread

You could use the same technique other noise cancellers use: finger printing. Take a piece of audio without meaningful signal, and subtract its spectrum from your recording. It's not quite as simple as I describe (you need the two signals to be in phase), but that will take care of some noise and the whine, hum, etc. Here is a description how CEDAR's (rather expensive) software does it: http://www.cedaraudio.com/intro/dehiss_intro.html
Back to top
View user's profile Send private message
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Sun Jul 12, 2009 12:57 am    Post subject: Reply with quote  Mark this post and the followings unread

Kewl, neat idea TGV. I may give that a try. Thanks for the suggestion.

Les

_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 18195
Location: Durham, NC
Audio files: 211
G2 patch files: 60

PostPosted: Mon Jul 13, 2009 9:28 pm    Post subject: Reply with quote  Mark this post and the followings unread

Finger printing is a rather static technique. There is a training sequence of some sort, either silence or a know signal. As the channel changes you have to retrain. This technique is used in modems and other analog telecommunication circuits. Inventor's technique is. on the other hand, truly adaptive.
_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
TGV



Joined: Jul 03, 2009
Posts: 23
Location: Utrecht, The Netherlands

PostPosted: Tue Jul 14, 2009 12:13 am    Post subject: Reply with quote  Mark this post and the followings unread

Under normal circumstances, noise, whine, and hum are "static": it's the circuitry and microphones that generate it, and they don't change (at least not perceptibly). The adaptive technique has an advantage: you don't need a finger print, but it has problems with transients (feed it a snare or kick and you'll see) and it cannot take out whine and hum, since their harmonic amplitudes are almost constant over time. That's why I suggested it.

Anyway, there is no reason to use just one of them. You could use the finger-print technique on the end signal, and adaptive filtering on the mike, or something like that.
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Tue Jul 14, 2009 5:49 am    Post subject: Reply with quote  Mark this post and the followings unread

mosc wrote:

Still, there is some whine caused I think from some power main harmonics. Your adaptive filter won't get rid of those constant signals because they are seen as valid inputs signals.

You could get rid of the whine with a fixed equalizer, but an adaptive one would be more fun and useful. What happens if you differentiate the frequency domain coefficients as well?


Call me lazy but in that case I'd first try sorting out the ground/mains situation before breaking out the DSP. Typically that takes less time and you save on headroom and sound quality.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24075
Location: The Netherlands, Enschede
Audio files: 277
G2 patch files: 320

PostPosted: Tue Jul 14, 2009 7:29 am    Post subject: Reply with quote  Mark this post and the followings unread

In this case, as a listener, to me it seems that the airconditioner and a computer fan are the main sources of noise ... which would be something in favor of an adaptive technique. I must say that I dont quite understand what happens in the code, but it does filter noise and it doesn't give too many artifacts ... so not bad at all I'd say.
_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
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: Kassen
Page 1 of 1 [19 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 » ChucK programming language
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


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