# Matlab FIR and IIR (little help with simple task)

1. ## Matlab FIR and IIR (little help with simple task)

I am total beginner using Matlab so I need some help creating FIR and IIR filters with Mathlab.

and I should filter it with FIR, which have these factors: [-0.04, 0.1, 0.3, 0.4, 0.3, 0.1, -0.04]

I must also filter it with IIR, which have factors b=[0.2939 0.2939], a=[1 -0.4231]

I tried google right commands and actually found something. Problem is that no matter how much I tried commands didnt work.

2. ## Re: Matlab FIR and IIR (little help with simple task)

Have you tried the filter function?

1 members found this post helpful.

•

3. ## Re: Matlab FIR and IIR (little help with simple task)

Originally Posted by RBB
Have you tried the filter function?
Actually I tried it, but seems like it only filtered only 7 first samples and then erased everything after that. Of course it's possible that I made some mistake when I tried it. Like I said I am beginner with Matlab

4. ## Re: Matlab FIR and IIR (little help with simple task)

Why don't you paste the section of code, that calls the filter function.

1 members found this post helpful.

5. ## Re: Matlab FIR and IIR (little help with simple task)

Originally Posted by RBB
Why don't you paste the section of code, that calls the filter function.
Because I dont have it anymore. I tried it yesterday and because it totally failed I didnt save it.

•

6. ## Re: Matlab FIR and IIR (little help with simple task)

It should only be a couple lines long...

B = [-0.04, 0.1, 0.3, 0.4, 0.3, 0.1, -0.04];
y = filter(B, 1, x);

1 members found this post helpful.

7. ## Re: Matlab FIR and IIR (little help with simple task)

Originally Posted by RBB
It should only be a couple lines long...

B = [-0.04, 0.1, 0.3, 0.4, 0.3, 0.1, -0.04];
y = filter(B, 1, x);
Thanks, that really helped.

So IIR-filter would go like this?
a=[1 -0.4241]
b=[0.2929 0.2929]
y = filter(b, a, x);

8. ## Re: Matlab FIR and IIR (little help with simple task)

That's looks right.

1 members found this post helpful.

9. ## Re: Matlab FIR and IIR (little help with simple task)

Errmm.. It seems like I must also make spectrograms from signals.

Command goes like this:
S=spectrogram(x,window,noverlap,nfft,fs).
So x is signal, window = ?, noverlap=?, nfft=? and fs=44100.

I know that these are explained in here, but I don't really understand without good example.

•

10. ## Re: Matlab FIR and IIR (little help with simple task)

firstly try only spectrogram(x), then check other options if needed.

11. ## Re: Matlab FIR and IIR (little help with simple task)

Originally Posted by Scrts
firstly try only spectrogram(x), then check other options if needed.
It's only say: "??? Error using ==> spectrogram at 113
X must be a vector (either row or column)."

Edit: Oookey.. Audiofile must be mono not stereo or spectrogram doesn't work.

12. ## Re: Matlab FIR and IIR (little help with simple task)

You can access just a single vector in the array via...
x(1,:) x(2,:)
or
x(:,1) x(:,2)
depending on the array size

--[[ ]]--