From 8407b2a5d8705fed672b673b6c5ca6ee6ea5e8bb Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 18 Aug 2018 21:55:18 +0300 Subject: [PATCH] Low pass response to input signal init --- Low Pass Inverse Chebyshev/low_pass_design.m | 82 ++++++++++++++++++-- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/Low Pass Inverse Chebyshev/low_pass_design.m b/Low Pass Inverse Chebyshev/low_pass_design.m index 04f4b5d..b5d1a47 100644 --- a/Low Pass Inverse Chebyshev/low_pass_design.m +++ b/Low Pass Inverse Chebyshev/low_pass_design.m @@ -411,29 +411,95 @@ fprintf(['\n' '===== GAIN ADJUSTMENT =====' '\n' ... % ========== GAIN ADJUSTMENT END ========== -%% ========== TRANSFER FUNCTIONS START ========== +%% ========== TRANSFER FUNCTIONS STUDY START ========== 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; %{ +% Plots each unit's frequency response +for i=1:design_number_of_poles + plot_transfer_function(unit_transfer_function(1,i), ... + (low_frequency)); +end + +% Plots the total filter frequency response plot_transfer_function(total_transfer_function, ... - [10 ... + [low_frequency ... specification_pass_frequency ... design_half_power_radial_frequency/(2*pi) ... specification_stop_frequency]); + +% Plots the total filter attenuation function +plot_transfer_function(inv(total_transfer_function), ... + [low_frequency ... + specification_pass_frequency ... + design_half_power_radial_frequency/(2*pi) ... + specification_stop_frequency]); +%} +%{ +ltiview(unit_transfer_function(1,1)); +ltiview(unit_transfer_function(1,2)); +ltiview(total_transfer_function); +ltiview(unit_transfer_function(1,1), unit_transfer_function(1,2), ... + total_transfer_function); %} -%ltiview(unit_transfer_function(1,1)); -%ltiview(unit_transfer_function(1,2)); -%ltiview(total_transfer_function); -%ltiview(unit_transfer_function(1,1), unit_transfer_function(1,2), ... - %total_transfer_function); +hold off + +Fs = 1000; % Sampling frequency +T = 1/Fs; % Sampling period +L = 1500; % Length of signal +t = (0:L-1)*T; % Time vector + +input_signal_frequency = 2000; % Hz +input_signal_number_of_periods = 100000; +input_signal_T = input_signal_number_of_periods*(1/input_signal_frequency); +input_signal_duty_cycle = 20; +input_signal_Fs = 80000; +input_signal_dt = 1/input_signal_Fs; +input_signal_t = 0:input_signal_dt:input_signal_T-input_signal_dt; + +input_square_wave = (1+square(2*pi*input_signal_frequency*input_signal_t, ... + input_signal_duty_cycle))/2; + +system_output = lsim(total_transfer_function, input_square_wave, input_signal_t); +% Plots only the first 10 periods +temp = 10*input_signal_Fs/input_signal_frequency; +figure(1) +plot(input_signal_t(1:temp), input_square_wave(1:temp), ... + input_signal_t(1:temp), system_output(1:temp)); +grid on + +input_square_wave_fft = fft(input_square_wave); +L = length(input_signal_t); +P2 = abs(input_square_wave_fft/L); +P1 = P2(1:L/2+1); +P1(2:end-1) = 2*P1(2:end-1); +f = input_signal_Fs*(0:(L/2))/L; +figure(2) +%plot(f,P1) +semilogx(f,P1) +grid on + +system_output_fft = fft(system_output, length(input_signal_t)); +P2 = abs(system_output_fft/L); +P1 = P2(1:L/2+1); +P1(2:end-1) = 2*P1(2:end-1); +figure(3) +%plot(f, P11) +semilogx(f,P1) +grid on + +%filter_fft = fft(total_transfer_function); % Clears unneeded variable from workspace +clear low_frequency clear -regexp _numerator$ clear -regexp _denominator$ clear -regexp _transfer_function$ +clear -regexp ^input_signal_ -% ========== TRANSFER FUNCTIONS END ========== \ No newline at end of file +% ========== TRANSFER FUNCTIONS STUDY END ========== \ No newline at end of file