Effacer les filtres
Effacer les filtres

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

158 vues (au cours des 30 derniers jours)
Abdur Raziq khan
Abdur Raziq khan le 14 Jan 2021
Commenté : Cris LaPierre le 22 Juin 2022
%% 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 commentaires
Abdur Raziq khan
Abdur Raziq khan le 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 le 14 Jan 2021
I take two element vector of increaning duration but gives me error?

Connectez-vous pour commenter.

Réponse acceptée

Cris LaPierre
Cris LaPierre le 15 Jan 2021
Modifié(e) : Cris LaPierre le 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 commentaires
Kosta Manser
Kosta Manser le 22 Juin 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 le 22 Juin 2022
There must be some details missing. Is your xdata of data type duration? What code follows your xlim code?

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by