필터 지우기
필터 지우기

How do i plot an audio file with an interval in ms?

조회 수: 24 (최근 30일)
Michael Sugiarto
Michael Sugiarto 2022년 3월 22일
댓글: Scott MacKenzie 2022년 3월 22일
Hi! I am currently using matlab 2021 version. I want to know how would I plot an audio file in the interval of 20 miliseconds of my choice for example the audio recording is 10 seconds long but, I want to plot only from 0 to 20 miliseconds. How would I do that? This is my code right now
recObj = audiorecorder;
Fs=8000;
filename = sprintf('myAudioData.wav');
disp('Start speaking.')
recordblocking(recObj, 10);
disp('End of Recording.');
doubleArray = getaudiodata(recObj);
audiowrite(filename,doubleArray,Fs);
[x,Fs] = audioread('myAudioData.wav');
[m,n]=size(x);
dt=1/Fs;
t=dt*(0:m-1);
idx = (t>=1.030) & (t<1.032);
selected_t = t(idx);
selected_x = x(idx,:);
plot(selected_t, selected_x);

채택된 답변

Scott MacKenzie
Scott MacKenzie 2022년 3월 22일
편집: Scott MacKenzie 2022년 3월 22일
Using the sample frequency of the audio data (Fs), this code will extract and plot the first 20 ms:
[x, Fs] = audioread('AudioSample.wav'); % test audio file
ts = 1 / Fs; % duration of each sample
n = round(0.02/ts); % number of samples in 1st 20 ms
plot(x(1:n)); % plot 1st 20 ms of audio file
  댓글 수: 5
Michael Sugiarto
Michael Sugiarto 2022년 3월 22일
Thank you so much!!
Scott MacKenzie
Scott MacKenzie 2022년 3월 22일
@Michael Sugiarto, you're welcome. Good luck.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2022년 3월 22일
idx = t <= 20*10^-3 ;
plot(t(idx),x(idx))

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by