Complex Wave Division
geologic
function wavedivider2()
wave wave1, wave2
make/o/c/n=(numpnts(wave1)) lp
make/o/c/n=(numpnts(wave1)) sp
make/o/c/n=(numpnts(wave1)) tr
make/o/c/n=(numpnts(wave1)) cc
lp = r2polar(wave1)
sp = r2polar(wave2)
tr = cmplx(real(lp)/real(sp) * cos(imag(lp)-imag(sp)),real(lp)/real(sp) * sin(imag(lp)-imag(sp)))
cc = 1 + tr
end
wave wave1, wave2
make/o/c/n=(numpnts(wave1)) lp
make/o/c/n=(numpnts(wave1)) sp
make/o/c/n=(numpnts(wave1)) tr
make/o/c/n=(numpnts(wave1)) cc
lp = r2polar(wave1)
sp = r2polar(wave2)
tr = cmplx(real(lp)/real(sp) * cos(imag(lp)-imag(sp)),real(lp)/real(sp) * sin(imag(lp)-imag(sp)))
cc = 1 + tr
end
wave1 and wave2 are complex waves already in the directory when I run this. I make 4 complex waves for future use. With lp and sp, I convert the rectangular coordinates to polar so that lp should be a complex wave with (magnitude, phase) as the (real, imag) parts.
I'm confused here why I can't set a wave equal to real(lp). Actually what I want to do is divide lp by sp. Ideally, I would just say tr = lp / sp. What is the best way to do this? I know it's likely a little more complicated since the phase is in the imaginary part of the result of r2polar, so it should be exponentiated to recover the complex number. I've defined the real and imaginary parts of tr explicitly, but this introduces the clunky necessity of including the magnitude of the ratio of the real parts into both the real and imaginary part of tr.
The last step is just to check that I can perform arithmetic on the tr wave.
wave wave1, wave2
make/o/c/n=(numpnts(wave1)) lp
lp = wave1 / wave2
end
So this seems like the right way...Was there a better way to do it in polar coordinates?
I still couldn't do lp = real(wave1). Why is that?
September 2, 2014 at 12:06 pm - Permalink
Taking the /c flag out of the make command allows me to write lp = real(wave1).
September 2, 2014 at 12:12 pm - Permalink
wave/C wave1, wave2
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
September 3, 2014 at 09:18 am - Permalink
September 3, 2014 at 10:57 am - Permalink