关于“Matlab Demos”的学习和总结_matlab学习总结总结
关于“Matlab Demos”的学习和总结由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“matlab学习总结总结”。
关于“Matlab Demos”的学习和总结
这里总结了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 = 0msg_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(11;% Drive the simulation for each of the SNR values calculated above for idx2 = 1:length(EsNo)
% Exit loop only when minimum number of iterations have completed and the
% number of errors exceeds 'expSymErrs'
idx = 1;
while((idx logical or %
while(idx
% Generate random numbers from in the range [0, M-1]
msg_orig = randsrc(symbPerIter, 1, 0:M-1);
% Gray encode symbols
msg_gr_orig = grayencod(msg_orig+1)';
% Digitally modulate the signal
msg_tx = pskmod(msg_gr_orig, M);
% Add Gauian noise to the signal.The noise is calibrated using
% the 'measured' option.msg_rx = awgn(msg_tx, EsNo(idx2), 'measured', [], 'dB');
% Demodulate the signal
msg_gr_demod = pskdemod(msg_rx, M);
% Gray decode meage
msg_demod = graydecod(msg_gr_demod+1)';
% Calculate bit error count, BER, symbol error count and SER,% for this iteration.[errBit(idx)ratBit(idx)] = biterr(msg_orig, msg_demod, k);
[errSym(idx)ratSym(idx)] = symerr(msg_orig, msg_demod);
% Increment for next iteration
idx = idx + 1;
end
% average the errors and error ratios for the iterations.errors(idx2, :)= [sum(errBit), sum(errSym)];
ratio(idx2, :)= [mean(ratBit), mean(ratSym)];% %
函数说明 mean:
% %
MEAN
Average or mean value.% %
For vectors, MEAN(X)is the mean value of the elements in X.For % %
matrices, MEAN(X)is a row vector containing the mean value of % %
each column.% Plot the simulated results for SER and BER.semilogy(EbNo(1:size(ratio(:,2),1)), ratio(:,2), 'bo',...EbNo(1:size(ratio(:,1),1)), ratio(:,1), 'ro');
legend('Theoretical SER','Theoretical BER','Simulated SER','Simulated BER',0);
drawnow;end hold off;%-----------%
End of Function %-----------% % 函数说明:
% % DRAWNOW Flush pending graphics events.% %
DRAWNOW “flushes the event queue” and forces MATLAB to % %
update the screen.% %
% %
There are four events that cause MATLAB to flush the event % %
queue and draw the screen: % %
% %
-a return to the MATLAB prompt % %
-hitting a PAUSE statement % %
-executing a GETFRAME command % %
-executing a DRAWNOW command
程序代码(二): 程序代码(三): 关于升余弦滤波器
%-----------% Matlab Demos
No.3.1 %-----------% Raised Cosine Filtering %-----------%(1)% This demonstration uses the Communications Toolbox functions, RCOSINE and % RCOSFLT, to demonstrate the ISI rejection capability of the raised cosine % filter.%(2)% It demonstrates how to use RCOSINE and RCOSFLT, how the raised cosine
% filter controls intersymbol interference, and how to split % the raised cosine filtering between transmitter and receiver.%(3)% This data sequence represents a digital sequence that will be upsampled by % zero-padding before filtering.Raised cosine filters will be used to shape % the waveform without introducing intersymbol interference(ISI).%-----------% 几点主要的意思:
% 1
“升余弦函数 rcosine” 和 “升余弦滤波器函数 rcosflt”的使用;
% 2
波形成形的目标是在源端就利用升余弦函数的抗ISI特性消除ISI,因为不可能生成 %
绝对的的时域有限的信号; % 3
升余弦滤波器在源/宿端的分割。% % 从上到下几个code板块依次讨论了: % % Delay的影响 % % R的影响
% % 发、收端之间平方根升余弦滤波 % % 缺省方式下的rcosflt的快速调用方法
%-----------%
revised by lavabin 2006.08.02 %-----------clc;clear all;close all;echo off;tic;%-----------%
Parameter Definition %-----------Delay = 3;DataL = 20;R =.5;Fd = 1;Fs = 8;PropD = 0;% Generate random data.x = randsrc(DataL, 1, [], 1245);% at time 0, 1/Fd, 2/Fd,...% Fd is the sampling frequency of the data source % 1/Fd is the symbol period of the data source tx = [PropD: PropD + DataL1]./ Fd;% figure(2)% figure1 与 figure2的波形对比强烈地反映出了Delay的作用,滤波器输出的波形与输入
% 波形在包络上的相似性需要通过延迟输入信号来得到保证 figure;stem(tx, x, 'kx');hold on;plot(to, yo, 'b.');hold off;axis([0 30-1.6 1.6]);xlabel('Time');ylabel('Amplitude');%-----------% This step demonstrates the effect that changing the rolloff factor from.5 %(blue curve)to.2(red curve)has on the resulting filtered output.The % lower value for rolloff causes the filter to have a narrower transition band % causing the filtered signal overshoot to be greater for the red curve than for % the blue curve.%----------% Design filter.[yg, tg] = rcosine(Fd, Fs, 'fir',.2, Delay);% Filter data.[yo1, to1] = rcosflt(x, Fd, Fs, 'normal/fir/filter',yg);% figure(3)figure;stem(tx, x, 'kx');hold on;% Plot filtered data.plot(to, yo, 'b-',to1, yo1, 'r-');hold off;% Set axes and labels.axis([0 30-1.6 1.6]);xlabel('Time');ylabel('Amplitude');legend('Source Data','R = 0.5','R = 0.2')%-----------% A typical use of raised cosine filtering is to split the filtering between % transmitter and receiver.The data stream is upsampled and filtered at the % transmitter using the square-root raised cosine filter.This plot shows % the transmitted signal when filtered using the square-root raised cosine % filter.The “fir/sqrt” switch was used with RCOSINE to generate the % square-root raised cosine filter.%-----------% Design square root filter.[ys, ts] = rcosine(Fd, Fs, 'fir/sqrt', R, Delay);% Filter at the transmitter.[yc, tc] = rcosflt(x, Fd, Fs, 'filter', ys);% figure(4)figure;stem(tx, x, 'kx');hold on;plot(tc, yc, 'm.');hold off;axis([0 30-1.6 1.6]);xlabel('Time');ylabel('Amplitude');%-----------% The transmitted signal(magenta curve)is then filtered, but not upsampled, at % the receiver, using the same square-root raised cosine filter, resulting in a % signal depicted by the blue curve at the receiver.The resulting signal is % virtually identical to the signal filtered using a single raised cosine % filter.The “Fs” was used to filter without upsampling.%-----------% Filter at the receiver.[yr, tr] = rcosflt(yc, Fd, Fs, 'filter/Fs', ys);% Adjust for propagation delay.tcc = tc + Delay.* Fd;txx = tx + Delay.* Fd;% figure(5)figure;stem(txx, x, 'kx');hold on;plot(tcc, yc, 'm-',tr, yr, 'b-');hold off;axis([0 30-1.6 1.6]);xlabel('Time');ylabel('Amplitude');%-----------% This step demonstrates a quicker way to filter data using RCOSFLT.When % RCOSFLT is used without the “filter” type switch, it designs a filter and uses % it to filter the input data.This step creates the same plot as before but % designs the raised cosine filter and generates the filtered stream in one % command.%-----------% Design and filter.[yo2, to2] = rcosflt(x, Fd, Fs, 'normal/fir', R, Delay);% figure(6)figure;stem(tx, x, 'kx');hold on;plot(to2, yo2, 'b-');hold off;axis([0 30-1.6 1.6]);xlabel('Time');ylabel('Amplitude');%-----------displayEndOfDemoMeage(mfilename)%-----------simulation_time = toc %-----------%
End of Script %-----------% % 关于rcosflt的函数说明
%-----------% % RCOSFLT Filter the input signal using a raised cosine filter.% %
Y = RCOSFLT(X, Fd, Fs, TYPE_FLAG, R, DELAY)filters the input signal X % %
using a raised cosine FIR filter.The sample frequency for the input, X, % %
is Fd(Hz).The sample frequency for the output, Y, is Fs(Hz).Fs must be % %
an integer multiple of Fd.The TYPE_FLAG gives specific filter design % %
or filtering options.The rolloff factor, R, determines the width of the % %
transition band of the filter.DELAY is the time delay from the beginning % %
of the filter to the peak of the impulse response.% %
% %
R, the rolloff factor specifies the exce bandwidth of the filter.R must % %
be in the range [0, 1].For example, R =.5 means that the bandwidth of the % %
filter is 1.5 times the input sampling frequency, Fd.This also means that % %
the transition band of the filter extends from.5 * Fd and 1.5 * Fd.Since % %
R is normalized to the input sampling frequency, Fd, it has no units.% %
Typical values for R are between 0.2 to 0.5.% %
% %
DELAY determines the group delay of the filter.The group delay is the % %
opposite of the change in filter phase with respect to frequency.For linear % %
phase filters, the group delay is also the time delay between the input % %
signal and the peak response of the filter.DELAY also determines the % %
length of the filter impulse response used to filter X.This delay is % %
Fs/Fd *(2 * DELAY + 1).% %
% %
Y is the output of the upsampled, filtered input stream X.The length of % %
vector Y is % %
Fs/Fd *(length(X)+ 2 * DELAY).% %
% %
TYPE_FLAG is a string which may contain any of the option strings listed % %
below delimited by a '/' For example, the 'iir' and 'Fs' flags may % %
be combined as 'iir/Fs'.While some of the pairs of option substrings % %
are mutually exclusive, they are not mutually exclusive in general.% % % %
'fir'
Design an FIR filter and use it to filter X.When the 'filter' % %
TYPE_FLAG is not used, an FIR filter is designed and used to % %
filter X.See the 'filter' TYPE_FLAG description for the behavior % %
when the 'fir' and 'filter' TYPE_FLAGs are used together.This % %
option is exclusive of the 'iir' substring.% %
% %
'iir'
Design an IIR filter and use it to filter X.When the 'filter' % %
TYPE_FLAG is not used, an IIR approximation to the equivalent FIR % %
filter is designed and used to filter X.See the 'filter' % %
TYPE_FLAG description for the behavior when the 'iir' and 'filter' % %
TYPE_FLAGs are used together.This option is exclusive of the % %
'fir' substring.% % % %
'normal' Design a normal raised cosine filter and use it to filter X.The % %
filter coefficients are normalized so the peak coefficient is one.% %
This option is exclusive of the 'sqrt' substring.% %
% %
'sqrt'
Design a square root raised cosine filter and use it to filter X.% %
The filter coefficients are normalized so that the impulse % %
response of this filter when convolved with itself will result % %
in an impulse response that is approximately equal to the 'normal' % %
raised cosine filter.The difference in this approximation is due % %
to finite filter length.This is a useful option when the raised % %
cosine filtering is split between transmitter and receiver by % %
using the 'sqrt' filter in each device.This option is exclusive % %
of the 'normal' substring.% %
% %
'Fs'
X is input with sample frequency Fs(i.e., the input signal has % %
Fs/Fd samples per symbol).In this case the input signal is not % %
upsampled from Fd to Fs but is simply filtered by the raised % %
cosine filter.This is useful for filtering an oversampled data % %
stream at the receiver.When using the 'Fs' substring, the length % %
of vector, Y is % %
length(X)+ Fs/Fd * 2 * DELAY.% %
% %
'filter' Means the filter is provided by the user.When using the 'filter' % %
TYPE_FLAG, the input parameters are: % %
% %
Y = RCOSFLT(X, Fd, Fs, TYPE_FLAG, NUM)filters with % %
a user-supplied IIR filter.When TYPE_FLAG contains both 'filter' % %
and 'iir' type substrings, the IIR filter defined by numerator, % %
NUM, and denominator, DEN, is used as to filter X.The DELAY % %
parameter is used to force RCOSFLT to behave as if the filter were % %
designed by RCOSFLT using the same DELAY parameter.The DELAY % %
parameter should match the DELAY parameter used to design the % %
filter defined by NUM and DEN in the RCOSINE function.The default % %
value of DELAY is 3.% %
% %
The raised cosine filter should be designed using the RCOSINE % %
function.% %
% %
Y = RCOSFLT(X, Fd, Fs, TYPE_FLAG, R)filters the input signal X % %
using a raised cosine filter and default DELAY parameter, 3.% %
% %
Y = RCOSFLT(X, Fd, Fs, TYPE_FLAG)filters the input signal X using a % %
raised cosine filter and the following default parameters % %
DELAY = 3 % %
R =.5 % %
% %
Y = RCOSFLT(X, Fd, Fs)filters the input signal X using a raised cosine % %
filter and the following default parameters % %
DELAY = 3 % %
R =.5 % %
TYPE_FLAG = 'fir/normal' % %
% %
Y = RCOSFLT(X, Fd, Fs, TYPE_FLAG, R, DELAY, TOL)specifies the % %
tolerance in IIR filter design.The default value for TOL is.01.% %
% %
[Y, T] = RCOSFLT(...)returns the time vector in T.%-----------
安全事故学习和总结2008年6月25日至6月27日,在公司领导和有关部门的安排下,城郊供电所组织了为期三天的安全生产学习。主要是针对曲靖供电有限公司富源110kV变电站“6.24” 恶......
学习和出差总结从2018年3月1号开始很荣幸地被公司先后安排到总部苏州和项目地湛江进行将近十二天左右的学习。在这十二天中,接触到很多新事物和新的知识,遇见了并且认识到不同......
安全事故学习和总结 2012年4月9日,在上级领导和有关部门的安排下,我项目部组织了为期一天的安全生产学习。主要是针对楚雄供电局“2.27”人身触电死亡事故和红河供电局开远供......
英语是世界上最广泛使用的语言,对于中国学生来说,很多人都梦想讲一口流利的英语,学好英语对将来有很大的帮助,但是由于教育体制的落后和教学方法的不得当,给学习英语带来很多的困......
软件工程学习总结和体会西安交通大学20xx级研究生课程专题作业软 件 工 程 心 得专 业:班 级:学 号:姓 名:电 话:二xxx年十月体 会一、 软件生命周期各阶段任务目的和主要方......
