Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

close all clear % -- If you want to construct your own signal: % --- Define samp

ID: 3349410 • Letter: C

Question

close all

clear

% -- If you want to construct your own signal:

% --- Define sampling characteristics ---

fsamp = 50e3; % sampling rate

tsamp = 1/fsamp; % time step per point

tmax = 0.01; % maximum time

tvec= [tsamp:tsamp:tmax]; % time vector

n = length(tvec); % number of data points

% ---------------------------------------

% --- Define signals ---

f = 2000; % first signal frequency [Hz]

y = 2*sin(f*2*pi*tvec); % turn into multi-cycle time-based signal

f2 = 20e3; % second signal frequency [Hz]

y2 = 2*sin(f2*2*pi*tvec); % turn into multi-cycle time-based signal

y3 = y+y2; % superimpose both signals

% ----------------------

% -- If you want to import data from a file:

% load FilterData_HW5.mat

% % --- Plot simulated signals ---

% figure;plot(tvec,y);grid

% title('1 kHz signal')

% ylabel('Time (s)');ylabel('Amplitude')

% figure;plot(tvec,y2);grid

% title('10 kHz signal')

% ylabel('Time (s)');ylabel('Amplitude')

% figure;plot(tvec,y3);grid

% title('1 kHz + 10 kHz signal')

% ylabel('Time (s)');ylabel('Amplitude')

% % ---------------------

% --- Butterworth filter response ---

wn = .8; % define normalized cutoff frequency

[bu,au] = butter(6,wn,'low'); % create lowpass filter characteristics

FilSig = filter(bu,au,y3); % apply filter to data

% -----------------------------------

% --- Compare signals ---

figure;a =plot(tvec,y3);grid;hold on

b = plot(tvec,FilSig,'r');

axis([.002 0.005 -5 5]) % Cutoff initial part of signal to avoid rounding issues

xlabel('Time (s)')

ylabel('Amplitude')

legend([a,b],'Original signal','Filtered signal')

% -----------------------

signals that are produced by the end oft the attenuation (also known as the negative gain) AND time shift that the filter produces on the two signals when wn 0.8. Express the attenuation and time in units of dB and seconds, respectively. b.) Describe, in words, what the normalized cutoff frequency wn represents, and then solve for the equivalent cutoff frequency fe value for wn0.8. Note that this is a Matlab-specific variable, and is not related to second-order systems, so typing "help butter in Matlab may be helpful! c.) Determine the value for wn that is necessary to null out the 20-kHz component entirely, such that the attenuation is below 3.1 dB. Report wn to the nearest 1/10th value (i.e., an integer multiple of 0.1) and report the attenuation for this value. Show your work for this final calculation. Hint: An iterative solution method, in Matlab, may be the best way to proceed. d.) Make a plot that shows the initial signal and your signal produced in step c.), as a function of time, over the first 4 msec period.

Explanation / Answer

close all

clear

% -- If you want to construct your own signal:

% --- Define sampling characteristics ---

fsamp = 50e3; % sampling rate

tsamp = 1/fsamp; % time step per point

tmax = 0.01; % maximum time

tvec= [tsamp:tsamp:tmax]; % time vector

n = length(tvec); % number of data points

% ---------------------------------------

% --- Define signals ---

f = 2000; % first signal frequency [Hz]

y = 2*sin(f*2*pi*tvec); % turn into multi-cycle time-based signal

f2 = 20e3; % second signal frequency [Hz]

y2 = 2*sin(f2*2*pi*tvec); % turn into multi-cycle time-based signal

y3 = y+y2; % superimpose both signals

% ----------------------

% -- If you want to import data from a file:

% load FilterData_HW5.mat

% % --- Plot simulated signals ---

% figure;plot(tvec,y);grid

% title('1 kHz signal')

% ylabel('Time (s)');ylabel('Amplitude')

% figure;plot(tvec,y2);grid

% title('10 kHz signal')

% ylabel('Time (s)');ylabel('Amplitude')

% figure;plot(tvec,y3);grid

% title('1 kHz + 10 kHz signal')

% ylabel('Time (s)');ylabel('Amplitude')

% % ---------------------

% --- Butterworth filter response ---

wn = .8; % define normalized cutoff frequency

[bu,au] = butter(6,wn,'low'); % create lowpass filter characteristics

FilSig = filter(bu,au,y3); % apply filter to data

% -----------------------------------

% --- Compare signals ---

figure;a =plot(tvec,y3);grid;hold on

b = plot(tvec,FilSig,'r');

axis([.002 0.005 -5 5]) % Cutoff initial part of signal to avoid rounding issues

xlabel('Time (s)')

ylabel('Amplitude')

legend([a,b],'Original signal','Filtered signal')

% -----------------------