0% found this document useful (0 votes)
27 views9 pages

All All: For If Else End End

The document contains code to generate and analyze rectangular waveforms with different durations. It defines rectangular functions with durations of 1/3, 1/6, and 1 second. For each, it plots the time domain waveform, calculates the Fourier transform using numerical integration, and plots the magnitude of the Fourier transform. It then overlays the plots of the Fourier transforms on a single graph to compare their frequencies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views9 pages

All All: For If Else End End

The document contains code to generate and analyze rectangular waveforms with different durations. It defines rectangular functions with durations of 1/3, 1/6, and 1 second. For each, it plots the time domain waveform, calculates the Fourier transform using numerical integration, and plots the magnitude of the Fourier transform. It then overlays the plots of the Fourier transforms on a single graph to compare their frequencies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

TASK 3

Task 3a
clc; clear all; close all;
%-----------Rectangular function-----------
t = -2 : 0.01 : 2;
x = zeros(size(t));
T=1; %define length (time) of magnitude 1
for i = 1 : length(t)
if abs(t(i)) <= T/3
x(i) = 2;
else
x(i) = 0;
end
end
figure;
subplot(3,1,1); plot(t,x,'LineWidth',2);
ylim([0 3])
xlabel('t (sec)');
ylabel('x(t)');
title('Rectangular Function');
%-------------To plot Fourier transform------------
omega = [-60: 0.01 :60];
F = zeros(size(omega));
for k = 1 : length(omega)
F(k) = trapz(t,x.*exp(-j*omega(k)*t)); %Fourier Transform
Formula
end
F_Magnitude = abs(F); %Magnitude of the Fourier Transform
subplot(3,1,2); plot(omega,F_Magnitude,'LineWidth',2);
ylim([0 T*1.5])
xlabel('\omega (rad/sec)');
ylabel('|F(j\omega)|');
title('Fourier Transform of Rectangular');
%-------------Fourier plot graph |T*(sinc(w*(T/2)))|----------
y = zeros(size(omega));
a= T/3*3/T; % scaling factor
for k = 1 : length(omega)
y(k)= T*1/abs(a)*sinc(omega(k)*T/(a*2*pi));
y1(k)=abs(y(k));
end
subplot(3,1,3); plot(omega,y1,'LineWidth',2);
ylim([0 T*1.5])
xlabel('\omega (rad/sec)');
ylabel('|F(\omega)|');
title('Graph of T sinc(wT/3)');
Waveform for signal 3a
Task 3b

clc; clear all; close all;


%-----------Rectangular function-----------
t = -2 : 0.01 : 2;
x = zeros(size(t));
T=1; %define length (time) of magnitude 1
for i = 1 : length(t)
if abs(t(i)) <= T/6
x(i) = 2;
else
x(i) = 0;
end
end
figure;
subplot(3,1,1); plot(t,x,'LineWidth',2);
ylim([0 3])
xlabel('t (sec)');
ylabel('x(t)');
title('Rectangular Function');
%-------------To plot Fourier transform------------
omega = [-60: 0.01 :60];
F = zeros(size(omega));
for k = 1 : length(omega)
F(k) = trapz(t,x.*exp(-j*omega(k)*t)); %Fourier Transform
Formula
end
F_Magnitude = abs(F); %Magnitude of the Fourier Transform
subplot(3,1,2); plot(omega,F_Magnitude,'LineWidth',2);
ylim([0 T*1.5])
xlim([-60 60])
xlabel('\omega (rad/sec)');
ylabel('|G(j\omega)|');
title('Fourier Transform of Rectangular');
%-------------Fourier plot graph |T*(sinc(w*(T/2)))|----------
y = zeros(size(omega));
a= T/2*2/T; % scaling factor
for k = 1 : length(omega)
y(k)= T*1/abs(a)*sinc(omega(k)*T/(a*2*pi));
y1(k)=abs(y(k));
end
subplot(3,1,3); plot(omega,y1,'LineWidth',2);
ylim([0 T*1.5])
xlim([-60 60])
xlabel('\omega (rad/sec)');
ylabel('|G(\omega)|');
title('Graph of T sinc(wT/6)');
Waveform for signal 3b
Task 3c

clc; clear all; close all;


%-----------Rectangular function-----------
t = -6 : 0.01 : 6;
x = zeros(size(t));
T=3; %define length (time) of magnitude 1
for i = 1 : length(t)
if abs(t(i)) <= T
x(i) = 2;
else
x(i) = 0;
end
end
figure;
subplot(3,1,1); plot(t,x,'LineWidth',2);
ylim([0 3])
xlabel('t (sec)');
ylabel('x(t)');
title('Rectangular Function');
%-------------To plot Fourier transform------------
omega = [-60: 0.01 :60];
F = zeros(size(omega));
for k = 1 : length(omega)
F(k) = trapz(t,x.*exp(-j*omega(k)*t)); %Fourier Transform
Formula
end
F_Magnitude = abs(F); %Magnitude of the Fourier Transform
subplot(3,1,2); plot(omega,F_Magnitude,'LineWidth',2);
ylim([0 T*5])
xlim([-20 20]);
xlabel('\omega (rad/sec)');
ylabel('|H(j\omega)|');
title('Fourier Transform of Rectangular');
%-------------Fourier plot graph |T*(sinc(w*(T/2)))|----------
y = zeros(size(omega));
a= T/2*2/T; % scaling factor
for k = 1 : length(omega)
y(k)= T*1/abs(a)*sinc(omega(k)*T/(a*2*pi));
y1(k)=abs(y(k));
end
subplot(3,1,3); plot(omega,y1,'LineWidth',2);
ylim([0 T*1.5])
xlim([-20 20]);
xlabel('\omega (rad/sec)');
ylabel('|H(\omega)|');
title('Graph of T sinc(wT)');
Waveform for signal 3c
All Frequency in one.
clc; clear all; close all;
%-----------Rectangular function figure 3(a)-----------
t = -2 : 0.01 : 2;
x = zeros(size(t));
T=1; %define length (time) of magnitude 1
for i = 1 : length(t)
if abs(t(i)) <= T/3
x(i) = 2;
else
x(i) = 0;
end
end

%-------------To plot Fourier transform figure 3(a)------------


omega = [-60: 0.01 :60];
F = zeros(size(omega));
for k = 1 : length(omega)
F(k) = trapz(t,x.*exp(-j*omega(k)*t)); %Fourier Transform
Formula
end
F_Magnitude = abs(F); %Magnitude of the Fourier Transform
subplot(3,1,1); plot(omega,F_Magnitude,'LineWidth',2);
ylim([0 T*1.5])
xlabel('\omega (rad/sec)');
ylabel('|F(j\omega)|');
title('Fourier Transform of Rectangular');

%-----------Rectangular function figure 3(b)-----------


t = -2 : 0.01 : 2;
x = zeros(size(t));
T=1; %define length (time) of magnitude 1
for i = 1 : length(t)
if abs(t(i)) <= T/6
x(i) = 2;
else
x(i) = 0;
end
end
%-------------To plot Fourier transform figure 3(b)------------
omega = [-60: 0.01 :60];
F = zeros(size(omega));
for k = 1 : length(omega)
F(k) = trapz(t,x.*exp(-j*omega(k)*t)); %Fourier Transform
Formula
end
F_Magnitude = abs(F); %Magnitude of the Fourier Transform
subplot(3,1,2); plot(omega,F_Magnitude,'LineWidth',2);
ylim([0 T*1.5])
xlabel('\omega (rad/sec)');
ylabel('|G(j\omega)|');
title('Fourier Transform of Rectangular');

%-----------Rectangular function figure 3(c)-----------


t = -6 : 0.01 : 6;
x = zeros(size(t));
T=3; %define length (time) of magnitude 1
for i = 1 : length(t)
if abs(t(i)) <= T
x(i) = 2;
else
x(i) = 0;
end
end
%-------------To plot Fourier transform figure 3(c)------------
omega = [-60: 0.01 :60];
F = zeros(size(omega));
for k = 1 : length(omega)
F(k) = trapz(t,x.*exp(-j*omega(k)*t)); %Fourier Transform
Formula
end
F_Magnitude = abs(F); %Magnitude of the Fourier Transform
subplot(3,1,3); plot(omega,F_Magnitude,'LineWidth',2);
ylim([0 T*5])
xlabel('\omega (rad/sec)');
ylabel('|H(j\omega)|');
title('Fourier Transform of Rectangular');
Waveform of all frequency in one

You might also like