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 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