MATLAB Answers

calculating residual between two time domain signals

18 views (last 30 days)
Tuhin Choudhury
Tuhin Choudhury on 15 Oct 2019
Commented: Daniel M on 16 Oct 2019
I have two time domain signals, e.g.:
y1= 3*cos(10*t+180*pi/180);
y2= 2*cos(10*t+60*pi/180);
What is the correct procedure for calculating the residual of these two signals? The current code I am using is below, where I am simply subtracting the two signals to get the residual signal. I am not sure if the residual is correct and whether the affect of phase difference is taken into account in this calculation.
clear all ;
close all;
t= 0:0.001:1;
% first signal vector (larger magnitude)
y1= 3*cos(10*t+0*pi/180);
% seond signal vector (smaller magnitude)
y2= 2*cos(10*t+180*pi/180);
% residualI tried
%% plots
hold on
plot(t, y2)
hold on
legend ('y1', 'y2', 'residual')
Furthermore, the residual signal should be of smaller amplitude then the parent signals, isnt it so? I realise that can be achived by simply adding the signals instead of subtracting(y3= y1+y2 gives the figure below) them but is that the correct way?

Accepted Answer

Daniel M
Daniel M on 16 Oct 2019
Edited: Daniel M on 16 Oct 2019
It's unclear what you're trying to achieve, but yes that how to calculate the residuals (the difference between the observed value, y1 = f(x), and the estimated value, y2 = f(x*), where x* is an approximation of the unknown x). They are not necessarily smaller than the parent signals. It is what it is. You should try to determine algebraically what happens when you subtract two sine waves, in the general case.
Daniel M
Daniel M on 16 Oct 2019
The residuals, as it stands, would be res = x1-x2; However, I suspect that would not give you a satisfying result, and you would prefer to subtract the two signals as if they were in phase. Then what you need to do is find the phase difference between the two signals. (Here we know it because we have the equation for the signal, but in the general case we will not). To do this, you can curve fit your signals, or use fzero, as in this example:
Once you have the phase, you can shift one of your signals by that phase amount, then subtract them to get the residuals. Shifting the phase can be done using the fft, but can also be done in the time domain by just padding one of your signals, if you know the relationship between time and your index.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!