% MATLAB function for ECS 452 by Asst. Prof. Dr. Prapun Suksompong.

function y = DMC_Channel_sim(x,S_X,S_Y,Q)
%% Applying the effect of the channel to create the channel output y
y = zeros(size(x)); % preallocation
for k = 1:length(x)
    % Look at the channel input one by one. Choose the corresponding row
    % from the Q matrix to generate the channel output.
    y(k) = randsrc(1,1,[S_Y;Q(find(S_X == x(k)),:)]);
end