Is there a better way to write my downsampling function?

21 visualizaciones (últimos 30 días)
Adriana González
Adriana González el 8 de Dic. de 2020
Respondida: jibrahim el 9 de Dic. de 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

Respuestas (1)

jibrahim
jibrahim el 9 de Dic. de 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.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by