moved distortion_filter,
generate_heartbeat, to NotWorking
This commit is contained in:
26
src/NotWorking/distortion_filter.m
Normal file
26
src/NotWorking/distortion_filter.m
Normal file
@@ -0,0 +1,26 @@
|
||||
% An audio is distorted based on the value of HIGH. Nothing of a certain
|
||||
% threshold should be played above this constant, or they are simply clipped to this
|
||||
% value. Inspired from Meghaj_Echo.m and epic_effect_schluep.m.
|
||||
% Author: Jason Liang
|
||||
|
||||
function y = distortion_filter(x, HIGH)
|
||||
len = length(X);
|
||||
X = fft(x);
|
||||
X = fftshift(X);
|
||||
Y = zeros(1, len);
|
||||
|
||||
for ind = 1:len
|
||||
if (X(ind) > HIGH)
|
||||
Y(ind) = HIGH;
|
||||
elseif (X(ind) < -HIGH)
|
||||
Y(ind) = -HIGH;
|
||||
else
|
||||
Y(ind) = X(ind);
|
||||
end
|
||||
end
|
||||
|
||||
Y = fftshift(Y);
|
||||
y = ifft(Y);
|
||||
y = real(y);
|
||||
|
||||
end
|
46
src/NotWorking/generate_heartbeat.m
Normal file
46
src/NotWorking/generate_heartbeat.m
Normal file
@@ -0,0 +1,46 @@
|
||||
function x = generate_heartbeat(amplitude, frequency, phase, fs, duration, duty)
|
||||
% GENERATE_SINE: returns a matrix of sampled heart monitor wave
|
||||
|
||||
% CONTRIBUTORS:
|
||||
% Alex Nguyen: Original Author
|
||||
% Conner Hsu: Reviewed Code and Assisted in polishing
|
||||
|
||||
% DOCUMENTATION:
|
||||
% phase shift is in number of periods
|
||||
% fs is the sampling frequency: how many sample points per second
|
||||
% duration is time in seconds
|
||||
% duty cycle should be a number between 0 and 0.5.
|
||||
% duty of 0 or less would return 0 for all sample points
|
||||
% duty of 0.5 or less would return a heartbeat signal since there would be
|
||||
% equal amount of space within 1 period to have the right and left sides be equal
|
||||
% duty of greater than 0.5 but less than 1 would return a slope starting at that duty i.e.
|
||||
% the left side but leaving little room to the right side
|
||||
% duty of between 1 and 2 would give a sawtooth wave in the +amplitude.
|
||||
% duty greater than 2 would return 0 for all sample points
|
||||
|
||||
|
||||
% initialize local variables from input arguments
|
||||
n = fs * duration; % number of samples (length of matrix)
|
||||
dt = 1 / fs; % sampling period: time between two sample points
|
||||
|
||||
|
||||
% initialize a one dimensional zero matrix to be populated
|
||||
x = zeros(1, n);
|
||||
|
||||
% populate the matrix
|
||||
for i = 1:n
|
||||
t = i * dt; % time at the i'th sample
|
||||
st = mod(frequency * t - phase, 1);
|
||||
|
||||
if (duty-(duty / 2) < st && st < duty)
|
||||
slope = amplitude / duty;
|
||||
intercept = -0.5 * amplitude;
|
||||
x(i) = slope * st + intercept;
|
||||
elseif (duty < st && st < duty+(duty / 2))
|
||||
slope = amplitude / duty;
|
||||
intercept = -amplitude;
|
||||
x(i) = slope * st + (1.5 * intercept);
|
||||
else
|
||||
x(i) = 0;
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user