Home / Expert Answers / Electrical Engineering / nbsp-lab-task-1-i-write-a-matlab-code-to-find-the-magnitude-spectrum-of-a-square-wave-also-pl-pa305

(Solved):   Lab Task 1: i) Write a Matlab code to find the magnitude spectrum of a square wave. Also pl ...



Lab Task 1:
i) Write a Matlab code to find the magnitude spectrum of a square wave. Also plot
the square wave and correspondi

 

Lab Task 1: i) Write a Matlab code to find the magnitude spectrum of a square wave. Also plot the square wave and corresponding frequency domain representation of a square wave. Take t=0:0.01:2*pi. ii) Take N as an input number from user and consider only odd harmonics (kodd) and t=-n: 1/1000: n. Use Gibb's phenomenon to Plot x (t) against "t". Your output should look like as follows: MATLAB CODE and O/P: Making a Square Wave using 99 Harmonics 0.8 0.6 0.4 Time (sec) Making a Square Wave using 500 Harmonics Time (sec) a 0.4 02


We have an Answer from Expert

View Expert Answer

Expert Answer


1. clc clear all close all t = 0:(1/1e6):(10/1e5); x = 2.5*square(t*2*pi*1e5,50); N = length(x); fs = 10e5; figure(1) plot(t,x) X = abs(fft(x))/N; bins = (0:(N-1)); f = (bins*fs)/N; intN = ceil(N/2); figure(2) plot(f(1:intN),X(1:intN)) xlabel('Freque
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe