MATLAB Answers

Wave file creation with Sine

22 views (last 30 days)
Karthik Brs
Karthik Brs on 21 Apr 2016
Commented: Karthik Brs on 25 Apr 2016
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

Answers (1)

Arnab Sen
Arnab Sen on 25 Apr 2016
Hi Karthik,
In the script linear interpolation is done which might create the issue. Try interp1 with spline option as below,
vq2 = interp1(x,v,xq,'spline');
xlim([0 2*pi]);
title('Spline Interpolation');
For more details, refer to the following link:
  1 Comment
Karthik Brs
Karthik Brs on 25 Apr 2016
Thank you for your time Arnab! I have tried with 'spline' and all the other interp1 methods, none works unfortunately!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!