From 9d72926d3876a18a4d3890689bc73437b16464ff Mon Sep 17 00:00:00 2001 From: MekhiTheKing <95403331+MekhiTheKing@users.noreply.github.com> Date: Thu, 9 Dec 2021 20:58:19 -0800 Subject: [PATCH 1/4] Add files via upload --- src/generate_cosine.m | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/generate_cosine.m diff --git a/src/generate_cosine.m b/src/generate_cosine.m new file mode 100644 index 0000000..8a013ed --- /dev/null +++ b/src/generate_cosine.m @@ -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 \ No newline at end of file From 110dcccc03310127ce890c2a544de2dc37b3976a Mon Sep 17 00:00:00 2001 From: k7xu Date: Thu, 9 Dec 2021 21:02:30 -0800 Subject: [PATCH 2/4] added pulse wave for Brian --- src/Generators/generate_pulse.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/Generators/generate_pulse.m diff --git a/src/Generators/generate_pulse.m b/src/Generators/generate_pulse.m new file mode 100644 index 0000000..6bc08bb --- /dev/null +++ b/src/Generators/generate_pulse.m @@ -0,0 +1,26 @@ +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); + + % populate the matrix + for i = 1:n + F=F+(1/n)*cos(n*2*pi*(1e+6)*t).*sin(n*pi*0.1); + end + F=F*(2*10/pi); + F=F+10*0.1; +end \ No newline at end of file From f9cdd4c503886e655025a3e8a88cf4d285949aba Mon Sep 17 00:00:00 2001 From: MekhiTheKing <95403331+MekhiTheKing@users.noreply.github.com> Date: Thu, 9 Dec 2021 21:13:56 -0800 Subject: [PATCH 3/4] Added Comments and Changed Formatting --- src/distortion_filter.m | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/distortion_filter.m diff --git a/src/distortion_filter.m b/src/distortion_filter.m new file mode 100644 index 0000000..869aab7 --- /dev/null +++ b/src/distortion_filter.m @@ -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 \ No newline at end of file From 52a3bee8440a4a864871fcd2069c1188c96fab22 Mon Sep 17 00:00:00 2001 From: k7xu Date: Thu, 9 Dec 2021 21:32:24 -0800 Subject: [PATCH 4/4] Fixed my generator --- src/Generators/generate_pulse.m | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Generators/generate_pulse.m b/src/Generators/generate_pulse.m index 6bc08bb..2f9c316 100644 --- a/src/Generators/generate_pulse.m +++ b/src/Generators/generate_pulse.m @@ -13,14 +13,21 @@ function x = generate_pulse(amplitude, frequency, phase, fs, duration, duty) % 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 i = 1:n - F=F+(1/n)*cos(n*2*pi*(1e+6)*t).*sin(n*pi*0.1); + for n = 1:N + F=F+(1/n)*cos(n*2*pi*f0*t).*sin(n*pi*td); end - F=F*(2*10/pi); - F=F+10*0.1; + F=F*(2*A0/pi); + F=F+A0*td; end \ No newline at end of file