how to make distance affect on attenuation factor?

2 visualizaciones (últimos 30 días)
HUIHSUAN
HUIHSUAN el 11 de Mayo de 2024
Comentada: Mathieu NOE el 14 de Mayo de 2024
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 comentarios
Mathieu NOE
Mathieu NOE el 13 de Mayo de 2024
we cannot run your code because you did not provide the function dissipation
HUIHSUAN
HUIHSUAN el 13 de Mayo de 2024
oh my god totally forget it! thank you for remind! its a code from github!

Iniciar sesión para comentar.

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 13 de Mayo de 2024
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);
  2 comentarios
HUIHSUAN
HUIHSUAN el 14 de Mayo de 2024
superrrrrrr helpful!!! Thank you soooo much :D
Mathieu NOE
Mathieu NOE el 14 de Mayo de 2024
as awas, my pleasure !

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by