Limits must be a 2-element vector of increasing durations.

조회 수: 154 (최근 30일)
Abdur Raziq khan
Abdur Raziq khan 2021년 1월 14일
댓글: Cris LaPierre 2022년 6월 22일
%% question1 part(a)
load handel.mat
filename = 'handel.wav';
audiowrite('handel.wav',y,Fs)
clear y Fs
info = audioinfo('handel.wav')
[y,Fs] = audioread('handel.wav');
%sound(y,Fs);
t = 0:seconds(1/Fs):seconds(info.Duration);
t = t(1:end-1);
plot(t,y)
xlabel('Time-sec')
ylabel('Amplitude')
%% question1 part(b)
amplitudes = abs(y); % abs(a) is the amplitudes in an all-positive sense
mp = max(abs(y)); % max is the highest amplitude.
L=8;
dyn_range_of_interval = 2*mp/L;
thresholds = linspace(-(mp-dyn_range_of_interval),(mp-dyn_range_of_interval),L-1);
Temp_vector = [-mp thresholds mp];
for k=1:length(Temp_vector)-1
codebook(k) = (Temp_vector(k)+Temp_vector(k+1))/2; end
[index,quants] = quantiz(y,thresholds,codebook);
plot(t,y,'x',t,quants,'.')
legend('Original signal','Quantized signal');
xlim([0.2 0.4])
  댓글 수: 3
Abdur Raziq khan
Abdur Raziq khan 2021년 1월 14일
Error using xlim (line 31)
Limits must be a 2-element vector of increasing durations.
Error in task1 (line 33)
xlim([0.2 0.4])
Abdur Raziq khan
Abdur Raziq khan 2021년 1월 14일
I take two element vector of increaning duration but gives me error?

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 1월 15일
편집: Cris LaPierre 2021년 1월 16일
You are plotting a variable of data type duration as x. Therefore, your axis is made up of durtions. The xlim values you use must also be of datatype duration. You use seconds to create t, so do the same for xlim.
%% question1 part(a)
load handel.mat
t = 0:seconds(1/Fs):seconds(length(y)/Fs);
t = t(1:end-1);
plot(t,y)
xlabel('Time-sec')
ylabel('Amplitude')
%% question1 part(b)
amplitudes = abs(y); % abs(a) is the amplitudes in an all-positive sense
mp = max(abs(y)); % max is the highest amplitude.
L=8;
dyn_range_of_interval = 2*mp/L;
thresholds = linspace(-(mp-dyn_range_of_interval),(mp-dyn_range_of_interval),L-1);
Temp_vector = [-mp thresholds mp];
for k=1:length(Temp_vector)-1
codebook(k) = (Temp_vector(k)+Temp_vector(k+1))/2;
end
[index,quants] = quantiz(y,thresholds,codebook);
plot(t,y,'x',t,quants,'.')
legend('Original signal','Quantized signal');
xlim(seconds([0.2 0.4]))
  댓글 수: 4
Kosta Manser
Kosta Manser 2022년 6월 22일
I have been trying to use the xlim(seconds([start end])) in a subplot but it does not wok in that scenario. The xlimits are not enforced and no error is given.
Cris LaPierre
Cris LaPierre 2022년 6월 22일
There must be some details missing. Is your xdata of data type duration? What code follows your xlim code?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by