0% found this document useful (0 votes)
22 views2 pages

Square & Rect

This document contains code to generate a square wave using a trigonometric Fourier series with the first 30 terms. It plots the approximated square wave over time as each additional term is included in the series. It also contains code to plot an ideal square wave over time for comparison by defining sections that are 1s or 0s and combining them.

Uploaded by

Eysha qureshi
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)
22 views2 pages

Square & Rect

This document contains code to generate a square wave using a trigonometric Fourier series with the first 30 terms. It plots the approximated square wave over time as each additional term is included in the series. It also contains code to plot an ideal square wave over time for comparison by defining sections that are 1s or 0s and combining them.

Uploaded by

Eysha qureshi
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/ 2

Compact trigonometric fourier series of square wave:

clc
clear all
close all
t = linspace(-0.001,0.001,100000); % time
x=0;
for k=1:2:30;

x=x+((4*(sin(2*pi*k*t*1000)))/(pi*k)); % computes nd add the k-th terms of the


series
plot(t,x,'black');
grid on;
hold on

end
xlabel('time');
ylabel ('magnitude');
title('Square wave');

RECT:
t1=0:1:5;
t2=-5:1:0;
y1=ones(size(t1));
y2=zeros(size(t2));
t=[t2 t1];
y=[y2 y1];
plot(t,y)
hold on
plot(-t+5,y)
ylim([-5 5])

You might also like