0
$\begingroup$

I have a rather strange but i thin interesting question. The idea is to gain a better understanding of sampling rate vs frequency shifting when playing audio. The idea is a little experiment:

%synthetic example

T=1/(10*10^6);%period should be at least 1/(2*10^6Hz) => Nyquist freq if we want to be able to reproduce 10^5Hz max freq
x=0:T:1-T;

f=10^6;%frequency
y=sin(2*pi*f*x);

%i see visually that there is 11 samples constituting 1 period
%plot(y(1:11))
%plot(y(100:111))
%etc
nbPeriods=length(y)/11;%nbtotalsamples/nbsamplesOf1Period
%y contains 10^6 oscillations each of 11 samples
%therefore if i want to reproduce a 1Khz sound, I compute my sampling frequency :
% Fs = nbPeriods/10^3 

Fs=909.09;

a=audioplayer(y,Fs)

tic;
play(a)
toc;

my question is: is this reasoning correct? -> that Fs should be 909.09 to get a 1kHz sine wave from f=10^6;y=sin(2*pifx); when played at Fs=909.09 and considering of course the x range i have taken?

EDIT: following your answer would this (the comments!) be correct now:

clc;clear all;
%synthetic example

T=1/(10*10^6);%
x=0:T:1-T;%my sampling rate is 1/T= 10*10^6 =10MHz

f=10^6;%frequency
%y: as if i had 1 period T of a sampled signal (sampled at 10MHz)
y=sin(2*pi*f*x);%this signal has a freq of 1 MHz , according to 
%Nyquist Shannon sampling thm the MAX freq i could capture with 
%my sampling rate of 10MHz would be 5 MHz,
%so i am a bit below that with my 1MHz


%given that i want to create a 1KHz wave from y i must sample at
% (10*10^6 samples)/(10^3 samples)  = 10^4 10 KHz
%idea: cutting my 10M samples into chunks of 10^3 oscillations
Fs=10^4;

a=audioplayer(2*y,Fs/4)

tic;
play(a)
toc;

%indeed it plays now a sound that "sounds" like a reference 1KHz wave,

$\endgroup$
1
$\begingroup$

You reasoning is NOT correct. One period is 10 samples long, not 11. The 11th sample is the first sample of the 2nd period, not the last sample of the 1st period.

So originally you have

  1. sample rate: 10 MHz
  2. sine wave frequency: 1 MHz, which is 1/10th of the sample rate

If you want to get a 1 kHz sine wave you need to set the sample rate to 10 times 1 kHz, i.e. 10 kHz. If you play it back at a sample rate of 909 Hz, your resulting frequency would be 90.9 Hz.

$\endgroup$
  • $\begingroup$ and if i understand correctly you consider that my sample rate is 10MHz because i have 10*10^6 samples in x, as if i had 1 period of 10*10^6 samples (discretized in x) i.e. as if i had sampled a hypothetical signal (of unkown frequency but of freq of at least 1MHz) with a sample rate of 10MHz for 1 sec ? ^^ (just to be sure) $\endgroup$ – John Doe Aug 6 '18 at 16:59
  • $\begingroup$ he knows because you define it that way in your first line of code... $\endgroup$ – Marcus Müller Aug 6 '18 at 17:24
  • $\begingroup$ yes that's my point it is that we consider that this x is 1 period (of 10^7 samples) ? -> therefore being (to give a concrete theoretical example) the result of sampling a hypothetical signal at a Fs=10MHz $\endgroup$ – John Doe Aug 6 '18 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.