1. Trang chủ
  2. » Luận Văn - Báo Cáo

Báo cáo thí nghiệm thông tin số giới thiệu về matlab

52 0 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

TRƯỜNG ĐẠI HỌC BÁCH KHOA - ĐẠI HỌC ĐÀ NẴNG KHOA ĐIỆN TỬ - VIỄN THÔNG - - - - - - BÁO CÁO THÍ NGHIỆM THƠNG TIN SỐ Giáo viên hướng dẫn: Trần Văn Líc Sinh viên thực hiện: Phùng Lê Nam MSSV: 106200061 Mai Nhật Anh MSSV: 106200046 Lớp SH: 20DT2 Lớp HP: 20.38 Đà Nẵng 2023 MỞ ĐẦU: GIỚI THIỆU VỀ MATLAB Matlab sản phẩm hãng Mathwork - Cơng cụ lập trình, thuận tiện toán kỹ thuật phức tạp - Thuận tiện tính tốn ma trận, vẽ đồ thị, biểu đồ, thực thuật toán, tạo giao diện người dùng - Liên kết với chương trình máy tính khác viết ngơn ngữ lập trình khác Matlab bao gồm: - Gồm hàm xây dựng trình biên dịch có mfile - Mỗi hàm gồm dãy câu lệnh thực thuật tốn - Có thể tự viết chương trình lưu m-file - Các cửa sổ: command window, history, workspace, editor window, figure window, current director window MABLAB, viết tắt Matrix Labotary, cơng cụ phần mềm hỗ trợ tính tốn ma trận MATLAB tích hợp môi trường chung loạt khả bao gồm tính tốn, hiển thị kết lập trình nhằm giải vấn đề liên quan đến toán học Các vấn đề bao gồm: - Các phương trình toán học toán tử - Phát triển giải thuật - Thu thập liệu - Mơ hình hóa, mô tạo mẫu thiết kế - Phân tích, khảo sát thể liệu hình ảnh - Phát triển giao diện với người sử dụng Ưu điểm bật MATLAB, đề cập trên, khả tính tốn, đặc biệt toán liên quan đến ma trận vector, với thời gian nhiều lần so với cơng việc tính tốn ngơn ngữ lập trình khác C hay Fortran Khả lập trình MATLAB linh hoạt, cụ thể việc tạo câu lệnh riêng hàm riêng người sử dụng Hệ thống MATLAB gồm có phần chính:  Mơi trường phát triển: tập hợp công cụ, phần lớn chúng giao diện đồ hoạ, giúp người dùng sử dụng câu lệnh hàm MATLAB  Thư viện hàm toán học: Là tập hợp hàm toán học bao gồm từ hàm sin, cosin, phép tính đại số phức đến hàm phức tạp tìm ma trận đảo, tìm ma trận riêng, hàm Bessel biến đổi Fourier nhanh (Fast Fourier Transform – FFT)  Ngôn ngữ lập trình: ngơn ngữ bậc cao liên quan đến ma trận mảng Trong MATLAB có đầy đủ đặc trưng ngơn ngữ lập trình bao gồm lệnh rẽ nhánh, hàm, cấu trúc liệu, nhập/xuất liệu, đặc tính lien quan đến lập trình hướng đối tượng (object- oriented programming)  Đồ hoạ: tập hợp công cụ để biểu diễn ma trận vector đồ hoạ Bên cạnh công cụ mức thấp để thể liệu dạng chiều chiều, xử lý hình ảnh tĩnh, ảnh động cịn có cơng cụ mức cao dùng để tạo biểu diễn đồ hoạ theo ý đồ người sử dụng tạo giao diện đồ hoạ users  Các API: Là thư viện cho phép người sử dụng gọi hàm viết ngôn ngữ C Fortran Chúng bao gồm công cụ cho phép gọi hàm từ MATLAB dạng liên kết động, để đọc ghi tệp MAT Để khởi động MATLAB, người sử dụng nháy đúp chuột vào biểu tượng MATLAB hình desktop vào menu Start -> All Programs -> MATLAB ->R2009b -> MATLAB R2009b từ giao diện Windows Sau MATLAB khởi động, hình người sử dụng hiển thị lên mơi trường phát triển tích hợp MATLAB bao gồm số cửa sổ Hình 1.1 Hình 1.1 Giao diện MATLAB Trong có c a sốố quan trọng sau:  Cửa sổ lệnh (Command Window): có chức thể dấu nhắc để nhập vào lệnh từ bàn phím, hiển thị kết tính tốn sau gõ lệnh gọi hàm  Cửa sổ lệnh dùng (Command History): thể danh mục lệnh gõ hàm gọi theo phiên làm việc  Cửa sổ thư mục thời (Current Directory): thể danh sách tệp dạng đuôi m tồn thư mục thời Để thay đổi thư mục thời cửa sổ nhỏ nằm bên cửa số lệnh  Vùng làm việc (Workspace): thể danh mục tất biến bao gồm: tên biến, giá trị thời biến, kiểu biến tồn phiên làm việc Ngồi cịn loạt cửa sổ khác kích hoạt hiển thị gọi lệnh chọn mục phần Menu MATLAB Để biết thêm cửa số tham khảo t hêm phần trợ giúp (Help) MATLAB cách nhấn phím F1 Để soạn thảo kịch hàm, thực chọn menu File -> New -> M-File nhắp chuột vào biểu tượng New M-File cơng cụ (Toolbar) Trên hình hiển thị lên cửa sổ soạn thảo (Editor) có đầy đủ chức soạn thảo giống mơi trường soạn thảo ngơn ngữ lập trình khác Để xem trợ giúp lệnh hay hàm có sẵn MATLAB, gõ lệnh help kèm theo tên lệnh hàm từ cửa sổ lệnh MATLAB, ví dụ: >> help fft cửa số lệnh đưa nội dung chức năng, cú pháp cho tham số vào/ra cho hàm thực phép biến đổi Fourier nhanh MATLAB đặt tên FFT 1.1 Operators There are in general two kinds of operators: unary operators, which operate on a single value or operand; and binary operators, which operate on two values or operands The symbol “–”, for example, is both the unary operator for negation and the binary operator for subtraction Here are some of the common operators that can be used with numeric expressions: + addition – negation, subtraction * multiplication / division (divided by e.g 10/5 is 2) \ division (divided into e.g 5\10 is 2) ^ exponentiation (e.g., 5^2 is 25) 1.2 Vectors and matrices Vectors and matrices are used to store sets of values, all of which are the same type A vector can be either a row vector or a column vector A matrix can be visualized as a table of values The dimensions of a matrix are r × c, where r is the number of rows and c is the number of columns This is pronounced “r by c.” If a vector has n elements, a row vector would have the dimensions × n, and a column vector would have the dimensions n × A scalar (one value) has the dimensions × Therefore, vectors and scalars are actually just subsets of matrices Here are some diagrams showing, from lef to right, a scalar, a column vector, a row vector, and a matrix: The scalar is × 1, the column vector is × (3 rows by column), the row vector is × (1 row by columns), and the matrix is × All the values stored in these matrices are stored in what are called elements MATLAB is written to work with matrices; the name MATLAB is short for “matrix laboratory.” For this reason, it is very easy to create vector and matrix variables, and there are many operations and functions that can be used on vectors and matrices A vector in MATLAB is equivalent to what is called a one-dimensional array in other languages A matrix is equivalent to a two-dimensional array Usually, even in MATLAB, some operations that can be performed on either vectors or matrices are referred to as array operations The term array also frequently is used to mean generically either a vector or a matrix 1.2.1 Creating row Vectors There are several ways to create row vector variables The most direct way is to put the values that you want in the vector in square brackets, separated by either spaces or commas For example, both of these assignment statements create the same vector v: >> v = [1 4] v= 1234 >> v = [1,2,3,4] v= 1234 Both of these create a row vector variable that has four elements; each value is stored in a separate element in the vector If, as in the earlier examples, the values in the vector are regularly spaced, the colon operator can be used to iterate through these values For example, 1:5 results in all the integers from to 5: >> vec = 1:5 vec = 12345 Note that in this case, the brackets [ ] are not necessary to define the vector With the colon operator, a step value can also be specified with another colon, in the form (first:step:last) For example, to create a vector with all integers from to in steps of 2: >> nv = 1:2:9 nv = 13579 Similarly, the linspace function creates a linearly spaced vector; linspace(x,y,n) creates a vector with n values in the inclusive range from x to y For example, the following creates a vector with five values linearly spaced between and 15, including the and 15: >> ls = linspace(3,15,5) ls = 12 15 Vector variables can also be created using existing variables For example, a new vector is created here consisting first of all the values from nv followed by all values from ls: >> newvec = [nv ls] newvec = 9 12 15 Putting two vectors together like this to create a new one is called concatenating the vectors 1.2.2 Creating Column Vectors One way to create a column vector is by explicitly putting the values in square brackets, separated by semicolons: >> c = [1; 2; 3; 4] c= There is no direct way to use the colon operator described earlier to get a column vector However, any row vector created using any of these methods can be transposed to get a column vector In general, the transpose of a matrix is a new matrix in which the rows and columns are interchanged For vectors, transposing a row vector results in a column vector, and transposing a column vector results in a row vector MATLAB has a built- in operator, the apostrophe, to get a transpose >> r = 1:3; >> c = r’ c = 1.2.3 Creating Matrix Variables Creating a matrix variable is really just a generalization of creating row and column vector variables That is, the values within a row are separated by either spaces or commas, and the different rows are separated by semicolons For example, the matrix variable mat is created by explicitly typing values: >> mat = [4 1; 6] mat = There must always be the same number of values in each row If you attempt to create a matrix in which there are different numbers of values in the rows, the result will be an error message; for example: >> mat = [3 7; 2] ??? Error using ==> vertcat CAT arguments dimensions are not consistent Iterators can also be used for the values on the rows using the colon operator; for example: >> mat = [2:4; 3:5] mat = BÀI 3: KỸ THUẬT SỐ HĨA TÍN HIỆU I LÝ THUYẾT: Bộ biến đổi tương tự - số bản: Kỹ thuật lấy mẫu: a Khái niệm:  Lẫy mẫu trình chuyển đổi tín hiệu liên tục thành tín hiệu rời rạc cách lấy mẫu (Sample) tín hiệu liên tục thời điểm rời rạc cách  Tín hiệu sau lấy mẫu dãy xung PAM rời rạc (Pulse Amplitude Modulation) b Vai trò: Đảm bảo tín hiệu có tần số giới hạn tái tạo hồn tồn từ phiên mẫu c Chu kỳ lấy mẫu: Trong đó: chu kỳ lấy mẫu tần số lấy mẫu d Định lý lấy mẫu:  Xếp chồng tuần hồn phổ tín hiệu liên tục:  Trường hợp lấy mẫu với tần số lấy mẫu không đủ lớn xảy tượng chồng phổ  Chồng phổ (Aliasing) tránh tần số Nyquist lớn tần số lớn tín hiệu lấy mẫu Để chống chồng phổ ta sử dụng lọc  Chọn tần số lấy mẫu:  Trường hợp phổ tín hiệu tương tự từ đến Trường hợp phổ v tín hiệu tương tự từ đến: e Lấy mẫu ảnh:  Lấy mẫu: Phân chia không gian ảnh thành lưới ô vuông  Độ phân giải: Là số lượng điểm ảnh ảnh Độ phân giải thấp → Khơng xác; Độ phân giải cao → Chậm thuật tốn lãng phí nhớ  Ví dụ: Kỹ thuật lượng tử hố: a Khái niệm:  Lượng tử hố q trình xấp xỉ hoá giá trị mẫu  Mục đích q trình nhằm biểu diễn lại cách xác tín hiệu tương tự tín hiệu số  Q trình thực hàm bậc thang mơ tả hình sau: b Nhiễu lượng tử hố:  Sai số lượng tử hóa (nhiễu/ lỗi/ méo lượng tử hóa): Sai khác với giá trị thực giá trị lượng tử hóa  Kích thước bước lượng tử hóa ảnh hưởng đến méo lượng tử hóa  Muốn giảm méo lượng tử hóa, phải giảm kích thước bước lượng tử hóa, dẫn đến tăng số mức lượng tử hóa, tăng số bit mã hóa II BÀI TẬP Bài 1: Cho ảnh xám Test.bmp Thay đổi tần số lấy mẫu ảnh Quan sát ảnh, so sánh, đánh giá chất lượng dung lượng ảnh, rút nhận xét Từ chọn tần số lấy mẫu tối ưu Code Matlab: img = imread('C:\Users\ASUS\Desktop\HK VI\1.bmp'); figure img1=imresize(img,1/2); %Tan so lay mau 1/(2^i) img2=imresize(img,1/4); img3=imresize(img,1/8); img4=imresize(img,1/16); img5=imresize(img,1/32); img6=imresize(img,1/64); img7=imresize(img,1/128); %NOTE: tan so lay mau cang thap thi chat luong cang kem subplot(2,4,1) imshow(img) title('2048x2048') subplot(2,4,2) imshow(img1) title('1024x1024') subplot(2,4,3) imshow(img2) title('512x512') subplot(2,4,4) imshow(img3) title('256x256') subplot(2,4,5) imshow(img4) title('128x128') subplot(2,4,6) imshow(img5) title('64x64') subplot(2,4,7) imshow(img6) title('32x32') subplot(2,4,8) imshow(img7) title('16x16') Result: Chụp ảnh nhóm, chuyển ảnh xám thực lại yêu cầu Code Matlab: img = imread('C:\Users\ASUS\Desktop\HK VI\3.jpg'); img = rgb2gray(img); figure img1=imresize(img,1/2); %Tan so lay mau 1/(2^i) img2=imresize(img,1/4); img3=imresize(img,1/8); img4=imresize(img,1/16); img5=imresize(img,1/32); img6=imresize(img,1/64); img7=imresize(img,1/128); %NOTE: tan so lay mau cang thap thi chat luong cang kem subplot(2,4,1) imshow(img) title('2048x2048') subplot(2,4,2) imshow(img1) title('1024x1024') subplot(2,4,3) imshow(img2) title('512x512') subplot(2,4,4) imshow(img3) title('256x256') subplot(2,4,5) imshow(img4) title('128x128') subplot(2,4,6) imshow(img5) title('64x64') subplot(2,4,7) imshow(img6) title('32x32') subplot(2,4,8) imshow(img7) title('16x16') Result: Bài 2: Cho ảnh xám Test.bmp Thay đổi số mức lượng tử hoá ảnh Quan sát ảnh, so sánh, đánh giá chất lượng ảnh dung lượng ảnh, rút nhận xét Từ chọn số mức lượng tử hoá tối ưu Code Matlab: IMG = imread('C:\Users\ASUS\Desktop\HK VI\1.bmp'); img = rgb2gray(IMG); figure subplot(2,4,1) b=8; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh goc bit') subplot(2,4,2) b=7; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,3) b=6; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,4) b=5; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,5) b=4; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,6) b=3; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit' subplot(2,4,7) b=2; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,8) b=1; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh nhi phan') Result: Chụp ảnh nhóm, chuyển ảnh xám thực lại yêu cầu Code Matlab: IMG = imread('C:\Users\ASUS\Desktop\HK VI\3.jpg'); img = rgb2gray(IMG); figure subplot(2,4,1) b=8; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh goc bit') subplot(2,4,2) b=7; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,3) b=6; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,4) b=5; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,5) b=4; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,6) b=3; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,7) b=2; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,8) b=1; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh nhi phan') Result: Bài 3: Chọn ảnh màu chụp nhóm Thay đổi tần số lấy mẫu ảnh Quan sát ảnh, so sánh, đánh giá chất lượng ảnh dung lượng ảnh, rút nhận xét Code Matlab: img = imread('C:\Users\ASUS\Desktop\HK VI\1.bmp'); figure img1=imresize(img,1/2); %Tan so lay mau 1/(2^i) img2=imresize(img,1/4); img3=imresize(img,1/8); img4=imresize(img,1/16); img5=imresize(img,1/32); img6=imresize(img,1/64); img7=imresize(img,1/128); %NOTE: tan so lay mau cang thap thi chat luong cang kem subplot(2,4,1) imshow(img) title('2048x2048') subplot(2,4,2) imshow(img1) title('1024x1024') subplot(2,4,3) imshow(img2) title('512x512') subplot(2,4,4) imshow(img3) title('256x256') subplot(2,4,5) imshow(img4) title('128x128') subplot(2,4,6) imshow(img5) title('64x64') subplot(2,4,7) imshow(img6) title('32x32') subplot(2,4,8) imshow(img7) title('16x16') Result: Thay đổi số mức lượng tử hoá ảnh Quan sát ảnh, so sánh, đánh giá chất lượng ảnh dung lượng ảnh, rút nhận xét Code Matlab: IMG = imread('C:\Users\ASUS\Desktop\HK VI\3.jpg'); figure subplot(2,4,1) b=8; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh goc bit') subplot(2,4,2) b=7; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,3) b=6; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,4) b=5; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,5) b=4; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,6) b=3; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,7) b=2; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh bit') subplot(2,4,8) b=1; d=2^(8-b); z=round(img/d); changeBit=z*d; imshow(changeBit) title('Anh nhi phan') Result: Lưu ý: Cần quan sát thay đổi màu sắc Tần số lấy mẫu số mức lượng tử hố có ảnh hưởng đến màu sắc?

Ngày đăng: 03/07/2023, 15:28

Xem thêm:

w