Question

In MATLAB, generate a square wave of period 1s and length of 8s, sampled at 1024HZ. The maximum v...

In MATLAB, generate a square wave of period 1s and length of 8s, sampled at 1024HZ. The maximum value of the wave is 1 and the minimum value is -1. Take the fft of this data. Show both plots. The fft should represent Fourier series representation of the wave in lecture, comment on this aspect. Comment on the difference in FFT when I sample for 8.01 sec instead of 8 sec.

1 1
Add a comment Improve this question Transcribed image text
Answer #1

clc;
clear all;
close all;
%%%%%%generation of square wave%%%%%%%%%%%%%
f=1; %frequency of square wave
Fs=1024; %sampling frequency
ts=1/Fs;   
N=32*256; %we are using 256 point fft
t=0:ts:N*ts;
x=square(2*pi*f*t); %generating square wave
figure;
plot(t,x); %plotting square wave
xlabel('time');
ylabel('amplitude');
title('suqare wave');
%%%generating fourier transform
y=fft(x);
y=fftshift(y);
P2=abs(y/N);
P1 = P2(1:N);
P1(2:end-1) = P1(2:end-1);
f = Fs*((-N/2):(N/2-1))/N; %%%generating frequency
figure;
plot(f,P1);
title('N=256 point fft');
xlabel('frequency (Hz)');
ylabel('|X(f)|/N');

clc: clear all: close all 동동동동동몽genera tion of f-1; F3 1024; %sampling square wave 동동동동동동동동동동% frequency of square wave frequsuqare wave 0.8 0.6 0.4 0.2 ー0 0.2 0.4 0.6 0.8 4 8 timeN-256 point fft 0.7 r 0.6 0.5 0.4 0.3 0.2 0.1 0 -600 -400 -200 200 400 600 frequency (Hz)

Add a comment
Know the answer?
Add Answer to:
In MATLAB, generate a square wave of period 1s and length of 8s, sampled at 1024HZ. The maximum v...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT