05-28-2009 09:34 AM
I've attached my VI for calculating a Gausssian kernel function of selectable width and resolution. I am not an expert in mathmatics and I was hoping someone on here could confirm the validity of my code. If anyone has any suggestions please let me know.
Eric
05-28-2009 09:45 AM
05-28-2009 01:34 PM
Well, way too complicated comes to mind ;).
We don't need a loop. We also have a primitive for 1/x, no need for a diagram constant of "1".
Here's what I would probably do for an output of same width. Modify as needed. (note that the scaling is currently 0..1, I am not sure what you want).
05-28-2009 04:03 PM - edited 05-28-2009 04:04 PM
Sorry, here's a more direct version which also includes the same scaling as your code. (I usually do width in terms of "width at half height", so the earlier code is a bit crooked).
... and pease stick to DBL. I have no idea why one of your comtrols is EXT. 😉
05-28-2009 05:58 PM
First, I'm under the impression that a Gaussian kernel should have an area under the curve of 1, thus the scaling at the end of my submitted VI. I've attached a paper that suggests this point. The following webpage suggests it as well.
http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/AV0405/MISHRA/kde.html If this is incorrect, could you please advise differently.
Second, I applied the same integral scaling used in my submitted VI to the end of your suggested VI and found that the y-values differed slightly (see attached VI). This suggests a computational difference between the two. Why do you think this would occur? How do I know which is more correct?
05-28-2009 06:17 PM
Never mind that last message, I was responding to your earlier suggestion. Thank you for your help.
05-28-2009 07:15 PM
eemans wrote:First, I'm under the impression that a Gaussian kernel should have an area under the curve of 1, thus the scaling at the end of my submitted VI.
I am not familiar with your particular application, but if you do convolution, you simply want to normalize by dividing the kernel function with the sum of all array elements. This way the convolutee (;)) retains it's area.
Can you describe your application?
05-29-2009 11:16 AM
To better show what it is I'm trying to accomplish, I've attached the top level VI that's using the kernel function, entitled "Pattern Analysis of IPIs 2," . The zip folder contains the top level VI, a folder with all the subVI's and two data files. Open the "Pattern Analysis of IPIs 2" VI and go to the "Files" selector tab toward the bottom right of the front panel. Here you'll be able to select the folder containing the data files. You'll need to unzip the attached folder and save it somewhere, then select that folder as the "current folder" to be opened (you don't need to specify which data file to open, it will open both). Once the folder is selected you can run the VI and view its results.
When the program begins running a boolean indicator located in the bottom left corner will appear red and the slider bars along the bottom will be disabled. When everything has been calculated the boolean will turn green and the slider bars will become enabled. Choose the selector tab entitled "SPI, SDF & SDD" to view the spike density function. The spike density function (SDF) is what's being created with the Gaussian kernel. The enabled slider bars allow you to adjust the x-axis values of the plot. The cursors on the plot indicate indicate the start, peak and end of high rate bursts. It may be easier to visualize this by viewing the raw data located at the "Wfm Absolute and Relative Time" selector tab. To reduce file sizes the raw data has areas of "quite" removed, so you will only see the voltage change events, represented by what appear to be vertical lines.
To move to the next data file, click the button entitled "Save and Go to Next" located in the bottom right hand corner. A prompt will appear asking if you want to save the data, click "No" and the next file will automatically be loaded. To stop the VI, wait until the boolean is green and the slider bars are enabled, then click the "Stop" bottom located at the bottom right. It may take a few seconds for the VI to stop.
Moving to the block diagram, you'll see a yellow subVI with black writing that says "SDF," this is where the SDF is calculated. Open the front panel and block diagram of this subVI. On the block diagram you'll see the subVI entitled "Gaussian Kernel," this is the subVI you saw yesterday. The generated Gaussian kernel is alligned at peak pulse times (can be seen in the graph entitled "Gaussian Kernel Alligned at Peak Times") and summed to create the SDF. I only choose this method of generating the SDF because it seemed intuitive to me, it may be wrong. If it is, could you please demonstrate how to program the convolution. Ultimately, I'm trying to achieve the plot described on the third page of the attached paper.
05-29-2009 01:16 PM - edited 05-29-2009 01:17 PM
Ouch. Looking at any of your VIs, requires at least a 24 inch HD screen, which I currently don't have. There are also some missing subVIs, so I cannot run it. Do you use any toolkit?
Can you make a small and simple VI that only reads the data and does the manipulation with the gaussian kernel on it?
(BTW, just glancing at your VI, many things are way too complicated and can be done with near atomic operations. For example, have a look at "20 Burst Landmarks.vi". Massive uses of "delete from array" in tight loops is very memory inefficient. There is a lot of duplicate code, for example 10+ copies of the same formatting loop. Also, the way you built the final table can be done easily without any loop. See image (you actually use 20 input arrays, I only show a few...). Your version is on top, my version at the bottom. Both do the same thing if all imputs have the same size. (If the sizes differ, your version truncates to the shortest input while my version pads to the longest input.))
05-29-2009 04:12 PM
If you haven't guessed by now I'm an entirely self taught programmer who has never used a book or taken a course on computer programming. Because of that, I would imagine there are several little improvements I could make and it would be greatly appreciated if you could point them out to me. All the vi's used in the "Pattern Analysis . . .vi" are kept in that folder so I'm not sure which are missing. If you can let me know which ones it says are missing I'll gladly send them on. As far as toolkits go, I have no idea. I'm using a computer that already had the LabVIEW software on it. Also, I'm working on a laptop with a 17" screen and I can see the VIs fine. However, there are a couple that I haven't finished yet, like the "20 Burst Landmarks.vi", that are still pretty big.
I do appreciate the comment on the final table of the burst landmarks, if you have any more like it please let me know. The loops with the delete from array are essential to the program, if there is a better way of doing the same thing I'd love to hear it. The formatting loops are another essential feature, each of which is formatting a different aspect of the data. Again, if you have any suggestions on how I could do this differently, please let me know.
The only thing I really need to verify is the code for generating the SDF, it's the foundation of all the data analyses that happen in the "20 Burst Landmarks.vi" I've attached another zip file that has the "SDF.vi", "Gaussian Kernel.vi" , and the data files. Use the "SDF.vi" to select the data file to run. I want to compare my method of generating the SDF with the convolution method but I'm not sure how to program the convolution method. It would be increadibly helpful if you could demonstrate this. That first paper I attached discusses the convolution method I'm talking about.