How do I filter a signal, using FIR filters.

2 ビュー (過去 30 日間)
Peter Cristian
Peter Cristian 2022 年 3 月 26 日
編集済み: Scott MacKenzie 2022 年 3 月 26 日
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 Center および File ExchangeDigital Filter Analysis についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by