arrays have incompatible sizes for this operation help me PLZ

조회 수: 8(최근 30일)
Mahra Albadi
Mahra Albadi 2021년 11월 14일
댓글: Mahra Albadi 2021년 11월 28일
clear;close all;clc
counter=1;
min_nl=-10;
step_nl=1;
max_nl=0;
noise_levelsdB=min_nl:step_nl:max_nl;
for k=min_nl:step_nl:max_nl
k
data_size = 10000;
data =randi([0 1], data_size, 1); data=data';
bp=0.000001;
expand=100;
baseband=zeros(1,length(data)*expand);
for n=1:1:length(data)
if data(n)==1
se=ones(expand,1);
else
data(n)=0;
se=zeros(expand,1);
end
baseband((n-1)*expand+1:n*expand)=se;
end
end
A=sqrt(2); %Amplitude carrier
br=1/bp;%bit rate 1 mbps
f=br*11; % carrier freq 2Mz
t_bit=bp/expand:bp/expand:bp;
ss=length(t_bit);
transmitterCarrier=A*sin(2*pi*f*t_bit);
%show modulated signal%
basebandNRZ=(2*baseband-1);
modulated_signal=transmitterCarrier.*basebandNRZ;
sigma2=1/10^(k/20);
noise=sigma2*randn(1, length(modulated_signal));
noisy_modulated_signal=modulated_signal+noise;
demodulated_data=[];
carrier_receiver=sin(2*pi*f*t_bit);
for n=ss:ss:length(noisy_modulated_signal)
demodulated_signal=carrier_receiver.*noisy_modulated_signal((n-(ss-1)):n);
z=trapz(t_bit,demodulated_signal);
zz=round((2*z/bp));
if(zz>0)
a=1;
else
a=0;
end
demodulated_data=[demodulated_data a];
end
close all
semilogy(noise_levelsdB,BER)
xlabel('Eb/No(dB)')
ylabel('BER BPSK')
grid on
title('(Aaesha Mahra A, Mahra M)')
hold on
error in line 35

답변(1개)

VBBV
VBBV 2021년 11월 18일
clear;close all;clc
counter=1;
min_nl=-10;
step_nl=1;
max_nl=0;
noise_levelsdB=min_nl:step_nl:max_nl;
for k=min_nl:step_nl:max_nl
k;
data_size = 10000;
data =randi([0 1], data_size, 1); data=data';
bp=0.000001;
expand=100;
baseband=zeros(1,length(data)*expand);
for n=1:1:length(data)
if data(n)==1
se=ones(expand,1);
else
data(n)=0;
se=zeros(expand,1);
end
baseband((n-1)*expand+1:n*expand)=se;
end
end
A=sqrt(2); %Amplitude carrier
br=1/bp;%bit rate 1 mbps
f=br*11; % carrier freq 2Mz
t_bit=logspace(bp/expand,bp,length(br));
ss=length(t_bit);
transmitterCarrier=A*sin(2*pi*f*t_bit);
%show modulated signal%
basebandNRZ=(2*baseband-1);
modulated_signal=transmitterCarrier.*basebandNRZ
modulated_signal = 1×1000000
1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458 1.2458
sigma2=1/10^(k/20);
noise=sigma2*randn(1, length(modulated_signal));
noisy_modulated_signal=modulated_signal+noise;
demodulated_data=[];
carrier_receiver=sin(2*pi*f*t_bit);
for n=ss:100*ss:length(noisy_modulated_signal)
demodulated_signal=carrier_receiver.*noisy_modulated_signal((n-(ss-1)):n);
z=t_bit*trapz(demodulated_signal);
zz=round((2*z/bp));
if(zz>0)
a=1;
else
a=0;
end
demodulated_data=[demodulated_data a];
end
you can use normalize the dimensions of two vectors transmitterCarrier, basebandNRZ before multiplying them together

태그

Community Treasure Hunt

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

Start Hunting!

Translated by