# State Variable Filter in DSP

Started by July 30, 2006
Dear all,

I am very new to DSP and I need to construct a High Pass, State Variable Filter. I have taken the filter strucuture from the following link:

http://www.earlevel.com/Digital%20Audio/StateVar.html

I have constructed the Filter in Simulink and it works fine. However I wish to model it as an m-file. I am having severe problems in devising the equation that will calculate the output samples. My code looks something like:

Fc 00;
Fs = 44100;
t = 0:1/Fs:.1-1/Fs;

%White noise
x=randn(size(t));

%Filter coefficients
k=2*sin(pi*Fc/Fs);

for n=4:(length(x));

y(n)=x(n)-(k*k*(x(n-1)+x(n-2)))-(k*k*(x(n-2)+x(n-3)))-(k*(x(n-1)+x(n-2)));

end

%The following visualises the 2 signals

X = fft(x,10000);
X=X(1:5000);
XMags(X);
XdB *log10(XMag/max(XMag));
freq=(0:4999)*Fs/10000;
subplot(2,1,1), plot(freq, XdB);
% Graph labelling
title('Spectrum of the input signal x[n]')
ylabel('Magnitude (dB)'), grid on;
xlabel('Frequency (Hz)');
set(gca,'xlim',[0 20000],'ylim',[-50 0])

Y = fft(y,10000);
Y=Y(1:5000);
YMags(Y);
YdB *log10(YMag/max(YMag));
freq=(0:4999)*Fs/10000;
subplot(2,1,2), plot(freq, YdB);
title('Spectrum of the output signal y[n]')
ylabel('Magnitude (dB)'), grid on;
xlabel('Frequency (Hz)');
set(gca,'xlim',[0 20000],'ylim',[-50 0]);
I cannot get it to work at all, since I dont have a mathematical background im a struggling in constructing the y(n) expression. Can you help me.

Thanks