How do I filter a signal, using FIR filters.

2 次查看(过去 30 天)
I've got this code, what filter, and how should i use it to only show me in the end the component with the 300Hz frequency? Using a fir filter
```
t = 0:1/8000:1023/8000;
w = 0:8000/1024:4000;
x = 0.5*sin(2*pi*50*t) + 0.5*square(2*pi*130*t) + 0.3*sawtooth(2*pi*250*pi) + 0.2*sin(2*pi*300*t);
h =
y = filter(h,1,x);
figure;
subplot(2,1,1), plot(t,x);
z = abs(fft(x)) / 512;
subplot(2,1,2), plot(w, z(1:513));
figure;
subplot(2,1,1), plot(t,y);
z = abs(fft(y)) / 512;
subplot(2,1,2), plot(w, z(1:513));
```

采纳的回答

Scott MacKenzie
Scott MacKenzie 2022-3-26
You could perhaps use a butterworth bandpass filter: (Note: Requires Signal Processing Toolbox)
t = 0:1/8000:1023/8000;
w = 0:8000/1024:4000;
x = 0.5*sin(2*pi*50*t) + 0.5*square(2*pi*130*t) + 0.3*sawtooth(2*pi*250*pi) + 0.2*sin(2*pi*300*t);
% h =
% y = filter(h,1,x);
% create bandpass butterworth filter @ 300 Hz
fCutoff1 = 250;
fCutoff2 = 350;
[b, a] = butter(6, [fCutoff1 fCutoff2]/(8000/2), 'bandpass');
% filter the signal
y = filter(b, a, x);
figure;
subplot(2,1,1), plot(t,x);
z = abs(fft(x)) / 512;
subplot(2,1,2), plot(w, z(1:513));
figure;
subplot(2,1,1), plot(t,y);
z = abs(fft(y)) / 512;
subplot(2,1,2), plot(w, z(1:513));
  2 个评论
Peter Cristian
Peter Cristian 2022-3-26
Can i know why, or how did you know the order was 6?
Scott MacKenzie
Scott MacKenzie 2022-3-26
编辑:Scott MacKenzie 2022-3-26
I just used order six as it seemed to do a reasonable job in excluding neighboring frequencies. At order 3, for example, you get this:

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Digital Filter Analysis 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by