How to use function Hd I have created in Filter Design and Analysis Tool (FDATool)
6 次查看(过去 30 天)
显示 更早的评论
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]
0 个评论
回答(3 个)
Honglei Chen
2013-12-3
编辑:Wayne King
2013-12-3
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
0 个评论
Wayne King
2013-12-3
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Digital Filter Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!