How can I determine b and a values for a data signal when using filter() function
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hello,
How do I determine the suitable b and a values when using filter function to filter a data signal?
채택된 답변
Star Strider
2020년 5월 10일
Use any of the filter design functions that produce transfer function output.
However the transfer function coefficients can create unstable filters. It is always best to have the filter functions create zero-pole-gain (z,p,k) representations rather than transfer function representations, then use the zp2sos function to convert them to second-order-section representation to produce robust, stable filters. The filtfilt function can use them, as well as digital filter objects (such as thouse produced by lowpass, bandpass, and similar functions) to filter signals.
댓글 수: 14
for filtfilt function (also for filter funtion), the definition needs transfer functions, right?
For a given data signal(I only have is the data), can you please tell what steps I should follow to get these coefficients?
For filtfilt, not necessarily. The filtfilt function can use transfer function vectors, second-order-section representations, or digital filter objects. It is extremely versatile.
Here is an example of code to design an elliptic bandpass filter that I did recentlly to filter an electrocardigram signal to illustrate the procedure:
Fs = 1000; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = [ 5 40]/Fn; % Normalised Passband (Passband = 5 Hz To 40 Hz)
Ws = [ 2 45]/Fn; % Normalised Stopband (Passband = 2 Hz To 45 Hz)
Rp = 1; % Passband Ripple/Attenuation
Rs = 50; % Stopband Ripple/Attenuation
[n,Wp] = ellipord(Wp, Ws, Rp, Rs); % Calculate Elliptic Filter Optimum Order
[z,p,k] = ellip(n, Rp, Rs, Wp,'bandpass'); % Elliptic Filter
[sos,g] = zp2sos(z,p,k); % Second-Order-Section For Stability
EKG = filtfilt(sos, g, EKG); % Filtered EKG
The filter passband and stopband frequencies must be between 0 Hz and the Nyquist frequency (although not equal to either one). All filter design code (regardless of the design you choose) follows these same essential steps. Only the functions change, and those depend on the filter you want to design (elliptic, Butterworth, Chebyshev, and other IIR filters). This creates a stable, robust filter. (The only filter this does not apply to is the Bessel filter, since it does not have a digital filter rperesentation.)
I can help you with FIR filters as well if you want to use them, however that is a different (and more complicated) discussion.
There are also other ways to design filters, such as designfilt (introduced in R2014a). The documentation for digitalFilter explores options for designfilt. I encourage you to explore them as well.
Another question, is it ok to decide these b and a coefficients by trial and error to get a better fit for the input signal?
Thank you very much. I'll go through those 2 links you mentioned. As a person with a very primary knowledge about these things, I was thinking if trial and error to get such b and a coefficients is ok too.
Yes!
Trial and error is an important part of signal processing, since even the best initial design does not always produce the desired result (at least in the filters I design). Even though my filter code usually runs correctly when I first try it (using the design steps I described in my previous Comment), the filter does not always do what I want it to, and needs to be changed slightly.
Thank you very much. You were very helpful!
I'll try everything you mentioned. :D
As always, my pleasure!
What I wrote is a guide, not a definitive solution for all problems, although it should get you most of the way to the filter design and implementation that give you the result you want. (The lowpass function and its friends are also helpful, although I did not mention them because you have already discovered them.)
But designing a lowpass filter like that using filtfilt() or filter() is the same as using lowpass() in Matlab. Am I right?
Essentially, yes. The lowpass, bandpass, and related functions design different types of filters, depending on the function and requirements. They design both FIR and IIR filters. You can examine the filters the function creates by requesting the second (digital filter) output, and then right-clicking on it (or displaying it separately, as you would other variables). Everything you need to know about it is there. You can also use the digital filter object to filter other signals (using the same filter specifications) with filtfilt.
Thanks again!!! :D
As always, my pleasure!
One thing I forgot to mention is that when you are designing your own filters, it is best to always use the freqz function to be certain that the filter is doing what you want it to.
I will do so. I'll read about it a bit more and try designing. I really appreciate your help.
As always, my pleasure!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Digital Filter Design에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
