Frequencies space to time space with Fourier Trasform (FT and IFT)

5 Ansichten (letzte 30 Tage)
Federico Radice
Federico Radice am 12 Apr. 2021
Bearbeitet: Matt J am 13 Apr. 2021
Switching from the freqencies space (F) to time space (g) something goes wrong. You can notice if repeating more times.
Simply going to frequencies space and coming back to time space, the audio changes. Why?
("Input" and "Output" are shown as they should be filters.)I think the problem is in the inverse Fourier Trasform (ifft() and the
rest) but cannot find it.
% Config
iterations = 4;
% Load file
[y,Fs] = audioread("noise2NumTel.wav"); % It happens with any audio file
for cont = 1:iterations
figure1 = figure('Name', sprintf("Ripetizione %d", cont));
N = numel(y);
fj = [y ; 0];
Dt = 1/Fs;
tj = Dt*(0:N);
% plot input signal
subplot(2, 3, [1 2]);
h1 = plot(tj, real(fj), 'b');
axis tight;
grid on;
xlabel('Tempo (secondi)');
title('Input: tempo');
% FT
nu = (-N/2:N/2)/T;
f = [.5*(fj(1)+fj(end)) ; fj(2:end-1)];
F = fftshift(fft(f));
F = [F ; F(1)]*T/N;
if mod(N/2, 2) == 0
F(2:2:end) = -F(2:2:end);
else
F(1:2:end) = -F(1:2:end);
end
% plot spettro input
subplot(2, 3, 3);
h1 = plot(nu, abs(F), 'r');
assi= axis;
axis([-3000 3000 assi(3:4)]);
grid on;
xlabel('Hz');
title('Input: frequenze');
% plot output frequenze
subplot(2, 3, 6);
h1 = plot(nu, abs(F), 'r');
assi= axis;
axis([-3000 3000 assi(3:4)]);
grid on;
xlabel('kHz');
title('Output: frequenze');
% Some filter on frequencies ...
% ... () ...
%
% Inverse FT
G = [ .5*(F(1)+F(end)) ; F(2:end-1) ];
g = fftshift(ifft(G));
g = [g ; g(1)]/T*N;
if mod((numel(g)-1)/2, 2) == 0
g(2:2:end) = -g(2:2:end);
else
g(1:2:end) = -g(1:2:end);
end
% plot output dignal
subplot(2, 3, [4 5]);
h1 = plot(tj, real(g), 'b');
axis tight;
grid on;
xlabel('Tempo (secondi)');
title('Output: tempo');
% Working on y
y = g;
end
Iteration 1
Iteration 1
Iteration 2
Iteration 2
Iteration 3
Iteration 3
Iteration 4
Iteration 4

Antworten (1)

Matt J
Matt J am 12 Apr. 2021
Simply going to frequencies space and coming back to time space, the audio changes. Why?
But what you are doing is not simply going to frequency space and back. You are making modifications to the frequency spectrum before doing the inverse Fourier transform:
F = [F ; F(1)]*T/N;
if mod(N/2, 2) == 0
F(2:2:end) = -F(2:2:end);
else
F(1:2:end) = -F(1:2:end);
end
Given the above changes, why expect the final time signal to be the same as the original?
  2 Kommentare
Federico Radice
Federico Radice am 13 Apr. 2021
So what would be a simple "go-and-back" between the 2 spaces like?
(A simple lowpass filter for example.)
I foundamentally copied this code from the teacher's slide, and I cannot get where the error is :|
Matt J
Matt J am 13 Apr. 2021
Bearbeitet: Matt J am 13 Apr. 2021
If you want to undo the FFT without any changes to the signal, it would have to look like this
ifft(fft(signal))
although I don't know why you would ever want to do that. The whole point of going to the frequency domain is to modify the signal there in some way.
My ultimate point though was that it makes no sense to expect "no change" in your original signal for two reasons (1) You changed the spectrum, so you should expect that to have some effect in the time domain (2) If no change was the goal it would make no sense to be processing the signal in the first place. Just don't touch the thing.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by