how to make distance affect on attenuation factor?
2 ビュー (過去 30 日間)
古いコメントを表示
This is so far my distance effect function, but the attenuation factor(Att_linear) doens't work with input signal(inwave_lowpass) arrays have incompatible sizes for this operation, I tried to use convolve to solve it, but it will make the output (attenuated_signal) sounds like broken noise. I also tried filter(Att_linear, 1, inwave_lowpass) but it make the output sounds like broken also.
[inwave,fs]=audioread("anechoic_voice.wav");
%LOW-PASS FILTER%
% Define filter specifications
cutoff_frequency = 20000;
sampling_frequency = fs;
filter_order = 4;
%matlab lowpass filter
inwave_lowpass = lowpass(inwave,cutoff_frequency,sampling_frequency) ;
%ABSORPTION context%
%citing dissipation function by Densil C.(2015)
%alpha=absorption coeff (dB/m)
f_desired=(20:20000);
alpha = dissipation (f_desired, 20, 50,100,1);
%definie destination
r=1;
%decay factor in dB
Att=alpha.*r;
% Convert attenuation factor to linear scale
Att_linear = 10.^(Att/20);
% Apply attenuation to the input signal%
%attenuated_signal =inwave_lowpass.*Att_linear; %Problem: .*not work cuz arrays have incompatible sizes for this operation.%
attenuated_signal =conv(inwave_lowpass,Att_linear);%Problem: convolve not work for r when output.%
% Plot the frequency response of the attenuation filter
freqz(Att_linear, 1, 1024, fs);
% Play the attenuated signal
sound(attenuated_signal, fs);
Thank you for your time!
2 件のコメント
Mathieu NOE
2024 年 5 月 13 日
we cannot run your code because you did not provide the function dissipation
採用された回答
Mathieu NOE
2024 年 5 月 13 日
hello again
try this corrected code :
[inwave,fs]=audioread("anechoic_voice.wav");
%LOW-PASS FILTER%
% Define filter specifications
cutoff_frequency = 20000;
filter_order = 4;
%matlab lowpass filter
inwave_lowpass = lowpass(inwave,cutoff_frequency,fs) ;
%ABSORPTION context%
%citing dissipation function by Densil C.(2015)
%alpha=absorption coeff (dB/m)
f_desired=linspace(0,fs/2,100); % frequency vector must go from 0 to fs/2;
alpha = dissipation (f_desired, 20, 50,100,1);
%define distance
distance = 1;
% Generate a FIR filter for dissipation (code copied from inside the
% function)
magnitude = 10.^((-alpha * distance) / 20);
filterlen = 16;
h = fir2(filterlen,f_desired(:)/(fs/2),magnitude(:)); % h = FIR coefficients
% Plot the impulse response of the attenuation filter
figure,plot(h);
% Apply attenuation to the input signal%
attenuated_signal = filter(h,1,inwave_lowpass);
% Plot the frequency response of the attenuation filter
figure,freqz(h, 1, 1024, fs);
% Play the attenuated signal
sound(attenuated_signal, fs);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Filter Design についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!