This commit is contained in:
TurtleEmperorx 2021-12-10 13:56:01 -08:00
commit 300cf17c70
10 changed files with 211 additions and 13 deletions

Binary file not shown.

View File

@ -0,0 +1,33 @@
function x = generate_pulse(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_puse: returns a matrix of sampled pulse wave
% CONTRIBUTORS:
% Brian Tran: Created the wave
% 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 is a number between 0 and 1
% 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);
f0=1e+6; % 1MHz
Fs=3e+6;
Tf=0.001; % 1 millisecond
t=0:1/Fs:Tf-1/Fs;
td=0.1; % duty cycle
A0=10; % 10 Volts
F=0;
N=1000; % Number of points
% populate the matrix
for n = 1:N
F=F+(1/n)*cos(n*2*pi*f0*t).*sin(n*pi*td);
end
F=F*(2*A0/pi);
F=F+A0*td;
end

View File

@ -12,16 +12,30 @@ function output = fade_in(input, time)
len = length(input);
% need to use whole number for time
time = round(time);
% if time parameter longer than signal, treat time as
% the duration of original signal
if time > len
time = len
time = len;
end
% in order to create array, time >=1
% if not, it's arbitrarily set to 1
% in which case the fade_in effect
% is virtually nonexistent
if time < 1
time = 1;
end
% set multiplier as 1D array
% fade in effect: from no volume to full volume of signal
multiplier = (1 : time) / time;
while length(multiplier) < len
multiplier = [multiplier 1];
end
% the resulting fade-in output
output = input .* multiplier;
end

View File

@ -11,18 +11,33 @@ function output = fade_out(input, time)
len = length(input);
% need to use time as a whole number
time = round(time);
% if time parameter longer than signal, treat time as
% the duration of original signal
if time > len
time = len
end
% in order to create array, time >=1
% if not, it's arbitrarily set to 1
% in which case the fade_in effect
% is virtually nonexistent
if time < 1
time = 1;
end
% set multiplier as 1D array
multiplier = (1 : time) / time;
% fade out effect: from full volume of signal to no volume
multiplier = flip(multiplier)
multiplier = flip(multiplier);
while length(multiplier) < len
multiplier = [multiplier 0];
end
% the resulting fade-in output
output = input .* multiplier;

View 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

View File

@ -1,26 +1,26 @@
%Written by Darell
%Written by Darell, edited by Arthur Lu
% CONTRIBUTORS:
% Person1: Darell
% Person2: Arthur Lu
% DOCUMENTATION:
%Pass-through function used by app
function output = SoundGeneratorSelect(amplitude, frequency, phase, fs, duration, duty,number)
if(number == "Option 1")
if(number == "Sine")
output = generate_sine(amplitude, frequency, phase, fs, duration, duty);
elseif(number == "Option 2")
elseif(number == "Square")
output = generate_square(amplitude, frequency, phase, fs, duration, duty);
elseif(number == "Option 3")
elseif(number == "Triangle")
output = generate_triangle(amplitude, frequency, phase, fs, duration, duty);
elseif(number == "Option 4")
elseif(number == "Sawtooth")
output = generate_sawtooth(amplitude, frequency, phase, fs, duration, duty);
elseif(number == "Option 5")
elseif(number == "WhiteNoise")
output = generate_white(amplitude, fs, duration);
elseif(number == "Option 6")
elseif(number == "HalfCircle")
output = generate_halfCircles(amplitude, frequency, phase, fs, duration, duty);
else
output = 0;
output = zeros(1, fs * duration);
end
end

30
src/distortion_filter.m Normal file
View File

@ -0,0 +1,30 @@
% 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
% Mekhi Ellington: Added some comments and editted formatting
function y = distortion_filter(x, HIGH)
len = length(X); %Storing length of X.
X = fft(x); %X is the Fourier Transform of x.
X = fftshift(X); %Shifts X.
Y = zeros(1, len); %Matrix of length containing zeros.
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); %Shifts Y.
y = ifft(Y); %Inverse Fourier Transform of Y.
y = real(y); %Stores only the real part of the complex y.
end

25
src/generate_cosine.m Normal file
View File

@ -0,0 +1,25 @@
function x = generate_cosine(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_WAVENAME: returns a matrix of sampled WAVENAME wave
% CONTRIBUTORS:
% Mekhi Ellington: Original Creator
% 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 is a number between 0 and 1
% 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;
x(i) = amplitude * cos(2*pi*frequency*t-phase);
end
end

55
src/generate_trapezoid.m Normal file
View File

@ -0,0 +1,55 @@
function x = generate_trapezoid(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_TRAPEZOID: returns a matrix of sampled square wave
% CONTRIBUTORS:
% Daniel Doan: Author
% 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 1.
% duty of 0.5 would have 2 trapezoids in first half of each cycle
% example of wave with duty of 0.5, where the peaks are amplitude/2:
%
% ____
% / \
% / \ ________________
% \ /
% \____/
%
% 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;
% periodic ramp from 0 to 1
% progression through a cycle
st = mod(frequency * t - phase, 1);
slope = (amplitude/2) / (duty/8);
if(st < duty)
if(st < duty/8 || st > 7*duty/8)
x(i) = slope * st;
else
if(st < 5*duty/8)
x(i) = amplitude/2 - slope * (st-(3*duty/8));
end
if(st < 3*duty/8)
x(i) = amplitude/2;
end
if(st > 5*duty/8)
x(i) = -amplitude/2;
end
end
end
end
end