calculating residual between two time domain signals

Hello,
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;
clc;
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
y3=y1-y2;
%% plots
figure
plot(t,y1)
hold on
plot(t, y2)
hold on
plot(t,y3)
legend ('y1', 'y2', 'residual')
mat1.png
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?
mat2.png

 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.

8 Comments

Hi Daniel, thanks for the answer!
I realise my description was a little unclear. Let me try to explain this with an example.
Suppose you bought a brand new fan, and measured the vibrations at its base. These vibrations are given by signal y2 (which would be typically quite low since the fan is new and defect-free). Now, after a long time of usage, there's a defect in the fan (e.g one blade broke off resulting in unblance). The vibrations of this damaged system would be higher in magnitude: perhaps y1. My objective is to calculate the vibrations generates solely due to the defect. Therefore, to calculate the residual vibration between the original fan and the damaged fan, the correct way would be : y1-y2?
Calculating residuals only works if the sine waves are time locked, and in this example they would not be. In this case, I would be more likely to do a spectral analysis.
Hi,
two questions:
  • By 'time locked', do you mean that both the sine waves should have the same 'start position' at t=0 and the same overall time duration? If yes, then this example case is time locked. So, would 'residual= y1-y2' work in that case? If no, then could you please explain the term 'time locked'?
  • How would you obtain residuals (vibration in damaged system - vibration in perfect system) in spectral analysis? Could you please share a link or an example code?
OK say I have a signal x and then I run a low pass filter on it to get X. In this case, it is the same signal with some high frequency noise removed. A residual of x-X would show the noise that was removed. But in the general case of x1 = A*sin(w1*t+phi1) and x2 = B*sin(w2*t+phi2) calculating a residual may or may not have the same utility as before. It depends on what you're looking for and how you are using it.
In your case, I would try spectral subtraction. You take your noisy signal and subtract out your perfect signal in the frequency domain, then convert back to time domain. There is lots of documentation and tutorials on spectral analysis on the Mathworks website. Start by looking up fft.
Thank you for the suggestion, but I am not sure if fft would be useful here, since there is no high frequency noise here; both signals are at the same frequency. In general terms it is :
x1= A cos(w1*t+ phi1) and x2= Bcos(w*t+ phi2) with the same w and t , as I have mentioned before. Only thing changing is the amplitude and phase, so how is it possible to use frequency analysis to find the difference between x1 and x2?
If you're talking about your example with the vibration of a fan, why would you assume the natural frequencies are the same? This whole question depends on the characteristic of the signals under question, so it is hard to answer in general terms.
What do you do when your signals look like this? Maybe over time, the defects in the fan cause it to behave multi-modally.
t = 0:0.001:10;
x1 = 3*sin(2*pi*10*t) + 0.5*rand(size(t));
x2 = 2*sin(2*pi*10*t + pi) + 1.2*sin(2*pi*9.5*t + pi/3) + 0.5*rand(size(t));
figure
plot(t,x1,t,x2)
Right, it is completely dependent on the type of signal. Also, its true that the defects may induce vibrations of variable frequencies in the fan. However, in my case, I am dealing with the 1X component of the signals only; meaning that I have already filtered out the random noise and the vibrations at higher harmonics (or any vibrations at any other frequency for that matter).
For your example case:the 0.5*rand(size(t)) (noise) and the higher frequency vibration componenet due to defect (1.2*sin(2*pi*9.5*t + pi/3)) would have been already eliminated. I am stuck at the next step, where I am calculating the difference between the pure 1X signals before and after the defect.
t = 0:0.001:10;
x1 = 3*sin(2*pi*10*t); %+ 0.5*rand(size(t));
x2 = 2*sin(2*pi*10*t + pi);% + 1.2*sin(2*pi*9.5*t + pi/3) + 0.5*rand(size(t));
figure
plot(t,x1,t,x2)
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)

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Products

Release

R2017b

Community Treasure Hunt

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

Start Hunting!