Filter löschen
Filter löschen

how to make distance affect on attenuation factor?

5 Ansichten (letzte 30 Tage)
HUIHSUAN
HUIHSUAN am 11 Mai 2024
Kommentiert: Mathieu NOE am 14 Mai 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 Kommentare
Mathieu NOE
Mathieu NOE am 13 Mai 2024
we cannot run your code because you did not provide the function dissipation
HUIHSUAN
HUIHSUAN am 13 Mai 2024
oh my god totally forget it! thank you for remind! its a code from github!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 13 Mai 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 Kommentare
HUIHSUAN
HUIHSUAN am 14 Mai 2024
superrrrrrr helpful!!! Thank you soooo much :D
Mathieu NOE
Mathieu NOE am 14 Mai 2024
as awas, my pleasure !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by