How can I implement a stable Shelving filter for short pulses?
이전 댓글 표시
I don't know much about MATLAB and have only been experimenting with it for 1 week.
I have a SOFA file with a HRTF (Head Related Transfer Function) measurement.
The measurement is faulty and I wanted to apply a simple shelf filter below 350Hz on the left channel. After a lot of research I managed to apply an IIR shelf filter with the "shelvFilt" function. The problem is that the frequency response is very unstable, probably because HRTFs are very short pulses.
The next idea that comes to my mind is an FIR filter, does anyone have an idea how to best implement this?
This is the code with the IIR shelf filter using the SOFAToolbox + a screenshot with the unstable result.
% Load the SOFA file
data = SOFAload('/Users/username/Desktop/HRTF_48000.sofa');
% Extract the left channel data from Data.IR
leftChannelData = squeeze(data.Data.IR(:, 1, :));
% Create the shelving filter
shelvFilt = shelvingFilter(Gain=-1, Slope=1, CutoffFrequency=350, FilterType="lowpass", SampleRate=48000);
% Apply the shelving filter to the left channel data
filteredLeftChannelData = shelvFilt(leftChannelData);
% Update the left channel data in the new SOFA structure
newData = data;
newData.Data.IR(:, 1, :) = filteredLeftChannelData;
% Save the new SOFA structure as a new SOFA file
SOFAsave('/Users/username/Desktop/HRTF_48000_Modified.sofa', newData, 0);
댓글 수: 7
Hi Hasan,
Is this the desired magnitude response fo the filter you want to apply to the input signal?
shelvFilt = shelvingFilter(Gain=-1, Slope=1, CutoffFrequency=350, FilterType="lowpass", SampleRate=48000);
[b,a] = shelvFilt.coeffs;
[h,f] = freqz(b,a,1024,48000);
semilogx(f,db(abs(h))),grid
ylabel('Mag (db)')
Can you expand on what you mean by " frequency response is very unstable"?
Hasan Aydin
2023년 6월 25일
Paul
2023년 6월 25일
How did you generate the frequency repsponse plot attached to the question?
How are you generating the lower graph in the plot attached to the preceding comment? Using the coded in the question?
Can you attach the left and right channel data in .mat file using the paperclip icon in the Insert menu?
Hasan Aydin
2023년 6월 25일
Paul
2023년 6월 25일
I have no idea what the SOFA toolbox is, nor the REW software, nor the Spatial Renderer. As this is a Matlab forum, I think the best you can hope for is to save leftChannelData and rightChannelData to a .mat file and attach the .mat file to the Question or a comment using the paperclip icon so that people can take a look at it based on the code included in the Question.
jibrahim
2023년 6월 26일
Hi Hasan,
If you attach your SOFA file, I can try to take a look.
Two comments:
1) Starting in release R2023B, you will be able to read and write SOFA files in MATLAB with Audio Toolbox.
2) Make sure leftChannelData is a column vector, as that is what the shevling filter expects. A row vector would be wrong, as each sample of the input would be interpreted as coming from an independent channel.
Hasan Aydin
2023년 6월 26일
편집: Hasan Aydin
2023년 6월 26일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
