0

I have applied a DCT (type 2) to a vector of values acquired from a sensor, of length $N = 8$. I received a vector of DCT coefficients. How can I find out the frequency of each bin in Hz? The sampling frequency of initial values is 10000 Hz.

Jdip
  • 5,980
  • 3
  • 7
  • 29
Azazel
  • 9
  • 1
  • 1
    It's right there in the formula, could you elaborate what the question is? – Marcus Müller Nov 19 '21 at 09:38
  • as example, we have vector of values x = [16, 11, 10, 16, 24, 40, 51, 61]. after applying dct we receive vector of values X = [80.9637 -47.811 19.3879 2.1278 1.76777 0.863142 1.53637 -1.82703]. so what frequency does the value 80.9637 or -47.811 represent? what is the formula to find out the frequency for each coefficient – Azazel Nov 19 '21 at 12:49
  • look at the formula of the DCT-II, not at the numbers. Do you know how to read the frequency from the argument of the cosine? – Marcus Müller Nov 19 '21 at 12:50
  • in DCT-II formula we have cos ( pi / N * (n + 1/2) * k ). N = length of dct, k = bin number. but we also have n, because this cosine is taken from summ. what should i do with this n? i cant calculate this. as for reading frequency from the argument, i know that frequency of A * cos (Bx - C) + D is B / 2pi. i don't understand how to deal with this all, can you write the correct formula please? is this something like (pi / N * k) / 2pi ? – Azazel Nov 19 '21 at 14:34
  • I know that frequency of A · cos (Bx - C) + D is B / 2pi. Exactly! Now you realize n is your variable (instead of x), so you equate $Bn - C = \pi/N (n+\frac12)k$, and solve for $B$. – Marcus Müller Nov 19 '21 at 15:06
  • i solved the equation for B and got B = (2 * C * N + k * pi + 2 * k * n * pi) / (2 * n * N). how can i use it? even if i apply the formula above, i get frequency = (2 * C * N + k * pi + 2 * k * n * pi) / (4 * n pi N). i still can't get frequency in Hz, because of unknown variables (we know N, k and of course pi) – Azazel Nov 19 '21 at 18:47
  • ah, but with that frequency you can calculate the period in samples! And if you know how long a period is in samples, and you know the sampling rate, you know how long the period is in seconds. and if you know how long a period is in seconds, then you know the frequency in Hertz. – Marcus Müller Nov 19 '21 at 19:52
  • (also, you still have $n$ in your frequency. you hence didn't solve correctly. $n$ is the discrete time variable.) – Marcus Müller Nov 19 '21 at 19:53
  • i tried to check myself and solved via WolframAlpha. here is the link to the result. there is "n" in the result, how can i reduce this variable? and what should i use for C - should i use 0 for it? – Azazel Nov 20 '21 at 01:14
  • I really don't see how this can be done incorrectly, it's a linear equation! Do you perhaps confuse $n$ and $N$? Anyway, although I feel this is basic math, I thought it might be helpful to demonstrate it once, so see my answer please. – Marcus Müller Nov 20 '21 at 12:23

1 Answers1

2

i know that frequency of A * cos (Bx - C) + D is B / 2pi

Exactly. So let's take the DCT-II:

$$X[k]:=\sum_{n=0}^{N-1} x_n \cos \left[\, \tfrac{\,\pi\,}{N} \left( n + \frac{1}{2} \right) k \, \right] \qquad \text{ for } ~ k = 0,\ \dots\ N-1$$

and look at the argument of the cosine.

\begin{align} \frac\pi N\left( n+\frac12 \right) k &= \underbrace{\pi \frac kNn}_{Bn} + \underbrace{\pi\frac k{2N}}_{-C}\\[1em] B&=\pi\frac kN \end{align}

Therefore, the frequency is $\frac k{2N}$, which should align nicely with any explanation of how to construct the bases: you take the Nyquist rate and divide it into $N$ even parts.

Now, this is frequency relative to your sampling rate, so all you need to do is realize (see comments):

with that frequency you can calculate the period in samples! And if you know how long a period is in samples, and you know the sampling rate, you know how long the period is in seconds. and if you know how long a period is in seconds, then you know the frequency in Hertz.

So, this is really just the fraction of your sampling rate. Note that relative frequencies are really the basics of any discrete signal theory introduction, which means you might benefit from revisiting an introductory book on discrete-time signal processing (e.g. the Oppenheim book of the same title) in its first chapters.

Marcus Müller
  • 30,525
  • 4
  • 34
  • 58