I need to make a general code
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
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.
采纳的回答
Turlough Hughes
2022-1-1
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(:).';
更多回答(1 个)
yanqi liu
2022-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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Argument Definitions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!