├── Filters ├── Filters.pdf ├── Filters.pptx └── MATLAB │ ├── Butterworth.m │ ├── IIRPlot.m │ └── Lo-Fi-Demo.mp3 └── sampling and FFT ├── FFTDemo.m ├── Sampling_Demo_Workshop_Code.m ├── delayDemo.m ├── guitar.aiff ├── simpleSamplingDemo.m └── sineGeneration.m /Filters/Filters.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dynamic-cast/DSP-Workshop/f859884b989241f46c20aa1ae5f9da80dd616e43/Filters/Filters.pdf -------------------------------------------------------------------------------- /Filters/Filters.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dynamic-cast/DSP-Workshop/f859884b989241f46c20aa1ae5f9da80dd616e43/Filters/Filters.pptx -------------------------------------------------------------------------------- /Filters/MATLAB/Butterworth.m: -------------------------------------------------------------------------------- 1 | % Basic butterworth filter example 2 | % Uses a built in IIR filter 3 | 4 | [dataIn, Fs] = audioread('Lo-Fi-Demo.mp3'); % Read an audio file 5 | 6 | % Filter the signal 7 | fc = 800; % Make higher to hear higher frequencies. 8 | 9 | % Design a Butterworth filter. 10 | [b, a] = butter(6,fc/(Fs/2)); 11 | freqz(b,a) 12 | 13 | % Apply the Butterworth filter. 14 | filteredSignal = filter(b, a, dataIn); 15 | 16 | % Play the sound. 17 | player = audioplayer(filteredSignal, Fs); 18 | play(player); -------------------------------------------------------------------------------- /Filters/MATLAB/IIRPlot.m: -------------------------------------------------------------------------------- 1 | % Various Plots for IIR Filtering 2 | % h[n] = y[n]/x[n] 3 | 4 | clc; 5 | clear all; 6 | num = [1 0]; % a -> coefficients of y[n] Changeable to see what happens 7 | den = [1 -1]; % b -> coefficients of x[n] Changeable to see what happens 8 | 9 | figure(1) 10 | subplot(1,3,1) 11 | zplane(num,den) % Z plane plot of h(n) 12 | title('Pole Zero Plot') 13 | 14 | w = 0:pi/32:pi; % Omega Frequency (Changeable) 15 | [h,w]=freqz(num,den,w); % Freqz = frequency response 16 | mag=abs(h); % Absolute Value for magnitude 17 | phase=angle(h); 18 | 19 | subplot(1,3,2) 20 | plot(w/pi,mag) 21 | title('Magnitude Plot for IIR LPF') 22 | 23 | subplot(1,3,3) 24 | plot(w/pi,phase) 25 | title('Phase Plot for IIR LPF') -------------------------------------------------------------------------------- /Filters/MATLAB/Lo-Fi-Demo.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dynamic-cast/DSP-Workshop/f859884b989241f46c20aa1ae5f9da80dd616e43/Filters/MATLAB/Lo-Fi-Demo.mp3 -------------------------------------------------------------------------------- /sampling and FFT/FFTDemo.m: -------------------------------------------------------------------------------- 1 | %% This is a script for demoing the Fast Fourier Transfor (FFT) 2 | close; clear; clc 3 | 4 | Fs = 1000; %sampling rate 5 | nyquist = Fs/2; %nyquist frequency is half the sampling rate 6 | % f = 600; %cycles per second (Hz) 7 | f1 = 20; 8 | f2 = 30; 9 | f3 = 40; 10 | duration = 1.5; %length of signal in seconds 11 | Ts = 1/Fs; %duration between samples in seconds (sampling period) 12 | t = 0:Ts:duration; %time axis 13 | 14 | x1 = 3 * cos(2 * pi * f1 * t + 0.2); 15 | x2 = 1 * cos(2 * pi * f2 * t - 0.3); 16 | x3 = 2 * cos(2 * pi * f3 * t + 2.4); 17 | 18 | x = x1 + x2 + x3; 19 | 20 | % x = sin(2 * pi * f * t); %sinusoidal wave 21 | subplot(3, 1, 1) 22 | plot(t, x) 23 | xlim([0 0.1]) 24 | ylabel('amplitude') 25 | xlabel('time (seconds)') 26 | grid on 27 | 28 | % Take fourier transform 29 | X = fft(x); 30 | 31 | % Get the absolute value (magnitude) 32 | X_Mag = abs(X); 33 | 34 | % Get the angle (phase) 35 | X_phase = angle(X); 36 | 37 | % bins with frequency components: 38 | 39 | subplot(3, 1, 2) 40 | plot(X_Mag) 41 | ylabel('energy') 42 | xlabel('frequency (bins)') 43 | grid on 44 | 45 | N = length(X); %fft length 46 | % Ft = 0:N-1/N*Fs; % vector 0-44100 47 | % freqAxis = (0:N - 1)/Fs * N; 48 | 49 | % Next, calculate the frequency axis, which is defined by the sampling rate 50 | % basically saying we want fs number of equally spaces values between -1, 1 51 | % but we're putting our nyquist frequency out in front in order to specify 52 | % that we want Fs equally spaced values between -nyquist and + nyquist 53 | f_axis = Fs/2 * linspace(-1 ,1, N); 54 | 55 | 56 | %apply fftshift to put it in the form we are used to (see documentation) 57 | X_Shift = fftshift(X_Mag); 58 | subplot(3, 1, 3) 59 | plot(f_axis, X_Shift/(N/2)) 60 | ylabel('amplitude') 61 | xlabel('frequency (Hz)') 62 | grid on 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /sampling and FFT/Sampling_Demo_Workshop_Code.m: -------------------------------------------------------------------------------- 1 | %% This is a sampling script 2 | close, clc 3 | 4 | %% signal generation 5 | 6 | duration = 10; %seconds 7 | dt = 0.0001; %time step (how often we compute a sample) 8 | t = 0:dt:duration; %x-axis (time) 9 | f = 500; %frequency 10 | f1 = 1000; 11 | x_t = sin(2 * pi * f * t); %continuous time sinusoid 12 | x2_t = sin(2 * pi * f1 * t); 13 | x = x_t + x2_t; 14 | 15 | 16 | % plotting code 17 | subplot(4, 1, 1) % subplot 1 18 | plot(t ,x_t, 'linewidth',1.5) 19 | xlim([0 0.01]) % limit the x-axis 20 | title('Continuous Time Sinusoid x(t) (500Hz)') 21 | xlabel('time (seconds)') 22 | ylabel('amplitude') 23 | legend('x(t)') 24 | grid on 25 | 26 | subplot(4, 1, 2) % subplot 1 27 | plot(t ,x, 'linewidth',1.5) 28 | xlim([0 0.01]) % limit the x-axis 29 | title('Continuous Time Sinusoid x(t) (500Hz)') 30 | xlabel('time (seconds)') 31 | ylabel('amplitude') 32 | legend('x(t)') 33 | 34 | 35 | % hold on 36 | 37 | %% sampling 38 | 39 | Fs = 5000; % sampling frequency 40 | Ts = 1/Fs; % sampling period 41 | n = 0:Ts:10; % x-axis (samples) 42 | x_n = sin(2 * pi * f * n); % discrete time sinusoid 43 | x2_n = sin(2 * pi * f1 * n); 44 | x1 = x_n + x2_n; 45 | 46 | % plotted 47 | subplot(4, 1, 3) % subplot 2 48 | plot(t ,x, 'linewidth',1.5) 49 | hold on 50 | stem(n, x1, 'g', 'linewidth',1.5) % for 'discrete' 51 | hold off 52 | grid on 53 | xlabel('samples (n)') 54 | ylabel('amplitude') 55 | legend('x(t)', 'x[n]') 56 | xlim([0 0.01]) % limit the x-axis 57 | % sound(x_n) 58 | 59 | %% reconstruction 60 | 61 | t_r = linspace(0, max(n), (max(n)/dt)); %x-axis (reconstructed time axis) 62 | y_t = interp1(n, x1, t_r, "spline"); %reconstructed continous time sinusoid 63 | 64 | %plotting code 65 | subplot(4, 1, 4) % subplot 3 66 | plot(t_r, y_t,'r','linewidth',1.5) 67 | grid on 68 | xlim([0 0.01]) %limit x-axis 69 | % sound(x_n) 70 | 71 | %% Add FFT Code here to verify 72 | -------------------------------------------------------------------------------- /sampling and FFT/delayDemo.m: -------------------------------------------------------------------------------- 1 | % This is a script for applying a simple delay effect 2 | clear; close; clc 3 | 4 | [x,Fs] = audioread('guitar.aiff'); 5 | x = x(:,1); %make signal mono 6 | 7 | %delay time 8 | 9 | delayInSeconds = 0.25; 10 | 11 | delayInSamples = delayInSeconds * Fs; 12 | 13 | %making sure our signals are the same length 14 | 15 | zeroPadding = zeros(delayInSamples, 1); 16 | originalSignal = [x ; zeroPadding]; %88200 signal + 44100 zeros 17 | delayedSignal = [zeroPadding ; x]; %44100 zeros + 88200 signal 18 | 19 | 20 | y = zeros(size(originalSignal)); 21 | 22 | % for n = 1:length(originalSignal) 23 | % y(n,1) = originalSignal(n,1) + 0.5 * delayedSignal(n,1); 24 | % end 25 | 26 | % sound(x, Fs) 27 | % sound(y, Fs) 28 | 29 | for n = 1:length(x) 30 | if (n-delayInSamples) < 1 31 | y(n,1) = x(n,1); 32 | else 33 | y(n,1) = x(n,1) + 0.5 * x(n-delayInSamples,1); 34 | end 35 | end 36 | 37 | 38 | % sound(x, Fs) 39 | % sound(y, Fs) -------------------------------------------------------------------------------- /sampling and FFT/guitar.aiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dynamic-cast/DSP-Workshop/f859884b989241f46c20aa1ae5f9da80dd616e43/sampling and FFT/guitar.aiff -------------------------------------------------------------------------------- /sampling and FFT/simpleSamplingDemo.m: -------------------------------------------------------------------------------- 1 | %% This is a sampling script 2 | close, clc 3 | 4 | %% signal generation 5 | 6 | duration = 10; 7 | dt = 0.0001; %time step (how often we compute a sample) 8 | t = 0:dt:duration; %x-axis (time) 9 | f = 500; %frequency 10 | x_t = sin(2 * pi * f * t); %continuous time sinusoid 11 | 12 | 13 | % plotting code 14 | subplot(3, 1, 1) % subplot 1 15 | plot(t ,x_t, 'linewidth',1.5) 16 | xlim([0 0.01]) % limit the x-axis 17 | title('Continuous Time Sinusoid x(t) (500Hz)') 18 | legend('x(t)') 19 | grid on 20 | % hold on 21 | 22 | %% sampling 23 | 24 | Fs = 600; % sampling frequency 25 | Ts = 1/Fs; % sampling period 26 | n = 0:Ts:10; % x-axis (samples) 27 | x_n = sin(2 * pi * f * n); % discrete time sinusoid 28 | 29 | % plotted 30 | subplot(3, 1, 2) % subplot 2 31 | plot(t ,x_t, 'linewidth',1.5) 32 | hold on 33 | stem(n, x_n, 'g', 'linewidth',1.5) % for 'discrete' 34 | hold off 35 | grid on 36 | legend('x(t)', 'x[n]') 37 | xlim([0 0.01]) % limit the x-axis 38 | % sound(x_n) 39 | 40 | %% reconstruction 41 | 42 | t_r = linspace(0, max(n), (max(n)/dt)); %x-axis (reconstructed time axis) 43 | y_t = interp1(n, x_n, t_r, "spline"); %reconstructed continous time sinusoid 44 | 45 | %plotting code 46 | subplot(3, 1, 3) % subplot 3 47 | plot(t_r, y_t,'r','linewidth',1.5) 48 | grid on 49 | xlim([0 0.01]) %limit x-axis 50 | % sound(x_n) 51 | 52 | %% Add FFT Code here to verify 53 | -------------------------------------------------------------------------------- /sampling and FFT/sineGeneration.m: -------------------------------------------------------------------------------- 1 | %% This is a sine wave generation script 2 | 3 | %Generate a sine wave using a MATLAB function 4 | 5 | Fs = 44100; %sampling rate 6 | f = 3; %frequency (Hz) 7 | Ts = 1/Fs; 8 | t = 0:Ts:1; 9 | 10 | sineWave = sin(2 * pi * f * t); %sine wave 11 | subplot(2, 1, 1) %subplot 1 12 | plot(t, sineWave, 'linewidth', 2) 13 | title('Sine Wave (MATLAB Function)') 14 | grid on 15 | 16 | 17 | %% Generate a sine wave sample by sample 18 | 19 | y = zeros(1, 44100); 20 | 21 | for n = 1:Fs + 1 22 | %we require a new sample every 1/Fs seconds 23 | %that's every 0.00002267573 seconds 24 | y(n) = sin(2 * pi * n * f/Fs); 25 | end 26 | 27 | figure(2) 28 | subplot(2, 1, 2) 29 | plot(t,y, 'r', 'linewidth', 2) 30 | title('Sine Wave (sample by sample)') 31 | grid on 32 | --------------------------------------------------------------------------------