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!