Recover Data Bits with GMSK Modulation and Demodulation
This example show how to convert data bits into modulated symbols and then recover the original bits through demodulation by using the GMSK Modulator and GMSK Demodulator blocks, respectively. This example includes two Simulink® models: gmskModDemodScalar for specifying scalar inputs and gmskModDemodVector for specifying vector inputs, enabling you to work with each input mode separately. The GMSKModDemod subsystem in these models supports HDL code generation. To verify the behavior of these blocks, the example compares the input to the GMSK Modulator block with the output from the GMSK Demodulator block.
Set Up Input Parameters
Set up workspace parameters for the Simulink model. The model in this example uses these parameters to configure the GMSK Modulator and GMSK Demodulator blocks. These parameters control the behavior of these blocks. You can modify these variables according to your requirement.
bandwidthTimeProduct = 0.3; % Bandwidth time product pulseLength = 2; % Pulse length samplesPerSymbol = 4; % Number of samples per symbol decisionMethod = 'Approximate log-likelihood ratio'; gmskTraceback = 16; numBitsPerFrame = 1000; numFrames = 10; outputType = 'Vector'; % Select 'Scalar' or 'Vector' gmskMod = comm.GMSKModulator('BitInput', true, ... 'BandwidthTimeProduct', bandwidthTimeProduct, ... 'PulseLength',pulseLength, ... 'SamplesPerSymbol', samplesPerSymbol); gmskDemod = comm.GMSKDemodulator('BitOutput', true, ... 'BandwidthTimeProduct', bandwidthTimeProduct, ... 'PulseLength',pulseLength, ... 'SamplesPerSymbol', samplesPerSymbol, ... 'DecisionMethod',decisionMethod,... 'TracebackDepth', gmskTraceback); rxFrameSize = samplesPerSymbol*numBitsPerFrame; rng('default'); numErrs = 0;
Generate Input Data and Perform GMSK Modulation
Generate random data bits and a valid input signal for the GMSK Modulator block.
for frame = 1:numFrames % Generate random bits data(:,frame) = randi([0 1], numBitsPerFrame, 1); %#ok<*SAGROW> % GMSK Modulation modSignal(:,frame) = gmskMod(data(:,frame)); end txBits(:) = data(:)>0; txWaveformML = modSignal(:); rxSignal = txWaveformML;
Demodulate GMSK-modulated Data
Demodulate GMSK-modulated data symbols into data bits.
for frame = 1:numFrames demodSignal = gmskDemod(rxSignal((frame-1)*rxFrameSize+(1:rxFrameSize))); numErrs = numErrs + nnz(xor(data(1:end-gmskTraceback,frame),demodSignal(gmskTraceback+1:end)<0)); end
Run Model
Running the model imports the input signal variables to the model and exports dataOut and a control signal validOut to the MATLAB® workspace.
if strcmp(outputType,'Vector') modelName = 'gmskModDemodVector'; %#ok<*UNRCH> else modelName = 'gmskModDemodScalar'; end load_system(modelName); if strcmp(decisionMethod, 'Hard decision') set_param([modelName '/GMSKModDemod/GMSK Demodulator'], 'DecisionType', 'Hard'); else set_param([modelName '/GMSKModDemod/GMSK Demodulator'], 'DecisionType', 'Soft'); end txBitsSL = txBits(:); out = sim(modelName); rxDecBitsSL = out.decBits(out.decBitsValid);
Compare Modulator Input with Demodulator Output
Compare the data bits input to the GMSK Modulator block with the data bits output from the GMSK Demodulator block.
if isequal(txBitsSL(1:end-4*gmskTraceback), rxDecBitsSL) fprintf('Comparison of Modulator Input with Demodulator Output\n'); fprintf('Data bits at the input match with the data bits at the output.\n'); else fprintf('Comparison of Modulator Input with Demodulator Output\n'); fprintf('Data bits at the input do not match with the data bits at the output.\n'); end
Comparison of Modulator Input with Demodulator Output Data bits at the input match with the data bits at the output.