How can I modify this to receive the same data after demodulation?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
clc;
clear all;
close all;
no_of_data_bits = 64%Number of bits per channel
M =4 %Number of carriers
n=256;%Total number of bits 64*4
block_size = 16; %Size of each OFDM block to add cyclic prefix
cp_len = floor(0.1 * block_size); %Length of the cyclic prefix
%Transmitter
data = randsrc(1, no_of_data_bits, 0:M-1);
figure(1),stem(data); grid on; xlabel('Data Points'); ylabel('Amplitude')
title('Randomly Generated Original Data ')
% Perform QPSK modulation on the input source data
qpsk_modulated_data = pskmod(data, M);
figure(2),stem(qpsk_modulated_data);title('QPSK Modulation ')
% Converting the series data stream into four parallel data stream to form
% four sub carriers
S2P = reshape(qpsk_modulated_data, no_of_data_bits/M,M)
Sub_carrier1 = S2P(:,1)
Sub_carrier2 = S2P(:,2)
Sub_carrier3 = S2P(:,3)
Sub_carrier4 = S2P(:,4)
figure(3), subplot(4,1,1),stem(Sub_carrier1),title('Subcarrier1'),grid on;%plots bits 1-16
subplot(4,1,2),stem(Sub_carrier2),title('Subcarrier2'),grid on;%plots bits 17-32
subplot(4,1,3),stem(Sub_carrier3),title('Subcarrier3'),grid on;%plots bits 33-48
subplot(4,1,4),stem(Sub_carrier4),title('Subcarrier4'),grid on;%plots bits 49-64
% Inverse Fourier Transofrm for each subcarrier
number_of_subcarriers=4;
cp_start=block_size-cp_len;
ifft_Subcarrier1 = ifft(Sub_carrier1)
ifft_Subcarrier2 = ifft(Sub_carrier2)
ifft_Subcarrier3 = ifft(Sub_carrier3)
ifft_Subcarrier4 = ifft(Sub_carrier4)
figure(4), subplot(4,1,1),plot(real(ifft_Subcarrier1),'r'),
title('Inverse Fourier Transform on all the sub-carriers')
subplot(4,1,2),plot(real(ifft_Subcarrier2),'y')
subplot(4,1,3),plot(real(ifft_Subcarrier3),'g')
subplot(4,1,4),plot(real(ifft_Subcarrier4),'b')
%Add Cyclic Prefix
%A cyclic prefix is created to prevent intersymbol interference (ISI)
%when an OFDM signal is transmitted in a dispersive channel.
%The cyclic prefix (CP) is essentially an identical copy of the last
%portion of the OFDM symbol appended before the OFDM symbol.
%This CP preserves the orthogonality of the subcarriers and prevents
%ISI between successive OFDM symbols.
for i=1:number_of_subcarriers,
ifft_Subcarrier(:,i) = ifft((S2P(:,i)),16)% 16 is the ifft point
for j=1:cp_len,
cyclic_prefix(j,i) = ifft_Subcarrier(j+cp_start,i)
end
Append_prefix(:,i) = vertcat( cyclic_prefix(:,i), ifft_Subcarrier(:,i))
% Appends prefix to each subcarriers
end
App1=Append_prefix(:,1);
App2=Append_prefix(:,2);
App3=Append_prefix(:,3);
App4=Append_prefix(:,4);
figure(5), subplot(4,1,1),plot(real(App1),'r'),title('Cyclic prefix added to all the sub-carriers')
subplot(4,1,2),plot(real(App2),'y')
subplot(4,1,3),plot(real(App3),'g')
subplot(4,1,4),plot(real(App4),'b')
figure(6),plot((real(App1)),'r'),title('Orthogonality'),hold on ,plot((real(App2)),'y'),hold on ,
plot((real(App3)),'g'),hold on ,plot((real(App4)),'b'),hold on ,grid on
%Convert to serial from parallel
[rows_Append_prefix cols_Append_prefix]=size(Append_prefix)
len_ofdm_data = rows_Append_prefix*cols_Append_prefix
% OFDM signal to be transmitted
ofdm_signal = reshape(Append_prefix, 1, len_ofdm_data);
figure(7),plot(real(ofdm_signal)); xlabel('Time'); ylabel('Amplitude');
title('OFDM Signal');grid on;
%Serial stream passing through the channel
channel = randn(1,2) + sqrt(-1)*randn(1,2);
after_channel = filter(channel, 1, ofdm_signal);
awgn_noise = awgn(zeros(1,length(after_channel)),0);
recvd_signal = awgn_noise+after_channel; % With AWGN noise
%Converts from serial back to parallel
figure(8),plot(real(recvd_signal)),xlabel('Time'); ylabel('Amplitude');
title('OFDM Signal after passing through channel');grid on;
recvd_signal_paralleled = reshape(recvd_signal,rows_Append_prefix, cols_Append_prefix);
%now that the signal has passed through the channel we begin to work
%backawards, but we are first going to remove the CP
% Remove cyclic Prefix
%Now that the signal has already passed through the channel, we can get rid
%of the CP
recvd_signal_paralleled(1:cp_len,:)=[];
R1=recvd_signal_paralleled(:,1);
R2=recvd_signal_paralleled(:,2);
R3=recvd_signal_paralleled(:,3);
R4=recvd_signal_paralleled(:,4);
figure(9),plot((imag(R1)),'r'),subplot(4,1,1),plot(real(R1),'r'),
title('Cyclic prefix removed from the four sub-carriers')
subplot(4,1,2),plot(real(R2),'y')
subplot(4,1,3),plot(real(R3),'g')
subplot(4,1,4),plot(real(R4),'b')
% Fourier Transofrm of the recievied signal
%Similarly to how we took the IFFT of the original signal, as we are back
%tracking we are now taking the FFT
for i=1:number_of_subcarriers,
fft_data(:,i) = fft(recvd_signal_paralleled(:,i),16);
end
F1=fft_data(:,1);
F2=fft_data(:,2);
F3=fft_data(:,3);
F4=fft_data(:,4);
figure(10), subplot(4,1,1),plot(real(F1),'r'),title('Fourier Transform of all the four sub-carriers')
subplot(4,1,2),plot(real(F2),'y')
subplot(4,1,3),plot(real(F3),'g')
subplot(4,1,4),plot(real(F4),'b')
% Conversion to serial and demodulation
%The orignal data was in series, so we are taking the demodulated data
%which is still in parallel form and we are converting back into series to
%hopefully show the same data
recvd_serial_data = reshape(fft_data, 1,(16*4));
qpsk_demodulated_data = pskdemod(recvd_serial_data,4);
figure(11), subplot(2,1,1), stem(data)
grid on;xlabel('Data Points');ylabel('Amplitude');
title('Original Data')
subplot (2,1,2), stem(qpsk_demodulated_data,'bo');
grid on;xlabel('Data Points');ylabel('Amplitude');
title('Recieved Data')
0 Kommentare
Antworten (1)
Kaashyap Pappu
am 28 Nov. 2019
You could look into this example to carry out the same operation. Just modify the channel coefficient values to (1,1) and should work similarly.
Hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Propagation and Channel Models finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!