Is there a better way to write my downsampling function?

17 次查看(过去 30 天)
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

回答(1 个)

jibrahim
jibrahim 2020-12-9
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.

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by