Saving values after each iteration

  • Thread starter Thread starter gryphon1221
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 3K views
gryphon1221
Messages
9
Reaction score
0
Hello, I am taking a class on GPS navigation. Our homework is to construct a signal based on 10 initial condition values and use modelo-2 arithmetic to get each subsequent value. I have gotten this to work. However, I am only able to see the final 10 values the way I have it set up. I am trying to find a way to store each "k" value before the next iteration begins so that I will have a vector of all the values. I have it set up for 32 iterations, but eventually need about 7000 so an automatic process is necessary. Here is my code:

[k10]=input('Enter the value of intial k-10: ');
[k9]=input('Enter the value of initial k-9: ');
[k8]=input('Enter the value of initial k-8: ');
[k7]=input('Enter the value of initial k-7: ');
[k6]=input('Enter the value of initial k-6: ');
[k5]=input('Enter the value of initial k-5: ');
[k4]=input('Enter the value of initial k-4: ');
[k3]=input('Enter the value of initial k-3: ');
[k2]=input('Enter the value of initial k-2: ');
[k1]=input('Enter the value of initial k-1: ');

%k1-k10 represent the initial condition the 10 chips used to construct
%different PRN numbers.
%For PRN 22: k10=1, k9=1, k8=0, k7=0, k6=1, k5=1, k4=1, k3=1, k2=1, k1=1
%For PRN 27: k10=0, k9=0, k8=1, k7=1, k6=1, k5=1, k4=1, k3=1, k2=1, k1=1

N=32;
count=1;

%N is the maximum number of iterations requested and counts each iteration
%in increments of 1.

while count<=N

if k6+k9==1
k=1;
elseif k6+k9==2
k=0;
elseif k6+k9==0
k=0;
end
%This if-else statement resolves the modulo-2 arithmetic requirement for
%the PRN generator.

k10=k9;
k9=k8;
k8=k7;
k7=k6;
k6=k5;
k5=k4;
k4=k3;
k3=k2;
k2=k1;
k1=k;

%The above equalities represent the Linear Feedback Shift Register. Note
%that, after each iteration, the values shift from a position of k-j to a
%position of k-j-1 until the value falls off after the k-10 position.

count=count+1;

%count=count+1 moves each moves the count to the next iteration, ending at
%N iterations.

end

Thanks for any help. This is killing me.
 
Physics news on Phys.org
Apologies: This is in MATLAB
 
Make an array for each k1/2/3/.../10 to hold all of the values and change your loop so as you iterate from 1:N you go through different columns of k1/2/.../10.

For ex.
N=32;
count=1;

k10 = zeros(1,N)
K10(1) = input('Enter the value of intial k-10: ');

while count<=N

% Check current column
if k6(count)+k9(count)==1
k=1;
...

% Update the next column
k10(count + 1)=k9(count);
...

end
 
I see what you are doing there. I have been looking at arrays but tried to implement them all wrong at the end. I remade the code with the arrays as a part of every variable. It now looks like this:

N=32;
count=1;

k10=zeros(1,N);
k10(1)=1;
k9=zeros(1,N);
k9(1)=1;
k8=zeros(1,N);
k8(1)=0;
k7=zeros(1,N);
k7(1)=0;
k6=zeros(1,N);
k6(1)=1;
k5=zeros(1,N);
k5(1)=1;
k4=zeros(1,N);
k4(1)=1;
k3=zeros(1,N);
k3(1)=1;
k2=zeros(1,N);
k2(1)=1;
k1=zeros(1,N);
k1(1)=1;

while count<=N

%check current column
if k6(count)+k9(count)==1
k=1;
elseif k6(count)+k9(count)==0
k=0;
elseif k6(count)+k9(count)==2
k=0;
end

%update the next column
k10(count+1)=k9(count);
k9(count+1)=k8(count);
k8(count+1)=k7(count);
k7(count+1)=k6(count);
k6(count+1)=k5(count);
k5(count+1)=k4(count);
k4(count+1)=k3(count);
k3(count+1)=k2(count);
k2(count+1)=k1(count);
k1(count+1)=k;

end

I tried to run it with N=32 and it said busy for a long time. Is creating this many arrays going to bog down the system or did I do something wrong?
 
nevermind. Forgot the count=count+1

Thank you for the help.