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

148 visualizzazioni (ultimi 30 giorni)
%% 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 Commenti
Abdur Raziq khan
Abdur Raziq khan il 14 Gen 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 il 14 Gen 2021
I take two element vector of increaning duration but gives me error?

Accedi per commentare.

Risposta accettata

Cris LaPierre
Cris LaPierre il 15 Gen 2021
Modificato: Cris LaPierre il 16 Gen 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 Commenti
Kosta Manser
Kosta Manser il 22 Giu 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 il 22 Giu 2022
There must be some details missing. Is your xdata of data type duration? What code follows your xlim code?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by