Consider the following signal
x(n) = ASin(2πf1n) + BSin(2πf2n) + CSin(2πf3n);
where A = 9, B = 8, C = 9
Also f1 = 250 Hz, f2 = 750 Hz and f3 = 989
Sampling Frequency fs = 4000 Hz
Perform the following operation on signal x(n) in MATLAB by developing a code:
a) Plot the signal x(n) in time domain.
b) Perform the DFT of the signal and plot magnitude values of signal in frequency
domain.
c) Apply a Low-pass FIR filter (Use convolution to apply filter) with 500 Hz cut-off
frequency to filter the signal x(n).
d) Plot the signal x(n) in time and frequency domain after filtration
a)
clc;
clear all;
close all;
A=9;
B=8;
C=9;
f1=250;
f2=750;
f3=989;
fS=4000;
n=0:1:100;
x=A*sin(2*3.14*f1*n)+B*sin(2*3.14*f2*n)+C*sin(2*3.14*f3*n);
subplot(2,2,1);
xlabel("x--->");
ylabel("y--->");
title("x");
stem(x,n);
b)
clc;
clear all;
close all;
A=9;
B=8;
C=9;
f1=250;
f2=750;
f3=989;
fS=4000;
n=-10:0.1:10;
x=A*sin(2*3.14*f1*n)+B*sin(2*3.14*f2*n)+C*sin(2*3.14*f3*n);
dft = fft(x); % To Compute DFT of x
magnitude = abs(dft); % Magnitude
frequency = (0:length(dft)-1)*100/length(dft); % Frequency vector
subplot(2,1,1)
plot(frequency,magnitude)
title('Magnitude')
c)
clc;
clear all;
close all;
A=9;
B=8;
C=9;
f1=250;
f2=750;
f3=989;
fs=4000;
n=0:1:10;
x=A*sin(2*3.14*f1*n)+B*sin(2*3.14*f2*n)+C*sin(2*3.14*f3*n);
x1=int16(x);
lpf=lowpass(x1,500,fs);
subplot(2,2,1)
plot(lpf,n)
dft=fft(x);
frequency = (0:length(dft)-1)*100/length(dft);
title('Time domain')
subplot(2,2,2)
plot(lpf,frequency);
title("Frequency domain")
d)
Here is the plot in time domain :
Here is the plot of magnitudes in frequency domain :
Comments
Leave a comment