How to load .fda file made in filter designer into a workspace
52 views (last 30 days)
Show older comments
I created a low pass filter using the filterDesigner function and then exported the filter into the workspace as a object aswell as saved the file as a .fda file as this was the only option available. But when running my code the object is removed from my workspace how can the filter be loaded when my code is ran.
Please see code below
clc;
close all;
clear all;
%Fourier Transform of Sound File
%Load File
[y,Fs] = audioread('Healthy_6V.m4a'); %y=Audiodata and Fs=The sample rate
Nsamps = length(y); %Set the number of samples to equal recording length
t = (1/Fs)*(1:Nsamps); %Prepare time data for plot
%Caculate Fourier Transform - Unfiltered
y_fft = abs(fft(y)); %Obtain the FFT of the audio sample
y_fft = y_fft(1:Nsamps/2); %Discard half of Points to show single sided graph
f = Fs*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot
%Plot of Graphs - Unfiltered
figure
plot(t, y) %Plot Sound File in Time Domain
xlim([0 10])
xlabel('Time (s)')
ylabel('Amplitude')
title('Healthy System 6V in Time Domain')
figure
plot(f, y_fft) %Plot Sound File in Frequency Domain
grid minor
xlim([0 1000])
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Healthy System 6V in Frequency Domain')
%Load filter
%Implement filter to audio signal
y_filtered = filter(Hd, y);
y_fft_filtered = abs(fft(y_filtered));
y_fft_filtered = y_fft_filtered(1:Nsamps/2);
%Plot filtered data
figure
plot(f, y_fft_filtered) %Plot Sound File in Frequency Domain
grid minor
xlim([0 700])
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Healthy System 6V Filtered in Frequency Domain')
0 Comments
Answers (1)
Samay Sagar
on 24 May 2024
To ensure that the filter object “Hd” is available in the workspace when running the script, you can load the filter object from a MAT file or define it within the script itself. Here are two methods to achieve this:
1.Save and Load the Filter Object : After creating and exporting the filter in the “filterDesigner”, save the filter object to a MAT file:
% Assuming Hd is your filter object
save('myFilter.mat', 'Hd');
% Load the filter object in the script:
load('myFilter.mat', 'Hd');
2. Define the Filter Object in the Script : If the filter coefficients or the exact design parameters are known, the filter can be defined directly in the script using MATLAB's filter design function “designfilt”.
You can refer the following documentations to learn more about these functions:
0 Comments
See Also
Categories
Find more on Filter Analysis 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!