design filter to implement in microcontroller
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Eyal Sasson
am 16 Okt. 2022
Kommentiert: Star Strider
am 17 Okt. 2022
Hello :)
I want to design a filter that attenuate some frequencies and has minimun delay to the signal.
I'm building quacoopter controller, and I want to design a IIR or FIR filter to implement later in C code in the microcontroller.
is there some exaple or explanation on how could i desgin the filter and implement it in C code?
Thank you very much!
0 Kommentare
Akzeptierte Antwort
Star Strider
am 17 Okt. 2022
An IIR filter would be more efficient, and an elliptic filter the most efficient of those. The designfilt function may be the easiest way to create the filter you want, however it outputs a digitalFilter object that is a second-order-section implementation of the filter, not a transfer function, so it would then require the sos2tf function.
Since you want a transfer function, another way to design the filter using command-line functions would be something like this —
Fs = 1000; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = 100/Fn; % Passband Frequency (Normalised)
Ws = 110/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (Attenuation)
Rs = 60; % Stopband Ripple (Attenuation)
[n,Wn] = ellipord(Wp,Ws,Rp,Rs); % Calculate Optimal Filter Order
[b,a] = ellip(n,Rp,Rs,Wp,'low') % Transfer Function
figure
freqz(b,a, 2^16, Fs) % Filter Bode Plot
Explore the available options to design the filter you want.
.
4 Kommentare
Star Strider
am 17 Okt. 2022
As always, my pleasure!
Congratulations!
If you believe it would be appropriate to share your results, please post them (or a link to them).
Weitere Antworten (1)
Jan
am 16 Okt. 2022
You find C code implementation of filter() here: https://www.mathworks.com/matlabcentral/fileexchange/32261-filterm
As M code: https://www.mathworks.com/matlabcentral/answers/9900-use-filter-constants-to-hard-code-filter#comment_2203200 , which can be converted to C easily also.
Do you want to rewrite the tool to design of the filter parameters also?
2 Kommentare
Jan
am 17 Okt. 2022
Then you have to insert the code to obtain the next value into the loop for filtering.
Siehe auch
Kategorien
Mehr zu Digital Filter Design finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!