From: Wayne King on
ALittleDog <leqia.he(a)gmail.com> wrote in message <5dc2e652-55ad-4872-bbd3-ec474821ba2b(a)15g2000yqi.googlegroups.com>...
> I want to apply an analog filter, which is specified by coefficient
> vectors b and a, and a FIR filter, Hd, with numerator coefficients, b
> and block length, len already known, to a stream of discrete-time
> data.
> What are the Matlab functions I can apply for the analog and FIR
> filters, respectively?
> Thanks!

Are you working the Matlab command window, or are you talking about a Simullink model? I'm just a little uncertain of how you are using the terms, analog, block length, and stream in your post.

Is Hd a dfilt object? If you enter

class(Hd)

do you get something starting with dfilt. ?

Assuming that you are working in the Matlab command window, you can just use filter() either with your numerator and denominator coefficient vectors

y = filter(b,a,data);

or with the dfilt object, Hd

y = filter(Hd,data);

Wayne
From: Wayne King on
ALittleDog <leqia.he(a)gmail.com> wrote in message <4d676cb6-b74e-4020-886f-f76870f76025(a)19g2000yqu.googlegroups.com>...
> In detail, I got the following information for the FIR filter:
> % Coefficient Format: Decimal
>
> % Discrete-Time FIR Filter (real)
> % -------------------------------
> % Filter Structure : Direct-Form FIR
> % Filter Length : 291
> % Stable : Yes
> % Linear Phase : Yes (Type 1)
> % Arithmetic : fixed
> % Numerator : s24,23 -> [-1 1)
> % Input : s24,23 -> [-1 1)
> % Filter Internals : Specify Precision
> % Output : s24,23 -> [-1 1)
> % Product : s48,46 -> [-2 2)
> % Accumulator : s32,31 -> [-1 1)
> % Round Mode : convergent
> % Overflow Mode : wrap
>
> followed by a list of 291 numerators. Could you please tell me what
> are the function to implement and apply this filter?

I see now by your posting, that you do have a dfilt object. You hadn't posted this when I wrote back the first time. See my other post. You can use filter with your dfilt object. If you want to use filtfilt() to implement zerophase filtering, you will need to extract the coefficients from your object, Hd. Since you have an FIR filter, that will be straightforward.

y = filtfilt(Hd.Numerator,1,data);
From: ALittleDog on
Thank you for your reply!
y = filtfilt(Hd.Numerator,1,data) does work.
Is it correct that you mean Hd.Numerator the vector of the 291
numerators. No other functions are needed, like Hd =
dfilt.fftfir(FIR_coefs,len).
From: Wayne King on
ALittleDog <leqia.he(a)gmail.com> wrote in message <7d24fdef-b341-44b6-a63c-07ccc1469fca(a)r1g2000yqj.googlegroups.com>...
> Thank you for your reply!
> y = filtfilt(Hd.Numerator,1,data) does work.
> Is it correct that you mean Hd.Numerator the vector of the 291
> numerators. No other functions are needed, like Hd =
> dfilt.fftfir(FIR_coefs,len).

If you already have a filter object, then you can just use it as

y = filtfilt(Hd.Numerator,1,data);

Again, if you don't need zerophase filtering, you can just invoke the filter method with the object

y = filter(Hd,x);

If you have your FIR filter as a vector of coefficients, let's say you created your filter using firpm(), and you want to create a discrete-time overlap-add filter object, then you can do that with:

Hd = dfilt.fftfir(FIR_coefs,len);

Hope that helps,
Wayne
From: ALittleDog on
I apply an analog filter to a stream of time signals. When I look at
its frequency response, the magnitude is always less than 1. But the
results become unstable.I am wondering where the problem could be. The
code of the characteristics of the filter is attached. The data is a
rand(1000,1) time data.
When I looked at the max(y), it is infinite. I have also applied the
filter to a stream of real data with the sampling frequency = 1000 Hz.
And the result also explodes. I am really confused.

NatFreq = 100;
Damping = 0.7;
Q = 1/(2*Damping);
L = 1;
R = (2*pi*L*NatFreq)/Q;
C = 1/((2*pi*NatFreq)^2 * L);
% 1/LC
% H = -------------------
% s2 + s R/L + 1/LC
% Get response from poles and zeros
K = [1.01];
B = [0 0 K/L/C];
A = [1 R/L 1/L/C];
Freq = logspace(-1,4);
freqs(B, A, 2*pi*Freq)

x = rand(1000,1);
y = filter(B, A, x);
max(x)
max(y)