Merge branch 'DarellsAnnex'

This commit is contained in:
Darell Chua Yun Da 2021-12-02 13:46:20 +08:00
commit 74586d31c6
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,20 @@
function output_y = DarellbandpassFilter(y,Fs,LOW,MED,HIGH)
Len = length(y);
F = Fs * (-Len/2 : (Len/2 - 1))/Len ;
Mod_Freq = fftshift(fft(y));
lenf = length(F);
output = 0 .* Mod_Freq; % zero array of len f
for n = 1:lenf
if ((LOW < abs(F(n))) && HIGH > abs(F(n)))
output(n) = 1;
else
output(n) = 0;
end
end
filtered_Mod_Freq = fftshift(Mod_Freq .* output);
output_y = real(ifft(filtered_Mod_Freq));
end

25
src/Main_test.m Normal file
View File

@ -0,0 +1,25 @@
%Basic Example test
%Written by Darell
amplitude = 1;
frequency = 200;
phase = 0;
fs = 44800;
duration = 1;
duty = 0;
%example Sine Generation
x = generate_sine(amplitude, frequency, phase, fs, duration, duty);
x = x + generate_sine(amplitude, (frequency+5), phase, fs, duration, duty);
%play over 5 counts, should hear both frequencies, 5 beats between the 2 frequencies
playtime = 5;
play_continuous(x, fs, playtime)
LOW = 0;
HIGH = frequency + 1;
MED = "unused";
x = DarellbandpassFilter(x,fs,LOW,MED,HIGH);
%play over 5 counts, should only hear 200hz
playtime = 5;
play_continuous(x, fs, playtime)

9
src/play_continuous.m Normal file
View File

@ -0,0 +1,9 @@
function play_continuous(wave, fs, time)
%play_continuous: Darell Continuously Playing
soundfile = audioplayer(wave,fs);
countmax = time / (length(wave) / fs);
for count = 0:1:countmax %change to counts/while play button active
playblocking(soundfile);
end
end