MATLAB Examples

Channel Filtering Using a For Loop

This example filters input data through a Rayleigh fading channel within a for loop. It uses the small data sets from successive iterations to create an animated effect. The Rayleigh fading channel has two discrete major paths. For information on filtering data through a channel multiple times while maintaining continuity from one invocation to the next, see Configuring Channel Objects Based on Simulation Needs.

Set up parameters. Specify a bit rate of 50e3 Hz, and a loop iteration count of 125. Create a QPSK modulator and Rayleigh fading channel objects.

bitRate = 50000;    % Data rate is 50 kb/s
numTrials = 125;    % Number of iterations of loop

M = 4; % QPSK modulation order
qpskMod = comm.QPSKModulator;

rayChan = comm.RayleighChannel('SampleRate',bitRate,'MaximumDopplerShift',4,'PathDelays',[0 2e-5],'AveragePathGains',[0 -9]);

Initialize a scatter plot.

scatterPlot = comm.ConstellationDiagram;

Apply channel in a loop, maintaining continuity. Plot only the current data in each iteration.

for n = 1:numTrials
   tx = randi([0 M-1],500,1); % Generate random bit stream
   pskSig = qpskMod(tx); % PSK modulate signal
   fadedSig = rayChan(pskSig); % Apply channel effects

   % Plot the new data from this iteration.