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: clc;clear all;
%synthetic example
%in practice it seems that a period T = 2*maxFreq is not enough -> i choose
%10
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;
the objective is to play this sine wave y at the correct sampling frequency Fs in such as way as to obtain a perceptually (audio going out from the speakers) of 1KHz.
My idea is to generate a very high frequency sine, here 10^6 Hz, and then play it at a sampling freq Fs such that we obtain 1KHz. I computed that i need Fs = 909.09, however Matlab refuses that and i get this error message in console:
a =
audioplayer with properties:
SampleRate: 909.0900
BitsPerSample: 16
NumberOfChannels: 1
DeviceID: -1
CurrentSample: 1
TotalSamples: 10000000
Running: 'off'
StartFcn: []
StopFcn: []
TimerFcn: []
TimerPeriod: 0.0500
Tag: ''
UserData: []
Type: 'audioplayer'
Error using audioplayer/resume (line 766)
Device Error: Invalid sample rate
Error in audioplayer/play (line 125)
obj.resume();
Error in sineExample (line 25)
play(a)
Maybe my reasoning is wrong. Can someone help me to think about this/clarify/correct my (potential) mistakes?
play
, not inaudioplayer
– Ander Biguri