Amanni Amanni - 5 months ago 81
C++ Question

Generating a square wave for DFT

I'm working on an assignment to perform a 200 point DFT at a sampling frequency of 20kHz on a square wave of frequency 500Hz whose amplitude alternates between 0 and 20.

I'm using C++ and I have figured how to code the DFT equation, my problem is I'm having trouble representing the square wave in code using a for loop.

What I'm really still confused about is how many cycles of this square wave will be in my 200 point sample.



One cycle of your square wave will take 1/500 seconds. Each sample will be 1/20000 seconds. A simple division should tell you how many samples each square wave will be.

Another division will tell you how many of those waves will fit in your 200 point window.