Facing problem in ploting figures

9 visualizzazioni (ultimi 30 giorni)
imran khan
imran khan il 14 Dic 2019
Risposto: 埃博拉酱 il 28 Ott 2024 alle 10:25
i want to plot last two figures in one plot can anybody help me
clc,close all,clear all
codn=100;
EbN0=20:30;
q=1.6e-19; %
% signal-to-noise ratio in dB.
Ib=202e-6; % Background Noise Current+interfernce
N0=2*q*Ib; % Noise Spectral Density, 2*q*Ib
fs=360;
bode=10;
code=round(rand(1,codn))
code_len=round(1/bode/(1/fs)) % no of samples/symbol
SNR=10.^(EbN0./code_len);
sgma=zeros(1,length(SNR));
ber=zeros(1,length(SNR));
for iii=1:length(SNR)
for ii=1:codn
x((ii-1)*code_len+1:code_len*ii)=code(ii);
end
cl=SNR(iii)
size(x)
sgma(iii)=sqrt(N0/2/0.1);
% y=x+sgma(iii)*randn(1,length(x)); % if want to add noise
x2 = x-(1/2); % get rid of most of the dc peak
pt=ones(1,code_len);
rt=pt;
% set up time and frequency arrays
length(x)
u = length(x2);
N = 2^ceil(log2(abs(u)));
delt = 1/fs;
delf1=fs/u;
figure(1)
tvec2=(1:length(x2))*delt;
plot(tvec2,((x2(1,:)+0.5)))
title('orignal baseband')
xlabel('time');
ylabel('amplitude')
ylim([-1 1.5]);
y = fftshift(fft(x2)/N);
z=abs(y);
figure(2)
fvec2=(-length(x2)/2:length(x2)/2-1)*delf1;
plot(fvec2,z)
title('FFT')
xlabel('frequency')
ylabel('amplitude')
figure(3)
z=y;
z(abs(fvec2)>50 & abs(fvec2)<=150)=0;
plot(fvec2,abs(z))
xlabel('frequency removed from 50 to 150 HZ');
ylabel('amplitude')
figure(4)
zf=fftshift(z)*N;
zifft=ifft(zf)+0.5;
MF_out=conv(zifft,rt)*0.5; % sampling time = 0.1
MF_out_downsamp=MF_out(code_len:code_len:end);
MF_out_downsamp=MF_out_downsamp(1:10);
Rx_th=zeros(1,codn);
%Rx_th(find(MF_out_downsamp>1/2))=1;
%Rx_th(find(MF_out_downsamp>mean(abs(MF_out_downsamp))))
for k=1:length(MF_out_downsamp)
if MF_out_downsamp(k)>mean(abs(MF_out_downsamp))
Rx_th(k)=1;
end
if code(k)>mean(abs(code))
code(k)=1;
end
end
nra=code==Rx_th
nerr=length(nra)-sum(nra)
ber(iii)=1/10^(nerr/length(nra)*cl)
end
plot(tvec2,(abs(zifft)))
ylim([-1 1.5])
title('recovered signal')
xlabel('time');
ylabel('amplitude')
figure;
semilogy(EbN0,ber,'b');
xlabel('Eb/N0,(dB)');
ylabel('Bit Error Rate (BER)');
grid on
title('Bit error probability curve for OOK ');
legend('simulation','theory');
codn=1000;
EbN01=20:30;
q=1.6e-19; %
% signal-to-noise ratio in dB.
Ib=202e-6; % Background Noise Current+interfernce
N0=2*q*Ib; % Noise Spectral Density, 2*q*Ib
fs=3600;
bode=100;
code=round(rand(1,codn))
code_len=round(1/bode/(1/fs)) % no of samples/symbol
SNR=10.^(EbN0./code_len);
sgma=zeros(1,length(SNR));
ber=zeros(1,length(SNR));
for iii=1:length(SNR)
for ii=1:codn
x((ii-1)*code_len+1:code_len*ii)=code(ii);
end
cl=SNR(iii)
size(x)
sgma(iii)=sqrt(N0/2/0.1);
% y=x+sgma(iii)*randn(1,length(x)); % if want to add noise
x2 = x-(1/2); % get rid of most of the dc peak
pt=ones(1,code_len);
rt=pt;
% set up time and frequency arrays
length(x)
u = length(x2);
N = 2^ceil(log2(abs(u)));
delt = 1/fs;
delf1=fs/u;
figure(1)
tvec2=(1:length(x2))*delt;
plot(tvec2,((x2(1,:)+0.5)))
title('orignal baseband')
xlabel('time');
ylabel('amplitude')
ylim([-1 1.5]);
y = fftshift(fft(x2)/N);
z=abs(y);
figure(2)
fvec2=(-length(x2)/2:length(x2)/2-1)*delf1;
plot(fvec2,z)
title('FFT')
xlabel('frequency')
ylabel('amplitude')
figure(3)
z=y;
z(abs(fvec2)>50 & abs(fvec2)<=150)=0;
plot(fvec2,abs(z))
xlabel('frequency removed from 50 to 150 HZ');
ylabel('amplitude')
figure(4)
zf=fftshift(z)*N;
zifft=ifft(zf)+0.5;
MF_out=conv(zifft,rt)*0.5; % sampling time = 0.1
MF_out_downsamp=MF_out(code_len:code_len:end);
MF_out_downsamp=MF_out_downsamp(1:10);
Rx_th=zeros(1,codn);
%Rx_th(find(MF_out_downsamp>1/2))=1;
%Rx_th(find(MF_out_downsamp>mean(abs(MF_out_downsamp))))
for k=1:length(MF_out_downsamp)
if MF_out_downsamp(k)>mean(abs(MF_out_downsamp))
Rx_th(k)=1;
end
if code(k)>mean(abs(code))
code(k)=1;
end
end
nra=code==Rx_th
nerr=length(nra)-sum(nra)
ber1(iii)=1/10^(nerr/length(nra)*cl)
end
plot(tvec2,(abs(zifft)))
ylim([-1 1.5])
title('recovered signal')
xlabel('time');
ylabel('amplitude')
figure;
semilogy(EbN0,ber,'b');
hold on
semilogy(EbN0,ber1,'r');
xlabel('Eb/N0,(dB)');
ylabel('Bit Error Rate (BER)');
grid on
title('Bit error probability curve for OOK ');
legend('simulation','theory');

Risposte (2)

Himanshu
Himanshu il 28 Ott 2024 alle 9:47
Hey Imran,
By default, new plots clear existing plots and reset axes properties, such as the title. However, you can use the hold on command to combine multiple plots in the same axes. You can find an example of the same in the following docuentaion link:
Hope this is helpful!

埃博拉酱
埃博拉酱 il 28 Ott 2024 alle 10:25
As @Himanshu said, use hold to preserve old plots is a possible solution. But I prefer to use line instead of plot - it won't reset the previous plot, and will be able to do the same thing as plot, with a slight difference in syntax.

Categorie

Scopri di più su Propagation and Channel Models in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by