MATLAB Answers

Time axis explanation required

조회 수: 2(최근 30일)
Saad Rana
Saad Rana 7 Jun 2020
I am recording my 3 seconds voice signal to plot it in a graph. But the time axis in the graph seem strange. I am recording 3 second audio so to my understanding time axis should be from 0-3 but it shows values in [x10^5]. I asked another question here and foud out the code that plots the x axis but I cannot undeerstand how is it being plotted. Here's my code:
fs = 48000;
rec1 = audiorecorder(fs,16,1);
recordblocking(rec1, 3);
myRec1 = getaudiodata(rec1);
time = length(myRec1)/fs
ti = 0:time:(length(myRec1)*time)-time;
If I write:
it does not plot saying vectors must be of same length. So can anyone explain to me how is this line working
ti = 0:time:(length(myRec1)*time)-time;
I mean like how is it values in [x10^5] and not 0-3 in the x axis?


David Goodmanson
David Goodmanson 7 Jun 2020
Hi Saad,
'time' is (almost) the total length of the time record, so it will not be the spacing when setting up the time array. Try
time = (length(myRec1)-1)/fs
timearray = linspace(0,time,length(myRec1))

Community Treasure Hunt

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

Start Hunting!

Translated by