help-octave
[Top][All Lists]

## Re: Filter Implementation

 From: Doug Stewart Subject: Re: Filter Implementation Date: Mon, 3 Jul 2017 19:20:46 -0400

On Mon, Jul 3, 2017 at 7:09 PM, Doug Stewart wrote:

On Mon, Jul 3, 2017 at 4:39 PM, shall689 wrote:
Hello,

I have been struggling with trying to implement a low pass filter in excel
using filter coefficients generated from octave (see m file text below). The
coefficients are
b0 = 0.0074833989
b1 = 0.0074833989
a1 = -0.9850332

The excel file is computing the equation:y[n] = b0*x[n] + b1*x[n-1] +
a1*y[n-1]
and filtering the signal: y=2048*sin(2*pi*10000*t)

Excel computes a filtered sinewave having a peak value of 15.6 without any
phase shift.

I expected a sinewave with a peak value of 123 with a -89 phase shift.

Is the above equation correct?  Is there some special I have to do?

Thanks,
Stephen

m file
------
format long
fc = 600;
SampleRate = 250000
fin = 10000;
Tc = 1/(2*pi*fc);
s = tf ('s');
sysC = 1/(1+s*Tc) % continuous transfer functions
sysD = c2d (sysC, 1/SampleRate, 'tustin') % discrete transfer function
[b,a] = tfdata(sysD,'v') % extract the coefficents
InputSignalLengthInSeconds = 10/fin;   % input signal length in seconds
t =linspace(0,InputSignalLengthInSeconds,InputSignalLengthInSeconds*250000);
wt = 2*pi*t*fin;
y=2048*sin(wt);
plot(t,y);
hold on;
y2 = filter(b,a,y);
plot(t,y2);
%print ("FilteredSignal.jpg")
%bode(sysC);

I am working on it give my 20 min.

--
DAS

ok there must be something wrong in what you are doing in excel

figure(1) at the top of you M file and
this at the end of you M file.

t=0:0.001/1000:0.001;
x=2048*sin(2*pi*10000*t);
y(1) = b(1)*x(1)
for n=2:1001
y(n) = b(1)*x(n) + b(2)*x(n-1) + a(1)*y(n-1);
endfor

figure(2)
plot(t,x,t,y)

using this I see the phase shift etc.