You are on page 1of 8

Contents

Task 1
Task 2
Task 3
Task 4

clc; clear;

Task 1

%Define the time interval


%%ts=0.00001;
%%t=-0.1:ts:0.1;
%define the function m(t) and c(t)
fc=1000;
fs=100*fc;
ts= 1/(fs-1);
t=0: ts :1;

m=exp(-100*abs(t));
c=cos(2*pi*1000*t);
%perform the multiplication
g=m.*c;
%perform full-wave rectification
y=abs(g);

% Create the filter


cutoff=1000;
[a, b]=butter(5,2*cutoff*ts);
% Get the output after the filter;
z=filter(a,b,y);
% Plot the input and output on the same graph
figure (1)
plot(t,m,t,z);
legend('Input Signal','Output Signal')
xlabel ('time')
ylabel('amplitude')
title ('Example');
% Finding the FT of the signals
M=abs(fftshift(fft(m)));
G=abs(fftshift(fft(g)));
Y=abs(fftshift(fft(y)));
Z=abs(fftshift(fft(z)));
% Creating the vector for the frequency axis
f=(-length(t)/2:length(t)/2-1)/(length(t)*ts);
% Plotting all FT on one sheet, in a 2x2 matrix format
figure (2)
subplot (221);
plot(f,M)
subplot(222);
plot(f,G)
subplot (223);
plot(f,Y)
subplot(224);
plot(f,Z)
Task 2

%Define the time interval


%%ts=0.00001;
%%t=-0.1:ts:0.1;
%define the function m(t) and c(t)
fc=2000;
fs=100*fc;
ts= 1/(fs-1);
t=0: ts :1;

m=2 + sin(2*pi*1000*t);
c=cos(2*pi*10^4*t);
%perform the multiplication
g=m.*c;
%perform full-wave rectification
y=abs(g);

% Create the filter


cutoff=1000;
[a, b]=butter(5,2*cutoff*ts);
% Get the output after the filter;
z=filter(a,b,y);
% Plot the input and output on the same graph
figure (3)
plot(t,m,t,z);
legend('Input Signal','Output Signal')
xlabel ('time')
ylabel('amplitude')
title ('Example');
% Finding the FT of the signals
M=abs(fftshift(fft(m)));
G=abs(fftshift(fft(g)));
Y=abs(fftshift(fft(y)));
Z=abs(fftshift(fft(z)));
% Creating the vector for the frequency axis
f=(-length(t)/2:length(t)/2-1)/(length(t)*ts);
% Plotting all FT on one sheet, in a 2x2 matrix format
figure (4)
subplot (221);
plot(f,M)
subplot(222);
plot(f,G)
subplot (223);
plot(f,Y)
subplot(224);
plot(f,Z)
Task 3

%Define the time interval


%%ts=0.00001;
%%t=-0.1:ts:0.1;
%define the function m(t) and c(t)
fc=1000;
fs=100*fc;
ts= 1/(fs-1);
t=0: ts :1;

m=sin(2*pi*100*t);
c=cos(2*pi*1000*t);
%perform the multiplication
g=m+c;
%perform full-wave rectification
y=(g);

% Create the filter


cutoff=1000;
[a, b]=butter(5,2*cutoff*ts,'HIGH');
% Get the output after the filter;
z=filter(a,b,y);
% Plot the input and output on the same graph
figure (5)
plot(t,m,t,z);
legend('Input Signal','Output Signal')
xlabel ('time')
ylabel('amplitude')
title ('Example');
% Finding the FT of the signals
M=abs(fftshift(fft(m)));
G=abs(fftshift(fft(c)));
Y=abs(fftshift(fft(y)));
Z=abs(fftshift(fft(z)));
% Creating the vector for the frequency axis
f=(-length(t)/2:length(t)/2-1)/(length(t)*ts);
% Plotting all FT on one sheet, in a 2x2 matrix format
figure (6)
subplot (221);
plot(f,M)
title('Message')
subplot(222);
plot(f,G)
title('Carrier')
subplot(223);
plot(f,Y)
title('Addition')
subplot(224);
plot(f,Z)
title('Filtered')
Task 4
Define time interval

% ts=0.00001;
% t=-0.1:ts:0.1;

% fc=1000;
fs=100*1000;
t=-0.1:(1/(fs-1)):1;

% Define functions
wc=2*pi*1000;

m=2+sin(2*pi*100*t);
c=cos(2*pi*1000*t);

% perform Multiplication
g=m.*c;
% full wave rectification

y=abs(g);
% filter
w0=(4/pi)*(cos(wc*t)-1/3*cos(3*wc*t)+1/5*cos(5*wc*t));
cutoff=150;
D=(g.*w0);
[a ,b]=butter(5,2*cutoff*(1/fs),'low');
% output after filter

z=filter(a,b,D);
% plot input & output on same graph
figure(7)
plot(t,m,t,z);
legend('Input signal','output signal')
xlabel('time')
ylabel('amplitude')
title('example');
% finding FT of signals
M=abs(fftshift(fft(m)));
J=abs(fftshift(fft(D)));
G=abs(fftshift(fft(g)));
Y=abs(fftshift(fft(y)));
Z=abs(fftshift(fft(z)));
C=abs(fftshift(fft(c)));
% creating vector
% f=(-length(t)/2:length(t)/2-1)/(length(t)*ts);
f=(-fs/2:(fs/(length(m)-1)):(fs/2));
% % one screen plot
figure(8)
subplot(221)

plot(f,M)
title('Massy signal')
subplot(222)

plot(f,C)
title('Carrier signal')
subplot(223)

plot(f,Y)
title('After addition')
subplot(224)

plot(f,Z)
title('Filtered signal')
plot(f,Z)
Published with MATLAB® R2014a

You might also like