Problems of calculating the frequency response of a sine wave

I'm currently trying to calculate the frequency response of a microphone for iphone / mic. I play the sine on the speaker, record it through the microphone and try to get the frequency response. the ultimate goal is the ability to multiply FR by any sound so that the sound looks like an iphones / mic speaker.

My code is:

//apply window function vDSP_vmul(sineSweepMic,1,hammingWindow,1,sineSweepMic,1,n); vDSP_vmul(sineSweepFile,1,hammingWindow,1,sineSweepFile,1,n); //put both signals in complex arrays vDSP_ctoz((DSPComplex *)sineSweepMic, 2, &fftSineSweepMic, 1, nOver2); vDSP_ctoz((DSPComplex *)sineSweepFile, 2, &fftSineSweepFile, 1, nOver2); //fft of both file and mic sweeps vDSP_fft_zrip(fftSetup, &fftSineSweepFile, 1, log2n, FFT_FORWARD); vDSP_fft_zrip(fftSetup, &fftSineSweepMic, 1, log2n, FFT_FORWARD); //back to interleaved vDSP_ztoc(&fftSineSweepFile, 1, (COMPLEX *)sineSweepFile, 2, nOver2); vDSP_ztoc(&fftSineSweepMic, 1, (COMPLEX *)sineSweepMic, 2, nOver2); //divide mic-sweep by file-sweep to create frequency response vDSP_vdiv(sineSweepFile, 1, sineSweepMic, 1, frequencyResponse, 1, n); 

it still works, and when I multiply FR by the initial scan of the file, it sounds like a mic scan.

My problem: this only works for the exact file (sweep) from which FR is generated. As soon as I use FR to change other sounds, music appears, for example, only noise.

i use FR like this (as in the frequency domain, alternating, not complicated, even the same length):

  vDSP_vmul(soundToModify, 1, frequencyResponse, 1, soundToModify, 1, n); 

My sinusoidal sweep from a file being played on the speaker: enter image description here

My recorded sine wave (visible visible low frequencies): enter image description here

My sine-sweep file is multiplied in the frequency domain with FR generated as above in the code: enter image description here

My goal: in my understanding, the frequency response is information about each frequency, how much it is weakened or amplified by the system (in my example, it is not able to reproduce low frequencies). To get this information, I generate a sound containing each desired frequency (sine sweep), reproducing it and analyzing how each frequency changes, dividing the recorded recorded sweep / sweep of the file (division by code).

When you multiply this FR in the frequency domain by any sound, you need to change the frequency amplitudes to simulate playback in my system, right?

thanks!


UPDATE: in the end, the disadvantage was the lack of complex arithmetic, and both, the sine wave and pink noise worked pretty well, like an impulse to restore the impulse.

to get working code is just complicated - divide the recorded sweep fft data into the original fft scan data.

+4
source share
1 answer

If you want to recreate the sound of the iPhone / mic speaker, ideally you need to find the impulse response of the system.

What you are doing wrong: finding the FFT of the sinusoidality is pointless, since the input frequency is what changes (linearly or exponentially or otherwise) before the system induces its own frequency response on top of it. As Pavel R. suggested above, searching for FFT white noise makes more sense, since averaging over many statistically flat input frequencies will give you the actual frequency response of the system.

However, if your goal is to recreate the sound of the system, you also need to take care of a phase that is not performed in any of the above methods. The “ideal” way to do this is to capture the iPhone speaker / microphone response to the “pulse” in a completely calm and dry (no reflection) environment. There are 3 ways to do this: 1. Use sound pop sound or synthetic impulse sound for this. 2. Use the Gol codes, which is an easier way to average many measurements of the impulse response 3. Use sinusoidal sweeps, but then use the correlation to find the impulse response.

Link: https://ccrma.stanford.edu/realsimple/imp_meas/imp_meas.pdf

Once you get a measurement of the impulse response, roll it up with the signal you are trying to “colorize”, or take the FFT of both signals, multiply in the frequency domain, and then take the inverse FFT to get a color signal.

Explanation: I will try to explain this as far as I know: When you accept the impulse response FR, you take the magnitude of your FFT, discarding the phase data. Therefore, there are many filters (systems) with the same FR value, which will give you radically different outputs. In this case there will be Allpass Filters - they all have a flat FR, but if you put a pulse through them, you can get a sinusoidality depending on the filter parameters. Clearly, this should indicate that although you can always go from IR to FR, returning in the opposite direction means that you are free to choose. Therefore, you cannot throw out the phase, even for rough estimates. The fact that we cannot hear the phase means that we can look at FR for information about the system, but it does not allow us to ignore the phase of modeling the system. Hope this makes sense? To use sinusoidality, do the following: if s (t) = sin (A (t)) and A (t) = the integral [0 to t] (w (t) dt), map the signal e (t) = corr (v ( t), sin (A (t)), where v (t) = 2 * abs (dw / dt) will generate a pulse, so if you replace the sine scan in this correlation with the measured signal, you should get a pulse response. Hope this helps! Sorry for being so math.

+3
source

All Articles