0

我正在做一个计算两个信号之间相位角的项目。但是为了保持数学/代码简单,我使用简单的正弦/余弦函数来生成信号。

我的方法如下——

  1. 生成正弦/余弦信号

  2. 选择信号的样本大小(以指定要分析的信号的特定“快照”)

  3. 应用汉宁窗口(因为信号在我的应用程序中是非周期性的)

  4. 缓冲 10 个样本重叠的信号(进行滚动 FFT)

  5. 对两个缓冲信号进行 FFT

  6. 取 FFT 的平均值

  7. 现在提取振幅最大的谐波相位

  8. 取两个阶段之间的差异。

现在,在我的情况下,因为我有正弦和余弦,我不应该得到90°我的相位差吗?

相反,对于每个样本,我都会得到0, 。-180180

谢谢你的帮助!!

这是我的代码 -

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”给出了每个样本大小的两个信号之间的相位差。

4

0 回答 0