will processing a fragment of a wave file result in artifacts in the frequency domain?

2 views (last 30 days)
Hello everybody, this is my first post in the forum.
I need to do some processing on a wav file in order to distinct between two components. One coming directly from a sound source and another coming from a later reflection on an object. I need to process the two components in time separately. My question is, if the wave file 'my_wavfile' has let's say 1000 samples and the first component extends from sample '100:300' and the second from '500:800' then F=fft(my_wavfile(100:300)) will it create any artifacts in F because of cutting out the rest of the samples in the time domain?
I don't have a strong background in signal processing and any help would be appreciated

Accepted Answer

Wayne King
Wayne King on 9 May 2012
Again, these vectors are not equal so the DFT will not be equal. The length of the two DFTs are not equal
f1=[1 2 3 4 5]
f2=[1 2 3 4 5 0 0 0 0];
length(fft(f1))
length(fft(f2))
If you're getting at zero-padding, then zero-padding definitely changes the result of the DFT as expected.
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t);
xdft = fft(x); % length 1000
% now add zeros out to length 1024
xdft1 = fft(x,1024);
Qualitatively, these give the same picture.
plot(abs(xdft))
figure;
plot(abs(xdft1))
but they are clearly not equal. Remember the Fourier transform is 1-to-1.

More Answers (4)

Wayne King
Wayne King on 9 May 2012
You will be ok. The main issue that you will have is frequency resolution. By reducing your signal size from 1000 down to 300 samples, your frequency resolution is going to decrease from Fs/1000 where Fs is your sampling frequency to Fs/300.
Fs = 1e3;
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t).*(t<0.3)+cos(2*pi*200*t).*(t>0.3);
plot(abs(fft(x)))
plot(abs(fft(x)))
figure;
x1 = x(1:300);
plot(abs(fft(x1)))

buscuit
buscuit on 9 May 2012
Wayne, thanks for the prompt reply!
If it would not create any artifacts then why is it that:
if I assume that I am only interested in the first half of the file F1=fft(wavfile(1:500));
and after: wavfile(501:end)=0; F2=fft(wavfile)
then abs(F1) is not equal to abs(F2). In the second case I see components in the frequency domain I do not like. I would expect the two spectra to be the same. Once I am truncating a wavfile in both of the cases.

Wayne King
Wayne King on 9 May 2012
The DFT (implemented by fft()) is an invertible operator, which means it is 1 to 1. Even though you are just considering the abs() in this case (which can result in different vectors looking the same), replacing the last 500 samples by zeros is a VERY different waveform than the original. In other words
x = [1 2 3 4 5 4 3 2 1];
y = [1 2 3 4 5 0 0 0 0];
are very different so why would you expect their Fourier transforms not to be different?
fft(x)
fft(y)

buscuit
buscuit on 9 May 2012
ok, what you said makes sense. But I am more asking about the case when
wavfile=[1 2 3 4 5 4 3 2 1];
f1=[1 2 3 4 5]
f2=[1 2 3 4 5 0 0 0 0]
I would expect the fft(f1) and fft(f2) to be the same.
Thanks again Wayne for sticking with me in this

Community Treasure Hunt

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

Start Hunting!