How to use function Hd I have created in Filter Design and Analysis Tool (FDATool)
조회 수: 11 (최근 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!