I want audio spectrum analyzer which have 0.1hz fine resolution.

Hi, I'm doing my own project.

My goal is after getting violin sound by analogRead, turn timedomain into freqdomain by fft, and see which frequency vlioln is playing.

Here is problem.

I set freqency range as 150hz ~ 1500hz(cuz i'm new at violin). So sampling rate will be 3000hz following Nyquist sampling theory. And I want fine resolution about 0.1hz. Then the number of bins would be 30,000! Does it mean that I have to get analog inputs for 10sec?? (because it takes 1/3000 sec for 1 bin, and there are 30,000bin)

It seems wrong because there are many android apps for instrumental tuning. And they doesn't take any longer than 1sec for deciding which frequency is playing...

Is there anything I can't catch?? I hope any opinions of yours

Thanks

What type of Arduino do you have?

It seems wrong because there are many android apps for instrumental tuning. And they doesn't take any longer than 1sec for deciding which frequency is playing

And do these apps give the frequency to 0.1 Hz resolution? I think not.
And are the processors these apps run on comparable to an Arduino of any type? Again I think not.

Hi mike. Thanks for reply.

I have arduino Uno. And I am finding proper mic modules.

Well, the app that I use displays second decimal place.(I'm not sure it really measures or just computes, but can display anyway)

And I can't understand your intend for second question...sorry. Is that important?
Apart from what processer is, to me, it is the problem of possible or impossible.

pgn0329:
Is there anything I can't catch?? I hope any opinions of yours

Thanks

Yes, you make the mistake of thinking of the FFT as the only and best way to measure a tone's frequency, and
its not.

With careful interpolation from an appropriately windowed FFT you can measure peak frequency to a lot better resolution than the bin width,

However a better way to actually measure the frequency is more complicated - perhaps use FFT for initial estimate, bandpass filter out the fundamental, then refine the estimate using correlation techniques and
a model tone for comparison - basically generate a model tone at the estimated frequency and see how
fast its phase error drifts along the duration of the sample set. That allows you to refine the estimate.

A simpler approach, much easier to code, is to bandpass filter to the fundamental then estimate each
zero-crossing time by linear interpolation. Linear regression on the crossing times gives the frequency.

Hi MarkT

MarkT:
With careful interpolation from an appropriately windowed FFT you can measure peak frequency to a lot better resolution than the bin width,

Is that mean I shouldn't get analog inputs for 10 second for filling time domain bins?

  1. After getting inputs for less than 0.1 second
  2. then 300 bins of time domain would be filled
    3.at that moment it seems time domain is windowed by rectangular window, other bins are zeros(301~30,000)
  3. properly window those time domain bins and take FFT... Oh, maybe it is possible!! Am I thinking right??

And I can't understand your intend for second question...sorry. Is that important?

Not only does it say a thing about the processor but it also says how big the memory is in terms of samples you can hold. With a Uno you have only 2K of memory for everything. Inputs to the FFT process must contain a number of samples that is a power of two, so the biggest buffer you can have on a Uno is 1024, the next size up is 2048 which is more memory than you have. Don’t confuse a bin with a sample, a sample is your input waveform and a bin is the output of the FFT process.

at that moment it seems time domain is windowed by rectangular window, other bins are zeros(301~30,000)

No a FFT requires that you take the whole of a sample in the buffer containing exactly a whole number of waveforms of what you want to analyse. A window slowly attenuated the samples from zero to no attenuation at the start of the sample, and fades it out again at the end. Before you submit your sample buffer to the FFT you multiply the buffer by the window sample.

Well, the app that I use displays second decimal place.(I'm not sure it really measures or just computes, but can display anyway)

Yes I think you will find not only is it a cosmetic but the frequency it measures will be inconsistent.

Like Mark says an FFT is not the best way to detect a frequency. Many people come on here asking for what you are asking for and I have come to the conclusion it is not possible. Have a look at the Teensy board that will be much closer to getting a usable indication of what you want. Their web site has a few different algorithms that can do this sort of thing.

However what ever you use you need a good solid filter on the front end to prevent antialiasing. Probably a fourth of sixth order filter.

If you want to play about with an FFT then download the free app called Audacity and run it on your PC, it will take samples and let you examin the sample and even display an FFT of them. Then you can see what sorts of results you get, or don’t get.

Rectangular window is hopeless. Unless you synchronize your sampling precisely to the signal source its never useful.

Hann window (aka Hanning) is a reasonable general purpose window if you are not measuring anything
precisely.

Flattop windows are needed for accurate amplitude measuring or comparing tones for volume, other window types will give amplitude variation depending on precise frequency.

If you know/analyze the mathematical details of the window used you can use the slopes between the
neighbouring bins to estimate a peak's centre frequency to better than the bin-width. Assuming a clean
tone.

All professional RF spectrum analyzers use flat-top windows, often proprietry ones. Many cheap audio tools
(hardware or software) are inaccurate simply because they just use a Hann window and hope for the best.

The ratio between spectral peaks and the noise floor is dependent on the window functions variance.
There's a tradeoff between seeing stuff low in the noise and getting accurate peaks. This is why Hann
windows are common.

Many wonderful details of accurate spectral estimation are in this great paper:http://holometer.fnal.gov/GH_FFT.pdf

..I'm not a DSP expert.

I "feel like" 0.1Hz is going to be "difficult".

You might want to play around with [u]Audacity[/u]. It doesn't work in real-time, but you can display the spectrum of a recorded file and that should give you an idea of what you're dealing with.

As you probably know, all real world sounds contain multiple-simultaneous frequencies and that's why it's tricky to make a tuner. The fundamental frequency (which determines the perceived pitch) is usually the strongest frequency, but not always.

And, it's the harmonics & overtones that make a violin sound different from a piano when playing the exact-same note.

So sampling rate will be 3000hz following Nyquist sampling theory.

I'd recommend a higher sample rate. You'd have to filter-out the harmonics (before digitizing) to prevent aliasing. Every "real" audio ADC has a low-pass filter. And "strange things" can happen when you get very-close to the Nyquist limit. Also note that filters are imperfect and the filter cutoff frequency is defined as the -3dB point so a 1500Hz filter would let-through some signal above 1500Hz and you'd need a lower cutoff frequency at a 3000Hz sample rate.

Thanks guys. Such a good advices, reference, tool, and web page. I should study more and come back:)

As a feel for what resolution is theoretically possible, consider a 0.1s sampling at 48kSPS of a 1kHz tone.
Thats about 5000 samples.

That will have 100 cycles of the fundamental, ie 200 zero-crossings. If the sample depth is 12 bits, you
might be able to linearly interpolate a zero crossing to about 1/200th of a sample period, ie 100ns.

Averaging of those crossings refines the estimate by the square root of the number of crossings to about
6ns, which as a fraction of 0.1s is 0.06ppm, ie a frequency resolution of 60 micro hertz.

This is, of course, completely unrealistic unless the original tone is ultra stable and has ultra low distortion.

However just by rounding zero-crossings to the nearest sample you get 1 part in 5000, ie 0.2Hz
resolution. So for 1s sampling time you can get 0.02Hz resolution or better, without super high constraints
on the cleanliness of the signal.

Interesting mathematics!

MarkT:
If the sample depth is 12 bits, you might be able to linearly interpolate a zero crossing to about 1/200th of a sample period, ie 100ns.

I can't understand which concepts are you explaining...

Let's say. There would be zero crossing point between two samples and bit depth is 12 bits. I understood your explanation as 'I can find more fine zero crossing point to about 1/200 of sample time.' In this example, fine interval will be 100ns.

But why 1/200? Isn't it 1/4096(=2^12)?

And totally new at those below quotes...

Can you explain more or let me know which concept or keyword I should find?

With 4096 graduations peak to peak its not hard to linearly interpolate to high time resolution, the waveform slope affecting the resolution attainable form a pair or a handful of samples.

Using correlation to least-squares fit an entire model sinusoid to the data is the most accurate of all I suspect as
that uses every sample to contribute to the estimate - basically curve fitting to a graph.

But why 1/200? Isn't it 1/4096(=2^12)?

You are confusing the resolution of the amplitude measurement with the resolution of the time measurement. The former is given by the A/D and the latter by the sample rate. The two figures are not related.