Re: Better way to create multiple samples of process?
- From: PB <pbodin@xxxxxxxxxxxxxxxxxxx>
- Date: Sat, 27 Aug 2005 04:23:08 -0400
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
.
- Follow-Ups:
- Re: Better way to create multiple samples of process?
- From: matlab beginner
- Re: Better way to create multiple samples of process?
- References:
- Better way to create multiple samples of process?
- From: matlab beginner
- Better way to create multiple samples of process?
- Prev by Date: Re: Better way to create multiple samples of process?
- Next by Date: Re: Better way to create multiple samples of process?
- Previous by thread: Re: Better way to create multiple samples of process?
- Next by thread: Re: Better way to create multiple samples of process?
- Index(es):
Relevant Pages
|