通信原理基于matlab的計(jì)算機(jī)仿真源代碼.doc
《通信原理基于matlab的計(jì)算機(jī)仿真源代碼.doc》由會(huì)員分享,可在線閱讀,更多相關(guān)《通信原理基于matlab的計(jì)算機(jī)仿真源代碼.doc(35頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。
例 Error! No text of specified style in document.1 %周期信號(hào)(方波)的展開(kāi),fb_jinshi.m close all; clear all; N=100; %取展開(kāi)式的項(xiàng)數(shù)為2N+1項(xiàng) T=1; fs=1/T; N_sample=128; %為了畫出波形,設(shè)置每個(gè)周期的采樣點(diǎn)數(shù) dt = T/N_sample; t=0:dt:10*T-dt; n=-N:N; Fn = sinc(n/2).*exp(-j*n*pi/2); Fn(N+1)=0; ft = zeros(1,length(t)); for m=-N:N ft = ft + Fn(m+N+1)*exp(j*2*pi*m*fs*t); end plot(t,ft) 例 Error! No text of specified style in document.4 利用FFT計(jì)算信號(hào)的頻譜并與信號(hào)的真實(shí)頻譜的抽樣比較。 腳本文件T2F.m定義了函數(shù)T2F,計(jì)算信號(hào)的傅立葉變換。 function [f,sf]= T2F(t,st) %This is a function using the FFT function to calculate a signals Fourier %Translation %Input is the time and the signal vectors,the length of time must greater %than 2 %Output is the frequency and the signal spectrum dt = t(2)-t(1); T=t(end); df = 1/T; N = length(st); f=-N/2*df:df:N/2*df-df; sf = fft(st); sf = T/N*fftshift(sf); 腳本文件F2T.m定義了函數(shù)F2T,計(jì)算信號(hào)的反傅立葉變換。 function [t st]=F2T(f,sf) %This function calculate the time signal using ifft function for the input %signals spectrum df = f(2)-f(1); Fmx = ( f(end)-f(1) +df); dt = 1/Fmx; N = length(sf); T = dt*N; %t=-T/2:dt:T/2-dt; t = 0:dt:T-dt; sff = fftshift(sf); st = Fmx*ifft(sff); 另寫腳本文件fb_spec.m如下: %方波的傅氏變換, fb_spec.m clear all;close all; T=1; N_sample = 128; dt=T/N_sample; t=0:dt:T-dt; st=[ones(1,N_sample/2), -ones(1,N_sample/2)]; %方波一個(gè)周期 subplot(211); plot(t,st); axis([0 1 -2 2]); xlabel(t); ylabel(s(t)); subplot(212); [f sf]=T2F(t,st); %方波頻譜 plot(f,abs(sf)); hold on; axis([-10 10 0 1]); xlabel(f);ylabel(|S(f)|); %根據(jù)傅氏變換計(jì)算得到的信號(hào)頻譜相應(yīng)位置的抽樣值 sff= T^2*j*pi*f*0.5.*exp(-j*2*pi*f*T).*sinc(f*T*0.5).*sinc(f*T*0.5); plot(f,abs(sff),r-) 例 Error! No text of specified style in document.5 %信號(hào)的能量計(jì)算或功率計(jì)算,sig_pow.m clear all; close all; dt = 0.01; t = 0:dt:5; s1 = exp(-5*t).*cos(20*pi*t); s2 = cos(20*pi*t); E1 = sum(s1.*s1)*dt; %s1(t)的信號(hào)能量 P2 = sum(s2.*s2)*dt/(length(t)*dt); %s2(t)的信號(hào)功率s [f1 s1f]= T2F(t,s1); [f2 s2f]= T2F(t,s2); df = f1(2)-f1(1); E1_f = sum(abs(s1f).^2)*df; %s1(t)的能量,用頻域方式計(jì)算 df = f2(2)-f2(1); T = t(end); P2_f = sum(abs(s2f).^2)*df/T; %s2(t)的功率,用頻域方式計(jì)算 figure(1) subplot(211) plot(t,s1); xlabel(t); ylabel(s1(t)); subplot(212) plot(t,s2) xlabel(t); ylabel(s2(t)); 例 Error! No text of specified style in document.6 %方波的傅氏變換,sig_band.m clear all; close all; T=1; N_sample = 128; dt=1/N_sample; t=0:dt:T-dt; st=[ones(1,N_sample/2) -ones(1,N_sample/2)]; df=0.1/T; Fx = 1/dt; f=-Fx:df:Fx-df; %根據(jù)傅氏變換計(jì)算得到的信號(hào)頻譜 sff= T^2*j*pi*f*0.5.*exp(-j*2*pi*f*T).*sinc(f*T*0.5).*sinc(f*T*0.5); plot(f,abs(sff),r-) axis([-10 10 0 1]); hold on; sf_max = max(abs(sff)); line([f(1) f(end)],[sf_max sf_max]); line([f(1) f(end)],[sf_max/sqrt(2) sf_max/sqrt(2)]); %交點(diǎn)處為信號(hào)功率下降3dB處 Bw_eq = sum(abs(sff).^2)*df/T/sf_max.^2; %信號(hào)的等效帶寬 例 Error! No text of specified style in document.7 %帶通信號(hào)經(jīng)過(guò)帶通系統(tǒng)的等效基帶表示,sig_bandpass.m clear all; close all; dt = 0.01; t = 0:dt:5; s1 = exp(-t).*cos(20*pi*t); %輸入信號(hào) [f1 s1f]= T2F(t,s1); %輸入信號(hào)的頻譜 s1_lowpass = hilbert(s1).*exp(-j*2*pi*10*t); %輸入信號(hào)的等效基帶信號(hào) [f2 s2f]=T2F(t,s1_lowpass); %輸入等效基帶信號(hào)的頻譜 h2f = zeros(1,length(s2f)); [a b]=find( abs(s1f)==max(abs(s1f)) ); %找到帶通信號(hào)的中心頻率 h2f( 201-25:201+25 )= 1; h2f( 301-25:301+25) = 1; h2f = h2f.*exp(-j*2*pi*f2); %加入線性相位, [t1 h1] = F2T(f2,h2f); %帶通系統(tǒng)的沖激響應(yīng) h1_lowpass = hilbert(h1).*exp(-j*2*pi*10*t1); %等效基帶系統(tǒng)的沖激響應(yīng) figure(1) subplot(521); plot(t,s1); xlabel(t); ylabel(s1(t)); title(帶通信號(hào)); subplot(523); plot(f1,abs(s1f)); xlabel(f); ylabel(|S1(f)|); title(帶通信號(hào)幅度譜); subplot(522) plot(t,real(s1_lowpass)); xlabel(t);ylabel(Re[s_l(t)]);title(等效基帶信號(hào)的實(shí)部); subplot(524) plot(f2,abs(s2f)); xlabel(f);ylabel(|S_l(f)|);title(等效基帶信號(hào)的幅度譜); %畫帶通系統(tǒng)及其等效基帶的圖 subplot(525) plot(f2,abs(h2f)); xlabel(f);ylabel(|H(f)|);title(帶通系統(tǒng)的傳輸響應(yīng)幅度譜); subplot(527) plot(t1,h1); xlabel(t);ylabel(h(t));title(帶通系統(tǒng)的沖激響應(yīng)); subplot(526) [f3 hlf]=T2F(t1,h1_lowpass); plot(f3,abs(hlf)); xlabel(f);ylabel(|H_l(f)|);title(帶通系統(tǒng)的等效基帶幅度譜); subplot(528) plot(t1,h1_lowpass); xlabel(t);ylabel(h_l(t));title(帶通系統(tǒng)的等效基帶沖激響應(yīng)); %畫出帶通信號(hào)經(jīng)過(guò)帶通系統(tǒng)的響應(yīng) 及 等效基帶信號(hào)經(jīng)過(guò)等效基帶系統(tǒng)的響應(yīng) tt = 0:dt:t1(end)+t(end); yt = conv(s1,h1); subplot(529) plot(tt,yt); xlabel(t);ylabel(y(t));title(帶通信號(hào)與帶通系統(tǒng)響應(yīng)的卷積) ytl = conv(s1_lowpass,h1_lowpass).*exp(j*2*pi*10*tt); subplot(5,2,10) plot(tt,real(yt)); xlabel(t);ylabel(y_l(t)cos(20*pi*t); title(等效基帶與等效基帶系統(tǒng)響應(yīng)的卷積中心頻率載波) 例 36 %例:窄帶高斯過(guò)程,文件 zdpw.m clear all; close all; N0=1; %雙邊功率譜密度 fc=10; %中心頻率 B=1; %帶寬 dt=0.01; T=100; t=0:dt:T-dt; %產(chǎn)生功率為N0*B的高斯白噪聲 P = N0*B; st = sqrt(P)*randn(1,length(t)); %將上述白噪聲經(jīng)過(guò)窄帶帶通系統(tǒng), [f,sf] = T2F(t,st); %高斯信號(hào)頻譜 figure(1) plot(f,abs(sf)); %高斯信號(hào)的幅頻特性 [tt gt]=bpf(f,sf,fc-B/2,fc+B/2); %高斯信號(hào)經(jīng)過(guò)帶通系統(tǒng) glt = hilbert(real(gt)); %窄帶信號(hào)的解析信號(hào),調(diào)用hilbert函數(shù)得到解析信號(hào) glt = glt.*exp(-j*2*pi*fc*tt); [ff,glf]=T2F( tt, glt ); figure(2) plot(ff,abs(glf)); xlabel(頻率(Hz)); ylabel(窄帶高斯過(guò)程樣本的幅頻特性) figure(3) subplot(411); plot(tt,real(gt)); title(窄帶高斯過(guò)程樣本) subplot(412) plot(tt,real(glt).*cos(2*pi*fc*tt)-imag(glt).*sin(2*pi*fc*tt)) title(由等效基帶重構(gòu)的窄帶高斯過(guò)程樣本) subplot(413) plot(tt,real(glt)); title(窄帶高斯過(guò)程樣本的同相分量) subplot(414) plot(tt,imag(glt)); xlabel(時(shí)間t(秒)); title(窄帶高斯過(guò)程樣本的正交分量) %求窄帶高斯信號(hào)功率;注:由于樣本的功率近似等于隨機(jī)過(guò)程的功率,因此可能出現(xiàn)一些偏差 P_gt=sum(real(gt).^2)/T; P_glt_real = sum(real(glt).^2)/T; P_glt_imag = sum(imag(glt).^2)/T; %驗(yàn)證窄帶高斯過(guò)程的同相分量、正交分量的正交性 a = real(glt)*(imag(glt))/T; 用到的子函數(shù) function [t,st]=bpf(f,sf,B1,B2) %This function filter an input at frequency domain by an ideal bandpass filter %Inputs: % f: frequency samples % sf: input data spectrum samples % B1: bandpasss lower frequency % B2: bandpasss higher frequency %Outputs: % t: frequency samples % st: output datas time samples df = f(2)-f(1); T = 1/df; hf = zeros(1,length(f)); bf = [floor( B1/df ): floor( B2/df )] ; bf1 = floor( length(f)/2 ) + bf; bf2 = floor( length(f)/2 ) - bf; hf(bf1)=1/sqrt(2*(B2-B1)); hf(bf2)=1/sqrt(2*(B2-B1)); yf=hf.*sf.*exp(-j*2*pi*f*0.1*T); [t,st]=F2T(f,yf); 例 41 %顯示模擬調(diào)制的波形及解調(diào)方法DSB,文件mdsb.m %信源 close all; clear all; dt = 0.001; %時(shí)間采樣間隔 fm=1; %信源最高頻率 fc=10; %載波中心頻率 T=5; %信號(hào)時(shí)長(zhǎng) t = 0:dt:T; mt = sqrt(2)*cos(2*pi*fm*t); %信源 %N0 = 0.01; %白噪單邊功率譜密度 %DSB modulation s_dsb = mt.*cos(2*pi*fc*t); B=2*fm; %noise = noise_nb(fc,B,N0,t); %s_dsb=s_dsb+noise; figure(1) subplot(311) plot(t,s_dsb);hold on; %畫出DSB信號(hào)波形 plot(t,mt,r--); %標(biāo)示mt的波形 title(DSB調(diào)制信號(hào)); xlabel(t); %DSB demodulation rt = s_dsb.*cos(2*pi*fc*t); rt = rt-mean(rt); [f,rf] = T2F(t,rt); [t,rt] = lpf(f,rf,2*fm); subplot(312) plot(t,rt); hold on; plot(t,mt/2,r--); title(相干解調(diào)后的信號(hào)波形與輸入信號(hào)的比較); xlabel(t) subplot(313) [f,sf]=T2F(t,s_dsb); psf = (abs(sf).^2)/T; plot(f,psf); axis([-2*fc 2*fc 0 max(psf)]); title(DSB信號(hào)功率譜); xlabel(f); function [t st]=lpf(f,sf,B) %This function filter an input data using a lowpass filter %Inputs: f: frequency samples % sf: input data spectrum samples % B: lowpasss bandwidth with a rectangle lowpass %Outputs: t: time samples % st: output datas time samples df = f(2)-f(1); T = 1/df; hf = zeros(1,length(f)); bf = [-floor( B/df ): floor( B/df )] + floor( length(f)/2 ); hf(bf)=1; yf=hf.*sf; [t,st]=F2T(f,yf); st = real(st); 例 42 %顯示模擬調(diào)制的波形及解調(diào)方法AM,文件mam.m %信源 close all; clear all; dt = 0.001; %時(shí)間采樣間隔 fm=1; %信源最高頻率 fc=10; %載波中心頻率 T=5; %信號(hào)時(shí)長(zhǎng) t = 0:dt:T; mt = sqrt(2)*cos(2*pi*fm*t); %信源 %N0 = 0.01; %白噪單邊功率譜密度 %AM modulation A=2; s_am = (A+mt).*cos(2*pi*fc*t); B = 2*fm; %帶通濾波器帶寬 %noise = noise_nb(fc,B,N0,t); %窄帶高斯噪聲產(chǎn)生 %s_am = s_am + noise; figure(1) subplot(311) plot(t,s_am);hold on; %畫出AM信號(hào)波形 plot(t,A+mt,r--); %標(biāo)示AM的包絡(luò) title(AM調(diào)制信號(hào)及其包絡(luò)); xlabel(t); %AM demodulation rt = s_am.*cos(2*pi*fc*t); %相干解調(diào) rt = rt-mean(rt); [f,rf] = T2F(t,rt); [t,rt] = lpf(f,rf,2*fm); %低通濾波 subplot(312) plot(t,rt); hold on; plot(t,mt/2,r--); title(相干解調(diào)后的信號(hào)波形與輸入信號(hào)的比較); xlabel(t) subplot(313) [f,sf]=T2F(t,s_am); psf = (abs(sf).^2)/T; plot(f,psf); axis([-2*fc 2*fc 0 max(psf)]); title(AM信號(hào)功率譜); xlabel(f); 例 43 %顯示模擬調(diào)制的波形及解調(diào)方法SSB,文件mssb.m %信源 close all; clear all; dt = 0.001; %時(shí)間采樣間隔 fm=1; %信源最高頻率 fc=10; %載波中心頻率 T=5; %信號(hào)時(shí)長(zhǎng) t = 0:dt:T; mt = sqrt(2)*cos(2*pi*fm*t); %信源 %N0 = 0.01; %白噪單邊功率譜密度 %SSB modulation s_ssb = real( hilbert(mt).*exp(j*2*pi*fc*t) ); B=fm; %noise = noise_nb(fc,B,N0,t); %s_ssb=s_ssb+noise; figure(1) subplot(311) plot(t,s_ssb);hold on; %畫出SSB信號(hào)波形 plot(t,mt,r--); %標(biāo)示mt的波形 title(SSB調(diào)制信號(hào)); xlabel(t); %SSB demodulation rt = s_ssb.*cos(2*pi*fc*t); rt = rt-mean(rt); [f,rf] = T2F(t,rt); [t,rt] = lpf(f,rf,2*fm); subplot(312) plot(t,rt); hold on; plot(t,mt/2,r--); title(相干解調(diào)后的信號(hào)波形與輸入信號(hào)的比較); xlabel(t) subplot(313) [f,sf]=T2F(t,s_ssb); psf = (abs(sf).^2)/T; plot(f,psf); axis([-2*fc 2*fc 0 max(psf)]); title(SSB信號(hào)功率譜); xlabel(f); 例 44 %顯示模擬調(diào)制的波形及解調(diào)方法VSB,文件mvsb.m %信源 close all; clear all; dt = 0.001; %時(shí)間采樣間隔 fm=5; %信源最高頻率 fc=20; %載波中心頻率 T=5; %信號(hào)時(shí)長(zhǎng) t = 0:dt:T; mt = sqrt(2)*( cos(2*pi*fm*t)+sin(2*pi*0.5*fm*t) ); %信源 %VSB modulation s_vsb = mt.*cos(2*pi*fc*t); B=1.2*fm; [f,sf] = T2F(t,s_vsb); [t,s_vsb] = vsbpf(f,sf,0.2*fm,1.2*fm,fc); figure(1) subplot(311) plot(t,s_vsb);hold on; %畫出VSB信號(hào)波形 plot(t,mt,r--); %標(biāo)示mt的波形 title(VSB調(diào)制信號(hào)); xlabel(t); %VSB demodulation rt = s_vsb.*cos(2*pi*fc*t); [f,rf] = T2F(t,rt); [t,rt] = lpf(f,rf,2*fm); subplot(312) plot(t,rt); hold on; plot(t,mt/2,r--); title(相干解調(diào)后的信號(hào)波形與輸入信號(hào)的比較); xlabel(t) subplot(313) [f,sf]=T2F(t,s_vsb); psf = (abs(sf).^2)/T; plot(f,psf); axis([-2*fc 2*fc 0 max(psf)]); title(VSB信號(hào)功率譜); xlabel(f); function [t,st]=vsbpf(f,sf,B1,B2,fc) %This function filter an input by an residual bandpass filter %Inputs: f: frequency samples % sf: input data spectrum samples % B1: residual bandwidth % B2: highest freq of the basedband signal %Outputs: t: frequency samples % st: output datas time samples df = f(2)-f(1); T = 1/df; hf = zeros(1,length(f)); bf1 = [floor( (fc-B1)/df ): floor( (fc+B1)/df )] ; bf2 = [floor( (fc+B1)/df )+1: floor( (fc+B2)/df )]; f1 = bf1 + floor( length(f)/2 ) ; f2 = bf2 + floor( length(f)/2 ) ; stepf = 1/length(f1); hf(f1)=0:stepf:1-stepf; hf(f2)=1; f3 = -bf1 + floor( length(f)/2 ) ; f4 = -bf2 + floor( length(f)/2) ; hf(f3)=0:stepf:(1-stepf); hf(f4)=1; yf=hf.*sf; [t,st]=F2T(f,yf); st = real(st); 例 45 %顯示模擬調(diào)制的波形及解調(diào)方法AM、DSB、SSB, %信源 close all; clear all; dt = 0.001; fm=1; fc=10; t = 0:dt:5; mt = sqrt(2)*cos(2*pi*fm*t); N0 = 0.1; %AM modulation A=2; s_am = (A+mt).*cos(2*pi*fc*t); B = 2*fm; noise = noise_nb(fc,B,N0,t); s_am = s_am + noise; figure(1) subplot(321) plot(t,s_am);hold on; plot(t,A+mt,r--); %AM demodulation rt = s_am.*cos(2*pi*fc*t); rt = rt-mean(rt); [f,rf] = T2F(t,rt); [t,rt] = lpf(f,rf,2*fm); title(AM信號(hào));xlabel(t); subplot(322) plot(t,rt); hold on; plot(t,mt/2,r--); title(AM解調(diào)信號(hào));xlabel(t); %DSB modulation s_dsb = mt.*cos(2*pi*fc*t); B=2*fm; noise = noise_nb(fc,B,N0,t); s_dsb=s_dsb+noise; subplot(323) plot(t,s_dsb);hold on; plot(t,mt,r--); title(DSB信號(hào));xlabel(t); %DSB demodulation rt = s_dsb.*cos(2*pi*fc*t); rt = rt-mean(rt); [f,rf] = T2F(t,rt); [t,rt] = lpf(f,rf,2*fm); subplot(324) plot(t,rt); hold on; plot(t,mt/2,r--); title(DSB解調(diào)信號(hào));xlabel(t); %SSB modulation s_ssb = real( hilbert(mt).*exp(j*2*pi*fc*t) ); B=fm; noise = noise_nb(fc,B,N0,t); s_ssb=s_ssb+noise; subplot(325) plot(t,s_ssb); title(SSB信號(hào));xlabel(t); %SSB demodulation rt = s_ssb.*cos(2*pi*fc*t); rt = rt-mean(rt); [f,rf] = T2F(t,rt); [t,rt] = lpf(f,rf,2*fm); subplot(326) plot(t,rt); hold on; plot(t,mt/2,r--); title(SSB解調(diào)信號(hào));xlabel(t); function [out] = noise_nb(fc,B,N0,t) %output the narrow band gaussian noise sample with single-sided power spectrum N0 %at carrier frequency equals fc and bandwidth euqals B dt = t(2)-t(1); Fmx = 1/dt; n_len = length(t); p = N0*Fmx; rn = sqrt(p)*randn(1,n_len); [f,rf] = T2F(t,rn); [t,out] = bpf(f,rf,fc-B/2,fc+B/2); 例 46 %FM modulation and demodulation,mfm.m clear all; close all; Kf = 5; fc = 10; T=5; dt=0.001; t = 0:dt:T; %信源 fm= 1; %mt = cos(2*pi*fm*t) + 1.5*sin(2*pi*0.3*fm*t); %信源信號(hào) mt = cos(2*pi*fm*t); %信源信號(hào) %FM 調(diào)制 A = sqrt(2); %mti = 1/2/pi/fm*sin(2*pi*fm*t) -3/4/pi/0.3/fm*cos(2*pi*0.3*fm*t); %mt的積分函數(shù) mti = 1/2/pi/fm*sin(2*pi*fm*t) ; %mt的積分函數(shù) st = A*cos(2*pi*fc*t + 2*pi*Kf*mti); figure(1) subplot(311); plot(t,st); hold on; plot(t,mt,r--); xlabel(t);ylabel(調(diào)頻信號(hào)) subplot(312) [f sf] = T2F(t,st); plot(f, abs(sf)); axis([-25 25 0 3]) xlabel(f);ylabel(調(diào)頻信號(hào)幅度譜) %FM 解調(diào) for k=1:length(st)-1 rt(k) = (st(k+1)-st(k))/dt; end rt(length(st))=0; subplot(313) plot(t,rt); hold on; plot(t,A*2*pi*Kf*mt+A*2*pi*fc,r--); xlabel(t);ylabel(調(diào)頻信號(hào)微分后包絡(luò)) 例 51 %數(shù)字基帶信號(hào)的功率譜密度 digit_baseband.m clear all; close all; Ts=1; N_sample = 8; %每個(gè)碼元的抽樣點(diǎn)數(shù) dt = Ts/N_sample; %抽樣時(shí)間間隔 N = 1000; %碼元數(shù) t = 0:dt:(N*N_sample-1)*dt; gt1 = ones(1,N_sample); %NRZ非歸零波形 gt2 = ones(1,N_sample/2); %RZ歸零波形 gt2 = [gt2 zeros(1,N_sample/2)]; mt3 = sinc((t-5)/Ts); % sin(pi*t/Ts)/(pi*t/Ts)波形,截段取10個(gè)碼元 gt3 = mt3(1:10*N_sample); d = ( sign( randn(1,N) ) +1 )/2; data = sigexpand(d,N_sample); %對(duì)序列間隔插入N_sample-1個(gè)0 st1 = conv(data,gt1); %Matlab自帶卷積函數(shù) st2 = conv(data,gt2); d = 2*d-1; %變成雙極性序列 data= sigexpand(d,N_sample); st3 = conv(data,gt3); [f,st1f] = T2F(t,[st1(1:length(t))]); [f,st2f] = T2F(t,[st2(1:length(t))]); [f,st3f] = T2F(t,[st3(1:length(t))]); figure(1) subplot(321) plot(t,[st1(1:length(t))] );grid axis([0 20 -1.5 1.5]);ylabel(單極性NRZ波形); subplot(322); plot(f,10*log10(abs(st1f).^2/T) );grid axis([-5 5 -40 10]); ylabel(單極性NRZ功率譜密度(dB/Hz)); subplot(323) plot(t,[st2(1:length(t))] ); axis([0 20 -1.5 1.5]);grid ylabel(單極性RZ波形); subplot(324) plot(f,10*log10(abs(st2f).^2/T)); axis([-5 5 -40 10]);grid ylabel(單極性RZ功率譜密度(dB/Hz)); subplot(325) plot(t-5,[st3(1:length(t))] ); axis([0 20 -2 2]);grid ylabel(雙極性sinc波形);xlabel(t/Ts); subplot(326) plot(f,10*log10(abs(st3f).^2/T)); axis([-5 5 -40 10]);grid ylabel(sinc波形功率譜密度(dB/Hz));xlabel(f*Ts); function [out]=sigexpand(d,M) %將輸入的序列擴(kuò)展成間隔為N-1個(gè)0的序列 N = length(d); out = zeros(M,N); out(1,:) = d; out = reshape(out,1,M*N); 例 52 %數(shù)字基帶信號(hào)接收示意 digit_receive.m clear all; close all; N =100; N_sample=8; %每碼元抽樣點(diǎn)數(shù) Ts=1; dt = Ts/N_sample; t=0:dt:(N*N_sample-1)*dt; gt = ones(1,N_sample); %數(shù)字基帶波形 d = sign(randn(1,N)); %輸入數(shù)字序列 a = sigexpand(d,N_sample); st = conv(a,gt); %數(shù)字基帶信號(hào) ht1 = gt; rt1 = conv(st,ht1); ht2 = 5*sinc(5*(t-5)/Ts); rt2 = conv(st,ht2); figure(1) subplot(321) plot( t,st(1:length(t)) ); axis([0 20 -1.5 1.5]); ylabel(輸入雙極性NRZ數(shù)字基帶波形); subplot(322) stem( t,a); axis([0 20 -1.5 1.5]); ylabel(輸入數(shù)字序列) subplot(323) plot( t,[0 rt1(1:length(t)-1)]/8 ); axis([0 20 -1.5 1.5]);ylabel(方波濾波后輸出); subplot(324) dd = rt1(N_sample:N_sample:end); ddd= sigexpand(dd,N_sample); stem( t,ddd(1:length(t))/8 ); axis([0 20 -1.5 1.5]);ylabel(方波濾波后抽樣輸出); subplot(325) plot(t-5, [0 rt2(1:length(t)-1)]/8 ); axis([0 20 -1.5 1.5]); xlabel(t/Ts); ylabel(理想低通濾波后輸出); subplot(326) dd = rt2(N_sample-1:N_sample:end); ddd=sigexpand(dd,N_sample); stem( t-5,ddd(1:length(t))/8 ); axis([0 20 -1.5 1.5]); xlabel(t/Ts); ylabel(理想低通濾波后抽樣輸出); 例 57 %部分響應(yīng)信號(hào)眼圖示意,pres.m clear all; close all; Ts=1; N_sample=16; eye_num = 11; N_data=1000; dt = Ts/N_sample; t = -5*Ts:dt:5*Ts; %產(chǎn)生雙極性數(shù)字信號(hào) d = sign(randn(1,N_data)); dd= sigexpand(d,N_sample); %部分響應(yīng)系統(tǒng)沖擊響應(yīng) ht = sinc((t+eps)/Ts)./(1- (t+eps)./Ts); ht( 6*N_sample+1 ) = 1; st = conv(dd,ht); tt = -5*Ts:dt:(N_data+5)*N_sample*dt-dt; figure(1) subplot(211); plot(tt,st); axis([0 20 -3 3]);xlabel(t/Ts);ylabel(部分響應(yīng)基帶信號(hào)); subplot(212) %畫眼圖 ss=zeros(1,eye_num*N_sample); ttt = 0:dt:eye_num*N_sample*dt-dt; for k=5:50 ss = st(k*N_sample+1:(k+eye_num)*N_sample); drawnow; plot(ttt,ss); hold on; end %plot(ttt,ss); xlabel(t/Ts);ylabel(部分響應(yīng)信號(hào)眼圖); 例 61 %2ASK,2PSK,文件名binarymod.m clear all; close all; A=1; fc = 2; %2Hz; N_sample = 8; N = 500; %碼元數(shù) Ts = 1; %1 baud/s dt = Ts/fc/N_sample; %波形采樣間隔 t = 0:dt:N*Ts-dt; Lt = length(t); %產(chǎn)生二進(jìn)制信源 d = sign(randn(1,N)); dd = sigexpand((d+1)/2,fc*N_sample); gt = ones(1,fc*N_sample); %NRZ波形 figure(1) subplot(221); %輸入NRZ信號(hào)波形(單極性) d_NRZ = conv(dd,gt); plot(t,d_NRZ(1:length(t))); axis([0 10 0 1.2]); ylabel(輸入信號(hào)); subplot(222); %輸入NRZ頻譜 [f,d_NRZf]=T2F( t,d_NRZ(1:length(t)) ); plot(f,10*log10(abs(d_NRZf).^2/T)); axis([-2 2 -50 10]);ylabel(輸入信號(hào)功率譜密度(dB/Hz)); %2ASK信號(hào) ht = A*cos(2*pi*fc*t); s_2ask = d_NRZ(1:Lt).*ht; subplot(223) plot(t,s_2ask); axis([0 10 -1.2 1.2]); ylabel(2ASK); [f,s_2askf]=T2F(t,s_2ask ); subplot(224) plot(f,10*log10(abs(s_2askf).^2/T)); axis([-fc-4 fc+4 -50 10]);ylabel(2ASK功率譜密度(dB/Hz)); figure(2) %2PSK信號(hào) d_2psk = 2*d_NRZ-1; s_2psk = d_2psk(1:Lt).*ht; subplot(221) plot(t,s_2psk); axis([0 10 -1.2 1.2]); ylabel(2PSK); subplot(222) [f,s_2pskf] = T2F(t,s_2psk); plot( f,10*log10(abs(s_2pskf).^2/T) ); axis([-fc-4 fc+4 -50 10]);ylabel(2PSK功率譜密度(dB/Hz)); % 2FSK % s_2fsk = Acos(2*pi*fc*t + int(2*d_NRZ-1) ); sd_2fsk = 2*d_NRZ-1; s_2fsk = A*cos(2*pi*fc*t + 2*pi*sd_2fsk(1:length(t)).*t ); subplot(223) plot(t,s_2fsk); axis([0 10 -1.2 1.2]);xlabel(t); ylabel(2FSK) subplot(224) [f,s_2fskf] = T2F(t,s_2fsk); plot(f,10*log10(abs(s_2fskf).^2/T)); axis([-fc-4 fc+4 -50 10]);xlabel(f);ylabel(2FSK功率譜密度(dB/Hz)); 例 63 %QPSK & OQPSK clear all; close all; M = 4; Ts= 1; fc= 10; N_sample = 16; N_num = 100; dt = 1/fc/N_sample; t = 0:dt:N_num*Ts-dt; T = dt*length(t); py1f = zeros(1,length(t)); %功率譜密度1 py2f = zeros(1,length(t)); %功率譜密度2 for PL=1:100 %輸入100段N_num個(gè)碼字的波形,為了使功率譜密度看起來(lái)更加平滑, %可以取這100段信號(hào)功率譜密度的平均 d1 = sign(randn(1,N_num)); d2 = sign(randn(1,N_num)); gt = ones(1,fc*N_sample); %QPSK調(diào)制 s1 = sigexpand(d1,fc*N_sample); s2 = sigexpand(d2,fc*N_sample); b1 = conv(s1,gt); b2 = conv(s2,gt); s1 = b1(1:length(s1)); s2 = b2(1:length(s2)); st_qpsk = s1.*cos(2*pi*fc*t) - s2.*sin(2*pi*fc*t); s2_delay= [-ones(1,N_sample*fc/2) s2(1:end-N_sample*fc/2)]; st_oqpsk= s1.*cos(2*pi*fc*t) - s2_delay.*sin(2*pi*fc*t); %經(jīng)過(guò)帶通后,再經(jīng)過(guò)非線性電路 [f y1f] = T2F(t,st_qpsk); [f y2f] = T2F(t,st_oqpsk); [t y1] = bpf(f,y1f,fc-1/Ts,fc+1/Ts); [t y2] = bpf(f,y2f,fc-1/Ts,fc+1/Ts); subplot(221); plot(t,y1); xlabel(t); ylabel(QPSK波形); axis([5 15 -1.6 1.6]);title(經(jīng)過(guò)帶通后的波形); subplot(222) plot(t,y2); xlabel(t); ylabel(OQPSK波形); axis([5 15 -1.6 1.6]);title(經(jīng)過(guò)帶通后的波形); %經(jīng)過(guò)非線性電路 y1 = 1.5*tanh(2*y1); y2 = 1.5*tanh(2*y2); [f y1f] = T2F(t,y1); [f y2f] = T2F(t,y2); py1f = py1f + abs(y1f).- 1.請(qǐng)仔細(xì)閱讀文檔,確保文檔完整性,對(duì)于不預(yù)覽、不比對(duì)內(nèi)容而直接下載帶來(lái)的問(wèn)題本站不予受理。
- 2.下載的文檔,不會(huì)出現(xiàn)我們的網(wǎng)址水印。
- 3、該文檔所得收入(下載+內(nèi)容+預(yù)覽)歸上傳者、原創(chuàng)作者;如果您是本文檔原作者,請(qǐng)點(diǎn)此認(rèn)領(lǐng)!既往收益都?xì)w您。
下載文檔到電腦,查找使用更方便
9.9 積分
下載 |
- 配套講稿:
如PPT文件的首頁(yè)顯示word圖標(biāo),表示該P(yáng)PT已包含配套word講稿。雙擊word圖標(biāo)可打開(kāi)word文檔。
- 特殊限制:
部分文檔作品中含有的國(guó)旗、國(guó)徽等圖片,僅作為作品整體效果示例展示,禁止商用。設(shè)計(jì)者僅對(duì)作品中獨(dú)創(chuàng)性部分享有著作權(quán)。
- 關(guān) 鍵 詞:
- 通信 原理 基于 matlab 計(jì)算機(jī)仿真 源代碼
鏈接地址:http://kudomayuko.com/p-9048854.html