I am trying to construct a time signal that needs to have a known magnitude response.
The idea is to apply in Matlab/Octave an IFFT directly to the desired magnitude response: this corresponds to setting the real part equals to the magnitude response and the phase to zero.
The resulting time signal will be non-causal (half peak at the start/end of the buffer), so I am applying a bulk delay of half of buffer length, as you can see from the following image.
Now, if I try to plot the desired and the derived magnitude responses, there are evedent differences in 10-100 Hz range, while in the other frequencies the two responses are almost identical. Why do I get these differences?
The Matlab/Octave code I am using is the following, you can find the "h.mat" file here:
% Impulse response with the desired magnitude
load('h.mat');
% Desired magnitude
Hmag = abs(fft(h));
% Non-causal response
y = ifft(Hmag);
% Apply bulk delay
y_sh = circshift(y,length(y)/2);
figure; plot(y); hold on; plot(y_sh);
legend("non-causal","bulk delayed");
% Plot the two magnitude responses
fs = 48000;
NFFT = 32768;
f = linspace(0,fs,NFFT);
figure;
semilogx(f,20*log10(abs(fft(h,NFFT)))); hold on;
semilogx(f,20*log10(abs(fft(y_sh,NFFT))));
I am new to DSP so probably there are some naive errors in my implementation.