how to make distance affect on attenuation factor?

6 次查看(过去 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!

采纳的回答

Mathieu NOE
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 CenterFile Exchange 中查找有关 Filter Design 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by