我是靠谱客的博主 纯真奇迹,最近开发中收集的这篇文章主要介绍matlab resample上采样,resample matlab实现,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

使用线性插值实现sample rate转换。

function output = simpleResample(input, inputfs, outputfs)

inputLen = length(input(:, 1));

outputLen = floor(inputLen * outputfs / inputfs);

output = zeros(outputLen, 1);

timeStep = inputfs / outputfs;

curTime = 1;

integer = 0;

frac = 0;

for i = 1:1:outputLen

integer = floor(curTime)

frac = curTime - floor(curTime);

if integer + 1 < inputLen

output(i, 1) = input(integer, 1) + frac * ( input(integer + 1, 1) - input(integer, 1));

end

curTime = curTime + timeStep;

end

win = fir1(13, 0.6, 'low')

output = filter(win, 1, output);

end

使用sinc window实现sample rate转换,可能sinc window 没有设计好,效果不是很好。

function ouput = myResample( input, inputfs, outputfs)

inputLen = length(input(:, 1));

outputLen = floor(inputLen * outputfs / inputfs);

output = zeros(outputLen, 1);

timeStep = inputfs / outputfs;

factor = outputfs / inputfs;

L = 8;%entries per zero-crossing

Nz = 7;%number of zero-crossing

winLen = 2 * L * Nz + 1;

filterInt = 4;

filterLen = floor(winLen / filterInt);

%generate sinc window function

for i = ceil(-winLen/2) :1 : floor(winLen/2)

winIdx = i + floor(winLen/2) + 1;

tmp = pi * double(i) / L;

if i == 0

win(winIdx) = 1;

else

win(winIdx = sin(tmp)/tmp;

end

end

win = win * 0.6;

%add delay before input

delaySample = floor(filterLen / 2);

delayInput = zeros(inputLen + delaySample, 1);

delayInput(delaySample + 1 : inputLen + delaySample, 1) = input(:, 1);

curTime = 1;

t = 1;

pos = 1;

for t = 1:1:outputLen

integer = floor(curTime)

frac = curTime - floor(curTime);

filtOfsset = floor(frac * filterInt);

if integer + filtLen - 1 < inputLen + delaySample

pos = integer;

winStart = floor(winLen / 2 - filterInt * filterLen / 2) - 1;

winEnd = floor(winLen /2 + filterInt * filterLen / 2);

%filter by sinc window

for j = winStart : 1 : winEnd

if j - filtOffset < 1

winCoeff = 0;

else

winCoeff = win(j - filtOffset);

end

output(t, 1) = output(t, 1) + winCoeff * delayInput(pos, 1);

pos = pos + 1;

end

end

curTime = curTime + timeStep;

end

end

最后

以上就是纯真奇迹为你收集整理的matlab resample上采样,resample matlab实现的全部内容,希望文章能够帮你解决matlab resample上采样,resample matlab实现所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部