My signal after filtering gets attenuated
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mariam Atef
el 29 de Mayo de 2022
Respondida: Mariam Atef
el 29 de Mayo de 2022
I've been developing the code below to receive an audio signal, then filter it and amplify then plot the output. when I insert amplification gain values to 0 db for all frequency ranges, it's supposed to give me and output signal the same as the input signal. However, I keep getting an attenuated version of it. Can anybody tell me what's wrong with mycode?
Link for wav file I'm using as an input: https://drive.google.com/file/d/17c9DFoXetUyfjFak6RaosGdMSjHM1kxE/view?usp=sharing
PS: that's a shortened sample of the good. I've set the gains array to be of zeroes by default.
% getting the .wav file + its frequency + duration
file = inputdlg('Enter the required wav file name in the format (filename.wav):');
[y,fs] = audioread(file{1});
duration=length(y)/fs;
ofs=str2double(inputdlg('Specify the required output sample rate in Hz:'));
t = linspace(0,duration,length(y)); %time axis to plot any time domain input signals either before or after filtering
ranges = [0 170 310 600 1000 3000 6000 12000 14000 16000];
gains = [0 0 0 0 0 0 0 0 0];
%%filtering the passed audio
filters = []; %an array of the filtered signals
ampFilter = []; %an array of amplified filtered signals
compositeSignal = 0; %output signal
for i = 1:9
switch i
case 1
[num1 den1] = butter(4, 2*170/fs,'low');
filters = [filters filter(num1,den1,y)];
case 2
[num2 den2] = butter(4, [2*170/fs,2*310/fs],'bandpass');
filters = [filters filter(num2,den2,y)];
case 3
[num3 den3] = butter(4, [2*310/fs,2*600/fs],'bandpass');
filters = [filters filter(num3,den3,y)];
case 4
[num4 den4] = butter(4, [2*600/fs,2*1000/fs],'bandpass');
filters = [filters filter(num4,den4,y)];
case 5
[num5 den5] = butter(4, [2*1000/fs,2*3000/fs],'bandpass');
filters = [filters filter(num5,den5,y)];
case 6
[num6 den6] = butter(4, [2*3000/fs,2*6000/fs],'bandpass');
filters = [filters filter(num6,den6,y)];
case 7
[num7 den7] = butter(4, [2*6000/fs,2*12000/fs],'bandpass');
filters = [filters filter(num7,den7,y)];
case 8
[num8 den8] = butter(4, [2*12000/fs,2*14000/fs],'bandpass');
filters = [filters filter(num8,den8,y)];
case 9
[num9 den9] = butter(4, [2*14000/fs,2*16000/fs],'bandpass');
filters = [filters filter(num9,den9,y)];
end
ampFilter = [ampFilter (10^(gains(i)/20))*filters(:,i)];
compositeSignal = compositeSignal + filters(:,i);
end
%plot the signal in time & frequency domain before and after
figure;
sub1=subplot(2,1,1);
plot(sub1,t,y); xlabel('time'); title('Before Amplification (time domain)');
sub4=subplot(2,1,2);
to = linspace(0,length(compositeSignal)/ofs,length(compositeSignal)); %an axis for output signal using the output sampling frequency recevied from user
plot(sub4,to,compositeSignal);xlabel('time');title('After Amplification (time domain)');
% play and save the composite wave signal to a wav file
sound(compositeSignal,ofs);
audiowrite('compositeSignal.wav',compositeSignal,ofs);
Respuesta aceptada
Más respuestas (1)
William Rose
el 29 de Mayo de 2022
@Mariam Atef, please include a short .wav file so we can run your code. Please post the most simple possible version of your code that demonstrates the unexpected or unwanted behavior. Thank you.
1 comentario
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!