I'm currently trying to calculate the frequency response of the iphone's speaker/microphone roundtrip. I play a sine sweep on the speaker, record it via the microphone and try to get the frequency response out of that. final goal is to be able to multiply the FR to any given sound to make it sound like the iphones speaker/mic.
My Code so far:
//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);
this works so far and when i multiply the FR with the initial file-sweep it sounds like the mic-sweep.
My Problem: this only works for the exact file (sweep) the FR is generated from. As soon as i use the FR to modify other sounds, music for example only noise comes out.
i use the FR like this (both in frequency domain, interleaved, not complex, even same length):
vDSP_vmul(soundToModify, 1, frequencyResponse, 1, soundToModify, 1, n);
My sine-sweep from file played on speaker:
My recorded sine-sweep (attenuated low frequencies visible):
My file sine-sweep multiplied in frequency domain with the FR generated as above in code:
My Goal: in my understanding the frequency response is the information about each frequency, how much it is attenuated or amplified by the system (in my example it is not able to reproduce low frequencies). To get this kind of information i generate a sound containing every desired frequency (sine-sweep) play it and analyze how every frequency is modified by dividing recorded-sweep/file-sweep (division in code).
By multiplying this FR in frequency domain to any sound should modify the frequency amplitudes to mimic a playback on my system, right?
thanks!
UPDATE: in the end the fault was the missing complex arithmetic and both, the sine-sweep as well as the pink noise worked pretty well as a impulse to recover th impulse response.
to get working code just complex-divide the recorded sweep fft data by the initial sweep fft data.