⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convbase.m

📁 matlab ofdm simulation
💻 M
字号:
function  DataOut = convbase(DataIn,CurrBase,NewBase)
%CONVBASE Converts the number base of the input data (DataIn)
%	DataOut = convbase(DataIn,CurrBase,NewBase)
%	from the current base (CurrBase) to the new base required
%	(NewBase). If the new base is less the the old base, e.g
%	NewBase = 2 and CurrBase = 8, the DataOut will have more
%	data words. For the above example DataOut will be 4 times
%	longer then DataIn.
%	The actual base used = 2^NewBase, thus NewBase = 8, is base 256
%	E.g. DataIn = [ 2 64 20 ] with CurrBase = 8, NewBase = 2
%	DataOut = [0 0 0 2, 1 0 0 0, 0 1 1 0]
%	Note : Both the input and output data is in a serial format.
%====================================
% Convert the number base of the data
%====================================
if CurrBase > NewBase,
	%Convert the input data into the base (NewBase) required
	leftover = DataIn';
	DataOut = [];
	for k = 1:(CurrBase/NewBase)
		DataOut = [DataOut rem(leftover,2^NewBase)];
		leftover = floor(leftover./(2^NewBase));
	end
	DataOut = reshape(DataOut',1,size(DataOut,1)*size(DataOut,2));
elseif CurrBase < NewBase,
	%=======================
	%Convert back to decimal
	%=======================
	remainder = rem(length(DataIn),NewBase/CurrBase);
	if (remainder > 0),
		disp('WARNING : Received data length problem when converting base');
		disp('Clipping data to make possible');
		DataIn = DataIn(1:length(DataIn)-remainder);
	end
	Datawords=reshape(DataIn,NewBase/CurrBase,size(DataIn,1)*size(DataIn,2)/...
		(NewBase/CurrBase))';
	DataOut = zeros(size(Datawords,1),1);
	for k = 1:(NewBase/CurrBase)
		DataOut = DataOut+Datawords(:,k)*(2^CurrBase)^(k-1);
	end
	DataOut = DataOut.';
else
	DataOut = DataIn;	%No change of base.
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -