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

📄 ofdm_lpf.m

📁 OFDM信道估计和均衡的仿真程序
💻 M
字号:
%+----------------------------------------------------------------+
%|                                                                |
%|  Name: ofdm_LPF.m                                                 |
%|  Author: Mathew Liu, James Shen                                |
%|  Description: Basic OFDM model used for simulation purposes.   |    
%|  Using rcosine as transmit filter. Works using LPF at the      |
%|  receiver.                                                     |
%|                                                                |
%+----------------------------------------------------------------+

% We assume that with are using 64 length FFT with 64 subcarriers 
% all carrying data. So there are no carriers specifically assigned
% to pilot.
clear all;
close all;
%=============== Some standard Hyperlan Params ====================
T = 50e-9; % System baseband sampling period.  
fs = 1/T;  % System baseband sampling freq = 20MHz .
Tcp = 16*T;% CP period.
Tu = 64*T; % Useful symbol period.
Ts = Tu+Tcp; % OFDM Symbol period 80 samples.
delta_f = 0.3125e6;        % Frequency spacing.
time_scale = T:T:Ts;       % Time samples in baseband signals.
N = length(time_scale);    % NUmber of time samples in baseband.
f1 = 1/Ts:1/Ts:N/(2*Ts);   % Freqs in the 1st half of Nyquist circle.
f2 = -N/(2*Ts):1/Ts:-1/Ts; % Freqs in the 2nd half of Nyquist circle.
freq_scale = [f1 f2];      % Baseband frequency scale.
fc = 2.4e9; % Carrier freq.
% If Rfs=2*fc then,
%       If fc=5.2, over=size(rt)/80 - 1=519;
%       If fc=2.4, over=239
% If Rfs=5*fc then,
%       If fc=5.2, over=size(rt)/80 - 1=1299;
%       If fc=2.4, over=599
Rfs = 5*fc; % Simulation frequency. 
            % Mimics real time behaviour for bandpass signal. 
            % Sampling at Nyquist rate of twice the highest freq.
RT = 1/Rfs;      % The real-time sampling period 
rt = RT:RT:Ts;   % The time samples in real-time bandpass
RN = length(rt); % Number of samples in real-time bandpass
f3 = 1/Ts:1/Ts:RN/(2*Ts);
f4 = -RN/(2*Ts):1/Ts:-1/Ts;
rf_scale = [f3 f4]; % Bandpass freq scale.
%============== Our params based on Hyperlan/2 ====================
FFTLen = 64; % Length of FFT.
CPLen = 16;  % Length of Cyclic Prefix
M = 4;       % Bits encoded in a QAM symbol.

%+----------------------------------------------------------------+
%|                    OFDM   TRANSMITTER                          |
%+----------------------------------------------------------------+
%==================== Data Generation =============================
input = rand(1,FFTLen*M) > 0.5; % transmits one symbol

%================ Serial To Block (FFTLen, M) =====================
input_para = reshape(input,FFTLen,M);

%================== Baseband Modulation ===========================
input_symbols = qammod(input_para,FFTLen, M);
figure(1);
plot(input_symbols,'ob');grid;axis square;axis equal, ...
    title('4 bit QAM constellation'), ylabel('Imaginary'), xlabel('Real');

%====================== IFFT =======================================
input_time_para = ifft(input_symbols);

%================ Parallel to Serial ===============================
input_time_serial = reshape(input_time_para,1,FFTLen); % Time domain signal

%=============  Gaurd Interval Insertion (GII) =====================
input_ext = [input_time_serial((FFTLen-CPLen+1):FFTLen),input_time_serial];
figure(2);
subplot(2,1,1);
stem(time_scale, abs(input_ext)), title('Cycl. Ext. Signal (Time)'), ...
    ylabel('Amplitude'), xlabel('Time (s)');
subplot(2,1,2);
stem(freq_scale, abs(fft(input_ext))), ...
    title('Specturm of Cycl. Ext. Signal (Freq)'), ...
    ylabel('Amplitude'), xlabel('Frequncy (Hz)');

%=================== Pulse shaping Tansmit Filter ====================
over = 599; % Oversampling factor according to Simulation frequency.
input_over = kron(input_ext, [1, zeros(1,over)]);
Nover = length(input_over);
pulse_shape = rcosine(1,(over+1),'normal',0.35); % raised-cosine pulse-shape
[trash,pos] = max(pulse_shape); % raised cosine filter delay 'pos'
input_shaped_temp = conv(pulse_shape, input_over);

input_shaped = input_shaped_temp(pos:(pos+Nover-1));% Get rid of transient

%-----------------Over sampling scales--------------------------------
overt = Ts/Nover:Ts/Nover:Ts;
f5 = 1/T:1/T:Nover/(2*T);
f6 = -Nover/(2*T):1/T:-1/T;
overf_scale = [f5 f6];
%=================== Graphing Section ================================
figure(3);
subplot(2,1,1);
stem(overt(1:5000), abs(input_over(1:5000)), 'b'), ...
    title('Signal after over sampling'), ...
    ylabel('Amplitude'), xlabel('Time (s)'); hold on;
plot(overt(1:5000), abs(input_shaped(1:5000)), 'r'), ...
    title('Signal after pulse shaping.'); hold off;
subplot(2,1,2);
plot(overf_scale, abs(fft(input_shaped))), ...
    ylabel('Amplitude'), xlabel('Frequncy (Hz)');

%================== Upconverter to Carrier Freq =======================
input_bandpass = 2*real(input_shaped.*exp(j*2*pi*fc*rt)); % Bandpass signal
figure(4);
subplot(2,1,1);
plot(rt(1:5000), input_bandpass(1:5000)), title('Bandpass signal (time)'), ...
    ylabel('Amplitude'), xlabel('Time (s)');
subplot(2,1,2);
stem(rf_scale, abs(fft(input_bandpass))), ...
    title('Spectrum of Bandpass Signal (Freq)'), ...
    ylabel('Amplitude'), xlabel('Frequncy (Hz)');

%+----------------------------------------------------------------+
%|                    CHANNEL MODEL                               |
%+----------------------------------------------------------------+
%=============== Pass Through Rayleigh Channel ====================
output_ext = filter(1, 1, input_bandpass); % Does nothing at the moment.

%+----------------------------------------------------------------+
%|                    OFDM   RECEVIER                             |
%+----------------------------------------------------------------+
%================ Downconvert ====================================

rec_over_bad = output_ext.*exp(-j*2*pi*fc*rt); % I/Q downconversion
figure(5);
subplot(2,1,1);
plot(rt(1:5000), abs(rec_over_bad(1:5000))), ...
    title('Received Baseband Signal (time)'), ...
    ylabel('Amplitude'), xlabel('Time (s)');
subplot(2,1,2);
rec_over_temp = abs(fft(rec_over_bad));
rec_over_temp = rec_over_temp./max(abs(rec_over_temp)); % Normalize spectrum for plotting.
stem(rf_scale, rec_over_temp), title('Spectrum of Baseband Signal (Freq)'), ...
     ylabel('Amplitude'), xlabel('Frequncy (Hz)'); hold on;

f = remez(50,[0 0.1 0.2 1],[1 1 0 0]); % Design of the receiver lowpass filter, order 50
LPF = freqz(f,1,-pi:2*pi/RN:pi-2*pi/RN); % Frequency response of the filter
plot([f4, f3], abs(LPF),'r'); hold off;

rec_over_temp = conv(f, rec_over_bad); % Signal is filtered
rec_over = rec_over_temp(26:(26+Nover-1)); % Discard transient (delay is here 26, linear phase FIR of order 50)

figure(6);
subplot(2,1,1);
plot(rt(1:5000), abs(rec_over(1:5000))), ...
    title('Received Baseband LPF Signal (time)'), ...
    ylabel('Amplitude'), xlabel('Time (s)');
subplot(2,1,2);
stem(rf_scale, abs(fft(rec_over))), ...
    title('Spectrum of Baseband LPF Signal (Freq)'), ...
     ylabel('Amplitude'), xlabel('Frequncy (Hz)'); hold on;

rec_baseband = rec_over(1:over+1:Nover);

output_ext = rec_baseband;

%============== Gaurd Interval Removal (GIR) =========================
output_time_serial = output_ext((CPLen+1):FFTLen+CPLen);

%======== Serial To Parallel =========================================
output_time_para = reshape(output_time_serial,FFTLen,1);

%================= FFT ===============================================
output_symbols = fft(output_time_para);

%================= Baseband Demodulation =============================
figure(7);
plot(output_symbols,'ob');grid;axis square;axis equal, ...
    title('Received Symbols'), ylabel('Imaginary'), xlabel('Real');;

output_para = qamdemod(output_symbols,FFTLen, M);

%================ Parallel to Serial =================================
output = reshape(output_para,1,FFTLen*M); % Time domain signal

%==================== BER Calculation ================================
errors = abs(input - output);
num_errors = sum(sum(errors));
BER = num_errors/(FFTLen*M)











⌨️ 快捷键说明

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