How to use function Hd I have created in Filter Design and Analysis Tool (FDATool)

6 Ansichten (letzte 30 Tage)
Hello,
I am a beginner of MATLAB and need to apply a filter I have created with instrument Filter Design and Analysis Tool (FDATool) on my audio signal (right channel). How to do that?
My m-file looks:
[y,Fs,nBits]=wavread('song_ttsgb.wav');
left=y(:,1); % Left channel
right=y(:,2); % Right channel
And filter looks:
function Hd = filter
%FILTER Returns a discrete-time filter object.
% MATLAB Code
% Generated by MATLAB(R) 8.2 and the DSP System Toolbox 8.5.
% Generated on: 01-Dec-2013 00:38:07
% Equiripple Highpass filter designed using the FIRPM function.
% All frequency values are in Hz.
Fs = 48100; % Sampling Frequency
Fstop = 82; % Stopband Frequency
Fpass = 880; % Passband Frequency
Dstop = 0.0001; % Stopband Attenuation
Dpass = 0.057501127785; % Passband Ripple
dens = 20; % Density Factor
% Calculate the order from the parameters using FIRPMORD.
[N, Fo, Ao, W] = firpmord([Fstop, Fpass]/(Fs/2), [0 1], [Dstop, Dpass]);
% Calculate the coefficients using the FIRPM function.
b = firpm(N, Fo, Ao, W, {dens});
Hd = dfilt.dffir(b);
% [EOF]

Antworten (3)

Honglei Chen
Honglei Chen am 3 Dez. 2013
Bearbeitet: Wayne King am 3 Dez. 2013
The filter is a bad name since it conflicts with the builtin filter command. I'd suggest your to change that line to
function Hd = createMyFilter
and then you can do
hd = createMyFilter;
y = filter(hd,right);
HTH

Martin
Martin am 3 Dez. 2013
It should be works already. Let me ask you one more question.. if you know.. how to call this function from external m-file..

Wayne King
Wayne King am 3 Dez. 2013
You create the function as Honglei has suggested (don't call it filter as he correctly suggested)
Then as long as you place the folder containing, createMyFilter.m, on the MATLAB path, you can call it just as Honglei has suggested.
Use
>>pathtool
to add the folder containing createMyFilter.m to the MATLAB path.
%% Filter data
data = randn(1000,1);
hd = createMyFilter;
y = filter(hd,data);

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by