How to find cutoff frequency (wc) using second order low pass filter and 3rd order low pass filter.
24 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Rahul
on 13 Jul 2023
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.
More Answers (0)
See Also
Categories
Find more on Single-Rate Filters in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!