# sampling rate Matlab

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?

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,