Error in using fir1() function

18 views (last 30 days)
Arnab Ray
Arnab Ray on 4 Apr 2012
I have written the following code for an FIR filter design.
clc;
close all;
clear all;
fp=input('enter the pass band frequency:');
fs=input('enter the stop band frequency:');
rp=input('enter the pass band attenuation:');
rs=input('enter the stop band attenuation:');
f=input('enter the sampling frequency:');
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n=abs(n);
wp=-2*fp/f;
ws=-2*fs/f;
wn=(ws+wp)/2;
if(rem(n,2)==0)
m=n+1;
else
m=n;
n=n-1;
end
w=hann(m);
b=fir1(n,wn,w);
freqz(b,1,500,3000);
title('magnitude and phase response');
During execution, the following values for the input are provided:
enter the pass band frequency:1000
enter the stop band frequency:1200
enter the pass band attenuation:0.2
enter the stop band attenuation:45
enter the sampling frequency:3000
The error displayed after entering the values is:
??? Error using ==> fir1 at 77 Frequencies must fall in range between 0 and 1.
Error in ==> hanning1 at 35 b=fir1(n,wn,w);
Please help in resolving the error.

Accepted Answer

Wayne King
Wayne King on 4 Apr 2012
Why are you putting - signs on these:
wp=-2*fp/f;
ws=-2*fs/f;
Take out the - signs.
  1 Comment
Arnab Ray
Arnab Ray on 4 Apr 2012
Thank you for solving. The problem has been resolved.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!