I mean that I have this code
%function const_interleaver(select)
%% constructing the orignal address matrix
Address=zeros(24); s
for i=1:24
for j=1:24
Address(i,j)=24*(i-1)+j;
end
end
%% chosing the matrix size
if select==1 % 8-bit
for i=1:8
for j=1:8
Address(i,j)=Address(i,j)-(i-1)*16
end
end
elseif select==2 % 16-bit
for i=1:16
for j=1:16
Address(i,j)=Address(i,j)-(i-1)*8;
end
end
else select==3 % 24-bit
end
and it works in cases, and these cases have a common code between them. I need to make a general code, and by choosing one of the cases, part of it will work, for example, in the case of (select=1) 8 * 8, the code will work to part 8, but if it is (select=2) 16 * 16, it will work to part 16 * 16 And if it is (select=3) 24 * 24, it will work to part 24.
and the general code is :
%clear all
%clc
dim =24; % define square matrix dimention
x = [];
coun = 1;
for i=1:dim:(dim.^2-dim+1)
row = [i:i+dim-1];
x = [x;row];
end
Input_Index = x; % generate square matrix in order ascending index
% ==========================================
% Generate Chaotic interleaver Scheme
%==========================================
%-------------------(1)-------------------------
part1 = [];
for i =1:2
part1_i =x(dim:-1:dim/2 + 1,i)';
part1 = [part1 part1_i];
end
part1;
%-------------------(2)-------------------------
part2 = [];
for i =1:2
part2_i =x(dim/2:-1:1,i)';
part2 = [part2 part2_i];
end
part2;
%-------------------(3)-------------------------
part3 = [];
for i =3:4
part3_i =x(dim:-1:dim/2 + 1,i)';
part3 = [part3 part3_i];
end
part3;
%-------------------(4)-------------------------
part4 = [];
for i =3:4
part4_i =x(dim/2:-1:1,i)';
part4 = [part4 part4_i];
end
part4;
%-------------------(5)-------------------------
part5 = [];
for i =5:6
part5_i =x(dim:-1:dim/2 + 1,i)';
part5 = [part5 part5_i];
end
part5;
%-------------------(6)-------------------------
part6 = [];
for i =5:6
part6_i =x(dim/2:-1:1,i)';
part6 = [part6 part6_i];
end
part6;
%-------------------(7)-------------------------
part7 = [];
for i =7:8
part7_i =x(dim:-1:dim/2 + 1,i)';
part7 = [part7 part7_i];
end
part7;
%-------------------(8)-------------------------
part8 = [];
for i =7:8
part8_i =x(dim/2:-1:1,i)';
part8 = [part8 part8_i];
end
part8;
%-------------------(9)-------------------------
part9 = [];
for i =9:12
part9_i =x(dim:-1:dim/2 + dim/4+1,i)';
part9= [part9 part9_i];
end
part9;
%-------------------(10)-------------------------
part10 = [];
for i =9:12
part10_i =x(dim/2+dim/4:-1:dim/2+1 ,i)';
part10= [part10 part10_i];
end
part10;
%-------------------(11)-------------------------
part11= [];
for i =9:12
part11_i =x(dim/2:-1:dim/4+1 ,i)';
part11= [part11 part11_i];
end
part11;
%-------------------(12)-------------------------
part12= [];
for i =9:12
part12_i =x(dim/4:-1:1 ,i)';
part12= [part12 part12_i];
end
part12;
%-------------------(13)-------------------------
part13 = [];
for i =13:16
part13_i =x(dim:-1:dim/2 + dim/4+1,i)';
part13= [part13 part13_i];
end
part13;
%-------------------(14)-------------------------
part14= [];
for i =13:16
part14_i =x(dim/2+dim/4:-1:dim/2+1 ,i)';
part14= [part14 part14_i];
end
part14;
%-------------------(15)-------------------------
part15= [];
for i =13:16
part15_i =x(dim/2:-1:dim/4+1 ,i)';
part15= [part15 part15_i];
end
part15;
%-------------------(16)-------------------------
part16= [];
for i =13:16
part16_i =x(dim/4:-1:1 ,i)';
part16= [part16 part16_i];
end
part16;
%-------------------(17)-------------------------
part17 = [];
for i =17:20
part17_i =x(dim:-1:dim/2 + dim/4+1,i)';
part17= [part17 part17_i];
end
part17;
%-------------------(18)-------------------------
part18= [];
for i =17:20
part18_i =x(dim/2+dim/4:-1:dim/2+1 ,i)';
part18= [part18 part18_i];
end
part18;
%-------------------(19)-------------------------
part19= [];
for i =17:20
part19_i =x(dim/2:-1:dim/4+1 ,i)';
part19= [part19 part19_i];
end
part19;
%-------------------(20)-------------------------
part20= [];
for i =17:20
part20_i =x(dim/4:-1:1 ,i)';
part20= [part20 part20_i];
end
part20;
%-------------------(21)-------------------------
part21 = [];
for i =21:24
part21_i =x(dim:-1:dim/2 + dim/4+1,i)';
part21= [part21 part21_i];
end
part21;
%-------------------(22)-------------------------
part22= [];
for i =21:24
part22_i =x(dim/2+dim/4:-1:dim/2+1 ,i)';
part22= [part22 part22_i];
end
part22;
%-------------------(23)-------------------------
part23= [];
for i =21:24
part23_i =x(dim/2:-1:dim/4+1 ,i)';
part23= [part23 part23_i];
end
part23;
%-------------------(24)-------------------------
part24= [];
for i =21:24
part24_i =x(dim/4:-1:1 ,i)';
part24= [part24 part24_i];
end
part24;
Chaotic_Interleaver_index = [part24;part23;part22;part21;part20;part19;part18;part17;part16;part15;part14;part13 ...
;part12;part11;part10;part9;part8;part7;part6;part5;part4;part3;part2;part1];
Chaotic_Interleaver_index_frame = [part24,part23,part22,part21,part20,part19,part18,part17,part16,part15,part14,part13 ...
,part12,part11,part10,part9,part8,part7,part6,part5,part4,part3,part2,part1];

6 件のコメント

Jan
Jan 2021 年 12 月 30 日
Just a hint:
Replace:
Address=zeros(24); s % The "s" is a typo, isn't it?
for i=1:24
for j=1:24
Address(i,j)=24*(i-1)+j;
end
end
by
Address = 24 * (0:23).' + (1:24);
Zeina Abdullah
Zeina Abdullah 2021 年 12 月 31 日
thank you @Jan i will try to do this hint . but can you help me in my problem have you any Suggestion
yanqi liu
yanqi liu 2021 年 12 月 31 日
yes,sir,the select may be 1、2、3,and use part 8、16、24
but how to process the other select and part?
Zeina Abdullah
Zeina Abdullah 2021 年 12 月 31 日
@yanqi liu i mean if the select==1 the part 1,2,3,4,5,6,7 and part 8 work. when select==2 the part 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,and part 16 . and when select ==3 the part1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 and part 24 work
Rik
Rik 2022 年 1 月 1 日
If you don't use numbered variables, but instead use arrays, it looks like a for loop will solve your problem.
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
thank you @Rik i will try but iam beginner in matlab

サインインしてコメントする。

 採用された回答

Turlough Hughes
Turlough Hughes 2022 年 1 月 1 日

0 投票

Try this:
function [idx,x] = chaoticInterleaver(N)
assert(mod(N,8)==0,'N must be divisible by 8.')
idx = zeros(N);
x = N * (0:N-1).' + (1:N); % from Jan
% Lower part
idx(N-7:2:end-1, :) = frf(x(1:N/2, 1:8), N);
idx(N-6:2:end,:) = frf(x(N/2+1:end,1:8), N);
if N >= 16
for ii = 1:4 % Upper part
idx(ii:4:N-8,:) = frf( x(N/4*(ii-1)+1:N/4*ii, 9:end), N);
end
end
end
function out = frf(partX,N)
% flipud, reshape with N rows, and then flip again (hence the name frf).
out = flipud(reshape(flipud(partX),N,[]).');
end
It may work for higher N too if the "upper part" rules are the same. The interleaver index frame is then:
interleaverIndexFrame = idx.';
interleaverIndexFrame = interleaverFrame(:).';

13 件のコメント

Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
@Turlough Hughes thank you very much i will try the code if it work i will put accept answer
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
@Turlough Hughes there is an error
Not enough input arguments.
Error in chaoticInterleaverN (line 2)
assert(mod(N,8)==0,'N must be divisible by 8.')
Turlough Hughes
Turlough Hughes 2022 年 1 月 2 日
編集済み: Turlough Hughes 2022 年 1 月 2 日
It seems that you changed the function definition line to
function [idx,x] = chaoticInterleaverN
...
but it should be as follows:
function [idx,x] = chaoticInterleaver(N)
Simply save the first piece of code I provided in my answer as a function (called chaoticInterleaver.m), and then call it as follows:
[Chaotic_Interleaver_index, Address] = chaoticInterleaver(8) % you can use inputs 8, 16, 24, etc as required
Chaotic_Interleaver_index = 8×8
31 23 15 7 32 24 16 8 63 55 47 39 64 56 48 40 29 21 13 5 30 22 14 6 61 53 45 37 62 54 46 38 27 19 11 3 28 20 12 4 59 51 43 35 60 52 44 36 25 17 9 1 26 18 10 2 57 49 41 33 58 50 42 34
Address = 8×8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
thank you the code is working. iam beginner in matlab can you explain the functions in the comment
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
please i need more details to understand the code because the code is working well
Turlough Hughes
Turlough Hughes 2022 年 1 月 2 日
Perhaps it's best to explain my thought process with some figures.
First consider the case of N == 8. In this scenario you start with the matrix x as follows:
N = 8;
idx = zeros(N); % Space for Chaotic Interleaver Index
x = N * (0:N-1).' + (1:N);
The frf() function is applied to the top half and then the lower half of x. You can see how the frf() function rearranges the top half of x for the chaotic interleaver index, idx, in the following figure (blue parts show how two columns are reordered into a given row):
However, those output rows don’t go directly into idx, instead, they're organised into idx's odd numbered rows in the last 8 rows of idx:
>> idx(N-7:2:end-1, :) = frf(x(1:N/2, 1:8), N)
idx =
31 23 15 7 32 24 16 8
0 0 0 0 0 0 0 0
29 21 13 5 30 22 14 6
0 0 0 0 0 0 0 0
27 19 11 3 28 20 12 4
0 0 0 0 0 0 0 0
25 17 9 1 26 18 10 2
0 0 0 0 0 0 0 0
In the case of N = 8, the first 8 rows are the last 8 rows (this matters for N>=16). Following the same procedure, the lower half of x will fill the odd rows in idx. Ok... Thus far we have covered frf() and the following two lines of code from my original answer:
% Lower part
idx(N-7:2:end-1, :) = frf(x(1:N/2, 1:8), N);
idx(N-6:2:end,:) = frf(x(N/2+1:end,1:8), N);
For the case of N==16, the process is the same on the left hand side of x:
One thing to remember is that all elements in the first 8 columns of x will end up on the bottom 8 rows of idx. The RHS is treated slightly differently. First, it's separated into 4 parts... let's consider the upper part (highlighted in red above). The procedure is similar except four columns in the input make up a single row in the output:
Each part on the RHS of x produces 2 rows, giving 8 rows in total, making the upper half of idx. Of course, they don’t go directly into idx, the two rows go into row 1 and 5 of idx, subsequently it's rows 2 and 6, rows 3 and 7, and finally rows 4 and 8. For the case of N == 24 its the same pattern, except the four parts on the right are 6 by 16 arrays and frf gives 4 rows that go into idx on rows 1 5 9 and 13, and so on.
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
Wow, very detailed and understandable explanation . thank you
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
@Turlough Hughes i have another problem . i need to find relashionship between the output numbers in 8 , 16 in matrix 24 . for example i have 64 output in 8*8 matrix this 64 if there is any number or item in the same address or in the same boundary of the 8*8 matrix . and the 16*16 with 24*24
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
like this in file
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
this file have output of matrix 8*8 and 16*16 . this file and the above will find relashionship between them .as i am color the each file such as 8*8 red in file of 24*24 above will compared with same dimation and color . and 16*16 with 16*16 in the file above of 24*24
Turlough Hughes
Turlough Hughes 2022 年 1 月 3 日
I'm not sure what you mean. Perhaps what you need is the ismember function?
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 3 日
I mean your code is working very well and I am depend on it . But I have another step after this output. The 8×8 and 16×16 have group of numbers shared or existing . I need to do something like a relationship between these shared outputs . Hint the shared outputs not in the same address
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 3 日
And thank you for your suggestion I will read this dismember function and I will try to understand it

サインインしてコメントする。

その他の回答 (1 件)

yanqi liu
yanqi liu 2022 年 1 月 1 日

1 投票

clc; clear all; close all;
%function const_interleaver(select)
%% constructing the orignal address matrix
Address=zeros(24);
for i=1:24
for j=1:24
Address(i,j)=24*(i-1)+j;
end
end
%% chosing the matrix size
bns = zeros(1,24);
if select==1 % 8-bit
for i=1:8
for j=1:8
Address(i,j)=Address(i,j)-(i-1)*16;
end
end
% part 1,2,3,4,5,6,7 and part 8
bns([1,2,3,4,5,6,7,8]) = 1;
elseif select==2 % 16-bit
for i=1:16
for j=1:16
Address(i,j)=Address(i,j)-(i-1)*8;
end
end
% part 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,and part 16
bns([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]) = 1;
else select==3 % 24-bit
% part1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 and part 24
bns([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]) = 1;
end
% select==1 the part 1,2,3,4,5,6,7 and part 8 .
% select==2 the part 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,and part 16
% select ==3 the part1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 and part 24
%clear all
%clc
dim =24; % define square matrix dimention
x = [];
coun = 1;
for i=1:dim:(dim.^2-dim+1)
row = [i:i+dim-1];
x = [x;row];
end
Input_Index = x; % generate square matrix in order ascending index
% ==========================================
% Generate Chaotic interleaver Scheme
%==========================================
if bns(1)
%-------------------(1)-------------------------
part1 = [];
for i =1:2
part1_i =x(dim:-1:dim/2 + 1,i)';
part1 = [part1 part1_i];
end
part1;
end
if bns(2)
%-------------------(2)-------------------------
part2 = [];
for i =1:2
part2_i =x(dim/2:-1:1,i)';
part2 = [part2 part2_i];
end
part2;
end
if bns(3)
%-------------------(3)-------------------------
part3 = [];
for i =3:4
part3_i =x(dim:-1:dim/2 + 1,i)';
part3 = [part3 part3_i];
end
part3;
end
if bns(4)
%-------------------(4)-------------------------
part4 = [];
for i =3:4
part4_i =x(dim/2:-1:1,i)';
part4 = [part4 part4_i];
end
part4;
end
if bns(5)
%-------------------(5)-------------------------
part5 = [];
for i =5:6
part5_i =x(dim:-1:dim/2 + 1,i)';
part5 = [part5 part5_i];
end
part5;
end
if bns(6)
%-------------------(6)-------------------------
part6 = [];
for i =5:6
part6_i =x(dim/2:-1:1,i)';
part6 = [part6 part6_i];
end
part6;
end
if bns(7)
%-------------------(7)-------------------------
part7 = [];
for i =7:8
part7_i =x(dim:-1:dim/2 + 1,i)';
part7 = [part7 part7_i];
end
part7;
end
if bns(8)
%-------------------(8)-------------------------
part8 = [];
for i =7:8
part8_i =x(dim/2:-1:1,i)';
part8 = [part8 part8_i];
end
part8;
end
if bns(9)
%-------------------(9)-------------------------
part9 = [];
for i =9:12
part9_i =x(dim:-1:dim/2 + dim/4+1,i)';
part9= [part9 part9_i];
end
part9;
end
if bns(10)
%-------------------(10)-------------------------
part10 = [];
for i =9:12
part10_i =x(dim/2+dim/4:-1:dim/2+1 ,i)';
part10= [part10 part10_i];
end
part10;
end
if bns(11)
%-------------------(11)-------------------------
part11= [];
for i =9:12
part11_i =x(dim/2:-1:dim/4+1 ,i)';
part11= [part11 part11_i];
end
part11;
end
if bns(12)
%-------------------(12)-------------------------
part12= [];
for i =9:12
part12_i =x(dim/4:-1:1 ,i)';
part12= [part12 part12_i];
end
part12;
end
if bns(13)
%-------------------(13)-------------------------
part13 = [];
for i =13:16
part13_i =x(dim:-1:dim/2 + dim/4+1,i)';
part13= [part13 part13_i];
end
part13;
end
if bns(14)
%-------------------(14)-------------------------
part14= [];
for i =13:16
part14_i =x(dim/2+dim/4:-1:dim/2+1 ,i)';
part14= [part14 part14_i];
end
part14;
end
if bns(15)
%-------------------(15)-------------------------
part15= [];
for i =13:16
part15_i =x(dim/2:-1:dim/4+1 ,i)';
part15= [part15 part15_i];
end
part15;
end
if bns(16)
%-------------------(16)-------------------------
part16= [];
for i =13:16
part16_i =x(dim/4:-1:1 ,i)';
part16= [part16 part16_i];
end
part16;
end
if bns(17)
%-------------------(17)-------------------------
part17 = [];
for i =17:20
part17_i =x(dim:-1:dim/2 + dim/4+1,i)';
part17= [part17 part17_i];
end
part17;
end
if bns(18)
%-------------------(18)-------------------------
part18= [];
for i =17:20
part18_i =x(dim/2+dim/4:-1:dim/2+1 ,i)';
part18= [part18 part18_i];
end
part18;
end
if bns(19)
%-------------------(19)-------------------------
part19= [];
for i =17:20
part19_i =x(dim/2:-1:dim/4+1 ,i)';
part19= [part19 part19_i];
end
part19;
end
if bns(20)
%-------------------(20)-------------------------
part20= [];
for i =17:20
part20_i =x(dim/4:-1:1 ,i)';
part20= [part20 part20_i];
end
part20;
end
if bns(21)
%-------------------(21)-------------------------
part21 = [];
for i =21:24
part21_i =x(dim:-1:dim/2 + dim/4+1,i)';
part21= [part21 part21_i];
end
part21;
end
if bns(22)
%-------------------(22)-------------------------
part22= [];
for i =21:24
part22_i =x(dim/2+dim/4:-1:dim/2+1 ,i)';
part22= [part22 part22_i];
end
part22;
end
if bns(23)
%-------------------(23)-------------------------
part23= [];
for i =21:24
part23_i =x(dim/2:-1:dim/4+1 ,i)';
part23= [part23 part23_i];
end
part23;
end
if bns(24)
%-------------------(24)-------------------------
part24= [];
for i =21:24
part24_i =x(dim/4:-1:1 ,i)';
part24= [part24 part24_i];
end
part24;
end
Chaotic_Interleaver_index = [part24;part23;part22;part21;part20;part19;part18;part17;part16;part15;part14;part13 ...
;part12;part11;part10;part9;part8;part7;part6;part5;part4;part3;part2;part1];
Chaotic_Interleaver_index_frame = [part24,part23,part22,part21,part20,part19,part18,part17,part16,part15,part14,part13 ...
,part12,part11,part10,part9,part8,part7,part6,part5,part4,part3,part2,part1];

4 件のコメント

Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
@yanqi liu this code write in the same file or in Separated
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
@yanqi liu thank you i will try this way and if it work will .i will put to your answer accept answer
yanqi liu
yanqi liu 2022 年 1 月 2 日
yes,sir,it is one file
thanks
Zeina Abdullah
Zeina Abdullah 2022 年 1 月 2 日
ok thank you @yanqi liu

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by