Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

clc;

clear all;
close all;

fprintf('This is a window function plotting program\n');


fprintf('1. Rectangle = rec\n2. Triangle = tri\n3. Hamming = ham\n4. Hanning = han\n5. Plot All = all\
n');

a = input('Enter Total number of samples: ');


n = 0:a;
N = length(n);

x = input('\nEnter window type: ','s');


rec = 'rec';
tri = 'tri';
ham = 'ham';
han = 'han';
all = 'all';

if strcmp(rec, x)
wr = ones(1, N);
figure(1);
subplot(221);
stem(n, wr, 'red');
set(gca, 'fontname', 'Times New Roman');
title('{\it Rectangular Window}', 'fontweight', 'bold', 'fontsize', 14);
xlabel('\color{darkgreen}{\it n}', 'fontweight', 'bold', 'fontsize', 12);
ylabel('\color{darkgreen}{\it Wrec(n)}', 'fontweight', 'bold', 'fontsize', 12);
elseif strcmp(tri, x)
wtri = 1 - (abs(2*n - N + 1) / (N - 1));
subplot(222);
stem(n, wtri, 'blue');
set(gca, 'fontname', 'Times New Roman');
title('{\it Triangular Window}', 'fontweight', 'bold', 'fontsize', 14);
xlabel('\color{darkgreen}{\it n}', 'fontweight', 'bold', 'fontsize', 12);
ylabel('\color{darkgreen}{\it Wtri(n)}', 'fontweight', 'bold', 'fontsize', 12);
elseif strcmp(ham, x)
wham = 0.54 - 0.46 * cos((2 * pi * n) / (N - 1));
subplot(223);
stem(n, wham, 'green');
set(gca, 'fontname', 'Times New Roman');
title('{\it Hamming Window}', 'fontweight', 'bold', 'fontsize', 14);
xlabel('\color{darkgreen}{\it n}', 'fontweight', 'bold', 'fontsize', 12);
ylabel('\color{darkgreen}{\it Wham(n)}', 'fontweight', 'bold', 'fontsize', 12);
elseif strcmp(han, x)
whan = 0.5 - 0.5 * cos((2 * pi * n) / (N - 1));
subplot(224);
stem(n, whan, 'magenta');
set(gca, 'fontname', 'Times New Roman');
title('{\it Hanning Window}', 'fontweight', 'bold', 'fontsize', 14);
xlabel('\color{darkgreen}{\it n}', 'fontweight', 'bold', 'fontsize', 12);
ylabel('\color{darkgreen}{\it Whan(n)}', 'fontweight', 'bold', 'fontsize', 12);
elseif strcmp(all, x)
wr = ones(1, N);
figure(1);
subplot(221);
stem(n, wr, 'red');
set(gca, 'FontName', 'Times New Roman');
title('Rectangle window', 'fontweight', 'bold', 'fontsize', 14);
xlabel('\color{darkgreen}n', 'fontsize', 12);
ylabel('\color{darkgreen}wr', 'fontsize', 12);
hold on;

wtri = 1 - (abs(2 * n - N * 1) / (N - 1));


subplot(222);
stem(n, wtri, 'green');
set(gca, 'fontname', 'Times New Roman');
title('Triangle window', 'fontweight', 'bold', 'fontsize', 14);
xlabel('\color{darkgreen}n', 'fontsize', 12);
ylabel('\color{darkgreen}wtri', 'FontSize', 12);
hold on;

wham = 0.54 - 0.46 * cos((2 * pi * n) / (N - 1));


subplot(223);
stem(n, wham, 'blue');
set(gca, 'fontname', 'Times New Roman');
title('Hamming window', 'fontweight', 'bold', 'fontsize', 14);
xlabel('\color{darkgreen}n', 'fontsize', 12);
ylabel('\color{darkgreen}wham', 'fontsize', 12);
hold on;

whan = 0.5 - 0.5 * cos((2 * pi * n) / (N - 1));


subplot(224);
stem(n, whan, 'cyan');
set(gca, 'FontName', 'Times New Roman');
title('Hanning window', 'fontweight', 'bold', 'fontsize', 14);
xlabel('\color{darkgreen}n', 'fontsize', 12);
ylabel('\color{darkgreen}whan', 'fontsize', 12);
hold on;
end

You might also like