MATLAB Answers

Is there a better way to write my downsampling function?

21 views (last 30 days)
Adriana González
Adriana González on 8 Dec 2020
Answered: jibrahim on 9 Dec 2020
I have an audio data I read as a csv and to reduce computation I downsample my data before going with further processing. My code runs my datareduced function 4 times to downsample the data 81:1, but I'm wondering if there's a more efficient/shorter way to write this up in matlab
data = csvread( "VoiceTest1.csv");
% downsample data (81:1) to make processing quicker
reducedData = data;
for i = 1:4
reducedData = reduce(reducedData);
end
function dataReduced = reduce(d)
x1 = d(1:3:end); %slice the x0 and x1's
x2 = d(2:3:end); %slice the x0 and x1's
x3 = d(3:3:end); %slice the x0 and x1's
smooth = conv([1/2 1/2], [1/2 1/2]);
s = min([size(x1,1) size(x2,1) size(x3,1)]);
x1 = x1(1:s);
x2 = x2(1:s);
x3 = x3(1:s);
dataReduced = x1.*smooth(1) + x2.*smooth(2) + x3.*smooth(3);
end
Is there any way to make this function better in matlab?
Any suggestions? Thanks

  0 Comments

Sign in to comment.

Answers (1)

jibrahim
jibrahim on 9 Dec 2020
Hi Adriana,
You should be able to use one of many resampling functions in Signal Processing Toolbox:
Take a look at resample in particular for your use case.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!