-
Notifications
You must be signed in to change notification settings - Fork 1
/
generateAudio.m
32 lines (24 loc) · 879 Bytes
/
generateAudio.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function finalAudioOutput = generateAudio (Pr_Audio, srate, srate_mul)
second = 1;
hertz = 1/second;
maxPressure = max(Pr_Audio);
audioOutput = Pr_Audio./maxPressure;
audioOutput(audioOutput>1) = 1;
audioOutput(audioOutput<-1) = -1;
% Generate a low pass butterwoth filter (IIR)
fc = 22050*hertz; % Cutoff Frequency
wc = (2*pi*fc)/srate;
% create butterworth filter
order = 2; % filter order
[b, a] = butter(order, wc);
% Frequency response of the digital filter
freqz(b, a);
% filter the original signal
filtered_audio = filter(b,a, audioOutput);
% downsample the signal
finalAudioOutput = filtered_audio(1:srate_mul:end);
% play the audio
sound(finalAudioOutput, 1*44100);
% save audio file
audiowrite('audioSound.mp4',finalAudioOutput,44100);
end