"Block averaging" function?
| February 17, 2010 - 11:21 | |||
|---|---|---|---|
|
|
|||
| February 17, 2010 - 12:42 | |||
|---|---|---|---|
|
You haven't shown us the Igor function you're using, but here's what I would use: Function BlockAverage(inputWave, outputWave, blockSize) WAVE inputWave WAVE outputWave Variable blockSize Variable inputPoints = numpnts(inputWave) if (!WaveExists(inputWave)) print "The input wave does not exist." return -1 endif if (!WaveExists(outputWave)) print "The output wave does not exist." return -2 endif if (blocksize < 1 || blocksize > inputPoints) print "The block size parameter is not within an appropriate range." return -3 endif Redimension/N=(inputPoints/blockSize) outputWave outputWave = sum(inputWave, pnt2x(inputWave, blockSize * p), pnt2x(inputWave, (blockSize * (p + 1)) - 1))/blockSize return 0 End |
|||
| February 17, 2010 - 13:20 | |||
|---|---|---|---|
|
Put this in your procedure window: #include <Decimation> Then choose Analysis->Decimate. To see what the is going on under the hood, choose Windows->Procedure Windows->Decimation.ipf. Basically, it creates a destination wave and then executes a wave assignment statement that calls the mean function. |
|||
| terracotta | February 18, 2010 - 08:55 | ||
|---|---|---|---|
|
Thanks a lot for the replies. The decimate function is interesting, but Adam's code is more what I was looking for. I tried it out and it is much faster than my own code (I was looping through the entire wave with a for loop and increasing the index by the block size each time). Thanks again. |
|||


Joined: 2010-02-10
Location: United States
Hi everyone,
I have actually written a simple function myself to do this, but it is rather slow and I was wondering if a function existed within Igor that would allow me to do this quickly.
I am attempting to "compress" a wave by taking the first 5 points of it, taking the average value of these points, and making this average one point in a new wave. I would then go to the next 5 points, take the average, and so on; the resulting wave is 5 times smaller than the initial. I could then make it 5 times smaller still by calling the function again using the output of the first call.
As I mentioned, it is very simple to program conceptually, but I was hoping someone might be able to point out a function that could do this and would be less computationally intensive (since I hear that many built-in Igor functions are quite optimized). I've looked through the Igor documentation and wasn't able to find anything, but it's entirely possible I missed something.
Thanks in advance.