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

Status
Not open for further replies.

#### Draculaardi

##### Newbie level 4
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.

#### RBB

##### Full Member level 5
Have you tried the filter function?

Draculaardi

### Draculaardi

Points: 2

#### Draculaardi

##### Newbie level 4
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

#### RBB

##### Full Member level 5
Why don't you paste the section of code, that calls the filter function.

Draculaardi

### Draculaardi

Points: 2

#### Draculaardi

##### Newbie level 4
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.

#### RBB

##### Full Member level 5
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);

Draculaardi

### Draculaardi

Points: 2

#### Draculaardi

##### Newbie level 4
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);

#### RBB

##### Full Member level 5
That's looks right.

Draculaardi

### Draculaardi

Points: 2

#### Draculaardi

##### Newbie level 4
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.

#### Scrts

##### Member level 3
firstly try only spectrogram(x), then check other options if needed.

#### Draculaardi

##### Newbie level 4
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.

Last edited:

#### RBB

##### Full Member level 5
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

Status
Not open for further replies.