I need to measure certain parameters between two signals with different frequencies. Namely, lag/phase difference.
I understand that I can't use xcorr for instance because the frequencies are different.
If needed I can attach the data.
I'm able to measure the frequency of both signals using:
%calculate frequencies
[maxValue1,indexMax1] = max(abs(fft(sig1-mean(sig1))));
f1 = indexMax1 * 100 / 100;
[maxValue2,indexMax2] = max(abs(fft(sig2-mean(sig2))));
f2 = indexMax2 * 100 / 100;
%which one is higher?
maxF = max (f1, f2);
How could I enforce/change either signal's frequency to be like the other? For example, both signals' frequencies should be maxF.
An FFT might not be the best way to do what you want to do. If each of your two signals are truly monocomponent (ie, they are not mixtures of multiple sine waves), you can get way better performance using the hilbert transform. The hilbert converts your real signal into a complex signal. It also allows you to directly evaluate the phase, frequency, and amplitude very easily.
%convert to complex domain
h_sig1 = hilbert(sig1);
h_sig2 = hilbert(sig2);
%plot instantaneous phase of the signals
phase_sig1_rad = angle(h_sig1); %radians
phase_sig2_rad = angle(h_sig2); %radians
dphase_rad = wrapTo2Pi(phase_sig1_rad - phase_sig2_rad);
plot([phase_sig1_rad(:) phase_sig2_rad(:) dphase_rad(:)]);
%other info: compute the frequency of the signals
dt_sec = 1/sample_rate_Hz; %what is the time between samples
freq_sig1_Hz = diff(unwrap(phase_sig1_rad))/(2*pi)/dt_sec;
freq_sig2_Hz = diff(unwrap(phase_sig2_rad))/(2*pi)/dt_sec;
%other info: compute the amplitude of the signals
amp_sig1 = abs(h_sig1);
amp_sig2 = abs(h_sig2);
Hope this helps!