LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Peak Detector

Hi
 
I need to write a vi that takes a binary file, converts it to dB, filters the noise out below 400Hz then creates an array showing the 5 greatest amplitude and frequency peaks above a certain threshold and width. I've had a go already but it is very slowly. The input file is sampled at 44100Hz and the file can be between 10 and 40 seconds long.
 
Any help would greatly appreciated.
 
Cheers
 
Dave
0 Kudos
Message 1 of 20
(5,616 Views)
Hi David
What do you have so far?
If you would like to post your code I could look into speading it up for you.
Which parts take the longest amount of time?
 
Thanx
 
AdamB
Applications Engineering Team Leader | National Instruments | UK & Ireland
0 Kudos
Message 2 of 20
(5,571 Views)
Hi Adam
 
Thanks for this. I've attached the vi that extracts the peaks, the main vi it is run in that transfers data to excel, and an example binary file. Note that I had to rename the binary file as .txt instead of .dat to upload it so you may need to change the extension.
 
Cheers
 
Dave
0 Kudos
Message 3 of 20
(5,566 Views)
Hi again,
 
What version of the SVT toolit do you have? (and LV)
I have version 4.0 of the toolkit and some of the output data types have changed
 
Thanx
 
AdamB
Applications Engineering Team Leader | National Instruments | UK & Ireland
0 Kudos
Message 4 of 20
(5,559 Views)

Hi Adam

I'm running LV 7.1 along with the SVT toolkit that came with it - where can I get the version number from?

Cheers

 

Dave

0 Kudos
Message 5 of 20
(5,554 Views)
Hello (yet again),
 
Well I'm getting about a second to go through and do the calculations on this data.  That's pretty much what I would expect to see on such a big array. (once converted it's 7Mb)
There are a lot of array manipulations which means that the 7Mb will need to be duplicated for different operations.
 
What times are you seeing?
 
AdamB
Applications Engineering Team Leader | National Instruments | UK & Ireland
Message 6 of 20
(5,556 Views)

Hi Adam

From hitting the open file button to the two output arrays being filled it's taking about 8seconds. When I use it in the main vi it takes minutes to do the same thing.

Cheers

Dave

0 Kudos
Message 7 of 20
(5,554 Views)

Hi,

Well on my machine the sort array is the function that is taking up the most amount of time.  In the code you have given me, you don't actually need the sort array because the array is already sorted with regards to the frequancy.

If you look at your data before and after the sort it will match.

I do however suspect that you are really trying to sort by the amplitude.  In this case you need to firstly swap the inputs to the build array (after the peak detects) and then the sort data will sort with regards to the amplitudes.

As for the actual sort function, this is a function that does take it's time when you are trying to sort clusters.  If you simply sort the amplitudes (as an array) and then pull out the appropriate frequances you might get better speeds.  I'll post a picture of the method I will use in a bit.

Thanx

AdamB

Applications Engineering Team Leader | National Instruments | UK & Ireland
Message 8 of 20
(5,550 Views)

Hi Adam

Thanks for that - I should have said that I am looking for the 5 'greatest amplitude' peaks for both magnitude and frequency and their corresponding locations - hence why I needed to sort them as a cluster to keep the amplitude and locations together. If you could post an example that would be brilliant.

Cheers

Dave

0 Kudos
Message 9 of 20
(5,545 Views)
Hi David,
 
The implementation of your Sort Array functions are actually sorting by frequency (not by amplitude)
Anyway here is a screen shot of the code I have made.
 
I take the array, search for the max and pass this to be stored (along with it's appropriate frequency value).  Then I delete the max value from the array, and search for the next highest. and so on and so forth until I have the 5 max values. (and their frequencies)
 
Finally I pass that data forward from the for loop in the array format you need.
 
Take a look, implement the code and see what you think.
 
AdamB
 
Applications Engineering Team Leader | National Instruments | UK & Ireland
0 Kudos
Message 10 of 20
(5,542 Views)