0% found this document useful (0 votes)
60 views

Finding The Spectrum of A Sinusoidal Signal: Program

The documents describe various signal processing techniques including: 1) Finding the spectrum of sinusoidal signals using FFT and plotting the amplitude and power spectra. 2) Computing the DFT and IDFT of a given discrete-time signal. 3) Generating a sinusoidal signal by filtering a triangle wave and analyzing the filtered output. 4) Implementing decimation on signals and sequences to downsample the data.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Finding The Spectrum of A Sinusoidal Signal: Program

The documents describe various signal processing techniques including: 1) Finding the spectrum of sinusoidal signals using FFT and plotting the amplitude and power spectra. 2) Computing the DFT and IDFT of a given discrete-time signal. 3) Generating a sinusoidal signal by filtering a triangle wave and analyzing the filtered output. 4) Implementing decimation on signals and sequences to downsample the data.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 63

Finding the spectrum of a Sinusoidal Signal

Program:
clc;
clear all;
close all;
f = input ('Enter'enter the msg signal frequency>>> ');
fs = input ('Enter'enter the signal sampling frequency>>> ');
N= input ('Enter'enter the total number of samples>>> ');
x = sin (2*pi*f*[1: N]/fs);
y = fft (x);
res = fs/N;
z = res * [0: N-1];
figure
plot (z, abs(y));
title ('The Amplitude Spectrum of the sinusoidal msg signal');
xlabel ('frequency(Hz)');
ylabel ('amplitude(V)');
p = (abs(y/N).^2);
figure
plot (z, p);
title ('The Power Spectrum of the sinusoidal msg signal');
xlabel ('Frequency(Hz)');
ylabel ('Power(Watt)');

Workspace:
.


Output:
Enter the msg signal frequency>>> 100
Enter the signal sampling frequency>>> 2000
Enter the total number of samples>>> 2000


0 200 400 600 800 1000 1200 1400 1600 1800 2000
0
200
400
600
800
1000
1200
The Amplitude Spectrum of the sinusoidal msg signal
frequency(Hz)
a
m
p
l
i
t
u
d
e
(
V
)
0 200 400 600 800 1000 1200 1400 1600 1800 2000
0
0.05
0.1
0.15
0.2
0.25
The Power Spectrum of the sinusoidal msg signal
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
Finding the spectrum of multi-tone Sinusoidal signal
Program:
clc;
clear all;
close all;
f1 = input ('enter the msg1 signal frequency>>> ');
f2 = input ('enter the msg2 signal frequency>>> ');
fs = input ('enter the signal sampling frequency>>> ');
N= input ('enter the total number of samples>>> ');
x = sin (2*pi*f1*[1: N]/fs) + sin (2*pi*f2*[1: N]/fs);
res = fs/N;
z = res * [0: N-1];
y = fft (x);
figure
plot (z, abs (y)
title ('The Amplitude Spectrum of the sinusoidal msg signal');
xlabel ('Frequency(Hz)');
ylabel ('amplitude(V)');
p = (abs(y/N). ^ 2);
figure
plot (z, p);
title ('The Power Spectrum of the sinusoidal msg signal');
xlabel ('Frequency(Hz)');
ylabel ('Power(Watt)');
Workspace:


Output:
Enter the msg1 signal frequency>>> 100
Enter the msg2 signal frequency>>> 200
Enter the signal sampling frequency>>> 2000
Enter the total number of samples>>> 2000


0 200 400 600 800 1000 1200 1400 1600 1800 2000
0
2000
4000
6000
8000
10000
12000
The Amplitude Spectrum of the sinusoidal msg signal
Frequency(Hz)
a
m
p
l
i
t
u
d
e
(
V
)
Finding DFT / IDFT of given DT signal
Program:
clc;
clear all;
x = input ('enter the sequence for which dft has to be found>>>');
m = length(x);
dft_mtx = dftmtx (m);
for i = 0 : m-1
for k = 0 : m-1
dft_mtx (i+1, k+1) = exp (-2*j*pi*i*k/m);
end
end
y = dft_mtx * x';
y_new = (dft_mtx')*y/m;
disp ('the input sequence is');
disp (x);
disp ('the dft of the given sequence is');
disp (y);
disp ('the idft of the above dft is');
disp (y_new);
Workspace:


Output:
Enter the sequence for which dft has to be found>>> [1 2 3 4 5 6 6 7 5 4]
The input sequence is
1 2 3 4 5 6 6 7 5 4

The dft of the given sequence is
43.0000
-9.9721 + 6.5186i
-3.1180 + 0.3633i
-1.0279 - 0.0858i
-0.8820 + 1.5388i
-3.0000 - 0.0000i
-0.8820 - 1.5388i
-1.0279 + 0.0858i
-3.1180 - 0.3633i
-9.9721 - 6.5186i

The idft of the above dft is
1.0000 + 0.0000i
2.0000 + 0.0000i
3.0000 - 0.0000i
4.0000 + 0.0000i
5.0000 + 0.0000i
6.0000 - 0.0000i
6.0000 - 0.0000i
7.0000 + 0.0000i
5.0000 - 0.0000i
4.0000 + 0.0000i


Generation of Sinusoidal Signal through Filtering
Program:
clc;
clear all;
close all;
N = input('enter the total number of samples(even)>>>');
m = input('enter the number of samples per cycle(odd)>>>');
fs = input('enter the sampling frequency>>>');
m_new = ceil(m/2);
count = N / m;
x = zeros(1, N);
for k = 0 : count
for i = 1 : m_new
x(i+(k*m)) = i - 1;
end
for j = 1 : m_new-1
x(j+m_new+(k*m)) = m_new - j - 1;
end
end
res = fs/N;
z = res * [0: N];
figure
plot (z, x);
title ('Triangle Function');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
figure
plot (z,abs(fft(x)));
title ('Amplitude response of the Triangle Function');
xlabel ('Frequency(Hz) ');
ylabel ('Amplitude(V)');
p = (abs (fft (x)/N)).^2;
figure
plot (z, p);
title ('Power Spectrum of the Triangle Function');
xlabel ('Frequency(Hz) ');
ylabel ('Power (Watt)');
fc = fs/m;
n = 2*(fc + 20)*[-N/2 : N/2]/N;
h = sinc(n);
w = blackman(N+1)';
figure
plot(z, w);
title ('Amplitude response of the Blackman Window');
xlabel ('Frequency(Hz) ');
ylabel ('Amplitude(V)');
h_new = h.*w;
figure
plot(z, h_new);
title ('Impulse response of the windowed filter');
xlabel ('Frequency(Hz) ');
ylabel ('Amplitude(V)');
figure
plot (abs (fft (h_new)));
title ('Amplitude response of the windowed filter');
xlabel ('Frequency(Hz) ');
ylabel ('Amplitude(V)');
y1 = filter(h_new, 1, x);
figure
plot(z, abs(fft(y1)));
title ('Amplitude response of the filtered output');
xlabel ('Frequency(Hz) ');
ylabel ('Amplitude(V)');
p1 = (abs (fft (y1)/N)).^2;
figure
plot (z, p1);
title ('Power Spectrum of the Triangle Function');
xlabel ('Frequency(Hz) ');
ylabel ('Power (Watt)');
figure
plot(z, y1);
title ('The Filtered Output');
xlabel ('Frequency(Hz) ');
ylabel ('Amplitude(V)');























Workspace:















Output:
Enter the total number of samples (even)>>>1000
Enter the number of samples per cycle (odd)>>>11
Enter the sampling frequency>>>1000

0 50 100 150 200 250 300
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
Triangle Function
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)


0 100 200 300 400 500 600 700 800 900 1000
0
500
1000
1500
2000
2500
Amplitude response of the Triangle Function
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 100 200 300 400 500 600 700 800 900 1000
0
1
2
3
4
5
6
Power Spectrum of the Triangle Function
Frequency(Hz)
P
o
w
e
r

(
W
a
t
t
)


0 100 200 300 400 500 600 700 800 900 1000
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Amplitude response of the Blackman Window
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)



250 300 350 400 450 500 550 600 650 700 750
-0.2
0
0.2
0.4
0.6
0.8
1
Impulse response of the windowed filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 200 400 600 800 1000 1200
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
Amplitude response of the windowed filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt



0 100 200 300 400 500 600 700 800 900 1000
0
1000
2000
3000
4000
5000
6000
Amplitude response of the filtered output
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 100 200 300 400 500 600 700 800 900 1000
0
5
10
15
20
25
30
Power Spectrum of the Filtered output
Frequency(Hz)
P
o
w
e
r

(
W
a
t
t
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt


Formatted: Font: Times New Roman, 12 pt



250 300 350 400 450 500 550 600 650 700 750
-0.2
0
0.2
0.4
0.6
0.8
1
Impulse response of the windowed filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 200 400 600 800 1000 1200
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
Amplitude response of the windowed filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt



0 100 200 300 400 500 600 700 800 900 1000
0
1000
2000
3000
4000
5000
6000
Amplitude response of the filtered output
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 100 200 300 400 500 600 700 800 900 1000
0
5
10
15
20
25
30
Power Spectrum of the Filtered output
Frequency(Hz)
P
o
w
e
r

(
W
a
t
t
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt

















Formatted: Font: Times New Roman, 12 pt
Implementation of Decimation Process
on a variable

Program:
clc;
clear all;
x = input ('enter the sequence to be decimated>>> ');
N = length (x);
n = input ('enter the value by which the sequence must be decimated>>> ');
y = x (1: n: N);
disp ('the input sequence is');
disp (x);
disp ('the decimated output sequence is');
disp (y);

Workspace:

Output:
Enter the sequence to be decimated>>> [1 2 3 4 5 6 7]
Enter the value by which the sequence must be decimated>>> 2
The input sequence is
1 2 3 4 5 6 7

The decimated output sequence is
1 3 5 7
Implementation of Decimation Process
on a signal
Program:
clc;
clear all;
f = input('enter the frequency of the sinusoidal singal that must be decimated>>> ');
fs = input('enter the sampling frequency of the given signal>>> ');
N = input('enter the total number of samples>>> ');
n = input('enter the value by which the given signal must be decimated>>> ');
x = sin(2*pi*f*[0 : N]/fs);
res = fs/N;
z = res*[0 : N];
figure
plot (z, abs (fft (x)));
title ('Amplitude Response of the Input Signal');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
p = (abs (fft (x)/N)) .^ 2;
figure
plot (z, p);
title ('Power Spectrum of the Input Signal');
xlabel ('Frequency(Hz)');
ylabel ('Power(Watt)');
x_new = x(1 : n : N+1);
z1 = res*[0: N/n];
figure
plot (z1, abs(fft (x_new)));
title ('Amplitude Response of the Decimated Signal');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
p1 = (abs (fft (x_new)*n/N)) .^ 2;
figure
plot (z1, p1);
title ('Power Spectrum of the Decimated Signal');
xlabel ('Frequency(Hz)');
ylabel ('Power(Watt)');


Workspace:

Output:
Enter the frequency of the sinusoidal signal that must be decimated>>> 100
Enter the sampling frequency of the given signal>>> 2000
Enter the total number of samples>>> 2000
Enter the value by which the given signal must be decimated>>> 2

0 100 200 300 400 500 600 700 800 900 1000
0
50
100
150
200
250
300
350
400
450
500
Amplitude Response of the Decimated Signal
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)



0 200 400 600 800 1000 1200 1400 1600 1800 2000
0
0.05
0.1
0.15
0.2
0.25
Power Spectrum of the Input Signal
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
0 100 200 300 400 500 600 700 800 900 1000
0
50
100
150
200
250
300
350
400
450
500
Amplitude Response of the Decimated Signal
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)


0 100 200 300 400 500 600 700 800 900 1000
0
0.05
0.1
0.15
0.2
0.25
Power Spectrum of the Decimated Signal
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
Formatted: Font: Times New Roman, 12 pt
















0 100 200 300 400 500 600 700 800 900 1000
0
0.05
0.1
0.15
0.2
0.25
Power Spectrum of the Decimated Signal
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
Formatted: Font: Times New Roman, 12 pt
Implementation of Interpolation Process
on a variable
Program:
clc;
clear all;
x = input ('enter the sequence to be interpolated>>> ');
N = length (x);
n = input ('enter the value by which the sequence must be up-sampled>>> ');
m = N * n;
y = zeros (1, m);
y (1: n: m) = x;
disp ('the input sequence is');
disp (x);
disp ('the interpolated output sequence is');
disp (y);
Workspace:

Output:
Enter the sequence to be interpolated>>> [1 2 3 4 5]
Enter the value by which the sequence must be up-sampled>>> 3
The input sequence is
1 2 3 4 5
The interpolated output sequence is
1 0 0 2 0 0 3 0 0 4 0 0 5 0 0
Implementation of Interpolation Process
on a signal
Program:
clc;
clear all;
f = input ('enter the frequency of the sinusoidal singal that must be up-sampled>>> ');
fs = input ('enter the sampling frequency of the given signal>>> ');
N = input ('enter the total number of samples>>> ');
m = input ('enter the value by which the given signal must be up-sampled>>> ');
x = sin (2*pi*f*[1: N]/fs);
res = fs/N;
z = res*[0: N-1];
figure
plot (z, abs (fft (x)));
title ('Amplitude Response of the Input Signal');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
p = (abs (fft (x)/N)) .^ 2;
figure
plot ( z, p);
title ('Power Spectrum of the Input Signal');
xlabel ('Frequency(Hz)');
ylabel ('Power(Watt)');
M = N*m;
x_up = upsample(x, m);
z1 = res*[0: M-1];
figure
plot (z1, abs (fft (x_up)));
title ('Amplitude Response of the Up-sampled Signal');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
n = 2*f*[-N/2: N/2]/N;
h = sinc (n);
figure
plot (h);
title ('Impulse Response of the Image Rejection Filter');
xlabel ('Frequency (Hz)');
ylabel ('Amplitude (V)');
figure
plot (abs (fft (h)));
title ('Amplitude Response of the Image Rejection Filter');
xlabel ('Frequency (Hz)');
ylabel ('Amplitude (V)');
w = blackman (N+1)';
figure
plot(w);
title ('Amplitude Response of the Blackman Window');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
h_new = h.*w;
figure
plot (h_new);
title ('Impulse Response of the Windowed Image Rejection Filter');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
figure
plot (abs (fft (h_new)));
title ('Amplitude Response of the Windowed Image Rejection Filter');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
y = filter (h_new, 1, x_up);
figure
plot (z1, abs (fft (y)));
title ('Amplitude Response of the Image Rejected Interpolated Input Signal');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
p1 = (abs (fft (y)/M)) .^ 2;
figure
plot (z1, p1);
title ('Power Spectrum of the Image Rejected Interpolated Input Signal');
xlabel ('Frequency(Hz)');
ylabel ('Power(Watt)');





















Workspace:














Output:
Enter the frequency of the sinusoidal signal that must be up-sampled>>> 100
Enter the sampling frequency of the given signal>>> 1000
Enter the total number of samples>>> 1000
Enter the value by which the given signal must be up-sampled>>> 2


0 100 200 300 400 500 600 700 800 900 1000
0
50
100
150
200
250
300
350
400
450
500
Amplitude Response of the Input Signal
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)



0 100 200 300 400 500 600 700 800 900 1000
0
0.05
0.1
0.15
0.2
0.25
Power Spectrum of the Input Signal
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
0 200 400 600 800 1000 1200 1400 1600 1800 2000
0
50
100
150
200
250
300
350
400
450
500
Amplitude Response of the Up-sampled Signal
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)



300 350 400 450 500 550 600 650 700
-0.4
-0.2
0
0.2
0.4
0.6
0.8
Impulse Response of the Image Rejection Filter
Frequency (Hz)
A
m
p
l
i
t
u
d
e

(
V
)
0 200 400 600 800 1000 1200
0
1
2
3
4
5
6
Amplitude Response of the Image Rejection Filter
Frequency (Hz)
A
m
p
l
i
t
u
d
e

(
V
)
Formatted: Font: Times New Roman, 12 pt



0 200 400 600 800 1000 1200
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Amplitude Response of the Blackman Window
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
300 350 400 450 500 550 600 650 700
-0.2
0
0.2
0.4
0.6
0.8
1
Impulse Response of the Windowed Image Rejection Filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt



0 200 400 600 800 1000 1200
0
1
2
3
4
5
6
Amplitude Response of the Windowed Image Rejection Filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 200 400 600 800 1000 1200 1400 1600 1800 2000
0
200
400
600
800
1000
1200
1400
1600
1800
2000
Amplitude Response of the Image Rejected Interpolated Input Signal
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt


0 200 400 600 800 1000 1200 1400 1600 1800 2000
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Power Spectrum of the Image Rejected Interpolated Input Signal
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
Formatted: Font: Times New Roman, 12 pt



0 200 400 600 800 1000 1200
0
1
2
3
4
5
6
Amplitude Response of the Image Rejection Filter
Frequency (Hz)
A
m
p
l
i
t
u
d
e

(
V
)
0 200 400 600 800 1000 1200
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Amplitude Response of the Blackman Window
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt



300 350 400 450 500 550 600 650 700
-0.2
0
0.2
0.4
0.6
0.8
1
Impulse Response of the Windowed Image Rejection Filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 200 400 600 800 1000 1200
0
1
2
3
4
5
6
Amplitude Response of the Windowed Image Rejection Filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt



0 200 400 600 800 1000 1200 1400 1600 1800 2000
0
200
400
600
800
1000
1200
1400
1600
1800
2000
Amplitude Response of the Image Rejected Interpolated Input Signal
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 200 400 600 800 1000 1200 1400 1600 1800 2000
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Power Spectrum of the Image Rejected Interpolated Input Signal
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt

Implementation of I/D Sampling Rate
Converters
Program:
clc;
clear all;
close all;
fs = input ('enter the sampling frequency of the given signal>>> ');
f1 = input ('enter the frequency of 1st msg signal>>> ');
f2 = input ('enter the frequency of 2nd msg signal>>> ');
l = input ('enter the value by which the signal must be up sampled>>> ');
m = input ('enter the value by which the signal must be down sampled>>> ');
x = sin (( 2*pi*f1*[1: fs]/fs) + sin (( 2*pi*f2*[1: fs]/fs);
figure
plot (abs (fft (x)));
title ('Amplitude Response of the Input Signal');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
p = (abs (fft (x)/fs)).^2;
figure
plot (p);
title ('Power spectrum of the Input Signal');
xlabel ('Frequency(Hz)');
ylabel ('Power (Watt)');
N1 = l*fs;
fs1 = N1;
x_up = zeros (1, N1);
x_up (1: l: N1) = x;
figure
plot (abs (fft (x_up)));
title ('Amplitude Response of the up-sampled Input Signal');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
p1 = (abs (fft (x_up)/N1)).^2;
figure
plot (p1);
title ('Power spectrum of the up-sampled Input Signal');
xlabel ('Frequency(Hz)');
ylabel ('Power(Watt)');
fc1 = fs1/ (/(2*l);
fc2 = fs1/ (/(2*m);
if fc1 <= fc2
fc = fc1;
else
fc = fc2;
Formatted: Font: (Intl) Times New Roman
Formatted: Font: (Intl) Times New Roman
end
n = 2 * (fc)*[-N1/2: N1/2]/fs1;
h = sinc (n);
figure
plot (abs (fft (h)));
title ('Amplitude Response of the filter');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
w = blackman (N1+1)';
h_new = h.*w;
figure
plot (abs (fft (h_new)));
title ('Amplitude Response of the windowed filter');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
y = filter (h_new, 1, x_up);
figure
plot (abs (fft (y)));
title ('Amplitude Response of the image rejected output');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
p2 = (abs (fft (y)/N1)).^2;
figure
plot (p2);
title ('Power spectrum of the image rejected output');
xlabel ('Frequency(Hz)');
ylabel ('Power(Watt)');
y_down = y (1: m: fs1);
figure
plot (abs (fft (y_down)));
title ('Amplitude Response of the image rejected down-sampled output');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
p3 = (abs (fft (y_down)*m/N1)).^2;
figure
plot (p3);
title ('Power spectrum of the image rejected down-sampled output');
xlabel ('Frequency(Hz)');
ylabel ('Power(Watt)');








Workspace:


Formatted: Font: Times New Roman












Output:
Enter the sampling frequency of the given signal>>> 400
Enter the frequency of 1st msg signal>>> 100
Enter the frequency of 2nd msg signal>>> 190
Enter the value by which the signal must be up sampled>>> 11
Enter the value by which the signal must be down sampled>>> 5

0 50 100 150 200 250 300 350 400
0
50
100
150
200
250
Amplitude Response of the Input Signal
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)


0 50 100 150 200 250 300 350 400
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
Power spectrum of the Input Signal
Frequency(Hz)
P
w
e
r
(
W
a
t
t
)
0 500 1000 1500 2000 2500 3000 3500 4000 4500
0
50
100
150
200
250
Amplitude Response of the up-sampled Input Signal
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)





0 500 1000 1500 2000 2500 3000 3500 4000 4500
0
2
4
6
8
10
12
Amplitude Response of the filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 500 1000 1500 2000 2500 3000 3500 4000 4500
0
2
4
6
8
10
12
Amplitude Response of the windowed filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt



0 500 1000 1500 2000 2500 3000 3500 4000 4500
0
200
400
600
800
1000
1200
Amplitude Response of the image rejected output
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 500 1000 1500 2000 2500 3000 3500 4000 4500
0
0.01
0.02
0.03
0.04
0.05
0.06
0.07
Power spectrum of the image rejected output
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt



0 100 200 300 400 500 600 700 800 900
0
50
100
150
200
250
Amplitude Response of the image rejected down-sampled output
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 100 200 300 400 500 600 700 800 900
0
0.01
0.02
0.03
0.04
0.05
0.06
0.07
Power spectrum of the image rejected down-sampled output
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt
FIR Low Pass Filter
Program:
clc;
clear all;
close all;
fs = input ('Enter the rate at which the given signal is being sampled>>> ');
fc = input ('Enter the cut-off frequency of the required low pass filter>>> ');
N = input ('Enter the total number of samples>>> ');
n = 2 * fc * [-N/2: N/2]/fs;
h = sinc (n);
w = blackman (N+1)';
h_w = w.* h;


0 500 1000 1500 2000 2500 3000 3500 4000 4500
0
2
4
6
8
10
12
Amplitude Response of the filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt



0 500 1000 1500 2000 2500 3000 3500 4000 4500
0
2
4
6
8
10
12
Amplitude Response of the windowed filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
0 500 1000 1500 2000 2500 3000 3500 4000 4500
0
200
400
600
800
1000
1200
Amplitude Response of the image rejected output
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt



0 500 1000 1500 2000 2500 3000 3500 4000 4500
0
0.01
0.02
0.03
0.04
0.05
0.06
0.07
Power spectrum of the image rejected output
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
0 100 200 300 400 500 600 700 800 900
0
50
100
150
200
250
Amplitude Response of the image rejected down-sampled output
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt


res = fs/N;
z = res*[0: N];
figure
plot (z, abs (fft (h_w)));
title ('Amplitude response of the FIR Low Pass Filter');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
0 100 200 300 400 500 600 700 800 900
0
0.01
0.02
0.03
0.04
0.05
0.06
0.07
Power spectrum of the image rejected down-sampled output
Frequency(Hz)
P
o
w
e
r
(
W
a
t
t
)
Formatted: Font: Times New Roman, 12 pt
Workspace:


Formatted: Font: Times New Roman
Output:
Enter the rate at which the given signal is being sampled>>> 4000
Enter the cut-off frequency of the required low pass filter>>> 100
Enter the total number of samples>>> 4000


0 500 1000 1500 2000 2500 3000 3500 4000
0
5
10
15
20
25
Amplitude response of the FIR Low Pass Filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Formatted: Font: Times New Roman, 12 pt
FIR High Pass Filter
Program:
clc;
clear all;
close all;
fs = input ('Enter the rate at which the given signal is being sampled>>> ');
fc = input ('Enter the cut-off frequency of the required high pass filter>>> ');
N = input ('Enter the total number of samples>>> ');
fc1 = (fs/2) - fc;
n = 2 * fc1 * [-[ -N/2: N/2]/fs;
h = sinc (n);
a = -1 * ones (1, N+1);
b = [0: N];
c = a.^b;
h_new = c .* h;
w = blackman (N+1)';
h_w = w .* h_new;
res = fs/N;
z = res*[0: N];
figure
res = fs/N;
z = res*[0: N];
figure
plot (z, abs (fft (h_w)));
title ('Amplitude response of the FIR High Pass Filter');
xlabel ('Frequency(Hz)');
ylabel ('Amplitude(V)');
Workspace:

Output:
Enter the rate at which the given signal is being sampled>>> 4000
Enter the cut-off frequency of the required high pass filter>>> 100
Enter the total number of samples>>> 4000
Formatted: Font: Times New Roman
Formatted: Font: Times New Roman


0 500 1000 1500 2000 2500 3000 3500 4000
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Amplitude response of the FIR High Pass Filter
Frequency(Hz)
A
m
p
l
i
t
u
d
e
(
V
)
Linear Convolution of a Sequence
Program:
clc;
clear all;
close all;
x = input ('Enter the sequence x>>> ');
h = input ('Enter the sequence h>>> ');
N = length (x);
n = length (h);
y = zeros (1, N+n);
t = zeros (1, n);
for i = 1:N+n-1
if i <= N
t(1)= x(i);
for j = 1 : n
y(i) = y(i) + h(j)*t(j);
end
for k = n:-1:2
t(k) = t(k-1);
end
else
t(1)= 0;
for j = 1:n
y(i) = y(i) + (h(j)*t(j));
end
for k = n:-1:2
t(k) = t(k-1);
end
end
end
disp ('The given sequences are');
disp ('x =');
disp (x);
disp ('h =');
disp (h);
disp ('The convoluted output of x and h is');
disp ('y =');
disp (y);

Workspace:

Output:
Enter the sequence x>>> [1 2 3 4 5 6]
Enter the sequence h>>> [1 2 3 4 5 6 7 8 9]
The given sequences are
x =
1 2 3 4 5 6

h =
1 2 3 4 5 6 7 8 9

The convoluted output of x and h is
y =
1 4 10 20 35 56 77 98 119 130 130 118 93 54 0

Formatted: Font: Times New Roman
Generation of
Dual-tone Multi Frequency Signal
Program:
clc;
clear all;
close all;
key = input ('Enter any key on your keypad>>> ');
fs= 4000;
N = fs;
row = [697 770 884 941];
column = [1209 1366 1477];
if key == 1 || key == 2 || key == 3
row1 = row (1, 1);
end
if key == 4 || key == 5 || key == 6
row1 = row (1, 2);
end
if key == 7 || key == 8 || key == 9
row1 = row (1, 3);
end
if key == '*' || key == 0 || key == '#'
row1 = row (1, 4);
end
if key == 1 || key == 4 || key == 7 || key == '*'
col = column (1, 1);
end
if key == 2 || key == 5 || key == 8 || key == 0
col = column (1, 2);
end
if key == 3 || key == 6 || key == 9 || key == '#'
col = column (1, 3);
end
res = fs/N;
z = res*[0: N];
In = [1 zeros(1, N)];
a1 = sin (2* pi*row1/fs);
b1 = [1 (-2*cos (2*pi*row1/fs)) 1];
a2 = sin (2* pi*col/fs);
b2 = [1 (-2*cos (2*pi*col/fs)) 1];
y = filter (a1, b1, In) + filter (a2, b2, In);
figure
plot (z, y);
title ('The DTMF Signal');
xlabel ('Frequency Index (Hz)');
ylabel ('Amplitude (V)');
figure
plot (z, abs (fft (y)));
title ('The DTMF Signal');
xlabel ('Frequency (Hz)');
ylabel ('Amplitude (V)');

Workspace:


Formatted: Font: Times New Roman
Output:
Enter any key on your keypad>>> 1



0 500 1000 1500 2000 2500 3000 3500 4000
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
The DTMF Signal
Frequency Index (Hz)
A
m
p
l
i
t
u
d
e

(
V
)
0 500 1000 1500 2000 2500 3000 3500 4000
0
200
400
600
800
1000
1200
1400
1600
1800
2000
Amplitude Response of the DTMF Signal
Frequency (Hz)
A
m
p
l
i
t
u
d
e

(
V
)
Formatted: Font: Times New Roman, 12 pt
Formatted: Font: Times New Roman, 12 pt

You might also like