• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

resamplematlab实现

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

使用线性插值实现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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
蛙蛙推荐:蛙蛙Delphi学习经验(第一版)发布时间:2022-07-18
下一篇:
吐血整理 Delphi系列书籍 118本(全)发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap