第一天的课程感觉比較简单,主要介绍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. ScrollView属性fillViewport解决android布局不能撑满全屏的问题

    转:http://blog.sina.com.cn/s/blog_6cf2ea6a0102v61f.html 开发项目中遇到一个问题,布局高度在某些国产酷派小屏幕手机上高度不够全部显示,于是使用了Sc ...

  2. 软件测试学习日志————round 1 some questions of two small programs

    Below are four faulty programs. Each includes a test case that results in failure. Answer the follow ...

  3. J2SE知识点摘记(十八)

    Java容器类类库的用途是“保存对象”,并将其划分为两个不同的概念: 1)  Collection . 一组对立的元素,通常这些元素都服从某种规则.List必须保持元素特定的顺序,而Set 不能有重复 ...

  4. Umbraco安装权限问题

    当安装或升级,甚至是使用Umbraco时,如果出现一些莫名其妙的问题. 估计都是权限出了问题,用心参考下文: https://our.umbraco.org/documentation/Getting ...

  5. Silverlight Socket 实现收发信息

    原文 http://www.cnblogs.com/ZetaChow/archive/2009/05/16/2237347.html 刚接触Silverlight的时候,除了其异步应用WCF.流媒体. ...

  6. elk之nginx

    elk之nginx: ignore_older => 86400,不处理一天以前的文件. zjtest7-frontend:/usr/local/logstash-2.3.4/config# c ...

  7. hdu 4598 Difference(奇圈判定+差分约束)

    这是通化邀请赛的题,当时比赛的时候还完全没想法呢,看来这几个月的训练还是有效果的... 题意要求(1) |ai| < T for all i   (2) (vi, vj) in E <=& ...

  8. 解析微信node开发;拿token

    获取token,本着两个原则, 1.先查询是否有token,有的话判断其时间是否与上一次请求时间差是否超过7100: a.不超过,直接用得到: b.超过,再获取刷新: 2.没有token获取刷新tok ...

  9. jquery判断移动设备代码片段;pc、iphone、安卓

    $(document).ready(function () { /* 判断设备*/ var browser={ versions:function(){ var u = navigator.userA ...

  10. 小Y的难题

    Font Size:Aa Aa Aa Description 近期小Y迷上了数学,总是在思考各种数学问题.有一天,他不小心把墨水洒在草稿纸上.他如今能看到的是"2?3?1?4"(? ...