Is there a better way to write my downsampling function?
23 views (last 30 days)
Show older comments
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
Answers (1)
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
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!