Adding duration in second as x axis

1 view (last 30 days)
masnoob
masnoob on 10 Jun 2018
Commented: masnoob on 11 Jun 2018
I have recorded and saved the sound signal and now would like to recreate the plot same as displayed using dsp.timeScope object.
plot(duration,data)
I have tried duration = start:step:end but it ended up having an extra 1 more data point in duration.(Must start with 0 not 1) Is there anyway to overcome this problem? Sampling rate is 44100Hz

Accepted Answer

dpb
dpb on 10 Jun 2018
Don't alias the builtin duration; that will create problems working with time objects.
You don't really want a duration, you just want sampled time.
dt=1000/44100; % sampling time, ms
N=(length(data); % number samples in record
T=(length(data)-1)*dt; % sample time, ms
t=linspace(0,T,N); % make the time vector match the size of the data stream
plot(t,data) % plot, axis will be in msec; adjust xlim, xtick as wanted
If you really, really wanted to use one of the fancier ML features, use a timeseries

More Answers (0)

Community Treasure Hunt

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

Start Hunting!