i want to filter a frequeny... ?

3 次查看(过去 30 天)
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');

采纳的回答

21did21
21did21 2012-10-3
编辑:21did21 2012-10-3
thanks you for your answer !!
but, i am a beginner. can you explain this ?
1°) why we must have "fs = 10" ? because we have a total time of 10 ? (t(end)-t(1) ?
2°) i don't understand this line : "[N,Wn] = buttord(2*[0.5 3.5]/fs,2*[1 3]/fs,0.1,3);"
N ===> is the order of the filter 2*[1 3]/fs ===> is the range of frequencies that i want to cut 0.1 ===> maximal attenuation 3 ===> minimal attenuation
but, what is 2*[0.5 3.5]/fs ??? i don't understand how you choice this ?
why 0.5 and 3.5 ???
=> with you don't choice 0.3 3 for example ?
  2 个评论
Walter Roberson
Walter Roberson 2012-10-3
fs = 10 stands for a sampling frequency of 10 Hz, not for the total time.
Honglei Chen
Honglei Chen 2012-10-3
You don't have to use fs = 10. It's just for your question, fs = 10 is a good choice. fs = 100 would be a little high and make the filter design difficult
buttord estimates the order of a Butterworth filter. the first argument is passband and the second is stopband. I'm basically choosing the pass band to be between 0 and 0.5 and 3.5 to fs/2 and the stop band to be between 1 and 3 as you did. You could choose 0.3 and 3.2 if you want. This basically impacts the transition band which in turn could affect your filter order.

请先登录,再进行评论。

更多回答(2 个)

Honglei Chen
Honglei Chen 2012-10-3
编辑:Honglei Chen 2012-10-3
There are several issues in your code
  1. your sample rate is 100Hz, not 1000Hz as you claimed
  2. you specified a filter order of 1, which may be difficult to achieve what you want to do
  3. 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');

21did21
21did21 2012-10-4
thanks a lot !

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by