I created a filter using filter designer and exported either coefficients, objects, or system objects - how to use filter in Matlab?

26 views (last 30 days)
It can't be that difficult! The filter is easy to design - it looks perfect. Yet, I have looked and looked at how to implement it in Matlab code - and I can't find out how to do it. Attached is the filter created in the filter designer. I have tried exporting it as a objects, as coefficients, and as system objects. I just want to have it filter it out this little sample check - but nothing works. Why does Matlab have to make it so difficult. Once a filter is made - it should be a simple filter entry to use that filter. But it is not.
Monty

Answers (1)

Garmit Pant
Garmit Pant on 26 Sep 2023
Hello Monty
I understand that you are trying to design a filter using the MATLAB Filter Designer app and you want to use the filter to filter a signal in your MATLAB code.
You can save and export a filter designed in the Filter Designer app in multiple ways. Two of the ways are listed below:
  1. Export as an object to the Workspace:
  2. Select File > Export. The Export dialog box appears.
  3. Select Workspace from the Export To menu.
  4. Select Objects from the Export As menu to save the filter in a filter object.
  1. Generating MATLAB Code:
  2. Choose File > Generate MATLAB Code > Data Filtering Function
You can refer to the following code snippet to use these created filters in your MATLAB code:
% check filter with add 2 sine signals together
tcheck=(0:0.0001:0.01);
ycheck=100*sin(2*pi*500*tcheck)+100*sin(2*pi*1000*tcheck);
figure (501)
plot(tcheck,ycheck)
y500=100*sin(2*pi*500*tcheck);
figure (502)
plot (tcheck, y500)
yfiltercheck = filter(Hd,ycheck);
%Filter saved in a MATLAB file named 'filterCustom.m'
hd = filterCustom;
yfiltercheck2 = filter(hd,ycheck);
% Plot the filtered data
figure (601)
plot (tcheck, yfiltercheck2);title ('Check, Filtered')
xlabel ('Time (seconds)'); ylabel ('Amplitude');
grid on;grid minor
For further understanding, you can refer to the following MATLAB Documentation:
  1. https://www.mathworks.com/help/dsp/ug/using-filter-designer.html - How to use Filter Designer App and export a filter.
  2. https://www.mathworks.com/help/signal/ug/filtering-data-with-signal-processing-toolbox.html How to use different filters.
I hope this helps!
Best Regards
Garmit

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!