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
resample matlab实现的更多相关文章
- Resample the mask
我们所用功能像和mask的size不同时,我们首先要对mask进行resample,令其和功能像的size相同才可以. 根据严超赣老师的回复,有三种方法:http://restfmri.net/for ...
- matlab numpy equivalents
THIS IS AN EVOLVING WIKI DOCUMENT. If you find an error, or can fill in an empty box, please fix it! ...
- 《DSP using MATLAB》示例 Example 9.6
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 基于MATLAB的语音信号处理
一.图形界面设计 1.新建GUI界面 2.新建空白页 3.命名为"yydsp",打开界面 4.拖放控件 5.按预定功能修改界面 6.填写Callback函数 未填写前的代码: fu ...
- 机器学习技法实现(一):AdaBoost- Decision Stump (AdaBoost - 决策树的基于Matlab的实现)
经过前面对AdaBoost的总结,下面要基于Matlab实现AdaBoost-Stump进行二维平面数据点的分类的实验. 一. 实验原理 参看 http://blog.csdn.net/lg12591 ...
- 【VS开发】【智能语音处理】MATLAB 与 音频处理 相关内容摘记
MATLAB 与 音频处理 相关内容摘记 MATLAB 与 音频处理 相关内容摘记 1 MATLAB 音频相关函数 1 MATLAB 处理音频信号的流程 2 音量标准化 2 声道分离合并与组合 3 数 ...
- Matlab 绘制三维立体图(以地质异常体为例)
前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...
- Matlab slice方法和包络法绘制三维立体图
前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...
- Matlab 高斯_拉普拉斯滤波器处理医学图像
前言:本程序是我去年实现论文算法时所做.主要功能为标记切割肝脏区域.时间有点久,很多细节已经模糊加上代码做了很多注释,因此在博客中不再详述. NOTE: 程序分几大段功能模块,仔细阅读,对解决医学图像 ...
随机推荐
- SQL Server无备份误删数据的恢复
在正式生产数据库中,因为客户现场管理不规范产生了一条错误数据,由于自身睡眠不佳加上客户方言表达,将编号记错,在没有备份的情况下,直接连远程数据库执行了delete操作. 由于备份设置的是每日0点,当天 ...
- day9 修改文件
# 修改文件 # 文件是不能修改 with open('小护士班主任', mode='r', encoding='utf-') as f, open('小护士班主任.bak', 'w', encodi ...
- 【论文翻译】An overiview of gradient descent optimization algorithms
这篇论文最早是一篇2016年1月16日发表在Sebastian Ruder的博客.本文主要工作是对这篇论文与李宏毅课程相关的核心部分进行翻译. 论文全文翻译: An overview of gradi ...
- C++->输入输出文件流的相关函数
标准输入输出流与文件输入输出流的关系图: 文件输出流头文件“ofstream/fstream”,文件输入流头文件“ifstream/fstream” 1.1.打开文件方式:流类 对象名(文件名,方式) ...
- awk数组学习1
看到有网上一篇博客写的 https://blog.csdn.net/hu721659947/article/details/80352003 输出数组中大于5的数,需要注意if [ $a –ge$b ...
- 剑指offer-面试题14-剪绳子-贪婪算法
/* 题目: 给定一个长度为n的绳子,把绳子剪为m段,(n>1,m>1) 求各段绳子乘积的最大值. */ /* 思路: 贪婪算法. 当绳子的长度大于5时,尽可能多的剪长度为3的绳子:当剩下 ...
- sublime text3插件使用
sublime text 使用BUG解决 一.安装emmet.Package Control插件ctrl+shift+p -> install package ->emmet(Zen Co ...
- H5_0011:JS动态创建html并设置CSS属性
1,创建html文本,并设置指定css样式 r = function(e) { var t = document.createElement("div"); t.innerHTML ...
- 转载:openmax基本概念
https://yellowmax.blog.csdn.net/article/details/78080168 https://yellowmax.blog.csdn.net/article/det ...
- MySQL8.0.11解压版安装详细教程
1. 从官网下载zip包 官网网址(https://dev.mysql.com/downloads/mysql/) 2. 解压 将压缩包解压到一个目录(后续将此目录作为安装目录),我这里是解压到了D: ...