How to get ber vs snr graph of received signal?
11 ビュー (過去 30 日間)
古いコメントを表示
clc;
M =8; %here we initialize the number of constellation point of qam
no_of_data_bits=1024;
Fm=10^6;%Max freq
block_size = 16; %Size of each OFDM block to add cyclic prefix
cp_len = floor(0.1 * block_size); %Length of the cyclic prefix
data_source= abs(round(randn(1,no_of_data_bits)));%here we take random normal function
figure(1);
x=1:no_of_data_bits;
stem (x*(1/Fm),data_source);
grid minor;
xlabel('time(Microsecond)','Fontsize',16);
ylabel('amplitude','Fontsize',16);
title('Transmitted Data','Fontsize',16);%here we plot that transmitted data
qam_modulated_data = qammod(data_source, M);%here we perform 8bit qam on the random normal function
nqdata = length(qam_modulated_data);
data = 0:M-1;
scatterplot(qam_modulated_data,1,0,'r*');
[udata, uidx] = unique(qam_modulated_data);
nudata = length(udata);
grid minor
for k=1:nudata
text(real(udata(k))-0.4,imag(udata(k))+0.4,num2str(data_source(uidx(k))));
end
axis([-4 4 -2 2])
qm = abs(qam_modulated_data);
figure(3);
stem(qm)
title('MODULATED TRANSMITTED DATA','Fontsize',16);%here we plot those constellation point
y=ifft(qam_modulated_data);
figure(4);
x=1:nqdata;
stem(x(2:end)*Fm,abs(y(2:end)));
grid minor;
xlabel('freq(Mhz)','Fontsize',16);
ylabel('amplitude of ifft','Fontsize',16);
title('without hermitian ifft','Fontsize',16);
udata1(1:(M/2))=qam_modulated_data(1:(M/2)); %here we introduce another array named qam_modulated_data1 where first four element is first four constellation point
udata1(((M/2)+1):M)=qam_modulated_data(1:(M/2));% in my qam_modulated_data1 array last four point is Hermitian of first four point
figure(5);
x=1:M;
stem (x*Fm,abs(udata1));
grid minor;
xlabel('frequency(MHZ)','Fontsize',16);
ylabel('amplitude','Fontsize',16);
title('Hermitian symmetry','Fontsize',16);
y1=ifft(udata1); %here we apply fast Fourier transform on the data of udata1
figure(6);
x=1:M;
stem(x*Fm,abs(y1)); %here we plot that fft result
grid minor;
xlabel('Freq(Mhz)','Fontsize',16);
ylabel('amplitude','Fontsize',16);
title('even frequency suppressed output','Fontsize',16);
y1c=conj(y1);
real_y1=y1.*y1c ;
figure(7);
x=1:M;
stem(x*Fm,real_y1);
grid on;
xlabel('Freq(Mhz)','Fontsize',16);
ylabel('amplitude of real values of ifft','Fontsize',16);
title('real value of ifft','Fontsize',16);
number_of_subcarriers=M;
assert(number_of_subcarriers <= M);
cp_start=block_size-cp_len;
ifft_Subcarrier = zeros(16, number_of_subcarriers);
cyclic_prefix = zeros(cp_len, number_of_subcarriers);
Append_prefix = zeros(16+cp_len, number_of_subcarriers);
for i=1:number_of_subcarriers
S2P = reshape(qam_modulated_data, no_of_data_bits/M,M);
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
A1=Append_prefix(:,1);
A2=Append_prefix(:,2);
A3=Append_prefix(:,3);
A4=Append_prefix(:,4);
A5=Append_prefix(:,5);
A6=Append_prefix(:,6);
A7=Append_prefix(:,7);
A8=Append_prefix(:,8);
figure(12), subplot(8,1,1),plot(real(A1),'r'),title('Cyclic prefix added to all the odd sub-carriers','Fontsize',16)
subplot(8,1,2),plot(real(A2),'y')
subplot(8,1,3),plot(real(A3),'b')
subplot(8,1,4),plot(real(A4),'g')
subplot(8,1,5),plot(real(A5),'m')
subplot(8,1,6),plot(real(A6),'k')
subplot(8,1,7),plot(real(A7),'c')
subplot(8,1,8),plot(real(A8),'g')
xlabel('frequency(MHZ)','Fontsize',16);
ylabel('amplitude','Fontsize',16);
%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(13),
plot(real(ofdm_signal)); xlabel('Time','Fontsize',16); ylabel('Amplitude','Fontsize',16);
title('OFDM Signal','Fontsize',16);grid on;
% Frequency selective channel with 4 taps
Ts = 1e-3; % Sampling period of channel
Fd = 0; % Max Doppler frequency shift
tau = [0 .2e-9 .5e-9 1.6e-9 2.3e-9 5e-9]; % Path delays
pdb = [0.189 0.379 0.239 0.095 0.061 0.037]; % Avg path power gains
h = comm.RayleighChannel('SampleRate', 1/Ts, ...
'MaximumDopplerShift', Fd, ...
'PathDelays', tau, ...
'AveragePathGains', pdb, ...
'PathGainsOutputPort', false);
reset(h); %ResetBeforeFiltering equivalent
channel = step(h, ofdm_signal(:,j).'); %second output is PathGains
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(14),
plot(real(recvd_signal)),xlabel('Time','Fontsize',16); ylabel('Amplitude','Fontsize',16);
title('OFDM Signal after rayleigh fading passing through channel','Fontsize',16);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);
R5=recvd_signal_paralleled(:,5);
R6=recvd_signal_paralleled(:,6);
R7=recvd_signal_paralleled(:,7);
R8=recvd_signal_paralleled(:,8);
figure(15),plot((imag(R1)),'r'),subplot(8,1,1),plot(real(R1),'r'),
title('Cyclic prefix removed from the eight sub-carriers','Fontsize',16)
subplot(8,1,2),plot(real(R2),'y')
subplot(8,1,3),plot(real(R3),'g')
subplot(8,1,4),plot(real(R4),'b')
subplot(8,1,5),plot(real(R5),'k')
subplot(8,1,6),plot(real(R6),'c')
subplot(8,1,7),plot(real(R7),'m')
subplot(8,1,8),plot(real(R8),'b')
xlabel('frequency(MHZ)','Fontsize',16);
ylabel('amplitude','Fontsize',16);
% Fourier Transofrm of the received 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);
F5=fft_data(:,5);
F6=fft_data(:,6);
F7=fft_data(:,7);
F8=fft_data(:,8);
figure(16), subplot(8,1,1),plot(real(F1),'r'),title('Fourier Transform of all the eight sub-carriers','Fontsize',16)
subplot(8,1,2),plot(real(F2),'y')
subplot(8,1,3),plot(real(F3),'g')
subplot(8,1,4),plot(real(F4),'b')
subplot(8,1,5),plot(real(F5),'K')
subplot(8,1,6),plot(real(F6),'c')
subplot(8,1,7),plot(real(F7),'m')
subplot(8,1,8),plot(real(F8),'g')
xlabel('Time(microsec)','Fontsize',16);
ylabel('amplitude','Fontsize',16);
% 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*8));
qam_demodulated_data = qamdemod(recvd_serial_data,M);
figure(17),
subplot(2,1,1),
x=1:no_of_data_bits;
stem(x*(1/Fm),data_source);
grid on;xlabel('Data Points(time in microsec)','Fontsize',16);ylabel('Amplitude','Fontsize',16);
title('Original Data','Fontsize',16)
subplot (2,1,2),
num_sent = length(data_source);
lie_about_the_time = linspace(x(1)/Fm, x(end)/Fm, length(qam_demodulated_data));
stem(lie_about_the_time, qam_demodulated_data);
grid on;xlabel('Data Points(time in microsec)','Fontsize',16);ylabel('Amplitude','Fontsize',16);
title('Received Data','Fontsize',16);
Now I want ber vs snr graph of qam_demodulated_data,can anyone please help?
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Propagation and Channel Models についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!