LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I'm trying to detect the dominant frequency in an incoming guitar signal, could someone please help?

Hi all,

 

I am trying to use Labview detect the notes being played on a guitar.

 

So far I have the guitar signal being read into Labview via the line in port of my computer. (I've simply used an example that I forget the name of - My .vi is attached, named Diagnostic.vi). It then organises the input, does the frequency analysis on it and produces a figure for the dominant frequency (plus other things).

 

The principal of what I have the program doing here is fine - the .vi determines the dominant frequency in the signal. However, (and I think this is where my understanding is lacking) I can't get the program to 'window' the frequency analysis over a short time period (such as 1/8th of a second) without compromising frequency analysis resolution. Here's the scenario: 

 

As you will see in my vi there are two inputs labelled 'sampling rate' and 'number of samples'. If I set sampling rate to the maximum allowed rate (44100hz) and the number of samples to 44100hz, I get dumped with all 44100 samples every second, no problem with this, its as expected. 

 

But I want my sampling window (i.e. the number of samples the frequency analysis is performed over) to be a lot shorter (1/8th of a second would be ideal). My initial instinct is to reduce 'number of samples' to the number acquired by the sound card in 1/8th of a second at 44100hz. 44100/8=5512.5. (as this is the number of samples I wish to analyse)

 

But in my .vi this has the effect of reducing the effectiveness of the frequency analysis. The spikes in the graph of each harmonic are significantly less defined. 

 

Is this the nature of the mathematics of FFT and windowing? Or am i doing something wrong with the code to achieve the desired results?

 

Any help will be massively appreciated.

 

 

Kind Regards,

 

Ryan  

0 Kudos
Message 1 of 6
(4,290 Views)

Ryan,

 

The frequency resolution of the FFT is the reciprocal of the duration of the signal: df = 1/T = 1/0.125 s = 8 Hz

 

What you may need to do is to take your 1/8 second sample sets and zero pad them out to a second.  Of course you also need to decide what to do with the half of a sample.  This looks like a rectangular window, so you may want to do other windowing to shape the spectral response as desired.  The padding would have 19294 samples with value = zero followed by your 5512 data samples and another 19294 zero samples for a total of 44100.  If speed is an issue, consider making the FFT input array have a length which is an integer power of 2 (32768 for example).  The FFT algorithm is fastest for such array sizes.  It may not make much difference on the latest versions of LV, but it is something to keep in mind.

 

Lynn 

0 Kudos
Message 2 of 6
(4,268 Views)

Lynn - Thanks for the reply.

 

Would this method allow me to get an output of the dominant frequency 8 times a second?

 

 

Ryan 

0 Kudos
Message 3 of 6
(4,260 Views)

Ryan,

 

I have not timed it.  I would think that most modern computers could do a 32K point FFT in much less than 125 ms.  It may depend on what else your program is doing and how well it is structured to avoid bottlenecks.

 

What do you do with chords?  Those should have multiple frequencies present simultaneously, right?

 

Lynn 

0 Kudos
Message 4 of 6
(4,255 Views)

Thanks Lynn. 

 

For basic chords I have a set of harmonics that the system can 'expect' to hear when a certain chord is played. Although there are more than one chord which could have these harmonics, this anomaly doesn't affect the success of my application. I'm merely trying to detect if the guitarist is playing the chord which the computer suggests.  

 

The problem I have is detecting notes fast enough in real time. If no single note or chord lasts less than half a second then the system works a treat.

 

So all I'm trying to do with this is speed up the frequency analysis.

 

Thanks again for your input.

 

Ryan.  

 

 

 

 

0 Kudos
Message 5 of 6
(4,252 Views)

I have posted a couple of examples in the past that may help you out.  Both rely on the Extract Single/Multiple Tone Information VIs.  These VIs use FFT, but apply an appropriate window to the data and use the resulting known peak shape to get sub-sample accuracy.  The only caveat is that you need ten to twenty cycles of the waveform to get good accuracy.  With a guitar, this should not be an issue, since the low E should be 82.4Hz, giving you an 8.2Hz update rate with ten cycles.

 

Let us know if you need more information.

0 Kudos
Message 6 of 6
(4,213 Views)