]> git.parisson.com Git - cnaq.git/commitdiff
Add noise tools
authoryomguy <yomguy@5fc3e0e6-29bc-4d03-b52b-c088cb822bde>
Fri, 21 Mar 2008 17:01:07 +0000 (17:01 +0000)
committeryomguy <yomguy@5fc3e0e6-29bc-4d03-b52b-c088cb822bde>
Fri, 21 Mar 2008 17:01:07 +0000 (17:01 +0000)
git-svn-id: http://svn.parisson.org/svn/CNAQ/trunk@153 5fc3e0e6-29bc-4d03-b52b-c088cb822bde

tools/pink_noise.m [new file with mode: 0644]
tools/white_noise.m [new file with mode: 0644]

diff --git a/tools/pink_noise.m b/tools/pink_noise.m
new file mode 100644 (file)
index 0000000..b739a97
--- /dev/null
@@ -0,0 +1,15 @@
+function s = pink_noise(n)
+
+% Generate a pink noise
+% n : number of samples to synthesize
+
+% Filter coefficients
+B = [0.049922035 -0.095993537 0.050612699 -0.004408786];
+A = [1 -2.494956002 2.017265875 -0.522189400];
+
+nT60 = round(log(1000)/(1-max(abs(roots(A))))); % T60 est.
+v = randn(1, n + nT60); % Gaussian white noise: N(0,1)
+s = filter(B, A, v);    % Apply 1/F roll-off to PSD
+s = 2*s(nT60+1:end);    % Skip transient response
+
+end
diff --git a/tools/white_noise.m b/tools/white_noise.m
new file mode 100644 (file)
index 0000000..65f5a3c
--- /dev/null
@@ -0,0 +1,8 @@
+function s = white_noise(n)
+
+% Generate a white noise
+% n : number of samples to synthesize
+
+s = 2*(rand(n,1)-0.5);
+
+end