📄 64qam.m
字号:
clear all;
close all;
%% set parameters
fft_size = 256;
Ng = fft_size/4; % guard_interval length
nOFDM_symbol = fft_size+Ng; % number of points in an ofdm symbol
bit_number = 6; % using 64-QAM
used_subcarrier_number = 200;
transmit_symbol_number = 10; % 10 OFDM symbol
total_bits_number = bit_number*used_subcarrier_number*transmit_symbol_number; % total transmit bits
%% generate input serial(for 10 OFDM symbol using 64-QAM)
x = ceil(2.*rand(1,total_bits_number));
x = x-1;
%% mapper
s(1,:) = mapper(x,total_bits_number,bit_number);
%% subcarrier allocation & transformed to time-domain by IFFT
guard_band1 = zeros(1,28);
guard_band2 = zeros(1,27);
freq_domain_series = zeros(1,fft_size);
time_domain_serise = zeros(10,fft_size);
for m = 1:10
freq_domain_series(m,1:fft_size) =[guard_band1 s(((m-1)*used_subcarrier_number+1)...
:((m-1)*used_subcarrier_number+100)) 0 s(((m-1)*used_subcarrier_number+101)...
:((m-1)*used_subcarrier_number+used_subcarrier_number)) guard_band2];
end
freq_domain_series = ifftshift(freq_domain_series);
for m = 1:10
time_domain_serise(m,:) = ifft(freq_domain_series(m,:));
end
%% guard interval insertion (guard interval ratio 1/4)
time_domain_serise = [time_domain_serise(:,193:fft_size) time_domain_serise];
%% windowing
%===========================================================
% window function
for k = 0:7
w1(k+1) = 0.5 + 0.5*cos(pi+pi*k/8);
end
for h = 0:7
w2(h+1) = 0.5 + 0.5*cos(k*pi/8);
end
w = [w1 ones(1,312) w2];
%=============================================================
%% implement windowing
temp1 = zeros(10,8); % put the next symbol's head
temp1(1:9,:) = [time_domain_serise(2:10,1:8) ]; % to the previous symbol's tail
temp = [time_domain_serise temp1]; %
ofdm_symbol = zeros(10,320);
temp2 = zeros(1,320);
for p = 1:10 % implement windowing
a(p,1:328) =w.*temp(p,:);
if p ==1
ofdm_symbol = a(1:320);
else
temp2(1:8) = a((p-1),321:328);
ofdm_symbol(p,:) = temp2+a(p,1:320);
end
end %
%% plot time-domain waveform
ofdm_symbol = ofdm_symbol';
ofdm_symbol_temp = ofdm_symbol(1:end);
ofdm_symbol_real = real(ofdm_symbol_temp);
ofdm_symbol_imag = imag(ofdm_symbol_temp);
t = 0:1/32/(10^6):10^(-4)-1/32/(10^6);
subplot(2,1,1);
plot(t,ofdm_symbol_real);
xlabel('time, second');
ylabel('Amplitude ');
title('Real part output time-domain waveforms using 64-QAM ');
grid on;
subplot(2,1,2);
plot(t,ofdm_symbol_imag);
xlabel('time, second');
ylabel('Amplitude ');
title('Imaginary part output time-domain waveforms using 64-QAM ');
grid on;
%% plot power spectral density
fsMHz = 32;
[Pxx,W] = pwelch(ofdm_symbol_temp,[],[],fft_size,32);
Pxx = fftshift(Pxx);
figure
plot([-128:127]*fsMHz/fft_size,10*log10(Pxx));
xlabel('frequency, MHz')
ylabel('Power spectrum. dB')
title('Power spectrum using 64-QAM ');
grid on;
%% calculate PAPR
peak_power = max(abs(ofdm_symbol_temp))^2;
average_power = sum(abs(ofdm_symbol_temp).^2)/(nOFDM_symbol*transmit_symbol_number);
papr = 10*log10(peak_power/average_power);
%% quantization
quant_bit = 6;
input_range_real = max(ofdm_symbol_real)-min(ofdm_symbol_real);
input_range_imag = max(ofdm_symbol_imag)-min(ofdm_symbol_imag);
for ii = 1:10
quant_ofdm_symbol_real(ii,1:320) = quantize( ofdm_symbol_real((1+(ii-1)*nOFDM_symbol):...
(320+(ii-1)*nOFDM_symbol)) ,input_range_real, quant_bit,nOFDM_symbol,min(ofdm_symbol_real) );
quant_ofdm_symbol_imag(ii,1:320) = quantize( ofdm_symbol_imag((1+(ii-1)*nOFDM_symbol):...
(320+(ii-1)*nOFDM_symbol)) ,input_range_imag, quant_bit,nOFDM_symbol,min(ofdm_symbol_imag) );
end
quant_ofdm_symbol_real = quant_ofdm_symbol_real';
quant_ofdm_symbol_real = quant_ofdm_symbol_real(1:end);
quant_ofdm_symbol_imag = quant_ofdm_symbol_imag';
quant_ofdm_symbol_imag = quant_ofdm_symbol_imag(1:end);
quant_ofdm_symbol = quant_ofdm_symbol_real + j*quant_ofdm_symbol_imag;
% calculate quantization error
quant_error_real = abs(quant_ofdm_symbol_real-ofdm_symbol_real);
quant_error_imag = abs(quant_ofdm_symbol_imag-ofdm_symbol_imag);
%% remove guard-interval
quant_ofdm_symbol = reshape(quant_ofdm_symbol,320,10);
quant_ofdm_symbol = quant_ofdm_symbol';
quant_ofdm_symbol = quant_ofdm_symbol(:,65:end);
%% do fft to the quantized signals
for iii = 1:10
quantized_freq_domain_waveform(iii,1:fft_size) = fft(quant_ofdm_symbol(iii,1:fft_size));
end
quantized_freq_domain_waveform = fftshift(quantized_freq_domain_waveform);
%% plot I/Q plane (without quantization)
freq_domain_series = freq_domain_series';
freq_domain_series = freq_domain_series(1:end);
figure
plot(imag(freq_domain_series),real(freq_domain_series),'*')
xlabel('Im')
ylabel('Re ')
title('I/Q plane using 64-QAM without quantization ');
grid on;
qqq = quantized_freq_domain_waveform';
qqq = qqq(1:end);
figure
plot(imag(qqq ),real(qqq),'*');
xlabel('Im')
ylabel('Re ')
title('I/Q plane using 64-QAM ');
grid on;
%% remove guard-band and DC component
without_guardband_freq_domain_waveform = [quantized_freq_domain_waveform(:,29:128) quantized_freq_domain_waveform(:,130:229)];
without_guardband_freq_domain_waveform = without_guardband_freq_domain_waveform';
without_guardband_freq_domain_waveform = without_guardband_freq_domain_waveform(1:end);
%% plot I/Q plane
figure
plot(imag(s),real(s),'*')
xlabel('Im')
ylabel('Re ')
title('I/Q plane using 64-QAM (removing guard-band and DC component,without quantization)');
grid on;
figure
plot(imag(without_guardband_freq_domain_waveform ),real(without_guardband_freq_domain_waveform),'*');
xlabel('Im')
ylabel('Re ')
title('I/Q plane using 64-QAM (removing guard-band and DC component)');
grid on;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -