时间延长信号/将python代码移植到matlab/八度 [英] Time stretching signal / porting python code to matlab / octave

查看:111
本文介绍了时间延长信号/将python代码移植到matlab/八度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将paulstretch的信号扩展到matlab/八度. https://github.com/paulnasca/paulstretch_python

I'm trying to port over paulstretch's signal stretching over to matlab / octave. https://github.com/paulnasca/paulstretch_python

请参阅下面的工作流程

See workflow i'm following below

我可以将信号分为频率,幅度和相位,然后使用下面的代码将它们重新加入. 我在窗口部分上移植,重叠和扩展信号时遇到了问题.有什么想法吗?

I can separate the signals into frequencies, amplitude and phase and join them back using the code below. I'm having issues porting over the windowing segments, overlapping, and extending the signals. Any ideas?

matlab/倍频程代码示例:

freq=[0;0.534974;1.06995;1.60492;2.1399]
amp1=[3.94414e-19;1.20523e-05;5.08643e-06;4.22469e-05;3.04322e-05]
phase=[0;0.0546221;-1.11534;-2.4926;-2.55601]

a1=[freq,amp1,phase];
t_rebuilt=linspace(0,2*pi,8000);
sigcomb=zeros(1,length(t_rebuilt));

kk=0
for kk=1:1:length(freq) %rebuild signal from collected freq,amplitudes,and phases
    sigcomb=sigcomb+a1(kk,2)*cos((a1(kk,1))*t_rebuilt+(a1(kk,3)));
end
normalize=(sigcomb/max(abs(sigcomb))*.8);
wavwrite([normalize'] ,8000,16,strcat('/tmp/test.wav')); 

PS:这只是测试数据,要获得音频信号,我将不得不使用更多的数据点,这使问题变得一团糟.

PS: This is just test data, to get an audio signal I would have to use many more data points which would make a mess of the question.

我的想法是,无论文件被拉长多长时间,都使用一个for循环来创建新信号的切碎的1秒wav文件,因为这将防止具有较大持续时间的文件出现数组大小的内存问题.然后使用我已经弄清楚的其他程序(例如sox)将它们结合在一起.

My thought's are to use a for loop to create chopped up 1 second wav files of the new signal no matter how long the file is stretched out for, as this will prevent array size memory issues with larger duration files. Then join them together using another program like sox which I've already figured out.

PS:我使用的是八度3.8.1,它应该与matlab兼容

PS: I'm using octave 3.8.1 which is suppose to be compatible with matlab

推荐答案

我尝试构建一个没有循环的版本,并使用从以下版本开始的original.ogg http://hypermammut.sourceforge.net/paulstretch/.我认为这是速度和内存大小之间的折衷(如果输入文件很长,下面的版本可能会占用很多内存)

I've tried to build a version without loops and use the original.ogg from http://hypermammut.sourceforge.net/paulstretch/. I think it's a tradeoff between speed and memory size (the version below might use much memory if the input file is long)

[d, fs, bps] = wavread ("original.wav");
printf ("Input duration = %.2f s\n", rows (d)/fs);

stretch = 8;
windowsize = round (0.25 * fs);

step = round ((windowsize/2)/stretch);

## original window
fwin = @(x) (1-x.^2).^1.25;
win = fwin (linspace (-1, 1, windowsize));

#win = hanning (windowsize)';

## build index
ind = (bsxfun (@plus, 1:windowsize, (0:step:(rows(d)-windowsize))'))';
cols_ind = columns(ind);

## Only use left channel
left_seg = d(:,1)(ind);
clear d ind;

## Apply window
left_seg = bsxfun (@times, left_seg, win');

## FFT
fft_left_seg = fft (left_seg);
clear left_seg

#keyboard

## overwrite phases with random phases
fft_rand_phase_left = fft_left_seg.*exp(i*2*pi*rand(size(fft_left_seg)));
clear fft_left_seg;

ifft_left = ifft (fft_rand_phase_left);
clear fft_rand_phase_left;

## window again
ifft_left = bsxfun (@times, real(ifft_left), win');

## restore the windowed segments with half windowsize shift
restore_step = floor(windowsize/2);
ind2 = (bsxfun (@plus, 1:windowsize, (0:restore_step:(restore_step*(cols_ind-1)))'))';
left_stretched = sparse (ind2(:), repmat(1:columns (ind2), rows(ind2), 1)(:), real(ifft_left(:)), ind2(end, end), cols_ind);
clear ind2 ifft_left win;

left_stretched = full (sum (left_stretched, 2));

## normalize
left_stretched = 0.8 * left_stretched./max(left_stretched);
printf ("Output duration = %.2f s\n", rows (left_stretched)/fs);
wavwrite (left_stretched, fs, bps, "streched.wav");
system("aplay streched.wav")

这篇关于时间延长信号/将python代码移植到matlab/八度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆