| Author |
Message |
reddy2
Joined: 29 Mar 2006 Posts: 10
|
07 Aug 2006 2:13 rayleigh fading channel matlab code |
|
|
|
|
Can some one help me with matlab code for rayleigh fading channel .
Thank you
|
|
| Back to top |
|
 |
Google AdSense

|
07 Aug 2006 2:13 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
carpa
Joined: 12 Nov 2004 Posts: 78 Helped: 5
|
07 Aug 2006 9:02 matlab code for rayleigh distribution |
|
|
|
|
| If you have communication blockset in simulink, you can try "Multipath Rayleigh Fading Channels" in it.
|
|
| Back to top |
|
 |
iTdl
Joined: 25 Jul 2005 Posts: 143 Helped: 5
|
08 Aug 2006 9:41 average fade duration matlab |
|
|
|
|
Here is a matlab code:
You can mention the number of taps and corresponding power:
tap_delay=[0 10 20 30 40 50];
tap_power_db=[-3.9234 -5.2288 -6.9897 -13.0103 -15.2288 -16.9897];
L=length(tap_delay);
tap_power_lin=10.^(tap_power_db/10);
temp=randn(1,L)+j*randn(1,L);
for k=1:L
h(k)=sqrt(tap_power_lin(k)/2).*real(temp(k))+j*sqrt(tap_power_lin(k)/2).*imag(temp(k));
end
|
|
| Back to top |
|
 |
ahmedseu
Joined: 31 Jul 2006 Posts: 251 Helped: 24 Location: Bahrain
|
08 Aug 2006 16:06 rayleigh distribution matlab |
|
|
|
|
% Calculating average fade duration and plotting envelope of Rayleigh distribution for specified value of fm and ro %
%************************** ****************************************************************************************%
close all
clear all
clc
N=256; %Number of frequency samples
M=8192; %Number of time samples
% Required parameters for INPUT: fm and row (r0)
fm=input('ENTER THE VALUE OF fm [20 Hz, 200Hz]:')
r0=input('ENTER THE VALUE OF r0 [1,0.1,0.01]:')
y=1;
Afd_p=0; % Average fade duration; practical value
Nr_p=0; % Number of Zero-crossing level per second
Rrms_p=0; % Practically calculated R-rms value
while(y<=1)
delta_f=2*fm/N; % Frequency resolution
delta_t=N/(M-1)/2/fm; % Time resolution
%************************* NOTE **********************************%
% "If N=M-1, then the time resolution delta_t=1/2*fm, which may not be
% small so take M >> N. When M > N, we need to pad with zero values
% before taking IFFT."
X1(1)=randn(1); % Generating Gaussain Random with N(0,1)
X1=X1(1);
Y1(1)=randn(1);
Y1=Y1(1);
for m=2 N/2)+1
X1(m)=randn(1);
X2(m)=randn(1);
Y1(m)=randn(1);
Y2(m)=randn(1);
X(m)=X1(m)+i*X2(m);
Y(m)=Y1(m)+i*Y2(m);
end
for m=1 N/2)+1
X(M-m+1)=conj(X(m+1));
Y(M-m+1)=conj(Y(m+1));
end
% Sample Se(f) Spectrum
for jj=1:N/2
SeF(jj)=1.5/(pi*fm*(sqrt(1-((jj-1)*delta_f/fm)^2)));
end
% Calculating Edge Value by extending the slope prior to passband edge to edge
SeF((N/2)+1)=SeF(N/2)+SeF(N/2)-SeF((N/2)-1);
for m=1:N/2
SeF(M-m+1)=SeF(m+1);
end
for m=1:M
X_shaped(m)=X(m)*sqrt(SeF(m));
Y_shaped(m)=Y(m)*sqrt(SeF(m));
end
X_component=real(ifft(X_shaped)); % Only considering the real part
Y_component=real(ifft(Y_shaped));
%************* Find R-rms value and envelope of Rayleigh Distribution ***********%
R=sqrt(X_component.^2+Y_component.^2);
r=20*log10(R);
rms=sqrt(mean(R.^2));
Rrms=20*log10(rms);
level=20*log10(r0*rms);
R=r-Rrms;
figure
plot(1:8192,R,'r')
xlabel ('Time Samples, M=8192');
ylabel ('Instantaneous Power dB');
title ('Figure(1):Rayleigh fading signal for Specified fm & r0 ');
% Calculating (Practically) Number of Zero Level Crossing and Average Fade Duration %
h=1;
c=0;
C1=0;
NUM=0;
while h<=M
if r(h)<=level
i=h;
while i<=M
if r(i)>=level
NUM=NUM+1;
break;
end
i=i+1;
end
c=i-h;
C1=C1+c;
h=i-1;
end
h=h+1;
end
Afd_p=Afd_p+(C1/NUM)*delta_t;
Nr_p=Nr_p+NUM*delta_f;
Rrms_p=Rrms_p+Rrms;
y=y+1;
end
%************ Theoretical calculation of Number of Zero Level Crossing (Nr) and Average Fade Duration ************* %
Nr_theoretical=sqrt(2*pi)*fm*r0*exp(-r0^2);
z1=exp(r0^2)-1;
z2=r0*fm*sqrt(2*pi);
Average_fade_duration_theoretical =z1/z2;
rowdb=10*log10(r0) ;
Rrms_theoretical=Rrms+rowdb;
%*********************** Displayiing Calculated values ************************ %
Nr_practical=(Nr_p);
Nr_practical
Nr_theoretical
Average_fade_duration_Practical=(Afd_p);
Average_fade_duration_Practical
Average_fade_duration_theoretical =z1/z2
Rrms_Practical=Rrms_p
Rrms_theoretical
|
|
| Back to top |
|
 |
thewinner
Joined: 26 Oct 2009 Posts: 1 Location: bangalore
|
27 Oct 2009 22:57 Re: rayleigh distribution matlab |
|
|
|
|
| ahmedseu wrote: |
% Calculating average fade duration and plotting envelope of Rayleigh distribution for specified value of fm and ro %
%************************** ****************************************************************************************%
close all
clear all
clc
N=256; %Number of frequency samples
M=8192; %Number of time samples
% Required parameters for INPUT: fm and row (r0)
fm=input('ENTER THE VALUE OF fm [20 Hz, 200Hz]:')
r0=input('ENTER THE VALUE OF r0 [1,0.1,0.01]:')
y=1;
Afd_p=0; % Average fade duration; practical value
Nr_p=0; % Number of Zero-crossing level per second
Rrms_p=0; % Practically calculated R-rms value
while(y<=1)
delta_f=2*fm/N; % Frequency resolution
delta_t=N/(M-1)/2/fm; % Time resolution
%************************* NOTE **********************************%
% "If N=M-1, then the time resolution delta_t=1/2*fm, which may not be
% small so take M >> N. When M > N, we need to pad with zero values
% before taking IFFT."
X1(1)=randn(1); % Generating Gaussain Random with N(0,1)
X1=X1(1);
Y1(1)=randn(1);
Y1=Y1(1);
for m=2 N/2)+1
X1(m)=randn(1);
X2(m)=randn(1);
Y1(m)=randn(1);
Y2(m)=randn(1);
X(m)=X1(m)+i*X2(m);
Y(m)=Y1(m)+i*Y2(m);
end
for m=1 N/2)+1
X(M-m+1)=conj(X(m+1));
Y(M-m+1)=conj(Y(m+1));
end
% Sample Se(f) Spectrum
for jj=1:N/2
SeF(jj)=1.5/(pi*fm*(sqrt(1-((jj-1)*delta_f/fm)^2)));
end
% Calculating Edge Value by extending the slope prior to passband edge to edge
SeF((N/2)+1)=SeF(N/2)+SeF(N/2)-SeF((N/2)-1);
for m=1:N/2
SeF(M-m+1)=SeF(m+1);
end
for m=1:M
X_shaped(m)=X(m)*sqrt(SeF(m));
Y_shaped(m)=Y(m)*sqrt(SeF(m));
end
X_component=real(ifft(X_shaped)); % Only considering the real part
Y_component=real(ifft(Y_shaped));
%************* Find R-rms value and envelope of Rayleigh Distribution ***********%
R=sqrt(X_component.^2+Y_component.^2);
r=20*log10(R);
rms=sqrt(mean(R.^2));
Rrms=20*log10(rms);
level=20*log10(r0*rms);
R=r-Rrms;
figure
plot(1:8192,R,'r')
xlabel ('Time Samples, M=8192');
ylabel ('Instantaneous Power dB');
title ('Figure(1):Rayleigh fading signal for Specified fm & r0 ');
% Calculating (Practically) Number of Zero Level Crossing and Average Fade Duration %
h=1;
c=0;
C1=0;
NUM=0;
while h<=M
if r(h)<=level
i=h;
while i<=M
if r(i)>=level
NUM=NUM+1;
break;
end
i=i+1;
end
c=i-h;
C1=C1+c;
h=i-1;
end
h=h+1;
end
Afd_p=Afd_p+(C1/NUM)*delta_t;
Nr_p=Nr_p+NUM*delta_f;
Rrms_p=Rrms_p+Rrms;
y=y+1;
end
%************ Theoretical calculation of Number of Zero Level Crossing (Nr) and Average Fade Duration ************* %
Nr_theoretical=sqrt(2*pi)*fm*r0*exp(-r0^2);
z1=exp(r0^2)-1;
z2=r0*fm*sqrt(2*pi);
Average_fade_duration_theoretical =z1/z2;
rowdb=10*log10(r0) ;
Rrms_theoretical=Rrms+rowdb;
%*********************** Displayiing Calculated values ************************ %
Nr_practical=(Nr_p);
Nr_practical
Nr_theoretical
Average_fade_duration_Practical=(Afd_p);
Average_fade_duration_Practical
Average_fade_duration_theoretical =z1/z2
Rrms_Practical=Rrms_p
Rrms_theoretical |
Can somebody provide me brief explanation and further references for understanding the above code?
|
|
| Back to top |
|
 |