Matrix dimensions must agree spread spectrum code

1 visualización (últimos 30 días)
mohamed tarek
mohamed tarek el 3 de Dic. de 2020
Comentada: KSSV el 5 de Dic. de 2020
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');

Respuestas (1)

KSSV
KSSV el 3 de Dic. de 2020
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
Matrix dimensions must agree.
  2 comentarios
haitham abodoh
haitham abodoh el 4 de Dic. de 2020
I understand this error, but it means that it wants to solve this error, and we do not know. thanks for your reply .
KSSV
KSSV el 5 de Dic. de 2020
Get them to the same size to solve the error.

Iniciar sesión para comentar.

Categorías

Más información sobre Time-Frequency Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by