Error in using fir1() function

조회 수: 5 (최근 30일)
Arnab Ray
Arnab Ray 2012년 4월 4일
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.

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by