Why do I get additional frequencies using standard audiowrite BitsPerSample values?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nik Rocky
el 8 de Sept. de 2022
Comentada: Mathieu NOE
el 13 de Sept. de 2022
Hello,
I want to write spectral data to wav file and read it again.
If I do some example with two sine waves, after writing+reading a wav file I get more frequencies in spectrum (aliasing/quantization noise?).
% generate sin-waves
wave = dsp.SineWave(Frequency=2.45e6,SampleRate=5e6);
wave.SamplesPerFrame = 1024;
wave2 = dsp.SineWave(Frequency=2.46e6,SampleRate=5e6);
wave2.SamplesPerFrame = 1024;
% save and visualize
scope1 = spectrumAnalyzer(SampleRate=wave.SampleRate,...
ViewType="spectrum-and-spectrogram",...
PlotAsTwoSidedSpectrum=false);
%data = [];
y = [];
for ii = 1:250
x = wave() + 0.5*wave2()+ 0.05*randn(1024,1);
scope1(x);
pause(0.01)
if scope1.isNewDataReady
y = [y,x];
%data = [data;getSpectrumData(scope)];
end
end
% set
Fs = 48000;
% write wav
audiowrite(wavefile,y,Fs,'BitsPerSample',16);
% visualize output orig
scope2 = spectrumAnalyzer(SampleRate=wave.SampleRate,...
ViewType="spectrum-and-spectrogram",...
PlotAsTwoSidedSpectrum=false);
for a = 1:width(y)
scope2(y(:,a))
pause(0.01)
end
% read wav
[b,Fs] = audioread('test.wav');
info = audioinfo('test.wav');
% visualize output wav
scope3 = spectrumAnalyzer(SampleRate=wave.SampleRate,...
ViewType="spectrum-and-spectrogram",...
PlotAsTwoSidedSpectrum=false);
for a = 1:width(b)
scope3(b(:,a))
pause(0.01)
end
when I change BitsPerSample parameter to 32/64:
% write wav
audiowrite(wavefile,y,Fs,'BitsPerSample',64);
I get a right values/signal form.
Why it is happends? It is aliasing/quantization noise?
0 comentarios
Respuesta aceptada
Mathieu NOE
el 8 de Sept. de 2022
hello
if you export data to wav format , you have to make sure that the amplitude do not exceed +/- 1 otherwise the signal will be clipped and there you have a distorted signal (and that's why you get all the spurious frequencies)
seems to me this condition is not met as I can see the FFT peaks are well above 0 dB => clipping !
x = wave() + 0.5*wave2()+ 0.05*randn(1024,1);
% and normalize !!
x = x./max(abs(x));
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!