generate audio signals -凯发k8网页登录
this example shows how to generate audio signals using a 5.1 channel sound system.
load audio signal
load an audio file containing a sample of handel's "hallelujah chorus."
load handel;
plot audio signal
plot the data to identify five distinct segments. each segment represents a "hallelujah" in the chorus. the segments are annotated as 1 to 5.
ly = length(y); lspan = 1:ly; t = lspan/fs; hf = figure; plot(t,y./max(y)) axis tight; title("signal (handel''s hallelujah chorus) vs time"); xlabel("time (s)"); ylabel("amplitude"); markers = struct('xpos',[0.2,0.4,0.55,0.65,0.8],'string',num2str([1:5]')); for i = 1:5, annotation(hf,'textbox',[markers.xpos(i) 0.48 0.048 0.080],'string', markers.string(i),'backgroundcolor','w','fontsize',16); end
create a dataacquisition and add audio output channels
this example uses a 5.1 channel sound system with device id 'audio2'
.
1. create a dataacquisition with directsound
as the vendor and add an audio output channel to it.
dd = daq("directsound"); nch = 6; addoutput(dd, "audio2", 1:nch, "audio");
2. update the generation scan rate to match the audio sampling rate.
dd.rate = fs;
3. generate audio signals (handel's "hallelujah chorus"). "hallelujah" should be voiced five times, one for each segment depicted in the figure on all channels of the speaker system.
write(dd, repmat(y,1,nch));
4. close the figure.
close(hf);