Skip to content

Instantly share code, notes, and snippets.

@yichao0319
Created July 13, 2012 18:31
Show Gist options
  • Save yichao0319/3106527 to your computer and use it in GitHub Desktop.
Save yichao0319/3106527 to your computer and use it in GitHub Desktop.
matlab:slice
function [ out_sym, table ] = slice( in_sym, mod_type )
%SLICE Makes hard decision on input symbols with designated modulation type
%
% Inputs:
% in_sym: input symbols to be sliced
% mod_type: modulation type, BPSK, QPSK, 16QAM, or 64QAM
%
% Outputs:
% out_sym: output symbols
% table: mapping alphabet
%
% get the code form: http://read.pudn.com/
in_sym = in_sym(:);
% BPSK
if strcmp(mod_type,'BPSK')
table=exp(j*[0 -pi]); % generates BPSK symbols
% QPSK modulation
elseif strcmp(mod_type,'QPSK')
table=exp(j*[-3/4*pi 3/4*pi 1/4*pi -1/4*pi]); % generates QPSK symbols
% 16-QAM modulation
elseif strcmp(mod_type,'16QAM')
% generates 16QAM symbols
m=1;
for k=-3:2:3
for l=-3:2:3
table(m) = (k+j*l)/sqrt(10); % power normalization
m=m+1;
end;
end;
% 64-QAM modulation
elseif strcmp(mod_type,'64QAM')
% generates 64QAM symbols
m=1;
for k=-7:2:7
for l=-7:2:7
table(m) = (k+j*l)/sqrt(42); % power normalization
m=m+1;
end;
end;
else
error('Unimplemented modulation');
end
out_sym = zeros(length(in_sym),1);
d = zeros(1,length(table));
for n_sym = 1:length(in_sym)
for n_d = 1:length(d)
d(n_d) = abs(in_sym(n_sym) - table(n_d));
end
[m,index] = min(d);
out_sym(n_sym) = table(index);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment