Clear Filters
Clear Filters

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

159 views (last 30 days)
%% 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 Comments
Abdur Raziq khan
Abdur Raziq khan on 14 Jan 2021
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 on 14 Jan 2021
I take two element vector of increaning duration but gives me error?

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 15 Jan 2021
Edited: Cris LaPierre on 16 Jan 2021
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 Comments
Kosta Manser
Kosta Manser on 22 Jun 2022
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 on 22 Jun 2022
There must be some details missing. Is your xdata of data type duration? What code follows your xlim code?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!