unable to plot semilogy properly
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Abdul Hamzah
il 2 Mar 2024
Commentato: Star Strider
il 2 Mar 2024
hello everyone, I have a code that simulates QAM modulation below:
% QPSK
M = 8;
k = log2(M); % Bits per symbol
EbNoVec = (5:15); % Eb/No values (dB)
numSymPerFrame = 1000; % Number of PSK symbols per frame
berEst = zeros(size(EbNoVec));
for n = 1:length(EbNoVec)
% Convert Eb/No to SNR
snrdB = EbNoVec(n) + 10*log10(k);
% Reset the error and bit counters
numErrs = 0;
numBits = 0;
while numErrs < 200 && numBits < 1e7
% Generate binary data and convert to symbols
data_in = randi([0 1],numSymPerFrame*k,1);
%----------------------------------------------------------------
% Your modulator here:
modSig = pskmod(data_in,M,InputType='bit'); % PSK Modulation
% Pass through AWGN channel:
rxSig = awgn(modSig, snrdB); % Additive White Gaussian Noise with
% increasing snrdB
% Your demodulator here:
data_out = pskdemod(rxSig,M,OutputType='bit'); % PSK Demodulation
%----------------------------------------------------------------
% Calculate the number of bit errors
nErrors = biterr(data_in,data_out);
numErrs = numErrs + nErrors;
numBits = numBits + numSymPerFrame*k;
end
% Estimate the BER
berEst(n) = numErrs/numBits;
fprintf("snrdB: %.6f berEst: %.6f " + ...
" \n \t numErrs: %d numBits: %d\n\n", snrdB, berEst(n), numErrs, numBits);
end
fitEbN0 = EbNoVec(1):0.25:EbNoVec(end); % Interpolation values
berfit(EbNoVec,berEst,fitEbN0);
hold on;
for n=1:length(EbNoVec)
semilogy([EbNoVec(n) EbNoVec(n)],'g-+');
end
hold off;
the code runs well, but unfortunately the semilogy looks like this :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1633211/image.png)
the 'g-+' does not show up on the plot...do you know how to resolve this issue?? any response regarding this problem is really appreciated..thx
0 Commenti
Risposta accettata
Star Strider
il 2 Mar 2024
Modificato: Star Strider
il 2 Mar 2024
% QPSK
M = 8;
k = log2(M); % Bits per symbol
EbNoVec = (5:15); % Eb/No values (dB)
numSymPerFrame = 1000; % Number of PSK symbols per frame
berEst = zeros(size(EbNoVec));
for n = 1:length(EbNoVec)
% Convert Eb/No to SNR
snrdB = EbNoVec(n) + 10*log10(k);
% Reset the error and bit counters
numErrs = 0;
numBits = 0;
while numErrs < 200 && numBits < 1e7
% Generate binary data and convert to symbols
data_in = randi([0 1],numSymPerFrame*k,1);
%----------------------------------------------------------------
% Your modulator here:
modSig = pskmod(data_in,M,InputType='bit'); % PSK Modulation
% Pass through AWGN channel:
rxSig = awgn(modSig, snrdB); % Additive White Gaussian Noise with
% increasing snrdB
% Your demodulator here:
data_out = pskdemod(rxSig,M,OutputType='bit'); % PSK Demodulation
%----------------------------------------------------------------
% Calculate the number of bit errors
nErrors = biterr(data_in,data_out);
numErrs = numErrs + nErrors;
numBits = numBits + numSymPerFrame*k;
end
% Estimate the BER
berEst(n) = numErrs/numBits;
fprintf("snrdB: %.6f berEst: %.6f " + ...
" \n \t numErrs: %d numBits: %d\n\n", snrdB, berEst(n), numErrs, numBits);
end
fitEbN0 = EbNoVec(1):0.25:EbNoVec(end); % Interpolation values
figure
yyaxis left
berfit(EbNoVec,berEst,fitEbN0);
yyaxis right
semilogy(EbNoVec, EbNoVec,'g-+')
figure
berfit(EbNoVec,berEst,fitEbN0);
hlgd = findobj(gcf, 'Type','legend');
hlgd.AutoUpdate = 'on';
hold on;
semilogy(EbNoVec, EbNoVec,'g-+', 'DisplayName','EbNoVec')
hold off;
ylim([min([berEst EbNoVec]) max([berEst EbNoVec])] .* [0.1 10])
get(hlgd) % Show Changed Legend Properties
To plot them on the same axes without using yyaxis, set the ylim limits to accommodate both sets of data. (There must be something about the berfit function that does not allow this to be the default.)
EDIT — (2 Mar 2024 at 14:47)
Added second plot and explanation.
EDIT — (2 Mar 2024 at 15:47)
Changed legend.
.
4 Commenti
Star Strider
il 2 Mar 2024
Yes.
First, I got its handle with:
hlgd = findobj(gcf, 'Type','legend');
then I changed it to turn 'AutoUpdate' to 'on' and that added ‘EbNoVec’ to it, which is what I wanted to do. (You can change it to not do that by turning 'AutoUpdate' to 'off'.)
I am not certain what else you want to change, however that should also serve as an example of how to change its properties.
The:
get(hlgd)
function call displays the legend properties. Comment that line (or delete it) to prevent the properties from displaying.
.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su QAM in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!