diff --git a/Band Elimination Chebyshev/band_elimination_design.m b/Band Elimination Chebyshev/band_elimination_design.m index 547fd38..1889b19 100644 --- a/Band Elimination Chebyshev/band_elimination_design.m +++ b/Band Elimination Chebyshev/band_elimination_design.m @@ -871,15 +871,13 @@ plot(sampling_time_vector(1:500), input_signal(1:500), ... sampling_time_vector(1:500), system_output(1:500)); grid on - % Plots the power spectrum of the input signal -input_square_wave_fft = fft(input_signal); -Pyy = input_square_wave_fft.*conj(input_square_wave_fft)/sampling_length_L; +input_signal_fft = fft(input_signal); +Pyy = input_signal_fft.*conj(input_signal_fft)/sampling_length_L; figure(2) semilogx(frequency_vector,Pyy(1:sampling_length_L/2+1)) grid on - % Plots the power spectrum of the output signal system_output_fft = fft(system_output, length(sampling_time_vector)); Pyy = system_output_fft.*conj(system_output_fft)/sampling_length_L; diff --git a/Band Pass Chebyshev/band_pass_design.m b/Band Pass Chebyshev/band_pass_design.m index a2c7166..7c1cf95 100644 --- a/Band Pass Chebyshev/band_pass_design.m +++ b/Band Pass Chebyshev/band_pass_design.m @@ -376,7 +376,7 @@ units_central_frequency_gain = zeros([1 band_pass_number_of_poles]); units_alpha = zeros([1 band_pass_number_of_poles]); units_Z2 = zeros([1 band_pass_number_of_poles]); units_Z3 = zeros([1 band_pass_number_of_poles]); -unit_transfer_functions = [tf(1) tf(1) tf(1) tf(1)]; +units_transfer_functions = [tf(1) tf(1) tf(1) tf(1)]; units_filter_central_frequency_gain = zeros([1 band_pass_number_of_poles]); for i=1:band_pass_number_of_poles @@ -442,10 +442,10 @@ for i=1:band_pass_number_of_poles units_BW(1,i) ... band_pass_poles_radial_frequencies(1,i)^2]; %} - unit_transfer_functions(i) = tf(unit_numerator, unit_denominator); + units_transfer_functions(i) = tf(unit_numerator, unit_denominator); [units_filter_central_frequency_gain(1,i),phase] = ... - bode(unit_transfer_functions(i), ... + bode(units_transfer_functions(i), ... design_geometric_central_radial_frequency); end @@ -483,8 +483,8 @@ clear clearVars %% ========== TRANSFER FUNCTIONS STUDY START ========== total_transfer_function = series(series(series( ... - unit_transfer_functions(1), unit_transfer_functions(2)), ... - unit_transfer_functions(3)), unit_transfer_functions(4)); + units_transfer_functions(1), units_transfer_functions(2)), ... + units_transfer_functions(3)), units_transfer_functions(4)); %{ % Plots each unit's frequency response @@ -559,15 +559,13 @@ plot(sampling_time_vector(1:2000), input_signal(1:2000), ... sampling_time_vector(1:2000), system_output(1:2000)); grid on - % Plots the power spectrum of the input signal -input_square_wave_fft = fft(input_signal); -Pyy = input_square_wave_fft.*conj(input_square_wave_fft)/sampling_length_L; +input_signal_fft = fft(input_signal); +Pyy = input_signal_fft.*conj(input_signal_fft)/sampling_length_L; figure(2) semilogx(frequency_vector,Pyy(1:sampling_length_L/2+1)) grid on - % Plots the power spectrum of the output signal system_output_fft = fft(system_output, length(sampling_time_vector)); Pyy = system_output_fft.*conj(system_output_fft)/sampling_length_L; @@ -577,7 +575,7 @@ grid on % Clears unneeded variables from workspace clearVars = {'temp', 'Pyy', 'frequency_vector', 'system_output', ... - 'unit_transfer_functions', 'system_output_fft', ... + 'units_transfer_functions', 'system_output_fft', ... 'total_transfer_function'}; clear(clearVars{:}) clear clearVars diff --git a/High Pass Butterworth/Multisim/high_pass_butterworth.ms14 b/High Pass Butterworth/Multisim/high_pass_butterworth.ms14 index e7f3559..29db5d8 100644 Binary files a/High Pass Butterworth/Multisim/high_pass_butterworth.ms14 and b/High Pass Butterworth/Multisim/high_pass_butterworth.ms14 differ diff --git a/High Pass Butterworth/high_pass_design.m b/High Pass Butterworth/high_pass_design.m index 913d40e..9071ec7 100644 --- a/High Pass Butterworth/high_pass_design.m +++ b/High Pass Butterworth/high_pass_design.m @@ -198,8 +198,8 @@ for i=1:low_pass_prototype_number_of_poles end % Clears unneeded variables from workspace -clearVars = {'i', 'prototype_normalized_stop_radial_frequency', ... - 'low_pass_prototype_half_power_radial_frequency', 'theta'}; +clearVars = {'i', 'prototype_normalized_stop_radial_frequency', 'theta', ... + 'low_pass_prototype_half_power_radial_frequency', 'temp_filter_order'}; clear(clearVars{:}) clear clearVars @@ -340,12 +340,12 @@ for i=1:high_pass_number_of_poles % Builds unit's transfer function % Builds numerator and denominator of the transfer function using the % eq. 6-68 - G = (units_R(1,i)+units_r2(1,i))/units_R(1,i); - unit_numerator = [G ... + temp_G = (units_R(1,i)+units_r2(1,i))/units_R(1,i); + unit_numerator = [temp_G ... 0 ... 0]; unit_denominator = [1 ... - 2/(units_C(1,i)*units_R(1,i))+(1-G)/(units_C(1,i)*units_R(1,i)) ... + 2/(units_C(1,i)*units_R(1,i))+(1-temp_G)/(units_C(1,i)*units_R(1,i)) ... 1/(units_C(1,i)^2*units_R(1,i)^2)]; units_transfer_functions(1,i) = ... @@ -375,52 +375,112 @@ for i=1:high_pass_number_of_poles end % Clears unneeded variables from workspace -clearVars = {'i'}; +clearVars = {'i', 'temp_G', 'unit_numerator', 'unit_denominator'}; clear(clearVars{:}) clear clearVars -clear -regexp _transfer_function$ % ========== UNITS IMPLEMENTATION END ========== %% ========== GAIN ADJUSTMENT START ========== -% total_gain_high = units_k(1,1)*units_k(1,2); unit_adjustment_gain = 1/total_gain_high; % We arbitrarily choose to use a 10KOhm series resistor in the adjustment % unit unit_adjustment_feedback_resistor = 10*10^3*unit_adjustment_gain; -% + +% ========== GAIN ADJUSTMENT END ========== + +%% ========== TRANSFER FUNCTIONS STUDY START ========== total_transfer_function = series(units_transfer_functions(1,1), ... units_transfer_functions(1,2)); total_transfer_function = total_transfer_function*unit_adjustment_gain; +% Arbitrary high frequency to display the gain at high frequencies +high_frequency = 90000; % Hz %{ -ltiview(units_transfer_functions(1,1), ... - units_transfer_functions(1,2)); -%} +% Plots each unit's frequency response +for i=1:high_pass_number_of_poles + plot_transfer_function(units_transfer_functions(1,i), ... + (high_frequency)); +end +% Plots the total filter frequency response +plot_transfer_function(total_transfer_function, ... + [specification_stop_frequency ... + design_half_power_radial_frequency/(2*pi) ... + specification_pass_frequency ... + high_frequency]); + +% Plots the total filter attenuation function +plot_transfer_function(inv(total_transfer_function), ... + [specification_stop_frequency ... + design_half_power_radial_frequency/(2*pi) ... + specification_pass_frequency ... + high_frequency]); +%} %{ -ltiview(units_transfer_functions(1,1), ... - units_transfer_functions(1,2), ... +ltiview('bodemag', units_transfer_functions(1,1)); +ltiview('bodemag', units_transfer_functions(1,2)); +ltiview('bodemag', total_transfer_function); +ltiview('bodemag', units_transfer_functions(1,1), units_transfer_functions(1,2), ... total_transfer_function); %} -%ltiview(total_transfer_function); +hold off + +sampling_time_seconds = 60; % s +sampling_frequency_Fs = 80000; % Hz +sampling_period_T = 1/sampling_frequency_Fs; % s +sampling_time_vector = 0:sampling_period_T: ... + sampling_time_seconds-sampling_period_T; +sampling_length_L = length(sampling_time_vector); +frequency_vector = sampling_frequency_Fs/sampling_length_L* ... + (0:(sampling_length_L/2)); + +input_cos_signal_frequency_1 = 0.2*specification_stop_radial_frequency; +input_cos_signal_frequency_2 = 0.7*specification_stop_radial_frequency; +input_cos_signal_frequency_3 = 1.6*specification_pass_radial_frequency; +input_cos_signal_frequency_4 = 2.4*specification_pass_radial_frequency; +input_cos_signal_frequency_5 = 3.5*specification_pass_radial_frequency; + +input_signal = cos(input_cos_signal_frequency_1*sampling_time_vector)+ ... + 0.6*cos(input_cos_signal_frequency_2*sampling_time_vector)+ ... + 1.5*cos(input_cos_signal_frequency_3*sampling_time_vector)+ ... + 0.7*cos(input_cos_signal_frequency_4*sampling_time_vector)+ ... + 0.4*cos(input_cos_signal_frequency_5*sampling_time_vector); + +system_output = lsim(total_transfer_function, input_signal, ... + sampling_time_vector); + +% Plots only the first 500 samples +figure(1) +plot(sampling_time_vector(1:500), input_signal(1:500), ... + sampling_time_vector(1:500), system_output(1:500)); +grid on + +% Plots the power spectrum of the input signal +input_signal_fft = fft(input_signal); +Pyy = input_signal_fft.*conj(input_signal_fft)/sampling_length_L; +figure(2) +semilogx(frequency_vector,Pyy(1:sampling_length_L/2+1)) +grid on + +% Plots the power spectrum of the output signal +system_output_fft = fft(system_output, length(sampling_time_vector)); +Pyy = system_output_fft.*conj(system_output_fft)/sampling_length_L; +figure(3) +semilogx(frequency_vector,Pyy(1:sampling_length_L/2+1)) +grid on -%{ -plot_transfer_function(total_transfer_function, ... - [design_half_power_radial_frequency/(2*pi) ... - specification_stop_frequency ... - specification_pass_frequency ... - 15000]); -%} - % Clears unneeded variable from workspace -clearVars = {'total_transfer_function'}; +clearVars = {'high_frequency', 'total_transfer_function', 'Pyy', ... + 'frequency_vector', 'system_output', 'system_output_fft'}; clear(clearVars{:}) clear clearVars clear -regexp _transfer_functions$ +clear -regexp ^sampling_ +clear -regexp ^input_ -% ========== GAIN ADJUSTMENT END ========== \ No newline at end of file +% ========== TRANSFER FUNCTIONS STUDY END ========== \ No newline at end of file diff --git a/Low Pass Inverse Chebyshev/low_pass_design.m b/Low Pass Inverse Chebyshev/low_pass_design.m index 3193fe8..7638927 100644 --- a/Low Pass Inverse Chebyshev/low_pass_design.m +++ b/Low Pass Inverse Chebyshev/low_pass_design.m @@ -418,7 +418,8 @@ total_transfer_function = series(unit_transfer_function(1,1), ... unit_transfer_function(1,2)); total_transfer_function = total_transfer_function*unit_adjustment_gain; -low_frequency = 10; +% Arbitrary low frequency to display the gain at low frequencies +low_frequency = 10; % Hz %{ % Plots each unit's frequency response for i=1:design_number_of_poles