help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help to vectorize THIS loop


From: Ben Abbott
Subject: Re: Help to vectorize THIS loop
Date: Wed, 02 Oct 2013 20:46:02 -0400

On Oct 2, 2013, at 7:54 PM, Macy wrote:

> 
> --- address@hidden wrote:
> 
> From: Ben Abbott <address@hidden>
> To: Macy <address@hidden>
> Cc: address@hidden
> Subject: Re: Help to vectorize THIS loop
> Date: Wed, 02 Oct 2013 19:38:14 -0400
> 
> 
>> On Sep 25, 2013, at 12:21 PM, Macy wrote:
>> 
>>> Anybody have any comments on this one?
>>> 
>>> Compare these two, which seems like they should yield similar results:
>>> [watch for wrap]
>>> 
>>> CLOCKJITTERCOMPARE.m
>>> %  these values are 'kind of' like what is being used
>>> SP=20e3;
>>> SR=200e6;
>>> t=([1:SP]-1)/SR;
>>> sig=.99*cos(2*pi()*t*20e6);
>>> clkjtr=200e-15;
>>> 
>>> % actual code
>>> dtn=clkjtr*randn(1,SP);
>>> tb=t+dtn;
>>> 
>>> sigcn1=sig;
>>> for i=2:(SP-1)
>>> if (tb(i)<t(i))
>>>   sigcn1(i)=sig(i)-SR*(sig(i)-sig(i-1))*(t(i)-tb(i));
>>> else
>>>   sigcn1(i)=sig(i)+SR*(sig(i+1)-sig(i))*(tb(i)-t(i));
>>> endif
>>> endfor
>>> %  end points, note t(1) == 0
>>> sigcn1(1)=sig(1)+SR*(sig(2)-sig(1))*tb(1);
>>> %  
>>> sigcn1(end)=sig(end)+SR*(sig(end)-sig(end-1))*(tb(end)-t(end));
>>> 
>>> %  save original value
>>> dtno=dtn;
>>> dtn=SR*dtno;
>>> %
>>> 
>>> sigcn2=sig;
>>> idxp=dtn>0;idxp(1)=0;idxp(end)=0;
>>> idxn=dtn<0;idxn(1)=0;idxn(end)=0;
>>> 
>>> dsigup=[0,diff(sig(2:end)),0];
>>> dsigdn=[0,diff(sig)];
>>> sigcn2=sig+(dsigup.*idxp+dsigdn.*idxn).*dtn;
>>> sigcn2(1)=sig(1)+(sig(2)-sig(1))*dtn(1);
>>> sigcn2(end)=sig(end)+(sig(end)-sig(end-1))*dtn(end);
>>> 
>>> %  restore original value
>>> dtn=dtno;
>>> 
>>> plot(sigcn2-sigcn1);
>>> % shouldn't this be a 'zero' line?
>> 
>> I'm not sure you'll get much help tracking down numeric noise.
>> 
>> Ben
> 

> Ben, 
> 
> Thank you for finding this posting!
> 
> I only wanted to check whether I was still in 16, 32, or 64 bit mode on the 
> installation.  Thought if someone tried it out and found 'almost no 
> difference' I should look at doing some type of upgrades here. Else, if they 
> have about the same effects I do on this antiquated system, I'd leave well 
> enough alone.
> 
> Did you try, get a set of 'steps'?

Yes. I get the steps.  They are due to numeric round-off.  For example a 
similar effect can be seen in the plot below.

        SR=200e6;
        t=([1:SP]-1)/SR;
        clkjtr=200e-15;
        dtn=clkjtr*randn(1,SP);
        plot (((t+dtn)-t)-dtn)

Ben




reply via email to

[Prev in Thread] Current Thread [Next in Thread]