www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/IIRFilterForPinkNoiseGenerationExample.m
%% IIR Filter for Pink Noise Generation % This example shows how to form the IIR filter for pink noise generation % used in |dsp.ColoredNoise|. %% % Set the exponent for the power spectral density ${1}/{|f|^{\alpha}}$ % equal to 1 for pink noise, ${1}/{|f|}$. Obtain the coefficients for % the all-pole filter. % Copyright 2015 The MathWorks, Inc. alpha = 1; den = zeros(1, 64); den(1) = 1; for idx = 2:64 den(idx) = (idx - 2 - alpha/2) * den(idx-1) / (idx-1); end %% % Obtain the transfer function of the all-pole filter and measure the slope % in dB/octave. [H,W] = freqz(1,den); freqvec = log2(W(2:end)); SF = 20*log10(abs(H(2:end))); X = ones(length(SF),2); X(:,2) = freqvec; lsest = X\SF %% % The slope is -2.72 dB/octave, which is very close to the expected value % of -3 dB/octave for pink noise. Plot the transfer function in dB against % the logarithm of the radian frequency to the base 2. plot(log2(W(2:end)),SF,'linewidth',2); xlabel('log_2(\omega)'); ylabel('dB'); grid on; title('Transfer Function of Pink Noise Filter'); %% % Replace the value for |alpha| with any real number in the range [-2,2] to % obtain colored noise realizations with power spectral densities equal to % $1/|f|^{\alpha}$.