Home > utils > build_snd.m

build_snd

PURPOSE ^

function [waveform, T] = build_snd(freqs, amplitudes, phases, Fs, npts)

SYNOPSIS ^

function [waveform, T] = build_snd(freqs, amplitudes, phases, Fs, npts)

DESCRIPTION ^

 function [waveform, T] = build_snd(freqs, amplitudes, phases, Fs, npts)

 Constructs a sound from the components specified in the freqs vector
 The freqs vector must be accompanied by a phases vector of equal length
 which specifies the starting phases of each frequency component in degrees

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [waveform, T] = build_snd(freqs, amplitudes, phases, Fs, npts)
0002 
0003 % function [waveform, T] = build_snd(freqs, amplitudes, phases, Fs, npts)
0004 %
0005 % Constructs a sound from the components specified in the freqs vector
0006 % The freqs vector must be accompanied by a phases vector of equal length
0007 % which specifies the starting phases of each frequency component in degrees
0008 
0009 % Modification history:
0010 % 12/95     PJ     Wrote function
0011 % 1/15/96    PJ    Added amplitude vector
0012 % 11/11/98      PJ      Fixed phase value
0013 % 02/15/05      PJ      Phase value was incorrect.  Now really fixed
0014 
0015 if max(freqs) > Fs/2
0016   error(['Maximum specified frequency <' int2str(max(freqs)) '> greater than nyquist (' int2str(Fs/2) ')']);
0017 end
0018 
0019 freqs = freqs(:)';
0020 amplitudes = amplitudes(:)';
0021 phases = phases(:)';
0022 
0023 waveform = ones(npts,1)*amplitudes .* sin(2*pi*((0:npts-1)'/Fs*freqs + ones(npts,1)*phases/360));
0024 
0025 T = (0:npts-1)/Fs;
0026 
0027 if size(waveform,2) > 1
0028   waveform = sum(waveform,2);
0029 end
0030 
0031 return

Generated on Sat 25-May-2019 04:00:51 by m2html © 2003