here I have to sound signals - one is a male speech signal and the other is a noise signal- , I have added them together - call it signal "mix" - and now I'm asked to filter it so that noise is removed and what remain is only the male speech signal. After analyzing the graphs of male speech and noise in time and frequency domain
Time Domain 1: https://www.dropbox.com/s/m5frew6f0qlbae5/filteres%20signal.jpg?dl=0
Frequency Domain
I observed that the max freq of male speech is a little less that the min freq of noise, so I made a low pass filter - using rect function - and filter it in frequency domain.
Ideal Low Pass Filter
I plotted the resulted signal in both frequency and time domain, the graph in frequency domain is the same as the male speech graph in frequency domain but in time domain it's not exactly the same
Filtered Signal
and I noticed the change also when I sounded the resulted signal.
Any help please to know why the filtered signal is not exactly as the original male speech?
*P.S: I know that filtering in this way is not sufficient but currently this is how we are supposed to do it in our report in my course.
Here is my Code:
[voice,Fs] = audioread ('hamid1.wav');
[noise,Fs] = audioread ('noise.wav');
voice(55126: 131072)=0 % to add both voice and noise signal together their dimensio must agree
mix = voice + noise; % the mixed signal
%vp = audioplayer(voice,Fs);
%play(vp);
%-- data for plotting voice --%
iFs = 1/Fs;
voiceLen = length(voice);
voiceF0 = 1/(iFs*voiceLen);
f_voice = 0:voiceF0: (voiceLen-1)*voiceF0;
t_voice = 0:iFs:(voiceLen-1)*iFs;
mag_voice = abs(fft(voice));
%-- data for plotting noise --%
noiseLen = length(noise);
noiseF0 = 1/(iFs*noiseLen);
f_noise = 0:noiseF0: (noiseLen-1)*noiseF0;
t_noise = 0:iFs:(noiseLen-1)/Fs;
mag_noise = abs(fft(noise));
%--------------------------------------------%
%-- data for plotting mix --%
mixLen = length(mix);
mixF0 = 1/(iFs*mixLen);
f_mix= 0:mixF0: (mixLen-1)*mixF0;
t_mix = 0:iFs:(mixLen-1)/Fs;
mag_mix = abs(fft(mix));
%-- plotting voice speech, noise and mix in frequency domain --%
figure(1);
subplot(3,1,1);
plot(f_voice,mag_voice);
title('voice speech in frequency domain');
xlabel('frequency'); ylabel('Magnitude');
subplot(3,1,2);
plot(f_noise,mag_noise);
title('noise in frequency domain');
xlabel('frequency'); ylabel('Magnitude');
subplot(3,1,3);
plot(f_mix,mag_mix);
title('mix signal in frequency domain');
xlabel('frequency'); ylabel('Magnitude')
%-- plotting voice speech, noise and mix in time domain --%
figure(2);
subplot(3,1,1);
plot(t_voice,voice);
title('voice speech in time domain');
xlabel('time'); ylabel('Amplitude');
subplot(3,1,2);
plot(t_noise,noise);
title('noise in time domain');
xlabel('time'); ylabel('Amplitude');
subplot(3,1,3);
plot(t_mix, mix);
title('mix signal in time domain');
xlabel('time'); ylabel('Amplitude')
%-- design the bandpass filter --
rect = 1*(f_mix>=0 & f_mix <3000);
rect2= rect+0*(f_mix>=3000 & f_mix <5482);
%-- plotting the ideal filter --%
figure(3)
plot(f_mix, rect2,'linewidth',2);
title('bandpass ideal filter');
xlabel('frequency'); ylabel('Magnitude')
axis([0 11000 0 1.5])
%-- Filtering the mix signal to extract voice speech without noise --%
filtered = rect2.*mag_mix'
filteredT = ifft(filtered)
figure(4)
subplot(2,1,1)
plot(f_mix, filtered)
title('Filtered signal in frequency domain')
xlabel('frequency')
ylabel('Magnitude')
subplot(2,1,2)
plot(t_mix, real(filteredT))
title('Filtered signal in time domain')
xlabel('time')
ylabel('Amplitude')
%-------------------------------------------%
filtSig = audioplayer(filteredT,Fs)
play(filtSig)
Here's a hint - is an ideal filter realizable? What's the inverse fourier transform of your ideal low pass filter? It's been a while since I've looked at this stuff but I don't think you're getting an error. Rather, you're seeing the effect of an overly rigid filter design.