% Simple one-notch phaser example in Matlab
%
% by Gary Scavone, McGill University.

fs = 44100;     % sample rate
Ts = 1 / fs;    % sample period
dur = 2.0;      % total sound duration
N = dur * fs;   % duration in samples

% Notch frequency parameters
fc1 = 5000;     % notch center frequency
Q = 2;          % "resonance" Q
r = exp(-pi*fc1*Ts/Q);  % corresponding pole radius

% Create an input noise signal
x = 2*rand(1, N) - 1.0;

% Create an LFO signal
f0 = 2;            % LFO frequency
deltafc = 0.2;     % LFO modulation depth
lfo = sin(2*pi*f0*Ts*(0:N-1));
modfc1 = fc1 + fc1*deltafc*lfo;

y = zeros(1, N);   % output sound vector
zi = zeros(1, 2);  % filter function state vector
a2 = r^2;
for n = 1:N
  a1 = -2*r*cos(2*pi*modfc1(n)*Ts);
  [tmp, zi] = filter([a2 a1 1], [1 a1 a2], x(n), zi);
  y(n) = 0.3*x(n) + tmp;
end

soundsc(y, fs);
spectrogram( y, 1024, 512, 1024, fs, 'yaxis' )