0% found this document useful (0 votes)
59 views7 pages

15LEB369

The document describes several signal processing examples: 1) It takes the discrete Fourier transform (DFT) of an input signal, an upsampled version of the signal, and a downsampled version. It plots the magnitude spectra of the original and processed signals. 2) It filters a corrupted audio signal using a notch filter to remove noise at a specific frequency. It plots the magnitude spectra before and after filtering. 3) It applies median filtering to reduce noise in an image. It shows the original noisy image and filtered image. 4) It describes filtering two input signals through two different linear time-invariant systems and plots the input/output signals. So in summary, the document presents examples

Uploaded by

s.r.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views7 pages

15LEB369

The document describes several signal processing examples: 1) It takes the discrete Fourier transform (DFT) of an input signal, an upsampled version of the signal, and a downsampled version. It plots the magnitude spectra of the original and processed signals. 2) It filters a corrupted audio signal using a notch filter to remove noise at a specific frequency. It plots the magnitude spectra before and after filtering. 3) It applies median filtering to reduce noise in an image. It shows the original noisy image and filtered image. 4) It describes filtering two input signals through two different linear time-invariant systems and plots the input/output signals. So in summary, the document presents examples

Uploaded by

s.r.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Question 6

len =input('enter the length of sequence: ');


L= input('enter the ussampling factor: ');
f= input('enter the signal frequency: ');
n=[0:len-1];
x=sin(2*pi*f*n);
y = zeros(1, L*length(x));
y([1:L: length(y)]) = x;
figure(1)
subplot(2,1,1)
stem(n,x);
title('Orginal Sequence');
xlabel('Time Index n');
ylabel('Amplitude');
subplot(2,1,2)
stem(n, y(1: length(x)));
title(['Original Sequence up-sampled by: ',
num2str(L)]);
xlabel('Time Index n');
ylabel('Amplitude');

figure(2)
z1 = fft(x, len);
k=0:1:len-1;
subplot(2,1,1)
%val1=abs(z1);
stem(k, abs(z1))
title('Magnitude of the DFT samples')
xlabel('Fequency index k') Question 7
ylabel('Magnitude')

z2 = fft(y, len);
k=0:1: L+len-1 ; len =input('enter the length of sequence: ');
M= input('enter the down-sampling factor: ');
subplot(2,1,2) f= input('enter the signal frequency: ');
n=[0:1:len-1];
stem(abs(z2)) m=0 : len *M-1;
title('Magnitude of the upsampled DFT samples') x=sin(2*pi*f*m);
xlabel('Fequency index k') y = downsample(x,M);
ylabel('Magnitude') figure(1)
subplot(2,1,1)
stem(n,x(1: len));
title('Input Sequence');
xlabel('Time Index n');
OUTPUT: ylabel('Amplitude');
enter the length of sequence: 50 subplot(2,1,2)
enter the ussampling factor: 3 stem(y);
enter the signal frequency: 0.042 title(['Input Sequence down-sampled by: ',
num2str(M)]);
xlabel('Time Index n');
ylabel('Amplitude');

figure(2)
z1 = fft(x, len);
k=0:1:len-1;
subplot(2,1,1)
%val1=abs(z1);
stem(k, abs(z1))
title('Magnitude of the DFT samples')
xlabel('Fequency index k')
ylabel('Magnitude')

z2 = fft(y, len);
k=0:1: M+len-1 ; Question 9
subplot(2,1,2) f=150;
t=[0:0.001:10];
stem(abs(z2)) c=[];
title('Magnitude of the down-sampled DFT x = sin( 2 * pi * f .* t);
samples') snr = [20:-5:-20];
xlabel('Fequency index k') for i=1:9
ylabel('Magnitude') y= awgn(x, snr(i));
z= corrcoef(x,y);
c=[c, z(1,2)]
end
figure()
OUTPUT: plot(snr,c)
enter the length of sequence: 50 title('Correlation coefficient Vs SNR')
enter the down-sampling factor: 3 xlabel('signal to noise ratio')
enter the signal frequency: 0.042 ylabel('correlation coefficient')

Question 10
clc;
clear all;
close all;
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
fs = 5000; P1(2:end-1) = 2*P1(2:end-1);
ts = 1/fs; f = Fs*(0:(L/2))/L;
L = 1500; plot(f,P1)
t = (0:L-1)*ts; xlabel('Spectrum of Input Signal')
title('Spectrum of Signal')
x = cos(2*pi*500*t) + cos(2*pi*1000*t) subplot(3,1,2)
+cos(2*pi*1500*t); M = fft(y1);
Fctff1 = 800 P2 = abs(M/L);
P1 = P2(1:L/2+1);
d1 = designfilt('lowpassfir', 'FilterOrder', 20, P1(2:end-1) = 2*P1(2:end-1);
'CutoffFrequency', ... f = Fs*(0:(L/2))/L;
Fctff1, 'SampleRate', 5000, 'Window', 'hamming'); plot(f,P1)
xlabel(['Spectrum of Signal passed through Low
Fctff2 = 1100; Pass Filter,Cutoff frequency ' num2str(Fctff1) ''])
d2 = designfilt('highpassfir', 'FilterOrder', 20, subplot(3,1,3)
'CutoffFrequency', ... M = fft(y2);
Fctff2, 'SampleRate', 5000, 'Window', 'hamming'); P2 = abs(M/L);
P1 = P2(1:L/2+1);
h1=impz(d1); P1(2:end-1) = 2*P1(2:end-1);
y1 = conv(x,h1); f = Fs*(0:(L/2))/L;
h2=impz(d2); plot(f,P1)
y2 = conv(x,h2); xlabel(['Spectrum of Signal passed through High
Pass Filter,Cutoff frequency ' num2str(Fctff2) ''])
figure;
subplot(3,1,1);
t=0:1:length(x)-1;
stem(t,x);
axis([0 50 -4 4])
xlabel('Input Signal')
ylabel('Amplitude')
title('Signal in Time Domain')
subplot(3,1,2);
t=0:1:length(y1)-1;
stem(t,y1);
axis([0 50 -4 4])
xlabel('Output when passed through Low Pass
Filter')
ylabel('Amplitude')
subplot(3,1,3);
t=0:1:length(y2)-1;
stem(t,y2);
axis([0 50 -4 4])
xlabel('Output when passed through High Pass
Filter')
ylabel('Amplitude')

figure;
subplot(3,1,1)
Y = fft(x);
Question number 11

clc;
clear all;
close all;
[x fs] = audioread('enjoy_10K_corrupted.wav');
sound(x, fs);

wo = 0.3;
bw = wo/5;

[b,a] = iirnotch(wo, bw);


fvtool(b,a) Question 12
subplot(2,1,1)
n =1500; clc
y=fft(x,n); clear all
k=(0:n-1)/n; close all
plot(k,abs(y)); image= imread('images.jpg');
title('Spectrum of Corrupted audio') image = rgb2gray(image);
xlabel('frequency') figure()
ylabel('Amplitude') subplot(1,2,1);
imshow(image)
title('Image with Noise')
h=impz(b,a);
[a,b] = size(image);
convol = conv(x,h); k = zeros(a,b,'uint8');
for i= 1:a
n =500; for j=1:b
y=fft(convol,n); xmin = max(1,i-1);
subplot(2,1,2) xmax = min(a,i+1);
k=(0:n-1)/n; ymin = max(1,j-1);
plot(k,abs(y)); ymax = min(a,j+1);
title('Spectrum of Filtered audio') z = image(xmin:xmax, ymin:ymax);
xlabel('frequency') k(i,j)= median(z(:));
ylabel('Amplitude') end
end
sound(convol, fs); subplot(1,2,2)
imshow(k);
title('Filtered Image')
t=0:1:length(y1_2)-1;
stem(t,y1_2);
axis([0 50 -1 1])
xlabel('Output through system 2')
ylabel('Amplitude')

figure;
subplot(3,1,1);
t=0:1:n
stem(t,x2);
axis([0 50 -1 1])
xlabel('Input 2')
ylabel('Amplitude')
Question 13 subplot(3,1,2);
t=0:1:length(y2_1)-1;
stem(t,y2_1);
clc; axis([0 50 -1 1])
clear all; xlabel('Output through system 1')
close all; ylabel('Amplitude')
subplot(3,1,3);
n=50 t=0:1:length(y2_2)-1;
b1 = [1/3 1/3 1/3]; stem(t,y2_2);
b2 = [1/3 -1/3 1/3]; axis([0 50 -1 1])
a = [1]; xlabel('Output through system 2')
ylabel('Amplitude')
fvtool(b1,a)
fvtool(b2,a)
h1 = impz(b1,a,n)
h2 = impz(b2,a,n)

t=0:1:n
x1 = sin(2*pi*(pi/4)*t);
x2 = sin(2*pi*(pi)*t);
y1_1= conv(x1,h1);
y1_2= conv(x1,h2);
y2_1= conv(x2,h1);
y2_2= conv(x2,h2);

subplot(3,1,1);
stem(t,x1);
axis([0 50 -1 1])
xlabel('Input 1')
ylabel('Amplitude')
subplot(3,1,2);
t=0:1:length(y1_1)-1;
stem(t,y1_1);
axis([0 50 -1 1])
xlabel('Output through system 1')
ylabel('Amplitude')
subplot(3,1,3);
0.1000
0.0900
Question14 0.2350
0.2341
clc; 0.0799
clear all; -0.0874
close all; -0.1448
-0.0796
b = [0 1 -1.2 1]; 0.0277
a = [1 -1.3 1.04 -0.222]; 0.0867
0.0661
h1 = impz(b,a,100) 0.0020
fvtool(b,a) -0.0469
fvtool(b,a,'polezero') -0.0484
ISstable_yes1_no0 = isstable(b,a) -0.0137
0.0221
fs = 2048; % Sampling frequency 0.0323
t = 1/fs; % Sampling period 0.0159
L = 50; % Length of signal -0.0080
n = (0:L-1)*t; -0.0197
-0.0138
s= sin(1800*n/fs) + sin(1900*n/fs) + 0.0008
sin(2000*n/fs); 0.0110
y=conv(s,h1); 0.0104
0.0023
figure; -0.0054
subplot(2,1,1) -0.0071
Y = fft(s); -0.0031
P1 = abs(Y/L); 0.0022
f = fs*(0:L-1)/L; 0.0045
plot(f,P1) 0.0029
xlabel('Spectrum of Input Signal') -0.0004
title('Spectrum of Signal') -0.0026
subplot(2,1,2) -0.0022
M = fft(y); -0.0003
P1 = abs(M/L); 0.0013
f = fs*(0:length(y)-1)/length(y); 0.0016
plot(f,P1) 0.0006
xlabel('Spectrum of Signal passed through Filter') -0.0006
-0.0010
-0.0006
0.0002
a) since poles are located other than origin 0.0006
hence iir filter. 0.0005
0.0000
From the response it is clear that given filter -0.0003
is notch filter. -0.0003
-0.0001
b) h1 = 0.0001
0.0002
0 0.0001
1.0000 -0.0000
-0.0001
-0.0001
0.0000
0.0001
0.0001
0.0000
-0.0000
-0.0000
-0.0000
0.0000
0.0000
0.0000
-0.0000
-0.0000
-0.0000
-0.0000
0.0000
0.0000
0.0000
-0.0000
-0.0000
-0.0000
0.0000
0.0000
0.0000
0.0000
-0.0000
-0.0000
-0.0000
0.0000
0.0000
0.0000
-0.0000
-0.0000
-0.0000
-0.0000
0.0000
0.0000
0.0000
-0.0000
-0.0000
-0.0000
0.0000
0.0000
0.0000
-0.0000

ISstable_yes1_no0 =

You might also like