DSP Lab-7: Parul 2021phxp0026p
DSP Lab-7: Parul 2021phxp0026p
DSP Lab-7: Parul 2021phxp0026p
Parul
2021phxp0026p
1.
Fs = 1000;
fpass=Fs/2;
dt = 1/Fs;
t = (0:dt:1);
%%Sine wave:
Fc1 = 10;
Fc2 = 200;
Fc3 = 2450;
Fc4 = 1250;
Fc5 = 1300;
x1 = 2*cos(2*pi*Fc1*t);
x2 = 2*cos(2*pi*Fc2*t);
x3 = 2*cos(2*pi*Fc3*t);
x4 = 2*cos(2*pi*Fc4*t);
x5 = 2*cos(2*pi*Fc5*t);
y=x2+x1+x3+x4+x5;
z= lowpass(y,fpass,Fs);
zmag=abs(fft(z));
N=length(z);
freq=0:Fs/N:Fs*(N-1)/N;
subplot(3,1,3);
stem(freq,zmag); %Plotting the Magnitude Spectrum after Normalization
xlabel('Frequency (Hz)');
ylabel('Magnitude Spectrum');
title('FFT Magnitude response')
% Plot the signal versus time:
subplot(3,1,1)
plot(t,y);
xlabel('time'); ylabel('amplitude'); title('Signal versus Time');
subplot(3,1,2)
plot(t,z);
xlabel('time'); ylabel('amplitude'); title('filtered Signal versus Time');
sprintf("Specified passband frequency is beyond the Nyquist range so signal has
been filtered with an allpass filter.")
2
Fs = 1000;
dt = 1/Fs;
t = (0:dt:1);
%%Sine wave:
Fc1 = 100;
Fc2 = 200;
Fc3 = 300;
Fc4 = 400;
x1 = 2*cos(2*pi*Fc1*t);
x2 = 2*cos(2*pi*Fc2*t);
x3 = 2*cos(2*pi*Fc3*t);
x4 = 2*cos(2*pi*Fc4*t);
y=x2+x1+x3+x4;
subplot(4,2,1);
plot(t,y);
ymag=abs(fft(y));
N=length(y);
freq=0:Fs/N:Fs*(N-1)/N;
subplot(4,2,3);
plot(freq,ymag);
xlabel('freq in hz');
ylabel('amplitude');
title('original')
z= bandpass(y,[200 300],Fs)
subplot(4,2,2)
plot(t,y,t,z,'linewidth',1.5);
title('Filtered Waveforms');
xlabel('Time (s)');
legend('Original Noisy Signal','Filtered Signal');
zmag=abs(fft(z));
N=length(z);
freq=0:Fs/N:Fs*(N-1)/N;
subplot(4,2,4);
plot(freq,zmag); %Plotting the Magnitude Spectrum after Normalization
xlabel('Frequency (Hz)');
ylabel('Magnitude Spectrum');
title('FFT Magnitude response')