⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ofdmtransmit.m

📁 ofdm的仿真
💻 M
字号:
%Transmission
%The available bandwidth is 8 MHz

clear all;
close all;

%Simulation 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;
rand('state',0);
a=-1+2*round(rand(M,1)).'+i*(-1+2*round(rand(M,1))).';%  qpsk  
A=length(a);
info=zeros(FS,1);
info(1:(A/2)) = [ a(1:(A/2)).']; %  Zero padding  
info((FS-((A/2)-1)):FS) = [ a(((A/2)+1):A).'];
%Subcarriers generation (B)
carriers=FS.*ifft(info,FS);
% tt=0:T/2:Tu;
% figure(1);
% subplot(211);
% stem(tt(1:20),real(carriers(1:20)));
% title('amp of the top 20 number');
% 
% subplot(212);
% stem(tt(1:20),imag(carriers(1:20)));
% title('arg of the top 20 number');
% figure(2);
% f=(2/T)*(1:(FS))/(FS);%(0-4096)*(1/T)
%subplot(211);
%plot(f,abs(fft(carriers,FS))/FS);
%title('info')
%subplot(212);
pwelch(carriers,[],[],[],2/T);% PSD of carriers
title('PSD estimate of carriers');
text(8,-40,'bandwidth is 2/T 18.28M');
figure(17);

% D/A simulation
L = length(carriers);
chips = [ carriers.';zeros((2*q)-1,L)];
p=1/Rs:1/Rs:T/2;
g=ones(length(p),1); %pulse shape
% figure(3);
% stem(p,g);
% title('pulse shape');
chips1=chips(:);
dummy=conv(g,chips1);%D/A using conv

% these code below is for test

% figure(12);
% ttt=1/Rs:1/Rs:1/Rs*length(dummy);
% % ttt=1:length(dummy);
% plot(ttt,abs(dummy));

u=[dummy(1:length(t))]; % (C)
u1=[(chips1(1:(length(t)-1)))',0]';
% figure(4);
% subplot(211);
% plot(t(1:400),real(u(1:400)));
% title('amp');
% subplot(212);
% plot(t(1:400),imag(u(1:400)));
% title('arg');
figure(5);
% ff=(Rs)*(1:(q*FS))/(q*FS);
%subplot(211);
%plot(ff,abs(fft(u,q*FS))/FS);
%subplot(212);
pwelch(u,[],[],[],Rs);
title('PSD estimate of carriers after D/A');
text(0.2,-40,'bandwidth is 4*q/T');
figure(18);
pwelch(u1,[],[],[],Rs);
title('PSD estimate of u1');
[b,a] = butter(13,1/20); %reconstruction filter
% [H,F] = FREQZ(b,a,FS,Rs);
%%%%Warning: Function call FREQZ invokes inexact match 
%C:\MATLAB7\toolbox\signal\signal\freqz.m.
% figure(6);
% plot(F,20*log10(abs(H)));
uoft = filter(b,a,u); %baseband signal (D)
uoft1 = filter(b,a,u1); %baseband signal (D)
figure(7);
subplot(211);
% plot(t(80:480),real(uoft(80:480)));
plot(t,real(uoft));
title('amp of baseband signal');
subplot(212);
% plot(t(80:480),imag(uoft(80:480)));
plot(t,imag(uoft));
title('arg of baseband signal');
figure(8);
pwelch(uoft,[],[],[],Rs);
title('PSD estimate of baseband signal');
text(0.2,-40,'bandwidth is 4*q/T');
figure(19);
pwelch(uoft1,[],[],[],Rs);
title('PSD estimate of uoft1');
% figure(8);
% subplot(211);
% plot(ff,abs(fft(uoft,q*FS))/FS);
% subplot(212);
% pwelch(uoft,[],[],[],Rs);

%Upconverter

s_tilde=(uoft.').*exp(1i*2*pi*fc*t);
s=real(s_tilde); %passband signal (E)
% figure(9);
% plot(t(80:480),s(80:480));
% plot(t,s);
% title('real of passband signal');
% figure(10);
% subplot(211);
% %13
% %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);
% subplot(212);
% %pwelch(((real(uoft).').*cos(2*pi*fc*t)),[],[],[],Rs);
% %pwelch(((imag(uoft).').*sin(2*pi*fc*t)),[],[],[],Rs);
figure(14);
pwelch(s_tilde,[],[],[],Rs);
title('PSD estimate of passband signal');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -