Exercise 2.3

本文展示了一个简单的C++程序示例,该程序通过定义两个函数output1()和output2()来分别输出民谣《Three Blind Mice》的两段歌词。在main函数中调用这两个函数实现了重复输出的效果。
#include<iostream>
using namespace std;

void output1()
{
    cout << "Three blind mice" << endl;
    return;
}

void output2()
{

    cout << "See how they run" << endl;
    return;
}

int main()
{
    output1();
    output1();
    output2();
    output2();
    return 0;
}

\documentclass{article} \usepackage{graphicx} \usepackage{amsmath} \usepackage{booktabs} \usepackage{multirow} \usepackage{float} \usepackage{subcaption} \usepackage{geometry} \usepackage{listings} \usepackage{xcolor} \usepackage{hyperref} \geometry{a4paper, margin=1in} \definecolor{codegreen}{rgb}{0,0.6,0} \definecolor{codegray}{rgb}{0.5,0.5,0.5} \definecolor{codepurple}{rgb}{0.58,0,0.82} \definecolor{backcolour}{rgb}{0.95,0.95,0.92} \lstdefinestyle{mystyle}{ backgroundcolor=\color{backcolour}, commentstyle=\color{codegreen}, keywordstyle=\color{magenta}, numberstyle=\tiny\color{codegray}, stringstyle=\color{codepurple}, basicstyle=\ttfamily\footnotesize, breakatwhitespace=false, breaklines=true, captionpos=b, keepspaces=true, numbers=left, numbersep=5pt, showspaces=false, showstringspaces=false, showtabs=false, tabsize=2 } \lstset{style=mystyle} \title{Mobile Fading Channel Modeling Lab Report} \author{Lin Yanying \\ Student ID: 04023326} \date{\today} \begin{document} \maketitle \section{Introduction} This report documents the implementation and analysis of mobile fading channel modeling using MATLAB. The experiments cover Gaussian probability density functions, autocorrelation functions, power spectral densities, Rice and Rayleigh distributions, and Rayleigh fading channel simulation using the sum-of-sinusoids method. \section{Exercise 1: Gaussian Probability Density Function (PDF)} \subsection{Exercise 1.1: Theoretical Gaussian PDF} \begin{lstlisting}[language=Matlab] %% Exercise 1.1 Theoretical Gaussian PDF mu = 0; sigma = 1; x = -4:0.05:4; pdf_theoretical = (1/(sqrt(2*pi)*sigma)) * exp(-(x - mu).^2 / (2*sigma^2)); integral_value = trapz(x, pdf_theoretical); \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=0.8\textwidth]{task1_1.png} \caption{Theoretical Gaussian PDF ($\mu=0$, $\sigma=1$)} \label{fig:gaussian_pdf} \end{figure} \textbf{Analysis:} The theoretical Gaussian PDF was plotted with mean $\mu=0$ and standard deviation $\sigma=1$. The integral of the PDF was computed using the trapezoidal method (\texttt{trapz}), yielding a value of 1.0000, which confirms that the PDF is correctly normalized. This matches the theoretical expectation that the total probability under the PDF curve should equal 1. \subsection{Exercise 1.2: Simulated Gaussian Noise} \begin{lstlisting}[language=Matlab] %% Exercise 1.2 Simulated Gaussian Noise noise = randn(1, 1000000); mu_sim = mean(noise); sigma_sim = std(noise); [counts, bins] = hist(noise, 100); pdf_sim = counts / (sum(counts) * (bins(2)-bins(1))); pdf_theo = (1/(sqrt(2*pi)*sigma_sim)) * exp(-(bins - mu_sim).^2 / (2*sigma_sim^2)); \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=0.8\textwidth]{task1_2.png} \caption{Comparison of simulated and theoretical Gaussian PDF} \label{fig:gaussian_sim} \end{figure} \textbf{Analysis:} A vector of 1,000,000 Gaussian random numbers was generated using \texttt{randn}. The simulated mean was 0.0008 and standard deviation was 1.0004, very close to the theoretical values of 0 and 1 respectively. The histogram of the simulated data closely matches the theoretical Gaussian curve, demonstrating that \texttt{randn} effectively generates Gaussian-distributed random numbers. The slight differences are due to finite sample size effects. \section{Exercise 2: Autocorrelation and Power Spectral Density} \subsection{Exercise 2.1: Autocorrelation Function (ACF)} \begin{lstlisting}[language=Matlab] %% Exercise 2.1 Autocorrelation Function (ACF) fc = 900e6; % 900 MHz v = 109.2 * (1000/3600); % Convert km/h to m/s c0 = 3e8; % Speed of light fm = v*fc/c0; % Maximum Doppler frequency Omega_p = 2; tau = 0:0.001:0.08; % Time delay vector ACF = (Omega_p/2) * besselj(0, 2*pi*fm*tau); \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=0.8\textwidth]{task2_1.png} \caption{ACF of Clarke&#39;s Model} \label{fig:acf} \end{figure} \textbf{Analysis:} The maximum Doppler frequency $f_m$ was calculated to be 91.00 Hz for a vehicle moving at 109.2 km/h with a carrier frequency of 900 MHz. The ACF was computed using the zeroth-order Bessel function of the first kind. At $\tau=0$, the ACF value was 1.00, which equals $\Omega_p/2$ as expected from theory. The ACF decreases as $\tau$ increases, showing the typical behavior of a fading channel. \subsection{Exercise 2.2: Power Spectral Density (PSD)} \begin{lstlisting}[language=Matlab] %% Exercise 2.2 Power Spectral Density (PSD) f = -1.5*fm:1:1.5*fm; % Frequency vector PSD = zeros(size(f)); idx = abs(f) <= fm; PSD(idx) = (Omega_p/(2*pi*fm)) ./ sqrt(1 - (f(idx)/fm).^2); \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=0.8\textwidth]{task2_2.png} \caption{PSD of Clarke&#39;s Model} \label{fig:psd} \end{figure} \textbf{Analysis:} The PSD shows the characteristic U-shape of Clarke&#39;s model, with singularities at $\pm f_m$. The power is concentrated around the maximum Doppler frequencies, as expected for isotropic scattering. The PSD is zero outside the range $[-f_m, f_m]$, consistent with the theoretical prediction. \subsection{Exercise 2.3: Rice PDF} \begin{lstlisting}[language=Matlab] %% Exercise 2.3 Rice PDF Omega_p = 1; x_rice = 0:0.01:3; K_values = [0, 3, 80]; for K = K_values rice_pdf = (2*x_rice*(K+1)/Omega_p) .* exp(-K - (K+1)*x_rice.^2/Omega_p) .* ... besseli(0, 2*x_rice*sqrt(K*(K+1)/Omega_p)); end \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=0.8\textwidth]{task2_3.png} \caption{Rice PDF for Different K Values} \label{fig:rice_pdf} \end{figure} \textbf{Analysis:} The Rice PDF was plotted for K values of 0, 3, and 80. When K=0, the Rice distribution reduces to the Rayleigh distribution, as seen in the plot. For K=3, the distribution begins to resemble a Gaussian centered around a non-zero mean. At K=80, the PDF approaches a narrow Gaussian distribution, indicating a strong LOS component with minimal fading. \subsection{Exercise 2.4: Non-central Chi-square Distribution} \begin{lstlisting}[language=Matlab] %% Exercise 2.4 Non-central Chi-square Distribution x_chi = 0:0.01:3; for K = K_values chi_pdf = (K+1)/Omega_p * exp(-K - (K+1)*x_chi/Omega_p) .* ... besseli(0, 2*sqrt(K*(K+1)*x_chi/Omega_p)); end \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=0.8\textwidth]{task2_4.png} \caption{Non-central Chi-square PDF for Different K Values} \label{fig:chi_square} \end{figure} \textbf{Analysis:} The non-central chi-square distribution shows similar trends to the Rice PDF. For K=0, it reduces to the central chi-square distribution. As K increases, the distribution becomes more concentrated around higher values, reflecting the increasing dominance of the LOS component over the scattered components. \section{Exercise 3: Rayleigh Fading Channel Simulation} \subsection{Exercise 3.1: Compute Simulation Model Parameters} \begin{lstlisting}[language=Matlab] %% Exercise 3.1 Compute Simulation Model Parameters N1 = 9; N2 = 10; b = 1; fm = 91; % Maximum Doppler frequency % Compute parameters for g1(t) c1n = sqrt(2*b/N1) * ones(1,N1); f1n = fm * sin(pi/(2*N1) * ((1:N1) - 0.5)); theta1n = 2*pi*(1:N1)/(N1+1); % Compute parameters for g2(t) c2n = sqrt(2*b/N2) * ones(1,N2); f2n = fm * sin(pi/(2*N2) * ((1:N2) - 0.5)); theta2n = 2*pi*(1:N2)/(N2+1); \end{lstlisting} \begin{table}[H] \centering \caption{Parameters of the simulation model ($f_m=91$ Hz, $b=1$, $N_1=9$, $N_2=10$)} \label{tab:params} \begin{tabular}{|c|c|c|c|c|} \hline $i$ & $n$ & $f_{i,n}$ (Hz) & $c_{i,n}$ & $\theta_{i,n}$ (rad) \\ \hline \hline 1 & 1 & 12.52 & 0.4714 & 0.6283 \\ 1 & 2 & 36.48 & 0.4714 & 1.2566 \\ 1 & 3 & 57.50 & 0.4714 & 1.8850 \\ 1 & 4 & 73.56 & 0.4714 & 2.5133 \\ 1 & 5 & 83.44 & 0.4714 & 3.1416 \\ 1 & 6 & 86.67 & 0.4714 & 3.7699 \\ 1 & 7 & 83.44 & 0.4714 & 4.3982 \\ 1 & 8 & 73.56 & 0.4714 & 5.0265 \\ 1 & 9 & 57.50 & 0.4714 & 5.6549 \\ \hline 2 & 1 & 7.12 & 0.4472 & 0.5712 \\ 2 & 2 & 21.25 & 0.4472 & 1.1424 \\ 2 & 3 & 34.14 & 0.4472 & 1.7136 \\ 2 & 4 & 45.50 & 0.4472 & 2.2848 \\ 2 & 5 & 55.05 & 0.4472 & 2.8560 \\ 2 & 6 & 62.55 & 0.4472 & 3.4272 \\ 2 & 7 & 67.82 & 0.4472 & 3.9984 \\ 2 & 8 & 70.74 & 0.4472 & 4.5696 \\ 2 & 9 & 71.26 & 0.4472 & 5.1408 \\ 2 & 10 & 69.38 & 0.4472 & 5.7120 \\ \hline \end{tabular} \end{table} \textbf{Analysis:} The parameters for the sum-of-sinusoids method were calculated using the method of exact Doppler spread (MEDS). The gains $c_{i,n}$ were equal for all sinusoids within each component, while the frequencies $f_{i,n}$ followed a specific sinusoidal spacing pattern. \subsection{Exercise 3.2: Develop MATLAB Function for Deterministic Processes} \begin{lstlisting}[language=Matlab] %% Exercise 3.2 MATLAB Function for Deterministic Processes function gi = generate_process(t, c, f, theta) gi = zeros(size(t)); for n = 1:length(c) gi = gi + c(n) * cos(2*pi*f(n)*t + theta(n)); end end \end{lstlisting} \textbf{Analysis:} A MATLAB function was created to generate the deterministic processes $\tilde{g}_i(t)$ using the computed parameters. This function takes the time vector, gains, frequencies, and phases as inputs. \subsection{Exercise 3.3: Simulate Channel Amplitude} \begin{lstlisting}[language=Matlab] %% Exercise 3.3 Simulate Channel Amplitude fs = 270.8e3; % Sampling frequency T_sim = 0.4; % Simulation time t = 0:1/fs:T_sim; g1 = generate_process(t, c1n, f1n, theta1n); g2 = generate_process(t, c2n, f2n, theta2n); alpha = sqrt(g1.^2 + g2.^2); alpha_dB = 20*log10(alpha); % Calculate distance covered v = 109.2 * (1000/3600); % Vehicle speed in m/s distance = v * T_sim; \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=0.8\textwidth]{task3_3.png} \caption{Fading channel envelope in dB} \label{fig:fading_envelope} \end{figure} \textbf{Analysis:} The fading envelope shows typical Rayleigh fading characteristics with deep fades of up to -40 dB. The vehicle covers 12.13 meters in 0.4 seconds at 109.2 km/h. \subsection{Exercise 3.4: Simulate and Analyze Statistics} \begin{lstlisting}[language=Matlab] %% Exercise 3.4 Simulate and Analyze Statistics fs_new = 50e3; T_sim_new = 20; t_new = 0:1/fs_new:T_sim_new; g1_new = generate_process(t_new, c1n, f1n, theta1n); g2_new = generate_process(t_new, c2n, f2n, theta2n); g_new = g1_new + 1i * g2_new; alpha_new = abs(g_new); % Compute statistics mu_g1 = mean(g1_new); sigma_g1 = std(g1_new); mu_alpha = mean(alpha_new); sigma_alpha = std(alpha_new); % Compute PDFs [counts_g1, bins_g1] = hist(g1_new, 100); pdf_g1 = counts_g1 / (sum(counts_g1) * (bins_g1(2)-bins_g1(1))); [counts_alpha, bins_alpha] = hist(alpha_new, 100); pdf_alpha = counts_alpha / (sum(counts_alpha) * (bins_alpha(2)-bins_alpha(1))); \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=0.8\textwidth]{task3_4.png} \caption{PDF of $g_1(t)$ and $\alpha(t)$} \label{fig:pdf_comparison} \end{figure} \textbf{Analysis:} The statistics for $g_1(t)$ showed mean = -0.0001 and std = 0.9999, very close to the theoretical N(0,1) distribution. The envelope $\alpha(t)$ had mean = 1.2496 and std = 0.5410, matching the theoretical Rayleigh distribution with $\sigma=1$. \subsection{Exercise 3.5: ACF of Signal Segment} \begin{lstlisting}[language=Matlab] %% Exercise 3.5 ACF of Signal Segment fs_acf = 1000; t_interval = [10000/fs_acf, 20000/fs_acf]; t_idx = find(t_new >= t_interval(1) & t_new <= t_interval(2)); g1_segment = g1_new(t_idx); [acf, lags] = xcorr(g1_segment, &#39;biased&#39;); tau_acf = lags/fs_acf; \end{lstlisting} \textbf{Analysis:} The ACF was computed for a segment of the simulated signal to analyze its temporal correlation properties. The biased option was used to ensure proper normalization. \subsection{Exercise 3.6: Compare ACF with Theoretical Results} \begin{lstlisting}[language=Matlab] %% Exercise 3.6 Compare ACF with Theoretical Results tau_theo = 0:0.001:0.08; acf_theo = zeros(size(tau_theo)); for n = 1:N1 acf_theo = acf_theo + (c1n(n)^2/2) * cos(2*pi*f1n(n)*tau_theo); end % Theoretical ACF from Clarke&#39;s model acf_clarke = (Omega_p/2) * besselj(0, 2*pi*fm*tau_theo); \end{lstlisting} \begin{figure}[H] \centering \includegraphics[width=0.8\textwidth]{task3_6.png} \caption{Comparison of simulated, sum-of-sinusoids, and theoretical ACF} \label{fig:acf_comparison} \end{figure} \textbf{Analysis:} The ACF comparison shows good agreement between the simulated ACF, sum-of-sinusoids ACF, and theoretical ACF, particularly for small $\tau$ values. The ACF at $\tau=0$ was 0.9987, close to the theoretical value of 1. \section{Conclusion} The lab exercises successfully demonstrated key concepts in mobile fading channel modeling. The Gaussian and Rayleigh distributions were verified through both theoretical analysis and simulation. The sum-of-sinusoids method proved effective for simulating Rayleigh fading channels, with the simulated statistics closely matching theoretical predictions. The ACF and PSD analysis provided insight into the temporal and spectral characteristics of fading channels. \end{document} 请将表格以三线表的形式给出,给出完整代码
最新发布
08-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值