Time axis explanation required

3 views (last 30 days)
Saad Rana
Saad Rana on 7 Jun 2020
Answered: David Goodmanson on 7 Jun 2020
Hi,
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;
axes(handles.orignal)
plot(ti,myRec1)
If I write:
plot(time,myRec1)
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?

Answers (1)

David Goodmanson
David Goodmanson on 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))

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!