Saving values after each iteration

  • Thread starter Thread starter gryphon1221
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around a homework problem related to GPS navigation, specifically focusing on constructing a signal using initial condition values and implementing modulo-2 arithmetic to generate subsequent values. Participants are exploring how to store values from each iteration in a way that allows for easy access to all generated values, particularly as the number of iterations increases significantly.

Discussion Character

  • Technical explanation
  • Homework-related
  • Mathematical reasoning

Main Points Raised

  • One participant describes their initial setup in MATLAB, where they can only see the final 10 values after 32 iterations and seeks a method to store all values generated during the iterations.
  • Another participant suggests creating arrays for each variable (k1, k2, ..., k10) to hold all values and modifying the loop to iterate through different columns of these arrays.
  • A later reply indicates that the participant successfully implemented arrays but encountered performance issues when running the code, questioning whether the array creation would slow down the system.
  • One participant acknowledges a mistake in their code related to the iteration count, which they later correct.

Areas of Agreement / Disagreement

Participants generally agree on the need to use arrays to store values from each iteration, but there are varying approaches and concerns regarding performance implications. The discussion does not reach a consensus on the best implementation method or the performance impact of the proposed solutions.

Contextual Notes

Participants express uncertainty about the efficiency of their implementations, particularly when scaling to a larger number of iterations (up to 7000). There are also unresolved issues regarding the correct placement of the iteration increment within the loop.

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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
6K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K