We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for
Did you mean:
438 Views
Registered: ‎03-30-2018

## Generate random Rayleigh Fading channel

Hi,

Is anyone here can share how to generate random Rayleigh fading channel in a matrix form of  5 x 5?

If I can use H = 1/sqrt(2)*(randn(5,5) + 1i*randn(5,5)) in MATLAB, then, how to write it in C++?

Thank you very much.

4 Replies
Scholar
406 Views
Registered: ‎05-21-2015

## Re: Generate random Rayleigh Fading channel

The easy way?  Random numbers are commonly generated on FPGAs using linear feedback shift registers.  With a long enough register, you can add about 12 results together to get something that looks like a Gaussian.

The hard way?  There are much better ways of generating Gaussian numbers using floating point math.  Feel free to check out Numerical Recipes for some examples.

Dan

371 Views
Registered: ‎03-30-2018

## Re: Generate random Rayleigh Fading channel

Thank you. But from the channel, how we can generate hermitian positive definite matrix, Z=HH^Herm, where H is the random Rayleigh fading channel which is iid and follows CN(0,1) distribution? Do we still need to generate a long register like in linear feedback shift register and do multiplication?

Scholar
346 Views
Registered: ‎05-21-2015

## Re: Generate random Rayleigh Fading channel

You might need to explain to me what this matrix H is.  Does it represent a band diagonal system, such as might be created from an FIR filter or something else?

Dan

302 Views
Registered: ‎03-30-2018

## Re: Generate random Rayleigh Fading channel

I tried to generate Rayleigh fading channel that follows normal distribution with zero-mean unit variance. I have tried to generate in in C++ and it worked. However, it did not work in Vivado HLS even though in C Simulation. My code is as below:

```#ifndef _rayleighfadingchannel_H_

#include <complex>

#define rows  4
#define cols  8
#define order  4

typedef  std:: complex<float>  cfloat_t;

//Prototype of top level function for C-synthesis

```

cpp file:

```#include "rayleighfadingchannel_h.h"

{

//library to generate Rayleigh fading channel
//mt19937 gen((int)time(0));
//normal_distribution<double> dist(0.0, 1.0);

//number of rows and columns
#define rows = 4;
#define cols = 8;
#define order = 4;
int i,j,k;
const double sq = sqrt(2.0);

for (int i = 0; i < rows; i++)	{
for (int j = 0; j < cols; j++) {
H[i][j] = cfloat_t(dist(gen), dist(gen)) / sq;
}
}

//====================================================================

//Generate Hermitian positive definite matrix, Z=HH^H
for (int i = 0; i < order; i++)
{
for (int j = 0; j < order; j++)

{
Z[i][j] = 0.0;
for (int k = 0; k < cols; k++)
Z[i][j] += H[i][k] * conj(H[j][k]);
}
}
}```

testbench file:

```#include <iostream>
#include <complex>
#include <cmath>

int main()
{
int i, j, k;

//library to generate Rayleigh fading channel
mt19937 gen(time(0));
normal_distribution<double> dist(0.0, 1.0);

cfloat_t Z[10][10],H[rows][cols];

//call multiplication function

//print
std::cout << "\nChannel matrix, H:" << "\n";
for (int i = 0; i < rows; ++i)
{
std::cout << "{";
for (int j = 0; j < cols; ++j)
{
std::cout << H[i][j] << ' ';
if (j == cols - 1)
std::cout << "}" << std::endl;
else
std::cout << ",";
}
}

//print
std::cout << "\nHermitian matrix, Z:" << "\n";
for (int i = 0; i < order; ++i)
{
std::cout << "{";
for (int j = 0; j < order; ++j)
{
std::cout << Z[i][j] << ' ';
if (j == order - 1)
std::cout << "}" << std::endl;
else
std::cout << ",";
}
}

return 0;
}```

the error that appeared: