0% fanden dieses Dokument nützlich (0 Abstimmungen)
4 Ansichten7 Seiten

Code Ofdm

Das Dokument enthält Matlab-Code für die Simulation eines Unterwasser-Akustikkanals, der in einer Masterarbeit verwendet wurde. Es beschreibt die Hauptfunktionen des Programms, einschließlich Sender, Kanal und Empfänger, sowie die Berechnung der Bitfehlerquote (BER) unter verschiedenen Bedingungen. Zusätzlich werden verschiedene Diagramme zur Visualisierung der Ergebnisse erstellt, einschließlich der QPSK-Signale und der BER-Entwicklung.

Hochgeladen von

Nam Ba
Copyright
© All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als DOCX, PDF, TXT herunterladen oder online auf Scribd lesen
0% fanden dieses Dokument nützlich (0 Abstimmungen)
4 Ansichten7 Seiten

Code Ofdm

Das Dokument enthält Matlab-Code für die Simulation eines Unterwasser-Akustikkanals, der in einer Masterarbeit verwendet wurde. Es beschreibt die Hauptfunktionen des Programms, einschließlich Sender, Kanal und Empfänger, sowie die Berechnung der Bitfehlerquote (BER) unter verschiedenen Bedingungen. Zusätzlich werden verschiedene Diagramme zur Visualisierung der Ergebnisse erstellt, einschließlich der QPSK-Signale und der BER-Entwicklung.

Hochgeladen von

Nam Ba
Copyright
© All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als DOCX, PDF, TXT herunterladen oder online auf Scribd lesen

CODE GỐC

%Main.m
%
----------------------------------------------------------------
-------------------------------------
% Writen by Kalangi Pullarao Prasanth/Sept'2004
% Matlab simulation code for Master Thesis
% Topic - "Modelling and Simulation of Underwater Acoustic
channel"
% Master of Science in Communication systems engineering
% University of Applied Sciences. Bremen
%
----------------------------------------------------------------
-------------------------------------
%SUMMARY
% This is the main program for the entire simulation. In this
there are 3
% major functions deined for.
%1. Transmitter
%2. Underwater Acoustic Channel
%3. Receiver and
%4. Error counter
% User has a choice to deline 2 var. One is Amplitude/Signal
strength. A and
% the other is data rate/bandwidth (digital),data_rate
%
% NOTE - Value of A should be greater than 15 W (default is 20
W) and the
%
%---------------------------------------------------------------
--------------------------------------
% Start of the Program
close all;
clear all;
clc;
%
%---------------------------------------------------------------
--------------------------------------
% start of simulation
% timer to calculate the simulation time
tic;
%
%---------------------------------------------------------------
--------------------------------------
% Input from the user
% Flag_signal=input(Enter 1 for multipath or 0 for direct path
');
Flag_signal=1; %default
%
%---------------------------------------------------------------
--------------------------------------
% signal strength
A=8;
%
%---------------------------------------------------------------
--------------------------------------
% data rate
data = 5000;
%
%---------------------------------------------------------------
--------------------------------------
% tune is a parameter which is used to supress the multipath
propagation or
% it can be thought as a parameter that deines the SNR. here we
are
% referring DIRECT PATH as the signal and MULTIPATH as noise.
% tune should be deined as a vector to compute the BER. By
default it takes
% a value of 1.
%
tune=[1:10];
%
%---------------------------------------------------------------
--------------------------------------
% for computing BER avg_value can be deined deined. Default
value is 1
%
avg_value=[1];
%
%---------------------------------------------------------------
--------------------------------------
% loop computing BER
%
for ii=1:length(tune)
for jj=1: avg_value
%
%---------------------------------------------------------------
--------------------------------------
% function calling Transmitter

[Mod_Signal,turbo_train,turbo_data,b_data,fc,ts,Tsym,Q,b,tinh] =
transmitter(A,data);

%
%---------------------------------------------------------------
--------------------------------------
% function calling Underwater Acoustic Channel
[Channel_Signal] =
underwater_acoustic_channel(Mod_Signal,ts,fc,Flag_signal);

%
%---------------------------------------------------------------
--------------------------------------
% function calling Receiver

[dat,r_new]=receiver(Channel_Signal,turbo_train,fc,Tsym,Q,length
(turbo_data),length(b_data),tune(ii),b,tinh);
temp=dat(1:length(dat))~=b_data(1:length(b_data)-2); % do Turbo
lay 2 bit Tail
nr_errors(jj )=sum(temp);

end
bit_truyen=b_data;
bit_thu=dat;
so_bit_truyen=length(b_data);
so_bit_nhan=length(dat);
so_bit_loi=nr_errors;

BER(ii)=sum(nr_errors)./(avg_value*data);
clear nr_errors;

BER
kq(ii) = BER(ii)
end
%
%---------------------------------------------------------------
--------------------------------------
% Plots BER
%if nargout == 1
%LINEAR SCALE
figure();
subplot(2,1,1);plot(tune,BER,'b>-');
hold on
xlabel('Gia tri Eb/No');
ylabel('Ty le bit loi - BER');
if Flag_signal == 1
title('Ty le bit loi trong kenh truyen da duong voi gia tri
Eb/N0 dang tuyen tinh');
else
title('Ty le bit loi trong kenh truyen thang voi gia tri
Eb/N0 dang tuyen tinh');
end
grid on

%LOG SCALE
if Flag_signal == 1
subplot(2,1,2);semilogy(tune,BER,'r>-');
hold on
xlabel('Gia tri Eb/No');
ylabel('Ty le bit loi - BER');
if Flag_signal == 1
title('Ty le bit loi trong kenh truyen da duong voi gia tri
Eb/N0 theo logarithm')
else
title('Ty le bit loi trong kenh truyen thang voi gia tri
Eb/N0 theo logarithm')
end
grid on
end
%
%---------------------------------------------------------------
--------------------------------------
% Plots the received QPSK states
%
% constellation_plot=input('Enter 1 for seeing the constellation
diagram or 0 if not');
constellation_plot=0; % Default
if constellation_plot ==0
figure;
plot(real(r_new),imag(r_new),'o');
hold on;
plot([-(round(max(abs(real(r_new))))+5)
(round(max(abs(real(r_new))))+5)],[0 0]);
plot([0 0],[-(round(max(abs(real(r_new))))+5)
(round(max(abs(real(r_new))))+5)]);
hold off;
xlabel('Phan thuc');
ylabel('Phan ao');
if Flag_signal == 1
title('Tin hieu QPSK thu duoc cho kenh truyen da duong');
else
title('Tin hieu QPSK thu duoc cho kenh truyen thang');
end
grid;
end

% End of simulation
Compuatational_time_in_seconds=toc

CODE THẲNG
close all;
clear all;
clc;

%% ================= BAT DAU MO PHONG =================


tic;
%% ================= CAU HINH KENH ====================
Flag_signal = 0; % 0 = kenh truyen thang

%% ================= THAM SO ==========================


A = 16; % SIGNAL STRENGTH
data = 5000; % so bit
tune = 1:10; % Eb/No
avg_value = 1;

%% ================= TINH BER =========================


for ii = 1:length(tune)
for jj = 1:avg_value

% ----- Transmitter ------------------------------------

[Mod_Signal,turbo_train,turbo_data,b_data,fc,ts,Tsym,Q,b,tinh] =
transmitter(A,data);

% ----- Channel ---------------------------------------


Channel_Signal =
underwater_acoustic_channel(Mod_Signal,ts,fc,Flag_signal);

% ----- Receiver --------------------------------------


[dat,r_new] =
receiver(Channel_Signal,turbo_train,fc,Tsym,Q,...

length(turbo_data),length(b_data),tune(ii),b,tinh);

% ----- Dem loi ---------------------------------------


temp = dat(1:length(dat)) ~= b_data(1:length(b_data)-2);
% Turbo co tail bits
nr_errors(jj) = sum(temp);

end

BER(ii) = sum(nr_errors)/(avg_value*data);
clear nr_errors;
end

%% ================= VE BER =========


figure;

plot(tune, BER, 'b>-','LineWidth',1.5);


grid on;
xlabel('Gia tri Eb/No');
ylabel('Ty le bit loi - BER');

title('Ty le bit loi trong kenh truyen thang voi gia tri Eb/No
dang tuyen tinh');
%% ================= KET THUC ==========================
Computational_time_in_seconds = toc;

CODE MỘT SỐ HÌNH


clc;
clear;
close all;

%% =====================================================
% THAM SO CHUNG
%% =====================================================
Fs = 50e3; % Tan so lay mau
fc = 5e3; % Song mang
Nsym = 200; % So ky hieu QPSK
SNR = 18; % Nhieu (dB)

%% =====================================================
% HINH 1: SO DO TAN XA QPSK (HINH CHU X)
%% =====================================================
bits = randi([0 1],1,2*Nsym);

I = 2*bits(1:2:end)-1;
Q = 2*bits(2:2:end)-1;
s = (I + 1j*Q)/sqrt(2);

% Tao ISI de ra hinh chu X


L = 15;
s_isi = interp1(1:Nsym,s,linspace(1,Nsym,L*Nsym),'linear');
r_qpsk = awgn(s_isi,SNR,'measured');

figure;
plot(real(r_qpsk),imag(r_qpsk),'b','LineWidth',0.8);
grid on; axis equal;
xlabel('Phan thuc');
ylabel('Phan ao');
title('So do tan xa cua tin hieu QPSK');

%% =====================================================
% HINH 2: SO DO TAN XA OFDM
%% =====================================================
Nfft = 64;
Nofdm = 200;
bits_ofdm = randi([0 1],1,2*Nfft*Nofdm);
I = 2*bits_ofdm(1:2:end)-1;
Q = 2*bits_ofdm(2:2:end)-1;
sym = (I + 1j*Q)/sqrt(2);

sym_mat = reshape(sym,Nfft,Nofdm);
ofdm_time = ifft(sym_mat,Nfft);

% Kenh nhieu
r_ofdm = awgn(ofdm_time,SNR,'measured');

figure;
plot(real(r_ofdm(:)),imag(r_ofdm(:)),'b','LineWidth',0.5);
grid on; axis equal;
xlabel('Phan thuc');
ylabel('Phan ao');
title('So do tan xa cua tin hieu OFDM');

%% =====================================================
% HINH 3: DANG SONG OFDM THEO THOI GIAN
%% =====================================================
ofdm_serial = real(ofdm_time(:));
t = (0:length(ofdm_serial)-1)/Fs;

figure;
plot(t,ofdm_serial,'b');
grid on;
xlabel('Thoi gian (s)');
ylabel('Bien do');
title('Tin hieu dieu che OFDM duoc phat trong kenh truyen');

Das könnte Ihnen auch gefallen