In: Electrical Engineering
Use and provide Matlab for the following: Generate the discrete-time signal x[n] = 4 cos (2pi. 10. nT5) + 2cos(2pi. 100. nT5) + 3cos(2pi 200. nT's), with Ts0.001 sec. Display the signal in both time and frequency-domain. Assume that the 100 Hz component of x [n] is your desired signal while the other two components are noise. Design a suitable filter to extract the desired (i.e. 100 Hz) signal. Display the filter's response. Display the output signal in the frequency-domain. Display the time-domain input and output signals in the same plot.
Matlab Code:
clc;clear;
Ts = 0.0001;
Fs = 1/Ts;
nT = 0:Ts:1;
x = 4*cos(2*pi*10*nT) + 2*cos(2*pi*100*nT) +
3*cos(2*pi*200*nT);
figure;
subplot(2,1,1)
plot(nT,x)
grid on
xlabel 'Time'
ylabel 'Amplitude'
title 'Time Domain Input Signal'
N = length(x);
del_f = (-Fs/2):(Fs/(N-1)):(Fs/2);
X = fftshift(fft(x)/N);
subplot(2,1,2)
plot(del_f,abs(X))
grid on;
xlabel 'Freq'
ylabel 'Amplitude'
title 'Frequency Domain Output Signal'
[b,a] =butter(3, (110/10000));
y_filt_low = filter(b,a,x);
[b,a] =butter(3, (90/10000), 'high')
y_filt = filter(b,a,y_filt_low);
figure;
subplot(2,1,1)
plot(nT,y_filt)
grid on;
xlabel 'Amplitude'
ylabel 'Time'
title 'Output Signal in Time Domain'
N = length(y_filt);
del_f = (-Fs/2):(Fs/(N-1)):(Fs/2);
X = fftshift(fft(y_filt)/N);
subplot(2,1,2)
plot(del_f,abs(X))
grid on;
xlabel 'Freq'
ylabel 'Amplitude'
title 'Output Signal in Frequecny Domain'
%%-----------------------------------------------------------------