Re: Better way to create multiple samples of process?



matlab beginner wrote:
>
>
> Hi,
>
> I want to create n=100 samples of the following process:
>
> v(n) = 0.5v(n-1) + g(n)
>
> where v(n) is a noise process correlated with g(n)=unit
> variance white noise.
>
> I came up with the following code:
>
> v = randn(101,1); %create noise process with 101 samples
> g = randn(101,1); %create noise process with 101 samples
>
> for n=2:101 %create 100 samples of v(n)
> v(n) = ( 0.5 * v(n-1) ) + g(n);
> n = n+1;
> end
>
> Is there a better way to do this?

Hi!

There is no need to update the iterator-variable:
v = randn(101,1); %create noise process with 101 samples
g = randn(101,1); %create noise process with 101 samples
v1=zeros(size(v1));
for n=2:101 %create 100 samples of v(n)
v1(n) = ( 0.5 * v(n-1) ) + g(n);
% n = n+1;
% You never need to do this and it has no effect on
% the iteration.
end
v1=v1(2:end);

Bin Shi answered the question on how to do this in a better way in
your last post with the same question. Use filter:

v2=filter([0 0.5],1,v)+g;
v2=v2(2:end);
isequal(v1,v2)

HTH

PB
.



Relevant Pages

  • Re: Richardson-Lucy deconvolution ?
    ... is to use the recorded image as the initial guess. ... the initial estimate also has noise. ... deconvolution is ill-conditioned and thus noise grows with iteration. ... Journal of the Optical Society of America-A, ...
    (sci.image.processing)
  • Re: Defect detection
    ... To filter out that noise I use a rational smoothing filter (that try ... their Xt values (at iteration t) would be ...
    (sci.image.processing)
  • Re: Defect detection
    ... To filter out that noise I use a rational smoothing filter (that try ... their Xt values (at iteration t) would be ...
    (sci.image.processing)
  • Re: Thumb Frustration
    ... Time to make some noise, ... Eimear ... Prev by Date: ...
    (rec.crafts.textiles.yarn)
  • Re: Siteswap Regular expression revisited
    ... validation stage. ... reduce a lot of noise. ... I'll comment more on the regex later when I've got time to sit down and ... Prev by Date: ...
    (rec.juggling)