2 つの信号間の位相角を計算するプロジェクトに取り組んでいます。しかし、数学/コードをシンプルに保つために、単純なサイン/コサイン関数を使用して信号を生成しています。
私の方法は次のとおりです-
サイン/コサイン信号を生成する
信号のサンプル サイズを選択します (分析する信号の特定の「スナップショット」を指定するため)。
ハニング ウィンドウを適用します (私のアプリケーションでは信号が非周期的であるため)
10 サンプルのオーバーラップで信号をバッファリングします (ローリング FFT を実行するため)。
両方のバッファリングされた信号の FFT を取る
FFTの平均を取る
次に、最大振幅の高調波の位相を抽出します
2 つのフェーズの差をとります。
さて、私の場合、サインとコサインがあるので90°
、位相差として取得するべきではありませんか?
代わりに、サンプルごと0
に 、-180
、のいずれかを取得します。180
ご協力いただきありがとうございます!!
ここに私のコードがあります -
Fs=100;
x=0:0.1:32;
ISin=sin(x);
ICos=cos(x);
s = length(ISin);
samplesize=16;
Displacement=zeros(samplesize,1);
Input=zeros(samplesize,1);
n=1;
p=1;
j=1;
for i=1:s
Displacement(j,1)=ICos(i);
Input(j,1)=ISin(i);
if n==samplesize
NFFT = 2^nextpow2(samplesize); % Next power of 2
%% Create Hanning Window and Buffer the Data
window=hann(NFFT);
Displacement_Buffered=buffer(Displacement,NFFT,10);
Input_Buffered=buffer(Input,NFFT,10);
Displacement_Buffered=Displacement_Buffered'*diag(window);
Input_Buffered=Input_Buffered'*diag(window);
%% Calculate the FFT of the Signals now
Displacement_FFT=fft(Displacement_Buffered,NFFT)/samplesize;
Input_FFT=fft(Input_Buffered,NFFT)/samplesize;
%Calculate the length of the frequency axis to be displayed
f = Fs/2*linspace(0,1,NFFT/2+1);
%Take the average
Displacement_FFT=mean(Displacement_FFT);
Input_FFT=mean(Input_FFT);
%Calculate the phase angles
Displacement_Phase=(angle(Displacement_FFT));
Input_Phase=(angle(Input_FFT));
%Identify the largest component
[Displacement_Max_Value Displacement_Max_Index]=max(abs(Displacement_FFT));
[Input_Max_Value Input_Max_Index]=max(abs(Input_FFT));
%Get the Phase angles that correspond to the largest harmonic
Z_Displacement=Displacement_Phase(Displacement_Max_Index);
Z_Input=Input_Phase(Input_Max_Index);
%Calculate the Phase angle differences
Z_Displacement_Input=Z_Displacement-Z_Input;
%Consolidate them in a matrix
DispvsInput(p,1)=Z_Displacement_Input*180/pi;
p=p+1;
j=1;
n=1;
end
%Counter
n=n+1;
j=j+1;
end
plot(DispvsInput)
xlabel('Sample Number')
ylabel('Phase Difference(deg)')
title('Phase Difference between Sine and Cosine')
'DispvsInput' という項は、各サンプル サイズの 2 つの信号間の位相差を示します。