# Matlab Rayleigh Fading Channel Simulation?

Status
Not open for further replies.

#### davyzhu Hi all,

I have got a Rayleigh Fading Channel Simulation code by Matlab.

The code list below:
a = sqrt(0.5)*( randn( 1, symbols_per_frame) + j*randn( 1, symbols_per_frame) );
% complex noise
noise = sqrt(variance)*( randn(1,symbols_per_frame) + j*randn(1,symbols_per_frame) );
% in all

Is the code right? If not right, how to modify it?

Best regards,
Davy

#### manasiri

##### Member level 5 #### mehtesham

##### Junior Member level 3 matlab rayleigh channel

but in some simulation i did:

a = randn( 1, symbols_per_frame) + j*randn( 1, symbols_per_frame) ;

% complex noise

noise = randn(1,symbols_per_frame) + j*randn(1,symbols_per_frame) ;

% in all

Nt is number of Tx antenna

#### davyzhu Hi mehtesham,

Thank you I am confused with your formular. If Nt increase, sqrt(SNR/Nt) will decrease?
BTW, code I got is SNR/Nt=0.5. Does it mean normalize?

Best regards,
Davy

#### carpa

##### Member level 3 rayleigh channel matlab code

You need filter the output by a digital filter.

#### ssstar

##### Junior Member level 1 phase ditortion channel+matlab

I am sorry to tell you。
I don't think you are right.
because it is very not accurent, you must know randn() is not very stable.

I suggest that you should look at the papers of Clark,Jakes, and C.xiao.
there are three ways to model Rayleight channel, which are IDFT/WSS/AR.
if you just play , forget it.

#### davyzhu frequency selective channel matlab

Hi,

I have read the Probability book. The phase shift is uniformly distribution. And the fading is Rayleigh distribution.

I am interested in paper about Rayleigh channel.

But what's IDFT/WSS/AR mean?

#### mehtesham

##### Junior Member level 3 #### mimomod

##### Member level 4 nakagami distribution matlab

Hi davyzhu,

the matlab codes you wrote are basically right. Off course others could argue that the randn() function is not stable or how to define the right power, etc. But basically, it is right.

But.....when I read your codes I found out that the codes are a little strange for simulating wireless channels. First, the codes generated different fading for each symbol. This happens rarely in practice since the channel will be more or less constant for several symbols, otherwise we have much difficulties to do signal processing at the receiver to get the original data back.

Secondly, the codes generated flat fading channel (more accurately, varying flat fading channel). This fading is the simplest fading in wireless environment. More widely used model is frequency selective fading channel, where you generate a kind of filter with its coefficients are the realizations of flat fading channel as generated by your codes. Better, thus more realistic, you take into account the Doppler effect for fading channel due to movement of TX and/or RX. This generation of fading channel needs more sound knowledge on statistics. You could see the book by Paetzold on fading channels. The book was uploaded in this forum, but sorry that I forget where to find.

best

#### wee

##### Junior Member level 2 simulation rayleigh channel

Hi all,

I am sorry if i got this wrong.

For Multipath fading, can i simply add a tau difference to the orignating signal and then use randn function to create an awgn environment?

(*Sorry for the highjacked*)

Thank you.

Regards.

#### lincolndsp

##### Banned mimomod said:
Hi davyzhu,

the matlab codes you wrote are basically right. Off course others could argue that the randn() function is not stable or how to define the right power, etc. But basically, it is right.

But.....when I read your codes I found out that the codes are a little strange for simulating wireless channels. First, the codes generated different fading for each symbol. This happens rarely in practice since the channel will be more or less constant for several symbols, otherwise we have much difficulties to do signal processing at the receiver to get the original data back.

Secondly, the codes generated flat fading channel (more accurately, varying flat fading channel). This fading is the simplest fading in wireless environment. More widely used model is frequency selective fading channel, where you generate a kind of filter with its coefficients are the realizations of flat fading channel as generated by your codes. Better, thus more realistic, you take into account the Doppler effect for fading channel due to movement of TX and/or RX. This generation of fading channel needs more sound knowledge on statistics. You could see the book by Paetzold on fading channels. The book was uploaded in this forum, but sorry that I forget where to find.

What changes should be made to fix this problem

mimomod said:
First, the codes generated different fading for each symbol. This happens rarely in practice since the channel will be more or less constant for several symbols

And is the original code multiplied by Rayleigh fading is a passband signal
or baseband?

#### Noo10

##### Newbie level 4 hi all
I want to genarte wireless source code for matlab Ka...

#### dalysk

##### Newbie level 5 #### amihomo

##### Full Member level 5 simuation of fast fading channel mat lab

davyzhu said:
Hi all,

I have got a Rayleigh Fading Channel Simulation code by Matlab.

The code list below:
a = sqrt(0.5)*( randn( 1, symbols_per_frame) + j*randn( 1, symbols_per_frame) );
% complex noise
noise = sqrt(variance)*( randn(1,symbols_per_frame) + j*randn(1,symbols_per_frame) );
% in all

Is the code right? If not right, how to modify it?

Best regards,
Davy

hi,

essentialy the fading process has two effects :
1)a phase distortion which is modeled as a uniform R.V in the interval [-Π,Π]
2)a push distortion which is modeled as a rayleigh , rice , nakagami , ... distribution.

in simulation we assume that the phase distortion in completeley compensated in the receiver and only analyze the effect of push distortion .

based on the above , your code seems to be correct.

regards

#### gr8_halem

##### Newbie level 4 may u try this;

chan=rayleighchan;
msx_rx=filter(chan,msg_mod);
msg_noise(z, =(msg_rx);
end

#### changfa rayleigh channel in matlab code

davyzhu said:
Hi all,

I have got a Rayleigh Fading Channel Simulation code by Matlab.

The code list below:
a = sqrt(0.5)*( randn( 1, symbols_per_frame) + j*randn( 1, symbols_per_frame) );
% complex noise
noise = sqrt(variance)*( randn(1,symbols_per_frame) + j*randn(1,symbols_per_frame) );
% in all

Is the code right? If not right, how to modify it?

Best regards,
Davy

The codes are no problem, but the physical meaning behind them is another story.

As one friend pointed out, your channel changes so fast in time domain that every symbol experiences independent fading. This is rare in reality because system designer want the TX/RX simple and rarely choose such operating point. A simple model is block-fading channel. To model this, you need to know the coherence time of the channel as well as your symbol duration, then you know how many symbols can be assumed experieceing same channel coefficients. For different block, channel is independent.

(For more accurate channel, you need to take Doppler spectrum into account. Doppler spectrum determines how fast your channel is evolved in time. To simulate this, generally a filtering is done. )

#### waqasbukhari

##### Newbie level 4 matlab code for rayleigh channel

following is the relevant code which i have used in my simulations in one of the projects "design and optimization of cooperative diversity in wireless sensor networks"

clear;

N =100; %Enter the number of random scaterers

M =1000 %Enter the no of realizations

A = 1 %Enter the value of A

fc =1000; %carrier frequency

Fs=4000; %sampling frequency greater than Nyquist rate

w = 2 * pi * fc ;

t = [0 1/Fs) M-1)*(1/Fs)];

L=length(t);

theta = (rand(N,1) * 2 * pi) - pi;

Ak = (rand(N,1) * 2) - 1;

X = zeros(1,L) ;

for m = 1:N

X=X+Ak(m)*cos(w.*t+theta(m));

end

% Analyzing that X(t) is a narrow-band spectral process

Y = fft(X) ;

Y = fftshift(Y) ;

plot(abs(Y)) ;

title( 'Magnitude of fft of a single realisation of X(t)') ;

xlabel( 'Frequency' ) ;

ylabel( 'Magnitude' ) ;

pause

%Calculating XI and XQ

Ak = (rand(N,M) * 2 ) - 1;

theta = (rand(N,M) * 2 * pi) - pi;

XI = zeros(1,M ) ;

XQ = zeros(1,M ) ;

for i=1:N

XI = XI+(Ak(i, .*cos(theta(i, ));

XQ = XQ+(Ak(i, .*sin(theta(i, ));

end

%Calculating the central moments and beta values for in and quadrature phase

U2_inphase = moment(XI,2);

U3_inphase = moment(XI,3);

U4_inphase = moment(XI,4);

B1_inphase = (U3_inphase)^2/(U2_inphase)^3

B2_inphase = (U4_inphase)/(U2_inphase)^2

%Calculating the envelope r from the M realisations of XI and XQ

r = sqrt(XI .^ 2 + XQ .^ 2);

phi = atan(XQ ./ XI);

R=hist(r,100);

index = 1:100 ;

R_index = (index/length(index)*ceil( max(r)));

stem(R_index,R)

title( 'Histogram of distribution of the Envelope R' ) ;

xlabel('R') ;

ylabel('Frequency of R' ) ;

pause

% including line of sight component

for a = 0:5

XL = a*cos(2*pi*fc*t);

XI_2 = XI + XL;

r = sqrt(XI_2 .^ 2 + XQ .^ 2);

R = hist(r,100);

index = 1:100 ;

R_index = (index/length(index)*ceil( max(r)));

subplot( 2, 3,(a +1));

plot(R_index,R)

end

#### saeddawoud

##### Full Member level 3 davyzhu said:
...
a = sqrt(0.5)*( randn( 1, symbols_per_frame) + j*randn( 1, symbols_per_frame) );
...

Why is this 0.5 factor?

#### tamoor

##### Newbie level 6 can any one share complete rayleigh fading channel for indoor communication with multiple users.
please share here, mathworks i get confuse.

##### Newbie level 2 i need complex rayleigh for ten antennas is this procedure right
for n=1:10;
G3=randn((2*n),M);
G4=randn((2*n),M);

bb=0;
RR=zeros(n,M);

for ii=1:2:2*n;
bb=bb+1;
Rr=abs(G3(ii, +1i*G3(ii+1, ); % Rayleigh fading hnk, 10x100
Ri=abs(G4(ii, +1i*G4(ii+1, );
yy=(1/sqrt(2))*(Rr+1*j*Ri);% complex Rayleigh fading hnk, 10x100
% yy=G3(ii+1)+1i*G4(ii+1, ;
hnk(bb, =yy;
end

Status
Not open for further replies.