\begin{tikzpicture}[scale=0.5]
  \def\hfreq{3}
  \def\vfreq{2}
  \matrix[column sep=0.5cm, row sep=0.5cm] {
     & 
      \begin{scope}[scale=0.5,xshift=0.5cm] 
        \draw plot[thin,domain=-0.5:7.5] function {(1 * (\hfreq > 0) + (1 / sqrt(8 / 2)) * (\hfreq == 0)) * cos((((2 * x + 1) * \hfreq * pi) / (2 * 8)))} node[right] {}; % $\frac{1}{\sqrt{N/2}} \cos \frac{(2x + 1) \cdot \hfreq \pi}{2 N}$
        \draw[->] (-0.5,0) -- (7.5, 0); 
        \draw plot[ycomb,thin,mark=*,domain=0:7,samples=8] function {(1 * (\hfreq > 0) + (1 / sqrt(8 / 2)) * (\hfreq == 0)) * cos((((2 * x + 1) * \hfreq * pi) / (2 * 8)))} node[right] {};
      \end{scope} 
    \\
      \begin{scope}[scale=0.5,yshift=0.5cm,rotate=90] 
        \draw plot[thin,domain=-0.5:7.5] function {(1 * (\vfreq > 0) + (1 / sqrt(8 / 2)) * (\vfreq == 0)) * cos((((2 * x + 1) * \vfreq * pi) / (2 * 8)))} node[right] {}; 
        \draw[->] (-0.5,0) -- (7.5, 0); 
        \draw plot[ycomb,thin,mark=*,domain=0:7,samples=8] function {(1 * (\vfreq > 0) + (1 / sqrt(8 / 2)) * (\vfreq == 0)) * cos((((2 * x + 1) * \vfreq * pi) / (2 * 8)))} node[right] {}; 
      \end{scope} 
    &  
      \begin{scope}[scale=0.5]
        \foreach \yinner in {0, 1, ..., 7} {
          \foreach \xinner in {0, 1, ..., 7} {
            % 2-D basis function
            \pgfmathparse{50 * (1 * (\vfreq > 0) + (1 / sqrt(8 / 2)) * (\vfreq == 0)) * (1 * (\hfreq > 0) + (1 / sqrt(8 / 2)) * (\hfreq == 0)) * cos((((2 * \yinner + 1) * \vfreq * pi) / (2 * 8)) r) * cos((((2 * \xinner + 1) * \hfreq * pi) / (2 * 8)) r) + 50} \pgfmathresult
            \fill[black!\pgfmathresult] (\xinner,\yinner) rectangle +(1,1);
          };
        };
      \end{scope}
    \\
  };
\end{tikzpicture}
