MATLAB function and hand written code output not matching?
3 次查看(过去 30 天)
显示 更早的评论
Dear All,
I am new to MATLAB. I am doing the following operation for QPSK modulation. One code is with in built MATLAB function for pskmod and other is hand written. I am attaching both the code please help me how to get the same output as the inbuilt MATLAB function's for hand written code.
regards,
YM
MATLAB's in built functions code:
clc
clear variable
clear all
M = 4;
b = [1,0,1,0,1,0,1,0];
%b = randi([0 1],12,1);
% check arguments
if( nargin < 2 )
M = 4; % QPSK is default
else
if( rem( log2(M), 1 ) ~= 0.0 )
error('M must be a power of two.')
end
end
% vectorise
b = b(:);
% check input length integer to be an integer multiple of M
assert( rem( length(b), M ) == 0 )
% check if b is binary
assert( sum((b ~= 0) & (b ~= 1)) == 0 )
% data symbols (binary --> integer conversion of ld(M) bits)
b2 = reshape( b, log2(M), length(b)/log2(M) ) .';
b2 = bi2de(b2, 'left-msb');
s = pskmod( b2, M, pi/M, 'gray' ); %* sqrt(2)
And this is the hand written code:
clc
clear variable
clear all
% Setting up parameters for modulation type
data = [1,0,1,0,1,0,1,0]; % generating binary data of 1000 bits with ones and zeros
%data = [1;1;0;1;1;1;1;0;0;1;1;0;0;0;0;0;1;0;0;0;0;0;0;0;0;0;0;0;0;1;0;1;0;0;0;0;0;0;0;0;0;0;1;1;1;0;0;0;1;0;0;0;0;0;1;0;1;1;0;1];
mod_type=input('Enter the modulation type[1 for BPSK,2 for QPSK,3 for 16QAM,4 for 64QAM]: ');
norm_factor=[1.0;0.7071;0.3162;0.1543]; % normalization factors, 1.0:BPSK,0.7071:QPSK,0.3162:16QAM,0.1543:64QAM
nc=[1;2;4;6]; % number of bits per subcarrier, 1:BPSK,2:QPSK,4:16QAM,6:64QAM
input_seq = data;
k=norm_factor(mod_type);
mode=nc(mod_type);
% Selecting constellation point as per modulation type
switch mode
case 1
b=k*[1 -1];
case 2
b=k*[1+1i -1+1i 1-1i -1-1i];
case 4
b=k*[1+1i 1+3i 1-1i 1-3i 3+1i 3+3i 3-1i 3-3i -1+1i -1+3i -1-1i -1-3i -3+1i -3+3i -3-1i -3-3i];
case 6
b=k*[3+3i 3+1i 3+5i 3+7i 3-3i 3-1i 3-5i 3-7i 1+3i 1+1i 1+5i 1+7i 1-3i 1-1i 1-5i 1-7i 5+3i 5+1i 5+5i 5+7i 5-3i 5-1i 5-5i 5-7i 7+3i 7+1i 7+5i 7+7i 7-3i 7-1i 7-5i 7-7i -3+3i -3+1i -3+5i -3+7i -3-3i -3-1i -3-5i -3-7i -1+3i -1+1i -1+5i -1+7i -1-3i -1-1i -1-5i -1-7i -5+3i -5+1i -5+5i -5+7i -5-3i -5-1i -5-5i -5-7i -7+3i -7+1i -7+5i -7+7i -7-3i -7-1i -7-5i -7-7i];
end
count=1;
count1=1;
for i=1:(ceil(length(input_seq)/mode))
temp=0;
for j=1:mode
temp=bitor(temp,bitshift(input_seq(count),(j-1)));
count=count+1;
if(count>length(input_seq))
break;
end
end
map_out(count1)=b(temp+1);
map_out = map_out;%* sqrt(2)
map_out = map_out(:);
count1=count1+1;
end
please help me with this. I want my hand written code's output to match to the MATLAB's in built function code's output.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 QPSK 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!