In: Electrical Engineering
The MATLAB routine analog _ filter1.m is a simulated analog filter. (Calling structure: output = analog _ filter1(input);). Repeat the strategy used in Problem 1.2, but generate the input sine waves in MATLAB and plot the output. Make Ts = 0.001 s and the number of points N = 1000. To generate sine waves, defne the time vector t = (0:999)*Ts as in Example 1.3. Use this vector to generate the input sine waves at various frequencies: input = sin(2*pi*f*t);. Use frequencies of 2, 10, 15, 20, 30, 40, 50, 60, 80, 90, 100, 150, 200, 300, and 400 Hz.
Find the amplitude of the output of analog _ filter1.m using MATLAB’s max operator and plot the resulting values in dB versus log frequency. This gives an approximation of the flter’s frequency characteristics or spectrum. Use this spectrum with the grid function enabled to determine the type, bandwidth, and attenuation slope of the flter. [Hint: Put the desired input frequencies in an array and use a for-loop to generate the input sine waves. Store the maximum values of the flter’soutput in an array for plotting. Plot the 20 log of the output values against the frequency array using the semilogx routine.
I'd like to know the code from the beginning until end for my self-study because my instructor didnt teach me this even once. Thank you so much.
analog_filter1.m -> https://pastebin.com/htg8Yhhg (just open the link and copy-paste it into matlab)
Given That :
The MATLAB routine analog _ filter1.m is a simulated analog filter.
Repeat the strategy used in Problem 1.2, but generate the input sine waves in MATLAB and plot the output.
Make Ts = 0.001 s and the number of points N = 1000. To generate sine waves, defne the time vector t = (0:999)*Ts.
Use this vector to generate the input sine waves at various frequencies: input = sin(2*pi*f*t);. Use frequencies of 2, 10, 15, 20, 30, 40, 50, 60, 80, 90, 100, 150, 200, 300, and 400 Hz.
Solution :
Given simulated Filter code is written in a seperate file with name analog_filter1.m
function output=analog_filter1(input)
[b,a]=butter(4,0.2,'High');
[b1,a1]=butter(2,0.12);
input=filter(b1,a1,input);
output=filter(b,a,input);
end
%----APPROXIMATE FILTER CHARACTERSTICS USING MATLAB----%
clear all; close all;
%______PROGRAM STARTS____%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%---Genetarion of Input Sine Waves----%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ts=0.001; %The sample interval is taken as given in the
problem
N=1000; %No.of Samples is taken as 1000 as given in the
problem
t=(0:N-1)*Ts; %Form the time scale with the choosen values of N and
Ts
%---Taking all the frequency values in an array----%
f=[2 10 15 20 30 40 50 60 70 80 90 100 150 200 300 400];
filter_response=zeros(1,length(f));
for i=1:length(f)
input=sin(2*pi*f(i)*t);
subplot(4,4,i),plot(t,input);title(['i/p for
f=',num2str(f(i))],'FontSize',18);
%---Get the output of the simulated filter given---%
output=analog_filter1(input);
%----Take the maximum value of the Output of the filter for a
particular input frequency f(i)----%
output_max=max(abs(output));
filter_response(i)=output_max;
end
%----Plot the Filter characterstics with amplitude taken in dB
on a log plot---%
figure,
semilogx(f,20*log(filter_response));
title('Filter Frequency Characterstics in log
plot','FontSize',18);
xlabel('Frequency','FontSize',18); ylabel('Output in
dB','FontSize',18);
grid on;
%____PROGRAM ENDS____%
The Grid is On.
And if we observe the Output Filter Characterstics,
It looks like a bandpass filter with central frequency of 100Hz.
The Bandwidth is approximately 185Hz (which is the frequency range where the Output is not less than 3dB of the Max value)
Let us consider two points which are at a distance of a decade, (-29.37dB,100Hz) and (-98.02dB, 10Hz) => The Attenuation slope is (98.02-29.37)db/decade=68.65dB/decade.
All the values are only approximate as we have taken very less number of frequency values as given in the problem statement.