How draw the frequency response

I'm learning signal processing on my own and I'm in the filters, I chose the moving average because it seems the simplest.

What I want to know is how to draw the frequency response of the moving average. I'm using p5j to draw. if you do not know p5j is a program to draw with code.

This is my sketch

https://editor.p5js.org/molo32/sketches/cX6VR6tAt

What I do is create a square wave and apply the moving average, after that I would like to draw the frequency response.

The sine wave above is just to show how to draw a can ignore it if it wants

Feel free to edit the code

Do not forget to pass me the code when I finish drawing the diagram above

• Just a bit on nomenclature: a system (for example, a filter) has a frequency response. A filtered signal is still a signal; that has a spectrum! So, how would one go about this on paper (so to translate it to code later)? One would first find the spectrum of the input signal (your square wave), then find the frequency transponse of your filter, and then multiply the two; the effect should be very much like what you'd expect from applying a moving average to a square wave (try imagining that graphically!). – Marcus Müller May 4 at 19:11
• and what you show in your question is actually not a sine wave – it's a sinc, which happens to be the frequency response of a moving average filter; I think you are confusing a few thins? – Marcus Müller May 4 at 19:14