




下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、精選優(yōu)質文檔-傾情為你奉上1.正態(tài)分布:#include <math.h> #include <stdlib.h> #include <time.h> #include <fstream> #include <iostream> using namespace std; #define pi 3. /Generate a randon number followed by uniform distribution between the inteval min,max template<typename T> T rand
2、(T min, T max) return min+(max-min)*rand()/(RAND_MAX+1.0); /calculate the normal density distribution values double normal(double x, double miu,double sigma) return 1.0/sqrt(2*pi)/sigma*exp(-1*(x-miu)*(x-miu)/(2*sigma*sigma); /Generate a distributed random output numberdouble randn(double miu,double
3、 sigma, double min ,double max) double x,y,dScope; do x=rand(min,max); y=normal(x,miu,sigma); dScope=rand(0.0,normal(miu,miu,sigma); while(dScope>y); return x; /Generate 10000 distributed random output numbers and put into a text called"123"int main(int argc,char* argv) double min,max,m
4、iu,sigma; srand(unsigned)time( NULL ); cin>>min>>max>>miu>>sigma; ofstream outfile("123.txt"); for (int i=0;i<10000;i+) outfile << randn(miu,sigma,min,max) << endl; return 0; 2.瑞利分布:#include <math.h> #include <stdio.h> #include <stdlib.
5、h> #include <time.h> #define pi 3./ generate the random numbers between the interval 0,1double randn()double f;f = (double)(rand()%1001); /0,1000return f/1000.0; /0,1/calculate the Rayleigh density function values by using the following generated random numbers double ruili(double sigma) Re
6、turn randn()/(sigma*sigma)*exp(-randn()*randn()/(2*sigma*sigma); /The main function can generate 10000 distributed random output numbers which are put into a text called”321”int main(void) double sigma; srand(unsigned)time( NULL ); printf("input sigma:n"); scanf("%lf",&sigma)
7、; for (int i=0;i<10000;i+) FILE *fp;fp=fopen("321.txt","a+");fprintf(fp,"%lf,",ruili(sigma);printf("%lfn",randn();fclose(fp); return 0;3.泊松分布:#include<stdio.h>#include<stdlib.h>#include<ctime>#include<math.h>/Generate the random numb
8、erslong Possion(double u)double P,U;long N;u=exp(-u);P=1;N=0;while(1)U=(double)rand()/RAND_MAX;P=P*U;if(P<=u) break;N+;return N;/ Generate 10000 distributed random output numbers which are put into a text called”312”void main() int k; double lamda; scanf("%lf",&lamda); FILE *fp1; fp
9、1=fopen("p1.txt","w"); srand(unsigned)time(0); for(k=1;k<10000;k+) fprintf(fp1,"%6ld ",Possion(lamda); fclose(fp1); 4. Design a 128th order FIR band-pass digital filter with cut-off frequencies 10 MHz & 50 MHz Apply it to a signal, and display related filter and
10、signal waveforms.fc=1000; %載波頻率Êfc=1000HZqifs=280; %采樣頻率fs=280HZt=1:2:1000; x=sin(2*pi*t*fc); %generate signal waveforms.a=fir1(128,10 50/(qifs/2) ; %Bandpass butt.freqz (a,1) ; % plot gain & phase (the b array is 1 for FIR filter)y=filter(a,1, x); % FIR band-pass filter design. 5. Design a
11、 4th order IIR low-pass filter with fc = 100 Hz.Apply it to a signal, and display related filter and signal waveforms.fc =100; %載波頻率fc=100HZqifs=1000; %采樣頻率fs=1KHZt=(1:1000)/500; x=sin(2*pi*t*fc) %generate signal waveforms.a,b=butter(4, fc/(qifs/2) ) ; % lowpass Butt.freqz (a,b) ; % plot gain &
12、phase responses of digital filtersy=filter(a,b,x); % to implement6. Based on Program 2.3/2.4 of Ref.9 (by Yong Soo Cho, et al), investigate the impact of of the RMS delay spread and T s tothe channel frequency selectivity.% plot_IEEE80211_model.mclear, clfscale=1e-9; % nanoTs=100*scale; % Sampling t
13、imet_rms=250*scale; % RMS delay spreadnum_ch=10000; % Number of channelsN=128; % FFT sizePDP=IEEE802_11_model(t_rms,Ts); for k=1:length(PDP) h(:,k) = Ray_model(num_ch).'*sqrt(PDP(k); avg_pow_h(k)= mean(h(:,k).*conj(h(:,k);endH=fft(h(1,:),N);subplot(221)stem(0:length(PDP)-1,PDP,'ko'), hol
14、d on,stem(0:length(PDP)-1,avg_pow_h,'k.');xlabel('channel tap index, p'), ylabel('Average Channel Powerlinear');title('IEEE 802.11 Model, sigma_tau=25ns, T_S=25ns');legend('Ideal','Simulation'); axis(-1 7 0 1);subplot(222)plot(-N/2+1:N/2/N/Ts/106,10*lo
15、g10(H.*conj(H),'k-');xlabel('FrequencyMHz'), ylabel('Channel powerdB')title('Frequency response, sigma_tau=25ns, T_S=25ns');7. Simulate a BPSK communication system, comparing simulated with theoretical BER results under AWGN channel.clc;clear all;close all;num=;for SN
16、R=0:10 data_bpsk=randsrc(1,num,1,-1); snr=1/(10(SNR/10); noise=sqrt(snr/2)*(randn(1,num); receive=data_bpsk+noise; pe(SNR+1)=0; for(i=1:num) if (receive(i)>=0) r_data(i)=1; else r_data(i)=-1; end end pe(SNR+1)=(sum(abs(r_data-data_bpsk)/2)/num; peb(SNR+1)=0.5*erfc(sqrt(10(SNR/10);endr=0:10;semilo
17、gy(r,peb,'b-v',r,pe,'m-x');%對y取底為10對數(shù)grid on;legend('理論誤碼率曲線','仿真誤碼率曲線');8. Simulate the error performance of a QPSK system using Quasi-analytical method, under AWGN channel. At least 200 errors should be generated for each EbNo% QPSK System Simulation, Pe evaluationc
18、lear;clc;SNRindB1=0:0.05:10; %仿真信噪比范圍SNRindB2=0:0.1:10; %理論信噪比范圍for i=1:length(SNRindB1), pb=cm_sm32(SNRindB1(i); % simulated bit error rates smld_bit_err_prb(i)=pb; disp(pb); echo off;end;%echo on;For i=1:length(SNRindB2), SNR=exp(SNRindB2(i)*log(10)/10); % signal to noise ratio theo_err_prb(i)=0.5
19、*erfc(sqrt(SNR); % theoretical bit error rate echo off;end;% Plotting commands follow %作圖grid onsemilogy(SNRindB1,smld_bit_err_prb,'*'); % 用對數(shù)坐標作出仿真信噪比-誤比特率的點hold onsemilogy(SNRindB2,theo_err_prb); %用對數(shù)坐標作出理論信噪比-誤比特率曲線hold onxlabel('信噪比(dB)');ylabel('誤碼率');legend('bit err
20、or probability','theory error probability');title('BER performance of QPSK transmission scheme under AWGN channel');function pb,ps=cm_sm32(snr_in_dB)% pb,ps=cm_sm32(snr_in_dB)% CM_SM3 finds the probability of bit error and symbol error for % the given value of snr_in_dB, signal t
21、o noise ratio in dB.N=10000;E=1; % energy per symbolsnr=10(snr_in_dB/10); % signal to noise ratiosgma=sqrt(E/snr)/2; % noise variances00=1 0; s01=0 1; s11=-1 0; s10=0 -1; % signal mapping% generation of the data source, QPSK modulationfor i=1:N, temp=rand; % a uniform random variable between 0 and 1
22、 if (temp<0.25), % with probability 1/4, source output is "00" dsource1(i)=0; dsource2(i)=0; elseif (temp<0.5), % with probability 1/4, source output is "01" dsource1(i)=0; dsource2(i)=1; elseif (temp<0.75), % with probability 1/4, source output is "10" dsource
23、1(i)=1; dsource2(i)=0; else % with probability 1/4, source output is "11" dsource1(i)=1; dsource2(i)=1; end;end;% detection and the probability of error calculationnumofsymbolerror=0;numofbiterror=0;% go through AWGN channelfor i=1:N, % the received signal at the detection, for the ith sym
24、bol,is: n=sgma*randn(1,2); % 2 normal distributed r.v with 0, variance sgma if (dsource1(i)=0) & (dsource2(i)=0), r=s00+n; elseif (dsource1(i)=0) & (dsource2(i)=1), r=s01+n; elseif (dsource1(i)=1) & (dsource2(i)=0), r=s10+n; else r=s11+n; end; % The correlation metrics are computed below
25、 c00=dot(r,s00); c01=dot(r,s01); c10=dot(r,s10); c11=dot(r,s11); % The decision on the ith symbol is made next c_max=max(c00,c01,c10,c11);% The decision on the ith symbol, MLD if (c00=c_max), decis1=0; decis2=0; elseif (c01=c_max), decis1=0; decis2=1; elseif (c10=c_max), decis1=1; decis2=0; else dec
26、is1=1; decis2=1; end;% Later, increment the error counter, if the decision is not correct, % Increment the error counter, if the decision is not correct symbolerror=0; if (decis1=dsource1(i), numofbiterror=numofbiterror+1; symbolerror=1; end; if (decis2=dsource2(i), numofbiterror=numofbiterror+1; sy
27、mbolerror=1; end; if (symbolerror=1), numofsymbolerror=numofsymbolerror+1; end;end;ps=numofsymbolerror/N; % since there are totally N symbolspb=numofbiterror/(2*N); % since 2N bits are transmitted9. Simulate the error performance of an 8-QAM system using the built-in Matlab channel function " rayleighchan ".% 8QAM System Simulation, Pe evaluation M=8; % QAM 調制階數(shù) k = log2(M); hMod=comm.RectangularQAMModulator(M); % 產生 8 QAM 信號調制器 display(hMod); txd = randint(1e4,1,M); %產生1,M范圍的均勻分布的隨機序列,用于在接收端發(fā)送基帶信號 qamSig = step(hMod,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 視覺感知行業(yè)面臨的機遇分析
- 山東省濟寧市任城區(qū)2024-2025學年下學期期中質量檢測六年級數(shù)學試題(含部分答案)
- 江蘇省常州市2024-2025學年七年級下學期期末模擬練習英語試卷(含答案)
- 河北省保定市定州市2024-2025學年八年級下學期4月期中數(shù)學試題(含答案)
- 2024-2025學年四校聯(lián)合教學質量檢測高一地理
- 部編版三年級上冊第三單元《去年的樹》教案
- 建筑施工特種作業(yè)-建筑起重機械司機(塔式起重機)真題庫-4
- 建筑施工特種作業(yè)-建筑起重機械安裝拆卸工(施工升降機)真題庫-2
- 入隊教育考核題目及答案
- 2023-2024學年四川省瀘州市江陽區(qū)高二下學期6月期末數(shù)學試題(解析版)
- DB37T 2906-2019 運動場地合成材料面層 驗收要求
- DB34∕T 451-2017 地理標志產品 舒城小蘭花
- 《卓有成效的管理者》Word電子版電子版本
- 三生事業(yè)六大價值
- 鋯石基本特征及地質應用
- 絲網除沫器小計算
- 制缽機的設計(機械CAD圖紙)
- 學校財務管理制度
- 三年級下冊美術課件-第15課色彩拼貼畫|湘美版(共11張PPT)
- 水稻病蟲統(tǒng)防統(tǒng)治工作總結
- 水在不同溫度下的折射率、粘度和介電常數(shù)
評論
0/150
提交評論