Examples Using Fading Channels

The following examples use fading channels:

Power of a Faded Signal

The code below plots a faded signal's power (versus sample number). The code also illustrates the syntax of the filter and rayleighchan functions and the state retention of the channel object. Notice from the output that NumSamplesProcessed equals the number of elements in sig, the signal.

c = rayleighchan(1/10000,100);
sig = j*ones(2000,1); % Signal
y = filter(c,sig); % Pass signal through channel.
c % Display all properties of the channel object.

% Plot power of faded signal, versus sample number.
plot(20*log10(abs(y)))

Below are the output and the plot.

c =
 
             ChannelType: 'Rayleigh'
       InputSamplePeriod: 1.0000e-004
         MaxDopplerShift: 100
              PathDelays: 0
           AvgPathGaindB: 0
      NormalizePathGains: 1
            StoreHistory: 0
               PathGains: -1.1700 + 0.1288i
      ChannelFilterDelay: 0
    ResetBeforeFiltering: 1
     NumSamplesProcessed: 2000

Comparing Empirical with Theoretical Results

The code below creates a frequency-flat Rayleigh fading channel object and uses it to process a DBPSK signal consisting of a single vector. The example continues by computing the bit error rate of the system for different values of the signal-to-noise ratio. Notice that the example uses filter before awgn; this is the recommended sequence to use when you combine fading with AWGN.

% Create Rayleigh fading channel object.
chan = rayleighchan(1/10000,100);

% Generate data and apply fading channel.
M = 2; % DBPSK modulation order
tx = randint(50000,1,M);  % Random bit stream
dpskSig = dpskmod(tx,M);  % DPSK signal
fadedSig = filter(chan,dpskSig); % Effect of channel

% Compute error rate for different values of SNR.
SNR = 0:2:20; % Range of SNR values, in dB.
for n = 1:length(SNR)
   rxSig = awgn(fadedSig,SNR(n)); % Add Gaussian noise.
   rx = dpskdemod(rxSig,M); % Demodulate.
   % Compute error rate.
   % Ignore first sample because of DPSK initial condition.
   [nErrors, BER(n)] = biterr(tx(2:end),rx(2:end));
end

% Compute theoretical performance results, for comparison.
BERtheory = berfading(SNR,'dpsk',M,1);

% Plot BER results.
semilogy(SNR,BERtheory,'b-',SNR,BER,'r*');
legend('Theoretical BER','Empirical BER');
xlabel('SNR (dB)'); ylabel('BER');
title('Binary DPSK over Rayleigh Fading Channel');

The resulting plot shows that the simulation results are close to the theoretical results computed by berfading.

Working with Delays

The value of a channel object's ChannelFilterDelay property is the number of samples by which the output of the channel lags the input. If you compare the input and output data sets directly, then you must take the delay into account by using appropriate truncating or padding operations.

The example illustrates one way to account for the delay before computing a bit error rate.

M = 2; % DQPSK modulation order
bitRate = 50000;

% Create Rayleigh fading channel object.
ch = rayleighchan(1/bitRate,4,[0 0.5/bitRate],[0 -10]);
delay = ch.ChannelFilterDelay;

tx = randint(50000,1,M); % Random bit stream
dpskSig = dpskmod(tx,M); % DPSK signal
fadedSig = filter(ch,dpskSig); % Effect of channel
rx = dpskdemod(fadedSig,M); % Demodulated signal

% Compute bit error rate, taking delay into account.
% Remove first sample because of DPSK initial condition.
tx = tx(2:end); rx = rx(2:end);
% Truncate to account for channel delay.
tx_trunc = tx(1:end-delay); rx_trunc = rx(delay+1:end);
[num,ber] = biterr(tx_trunc,rx_trunc) % Bit error rate

The output below shows that the error rate is small. If the example had not compensated for the channel delay, then the error rate would have been close to 1/2.

num =

   845


ber =

    0.0169

More Information About Working with Delays.   The discussion in Effect of Delays on Recovery of Convolutionally Interleaved Data describes two typical ways to compensate for delays. Although the discussion there is about interleaving operations instead of channel modeling, the techniques involving truncating and padding data are equally applicable to channel modeling.

Quasi-Static Channel Modeling

Typically, a path gain in a fading channel changes insignificantly over a period of 1/(100fd) seconds, where fd is the maximum Doppler shift. Because this period corresponds to a very large number of bits in many modern wireless data applications, assessing performance over a statistically significant range of fading would entail simulating a prohibitively large amount of data. Quasi-static channel modeling provides a more tractable approach, which you can implement using these steps:

  1. Generate a random channel realization using a maximum Doppler shift of 0.

  2. Process some large number of bits.

  3. Compute error statistics.

  4. Repeat the steps above many times to produce a distribution of the performance metric.

The example below illustrates the quasi-static channel modeling approach.

M = 4; % DQPSK modulation order
numBits = 10000; % Each trial uses 10000 bits.
numTrials = 20; % Number of BER computations

% Note: In reality, numTrials would be a large number
% to get an accurate estimate of outage probabilities
% or packet error rate.
% Use 20 here just to make the example run more quickly.

% Create Rician channel object.
chan = ricianchan; % Static channel
chan.KFactor = 3; % Rician K-factor
% Because chan.ResetBeforeFiltering is 1 by default,
% FILTER resets the channel in each trial below.

% Compute error rate once for each independent trial.
for n = 1:numTrials
   tx = randint(numBits,1,M);  % Random bit stream
   dpskSig = dpskmod(tx,M);  % DPSK signal
   fadedSig = filter(chan, dpskSig); % Effect of channel
   rxSig = awgn(fadedSig,20);  % Add Gaussian noise.
   rx = dpskdemod(rxSig,M);  % Demodulate.

   % Compute number of symbol errors.
   % Ignore first sample because of DPSK initial condition.
   nErrors(n) = symerr(tx(2:end),rx(2:end))
end
per = mean(nErrors > 0) % Proportion of packets that had errors

While the example runs, the Command Window displays the growing list of symbol error counts in the vector nErrors. It also displays the packet error rate at the end. The sample output below shows a final value of nErrors and omits intermediate values. Your results might vary because of randomness in the example.

nErrors =

  Columns 1 through 9 

     0     0     0     0     0     0     0     0     0

  Columns 10 through 18 

     0     0     0     0     7     0     0     0     0

  Columns 19 through 20 

     0   216


per =

    0.1000

More About the Quasi-Static Technique.   As an example to show how the quasi-static channel modeling approach can save computation, consider a wireless local area network (LAN) in which the carrier frequency is 2.4 GHz, mobile speed is 1 m/s, and bit rate is 10 Mb/s. The following expression shows that the channel changes insignificantly over 12,500 bits:

A traditional Monte Carlo approach for computing the error rate of this system would entail simulating thousands of times the number of bits shown above, perhaps tens of millions of bits. By contrast, a quasi-static channel modeling approach would simulate a few packets at each of about 100 locations to arrive at a spatial distribution of error rates. From this distribution one could determine, for example, how reliable the communication link is for a random location within the indoor space. If each simulation contains 5,000 bits, then 100 simulations would process half a million bits in total. This is substantially fewer bits compared to the traditional Monte Carlo approach.

Filtering Using a Loop

The section Configuring Channel Objects Based on Simulation Needs indicates how to invoke the filter function multiple times while maintaining continuity from one invocation to the next. The example below invokes filter within a loop and uses the small data sets from successive iterations to create an animated effect. The particular channel in this example is a Rayleigh fading channel with two discrete major paths.

% Set up parameters.
M = 4; % QPSK modulation order
bitRate = 50000; % Data rate is 50 kb/s.
numTrials = 125; % Number of iterations of loop

% Create Rayleigh fading channel object.
ch = rayleighchan(1/bitRate,4,[0 2e-5],[0 -9]);
% Indicate that FILTER should not reset the channel
% in each iteration below.
ch.ResetBeforeFiltering = 0;

% Initialize scatter plot.
h = scatterplot(0);

% Apply channel in a loop, maintaining continuity.
% Plot only the current data in each iteration.
for n = 1:numTrials
   tx = randint(500,1,M); % Random bit stream
   pskSig = pskmod(tx,M); % PSK signal
   fadedSig = filter(ch, pskSig); % Effect of channel

   % Plot the new data from this iteration.
   h = scatterplot(fadedSig,1,0,'b.',h);
   axis([-1.8 1.8 -1.8 1.8]) % Adjust axis limits.
   drawnow; % Refresh the image.
end

The scatter plot changes with each iteration of the loop, and the exact content varies because the fading process involves random numbers. Below are some snapshots of typical images that the example can produce.

Sample Scatter Plot (a)

Sample Scatter Plot (b)

Storing Channel State History

By default, the PathGains property of a channel object stores the current complex path gain vector.

Setting the StoreHistory property of a channel to true will make it store the last N path gain vectors, where N is the length of the vector processed through the channel. The following code illustrates this property:

h = rayleighchan(1/100000, 130);  % Rayleigh channel
tx = randint(10, 1, 2);           % Random bit stream
dpskSig = dpskmod(tx, 2);         % DPSK signal
h.StoreHistory = true;            % Allow states to be stored
y = filter(h, dpskSig);           % Run signal through channel
h.PathGains                       % Display the stored path gains data

h.PathGains =

  -0.0460 - 1.1873i
  -0.0439 - 1.1881i
  -0.0418 - 1.1889i
  -0.0397 - 1.1898i
  -0.0376 - 1.1904i
  -0.0355 - 1.1912i
  -0.0334 - 1.1920i
  -0.0313 - 1.1928i
  -0.0296 - 1.1933i
  -0.0278 - 1.1938i

The last element is the current path gain of the channel.

Note that setting StoreHistory to true will significantly slow down the execution speed of the channel's filter function.


© 1994-2005 The MathWorks, Inc.