Adding waves with different scaling.

I thought I had this figured out, but no.

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?
Wave operations are always done on a point-by-point basis. You could use one wave as a reference and interpret values y1 and y2 from the other two waves at the same x-value to be added to the first wave. This method restricts you to regions where all three waves have data. (you can't interpret a value for wave 2 at x=3 if it goes from x=100 to 1500).

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.
Thanks, I was afraid of that. I have also tended to stick to the point system for most of my work, but I figured maybe there was a good reason for the xscaling and I ought to get around to learning it.

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..
Instead of using

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 write

wave_sum = wave_1(x) + wave_2(x) + wave_3(x)

where the appropriate scaling of the waves is used.

Hope this helps,
Gregor
gregorK wrote:
you should explicitly write wave_sum = wave_1(x) + wave_2(x) + wave_3(x) where the appropriate scaling of the waves is used.


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.
That's good to know. I was unaware of using wave1(x). Learn something new everyday.
There it is. I was luckily bothering around with function generated waves, so I just did it manually by copypasting the function in three times and changing all of the parameters to fit. Will have to play around with this quick n easy solution tho, thanks.
741][quote=gregorK wrote:
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.


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) ?
And if you don't mind pointing and clicking, you can use the Wave Arithmetic package (Analysis->Packages->Wave Arithmetic). It is based on a graph of the data and uses graph cursors to identify the graph traces to work on. It handles traces that represent XY pairs, waveforms (traces that get the X values from wave scaling), and working on just the common subset in X values. Underneath the hood, there are quite a few uses of () insteand of []. There's a demo, too: File->Example Experiments->Analysis->Wave Arithmetic Panel Demo.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
daggaz wrote:
So you get something like a section with your data, then a constant flat line on either end equal to the end points?


Yes.

Make /N=128 /D hello = x
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
johnweeks wrote:
working on just the common subset in X values


Oh, and if you use #pragma rtGlobals=3 then an out-of-bounds access will result in an error. I recommend using it.
741][quote=daggaz wrote:
So you get something like a section with your data, then a constant flat line on either end equal to the end points?


Yes.

Make /N=128 /D hello = x
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
johnweeks wrote:
working on just the common subset in X values


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.