how to use audiowrite

6 次查看(过去 30 天)
clear; clc; close all;
data= load('am_data.mat');
d=data.d';
%
ds = d(16000+1:16000+2560);
%
Ds = fftshift(fft(ds));
%
f = ((-2560/2) : (2560/2 - 1)) * 0.100;
plot(f,abs(Ds));
%
T=1/256000;
t=(1:length(d))*T;
fc=-17000;
%
dm=d.*(exp(-1i*2*pi*t*fc))';
%
Dm=fftshift(fft(dm(16000+1:16000+2560)));
%
figure();
plot(f,abs(Dm));
%
th = (-100:100)*T;
h = sin(10000*pi*th + 1e-6)./(10000*pi*th+1e-6);
%
figure()
plot(th,h);
%
dmf = conv(dm,h);
%
Dmf = fftshift(fft(dmf(16000+1:16000+2560)));
figure()
plot(f,abs(Dmf));
%
dmfs = dmf(1:32:end)/max(abs(dmf));
sound(real(dmfs));
pause;
%
sound(abs(dmfs));
%
audiowrite('test.wav',dmfs,256000);

采纳的回答

Star Strider
Star Strider 2024-5-1
You did not actually ask a question.
However I get the impression that ‘dmfs’ is complex, and that is not going to work. That argument has to be a (samples x channels) real matrix, so you either need to use:
audiowrite('test.wav',real(dmfs),256000);
or:
audiowrite('test.wav',abs(dmfs),256000);
to get it to work.
If you want to write extra channels with the imaginary or phase information, that is certainly possible.
Something like that might be:
audiowrite('test.wav',[real(dmfs) imag(dmfs)],256000);
or:
audiowrite('test.wav',[abs(dmfs) angle(dmfs)],256000);
For this, ‘dmfs’ must be a column vector.
You can reconstruct it after you read it.
If you want to save a complex vector, it might be easier to just use the save function to save it as a .mat file:
Fs = 256000;
save('dmfs.mat','dmfs','Fs')
.
  2 个评论
wissal
wissal 2024-5-1
you were right thank you so mush
Star Strider
Star Strider 2024-5-1
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Prediction 的更多信息

产品


版本

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by