Help with creating a function which is dependent on the array previous values
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I need to create a first order or a second order Predictar and the user get to decide which order he wants. And the predictator is basically a new utlaized array of the main one but with its values dependent on the previous values ( first order depends on only 1 previous value, while 2nd order depends on 2 previous values and so on)
Here is how I did the first order Predictaror
%% x_k is my message signal
x_kdelay = [0 x_k(1:end-1)]; %Delay by 1 unit
d_k = x_k - x_kdelay;
But then I wanted to add the second order and here is what I did, but it's giving me an error.
x_kdelay = [0 x_k(1:end-1)]; %Delay by 1 unit
%%%%% Predictator (New global state)
if p == 1
d_k = x_k - x_kdelay;
elseif p == 2
for i5= 1: numel(x_k)
d_k(i5) = x_k(i5) - (x_kdelay(i)+x_kdelay(i-1))
end
end
Then Later on I want to re-do this step at the receiver side, here is the function I created for the first order Predictator re-do.
intial = 0;
x_hat = [];
for i3 = 1:numel(d_k)
x_ind = intial +dq_tx(i3);
x_hat = [x_hat x_ind];
intial = x_ind;
end
And I would apprechiate any help in modifying it to support the second order case as well.
Thank you
2 Kommentare
Dyuman Joshi
am 7 Dez. 2022
In the if-else segment, the loop index is incorrect or the variable i is not defined .
If it is i5, and since i5 starts with 1, then i5-1 == 0 will give you an error when used as an index.
if p == 1
d_k = x_k - x_kdelay;
elseif p == 2
for i5= 1: numel(x_k)
d_k(i5) = x_k(i5) - (x_kdelay(i)+x_kdelay(i-1))
%^ %^
end
end
For the 2nd code snippet, x_hat is same as cumsum(dq_tx(1:numel(d_k)) and initial is equalto last value of x_hat.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!