function [s] = pammod(N_symbols,M) % Randomly produces a sequence of N_symbols symbols, using a PAM modulation % with parameter M, giving the number of possible symbol values. M should % be a power of 2 ; the number of bits per symbol is then given by log_2(M) symbols_TX = (rand(N_symbols,1)-0.5)*M; s = zeros(N_symbols,1); for i = 1:N_symbols if symbols_TX(i) == 0 s(i) = -1; elseif symbols_TX(i) < 0 s(i) = floor(symbols_TX(i))*2+1; elseif symbols_TX(i) > 0 s(i) = ceil(symbols_TX(i))*2-1; end end end