How to find cutoff frequency (wc) using second order low pass filter and 3rd order low pass filter.

조회 수: 38 (최근 30일)
function [ filtered_result_data ] = PT2_Filter( data_need_to_be_filtered, wc, k, samplingtime )
filtered_result_data(1) = data_need_to_be_filtered (1);
filtered_result_data(2) = data_need_to_be_filtered (2);
b0 = wc^2 *samplingtime^2; %* 0.0001^2;
a0 = b0 + 4 * k * wc *samplingtime + 4; %* 0.0001 + 4;
a1 = 2 * b0 - 8;
a2 = b0 - 4 * k * wc *samplingtime + 4; %* 0.0001 + 4;
for i = 3:length(data_need_to_be_filtered)
filtered_result_data(i) = 1/a0 * ( b0 *( data_need_to_be_filtered(i)...
+ 2*data_need_to_be_filtered(i-1)+data_need_to_be_filtered(i-2) ) ...
- a1 * filtered_result_data(i-1) -a2 * filtered_result_data(i-2));
end
I am using this 2nd order low pass filter to filter the data in Matlab app. for that I need to write angular cutoff frequency(wc rad/s) and damping factor(k) and sampling time (from txt file) and it uses cutoff frequency(Hz) to filter the data. For example, right now i am using wc=608rad/s k = 0.707 and calculated frequncy I got cutoff frequency(fc) around 96 Hz (using formula wc=2*pi*fc). but I want to do reverse procedure like If I use dropdown menu and put some cutoff frequency like 50 Hz, 70 Hz etc. By selecting specific cutoff frequency what will I get angular cutoff frequency(wc) in matlab workspace or textbox of matlab app? Also, Code for, if we use 3rd order low pass filter to filter the data and find wc using 3rd order low pas filter. if anyone know how to write code for both filter, it would be very helpful.

채택된 답변

Rahul
Rahul 2023년 7월 13일
You can get the angular cutoff frequency using desired cutoff frequency by using the below given formula
% fc = 50 is taken as an example
fc = 50;
wc = 2 * pi * fc;
disp(['Angular Cutoff Frequency (wc): ' num2str(wc) ' rad/s']);
If you are using MATLAB app designer for aking your app, then you can add a textbox for fc and add these functions to the app itself with the callback of a button maybe. In the callback function the value of the textbox can be taken for fc value.
Furthur, to find wc using the 3rd order low pass filter, you can use the following code:
fc = 50;
wc = 2 * pi * fc;
b0 = wc^3 * samplingtime^3;
a0 = b0 + 6 * k * wc * samplingtime^2 + 12 * wc^2 * samplingtime + 8;
a1 = 3 * b0 - 24 * wc^2 * samplingtime^2 - 24;
a2 = 3 * b0 + 24 * wc^2 * samplingtime^2 - 24 * k * wc * samplingtime;
a3 = b0 - 6 * k * wc * samplingtime^2 + 12 * wc^2 * samplingtime - 8;
frequencies = linspace(0, fs/2, 1000); % Frequency range to evaluate
H = abs(b0 * exp(-1i*wc*samplingtime) ./ (a0 - a1*exp(-1i*wc*samplingtime) - a2*exp(-2i*wc*samplingtime) - a3*exp(-3i*wc*samplingtime)));
[~, index] = min(abs(H - 0.707));
wc_after_filter = frequencies(index) * 2 * pi;
% Angular cutoff frequency after passing through the filter
disp(['Angular Cutoff Frequency (wc) after filter: ' num2str(wc_after_filter) ' rad/s']);
Hope this helps.
Thanks.
  댓글 수: 1
Dhaval
Dhaval 2023년 7월 14일
편집: Dhaval 2023년 7월 14일
Hi Rahul,
Thank you so much for the answer. But I have few question,
  1. For sampling time, I can use this: Sampling time = evalin('base','samplingtime') it will read from file automatically and put it in the code. Am I right?
  2. Damping factor 0.707 is same for both 2nd order and 3rd order low pass filter?
  3. I can use the code for 2nd order lpf after removing a3 part from 3rd order LPF or there is another code for it.
  4. Actually I want to more frequencies like 50 to 200 Hz in 20 steps and I am using dropdown menu for it. So, If I chose any specific frequency from menu then it will give me wc value for specific frequency in th text field in MATLAB app. Am I right?

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by