?? ofdm_trans.m
字號(hào):
%DVB-T 2K Transmission
%The available bandwidth is 8 MHz
%2K is intended for mobile services
clear all;
close all;
%--------------------------DVB-T Parameters---------------------------------------------------------
Tu=224e-6; %useful OFDM symbol period
T=Tu/2048; %baseband elementary period
G=0; %choice of 1/4, 1/8, 1/16, and 1/32
delta=G*Tu; %guard band duration
Ts=delta+Tu; %total OFDM symbol period
Kmax=1705; %number of subcarriers
Kmin=0;
FS=4096; %IFFT/FFT length
q=10; %carrier period to elementary period ratio
fc=q*1/T; %carrier frequency
Rs=4*fc; %simulation period
t=0:1/Rs:Tu;
%--------------------------Data generator (A)-------------------------------------------------------
M=Kmax+1; %所有子載波的數(shù)目
rand('state',0); %確定隨機(jī)變量種子
a=-1+2*round(rand(M,1)).'+i*(-1+2*round(rand(M,1))).'; %生成信息位的復(fù)數(shù)據(jù),實(shí)部與虛部變化范圍為-1到1
A=length(a); %信息位長(zhǎng)度
info=zeros(FS,1); %信息位數(shù)據(jù)先賦零
info(1:(A/2)) = [ a(1:(A/2)).']; %信息位從1到1706/2賦隨機(jī)復(fù)數(shù)
info((FS-((A/2)-1)):FS) = [ a(((A/2)+1):A).']; %信息位從4906-1706/2+1賦隨機(jī)復(fù)數(shù),中間部分全部賦零
%----------------------------Subcarriers generation (B)-------------------------------------------------
carriers=FS.*ifft(info,FS); %對(duì)信息位作長(zhǎng)度為4096的IFFT(OFDM調(diào)制)
tt=0:T/2:Tu; %由于重采樣信息位之間時(shí)間間隔有T變化為T(mén)/2
figure(1);
subplot(211);
stem(tt(1:20),real(carriers(1:20))); %畫(huà)出前20個(gè)調(diào)制數(shù)據(jù)的實(shí)部
subplot(212);
stem(tt(1:20),imag(carriers(1:20))); %畫(huà)出前20個(gè)調(diào)制數(shù)據(jù)的虛部
figure(2);
f=(2/T)*(1:(FS))/(FS); %給出調(diào)制數(shù)據(jù)的頻率尺度f(wàn)
subplot(211);
plot(f,abs(fft(carriers,FS))/FS); %畫(huà)出調(diào)制數(shù)據(jù)的頻域幅度譜
subplot(212);
pwelch(carriers,[],[],[],2/T); %畫(huà)出調(diào)制數(shù)據(jù)的功率譜密度
% -------------------------------D/A simulation---------------------------------------------------------------
L = length(carriers); %調(diào)制數(shù)據(jù)長(zhǎng)度
chips = [ carriers.';zeros((2*q)-1,L)]; %以下七句模擬連續(xù)的調(diào)制數(shù)據(jù)(實(shí)際上就是將抽樣率升至RS)
p=1/Rs:1/Rs:T/2;
g=ones(length(p),1); %pulse shape
figure(3);
stem(p,g);
dummy=conv(g,chips(:));
u=[dummy(1:length(t))]; % (C)
figure(4);
subplot(211);
plot(t(1:400),real(u(1:400))); %畫(huà)出連續(xù)調(diào)制數(shù)據(jù)的前400點(diǎn)的實(shí)部
subplot(212);
plot(t(1:400),imag(u(1:400))); %畫(huà)出連續(xù)調(diào)制數(shù)據(jù)的前400點(diǎn)的虛部
figure(5);
ff=(Rs)*(1:(q*FS))/(q*FS); %給出連續(xù)調(diào)制數(shù)據(jù)的頻率尺度f(wàn)f
subplot(211);
plot(ff,abs(fft(u,q*FS))/FS); %給出連續(xù)調(diào)制數(shù)據(jù)的頻域幅度譜
subplot(212);
pwelch(u,[],[],[],Rs); %畫(huà)出連續(xù)調(diào)制數(shù)據(jù)的功率譜密度
[b,a] = butter(13,1/20); %reconstruction filter
[H,F] = FREQZ(b,a,FS,Rs); %給出低通濾波器的頻響特性
figure(6);
plot(F,20*log10(abs(H))); %畫(huà)出低通頻響
uoft = filter(b,a,u); %連續(xù)數(shù)據(jù)過(guò)低通
figure(7);
subplot(211);
plot(t(80:480),real(uoft(80:480))); %畫(huà)出經(jīng)過(guò)低通的數(shù)據(jù)的實(shí)部
subplot(212);
plot(t(80:480),imag(uoft(80:480))); %畫(huà)出經(jīng)過(guò)低通的數(shù)據(jù)的虛部
figure(8);
subplot(211);
plot(ff,abs(fft(uoft,q*FS))/FS); %畫(huà)出過(guò)D/A變換后的數(shù)據(jù)的頻域幅度譜
subplot(212);
pwelch(uoft,[],[],[],Rs); %畫(huà)出過(guò)D/A變換后的數(shù)據(jù)的功率譜密度
%-----------------------------------Upconverter---------------------------------------------------------
s_tilde=(uoft.').*exp(1i*2*pi*fc*t); %以fc為載波對(duì)經(jīng)過(guò)D/A變換后的數(shù)據(jù)作上變頻
s=real(s_tilde); %passband signal (E)
figure(9);
plot(t(80:480),s(80:480)); %畫(huà)出經(jīng)過(guò)上變頻后的數(shù)據(jù)
figure(10);
subplot(211);
%plot(ff,abs(fft(((real(uoft).').*cos(2*pi*fc*t)),q*FS))/FS);
%plot(ff,abs(fft(((imag(uoft).').*sin(2*pi*fc*t)),q*FS))/FS);
plot(ff,abs(fft(s,q*FS))/FS); %畫(huà)出經(jīng)過(guò)上變頻后的數(shù)據(jù)的頻域幅度譜
subplot(212);
%pwelch(((real(uoft).').*cos(2*pi*fc*t)),[],[],[],Rs);
%pwelch(((imag(uoft).').*sin(2*pi*fc*t)),[],[],[],Rs);
pwelch(s,[],[],[],Rs); %畫(huà)出經(jīng)過(guò)上變頻后的數(shù)據(jù)的功率譜密度
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -