Wave file creation with Sine
4 次查看(过去 30 天)
显示 更早的评论
Hello everyone, I have produced a wave sound file for a given data which contains information about the sound pressure and frequency. I am using the equation y = A sin(2*pi*f*t) to produce sound. I am using sound pressure as amplitude. What's strange is, when I produce the sound using this method, I am getting frequency components which are exactly double the original frequency values. When I remove the 2 from the Sin(2*pi*f*t), its working! Also, I observed that, when I use interpolated values for frequency(from 'interp1'), I am getting this 'double frequency' problem, without the interpolation, Sin(2*pi*f*t) works fine. Do any of you have an explanation for this? I am including my script here:
fs = 44100; % Sampling frequency
Paco = 10^-12; % Reference sound power
Po = 2*10^-5; % Reference sound pressure of '20µPa' (at 1000 Hz.)
r = 1; % Distance to the sound source from the listener
Q = 4; % Directivity factor for a point source
filename_audiowrite = sprintf('SSD_audiowrite_%d.wav',ii);
t_ramp = 20; %[secs]
t = 0:1/fs:t_ramp-1/fs;
RPM_max = max(cell2mat(RPM));
Frq = cell2mat(frq);
Wav_sum = 0;
for tv = 1:ordn
t_v{tv} = RPM(tv)/RPM_max*t_ramp; %Creation of individual Time Vectors
TLw_intrp{tv} = interp1(cell2mat(t_v(tv)),ord(tv).total_lw,t,'linear','extrap'); % Interpolating the values of sound power at different times for linear ramp
f_intrp{tv} = interp1(cell2mat(t_v(tv)),ord(tv).freq,t,'linear','extrap');
SPrL{tv} = cell2mat(TLw_intrp(tv))+10*log10(Q/(4*pi*r*r)); % Conversion of Sound power(TLw dB) to Sound Pressure Level(SprLdB)
Spr{tv} = sqrt(2)*(Po*(power(10,cell2mat(SPrL(tv))/20))); % Conversion of Sound Pressure Level(SprLdB)to Sound Pressure(Spr Pa)
Wav{tv} = cell2mat(Spr(tv)).*sin(pi*cell2mat(f_intrp(tv)).*t); % Data for the Wave file
Wav_sum = Wav_sum + cell2mat(Wav((tv))); % Summation of wav data for all time orders
end
audiowrite(filename_audiowrite,Wav_sum,fs,'BitsPerSample',32)
end
end
0 个评论
回答(1 个)
Arnab Sen
2016-4-25
Hi Karthik,
In the script linear interpolation is done which might create the issue. Try interp1 with spline option as below,
figure
vq2 = interp1(x,v,xq,'spline');
plot(x,v,'o',xq,vq2,':.');
xlim([0 2*pi]);
title('Spline Interpolation');
For more details, refer to the following link:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!