필터 지우기
필터 지우기

Plotting .wav on MATLAB and converting to array

조회 수: 16 (최근 30일)
John Smith
John Smith 2015년 11월 2일
댓글: Geoff Hayes 2015년 11월 4일
Hi all,
I am using the following code to plot a .wav file on MATLAB:
[wave,fs]=audioread('file.wav');
t=0:1/fs:(length(wave)-1)/fs;
plot(t,wave);
Is this the correct way to plot it? and are the y-axis in Volts and the x-axis in Seconds? If it is the correct way, why is the amplitude being trimmed/clipping at 1?
Also, how can I convert the .wav file into an array so I can than copy it into a text file and use it in another program?
Any help would be highly appreciated.

답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 11월 2일
John - according to audioread output parameters the samples are normalized between -1 and 1 if the data type is not specified or is of type double. As you have not included a data type when calling audioread then the "clamping" that you are observing is expected.
As for converting the wav file into an array, isn't that what the wave array is?
  댓글 수: 8
John Smith
John Smith 2015년 11월 4일
편집: John Smith 2015년 11월 4일
Sorry I forgot to include the code for plotting the text file. I used to code below:
.
%Load text file
path='C:\Users\John\Desktop\';
fileName='test3.txt';
fname=fullfile(path,fileName);
s=load(fname);
%Plot the signal
figure(1);
plot(s(:,1), s(:,2));
Geoff Hayes
Geoff Hayes 2015년 11월 4일
John - since you have written only the wave data to file (which may be both channels?) then your above code of
plot(s(:,1), s(:,2));
is just plotting one channel vs. the other. You probably only need to plot one channel but do so against time like you have done previously. So if you know the sampling frequency fs then you need to do (like before)
s=load(fname);
t=0:1/fs:(length(s)-1)/fs;
plot(t,s(:,1));

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by