matlab使用demos,关于“Matlab Demos”的学习和总结

本文详细介绍了如何利用Matlab Demos中的通信工具箱进行BPSK的Monte Carlo仿真,包括源代码、注释和关键步骤。通过模拟信号的产生、噪声添加、解调过程,探讨了仿真参数如仿真点总数和期望错误点数对估计值方差的影响,并分析了高EbNo值下计算时间增加的原因。
摘要由CSDN通过智能技术生成

这里总结了Matlab Demos下通信工具箱里面的examples,给出源代码和注释。

程序代码 (一):关于BPSK的Mente Carlo仿真

% -------------------------------------------------------------------------

% Matlab Demos                                                      No.1.1

% -------------------------------------------------------------------------

% Phase Shift Keying Simulation

% This demo shows how to simulate a basic Quarternary Phase Shift Keying

% (QPSK) communication link, and to generate empirical performance curves

% that can be compared to theoretical predictions.

% -------------------------------------------------------------------------

% 1. 两个函数的使用:rectpulse与intdump成对使用,重复插值与抽取,互为逆操作;

% 2. randn的seed的使用;

% 3. 这里的解调是直接采用MATLAB自带的pskmod、pskdemod函数;

% 4. 为什么在后面调用函数,当采用的EbNo越大的时候,计算需要的时间越长?甚至是

%    系统死机(大概超过10dB之后)?

% 5. 这里需要讨论的问题就是 Mente Carlo 仿真的数值问题,即当用一个试验样本函数去

%    估计一个观测值的时候,如何尽量减小估计值的方差问题(选择合适的仿真点总数和期望错误点数)。

% -------------------------------------------------------------------------

%                                       revised by lavabin  2006.07.26

% -------------------------------------------------------------------------

clc;clear all;close all;echo off;tic;

% -------------------------------------------------------------------------

%                      Parameter Definition

% -------------------------------------------------------------------------

nSamp = 8; numSymb = 100;

M = 4; SNR = 14;

seed = [12345 54321];

rand('state', seed(1)); randn('state', seed(2));

% -------------------------------------------------------------------------

%                Generating random information symbols

% -------------------------------------------------------------------------

numPlot = 10;

rand('state', seed(1));

msg_orig = randsrc(numSymb, 1, 0:M-1);

% -------------------------------------------------------------------------

% Phase modulating the data

% Use PSKMOD to phase modulate the data and RECTPULSE to upsample to a

% sampling rate 8 times the carrier frequency.

% -------------------------------------------------------------------------

grayencod = bitxor(0:M-1, floor((0:M-1)/2));

% Gray coding here!

% %  a = bitxor(0:M-1, floor((0:M-1)/2))

% %  a = 0     1     3     2

msg_gr_orig = grayencod(msg_orig+1);

% % Using "looktable" to map source data to Gray code

msg_tx = pskmod(msg_gr_orig,M);

% % Mapping source data to MPSK constellation

msg_tx = rectpulse(msg_tx,nSamp);

% -----------------------------

% figure(1);

% -----------------------------

scatterplot(msg_tx);

hold on;grid on;

% -------------------------------------------------------------------------

% Creating the noisy signal

% Then use AWGN to add noise to the transmitted signal to create the noisy

% signal at the receiver. Use the 'measured' option to add noise that is

% 14 dB below the average signal power (SNR = 14 dB). Plot the

% constellation of the received signal.

% -------------------------------------------------------------------------

randn('state', seed(2));

msg_rx = awgn(msg_tx, SNR, 'measured', [], 'dB');

% -----------------------------

% figure(2);

% -----------------------------

scatterplot(msg_rx);

hold on;grid on;

% -------------------------------------------------------------------------

% Recovering information from the transmitted signal

% Use INTDUMP to downsample to the original information rate. Then use

% PSKDEMOD to demodulate the signal, and detect the transmitted symbols.

% The detected symbols are plotted in red stems with circles and the

% transmitted symbols are plotted in blue stems with x's. The blue stems of

% the transmitted signal are shadowed by the red stems of the received

% signal. Therefore, comparing the blue x's with the red circles indicates

% that the received signal is identical to the transmitted signal.

% -------------------------------------------------------------------------

msg_rx_down  = intdump(msg_rx,nSamp);  % operation before DEMOD

msg_gr_demod = pskdemod(msg_rx_down,M);

[dummy graydecod] = sort(grayencod);

graydecod = graydecod - 1;

msg_demod = graydecod(msg_gr_demod+1)';

figure(3);

stem(0:numPlot-1, msg_orig(1:numPlot), 'bx'); hold on;

stem(0:numPlot-1, msg_demod(1:numPlot), 'ro'); hold off;

axis([ 0 numPlot -0.2 3.2]); xlabel('Time'); ylabel('Amplitude');

% -------------------------------------------------------------------------

% Comparing original message to demodulated message

% -------------------------------------------------------------------------

[errorBit ratioBit] = biterr(msg_orig, msg_demod, log2(M));

[errorSym ratioSym] = symerr(msg_orig, msg_demod);

% -------------------------------------------------------------------------

% Running simulation examples

% The next step executes an example file SIMBASEBANDEX, which is a complete

% sin of the modulated

% signal.mulation example for QPSK. It demonstrates how to create simulation

% drivers in MATLAB that plot the simulation results as they are generated.

% -------------------------------------------------------------------------

% Running the QPSK simulation example

% The green and magenta lines are the theoretical bit error rate (BER) and

% symbol error rate (SER) performance curves for QPSK, respectively. The

% example, SIMBASEBANDEX, plots the simulated BER and SER in red and blue

% lines, respectively. SIMBASEBANDEX uses PSKMOD and PSKDEMOD to simulate

% PSK at baseband using a complex envelope representation.

% -------------------------------------------------------------------------

% [MPSK_ratio, MPSK_errors] = simbasebandex_lavabin(0:2:10)

[MPSK_ratio, MPSK_errors] = simbasebandex_lavabin(0:.5:10)

% Note:这个函数simbasebandex_lavabin在整个script中只被调用了一次。

simulation_time = toc

% -------------------------------------------------------------------------

%                              End of Script

% -------------------------------------------------------------------------

displayEndOfDemoMessage(mfilename);

% ---------------------------------ÿ

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值