Is there a better way to write my downsampling function?

16 ビュー (過去 30 日間)
Adriana González
Adriana González 2020 年 12 月 8 日
回答済み: jibrahim 2020 年 12 月 9 日
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 Center および File ExchangeMultirate Signal Processing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by