第一天的课程感觉比較简单,主要介绍Karplus-Strong Algorithm

给出方程
y[n]=αy[n−M]+x[n],

x[n]是输入,M是延迟,α是衰弱系数

我们要衰减D次,总的採样数就是D*M

以下是最直接的实现

关于x
= x(:).';的语法是这种,这是一个转置,可是是非共轭转置,假设是x',那么1+i就成了1-i

function y = ks_loop(x, alpha, D)

% Length of the output signal must be larger than the length of the input signal,
% that is, D must be larger than 1
if D < 1
error('Duration D must be greater than 1');
end % Make sure the input is a row-vector
x = x(:).'; % Number of input samples
M = length(x); % Number of output samples
size_y = D * M; % Initialize with random input x
y = zeros(1, size_y);
y(1:M) = x; for index = (M+1):size_y
y(index) = alpha * y(index - M);
end y = y(:); return

以下来測试一下

x = randn(100, 1);

stem(x);

y
= ks_loop(x, 0.9, 10);

stem(y);

事实上,你已经完毕了KS算法

要知道,在matlab和octave这种软件中,矩阵运算比单个运算速度要快非常多,于是就有了优化的版本号

function y = ks(x, alpha, D)

% Length of the output signal must be larger than the length of the input signal,
% that is, D must be larger than 1
if D < 1
error('Duration D must be greater than 1.');
end % Make sure the input is a row-vector
x = x(:).'; % Number of input samples
M = length(x); % number of output samples
size_y = D * M; % Create a vector of the powers of alpha, [alpha^0 alpha^1 ....]
size_alphaVector = D;
alphaVector = (alpha*ones(size_alphaVector,1)).^((0:(size_alphaVector-1))'); % Create a matrix with M columns, each being the vector of the powers of alpha
alphaMatrix = repmat(alphaVector, 1, M); % Create a matrix with D rows filled by the input signal x
xMatrix = repmat(x, D, 1); % Multipliy the two, and take the transpose so we can read it out
% column-by-column
yMatrix = (alphaMatrix .* xMatrix).'; % Read out the output column by columnn
y = yMatrix(:); return

在matlab中,你能够用soundsc(y, FS)来播放音乐

y是我们的採样数据,FS是频率

以下这个样例能够播放opening
chord of Hard day's night
开头的音乐,太奇妙了

由于牵扯到音乐的相关知识,一些參数就不大懂,仅仅画出了最后的採样图看看

clear all
close all
clc % Parameters:
%
% - Fs : sampling frequency
% - F0 : frequency of the notes forming chord
% - gain : gains of individual notes in the chord
% - duration : duration of the chord in second
% - alpha : attenuation in KS algorithm Fs = 48000; % D2, D3, F3, G3, F4, A4, C5, G5
F0 = 440*[2^-(31/12); 2^-(19/12); 2^-(16/12); 2^(-14/12); 2^-(4/12); 1; 2^(3/12); 2^(10/12)];
gain = [1.2 3.0 1.0 2.2 1.0 1.0 1.0 3.5];
duration = 4;
alpha = 0.9785; % Number of samples in the chord
nbsample_chord = Fs*duration; % This is used to correct alpha later, so that all the notes decay together
% (with the same decay rate)
first_duration = ceil(nbsample_chord / round(Fs/F0(1))); % Initialization
chord = zeros(nbsample_chord, 1); for i = 1:length(F0) % Get M and duration parameter
current_M = round(Fs/F0(i));
current_duration = ceil(nbsample_chord/current_M); % Correct current alpha so that all the notes decay together (with the
% same decay rate)
current_alpha = alpha^(first_duration/current_duration); % Let Paul's high D on the bass ring a bit longer
if i == 2
current_alpha = current_alpha^.8;
end % Generate input and output of KS algorithm
x = rand(current_M, 1);
y = ks(x, current_alpha, current_duration);
y = y(1:nbsample_chord); % Construct the chord by adding the generated note (with the
% appropriate gain)
chord = chord + gain(i) * y;
end % Play output
soundsc(chord, Fs);

数字信号处理Day1自制电子音乐的更多相关文章

  1. 音乐制作:用FL Studio做电子音乐

    电音制作,自然少不了适合做电音的软件,市面上可以进行电音制作的软件不少,可是如果在这些软件中只能选择一款的话,想必多数人会把票投给FL Studio,毕竟高效率是永远不变的真理,今天就让我们来看看如何 ...

  2. 数字信号处理--FFT与蝶形算法

    在数字信号处理中常常需要用到离散傅立叶变换(DFT),以获取信号的频域特征.尽管传统的DFT算法能够获取信号频域特征,但是算法计算量大,耗时长,不利于计算机实时对信号进行处理.因此至DFT被发现以来, ...

  3. 数字信号处理与音频处理(使用Audition)

    前一阵子由于考博学习须要,看了<数字信号处理>,之前一直不清除这门课的理论在哪里应用比較广泛. 这次正巧用Audition处理了一段音频,猛然发现<数字信号处理>这门课还是很实 ...

  4. 数字信号处理MATLAB简单序列

    数字信号处理应用的几个基本序列: 1 单位样本序列 function mainImseq() clc clear disp('生成抽样序列'); y=imseq(,,); %调用样本函数,此时序列下标 ...

  5. FPGA与数字信号处理

    过去十几年,通信与多媒体技术的快速发展极大地扩展了数字信号处理(DSP)的应用范围.眼下正在发生的是,以更高的速度和更低的成本实现越来越复杂的算法,这是针对高级信息服更高带宽以及增强的多媒体处理能力等 ...

  6. 数字信号处理专题(3)——FFT运算初探

    一.前言 FFT运算是目前最常用的信号频谱分析算法.在本科学习数字信号处理这门课时一直在想:学这些东西有啥用?公式推来推去的,有实用价值么?到了研究生后期才知道,广义上的数字信号处理无处不在:手机等各 ...

  7. 数字信号处理专题(1)——DDS函数发生器环路Demo

    一.前言 会FPGA硬件描述语言.设计思想和接口协议,掌握些基本的算法是非常重要的,因此开设本专题探讨些基于AD DA数字信号处理系统的一些简单算法,在数字通信 信号分析与检测等领域都会或多或少有应用 ...

  8. 现代数字信号处理——AR模型

    1. AR模型概念观       AR模型是一种线性预测,即已知N个数据,可由模型推出第N点前面或后面的数据(设推出P点),所以其本质类似于插值,其目的都是为了增加有效数据,只是AR模型是由N点递推, ...

  9. 如何使用Matlab做数字信号处理的仿真1

    例如 第三版数字信号处理P51 -1.14习题时域离散信号的相关性研究x(n)=Asin(ωn)+u(n),其中ω=π/16,u(n)是白噪声,现要求 ⑴.产生均值为0,功率P=0.1的均匀分布白噪声 ...

随机推荐

  1. php的页面缓存练习

    <?php /* * 自定义页面缓存类 */ namespace page_cache; class Page { public $CacheRoot = "pageCache/&qu ...

  2. 关于Thinkphp3.2版本的分页问题

    最近公司官网改版,需要把旧的thinkphp版本换到现在最新的3.2去,因此,就开展了一系列的升级工作..在修改命名空间的同时,发现Page分页类能正常运行了,但是分页的链接却是错误的,例如在Admi ...

  3. @RenderSection

    @RenderSection在母版页中先占个位置,然后在使用该母版的页面中在各自去实现自己的Section. 在母版页_Layout.cshtml中使用格式为 @RenderSection(" ...

  4. 3000本IT书籍下载地址

    http://www.shouce.ren/post/d/id/112300    黑客攻防实战入门与提高.pdfhttp://www.shouce.ren/post/d/id/112299    黑 ...

  5. 电池和Adapter切换电路改进实验

    目的:很多单电池的机器在大负载的情况下,如把背光开到最亮,运行3D游戏,此时拔DC电源很容易出现机器死机,或花屏现象: 原因:Q5的导通时间不够,希望通过G极的快速放电,加快到导通时间: 修改前的电路 ...

  6. [原]容器学习(二):动手模拟AOP

    简单来说,Spring是一个轻量级的控制反转(IOC)和面向切面(AOP)的容器框架.上文已经介绍模拟IoC实现,这篇文章来动手模拟AOP. AOP简述 面向对象强调"一切皆是对象" ...

  7. poj1799---解析几何

    sin(a)=r/R-r,反三角asin(r/R-r),乘以2n=2pi,去化简,得到r 收获:define pi acos(-1) 这样pi的精度会高很多<math.h>(cos,sin ...

  8. 详解Spring中的CharacterEncodingFilter--forceEncoding为true在java代码中设置失效--html设置编码无效

    在项目中有很多让人头疼的问题,其中,编码问题位列其一,那么在Spring框架中是如何解决从页面传来的字符串的编码问题的呢?下面我们来看看Spring框架给我们提供过滤器CharacterEncodin ...

  9. python 【第三篇】:函数及参数

    函数背景 在学习函数之前,一直遵循:面向过程编程: 根据业务逻辑从上到下实现功能,其往往用一长段代码来实现指定功能,开发过程中最常见的操作就是粘贴复制,也就是将之前实现的代码块复制到现需功能处,如下: ...

  10. How many ways(记忆化搜索)

    How many ways Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...