-
-
Save vjames19/3cabe2cdbd3e54e9652c to your computer and use it in GitHub Desktop.
Quiz 2 INEL 4301
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function y = HL(x) | |
x2 = x(x >= -60 & x <= 60); | |
y(find(x >= -60 & x <= 60))= exp(-1i *((2*pi)/30 * x2)); | |
y(find(x > 60 | x < -60)) = 0; | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%INEL 4095 - Signals and Systems | |
%CAUSAL FIRST ORDER RC-FILTER | |
%Ideal Low-pass filter versus RC-filter | |
%Prof. Domingo Rodriguez - Spring 2012 | |
% | |
close all; | |
%PARAMETER SETTINGS************************************** | |
Fs=1000; %Sampling Frequency | |
Ts=1/Fs; %Sampling Period or Sampling Time | |
N=300; %Length of each discrete signal or vector | |
V=N*Ts; %Time duration (in seconds) for each signal | |
fm=60; %Cuttoff frequency | |
Wn=2*fm/Fs; %Normalized frequency | |
M=300; %Length of the impulse response signal | |
R=10000; %Value of Resistor | |
C=1/(2*pi*fm*R); %Value of Capacitor | |
a=1/(R*C); %Time Constant Parameter | |
h0=a; %Initial Condition Parameter | |
t=0:Ts:V-Ts; %General time axis | |
th=0:Ts:M*Ts-Ts; %Time axis for plotting impulse response signal | |
f=-Fs/2:Fs/M:Fs/2-Fs/M; %Frequency axis | |
%******************************************************** | |
%RC-FILLTER | |
hRC=h0*exp(-a*th); %RC-Filter impulse response function | |
hmax=max(hRC); %Maximum value of impulse response function | |
hRC=(hRC/hmax); %Normalized impulse response function | |
fhRC=fft(hRC); %Fourier Transform of impulse response function | |
sfhRC=fftshift(fhRC); %Frequency shift for two sided spectrum plot | |
asfhRC=abs(sfhRC); %Absolute value calculation | |
Hmax=max(asfhRC); %Maximum value of frequency response function | |
asfhRC=(asfhRC/Hmax); %Normilized frequency response function | |
% | |
%******************************************************** | |
%MATLAB FIR1 FILTER | |
Wn=(2*fm)/Fs; %Normilized cut-off frequency for ideal filter | |
h=fir1(N-1,Wn); %Impulse response function of ideal filter | |
fh=fft(h); %Fourier transform of impulse response function | |
sfh=fftshift(fh); %Frequency shift for two sided spectrum plot | |
msfh=abs(sfh); %Absolute value calculation | |
% | |
%******************************************************** | |
%PLOTS | |
%******************************************************** | |
plot(f,asfhRC,f,msfh,'r') %Plots of RC and Ideal filters | |
grid | |
xlabel('Frequency in Hz.') %Horizontal axis | |
ylabel('Magnitude') %Vertical axis | |
title('HL(f) and HRC(f)') %Title of plot | |
% Quiz | |
% HL = exp(-1i *((2*pi)/30 * f)); | |
% mHL = abs(HL); | |
% aHL = angle(HL); | |
% plot(f, mHL) | |
% grid | |
% xlabel('Frequency in Hz.') %Horizontal axis | |
% ylabel('Magnitude') %Vertical axis | |
% title('HL(f)') %Title of plot | |
% | |
% figure | |
% plot(f, aHL) | |
% grid | |
% xlabel('Frequency in Hz.') %Horizontal axis | |
% ylabel('Phase') %Vertical axis | |
% title('HL(f)') %Title of plot | |
%%%%%%%%%%%% Exercise A | |
% Fs = 480; | |
% N = 100; | |
% Ts = 1/Fs; | |
% V = N*Ts; | |
% t=0:Ts:V-Ts; | |
% finc = Fs/N | |
% f = -Fs/2:finc:Fs/2-finc; | |
figure | |
plot(f, abs(HL(f))) | |
grid | |
xlabel('Frequency in Hz.') %Horizontal axis | |
ylabel('Magnitude') %Vertical axis | |
title('HL(f)') %Title of plot | |
figure | |
plot(f, angle(HL(f))) | |
grid | |
xlabel('Frequency in Hz.') %Horizontal axis | |
ylabel('Phase') %Vertical axis | |
title('HL(f)') %Title of plot | |
%%%%%%%%%%%% Exercise B | |
hl = ifft(HL(f)); | |
%hl = 120*sinc(120*(t-1/30)); | |
plot(t, hl) | |
grid | |
xlabel('Time in s') %Horizontal axis | |
ylabel('Magnitude') %Vertical axis | |
title('hl(t)') %Title of plot | |
figure | |
plot(t, angle(hl)) | |
grid | |
xlabel('Time in s') %Horizontal axis | |
ylabel('Phase') %Vertical axis | |
title('hl(t)') %Title of plot | |
%%%%%%%%%%%% Exercise C | |
x = cos(2*pi*30*t) + cos(2*pi*45*t) + cos(2*pi*120*t); | |
% x = cos(2*pi*30*t) + cos(2*pi*30*t); | |
y = conv(x, hl, 'same'); | |
%y = 2*cos(2*pi*30*t)* HL(30)+ 2*cos(2*pi*45*t)*HL(45) + 2*cos(2*pi*120*t)*HL(120); | |
% y = cos(2*pi*120*t)*HL(120); | |
figure | |
plot(t, y) | |
grid | |
xlabel('Time in s') %Horizontal axis | |
ylabel('Magnitude') %Vertical axis | |
title('y(t)') %Title of plot | |
Y = fft(y); | |
figure | |
plot(f, abs(Y)) | |
grid | |
xlabel('Frequency in Hz.') %Horizontal axis | |
ylabel('Magnitude') %Vertical axis | |
title('Y(f)') %Title of plot | |
%%%$%%%%%%%%%%%%%%%%%%%% | |
% fh = -100:100-1; | |
% plot(fh, abs(HL(fh))) | |
% grid | |
% xlabel('Frequency in Hz.') %Horizontal axis | |
% ylabel('Magnitude') %Vertical axis | |
% title('HL(f)') %Title of plot | |
% | |
% figure | |
% plot(fh, angle(HL(fh))) | |
% grid | |
% xlabel('Frequency in Hz.') %Horizontal axis | |
% ylabel('Phase') %Vertical axis | |
% title('HL(f)') %Title of plot | |
% % Inverse | |
% hl = ifft(Hl); | |
% | |
% plot(fh, abs(hl)) | |
% grid | |
% xlabel('Time in s') %Horizontal axis | |
% ylabel('Magnitude') %Vertical axis | |
% title('hl(t)') %Title of plot | |
% | |
% figure | |
% plot(fh, angle(hl)) | |
% grid | |
% xlabel('Time in s') %Horizontal axis | |
% ylabel('Phase') %Vertical axis | |
% title('hl(t)') %Title of plot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment