UPGRADE YOUR BROWSER

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 
Search instead for 
Did you mean: 
Adventurer
Adventurer
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.

0 Kudos
4 Replies
Scholar dgisselq
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

Adventurer
Adventurer
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?

0 Kudos
Scholar dgisselq
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

0 Kudos
Adventurer
Adventurer
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:

header file:

#ifndef _rayleighfadingchannel_H_
#define _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
void rayleighfadingchannel(cfloat_t Z[10][10],cfloat_t H[rows][cols]);

#endif //__rayleighfadingchannel_H__ not defined

cpp file:

#include "rayleighfadingchannel_h.h"

void rayleighfadingchannel(cfloat_t Z[10][10],cfloat_t H[rows][cols])
{
				
//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);

//Generate Rayleigh fading channel, H
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 "rayleighfadingchannel_h.h"
#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
	rayleighfadingchannel(Z,H);
	
	//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:

Compiling ../../../../rayleighfadingchannel_tb.cpp in debug mode
../../../../rayleighfadingchannel_tb.cpp: In function 'int main()':
../../../../rayleighfadingchannel_tb.cpp:11:2: error: 'mt19937' was not declared in this scope
../../../../rayleighfadingchannel_tb.cpp:11:10: error: expected ';' before 'gen'
../../../../rayleighfadingchannel_tb.cpp:12:2: error: 'normal_distribution' was not declared in this scope
../../../../rayleighfadingchannel_tb.cpp:12:22: error: expected primary-expression before 'double'
../../../../rayleighfadingchannel_tb.cpp:12:22: error: expected ';' before 'double'
make: *** [obj/rayleighfadingchannel_tb.o] Error 1
ERROR: [SIM 211-100] 'csim_design' failed: compilation error(s).

 

Thanks for any response. 

0 Kudos