Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: FFT outputting with a margin of error (Read 4706 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

FFT outputting with a margin of error

Hello, I'm working on a project in java that uses Fourier Transform.  Everything about the project works perfectly, but my FFT analysis comes out inaccurate. The gist of it is right, the heavier the bass the higher the intensity, but it is not exact. This is my program running on low frequency waves in the order of Heaviest, Least heavy, then mid heaviest: http://pastebin.com/yxyBwv2Q. It's a single sin wave per section, so in each section all the Os should line up together. Instead they're staggered, meaning my FFT is doing something wrong. The code for my program is here: http://pastebin.com/wY0dZHUw. Perhaps there is something wrong with the math? It looked all good to me. The class I use to decode my MP3 files takes 1152 samples at a time. Since I'm only using the first 5 low frequencies I acquire from these samples (the list of these hz can be found at the bottom of my program), I assume a window method is not necessary, as I've been told it won't really affect low frequencies. I'm also trying to output as fast as possible, so I want to be able to get exact results as fast as I can (taking the minimum amount of samples while staying accurate is my goal).

Anyone know where I've gone wrong in this?

FFT outputting with a margin of error

Reply #1
If you print the actual output of the FFT instead of whatever it is you're doing there, do the values look correct?

FFT outputting with a margin of error

Reply #2
If you print the actual output of the FFT instead of whatever it is you're doing there, do the values look correct?

These are the values of the first 5 frequencies (first 10 numbers) right after fourier transform, no fixing the values yet: http://pastebin.com/UUSmU2q0. Each line break signifies a new sample grab. The first sample grab is quiet I believe, that's fine. But those 0s, they look suspicious. No idea if they're supposed to be there.

Here are the first five frequencies after performing the after math: http://pastebin.com/q1QRHig8
I'm not really sure what they're supposed to be, but they don't look very correct.

And straight decoded from my mp3 file (With imaginary 0s added), here is the first array before any edits besides adding in the 0s: http://pastebin.com/5AYQBAes

FFT outputting with a margin of error

Reply #3
There's nothing strange about 0s, as the imaginary part of the first and last FFT coefficients is always 0.

From your description, I don't understand your question. What is staggering? What is it that you expect to get and how is it different from what you are getting?

FFT outputting with a margin of error

Reply #4
There's nothing strange about 0s, as the imaginary part of the first and last FFT coefficients is always 0.

From your description, I don't understand your question. What is staggering? What is it that you expect to get and how is it different from what you are getting?

The Os in this run of the program are staggered: http://pastebin.com/yxyBwv2Q. For now, disregard anything after line 189 as those are different amplitude waves. From 0 to 189, a constant sin wave of 30hz at a set amplitude is playing. The amount of Os printed out is dependent on how loud the bass is. Since the bass is constant, from line 0 to 189 all the Os should line up together, as the bass intensity level is the same all those sample grabs. But since they don't line up, it means my program is being inaccurate. It's accurate to a degree, but not as accurate as it could be. I want to fix that.

FFT outputting with a margin of error

Reply #5
Due to spectral smearing, the maximal amplitude of FFT coefficients is not a precise indication of a sinusoid's amplitude. You should either apply a flat-top window to your time-domain signal or integrate the energy of all spectral bins contributing to the sinusoid.

FFT outputting with a margin of error

Reply #6
Due to spectral smearing, the maximal amplitude of FFT coefficients is not a precise indication of a sinusoid's amplitude. You should either apply a flat-top window to your time-domain signal or integrate the energy of all spectral bins contributing to the sinusoid.

I used this Flat Top method http://www.mathworks.com/help/signal/ref/flattopwin.html and coded it like this: http://pastebin.com/wncqYTTV. On my bass test file it works perfectly, very accurate results. But on any other things, it will just vary an O or 2 around a line like this: http://pastebin.com/MXjW6PPw. That file right there has a 440 tone, a 5000hz tone, and a 16000hz tone. No bass. What's wrong the window method I used?

FFT outputting with a margin of error

Reply #7
I can only suggest to debug your program in smaller pieces. Check all the numeric values, not the number of O's.