Saving values after each iteration

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

The discussion focuses on implementing a MATLAB solution for storing values generated through a Linear Feedback Shift Register (LFSR) for GPS navigation signal processing. The user initially struggled to retain all generated values across iterations, only seeing the final 10 values. The solution involved creating arrays for each variable (k1 to k10) to store values at each iteration, allowing for up to 7000 iterations. The final code provided effectively captures and stores each value in its respective array, ensuring all iterations are accounted for.

PREREQUISITES
  • Understanding of MATLAB programming language
  • Familiarity with Linear Feedback Shift Register (LFSR) concepts
  • Knowledge of modulo-2 arithmetic
  • Basic array manipulation in MATLAB
NEXT STEPS
  • Explore MATLAB array initialization techniques for efficient memory usage
  • Learn about optimizing MATLAB loops for performance improvements
  • Investigate advanced signal processing techniques in MATLAB
  • Study the implementation of LFSR in other programming languages for broader understanding
USEFUL FOR

Students and professionals in signal processing, MATLAB programmers, and anyone involved in GPS navigation system development.

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
2K
  • · Replies 1 ·
Replies
1
Views
2K