How do I filter a signal, using FIR filters.

2 Ansichten (letzte 30 Tage)
Peter Cristian
Peter Cristian am 26 Mär. 2022
Bearbeitet: Scott MacKenzie am 26 Mär. 2022
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));
```

Akzeptierte Antwort

Scott MacKenzie
Scott MacKenzie am 26 Mär. 2022
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 Kommentare
Peter Cristian
Peter Cristian am 26 Mär. 2022
Can i know why, or how did you know the order was 6?
Scott MacKenzie
Scott MacKenzie am 26 Mär. 2022
Bearbeitet: Scott MacKenzie am 26 Mär. 2022
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:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by