Adding AWGN to the OFDM PLC generator
6 views (last 30 days)
Show older comments
Hi,
My code below is about OFDM PLC generator using bpsk. I am stuck with adding the AWGN to the OFDM PLC code below, I appreciate any help regarding the code (where can I exactly add the code and what is the code that can be added to generate the AWGN and turbo codes). Appreciate your kind help on this regard.
%generation of data
l = 16384*32; % 1Mbps this is 1 mega bit of data from here we determine the bit rate of the system
lpf = l/32; % here we give the no. of user and data length of each user ..... u can use 64 as well as 128 that means 2 ki power(no. of user)
data = randint(l,1,2); % it generate randint(no. of row, no. of column, (0 and 1)) this is for bpsk if u want for QAM -16 then write 16
% data get generated
% serial to parallel
p_data = reshape(data,32,[]); %here reshape(matrix, no. of row, no. of column)
% serial to parallel ends
%modulation scheme
%here i use bpsk u can use qam as qammod(matrix, no. of level same as that in line no. 9 )
m_data = pskmod(p_data,2,pi); % binary phase shift key it best and mostly use that why i have used which give 0 as -1 and 1 as +1
% modulation ends
%now ifft
x_ifft = ifft(m_data);
%ifft ends
%cyclic prefix
p_cyc = [x_ifft(end-4:end,:) ; x_ifft]; % here i concatenate the last L-1 bit with whole matrix so that it act as a cyclic prefix
%its use is just to avoid inter symbol interfernce
%her L is 6 (that is length of channel delay(6) if it is more u use just L-1 bit of cyclic prefix)
%ends of cyclic prefix
%now again parallel to serial bcoz we have to transmit and we cant transmit
%serially
s_cyc = reshape(p_cyc,1,[]); % serially data
%end parallel to serial
%now every thing gets over now our aim is to transmit their now we design
%the channel which include multi path gain and channel noise and to
%transmit we have to do the linear convolution
%lets take channel to be random path gain
channel = randn(6,1);
hf = fft(channel,32); % just to get the impulse response of gain coefficent for each user if user is 32 then length is 32 if 64 thn use 64 length
%channel coefficent ends
%linear convolution
chnout = filter(channel,1,s_cyc);
%linear convolution ends
%generation of noise as here we are using asynchronous impulse noise for
%the case of power line communication
noiseq = randn(length(chnout),1);
tin = 1;
IAT = 10276;
tnoise = 34;
for ik = 1:51,
for ii = tin:tin+IAT-1,
impulse(ii) = imp((ii-tin)/tnoise);
impamp(ii) = impulse(ii)*noiseq(ii)*10;
end
tin = tin+IAT;
end
clear noiseq
leng =length(impamp);
noiseq = [impamp zeros(1,length(chnout)-leng)].';
%noise generation
%In the case for the wireless channel
AWGN;
%noise generation ends
%receiver along with noise addition in channel as the stength of noise
%depend on the signal to noise ratio that we are going to take
sereq = [];
power = mean(mean(abs(p_cyc).^2));
for il = 1:30 , % signal to noise ratio ranges from 1 to 30
eb2n(il) = il;
eb2n_num(il) = 10^(eb2n(il)/10);
var(il) = power/(2*eb2n_num(il)); %variance of the noise
signois(il) = sqrt(var(il)); % strength of noise
impnois = signois(il).*noiseq;
yout = chnout+impnois.'; % addition of noise in transmited signal
%serial to parallel conversion%
pout = reshape(yout,37,[]);
%serial to parallel over%
%removal of cyclic prefix
pncyc = pout(6:end,:);
%removal of cyclic prefix ends
%fft%
x_fft = fft(pncyc);
%fft over%
%just to remove the effect of channel coefficent
z_data = inv(diag(hf))*x_fft;
%ends
%decision making%
%parallel to serial%
h_data = reshape(z_data,1,[]).';
%serial to parallel ends
%demodulation
dec = pskdemod(h_data,2,pi);
%demodulation ends
%comparison nd to determine no. of bit in error
sereq = [sereq sum(dec~=data)/lpf];
%ends
end
%plot of bit error rate as compare with signal
semilogy(eb2n,sereq,'k-*'); %semilogy function is used as semilogy(xaxis , yaxis,'colour and shape of graph') and semilogy will make yaxis as logarithmic
%ends
0 Comments
Answers (1)
Ayaz Hussain
on 28 Feb 2017
impulse(ii) = imp((ii-tin)/tnoise); instead of impulse(ii) = double((ii-tin)/tnoise);
0 Comments
See Also
Categories
Find more on AI for Wireless in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!