fs=8e3; % tần số lấy mẫu
step=1/fs; % chu kỳ lấy mẫu
A=87.6; % hằng số nén luật A
t=0:step:1; %vecto thời gian- quá trình lấy mẫu
Pa=-14:28/255:14; % vecto các mức lượng tử hóa, biên độ lớn nhất và nhỏ nhất có thể của s(t) là 14 và -14
s(t)=(1*cos(2*pi*100*t))+(2*cos(2*pi*200*t+pi/2))+(3*cos(2*pi*200*t+pi/4)); % quá trình lấy mẫu
Array indices must be positive integers or logical values.
Error in untitled2 (line 8)
s(t)=(1*cos(2*pi*100*t))+(2*cos(2*pi*200*t+pi/2))+(3*cos(2*pi*200*t+pi/4)); % quá trình lấy mẫu

Antworten (1)

DGM
DGM am 10 Mai 2022

0 Stimmen

As mentioned in the comment you left,
t is not a nonzero integer, so you can't use it as an index on the LHS of the assignment.
s = cos(2*pi*100*t) + 2*cos(2*pi*200*t+pi/2) + 3*cos(2*pi*200*t+pi/4); % quá trình lấy mẫu

3 Kommentare

Nguyen Quoc Khanh
Nguyen Quoc Khanh am 20 Mai 2022
fs=8e3; % tần số lấy mẫu
step=1/fs; % chu kỳ lấy mẫu
A=87.6; % hằng số nén luật A
t=0:step:1; % vecto thời gian- quá trình lấy mẫu
Pa=-14:28/255:14; % vecto các mức lượng tử hóa, biên độ lớn nhất và nhỏ nhất có thể của s(t) là 14 và -14
s=1*cos(2*pi*100*t)+2*cos(2*pi*200*t+pi/2)+3*cos(2*pi*200*t+pi/4);% quá trình lấy mẫu
sc = compand(s,A,max(s),'A/compressor'); % nén luật A
C=quantiz(sc,Pa); % lượng tử hóa
% quá trình mã hóa và biến đổi từ ma trận sang veto nhị phân
Code=(de2bi(C))';
Code=(Code(:))';%
S=zeros(1,length(C));
% quá trình giải mã
for k=1:length(C)
S(k)=Pa(C(k)+1);
end
SC = compand(S,A,max(S),'A/expander');% giải nén luật A
SC=interp(SC,100);% quá trình nội suy, tấn số lấy mẫu mới=100.fs
% ve hinh
figure(1)
subplot(2,1,1)
for k=1:100
plot(k:0.01:k+0.99,Code(k)*[0 ones(1,98) 0],'color','r')
hold on
end
title('Tin hieu goc ban tin')
axis([0,100,0,3])
subplot(2,1,2)
plot(SC(1:100*100))
title('Tin hieu thu')
hold on;
figure(2)
subplot(3,1,1)
num_3s=3*(1/100)/step;%
stem(t(1:num_3s),s(1:num_3s))
title('Dang tin hieu lay mau o 3 chu ky dau tien, fs=8e3 Hz')
subplot(3,1,2)
stem(t(1:num_3s),sc(1:num_3s))
title('Dang tin hieu qua bo nen ')
subplot(3,1,3)
%
for k=1:num_3s
plot(t(k):step/99:t(k+1),sc(k)*[0 ones(1,98) 0],'color','b')
hold on
end
title('Dang tin hieu qua bo luong tu hoa 256 muc')
figure(3)
subplot(2,1,1)
plot(t(1:num_3s),s(1:num_3s))
title('Tin hieu goc lay mau fs=8e3 Hz')
subplot(2,1,2)
%
plot(step/100:step/100:3*1/100,SC(1:num_3s*100))
title('Tin hieu thu sau bo noi suy co tan so lay mau= 100.fs')
figure(4)
subplot(2,1,1)
one=ones(1,5);in=[];d=1;
for k=1:5:100*1*2
in(k:k+4)=one*Code(d);d=d+1;
end
[Pf,f]=SP(0:length(in)-1,in);
semilogy(f,Pf)
title('tin hieu goc')
subplot(2,1,2)
[Pf1,f1]=SP(0:100*100-1,SC(1:100*100));
semilogy(f1,Pf1)
title('tin hieu sau xu ly')
hold off;
Error in untitled (line 62)
[Pf,f]=SP(0:length(in)-1,in);
please help me fix bug !! thanks u
Torsten
Torsten am 20 Mai 2022
What is "SP" ? A function ? I can't find it.
Jan
Jan am 20 Mai 2022
Please post the complete error message.
What is "SP"?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 10 Mai 2022

Kommentiert:

Jan
am 20 Mai 2022

Community Treasure Hunt

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

Start Hunting!

Translated by