% To save a new set of files, you need to set the saveFiles to true.
outPath = fileparts(matlab.desktop.editor.getActiveFilename);
disp(outPath);
/Users/shahab/code/Fireball/OpenSource/onGithub/Tests/Wireless/NewProject/OnGit/neoradium/Playground/CompareWithMatlab/Polar/MatlabFiles
s = rng(100);       % Seed the RNG for repeatability
K = 54;             % Message length in bits, including CRC, K > 30
E = 120;            % Rate matched output length, E <= 8192
L = 8;              % List length, a power of two, [1 2 4 8]
numFrames = 1000;   % Number of frames to simulate
linkDir = 'DL';     % Link direction: downlink ('DL') OR uplink ('UL')
    % Downlink scenario (K >= 36, including CRC bits)
    crcLen = 24;      % Number of CRC bits for DL, Section 5.1, [6]
    poly = '24C';     % CRC polynomial
    nPC = 0;          % Number of parity check bits, Section 5.3.1.2, [6]
    nMax = 9;         % Maximum value of n, for 2^n, Section 7.3.3, [6]
    iIL = true;       % Interleave input, Section 5.3.1.1, [6]
    iBIL = false;     % Interleave coded bits, Section 5.4.1.3, [6]
    % Uplink scenario (K > 30, including CRC bits)
    % Generate a random message
    msg = randi([0 1],K-crcLen,1);
    save(strcat(outPath,'/msg.mat'),'msg');
    msg = load(strcat(outPath,'/msg.mat')).msg;
msgcrc = nrCRCEncode(msg,poly);
    save(strcat(outPath,'/msgcrc.mat'),'msgcrc');
encOut = nrPolarEncode(msgcrc,E,nMax,iIL);
    save(strcat(outPath,'/encOut.mat'),'encOut');
modIn = nrRateMatchPolar(encOut,K,E,iBIL);
    save(strcat(outPath,'/modIn.mat'),'modIn');
modOut = nrSymbolModulate(modIn,'QPSK');
    save(strcat(outPath,'/modOut.mat'),'modOut');
R = K/E;                          % Effective code rate
bps = 2;                          % bits per symbol, 1 for BPSK, 2 for QPSK
EsNo = EbNo + 10*log10(bps);
snrdB = EsNo + 10*log10(R)        % in dB
noiseVar = 1./(10.^(snrdB/10))
% Using AWGNChannel Channel
% chan = comm.AWGNChannel('NoiseMethod','Variance','Variance',noiseVar);
    % The channel definition above does exactly the following. We may use the following code
    % instead to be able save the noise file.
    % Do the following to make random noise and save it to file to be used by python.
    randDataI = randn(size(modOut), class(modOut));
    randDataQ = randn(size(modOut), class(modOut));
    chanNoise = noiseVar*(randDataI + 1i*randDataQ) / sqrt(2);
    save(strcat(outPath,'/chanNoise.mat'),'chanNoise');
    % Or just read the previously random noise to be consistent.
    chanNoise = load(strcat(outPath,'/chanNoise.mat')).chanNoise;
rxSig = modOut + chanNoise;
rxLLR = nrSymbolDemodulate(rxSig,'QPSK',noiseVar);
    save(strcat(outPath,'/rxLLR.mat'),'rxLLR');
decIn = nrRateRecoverPolar(rxLLR,K,N,iBIL);
    save(strcat(outPath,'/decIn.mat'),'decIn');
decBits = nrPolarDecode(decIn,K,E,L,nMax,iIL,crcLen);
    save(strcat(outPath,'/decBits.mat'),'decBits');
strrep(num2str(reshape(decBits.',1,[])),' ','')
ans = '100100110110000110100110000010111100001010001110100010'