基於MATLAB的模擬調製訊號與解調的模擬——DSB
阿新 • • 發佈:2018-12-12
實現模擬調製訊號與解調的模擬是我的MATLAB課程設計的一部分,我參考了網上的一些資料,並加入了一些自己的想法,程式碼已在本地MATLAB編譯通過且能正常執行
DSB——雙邊帶調製
dt=0.001; %時間取樣間隔 fm=1; %信源最高頻率 fc=10; %載波中心頻率 T=5; %訊號時長 t=0:dt:T; mt=sqrt(2)*cos(2*pi*fm*t); %信源 figure(1) subplot(311); plot(t,mt); title('調製訊號') coss=cos(2*pi*fc*t); subplot(312); plot(t,coss); title('載波訊號') %N0=0.01; %白噪聲單邊功率譜密度 %DSB調製 s_dsb=mt.*cos(2*pi*fc*t); B=2*fm; %noise=noise_nb(fc,B,N0,t); %s_dsb=s_dsb+noise; subplot(313) plot(t,s_dsb); %畫出DSB訊號波形 hold on plot (t,mt,'r--'); %標出m(t)波形 hold on plot(t,-mt,'r--'); title('DSB調製訊號'); %DSB相干解調 rt=s_dsb.*cos(2*pi*fc*t); figure(2); subplot(311); plot(t,rt); title('DSB調製訊號與載波訊號相乘') [f,rf]=T2F(t,rt);%傅立葉變換 [t,rt]=lpf(f,rf,fm);%低通濾波 subplot(312) plot(t,rt); title('經過低通濾波的相干解調訊號波形'); rt=rt-mean(rt); 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訊號功率譜');
用到的函式
①T2F.m
function [f,sf]= T2F(t,st) %利用FFT計算訊號的頻譜並與訊號的真實頻譜的抽樣比較。 %指令碼檔案T2F.m定義了函式T2F,計算訊號的傅立葉變換。 %This is a function using the FFT function to calculate a signal 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);
②lpf.m
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: lowpass bandwidth with a rectangle lowpass %Outputs: t: time samples % st: output data 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);