没有合适的资源?快使用搜索试试~ 我知道了~
首页MATLAB OFDM
资源详情
资源评论
资源推荐
%a_run_design.m 文件
setup %系统设置
QAM %QAM 调制方式
OFDM %OFDM 调制方式
Analysis %QAM 和 OFDM 两种方式对比
1setup %初始化部分
% setup
disp(' '), disp('------------------------------------------------------------')
disp('Simulation Setup')
% OFDM Setup -----------------------------------------------------------
fft_size = 128 % should be a power of 2 for fast computation
% more points = more time domain samples (smoother & more cycles)
num_carriers = 32 % should be <= fft_size/4
% number of carriers used for each data chunk
% new var - denotes even spacing or variations of carriers among fft points
input_type = 2;
% 1 = test input
test_input_type = 1;
% 1 = bit specified (binary)
binary_data = [0 1 0 1 0 1 0 1];
% 2 = random data stream (samples in the range of 0-255)
num_symbols = 9;
% 3 = sinusoidal
frequency = 2;
num_samples = 50;
% 2 = external file input
file_name = 'shortest.wav'; % Name of input file
file_input_type = 3;
% 1 = binary (not implemented)
% 2 = text % Demo file: 'text.txt'
% 3 = sound % Demo files: 'shortest.wav' & 'shorter.wav'
% 4 = image (not implemented)
% QAM Setup ------------------------------------------------------------
do_QAM = 1; % (1=on, 0=off)
QAM_periods = 10; % defines the number of periods per QAM Symbos (1=2*pi)
% Channel Simulation Parameters --------------------------------------------
channel_on = 1; % 1=on, 0=off
clip_level = 1.0; % 0.0 - 1.0 (0-100%)
% Max magnitude of the signal is 'clip_level' times the full magnitude of the signal
noise_level = 0.0; % 0.0 - 1.0 (0-100%)
1
% Magnitude of noise is 'noise_level' times the magnitude of the signal
% Multipath Channel Simulation
% Good defaults when fft_size = 128 and num_carriers = 32:
% d1=6; a1=0.30; d2=10; a2=0.25
d1 = 6; % delay in units
a1 = 0.30; % attenuation factor - multipath signal is x% of size or original signal
d2 = 10; % delay for second multipath signal
a2 = 0.25; % attenuation factor for second multipath signal
% ****************** TEST INPUT SETUP - DO NOT MODIFY **************************
if input_type == 1
if test_input_type == 1
%specify BINARY input bit-by-bit
data_in = binary_data;
end
if test_input_type == 2
%random input defined by parameters
num_levels = 255; %number of possible levels of a symbol
%must be integer between 1-255
data_samples = round(rand(1,num_symbols)*(num_levels-1));
data_in = zeros(1,8*length(data_samples));
for i = 1:length(data_samples)
data_in(1 + (i-1)*8:(i-1)*8 + 8) = eight2bin(data_samples(i));
end
end
if test_input_type == 3
%data stream represents sine wave samples
t = linspace(0,1,num_symbols); %evenly space number of samples
%take 8-bit samples of sine wave
data_samples = round(127.5*sin(frequency*2*pi*t) +127.5);
data_in = zeros(1,8*length(data_samples));
for i = 1:length(data_samples)
data_in(1 + (i-1)*8:(i-1)*8 + 8) = eight2bin(data_samples(i));
end
end
end
already_made_noise = 0; % initialization (don't change)
2、QAM.m
% QAM.m compares OFDM (multicarrier) to multi-level QAM (single carrier)
% when they transmit the same # of bits in a given time period
read % read data for QAM - does not affect OFDM
2
data_in_pol = bin2pol(data_in); % Converts binary data to polar data
% check to see if num_carriers is a power of 2
is_pow_2 = num_carriers;
temp_do_QAM = 0;
if is_pow_2 ~= 2
while temp_do_QAM == 0
temp_do_QAM = rem(is_pow_2,2);
is_pow_2 = is_pow_2/2;
if is_pow_2 == 2
temp_do_QAM = -99; % it is a power of 2 -> can do QAM
end
end
else
temp_do_QAM = -99; % 2 is a power of 2
end
if temp_do_QAM ~= -99
do_QAM = 0; % don't do it if it's not possible
disp(' '),disp('ERROR: Cannot run QAM because num_carriers is not valid.')
disp(' Please see "setup.m" for details.')
end
if do_QAM == 1
tic % Start stopwatch to calculate how long QAM simulation takes
disp(' '), disp('------------------------------------------------------------')
disp('QAM simulation'), disp('Transmitting')
% Pad with zeros so data can be divided evenly
data_length = length(data_in_pol);
r = rem(data_length,num_carriers);
if r ~= 0
for i = 1:num_carriers-r
data_in_pol(data_length+i) = 0; %pad input with zeros to complete last data set
end %speed improve possible
end
data_length = length(data_in_pol); %update after padding
num_OFDM_symbols = ceil(data_length / (2*num_carriers));
% num QAM symbols that represent equal amount of data to one OFDM symbol
num_QAM_symbols = num_carriers / 2;
% num samples per QAM symbol
num_symbol_samples = fft_size / num_QAM_symbols;
% convert polar data [-1, 1] to 4 level data [-3, -1, 1, 3]
3
data_in_4 = zeros(1,data_length/2);
for i = 1:2:data_length
data_in_4(i - (i-1)/2) = data_in_pol(i)*2 + data_in_pol(i+1);
end
% define sample points between 0 and 2*pi
ts = linspace(0, 2*pi*QAM_periods, num_symbol_samples+1);
% Generate 16-QAM data
% total length of 16-QAM transmission
tx_length = num_OFDM_symbols * num_QAM_symbols * num_symbol_samples;
QAM_tx_data = zeros(1,tx_length);
for i = 1:2:data_length/2
for k = 1:num_symbol_samples
QAM_tx_data(k+((i-1)/2)*num_symbol_samples) = data_in_4(i)*cos(ts(k)) +
data_in_4(i+1)*sin(ts(k));
end
end
% Do channel simulation on QAM data
xmit = QAM_tx_data; % ch uses 'xmit' data and returns 'recv'
ch
QAM_rx_data = recv; % save QAM data after channel
clear recv % remove 'recv' so it won't interfere with OFDM
clear xmit % remove 'xmit' so it won't interfere with OFDM
disp('Receiving') % Recover Binary data (Decode QAM)
cos_temp = zeros(1,num_symbol_samples); %
sin_temp = cos_temp; %
xxx = zeros(1,data_length/4); % Initialize to zeros for speed
yyy = xxx; %
QAM_data_out_4 = zeros(1,data_length/2); %
for i = 1:2:data_length/2 % "cheating"
for k = 1:num_symbol_samples
% multiply by carriers to produce high frequency term and original data
cos_temp(k) = QAM_rx_data(k+((i-1)/2)*num_symbol_samples) * cos(ts(k));
sin_temp(k) = QAM_rx_data(k+((i-1)/2)*num_symbol_samples) * sin(ts(k));
end
% LPF and decide - we will do very simple LPF by averaging
xxx(1+(i-1)/2) = mean(cos_temp);
yyy(1+(i-1)/2) = mean(sin_temp);
% Reconstruct data in serial form
QAM_data_out_4(i) = xxx(1+(i-1)/2);
QAM_data_out_4(i+1) = yyy(1+(i-1)/2);
end
4
剩余15页未读,继续阅读
weixin_39943290
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
- MW全能培训汽轮机调节保安系统PPT教学课件.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0