From acc58d6b377d10ea25139e3767ac952c4cadc6bc Mon Sep 17 00:00:00 2001 From: Saurav-IIITU <91366385+Saurav-IIITU@users.noreply.github.com> Date: Sat, 21 Oct 2023 11:57:54 +0530 Subject: [PATCH 1/3] Add files via upload Implementation of 'fftshift' function code --- algorithms/math/fftshift1.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 algorithms/math/fftshift1.m diff --git a/algorithms/math/fftshift1.m b/algorithms/math/fftshift1.m new file mode 100644 index 0000000..0d0e161 --- /dev/null +++ b/algorithms/math/fftshift1.m @@ -0,0 +1,18 @@ +I = magic(10); % Sample input + +[rows, cols] = size(I); +mid_row = ceil(rows / 2); +mid_col = ceil(cols / 2); + +% Rearrange the image pixels to shift the center +top_left = I(mid_row+1:end, mid_col+1:end); +top_right = I(mid_row+1:end, 1:mid_col); +bottom_left = I(1:mid_row, mid_col+1:end); +bottom_right = I(1:mid_row, 1:mid_col); + +shifted_image = [top_left, top_right; bottom_left, bottom_right]; + +% Display the original and shifted images +figure("Name","FFTShift"); +subplot(1, 2, 1), imshow(I, []), title('Original Image'); +subplot(1, 2, 2), imshow(shifted_image, []), title('Shifted Image'); \ No newline at end of file From e4dc58303dda4ea89075dbf41dc2f56668058e54 Mon Sep 17 00:00:00 2001 From: Saurav-IIITU <91366385+Saurav-IIITU@users.noreply.github.com> Date: Sat, 21 Oct 2023 21:19:19 +0530 Subject: [PATCH 2/3] Create factorial_recursive.m Function to calculate factorial with recursive method --- algorithms/math/factorial_recursive.m | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 algorithms/math/factorial_recursive.m diff --git a/algorithms/math/factorial_recursive.m b/algorithms/math/factorial_recursive.m new file mode 100644 index 0000000..38d4025 --- /dev/null +++ b/algorithms/math/factorial_recursive.m @@ -0,0 +1,7 @@ +function result = factorial_recursive(n) + if n == 0 || n == 1 + result = 1; + else + result = n * factorial_recursive(n - 1); + end +end From 8e69f8dce6a831250f17cf95f9ce06efb89714ea Mon Sep 17 00:00:00 2001 From: Saurav-IIITU <91366385+Saurav-IIITU@users.noreply.github.com> Date: Sat, 21 Oct 2023 21:34:19 +0530 Subject: [PATCH 3/3] Create linearSearch.m Added linear search function --- algorithms/searching/linearSearch.m | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 algorithms/searching/linearSearch.m diff --git a/algorithms/searching/linearSearch.m b/algorithms/searching/linearSearch.m new file mode 100644 index 0000000..558986e --- /dev/null +++ b/algorithms/searching/linearSearch.m @@ -0,0 +1,11 @@ +% Linear search function +function index = linearSearch(array, target) + index = -1; % Initialize index to -1 (not found) + + for i = 1:length(array) + if array(i) == target + index = i; % Target found at index i + break; % Exit the loop + end + end +end