i want to filter a frequeny... ?
古いコメントを表示
Hi all,
I write because I'm trying to do filtering in maltab.
in the code below I have a signal which is composed of two sinus of frequencies 0.3Hz and 2Hz.
I'd like to do is filter the sinus 2Hz the code below does not kidnapped this signal's component ...
you know where it comes from?
clear all;close all;clc;
%%original
t = 0:0.01:10;
y = sin(2*pi*0.3*t)+sin(2*pi*2*t);
%%filter
fs = 1000;
fcoupure = 2*[1 3]/fs;
[b]=fir1(1,fcoupure,'stop');
yfilter=filter(b,1,y);
figure (1);hold on;plot(t,y);plot(t,yfilter,'r');
%%butterworth
fs = 1000;
fcoupure = 2*[1 3]/fs;
[b,a]=butter(1,fcoupure,'stop');
yfilter=filter(b,a,y);
figure (2);hold on;plot(t,y);plot(t,yfilter,'r');
採用された回答
その他の回答 (2 件)
Honglei Chen
2012 年 10 月 3 日
編集済み: Honglei Chen
2012 年 10 月 3 日
There are several issues in your code
- your sample rate is 100Hz, not 1000Hz as you claimed
- you specified a filter order of 1, which may be difficult to achieve what you want to do
- your desired frequency is within a few Hz and you are sampling it at 100Hz, you could do what you want with a much lower sample rate, say 10Hz.
Taking Butterworth as example, you should first use buttord to derive the filter order and then pass the order to butter to design the filter
Here is an example using Butterworth with a sample rate of 10Hz
%%original
t = 0:0.1:10;
y = sin(2*pi*0.3*t)+sin(2*pi*2*t);
%%butterworth
fs = 10;
fcoupure = 2*[1 3]/fs;
[N,Wn] = buttord(2*[0.5 3.5]/fs,fcoupure,0.1,3);
[b,a]=butter(N,Wn,'stop');
yfilter=filter(b,a,y);
figure (2);hold on;plot(t,y);plot(t,yfilter,'r');
カテゴリ
ヘルプ センター および File Exchange で Filter Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!