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

147 次查看(过去 30 天)
%% 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