Adding waves with different scaling.
daggaz
I have three waves each with their own x scaling. I can graph them easily enough on the same graph and IGOR places them properly with their respective offsets to eachother.
When I try adding them, I can see that it is just doing point for point addition, rather than adding according to the destination wave x scaling so that only the overlaps add. Here is what I tried:
Make/o/d/n=2000 wave_sum
setscale/i x,0,1100, wave_sum
wave_sum = wave_1 + wave_2 + wave_3 //each of which has their own x-scaling and in this case, each contains 200 points.
What am I doing wrong?
It is these types of problems that lead me to avoid wave scaling. Instead, I focus on recording an x-wave for each data set, ensuring it's the same for each. Of course this can't be done if you aren't the one collecting the data.
December 4, 2012 at 05:18 am - Permalink
Its a shame that the wave arithmetic functions cant duplicate what the graphing functions so easily achieve. I thought maybe it would just calculate (linearily between points) matching values for the new scaling, and go from there..
December 4, 2012 at 05:26 am - Permalink
wave_sum = wave_1 + wave_2 + wave_3
where by default point-by-point arithmetic is used (i.e. by the point index
p
), you should explicitly writewave_sum = wave_1(x) + wave_2(x) + wave_3(x)
where the appropriate scaling of the waves is used.
Hope this helps,
Gregor
December 4, 2012 at 06:06 am - Permalink
To learn more about this, execute
DisplayHelpTopic "Indexing and Subranges"
.gregorK is right but there is one caveat: if the requested x value falls outside the x-range of the wave, then Igor will not extrapolate but will instead return the closest valid value. From the help: "If, in specifying a subrange, you use an X value that is out of range, Igor clips it to the closest valid X value." This is something to keep in mind when performing this type of assignments.
December 4, 2012 at 06:51 am - Permalink
December 4, 2012 at 07:09 am - Permalink
December 4, 2012 at 07:30 am - Permalink
So you get something like a section with your data, then a constant flat line on either end equal to the end points? Which gets added to the other functions? I suppose you could do something like wave_1(first_x,last_x) ?
December 4, 2012 at 07:34 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
December 4, 2012 at 09:09 am - Permalink
Yes.
•Print hello(55.3)
55.3
•Print hello(130)
127
•Print hello(10000)
127
•Print hello(1e6)
127
•Print hello(-2)
0
•Print hello(-100)
0
You have to be careful with these types of wave assignments because it is easy to ask for points for which Igor has no data. For example, if wave_sum covers a broader range than wave_1 then you are asking for non-existent data. So what you want to do is
Oh, and if you use
#pragma rtGlobals=3
then an out-of-bounds access will result in an error. I recommend using it.December 4, 2012 at 11:52 pm - Permalink
Yes.
•Print hello(55.3)
55.3
•Print hello(130)
127
•Print hello(10000)
127
•Print hello(1e6)
127
•Print hello(-2)
0
•Print hello(-100)
0
You have to be careful with these types of wave assignments because it is easy to ask for points for which Igor has no data. For example, if wave_sum covers a broader range than wave_1 then you are asking for non-existent data. So what you want to do is
Oh, and if you use
#pragma rtGlobals=3
then an out-of-bounds access will result in an error. I try to use this systematically, but be sure to read the documentation on it first.December 4, 2012 at 11:52 pm - Permalink