4

System is debian 10 with gnuradio 3.7.

untitled.grc create simple flow graph as below:
enter image description here

The only difference between 2 flows is bandwidth of gui sink,cause 2 different signal frequency as below:

enter image description here

Why Gnuradio bandwidth of sink cause signal frequency changed?

kittygirl
  • 600
  • 2
  • 10

1 Answers1

5

Gnu Radio doesn't really know anything about frequency in cycles per second (Hz), only cycles per sample. The left of the chart is -0.5 cycles per sample, the middle is 0 cycles per sample, and the right is +0.5 cycles per sample. It's up to you to enter the correct numbers for "bandwidth" and "center frequency" if you want the scale on the bottom to correctly map the frequency back to cycles per second.

For example, your two signal source blocks are configured with a sample rate of 32k and a frequency of 10k (Hz). This means they will output a signal at a frequency of:

$$ \require{cancel} {10\mathrm k\ \text {cycles} \over \cancel{\text{second}}} \times {\cancel{\text{second}} \over 32\mathrm k\ \text {samples}} = {0.3125\ \text{cycles} \over \text {sample}} $$

Try configuring these signal sources to output 20 kHz at a sample rate of 64 ksps: you'll find they output the same thing, because 20/64 is also equal to 0.3125.

If you know the sample rate, then you can divide a frequency in Hz by the sample rate to get frequency in cycles per second.

Or you can multiply by the sample rate to convert cycles per sample to frequency in Hz.

None of the blocks know the sample rate except what you configure in the block's parameters. Any block that asks for or provides any number in Hz is implicitly making this conversion between cycles per sample and cycles per second. If you enter incorrect information in these parameters, you will get incorrect results.

The default GRC project has a variable sample_rate, and the "Bandwidth" parameter defaults to that. You might want to change that if you are decimating or interpolating the sample stream, but in the example provided you'd want to leave it at the default so the GUI sink's "bandwidth" is equal to the signal source's "sample rate".

Phil Frost - W8II
  • 51,321
  • 5
  • 84
  • 209
  • In the `untitled.grc`,I set `bandwidth` of GUI SINK to `samp_rate*10`,why the peak of `frequency` move to `100khz`? – kittygirl Aug 27 '21 at 08:58
  • @kittygirl I expanded the answer more. The signal didn't move: you just configured the block to perform a different conversion between cycles per sample and cycles per second. – Phil Frost - W8II Aug 27 '21 at 13:29
  • I guess the formula result should be `0.3125 cycles/sample`? – kittygirl Aug 27 '21 at 18:49
  • `in the example provided you'd want to leave it at the default`,that's not true. I `set bandwidth to samp_rate*10` – kittygirl Aug 27 '21 at 18:54
  • Thanks again for your answer. As `Gnu Radio doesn't really know anything about frequency in cycles per second (Hz)`,how `Frequency(khz)` showed and not equal in result(as attached picture)? – kittygirl Aug 27 '21 at 18:59
  • @kittygirl no, you _do_ want to leave it at the default. Because if you don't you're lying to the GUI sink block, and it's going to believe you and give you wrong results. So stop lying, and it will work. The sample rate is `sample_rate`, not `sample_rate * 10`. – Phil Frost - W8II Aug 27 '21 at 19:17
  • Hey @PhilFrost-W8II , did you want that to result in $\frac{0.3125 cycles}{samples}$? – David Hoelzer Aug 27 '21 at 19:41
  • 1
    good catch, thanks – Phil Frost - W8II Aug 27 '21 at 19:44
  • `The sample rate is sample_rate`,agreed.I set `bandwidth` in `QT gui sink` to `sample_rate * 10`.Does it affect `sampe rate` in `QT gui sink` ?I don't think so.Then,what cause `Frequency(khz)` moved to `100` from `10`? – kittygirl Aug 27 '21 at 19:46
  • @kittygirl You might as well ask why if π=6 what causes the area of all circles to get bigger. The circle didn't get bigger and the frequency of your signal didn't change. You simply entered the incorrect conversion factor between cycles per second and cycles per sample. The "bandwidth" and "center frequency" parameters don't do anything except change the scale on the chart. Don't enter wrong numbers there, and the results won't be wrong. – Phil Frost - W8II Aug 27 '21 at 19:51
  • I believe `"bandwidth" and "center frequency" parameters don't do anything except change the scale on the chart`,then I set `band width` to `sample_rate * 10`,but `Frequency(khz)` changed.That's what I concern. – kittygirl Aug 27 '21 at 20:02
  • @kittygirl Why do you think the frequency(kHz) changed? Did you read it off the scale on the chart? Maybe the scale is wrong because you entered the wrong bandwidth? – Phil Frost - W8II Aug 27 '21 at 20:16
  • @kittygirl You seem to think the scale on the chart is telling you the frequency, but actually you're just telling the GUI sink how to draw the scale, and then asking why the frequency changed when you tell it to draw the scale differently. _The frequency is not changing_. You're just telling the sink to draw a different scale. It's up to you to figure out the right parameters to put in "bandwidth" and "center frequency" to draw the right scale. – Phil Frost - W8II Aug 27 '21 at 20:20
  • I never get this counterintuitive info about `read frequency based on scale` in gnuradio website.Maybe that's a bug? – kittygirl Aug 28 '21 at 11:25
  • @kittygirl it is a bug, but it's your fault. GNU Radio is a framework for writing programs that do signal processing. You wrote a buggy program, that displays the wrong scale on the frequency sink. It's _your_ responsibility to correctly perform the conversion from cycles/sample to cycles/second. To do this, the GUI sink needs to know the _correct_ sample rate. If you give it the wrong sample rate you've written a bug. The GUI sink doesn't know the sample rate, and that's why it asks you. Don't lie to it! – Phil Frost - W8II Aug 28 '21 at 18:22
  • You mentioned `Gnu Radio doesn't really know anything about frequency in cycles per second (Hz)`.After DFT,if Gnuradio doesn't knows the frequency(Hz),how can we get the frequency domain information? – kittygirl Sep 02 '21 at 20:16
  • @kittygirl The DFT calculates frequency in cycles/sample (not cycles/second). Converting between cycles/sample and cycles/second is what the math at the start of this answer shows. – Phil Frost - W8II Sep 02 '21 at 21:35