[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Help to vectorize THIS loop
From: |
Macy |
Subject: |
Help to vectorize THIS loop |
Date: |
Sun, 22 Sep 2013 20:32:00 -0700 |
I've got a large file of uniformly sampled time waveform, called sig.
I'd like to 'add' a small amount of aperture clock jitter to the data, call
that sigwn. How to vectorize instead of doing with a loop?
The rms aperture jitter is less than 1/10,000 of the sample time, so I assumed
I could easily use linear interpolation and 'slightly' adjust the magnitude of
each data point. without distorting the effect too much, right?
The loop checks each data point and if the clock is faster, adds a little bit
based upon the next data point, or if slower, adds a little bit based upon the
previous data point. only changing slightly to reflect the linear slope to that
value.
Let SR = sample per second
clkjtr = clock jitter rms in seconds
So I took the time as
t=[1:hugenumber];
then added noise to the time window
tn=t+clkjtr*randn(1,hugenumber);
end points are a unique case so I can do those separately.
sigwn=sig;
for i=2:hugenumber-1
if ( tn(i)<t(i) )
sigwn(i)=sig(i)-( sig(i)-sig(i-1) )*SR*( t(i)-tn)i) );
else
sigwn(i)=sig(i)+( sig(i+1)-sig(i) )*SR*( tn(i)-t)i) );
endif
endfor
any slick ways to vectorize this?
like don't create tn, but rather create
dtn=clkjtr*randn(1,hugenumber);
then make two lines, checking for 'sign' condition?
sigwn=sig;
sigwn(dtn<0)=sig(dtn<0)+ ??;
sigwn(dtn>0)=sig(dtn>0)+ ??;
except of course the END POINTS.
where I can only use 2:end-1 for these two lines.
arrrgggg!
I don't see how to avoid the end point problem WITHOUT creating more huge sized
variables, which may be ok.
- Help to vectorize THIS loop,
Macy <=