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.

 채택된 답변

Walter Roberson
Walter Roberson 2022년 3월 25일

1 개 추천

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);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

제품

릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by