I'm trying to make sure I understand my (digital) signal processing knowledge, by realizing a time-discrete version of a 1st order RC filter. (The background is that I'm trying to implement a PLL in software for SDR purposes, but this is a different story...)
My problem is that I thought I understood how to create the difference equation for such a filter, and therefore derive its coefficients. However when I plot the response in MATLAB using the freqz function - with the calculated a
and b
coefficients - I don't get what looks like an RC filter response.
I referenced the Wikipedia page on this topic (at http://en.wikipedia.org/wiki/Low-pass_filter#Discrete-time_realization), just to make sure I wasn't totally off in the weeds, but it still doesn't help. This details the difference equation as:
yi = alpha * xi + ( 1 - alpha ) * yi-1
where: alpha = sample period / ( RC + sample period )
An example:
fs = 96000.0; % Sample rate.
delta_t = 1.0 / fs; % Sample period.
fc = 5000.0; % Filter cut off frequency.
tau = 1 / ( 2 * pi * fc ); % Time constant of filter.
alpha = delta_t / ( tau + delta_t ); % Smoothing factor per Wikipedia page.
b = [ alpha ]; % 'b' coefficients
a = [ 1.0, ( 1 - alpha ) ]; % 'a' coefficents
freqz( b, a, 1024, fs ); % 1024 point FFT used.
The result:
Any thoughts as to where I'm going wrong? Have I totally misunderstood something?
Thanks in advance.