Using FFT to find and alter frequency in an audio file

Hi all

First off, to 'matfud' and others who have posted on using FFT to detect frequency content of an audio segment, many thanks. Your posts have been very, very helpful, especailly these threads:

"extracting frequency using fft "

"FFT to get DTMF on a Wav file "

Now, with the ***-kissing out of the way, I have a problem you might (or might not) be interested in helping with. I have done a lot of laymans reading on the subject, and am not a programmer, nor a DSP specialist, but I need to figure this stuff out for a project I am trying to put together.

So, here's the problem:

I want to be able to read in an audio file (wav, or mp3), do the necessary (FFT?) processing on it in overlapped segments to extract a list of all frequencies present in a given segment, and then alter these frequencies so that they areall either even or uneven numbers. I Know it sounds strange, but there is a reason for it. I then have to recreate the original audio as closely as possible, with the new frequencies in it.

I am going to try yo base the reading/processing part of it on what was written in the first of those two threads mentioned above but I then need to know how to get the new collection of frequencies converted back into an audio file.

[1303 byte] By [healyrona] at [2007-11-27 6:36:24]
# 1

If you're going to use FFT, you're going to have to deal with the trade off between

frequency resolution and the length of your time segments. You need to look

into different ways of compensating for those problems, through optimum filtering, windowing and/or zero-padding. For your specific problem, I would try to be happy with a filtering bank, which is analog to the discrete wavelet transform, dwt (or the fast one, fwt). This should give you a decent answer. Choose your wavelet so that it's as easy as possible to reconstruct the signal. Use the inverse dwt. The dwt is also dead easy to implement, you just need to read up on it a bit, check this out... http://perso.orange.fr/polyvalens/clemens/wavelets/wavelets.html

ArneWeisea at 2007-7-12 18:04:00 > top of Java-index,Other Topics,Algorithms...
# 2
Steganography and Watermarking are both considerably weakened if you ask for suggestions of how to do it in a public thread.
marlin314a at 2007-7-12 18:04:00 > top of Java-index,Other Topics,Algorithms...
# 3

Hi

Not reaqlly sure what you mean by Watermarking and Steganography being weakened when asked about in a public thread. If you mean that the 'technology' being investigated could become easily 'broken', then thanks for your concern and, no, I'm not being facetious :-)

However, for what I want to do, the technique needs to be neither strong, nor secret. Steganography, as I understand it, is the hiding of information in a carrier for the purposes of it being un-noticed, not completely un-noticeable. Small distinction, but it seems that most research is into the strength against attack of any given proposal. To my end, that it not relevant

Incidentally, what made this query somehow related to Steganographyor Watermarking ;-)

Thanks for the replies. Any more sugestions? All I am really interested in is knowing *Which* frequenceies are present in a given signal, without analysing every known frequency to see if it is there...

healyrona at 2007-7-12 18:04:00 > top of Java-index,Other Topics,Algorithms...
# 4

How did I get to Steganography and Watermarking? Well it goes like this:

You want to make things all even or all odd. This means changing the low order bit so that you have have nothing but zeros or nothing but ones, leveling out a noisy field where you couldn't write something without it being obscured by noise and creating a clear slate where you could write something.

You want the resultant audio after you have screwed with it to be similar to the one you started with. This means that you are not trying to do some filter that changes the audio for some desirable sonic reason, like noise reduction, equalization, bandpass filtering, audio compression or any other useful chunk of filtering, instead you want to hide something.

Lastly you are coy about the reasons for wanting to do this. No reason for you peons out there answering my questions to trouble yoursleves over WHY I want to so some obscure and poorly explaind thing, just tell me how to do it.

"I am not explosive expert or even in military but I am wondering if someone out there can tell me how to build shaped spherical charge that could drive fissile materials together to achieve high density for a short period of time."

"What? Nuclear bombs? I said nothing about nuclear bombs? What make you think I am trying build nuclear bomb. I am working on entirely different project but is secret and I can't tell you about it."

Sure, whatever you say.

To answer your question. Since all you want to do is scrape some area in a audio file clean, where you COULD be hiding something like a message or a water mark but where you will NOT be doing that because you have some entirely different purpose in mind, what you do is standard digital signal processing.

You use FFT or DCT to transform a pile of 256 numbers in the time domain into 256 numbers in the frequency domain. You can then munge on the numbers however you wish, setting some to zero, altering the low order bit, whatever you want. Then you back transform into the time domain and are left with a time domain signal similar tot he first. The alterations that you did in the frequency domain act like some kind of filtering on your original signal. How detectable or undetectable those modifications are depend on what exactly you did and depends on how sensitive are the ears of those that are listening to the signal. (not all ears are human, eh?)

The FFT and DCT are well defined, well understood, published algorithms and they are very fast. Get one from anywhere you like and use it to mash numbers back and forth between time and frequency domain. Screw with the numbers however you like in the frequency domain. Listen to the results to see if your screwing with the numbers was bothersome once the results are back-transformed.

Was you question about how to make a pile of numbers all even?

Sorry, can't help you there, that is classified information, for rather obvious reasons.

Enjoy!

marlin314a at 2007-7-12 18:04:00 > top of Java-index,Other Topics,Algorithms...
# 5

Hi

Thanks for your reply, whatever its intention was :-)

In relation to your comment "Lastly you are coy about the reasons for wanting to do this", I actually was not being coy. Coy is a characteristic that would rarely be used to describe me, but thanks anyway!

What I was doing was trying to avoid wasting the time and effort of people who might not be in the slightest interested in *why* I wanted to do something, but interested in *how*

Its no secret, actually, if you are interested in the *why* then let me know and I will happily email you a brief.

As for it being 'briefly explained', see the above point :-)

I'm not asking in order to find out how to scrape some area of audio clean, so I can hide a watermark in it. I'm aware that there are plenty of ways of embedding data. I'm more interested - at this current stage - in making use of the characteristics of the data before it has anything embedded in it.

Anyway, just thought, since you went to so much trouble, you might like to know.

Your last (sarcastic?) question: "Was you (sic) question about how to make a pile of numbers all even?" is actually nearer the mark than claims that this is about watermarking itself, except that it was about how to make a pile of *frequencies* all even, rather than numbers, but let's not split hairs.

After all that, I'm not really sure that what I want to do would wualify as either Steganography or Watermarking, and that's why I asked what led you to think it did.

Sorry :-)

healyrona at 2007-7-12 18:04:00 > top of Java-index,Other Topics,Algorithms...
# 6

I have followed this thread with interest and I'm not sure I understand it. The biggest problem I have is filtering out the ****.

You say "... then alter these frequencies so that they are all either even or uneven numbers ..." . Do you mean you want the magnitudes to be even or odd or the frequency to be even or odd? If so then it does not really make sense.

Assuming you mean you want the magnitudes to be even or odd then you have a problem. The FFT is an implementation of the DFT and given that this will be implemented in floating point with fixed length arithmetic any implementation is actually only an approximation. Given the transformation

time samples -> frequency samples -> time samples

will the new 'time samples' be the same as the original? Possibly but you can't guarantee it. You can say they will be close but not the same.

If you then have the transformation

time samples -> frequency samples -> even/odd transformation -> time samples -> frequency samples

will the final 'frequency samples' be the same as those coming from the 'even/odd transformation'? I would have to say probably not.

Assuming that this is to be done for watermarking then you already have a credibility problem with any court you have to convince that someone has stolen your copyright material. Also, the watermarking is easy to remove - transform to the frequency domain, randomize the last bit and then transform back to the frequency domain.

sabre150a at 2007-7-12 18:04:00 > top of Java-index,Other Topics,Algorithms...
# 7

to make an integer even you just set the low order bit to zero

n &= 0xfffffffe; // n is now even

Of course, setting n to 4 also makes it even,

There you are, several algorithm choices, go nuts.

All I meant by being coy was that you have had three opportunities now to disclose what you are trying to accomplish and have not availed yourself of a single one of them.

Since we don't know what you are trying to do, we are forced to guess. I already told you my two guesses, both of which I think are foolish. As you can see, even sabre thinks that what you are doing is some form of water marking and as he points out it is a dumb idea or rather the implementation that has been hinted at by your question is a poor implemenation of watermarking.

Without more information on what you are trying to accomplish it is unlikely that we can provide any particularly useful advice. Your suggestion that you could explain your purpose offline in some private email is not appropriate in a public forum such as this. Either tell us what you are trying to do or don't.

marlin314a at 2007-7-12 18:04:00 > top of Java-index,Other Topics,Algorithms...
# 8

Hi

Thanks to both previous posters for your replies. I'll start first with this:

"If you then have the transformation time samples -> frequency samples -> even/odd transformation -> time samples -> frequency samples will the final 'frequency samples' be the same as those coming from the 'even/odd transformation'? I would have to say probably not."

Thats correct. The end result will not be excactly the same as the starting frequency/signal. It does not need to be. As I mentioned above, the purpose of the experiment, and thats all it is, is not a form of watermarking, despite the fact that those more expert than me think it is. Following on from that, the reason I am being 'coy' for want of a better term, is because this is part of my Masters research and my supervisor has advised me not to be too free with academic information, specifically anything 'unusual' I might be looking into, which this is. Sorry if it causes a problem for people, but since I know little or nothing about the Academic world, I have to take his advice (i'm almost 40, just went back to college last year so not really up to speed on the politics of these things).

Going back to what was said earlier, it is exactly as was mentioned. If the initial signal is taken, and some frequencies (or, rather, all frequencies in some blocks of sound) are coverted to all od or all even, then the resultant sound is different. Moreover, it is impossible to prove, as was rightly mentioned, in a Court of law that the soudns were the same. That, again, is not my intention.

Thanks again for the feedback. I'll keep looking around. I might even get to understand this stuff one day (God forbid!)

healyrona at 2007-7-12 18:04:00 > top of Java-index,Other Topics,Algorithms...