help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lsim problem


From: Blake, James
Subject: lsim problem
Date: Thu, 29 Jul 2010 17:14:42 +0100

Hi,

I've been having some problems using lsim, and wonder whether the behaviour I'm 
seeing is (most probably) correct and I'm making a mistake, or perhaps a bug. 
I'm trying to model a signal so that I can move my filter to an embedded system 
sampling at 10 Hz, but started out using a signal sampled at a higher rate to 
try to get started.

Using the following code I would expect the lsim simulation of the filter 10 Hz 
sampled signal to match the 2 kHz signal (or indeed using an arbitrary sample 
rate). I don't have the control systems toolbox for Matlab, so can't test the 
lsim behaviour there, but I also use the scipy module for python, and indeed, 
lsim for the 10 Hz signal produces the same output as lsim for the 2 kHz signal.

Apologies if I'm doing something glaringly obvious,

Many thanks,

James

=================================

% synthesise triangle wave with pulse on top of it
fs = 2000;
t0 = 1/fs:1/fs:60;
ramp = 2.7-20e-3*t0;
pulse = 5e-3*sin(72/60*2*pi*t0);
p0 = ramp+pulse;
% downsample from 2kHz to 10Hz...
t1 = 0.1:0.1:t0(end);
p1 = interp1(t0,p0,t1);

% transfer function of 1st order Butterworth HPF with 10Hz cutoff...
[b,a] = butter (1, 1.6*2*pi, 'high', 's');
g = tf (b,a,0);
% apply transfer function of Butterworth HPF...
[R0, X] = lsim (g, p0', t0');
R0 = 200 .* R0;
R0 = R0 + 1.65;
[R1, X] = lsim (g, p1', t1');
R1 = 200 .* R1;
R1 = R1 + 1.65;

% using conventional digital filter, fs=10 Hz
[b0,a0] = butter(1,1.6/(fs/2),'high');
[b1,a1] = butter(1,1.6/(10/2),'high');
Rd0 = 200*filter(b0,a0,p0) + 1.65;
Rd1 = 200*filter(b1,a1,p1) + 1.65;

% plot them
figure;
plot(t0,R0,t1,R1,t0,Rd0,t1,Rd1)
axis([10,20,0,3])
legend('lsim XXX Hz','lsim 10 Hz','filter XXX Hz','filter 10 Hz')




reply via email to

[Prev in Thread] Current Thread [Next in Thread]