Clear Filters
Clear Filters

Designing Yulewalk Filter for a Bandpass Type

1 view (last 30 days)
I am currently analysing an sEMG data that needs to be filtered from the noise. Previously, I have been using Butterworth filter to make a bandpass type filter. Here is the code I wrote to design the Butterworth filter:
%% Butterworth filter design
fs = 10240;%sampling rate
fnyq = fs/2; %Nyquist frequency
flow = 20; %lowpass frequency
fhigh = 450; %highpass frequency
n_order = 10; %order of filter
[z,p,k]=butter(n_order,[flow fhigh]/(fnyq),'bandpass');
sos=zp2sos(z,p,k);
fvtool(sos,'FrequencyScale','log')
Now I want to generate a Yulewalk filter with the same parameters, with the code below:
%% Yulewalk Filter
fs = 10240;
fnyq = fs/2;
% Define the desired filter order
order = 10;
% Define the passband and stopband cutoff frequencies
bandpass = [20 450]; % Lower and upper cutoff frequencies for the passband
% Define the frequency bands and desired response
freqs = [0 bandpass(1)/fnyq bandpass(2)/fnyq 1];
response = [0 1 1 0];
% Design the bandpass filter using yulewalk
[b,a] = yulewalk(order, freqs, response);
fvtool(b,a,'FrequencyScale','log')
Somehow, when I analyze the frequency scale log, it doesn't have the same result.
Is there anything I could have missed?

Answers (1)

Star Strider
Star Strider on 12 Jun 2024
The yulewalk filter will be a FIR filter, whiel the original filter is an IIR filter. A FIR filter generally requires a much higher order than an IIR filter for the same result. For example, the kaiserord function calculates an order of 5715 for a similar filter, likely too long for your signal.
Example —
%% Yulewalk Filter
fs = 10240;
fnyq = fs/2;
% Define the desired filter order
order = 10;
% Define the passband and stopband cutoff frequencies
bandpass = [20 450]; % Lower and upper cutoff frequencies for the passband
% Define the frequency bands and desired response
freqs = [0 bandpass(1)/fnyq bandpass(2)/fnyq 1];
bandwidth = 2;
freqs2 = [bandpass(1)+[-1 1]*bandwidth bandpass(2)+[-1 1]*bandwidth];
response = [0 1 1 0];
% Design the bandpass filter using yulewalk
[n,Wn,beta,ftype] = kaiserord(freqs2,[0 1 0],[0.05 0.01 0.05],fs)
n = 5715
Wn = 2x1
0.0039 0.0879
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
beta = 3.3953
ftype = 'DC-0'
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
[b,a] = yulewalk(order, freqs, response);
% fvtool(b,a,'FrequencyScale','log')
figure
freqz(hh,1,2^20,fs)
set(subplot(2,1,1), 'XLim',[0 5])
set(subplot(2,1,2), 'XLim',[0 5])
sgtitle('‘kaiserord’ & ‘fir1’')
figure
freqz(b,a,2^20,fs)
set(subplot(2,1,1), 'XLim',[0 5])
set(subplot(2,1,2), 'XLim',[0 5])
sgtitle('Yule-Walker (As Designed)')
Experiment with significantly higher filter orders, keeping in mind the length of the signal you are filtering. Use filtfilt to do the actual filtering.
.

Community Treasure Hunt

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

Start Hunting!