Thanks, Christophe and Jerry. Using the cos(x) wave makes sense, providing a value of 1 and explains why I had a ridiculously small number when using sin(x).
Next, I will try to output all the time domain signals onto one output sink (spec-a) to keep the scaling the same and show the difference more clearly. Thanks for the help and lessons. On Mon, Apr 26, 2021 at 11:29 AM Christophe Seguinot < christophe.segui...@orange.fr> wrote: > of course twice not half. > > Thanks Jerry and sorry for writing to fast without correcting these > evidences! > > > On 26/04/2021 16:58, geraldfenkell wrote: > > is it not: The sampling frequency must be twice the max frequency to avoid > aliasing? > > regards > > Jerry VE3OBX > > ------------------------ > Hi James > > Your first signal (upper branch) is one of those I like to show to my > students to explain the Nyquist sampling theorem. > > 1- As Daniel said, sampling frequency Fs must be higher than *twice* the > maximum frequency Fmax: This is the Nyquist Sampling theorem, but don't > forget that this writes : *Fmax*2 > Fs* > > So in your flowgraph, the signal source breaks the rule: *1kHz=Fmax=Fs/2* > is not allowed. you could theoretically use Fs=0.8 0.9 or 0.99 kHz, not > 1.000 kHz ... but things are not so simple as explained below (3). > > 2- You signal (upper flowgraph branch) is a sine wave sample with 2 > samples / period since Fmax=F=Fs/2. So you are sampling a sine wave at > time t=kTs/2, that is exactly when your sine wave is zero. What you get > (nanoscale) is the error in the sin(kTs/2) computation. This result clearly > demonstrates that sampling with 2 samples/period is not possible (sometimes > it works, sometime not!). > > 2-bis- take your flowgraph, replace sine by cosine so that the signal get > sampled exactly when it amplitude is +1 or 1. Your time sink is closer to > the expected results, a sine wave... but the amplitude (I've got 0.04) is > not the one expected (lower than 1). This is due to the next point (3). > > 3- The sampling theorem states that is is possible to recover the original > signal from the sampled signal using an ideal low-pass filter, with a > transfer function H(f) so that H(f)=1 for f<Fmax/2 and H(f)=0 for > f>=Fmax/2, that is a filter with a transition bandwith of 0 Hz. This ideal > filter is not physically realizable. In gnuradio simulating this would > require and infinite number of coefficient. > > 3-bis- this explain why you don't get the correct amplitude in (2) : > because the filter used in the rational resampler has a finite transition > bandwidth. Try to lower the frequency to 0.8 or 0.9 to get a correct time > result (this depends on the transition bandwidth used in the rational > resampler). > > 4- This is why in real hardware and simulation, we generally use more than > 3 or 4 samples per period > > Regards > On 25/04/2021 22:26, James Hayek wrote: > > It definitely helps, thank you. One thing I noticed, and don't know how to > address is why the ""Correctly Sampled Signal"" Time Sink shows the > amplitude on the nanoscale.My signal source has an amplitude of one and the > Time Sink should be displaying a range from -1 to 1. > > I placed a rational resampler like you mentioned. I placed it after the > throttle block and before the Time Sink. I used an interpolation of 5 for > the signal that uses a variable sampling rate (2*freq) and see a nice sine > wave now. I am unsure how to do that for the signal source where I keep the > sample rate constant since a constant value of 5 distorts the signal. Is > there a way to tie this parameter to another? > > Yes, that's a good example. I see when freq is greater than samp_rate/2 > that the frequency sink displays an incorrect frequency. Maybe that's the > way to go about showing aliasing in GRC. > > > > On Sun, Apr 25, 2021 at 2:55 PM Daniel Estévez <dan...@destevez.net> > wrote: > >> El 25/4/21 a las 18:42, James Hayek escribió: >> > Apologies if I missed any response from my prior thread. >> > I wanted to elaborate more here, on what I am attempting to do. >> > >> > The goal is to create a GRC file to show how sampling rates affect a >> > generated signal. Knowing, for real samples, fs (sampling rate, >> > "samp_rate) would be greater than twice that of the highest >> > bandwidth (f, "freq"), I created a flow graph where one can adjust >> the >> > frequency whilst keeping the sampling rate constant. >> > >> > I would have imagined (since fs > 2B) for any frequency I set past >> > 1/2*fs, I would see distortion, and anything less would yield accurate >> > results. >> > >> > I created two sine wave Signal Sources. One where the _sample rate_ was >> >> > set to freq*2 and the _frequency_ was set to an adjustable variable, >> freq. >> > >> > The other where the _sample rate_ was set to a fixed samp_rate and the >> > _frequency_ was set to the same adjustable variable, freq. >> > >> > Both signals output to a QT GUI Time SInk. When I run the program, I see >> > the signal using a sampling rate of freq*2 is distorted >> > (triangular waveform) and the signal with the fixed sampling rate >> > distorts past a frequency of 1K Hz. I have the sampling rate to 32KSps. >> >> > Wouldn't it distort around 16KHz? What have I set up incorrectly? >> >> Hi James, >> >> Your results are perfectly fine. Nyquist theorem tells us that if we >> sample at a rate higher than 2*freq, then _it is possible_ to recover >> the original waveform. That's it. A key ingredient that sometimes is >> forgotten is the _it is possible_. >> >> What Nyquist doesn't say is that if you sample at a rate higher than >> 2*freq and join your samples with straight lines, then the result will >> look like a sine wave. Think about it, if you have very few samples per >> cycle of the sine wave, then you'll get something just like the >> triangular-ish wave you see. In order to have a very nice sine wave you >> need to have many, many points per cycle. And even so, if you zoom all >> the way in, the fact that you have a bunch of samples joined with >> straight lines will be visible. That always happens with discrete time >> sampling. >> >> The interesting question is then, how is it possible to recover the >> original waveform? This is basically done with sinc interpolation. You >> can try it yourself in GNU Radio by using the "Rational Resampler" block >> (for example) to interpolate your ugly triangular-ish waveform so that >> you get many points per cycle. You'll see a pretty sine wave of the >> correct frequency. >> >> Now the interesting part comes when you set your frequency higher than >> samp_rate/2. As long as you're generating a sine wave, you'll also get a >> pretty sine wave when you interpolate. However, the frequency of this >> sine wave will no longer be the "expected" one. In this way you can >> demonstrate aliasing. >> >> Hope this helps. >> >> Best, >> >> Dani. >> > > > > -- > Thanks, > James G Hayek > Youtube.com/JamesHayek > > -- Thanks, James G Hayek Youtube.com/JamesHayek