├── README.md ├── LICENSE ├── Rayleigh_Fading.m ├── Rician_Fading.m ├── Rayleigh_Capacity.m ├── Nakagami_Capacity.m └── Nakagami_Fading.m /README.md: -------------------------------------------------------------------------------- 1 | # multipath_channel_models 2 | This repo will be updated soon 3 | 4 | Includes: 5 | - Basic models of Rayleigh, Rician and Nakagami Fading channels. 6 | - Channel Capacity calculations under CSI@RX and CSI@TX-RX conditions. 7 | 8 | See Wireless Communications by Goldsmith 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Gökhan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Rayleigh_Fading.m: -------------------------------------------------------------------------------- 1 | clear;close all; 2 | %generate random vectors 3 | %in-phase component 4 | i=randn([1 10^6]); 5 | %quadtature component 6 | q=randn([1 10^6]); 7 | %build signal 8 | s=(i+1j*q); 9 | 10 | %calculate fading power 11 | s_pow=s.*conj(s); 12 | %calculate fading envelope 13 | s_env=sqrt(s_pow); 14 | 15 | %define number of bins 16 | bins=150; 17 | 18 | %plot envelope of fading with corresponding rayleigh distribution 19 | %create a new figure 20 | figure;subplot(1,2,1);hold on; 21 | %create histogram 22 | histogram(s_env,bins,'Normalization','pdf'); 23 | %fit rayleigh distribution to data 24 | env_dist=fitdist(s_env','Rayleigh'); 25 | %generate x-axis values 26 | env_x=linspace(0,max(s_env),bins); 27 | %generate y-axis values 28 | env_y=pdf(env_dist,env_x); 29 | %plot the distribution 30 | plot(env_x,env_y,'r--','LineWidth',1.5); 31 | %show grid, add legend... 32 | grid on;ylim([0 1]);xlim([0 5]); 33 | legend('Fading Envelope','Rayleigh Distribution'); 34 | xlabel('h');ylabel('f_h(h)');axis square; 35 | title('Envelope of Fading'); 36 | 37 | %plot power with corresponding exponential distribution 38 | %create a new figure 39 | subplot(1,2,2);hold on; 40 | %create histogram 41 | histogram(s_pow,bins,'Normalization','pdf'); 42 | %fit exponential dist to data 43 | pow_dist=fitdist(s_pow','Exponential'); 44 | %generate x-axis values 45 | pow_x=linspace(0,max(s_pow),bins); 46 | %generate y_axis values 47 | pow_y=pdf(pow_dist,pow_x); 48 | %plot the distribution 49 | plot(pow_x,pow_y,'r--','LineWidth',2); 50 | %show grid, add legend... 51 | grid on;ylim([0 1]);xlim([0 15]); 52 | legend('Signal Power', 'Exponential Distribution'); 53 | xlabel('v');ylabel('f_v(v)');axis square; 54 | title('Envelope-Squared, Power'); -------------------------------------------------------------------------------- /Rician_Fading.m: -------------------------------------------------------------------------------- 1 | clear;close all; 2 | %generate random vectors 3 | %define size 4 | size=10^6; 5 | %define K-factors 6 | Ks=[0.5 1 3 10]; 7 | %define signal,power and envelope matrices 8 | s=zeros(length(Ks),size); 9 | s_pow=zeros(length(Ks),size); 10 | s_env=zeros(length(Ks),size); 11 | %define number of bins 12 | bins=75; 13 | 14 | for j=1:length(Ks) 15 | K=Ks(j); 16 | %LOS components 17 | %a=sqrt(sqrt(K/2)/2);b=a; 18 | a=sqrt(K/2);b=a; 19 | %in-phase component 20 | i=a+randn([1 size]); 21 | %quadtature component 22 | q=b+randn([1 size]); 23 | %build fading component 24 | s=(i+1j*q); 25 | %calculate the fading envelope 26 | s_env=sqrt(s.*conj(s)); 27 | 28 | %plots 29 | subplot(2,2,j);hold on; 30 | %plot histogram of samples 31 | histogram(s_env, bins, 'Normalization', 'pdf'); 32 | %fit rician distribution to data 33 | env_dist=fitdist(s_env','Rician'); 34 | %fit rayleigh for comparison 35 | rayleigh_dist=fitdist(s_env','Rayleigh'); 36 | %generate x-axis values 37 | env_x=linspace(0,max(s_env),bins); 38 | %generate y-axis values 39 | env_y=pdf(env_dist,env_x); 40 | rayleigh_dist_y=pdf(rayleigh_dist,env_x); 41 | %plot rician distribution 42 | plot(env_x,env_y,'r--','LineWidth',2); 43 | %plot rayleigh distribution 44 | plot(env_x,rayleigh_dist_y,'g-.','LineWidth',2); 45 | %plot settings 46 | grid on;axis square;xlim([0 7]);ylim([0 1]); 47 | legend('Fading Envelope','Rician Dist.','Rayleigh Dist.'); 48 | xlabel('h');ylabel('f_h(h)');axis square; 49 | title(strcat('K=',num2str(K))); 50 | end 51 | %set appropriate size 52 | ss=get(0,'ScreenSize'); 53 | set(gcf,'Position',[0.2*ss(3),0.15*ss(4),0.66*ss(3),0.66*ss(4)]); 54 | %mu represents m 55 | %omega represents avg.power -------------------------------------------------------------------------------- /Rayleigh_Capacity.m: -------------------------------------------------------------------------------- 1 | clear;close all; 2 | %defs 3 | %define snr values in dBs 4 | SNR_dB=1:30; 5 | %define sample length 6 | len=10^6; 7 | %allocate output arrays 8 | csi_rx=zeros(1,length(SNR_dB)); 9 | csi_trx=zeros(1,length(SNR_dB)); 10 | %convert to std deviations for scaling 11 | n_pow=2./(10.^(SNR_dB./10)); 12 | %calculate awgn capacity, channel information irrelevant 13 | awgn_c=log2(1+(2./n_pow)); 14 | 15 | for j=1:length(SNR_dB) 16 | %in-phase component 17 | i=randn([1 len])./sqrt(n_pow(j)); 18 | %quadtature component 19 | q=randn([1 len])./sqrt(n_pow(j)); 20 | %build fading component, unit variance 21 | h=(i+1j*q); 22 | %calculate the power of the fading 23 | h_pow=h.*conj(h); 24 | %extract mean value of the power 25 | gamma_bar=mean(h_pow); 26 | 27 | %csi at rx only 28 | %take integral to obtain shannon capacity 29 | c=integral(@(gamma)(log2(1+gamma))... 30 | .*(exp(-gamma/gamma_bar)/gamma_bar),0,Inf); 31 | %store in array 32 | csi_rx(1,j)=c; 33 | 34 | %csi at both tx and rx 35 | %find the cut-off power for transmitter, set constraint 36 | f=@(gamma_0) integral(@(gamma)... 37 | (1./gamma_0-1./gamma).*(exp(-gamma/gamma_bar)/gamma_bar),gamma_0,Inf)-1; 38 | %find the solution of the constraint 39 | gamma_0=fzero(f,[1e-100,100]); 40 | %calculate shannon capacity utilizing the cut-off value 41 | c=integral(@(gamma)(log2(gamma/gamma_0)... 42 | .*exp(-gamma/gamma_bar)/gamma_bar),gamma_0,Inf); 43 | %store in array 44 | csi_trx(1,j)=c; 45 | end 46 | 47 | %plot results 48 | figure;hold on; 49 | plot(SNR_dB,awgn_c,'r-.','LineWidth',2); 50 | plot(SNR_dB,csi_rx,'b','LineWidth',2); 51 | plot(SNR_dB,csi_trx,'g','LineWidth',2) 52 | xlabel('SNR(dB)');ylabel('Shannon Capacity(Bits/Sec/Hz)'); 53 | title('Channel Capacity vs. SNR | Part II:Q1'); 54 | legend('AWGN Channel','Rayleigh Fading Channel w/ CSI@RX',... 55 | 'Rayleigh Fading Channel w/ CSI@TXRX','Location','NorthWest'); 56 | grid on;axis square; 57 | 58 | -------------------------------------------------------------------------------- /Nakagami_Capacity.m: -------------------------------------------------------------------------------- 1 | %clear;close all; 2 | %defs 3 | %define snr values in dBs 4 | SNR_dB=1:30; 5 | %define sample length 6 | len=10^6; 7 | %allocate output arrays 8 | csi_rx=zeros(1,length(SNR_dB)); 9 | csi_trx=zeros(1,length(SNR_dB)); 10 | %convert to std deviations for scaling 11 | n_pow=2./(10.^(SNR_dB./10)); 12 | %calculate awgn capacity, channel information irrelevant 13 | awgn_c=log2(1+(2./n_pow)); 14 | %select m value 15 | m=2; 16 | %solve (K+1)^2/(2K+1)=m 17 | f=@(K)(pow2(K+1)/(2*K+1))-m; 18 | fzero(f,[1e-100 100]); 19 | 20 | for j=1:length(SNR_dB) 21 | %select appropriate LOS values with K value 22 | a=sqrt(K/n_pow(j));b=a; 23 | %in-phase component 24 | i=a+randn([1 len])./sqrt(n_pow(j)); 25 | %quadrature component 26 | q=b+randn([1 len])./sqrt(n_pow(j)); 27 | %build fading component 28 | h=(i+1j*q); 29 | %calculate the fading power 30 | h_pow=h.*conj(h); 31 | %parameters for nakagami power distribution 32 | mu=m;omega=mean(h_pow); 33 | 34 | %csi at rx only 35 | %calculate the integral to obtain shannon capacity 36 | f=@(g)log2(1+g).*power(mu/omega,mu)... 37 | .*power(g,mu-1).*exp(-g.*mu/omega)/gamma(mu); 38 | c=integral(f,0,Inf); 39 | %store in array 40 | csi_rx(1,j)=c; 41 | 42 | %csi at both tx and rx 43 | %find the cut-off power for transmitter, set constraint 44 | f=@(gamma_0) integral(@(g)... 45 | (1./gamma_0-1./g).*power(mu/omega,mu)... 46 | .*power(g,mu-1).*exp(-g.*mu/omega)/gamma(mu),gamma_0,Inf)-1; 47 | %fins solution to constraint 48 | gamma_0=fzero(f,[1e-100,1000]); 49 | %calculate shannon capacity using the cut-off value 50 | c=integral(@(g)(log2(g/gamma_0)... 51 | .*power(mu/omega,mu).*power(g,mu-1)... 52 | .*exp(-g.*mu/omega)/gamma(mu)),gamma_0,Inf); 53 | %store in array 54 | csi_trx(1,j)=c; 55 | end 56 | %plot results 57 | figure;hold on; 58 | plot(SNR_dB,awgn_c,'r-.','LineWidth',2); 59 | plot(SNR_dB,csi_rx,'b','LineWidth',2); 60 | plot(SNR_dB,csi_trx,'g','LineWidth',2) 61 | xlabel('SNR(dB)');ylabel('Shannon Capacity(Bits/Sec/Hz)'); 62 | title('Channel Capacity vs. SNR | Part II:Q2'); 63 | legend('AWGN Channel','Nakagami Fading Channel w/ CSI@RX',... 64 | 'Nakagami Fading Channel w/ CSI@TXRX','Location','NorthWest'); 65 | grid on;axis square; -------------------------------------------------------------------------------- /Nakagami_Fading.m: -------------------------------------------------------------------------------- 1 | clear;close all; 2 | %generate random vectors 3 | %define size 4 | size=10^6; 5 | %define K-factors 6 | Ks=[0.5 1 3 10]; 7 | %define signal,power and envelope matrices 8 | s=zeros(length(Ks),size); 9 | s_pow=zeros(length(Ks),size); 10 | s_env=zeros(length(Ks),size); 11 | %define number of bins 12 | bins=150; 13 | 14 | %create figures 15 | env_fig=figure; 16 | pow_fig=figure; 17 | 18 | for j=1:length(Ks) 19 | K=Ks(j); 20 | %LOS components 21 | a=sqrt(K);b=a; 22 | %in-phase component 23 | i=a+randn([1 size]); 24 | %quadtature component 25 | q=b+randn([1 size]); 26 | %build fading component 27 | s=i+1j*q; 28 | %calculate the fading power 29 | s_pow=s.*conj(s); 30 | %calculate the fading envelope 31 | s_env=sqrt(s_pow); 32 | 33 | %plots 34 | %calculate nakagami-m distribution parameters 35 | m=power((K+1),2)/(2*K+1); 36 | omega=mean(s_pow); 37 | %approximate with nakagami-m distribution 38 | env_dist=makedist('Nakagami',m,omega); %make distribution 39 | %generate x-axis values 40 | env_x=linspace(0,max(s_env),bins); 41 | pow_x=linspace(0,max(s_pow),bins); 42 | %generate y-axis values 43 | env_y=pdf(env_dist,env_x); 44 | pow_y=(power((m/omega),m).*power(pow_x,m-1)... 45 | .*exp(-pow_x*m/omega))./gamma(m); 46 | %plot the envelopes 47 | %set current figure to envelope 48 | figure(env_fig); 49 | subplot(2,2,j);hold on; 50 | %plot histogram of samples 51 | histogram(s_env, bins, 'Normalization', 'pdf'); 52 | plot(env_x,env_y,'r--','LineWidth',2); 53 | %plot settings 54 | grid on;axis square;xlim([0 7]);ylim([0 1]); 55 | legend('Fading Envelope','Nakagami-m Dist.'); 56 | xlabel('h');ylabel('f_h(h)');axis square; 57 | title(strcat('m=',num2str(m))); 58 | 59 | %plot power 60 | figure(pow_fig); 61 | subplot(2,2,j);hold on; 62 | %plot power histogram 63 | histogram(s_pow,bins,'Normalization','pdf'); 64 | plot(pow_x,pow_y,'r--','LineWidth',2); 65 | %plot settings 66 | grid on;axis square;xlim([0 20]);ylim([0 1]); 67 | legend('Fading Power','Nakagami-m Power Dist.'); 68 | xlabel('v');ylabel('f_v(v)');axis square; 69 | title(strcat('\mu=',num2str(m),' | ','\Omega =',num2str(m/omega))); 70 | end 71 | %set appropriate size 72 | figure(env_fig); 73 | ss=get(0,'ScreenSize'); 74 | set(gcf,'Position',[0.2*ss(3),0.15*ss(4),0.66*ss(3),0.66*ss(4)]); 75 | figure(pow_fig); 76 | ss=get(0,'ScreenSize'); 77 | set(gcf,'Position',[0.2*ss(3),0.15*ss(4),0.66*ss(3),0.66*ss(4)]); 78 | %mu represents m 79 | %omega represents avg.power --------------------------------------------------------------------------------