How to test if two signals are equal

4 ビュー (過去 30 日間)
Italo
Italo 2011 年 11 月 25 日
Hello, I have computed by hand the frequency domain transfer function from a difference equation of a digital filter. I wanted to test if my computation is right, so I implemented both the difference equation and the frequency domain transfer function in Matlab. I chose a signal and I sent it through both of them separately. Now, how do I test if the two filtered signals are equal?
Thanks.

採用された回答

Wayne King
Wayne King 2011 年 11 月 25 日
As a simple example of my answer:
"Why do you need to input a signal? If you have the Fourier transform of your filter and the coefficients that give the difference equation, then just use freqz() with the coefficients to see if you have the correct Fourier transform. "
% coefficients from linear constant coefficient difference equation
% use freqz() to compute the frequency response
[H,W] = freqz([1/sqrt(2) 1/sqrt(2)],1);
% Compare to calculated Fourier transform
omega = 0:pi/512:pi-(pi/512);
FT = sqrt(2)*exp(-1j*omega./2).*cos(omega./2);
plot(W,abs(H)); hold on;
plot(W,abs(FT),'r-.','linewidth',2);

その他の回答 (2 件)

Image Analyst
Image Analyst 2011 年 11 月 25 日
Did you try subtracting them and seeing if all the elements are zero (or really close to zero)?
  2 件のコメント
Italo
Italo 2011 年 11 月 25 日
That was a good suggestion.
However it doesn't work in this case. The two filtered signals are out of phase. This means that when I substract them, the result is a signal with all the peaks of the operands.
Image Analyst
Image Analyst 2011 年 11 月 25 日
Maybe try normalized cross correlation using normxcorr2() in the Image Processing Toolbox. Look for high values indicating it is well aligned for some shift.

サインインしてコメントする。


Wayne King
Wayne King 2011 年 11 月 25 日
Why do you need to input a signal? If you have the Fourier transform of your filter and the coefficients that give the difference equation, then just use freqz() with the coefficients to see if you have the correct Fourier transform.

カテゴリ

Help Center および File ExchangeSignal Processing Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by