user3620862
user3620862

Reputation: 53

Adding signals and separate them using MATLAB

I have two signals m(t) = exp(-100*abs(t)) and c(t) = cos(2*pi*1000*t). I need to add them and then separate them using only a low pass filter (LPF) and a band pass filter (BPF) and plot the figures.

I wrote the code :

fs = 100*1000;
ts = 1/fs;
t = -0.1:ts:0.1-ts;
No = length(t);

m = exp(-100*abs(t));
c = cos(2*pi*1000*t);
g = m + c;

y = abs(g);

cutoff = 200;
[a b]= butter(5,2*cutoff*ts);

z = filter(a,b,y);

figure(1)
plot(t,m,t,z); 
legend('Input Signal','Output Signal')
xlabel('time') 
ylabel('amplitude')
title('Case Study')

Note that I used LPF [a b] = butter(5,2*cutoff*ts);

The problem is that the plot is shifted up and I think this is because of the DC component. Can you help me to edit the code and fix the shift? And should I use BPF? If yes, how?

Upvotes: 1

Views: 585

Answers (2)

AlessioX
AlessioX

Reputation: 3177

In the plot command, subtract the mean value, like this

plot(t,m,t,z-mean(z));

Hope this is what you're looking for

Upvotes: 0

Noel Segura Meraz
Noel Segura Meraz

Reputation: 2323

The offset you are getting is from using the abs value of g. If instead of filtering y you filter g then you get a better result. The offset comes from the dc component of abs(c) since this is not centered over zero, and any low pass filter will maintain this offset

Upvotes: 1

Related Questions