Friday, June 29, 2018

fft - How to find phase difference between 2 signals, one has an unknown function



I have a system that is forced by a sinusoidal function with specific amplitude, phase and frequency ( all these are known ahead of time). I get a deformation of sinusoidal form as well (think of a damped harmonic response), and I would like to find the phase lag. I was advised to use correlation but I don't have the function that produces the response, only gathered data. This what I am doing but honestly I am not confident in my findings:


    y =[] %this is the gathered data, first column is time, second is deformation
frequency =1000; %Hz,i know this for a fact
t=y(:,1); %just getting the time to produce a sine wave for calibrating

fs = 14*frequency; %this is random, i m just making sure i m above 2*frequency.
Nfft = fs ;

sine_wave = 1+sin(2*pi*frequency*t + pi/2);%I need to 1 + for physical reasons


FFT_sine_wave =fft(sine_wave,Nfft)/Nfft; %FFT of sine_wave
FFT_Y2 =fft(y(:,2),Nfft)/Nfft; %FFT of response

magsine_wave = abs(FFT_sine_wave); %magnitude of sine_wave
magY2 = abs(FFT_Y2); %magnitude of response

f=linspace(-fs/2, fs/2, Nfft); %frequency vector

[old_max_sine_wave index_sine_wave] = max(magsine_wave);
magsine_wave(index_sine_wave) = -Inf; %getting rid of the DC offset


[old_max_Y2 index_Y2] = max(magY2);
magY2(index_Y2) = -Inf;

[maxAmp_sine_wave index_sine_wave] = max(magsine_wave); %Finding new amplitudes
[maxAmp_Y2 index_Y2] = max(magY2);

new_ang = angle(FFT_sine_wave); %getting the angles of sin wave

ang_miew = new_ang(8002)*(180/pi)+180 % 8002 is where f = 1000 Hz falls in frequency

%vector, so i use the index to find angle

amp_miew = 2*abs(FFT_sine_wave(index_sine_wave)) %this gives me the correct amplitude

new_angY2 = angle(FFT_Y2)*(180/pi); %same reasoning as above
ang_miewY2 = new_angY2(8002)+180

Please help me out, if any of you need the y vector that gives the time and deformation please let me know. I am in dire need of help! Thank you in advance




No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...