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

resample matlab实现的更多相关文章

  1. Resample the mask

    我们所用功能像和mask的size不同时,我们首先要对mask进行resample,令其和功能像的size相同才可以. 根据严超赣老师的回复,有三种方法:http://restfmri.net/for ...

  2. matlab numpy equivalents

    THIS IS AN EVOLVING WIKI DOCUMENT. If you find an error, or can fill in an empty box, please fix it! ...

  3. 《DSP using MATLAB》示例 Example 9.6

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  4. 基于MATLAB的语音信号处理

    一.图形界面设计 1.新建GUI界面 2.新建空白页 3.命名为"yydsp",打开界面 4.拖放控件 5.按预定功能修改界面 6.填写Callback函数 未填写前的代码: fu ...

  5. 机器学习技法实现(一):AdaBoost- Decision Stump (AdaBoost - 决策树的基于Matlab的实现)

    经过前面对AdaBoost的总结,下面要基于Matlab实现AdaBoost-Stump进行二维平面数据点的分类的实验. 一. 实验原理 参看 http://blog.csdn.net/lg12591 ...

  6. 【VS开发】【智能语音处理】MATLAB 与 音频处理 相关内容摘记

    MATLAB 与 音频处理 相关内容摘记 MATLAB 与 音频处理 相关内容摘记 1 MATLAB 音频相关函数 1 MATLAB 处理音频信号的流程 2 音量标准化 2 声道分离合并与组合 3 数 ...

  7. Matlab 绘制三维立体图(以地质异常体为例)

    前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...

  8. Matlab slice方法和包络法绘制三维立体图

    前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...

  9. Matlab 高斯_拉普拉斯滤波器处理医学图像

    前言:本程序是我去年实现论文算法时所做.主要功能为标记切割肝脏区域.时间有点久,很多细节已经模糊加上代码做了很多注释,因此在博客中不再详述. NOTE: 程序分几大段功能模块,仔细阅读,对解决医学图像 ...

随机推荐

  1. C# 数组冒泡排序复习

    using System; namespace runoob { class MyClass { static void Main(string[] args) { MyClass1 myClass ...

  2. jQuery---事件的执行顺序

    事件的执行顺序 // 1 这个是p自己注册的事件(简单事件) $("p").on("click", function () { alert("呵呵哒& ...

  3. (LNMP) Nginx_PHP_MariaDB

    L用的是Centos7.5以上,主要是NMP三组件的安装记录. 通常会先安装一下依赖: yum install -y pcre-devel zlib-devel openssl-devel 使用yum ...

  4. 【笔记】机器学习 - 李宏毅 - 10 - Tips for Training DNN

    神经网络的表现 在Training Set上表现不好 ----> 可能陷入局部最优 在Testing Set上表现不好 -----> Overfitting 过拟合 虽然在机器学习中,很容 ...

  5. [CF1311F] Moving Points - 树状数组

    Solution 按 \(x\) 关键字升序排序,依次枚举每个点 考虑对任意 \(x_j < x_i\),那么当 \(v_j \leq v_i\) 时,它们不会相交,且 \(dis\) 就是它们 ...

  6. Pr制作音乐相册

    Pr制作音乐相册 设置蒙版效果

  7. MyEclipse配置和使用Maven

    maven是管理项目的,myeclipse是编写代码的.第一次写项目都要配置好多东西,很麻烦,now 来看看怎样新建一个maven项目. 工具/原料   myeclipse maven 方法/步骤   ...

  8. 【14】Softmax回归

    在下面的内容中,我们用C来表示需要分的类数. 最后一层的隐藏单元个数为4,为所分的类的数目,输出的值表示属于每个类的概率. Softmax函数的具体步骤如下图: 简单来说有三步: 计算z值(4×1矩阵 ...

  9. 安装Docker到Ubuntu(APT)

    运行环境 系统版本:Ubuntu 16.04.5 LTS 软件版本:Docker-CE-18.09.5 硬件配置:无 安装过程 1.卸载旧版本 root@ubuntu:~# sudo apt-get ...

  10. String类型的日期怎么转化为Date类型

    在一个SQL中,如果同时使用rownum和order by,会有一个先后顺序的问题. 比如select id1,id2 from t_tablename where rownum<3 order ...