📄 qpsk.m
字号:
clear all;
close all;
%% set parameters
N = 256; % fft size
Ng = 64; % guard_interval length
bit_number = 2;
used_subcarrier_number = 200;
transmit_symbol_number = 10;
total_bits_number = bit_number*used_subcarrier_number*transmit_symbol_number; % total transmit bits
%% generate input serial(for 10 OFDM symbol using QPSK)
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,256);
time_domain_serise = zeros(10,256);
for m = 1:10
freq_domain_series(m,1:256) =[guard_band1 s(((m-1)*200+1):((m-1)*200+100)) 0 s(((m-1)*200+101):((m-1)*200+200)) guard_band2];
freq_domain_series(m,1:256) = ifftshift(freq_domain_series(m,1:256));
time_domain_serise(m,1:256) = ifft(freq_domain_series(m,1:256));
end
% guard interval insertion (guard interval ratio 1/4)
time_domain_serise = [time_domain_serise(:,193:256) 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 to the previous symbol's tail
temp1(1:9,:) = [time_domain_serise(2:10,1:8) ]; %
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 out 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 QPSK ');
grid on;
subplot(2,1,2);
plot(t,ofdm_symbol_imag);
xlabel('time, second')
ylabel('Amplitude ')
title('Imaginary part output time-domain waveforms using QPSK ');
grid on;
% plot power spectral density
fsMHz = 32;
[Pxx,W] = pwelch(ofdm_symbol_temp,[],[],256,32);
Pxx = fftshift(Pxx);
figure(3)
plot([-128:127]*fsMHz/256,10*log10(Pxx));
xlabel('frequency, MHz')
ylabel('Power spectrum. dB')
title('Power spectrum using QPSK ');
grid on;
% calculate PAPR
nOFDM_symbol = 320;
peak_power = max(abs(ofdm_symbol_temp).^2);
average_power = sum(abs(ofdm_symbol_temp).^2)/(nOFDM_symbol*10);
papr = 10*log10(peak_power/average_power);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -