I have the following code for a digital signal processing problem with the file
[x,Fs] = audioread('speech_tait(2).m4a');
sound(x,Fs)
plot(x)
xlabel('Time')
ylabel('Audio Signal')
info = audioinfo('speech_tait(2).m4a');
t = 0:seconds(1/Fs):seconds(info.Duration);
t = t(1:end-2);
L = 1000;
VoicedSpeech = x(L:0+ L-1);
UnvoicedSpeech = x(L:0 + L-1);
%subplot(2,1,1);
% x1 = linspace(0,7);
% y1 = VoicedSpeech;
% plot(x,y1)
%
% subplot(2,1,2);
% y2 = UnvoicedSpeech;
% plot(x,y2)
I need to save 100 samples from the voiced segment (first spike) of the speech into a MATLAB vector called VoicedSpeech and save 300 samples from the unvoiced segment (second spike) of the speech into a MATLAB vector called UnvoicedSpeech, then use the subplot command to plot the two signals, VoicedSpeech and UnvoicedSpeech, on a single figure.
The commented part always gives me an error about having the wrong vector length.

 Réponse acceptée

Walter Roberson
Walter Roberson le 25 Mar 2022
L = 1000;
VoicedSpeech = x(L:0+ L-1);
When L is 1000, then the : expression is 1000:0+1000-1 which is 1000:999 which is going to be the empty vector.
You need to analyze the signal in x to figure out where a long-enough voiced segment starts, and extract 1000 from there, and where a long-enough unvoiced segments starts and extract 300 from there.
vp = appropriate value for where the voiced segment starts
VoicedSpeech = x(vp:vp+L-1);

Plus de réponses (0)

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Centre d'aide et File Exchange

Produits

Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by