I am trying to create a turbo encoder for my project.
Till now i have created the convolution encoder of 1/2 rate. Now i am having difficulty to apply interleaver. Here is my code. I am not getting output in ilvr. Correct me where i am going incorrect. Thanks in advance
msg = [0 1 0 1 1 1 0 0 1 0 1 0 0 0 1];
t= poly2trellis(3,[6 7]);
[isok,status] = istrellis(t);
code1 = convenc(msg,t);
ilvr = randperm(msg);
code2 = convenc(ilvr,t);
Well, firstly, if your question is about ilvr then why include the rest of the code other than the definition of msg and the line in question?
Secondly, when I ran this:
msg = [0 1 0 1 1 1 0 0 1 0 1 0 0 0 1];
ilvr = randperm(msg);
I got the following error:
Error using randperm
Size inputs must be scalar.
So, this means the the input is not what randperm was expecting. Then I typed help randperm, and looked at the help for randperm, so now I understand what randperm does and what inputs it expects. The error is because you gave randperm a vector, but the first input must be an integer.
I'm not sure what you are trying to do on that line, maybe you are trying to get a random permutation of the elements in msg? Following a hint in the help page, try this:
ilvr=msg(randperm(numel(msg)));
Related
I have the following three vectors:
trans_now=[1 2 4]; data2send=[1 0 0 1]; datasent=[0 0 0 0];
I want to set datasent to 1 for those nodes that are members of tran_now and whose data2send status is 1. e.g 4 is a member of trans_now and data2send(4) is 1 therefore datasent(4) should be set to 1.
I can do it using for loop and if statement as shown in the code below.
for i=1:length(trans_now)
if data2send(trans_now(i))==1
datasent(trans_now(i))=1;
end
end
However I want one liner code for this. The one liner code that I tried is
req_sent(req2send(trans_now)==1)=1;
But it doesn't work.
The output should set datasent vector to [1 0 0 1].
you could solve this in 2 ways:
1.
data_sent(trans_now) = data2send(trans_now)
the output is:
data_sent =
1 0 0 1
In this solution I assumed that all the initial values of data_sent are starting as 0 and that you need to assign it once.
2.
datasent(intersect(find(data2send == 1), trans_now)) = 1
output is:
data_sent =
1 0 0 1
In this solution no assumption is used and you assign only indices where data2send == 1 and also appear in trans_now
I want to write a short Matlab function for finding the sequence values in a time series like this:
Ex: a = [0 0 0 1 0 0 1 1 0 1 1 1 1 0 0];
My_expected_result = 3 ;(as number 1 happens 3 time of sequences)
Thank you.
Here's a simple regexp-based solution to find the number of runs of ones:
result = numel(regexp(char(a+'0'), '1+'));
You can also use strfind, which works for numerical arrays (although that's not documented):
result = numel(strfind([0 a], [1 0]));
Or just diff:
result = sum(diff([a 0])<0);
If you have the Image Processing Toolbox, bwlabel can be used for the job too:
result = max(bwlabel(a));
or (thanks to #rahnema1 for this one):
[~, result] = bwlabel(a);
I'm having trouble with this problem since I'm new to matlab
"Use help to learn about the built in function ‘rand’. Write a script to use the rand function to generate a sequence of ‘head’ or ‘tail’ where one is head and zero is tail. The other function that you need to use is ‘round’ to convert the output of the ‘rand’ function to an integer. When we run your function it should display something like this: “T H T T H H H…..”.
I've used the help function and searched online but I still don't understand the random function.
I've used
flip = random('norm',1:10,1)
flip =
1.0774 0.7859 1.8865 3.9932 6.5326 5.2303 7.3714 7.7744 10.1174 8.9109
As you can see, it keeps giving me random numbers. I want my numbers to be either 0 or 1.
I know the 10 in 1:10 will display 10 values, but what does the two 1's mean?
I'd appreciate any help, thanks!
For completeness, there's also the randi function (at least from 2011b onwards):
faceId = randi(2,1,10) % generates random integers between 1 and 2 (inclusively)
faceId =
2 2 2 1 1 2 2 1 1 2
That avoids the need for the < 0.5 comparison and the +1
You can do as follow:
faceId=rand(1,10)<0.5
faceId =
1 1 0 0 1 1 1 0 0 0
faceName='TH';
faceName(faceId+1)
ans =
THHHHTTHTH
I got the error "Solving CHIU requires an initial condition vector of length 651" when running this Matlab file:
TSPAN = (0:1:320);
[ta,xa] = ode15s('Chiu',TSPAN,[0.0258 0 0 0 0 0 0 0 5.88e9*exp(-701/(1.987*T)) 2.95e7*exp(-4353/(1.987*T)) 8.83]);
I really don't get what exactly this error means. What and where is the vector length 651? I only have 11 ODE equation. Can anyone help me?
I beieve, the first input to ode15s should be a functions handle, not the name of the function. So, instead of
[ta,xa] = ode15s('Chiu',TSPAN,...
try
[ta,xa] = ode15s(#Chiu,TSPAN,...
I have one matrix called targets (1X4000); column 1 to 2000 contains double value 0 and column 2001 to 4000 contains double value 1
a)
i want to create a matrix called targets_1 where i want to check if the value is 0 then make the entry 1 so at the end of the day i must have a matrix with :column 1 to 2000 with value 1 and column 2001:4000 with value zero
b)
Same situation as above but this time i want to check if the value is 1 then make the entry 1 and if it is zero then make the entry zero; at the end; my new matrix targets_2 contains values: column 1 to 2000 with value zero and column 2001:4000 with value 1
i know how to use the strcmp function to make such checking with strings, but problem is that my original matrix is double and i dont know if there is such function like
setosaCmp = strcmp('setosa',species);
which could work with double (numbers); any help would be appreciated
Your question isn't very clear. It sounds like the following would satisfy your description:
targets_1 = 1 - targets;
targets_2 = targets;
targets1 = double(targets == 0);
targets2 = targets;
I'm basing this answer purely on the fact that you've mentioned setosaCmp = strcmp('setosa', species);. From this I'm guessing that
You have Statistics Toolbox, as setosa is a species of iris from the Fisher Iris dataset widely used in Statistics Toolbox demos, and
You have a variable containing class labels, and you'd like to construct some class indicator variables (i.e. a new variable for each class label, each of which is 1 when the item is in that class, and 0 when it's not).
Is that right? If not, please ignore me.
If I'm right, then I think the command you're looking for is dummyvar from Statistics Toolbox. Try this:
>> classLabels = [1, 2, 1, 2, 3, 1, 3];
>> dummyvar(classLabels)
ans =
1 0 0
0 1 0
1 0 0
0 1 0
0 0 1
1 0 0
0 0 1