FIR1 basic question
8 views (last 30 days)
Show older comments
Hello Please help in FIR1 filtering. I clearly mentioned in the code about what I want to do.
clear all
clc
fm=100; % signal freq
fs=800; % sampling feq
fn=2*fm; %Nyquist rate
t=0:1/fs:0.1;
X = 2*sin(2*pi*fm*t) ;
% Here I created 100 hz sine wave
% addes some noise to it
Y=X+randn(1,length(X));
figure
plot(t,X)
hold on
plot(t,Y,'r')
% I need to have passband of the signal
% between 80Hz to 120 Hz
% So normalized frequencies are
fw1=fm/fn-0.1; % 80 Hz
fw2=fm/fn+0.1; % 120 Hz
% Coefficents for fir filter within passband
b = fir1(12,[fw1 fw2]);
figure
freqz(b,1,128)
% I convolved filter coefficients with noised signal
Filt_out=conv(b,Y);
figure
plot(Filt_out)
% Filtered Signal output
But Iam not getting filtered output..Please help to get the filtered output.
1 Comment
Jan
on 2 Oct 2011
Please explain the problem with any details. Do you get an error or does the results differ from your expectations?
Please read this about "clear all": http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301
Accepted Answer
Wayne King
on 2 Oct 2011
Hi, One major problem that you have is that you do not define your normalized frequencies correctly. If you want a passband between [80, 120]
Then your normalized frequencies are:
fp1 = (2*80)/fs;
fp2 = (2*120)/fs;
b = fir1(12,[fp1 fp2]);
Filt_out = filter(b,1,Y);
plot(t,X)
hold on
plot(t,Y,'r')
I would recommend designing your filter with fdesign.bandpass unless you have some compelling reason to use fir1
0 Comments
More Answers (0)
See Also
Categories
Find more on Filter Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!