<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Dear Dennis Shea,<div class=""><span class="Apple-tab-span" style="white-space:pre">       </span>Thank you for your huge effect.</div><div class=""><span class="Apple-tab-span" style="white-space:pre">   </span>I agree with you, a minus sign does not affect the amplitude but affect the phase.</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>If I understand well, you gave me two reasons to explain the difference of the phases in the Bloomfield’s book and the NCL example.</div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>1) you show that the ‘atan2' or ‘atan’ functions may effect the phase plot. I do not agree with you. It can not be resolved the ‘jump’ in the phase plot.</div><div class=""><span class="Apple-tab-span" style="white-space:pre">       </span>2) you think that the different lowpass filters may be a reason. I do not agree with you too. I have used eight filter methods to carry out the complex demodulation. The results show that the filter method can slightly affect the amplitude and phase, but the filter method can not be used to explain the ‘jump’ in phase plot.</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">  </span>Anyway, there is no an obvious difference in amplitude plot between Bloomfield’s book and NCL example. My question still focus on the differences of phases using the complex demodulation between Bloomfield’s book and NCL example. How to explain the huge and obvious differences? In a word, How to deal with the obvious ‘jump’ in NCL example? The NCL code ‘demod_cmplx_nai’ can not deal with the ‘jump’ too.</div><span class=""> <br class=""></span><span class=""><span class="Apple-tab-span" style="white-space:pre">       </span>You implied that a 'fancy' with the phase plot in Bloomfield’s book? Do you know or guess what technique Bloomfield did to deal with "a non-pretty jump”? I agree that Bloomfield used a technique to show only 4 degrees difference from 358 degrees to 2 degrees, but the technique does not include in the two Fortran subroutines which you sent to me. Do you have any idea to reproduce the phase plot in Bloomfield’s book?<br class=""></span><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>All the best,</div><div class="">Frank</div><div class=""><br class=""></div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 15, 2017, at 9:56 PM, Dennis Shea <<a href="mailto:shea@ucar.edu" class="">shea@ucar.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">This is a rather long and, perhaps, confusing response. It was written episodically.<br class=""><br class="">---<br class="">re: <b class="">"same mistake" </b>   .... I am not sure to what you are referring. The use of a minus sign?<br class=""><br class=""></div><div class="">The minus sign does not affect the amplitudes because the quantities are squared:  amp = sqrt(x*x+y*y)<br class=""></div><div class="">It does affect the phase. Also, use of <b class="">atan2 </b>or <b class="">atan </b>to determine the phase are other issues to consider.<br class=""><b class=""><br class=""></b><a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/atan2.shtml" class="">https://www.ncl.ucar.edu/Document/Functions/Built-in/atan2.shtml</a><b class=""><br class=""></b><a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/atan.shtml" class="">https://www.ncl.ucar.edu/Document/Functions/Built-in/atan.shtml</a><b class=""><b class=""><br class=""></b></b></div><div class=""><br class=""></div>PMEL:   <a href="https://www.pmel.noaa.gov/maillists/tmap/ferret_users/fu_2007/pdfHMANlJLqCE.pdf" target="_blank" class="">https://www.pmel.noaa.gov/<wbr class="">maillists/tmap/ferret_users/<wbr class="">fu_2007/pdfHMANlJLqCE.pdf</a><br class=""></div>Kessler: <a href="https://faculty.washington.edu/kessler/generals/complex-demodulation.pdf" target="_blank" class="">https://faculty.washington.<wbr class="">edu/kessler/generals/complex-<wbr class="">demodulation.pdf</a><br class=""><br class=""></div><div class="">PMEL references the same source as NCL.<br class="">Reference: Bloomfield, P. (1976). Fourier Decomposition of Time Series, An Introduction. Wiley, New York, 258pp.</div><div class=""><br class="">===<br class=""></div>I have attached the (slightly updated) fortran subroutines from Bloomfield  but will include here also::<br class="">     <b class="">demod_bloom1976 </b>(page 148)  <br class="">     <b class="">polar_bloom1976</b> (page 150)<br class=""><br class=""> ---------------------------<br class="">      subroutine <b class="">demod_bloom1976</b>(x,n,omega,d1,<wbr class="">d2)<br class="">      implicit none<br class="">c<br class="">c Fourier Analysis of Time Series: An Introduction<br class="">c P. Bloomfield (1976: Wiley); <b class="">p148</b><br class="">c Minor code changes to make code more 'modern'<br class="">c<br class="">      integer n                        ! INPUT<br class="">      real    x(n), omega, d1(n), d2(n)<br class="">      integer i                        ! LOCAL<br class="">      real    arg<br class=""><br class="">      do i=1,n<br class="">         arg   = (i-1)*omega<br class=""><b class="">         d1(i) =  x(i)*cos(arg)*2<br class="">         d2(i) = -x(i)*sin(arg)*2</b><br class="">      end do<br class=""><br class="">      return<br class="">      end<br class="">c ---------------------------<br class="">      subroutine <b class="">polar_bloom1976</b>(x,y,n)<br class="">      implicit none<br class="">c<br class="">c Fourier Analysis of Time Series: An Introduction<br class="">c P. Bloomfield (1976: Wiley); <b class="">p150</b><br class="">c Minor code changes to make code more 'modern'<br class="">c<br class="">      integer n                        ! INPUT<br class="">      real    x(n), y(n)<br class="">      integer i                        ! LOCAL<br class="">      real    amp, phi<br class=""><br class="">      do i=1,n<br class=""><b class="">         amp = sqrt(x(i)*x(i)+y(i)*y(i))<br class="">         phi = atan2(y(i),x(i))        </b>! radians<br class="">         x(i)= amp<br class="">         y(i)= phi<br class="">      end do<br class=""><br class="">      return<br class="">      end<br class="">c ---------------------------<br class="">c Bloomfield CALL SEQUENCE <br class="">c<br class="">c omega  = (2*pi*nom)/np2<br class="">c cutoff = (pi*(npa+nst))/np2<br class="">c ns     = np2/(nst-npa)<br class="">c call demod_bloom1976 (x,n,omega,d1,d2) ! DEMODULATION<br class="">c call lopass_bloom1976(d1,cutoff,ns)<wbr class="">    ! SMOOTH COSINE TERM<br class="">c call lopass_bloom1976(d2,cutoff,ns)<wbr class="">    ! SMOOTH SINE TERM<br class="">c lim = n-2*ns<br class="">c call polar_bloom1976(d1,d2,lim)    <wbr class="">    ! AMPLITUDE & PHASES<br class="">==============================<wbr class="">=<br class=""></div><div class=""><b class="">Bloomfield's book uses a different low-pass filter than NCL (Lanczos) so results are not directly ('exactly') comparable.</b><br class="">==============================<wbr class="">=<br class=""></div><div class="">NCL's  (attached) <b class="">demod_cmplx</b> uses array notation (no 'do' loops):<br class=""><br class="">...<br class="">   yr  =  y*cos(ARG)*2             ; 'real' series<br class="">   yi  = <b class="">-</b>y*sin(ARG)*2              ; 'imaginary'   <br class="">...<br class="">   wgt    = filwgts_lanczos (nwt, ihp, frqcut, fcb, nsigma)  <br class=""><br class="">;---Apply filter weights to raw demodulated series (nwt/2 point 'lost; at start/end)<br class=""><br class="">   yr = wgt_runave_n_Wrap ( yr, wgt, 0, 0) <br class="">   yi = wgt_runave_n_Wrap ( yi, wgt, 0, 0) <br class="">  <br class="">;---Use the low pass filtered values; <b class="">atan2 </b>uses y/x => yi/yr<br class="">   <br class="">   amp  = sqrt(yr^2 + yi^2)<br class="">   pha  = where(amp.eq.zero, zero, <b class="">atan2</b>(yi, yr))    ; primary phase (radians)<br class=""><br class="">   pha2 = conform(pha, zero, -1)                     ; secondary phase (Bloomfield)<br class="">   pha2 = where(pha.ge.zero, pha-pi2, pha+pi2)   <br class=""><br class="">==============================<wbr class="">====<br class=""></div><div class="">You could take NCL's attached '<b class="">demod_cmplx</b>'; copy it to create your own function (say): <b class="">demod_cmplx_nai<br class=""><br class=""></b></div><div class="">and change what you want .... for example.... remove the minus sign<br class=""><br class="">   yr  =  y*cos(ARG)*2             ; 'real' series<br class="">   yi  =   y*sin(ARG)*2              ; 'imaginary'   </div><div class=""><b class=""></b></div><div class=""><b class=""><br class=""></b></div><div class="">Play with it.<br class=""><br class="">==============================<wbr class="">====<br class=""></div><div class="">I did not do anything 'fancy' with the phase plot. Hence, there can be 'jumps' . Think 358 degrees to 2 degrees. 'We' know it is only 4 degrees different but the plotting does not. Hence, a non-pretty jump in the plot.<br class=""><br class="">==============================<wbr class="">=====<br class=""></div><div class="">Archived National Institute of Standards fortran software.   <br class=""></div><div class=""><br class=""></div><div class=""><b class="">DEMODU.f</b>  (attached): Does the same thing as Bloomfield/NCL. <br class="">The use af AMPL and PHAS names is because this was part of a larger library that reused array space.<br class=""><br class=""></div><div class="">The following <br class=""></div><div class=""><br class=""><a href="http://www.itl.nist.gov/div898/software/datapac/DEMOD.f" target="_blank" class="">http://www.itl.nist.gov/<wbr class="">div898/software/datapac/DEMOD.<wbr class="">f</a><br class=""><br class=""></div><div class="">uses <br class=""><br class="">      Y1(I)=X(I)*COS(6.2831853*F*AI)<br class="">      Y2(I)=X(I)*SIN(6.2831853*F*AI)<br class=""><br class=""></div><div class="">but then for phases uses <b class="">atan </b>(not <b class="">atan2</b>)<b class=""><br class=""><br class=""></b>      Z(I)=<b class="">ATAN</b>(Y1(I)/Y2(I))<b class="">     </b>!  atan(yr/yi)<b class="">  ... ?</b>implicitly handles - sign?<br class=""><b class=""><br class=""></b></div><div class="">I am done.<br class=""><br class=""></div><div class="">Cheers <br class=""></div><div class="">D<b class=""><br class=""></b></div><div class=""><br class=""></div><div class=""><br class=""><br class=""><br class=""><div class=""><br class=""><div class=""><div class=""><br class=""><br class=""></div></div></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Dec 13, 2017 at 8:31 AM, Nai Suan <span dir="ltr" class=""><<a href="mailto:shif422@gmail.com" target="_blank" class="">shif422@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Dennis Shea,<br class="">
        I found a same mistake in two documents Kessler: U. Washington: Complex Demodulation and PMEL: Complex Demodulation. The first formula should be conected by a ‘plus’ sign not ’minus’ sign.<br class="">
        All the best,<br class="">
Feng<br class="">
<div class="HOEnZb"><div class="h5"><br class="">
<br class="">
<br class="">
> On Dec 13, 2017, at 10:02 AM, Nai Suan <<a href="mailto:shif422@gmail.com" class="">shif422@gmail.com</a>> wrote:<br class="">
><br class="">
> Dear Dennis Shea,<br class="">
>       Thank you for your reply.<br class="">
>       If I am right, the phases of the 1700-1960 sunspot numbers has a unique solution. This means Bloomfield’s 2000 (Second Edition) is wrong or the 1st complex demodulation example in NCL is wrong. I have no idea for another option.<br class="">
>       You mentioned NCL example was translated from Bloomfield’s subroutine. Is there any possible reason that the translation has some problems?<br class="">
>       Anyway, if you are interested, I can send Bloomfield’s 2000 book to you.<br class="">
>       All the best,<br class="">
> Frank<br class="">
><br class="">
><br class="">
>> On Dec 13, 2017, at 12:15 AM, Dennis Shea <<a href="mailto:shea@ucar.edu" class="">shea@ucar.edu</a>> wrote:<br class="">
>><br class="">
>> If the low-pass filtering (Lanczos) and smoothing (weighted running average) don't explain the differences... I do not know.<br class="">
>> I do not have Bloomfield's 1976 book readily available. That used the 1700-1960 sunspot numbers. As I recall, NCL's plots were 'identical' to those in the 1976 book.<br class="">
>> ----<br class="">
>> <a href="http://www.ncl.ucar.edu/Applications/spec.shtml" rel="noreferrer" target="_blank" class="">http://www.ncl.ucar.edu/<wbr class="">Applications/spec.shtml</a><br class="">
>><br class="">
>> Data Analysis: Spectral analysis, Complex Demodulation<br class="">
>><br class="">
>> The 1st complex demodulation example uses the 1700-1960 sunspots<br class="">
>> <a href="http://www.ncl.ucar.edu/Applications/Scripts/demod_cmplx_1.ncl" rel="noreferrer" target="_blank" class="">http://www.ncl.ucar.edu/<wbr class="">Applications/Scripts/demod_<wbr class="">cmplx_1.ncl</a><br class="">
>> ----<br class="">
>><br class="">
>> The 'demod_cmplx' function can be seen at:<br class="">
>><br class="">
>> %> less  $NCARG_ROOT/lib/ncarg/<wbr class="">nclscripts/csm/contributed.ncl<br class="">
>><br class="">
>> Basically, it is a translation (fortran-77  ===> NCL) of Bloomfield's 1976 f77 subroutine.<br class="">
>><br class="">
>><br class="">
>><br class="">
>><br class="">
>><br class="">
>><br class="">
>> On Tue, Dec 12, 2017 at 4:03 AM, Nai Suan <<a href="mailto:shif422@gmail.com" class="">shif422@gmail.com</a>> wrote:<br class="">
>> Dear colleague,<br class="">
>>         I have a question about how to explain the phase of the complex demodulation. I found that the phases of the sunspot in the figures 7.9 and 7.11 (see the attachment) in Bloomfield (2000)’s book (chapter 7 complex demodulation) were totally different with the ‘demod_cmplx_1_lg.png (see the attachment)’. Which is right? I believe the original sunspots in two examples are same and the different low-pass filter methods can not be used to explain this difference. How to explain the difference?<br class="">
>>         Hope to hear your answer.<br class="">
>>         All the best,<br class="">
>> Frank<br class="">
>><br class="">
>><br class="">
>><br class="">
>> ><br class="">
>> ><br class="">
>> ><br class="">
>> ><br class="">
>> ><br class="">
>><br class="">
>><br class="">
>> ______________________________<wbr class="">_________________<br class="">
>> ncl-talk mailing list<br class="">
>> <a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">
>> List instructions, subscriber options, unsubscribe:<br class="">
>> <a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank" class="">http://mailman.ucar.edu/<wbr class="">mailman/listinfo/ncl-talk</a><br class="">
><br class="">
<br class="">
</div></div></blockquote></div><br class=""></div>
<span id="cid:25584A0B-9B9E-4553-BC2D-AA45205F78F3"><demod_cmplx.ncl></span><span id="cid:CDA107A8-D82B-4519-B488-5B10B5ACBE86"><demod_bloomfield_1976.f></span><span id="cid:35F73114-E288-439B-816C-1408F77267E4"><DEMODU_nist.f></span></div></blockquote></div><br class=""></div></body></html>