Matrix dimensions must agree spread spectrum code
显示 更早的评论
While trying to create a Spread Spectrum program I had a problem
Matrix dimensions must agree.
Error in untitled5 (line 36)
bpsk_sig=spreaded_sig.*carrier;
I tried to fix this problem, but I couldn't
Code
filename = 'mina.m4a.wma';
fid = fopen(filename, 'r+');
Sound_in_bits = fread(fid, [1 inf]);
fclose(fid);
% Generating the pseudo random bit pattern for spreading
d=round(rand(1,length(Sound_in_bits))); % "round" is used to approximate the values to 1 and -1
pn_seq=[];
carrier=[];
t=[0:2*pi/4:2*pi]; % Creating 5 samples for one cosine
for k=1:length(Sound_in_bits)
if d(1,k)==0
sig=-ones(1,1);
else
sig=ones(1,1);
end
c=cos(t);
carrier=[carrier c];
pn_seq=[pn_seq sig];
end
subplot(3,1,1); plot(pn_seq); grid;
title('Spreading code');
% Spreading of sequence
spreaded_sig= Sound_in_bits .* pn_seq;
subplot(3,1,2); plot(spreaded_sig); grid;
title('Spreaded signal');
% BPSK Modulation of the spreaded signal
bpsk_sig=spreaded_sig.*carrier;
% Modulating the signal
subplot(3,1,3);
plot(bpsk_sig);
axis([-1 620 -1.5 1.5]);
title('BPSK Modulated Signal');
回答(1 个)
The error is simple...you need to check the dimensions of your variables spreaded_sig and carrier. To use element by element multiplication (.*) they should be of same size if not you will get the mentioned error.
A = rand(5) ;
B = rand(5) ;
C = A.*B ; % no error
A = rand(3) ;
B = rand(2) ;
C = A.*B ; % Error
2 个评论
haitham abodoh
2020-12-4
I understand this error, but it means that it wants to solve this error, and we do not know. thanks for your reply .
KSSV
2020-12-5
Get them to the same size to solve the error.
类别
在 帮助中心 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!