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

40 次查看(过去 30 天)
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

回答(1 个)

Garmit Pant
Garmit Pant 2023-9-26
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

类别

Help CenterFile Exchange 中查找有关 Digital Filter Analysis 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by