Thread Subject: randn usage error

Subject: randn usage error

From: Vijayalayan T.R.

Date: 4 Nov, 2009 14:32:03

Message: 1 of 7

Hello all,

This is my first post so if its in an inappropriate section, my apologies.
 So this is the situation, I'm working on my postgrad project which involves locating a cell phone and I use Time Difference of Arrival with wavelet denoising filtering. I came across someone else's work which is similar to mine but in a diff technology. So I took up to study his code to get an idea of what I'm supposed to do.

In this test program.
this line is not working

randn('state', 2*(i+j));
        noi1_real=sqrt(pow/(2*oran))*randn(1,1024);

And the error is
??? Error using ==> randn
State must be a double scalar or the output of RANDN('state').

Error in ==> tez5 at 36
        randn('state', t);

Can anyone throw some light on what I'm supposed to do.

Thanks in advance

Cheers
Vi

Subject: randn usage error

From: Wayne King

Date: 4 Nov, 2009 14:42:03

Message: 2 of 7

"Vijayalayan T.R." <xcitingindian@yahoo.com> wrote in message <hcs392$4ve$1@fred.mathworks.com>...
> Hello all,
>
> This is my first post so if its in an inappropriate section, my apologies.
> So this is the situation, I'm working on my postgrad project which involves locating a cell phone and I use Time Difference of Arrival with wavelet denoising filtering. I came across someone else's work which is similar to mine but in a diff technology. So I took up to study his code to get an idea of what I'm supposed to do.
>
> In this test program.
> this line is not working
>
> randn('state', 2*(i+j));
> noi1_real=sqrt(pow/(2*oran))*randn(1,1024);
>
> And the error is
> ??? Error using ==> randn
> State must be a double scalar or the output of RANDN('state').
>
> Error in ==> tez5 at 36
> randn('state', t);
>
> Can anyone throw some light on what I'm supposed to do.
>
> Thanks in advance
>
> Cheers
> Vi

Hi, what are i and j equal to? If you don't assign these in your code, then by default they will be the complex number 0 + 1.0000i and you will get the above error.
Wayne

Subject: randn usage error

From: Peter Perkins

Date: 4 Nov, 2009 16:04:10

Message: 3 of 7

Vijayalayan T.R. wrote:

> randn('state', 2*(i+j));

> And the error is
> ??? Error using ==> randn
> State must be a double scalar or the output of RANDN('state').

As Wayne said, if i and j may be referring to complex values. But even if you fix that, there may be a bigger issue. If your intention is that i and j are loop counters, you almost certainly do _not_ want to be reseeding the generator every time though the loop(s). The only reason for wanting to do that is to ensure a certain kind of reproducability -- so that you can reproduce the results of any given iteration without going through the whole loop.

Take to heart this note in the (current version of the) help:

    Resetting the default stream to the same fixed state allows computations
    to be repeated. Setting the stream to different states leads to unique
    computations, however, it does not improve any statistical properties.

Subject: randn usage error

From: Vijayalayan

Date: 13 Dec, 2009 01:35:07

Message: 4 of 7

"Wayne King" <wmkingty@gmail.com> wrote in message <hcs3rr$bph$1@fred.mathworks.com>...
> "Vijayalayan T.R." <xcitingindian@yahoo.com> wrote in message <hcs392$4ve$1@fred.mathworks.com>...
> > Hello all,
> >
> > This is my first post so if its in an inappropriate section, my apologies.
> > So this is the situation, I'm working on my postgrad project which involves locating a cell phone and I use Time Difference of Arrival with wavelet denoising filtering. I came across someone else's work which is similar to mine but in a diff technology. So I took up to study his code to get an idea of what I'm supposed to do.
> >
> > In this test program.
> > this line is not working
> >
> > randn('state', 2*(i+j));
> > noi1_real=sqrt(pow/(2*oran))*randn(1,1024);
> >
> > And the error is
> > ??? Error using ==> randn
> > State must be a double scalar or the output of RANDN('state').
> >
> > Error in ==> tez5 at 36
> > randn('state', t);
> >
> > Can anyone throw some light on what I'm supposed to do.
> >
> > Thanks in advance
> >
> > Cheers
> > Vi
>
> Hi, what are i and j equal to? If you don't assign these in your code, then by default they will be the complex number 0 + 1.0000i and you will get the above error.
> Wayne

Hello Wayne,
Sorry for the delayed reply. As I told you, I'm trying to understand the code and I'm totally new to Matlab. I'm not sure about the i and j part. Sorry to sound dumb. I just don't have any Matlab experience. The code on reading makes some sense as in what the author is trying to do but thats about it.

 I have put the code here for your viewing.

clear all
gsm_set;
data=data_gen(INIT_L);


%this creates a binary data
[tx_burst,I,Q]=gsm_mod(Tb,OSR,BT,data,TRAINING);
 
s=I+j*Q;
 sl=length(s);
 pow=(1/sl)*sum(abs(s).^2);
 
 K=200 %Number of realizations
rand('seed',40);
 f=150*rand(1,K);
delay=floor(f);
delay(1:K/2)=-delay(1:K/2); %Delay is between 150 to +150
 n=[5 4 3 2 1 0 -1 -2 -3 -4 -5 -6];
 SNR=10.^(n./10);

 for k=1:length(SNR)
   oran=SNR(k)
    for i=1:K
        x=[zeros(1,200) s zeros(1,224)];
        y=[zeros(1,200+delay(i)) s zeros(1,224-delay(i))];
        
        t = 2*(i+j);
        randn('state', t);
        noi1_real=sqrt(pow/(2*oran))*randn(1,1024);
        
        randn('state',3*(i+j));
        noi1_imag=sqrt(pow/(2*oran))*randn(1,1024);
        
        randn('state',4*(i+j));
        noi2_real=sqrt(pow/(2*oran))*randn(1,1024);
        
        randn('state',5*(i+j));
        noi2_imag=sqrt(pow/(2*oran))*randn(1,1024);
        
        noi1=noi1_real+j*noi1_imag;
        noi2=noi2_real+j*noi2_imag;
        
        xn=x+noi1; %adding noise to x
        yn=y+noi2; %adding noise to y

Subject: randn usage error

From: Vijayalayan

Date: 13 Dec, 2009 01:35:07

Message: 5 of 7

"Wayne King" <wmkingty@gmail.com> wrote in message <hcs3rr$bph$1@fred.mathworks.com>...
> "Vijayalayan T.R." <xcitingindian@yahoo.com> wrote in message <hcs392$4ve$1@fred.mathworks.com>...
> > Hello all,
> >
> > This is my first post so if its in an inappropriate section, my apologies.
> > So this is the situation, I'm working on my postgrad project which involves locating a cell phone and I use Time Difference of Arrival with wavelet denoising filtering. I came across someone else's work which is similar to mine but in a diff technology. So I took up to study his code to get an idea of what I'm supposed to do.
> >
> > In this test program.
> > this line is not working
> >
> > randn('state', 2*(i+j));
> > noi1_real=sqrt(pow/(2*oran))*randn(1,1024);
> >
> > And the error is
> > ??? Error using ==> randn
> > State must be a double scalar or the output of RANDN('state').
> >
> > Error in ==> tez5 at 36
> > randn('state', t);
> >
> > Can anyone throw some light on what I'm supposed to do.
> >
> > Thanks in advance
> >
> > Cheers
> > Vi
>
> Hi, what are i and j equal to? If you don't assign these in your code, then by default they will be the complex number 0 + 1.0000i and you will get the above error.
> Wayne

Hello Wayne,
Sorry for the delayed reply. As I told you, I'm trying to understand the code and I'm totally new to Matlab. I'm not sure about the i and j part. Sorry to sound dumb. I just don't have any Matlab experience. The code on reading makes some sense as in what the author is trying to do but thats about it.

 I have put the code here for your viewing.

clear all
gsm_set;
data=data_gen(INIT_L);


%this creates a binary data
[tx_burst,I,Q]=gsm_mod(Tb,OSR,BT,data,TRAINING);
 
s=I+j*Q;
 sl=length(s);
 pow=(1/sl)*sum(abs(s).^2);
 
 K=200 %Number of realizations
rand('seed',40);
 f=150*rand(1,K);
delay=floor(f);
delay(1:K/2)=-delay(1:K/2); %Delay is between 150 to +150
 n=[5 4 3 2 1 0 -1 -2 -3 -4 -5 -6];
 SNR=10.^(n./10);

 for k=1:length(SNR)
   oran=SNR(k)
    for i=1:K
        x=[zeros(1,200) s zeros(1,224)];
        y=[zeros(1,200+delay(i)) s zeros(1,224-delay(i))];
        
        t = 2*(i+j);
        randn('state', t);
        noi1_real=sqrt(pow/(2*oran))*randn(1,1024);
        
        randn('state',3*(i+j));
        noi1_imag=sqrt(pow/(2*oran))*randn(1,1024);
        
        randn('state',4*(i+j));
        noi2_real=sqrt(pow/(2*oran))*randn(1,1024);
        
        randn('state',5*(i+j));
        noi2_imag=sqrt(pow/(2*oran))*randn(1,1024);
        
        noi1=noi1_real+j*noi1_imag;
        noi2=noi2_real+j*noi2_imag;
        
        xn=x+noi1; %adding noise to x
        yn=y+noi2; %adding noise to y

Subject: randn usage error

From: Greg Heath

Date: 13 Dec, 2009 08:23:59

Message: 6 of 7

On Dec 12, 8:35 pm, "Vijayalayan " <xcitingind...@yahoo.com> wrote:
> "Wayne King" <wmkin...@gmail.com> wrote in message <hcs3rr$bp...@fred.mathworks.com>...
> > "Vijayalayan T.R." <xcitingind...@yahoo.com> wrote in message <hcs392$4v...@fred.mathworks.com>...
> > > Hello all,
>
> > > This is my first post so if its in an inappropriate section, my apologies.
> > >  So this is the situation, I'm working on my postgrad project which involves locating a cell phone and I use Time Difference of Arrival with wavelet denoising filtering. I came across someone else's work which is similar to mine but in a diff technology. So I took up to study his code to get an idea of what I'm supposed to do.
>
> > > In this test program.
> > > this line is not working
>
> > > randn('state', 2*(i+j));
> > >         noi1_real=sqrt(pow/(2*oran))*randn(1,1024);
>
> > > And the error is
> > > ??? Error using ==> randn
> > > State must be a double scalar or the output of RANDN('state').
>
> > > Error in ==> tez5 at 36
> > >         randn('state', t);
>
> > > Can anyone throw some light on what I'm supposed to do.
>
> > > Thanks in advance
>
> > > Cheers
> > > Vi
>
> > Hi, what are i and j equal to? If you don't assign these in your code, then by default they will be the complex number 0 + 1.0000i and you will get the above error.
> > Wayne
>
> Hello Wayne,
> Sorry for the delayed reply.  As I told you, I'm trying to understand the code and I'm totally new to Matlab. I'm not sure about the i and j part. Sorry to sound dumb. I just don't have any Matlab experience. The code on reading makes some sense as in what the author is trying to do but thats about it.
>
>  I have put the code here for your viewing.
>
> clear all
> gsm_set;
> data=data_gen(INIT_L);
>
> %this creates a binary data
> [tx_burst,I,Q]=gsm_mod(Tb,OSR,BT,data,TRAINING);
>
> s=I+j*Q;

j is never defined.Therefore, by default, MATLAB assumes
j = sqrt(-1)

____SNIP

>  for k=1:length(SNR)
>    oran=SNR(k)
>     for i=1:K
>         x=[zeros(1,200) s zeros(1,224)];
>         y=[zeros(1,200+delay(i)) s zeros(1,224-delay(i))];
>
>         t = 2*(i+j);
>         randn('state', t);

1. t cannot be complex.
2. If this was a typo and it was meant to be t = 2*(i+k) then it
would work. However, it would not be correct. Only
random numbers generated from a single state will have
the desired statistical distribution. The most logical place
for the state initialization is before the loop, not within it.

Hope this helps.

Greg

Subject: randn usage error

From: Vijayalayan

Date: 14 Dec, 2009 00:55:10

Message: 7 of 7

Greg Heath <heath@alumni.brown.edu> wrote in message <3578f777-80b3-48ec-a74e-990e1d62a8b9@v25g2000yqk.googlegroups.com>...
> On Dec 12, 8:35?pm, "Vijayalayan " <xcitingind...@yahoo.com> wrote:
> > "Wayne King" <wmkin...@gmail.com> wrote in message <hcs3rr$bp...@fred.mathworks.com>...
> > > "Vijayalayan T.R." <xcitingind...@yahoo.com> wrote in message <hcs392$4v...@fred.mathworks.com>...
> > > > Hello all,
> >
> > > > This is my first post so if its in an inappropriate section, my apologies.
> > > > ?So this is the situation, I'm working on my postgrad project which involves locating a cell phone and I use Time Difference of Arrival with wavelet denoising filtering. I came across someone else's work which is similar to mine but in a diff technology. So I took up to study his code to get an idea of what I'm supposed to do.
> >
> > > > In this test program.
> > > > this line is not working
> >
> > > > randn('state', 2*(i+j));
> > > > ? ? ? ? noi1_real=sqrt(pow/(2*oran))*randn(1,1024);
> >
> > > > And the error is
> > > > ??? Error using ==> randn
> > > > State must be a double scalar or the output of RANDN('state').
> >
> > > > Error in ==> tez5 at 36
> > > > ? ? ? ? randn('state', t);
> >
> > > > Can anyone throw some light on what I'm supposed to do.
> >
> > > > Thanks in advance
> >
> > > > Cheers
> > > > Vi
> >
> > > Hi, what are i and j equal to? If you don't assign these in your code, then by default they will be the complex number 0 + 1.0000i and you will get the above error.
> > > Wayne
> >
> > Hello Wayne,
> > Sorry for the delayed reply. ?As I told you, I'm trying to understand the code and I'm totally new to Matlab. I'm not sure about the i and j part. Sorry to sound dumb. I just don't have any Matlab experience. The code on reading makes some sense as in what the author is trying to do but thats about it.
> >
> > ?I have put the code here for your viewing.
> >
> > clear all
> > gsm_set;
> > data=data_gen(INIT_L);
> >
> > %this creates a binary data
> > [tx_burst,I,Q]=gsm_mod(Tb,OSR,BT,data,TRAINING);
> >
> > s=I+j*Q;
>
> j is never defined.Therefore, by default, MATLAB assumes
> j = sqrt(-1)
>
> ____SNIP
>
> > ?for k=1:length(SNR)
> > ? ?oran=SNR(k)
> > ? ? for i=1:K
> > ? ? ? ? x=[zeros(1,200) s zeros(1,224)];
> > ? ? ? ? y=[zeros(1,200+delay(i)) s zeros(1,224-delay(i))];
> >
> > ? ? ? ? t = 2*(i+j);
> > ? ? ? ? randn('state', t);
>
> 1. t cannot be complex.
> 2. If this was a typo and it was meant to be t = 2*(i+k) then it
> would work. However, it would not be correct. Only
> random numbers generated from a single state will have
> the desired statistical distribution. The most logical place
> for the state initialization is before the loop, not within it.
>
> Hope this helps.
>
> Greg

Hey Greg,

The t bit was tried by me as an debugging attempt. As you can see below, the coder has tried 2*(i+j) and then 3*(i+j) , 4*(i+j) and 5*(i+j). So I doubt it being a typo for 4times. As far as I can understand, the code is used to create real and imaginary parts of noi1 and no2 (noises 1 & 2). Then noi1 is added to x to create xn(assume x with noise) and noi2 is added to y to create yn. but I don't the way it has been implemented and hence the error.

 t = 2*(i+j);
        randn('state', t);
        noi1_real=sqrt(pow/(2*oran))*randn(1,1024);
        
        randn('state',3*(i+j));
        noi1_imag=sqrt(pow/(2*oran))*randn(1,1024);
        
        randn('state',4*(i+j));
        noi2_real=sqrt(pow/(2*oran))*randn(1,1024);
        
        randn('state',5*(i+j));
        noi2_imag=sqrt(pow/(2*oran))*randn(1,1024);

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
state Vijayalayan T.R. 4 Nov, 2009 09:34:14
matlab Vijayalayan T.R. 4 Nov, 2009 09:34:14
randn Vijayalayan T.R. 4 Nov, 2009 09:34:13
rssFeed for this Thread

Contact us at files@mathworks.com