## Search This Blog

%Code to extract the 5 Hz signal:

clc
clear all
close all
x1=5;
x2=15;
x3=30;
t=0:0.001:2;
y1=sin(2*pi*t*x1);
figure;
plot(t,y1,'k');
title('Signal with 5 Hz');
y2=0.5*sin(2*pi*t*x2);
figure;
plot(t,y2,'g');
title('Signal with 15 Hz');
y3=0.3*sin(2*pi*t*x3);
figure;
plot(t,y3,'m');
title('Signal with 30 Hz');
x=y1+y2+y3;
figure;
plot(t,x,'c');
g=abs(fft(y1));
figure;
stem((g));
title('Magnitude response of 5 Hz signal');
g=abs(fft(y2));
figure;
stem((g));
title('Magnitude response of 15 Hz signal');
g=abs(fft(y3));
figure;
stem((g));
title('Magnitude response of 30 Hz signal');
gg=(fft(x));
figure;
g=abs(gg);
stem(g);
title('Magnitude response of composite signal');
i=find(g<900);
gg(i)=zeros(size(i));
figure;
m=ifft(gg);
plot(t,m,'b');
title('Filtered signal');

%Code to extract the 30 Hz signal:

clc
clear all
close all
x1=5;
x2=15;
x3=30;
t=0:0.001:2;
y1=sin(2*pi*t*x1);
figure;
plot(t,y1,'k');
title('Signal with 5 Hz');
y2=0.5*sin(2*pi*t*x2);
figure;
plot(t,y2,'g');
title('Signal with 15 Hz');
y3=0.3*sin(2*pi*t*x3);
figure;
plot(t,y3,'m');
title('Signal with 30 Hz');
x=y1+y2+y3;
figure;
plot(t,x,'c');
g=abs(fft(y1));
figure;
stem((g));
title('Magnitude response of 5 Hz signal');
g=abs(fft(y2));
figure;
stem((g));
title('Magnitude response of 15 Hz signal');
g=abs(fft(y3));
figure;
stem((g));
title('Magnitude response of 30 Hz signal');
gg=(fft(x));
figure;
g=abs(gg);
stem(g);
title('Magnitude response of composite signal');
i=find(g>310);
gg(i)=zeros(size(i));
figure;
m=ifft(gg);
plot(t,m,'b');
title('Filtered signal');

%Code to extract the 15 Hz signal:

clc
clear all
close all
x1=5;
x2=15;
x3=30;
t=0:0.001:2;
y1=sin(2*pi*t*x1);
figure;
plot(t,y1,'k');
title('Signal with 5 Hz');
y2=0.5*sin(2*pi*t*x2);
figure;
plot(t,y2,'g');
title('Signal with 15 Hz');
y3=0.3*sin(2*pi*t*x3);
figure;
plot(t,y3,'m');
title('Signal with 30 Hz');
x=y1+y2+y3;
figure;
plot(t,x,'c');
g=abs(fft(y1));
figure;
stem((g));
title('Magnitude response of 5 Hz signal');
g=abs(fft(y2));
figure;
stem((g));
title('Magnitude response of 15 Hz signal');
g=abs(fft(y3));
figure;
stem((g));
title('Magnitude response of 30 Hz signal');
gg=(fft(x));
figure;
g=abs(gg);
stem(g);
title('Magnitude response of composite signal');
i=find(g<450);
gg(i)=zeros(size(i));
i=find(g>550);
gg(i)=zeros(size(i));
figure;
m=ifft(gg);
plot(t,m,'b');
title('Filtered signal');