Dsp Reviwer
Dsp Reviwer
Plotting
- Open New live script
- Select Text , then type “USING LIVESCRIPT IN MATLAB”.
Change the text format from “Normal” to “Title”.
CODE:
x = [0:0.2:2*pi] - if you see (where 0 < x < 2pi)
y = sin (x)
plot (x,y) - Plotting in Live script
CODE:
x = [0:0.2:2*pi] - if you see (where 0 < x < 2pi)
z = cos (x)
plot (z,y) - Plotting in Live script
In MATLAB, we can represent a finite-duration sequence by a row vector
of appropriate values. However, such a vector does not have any
information about sample position n. Therefore, a correct
representation of x(n) would require two vectors, one each for x and n.
For example, a sequence:
x(n) = {2,1,-1,0,1,4,3,7}
In precise terms:
Purpose: It represents discrete data points clearly, showing their values on the y-axis
at specific x-axis positions.
Vertical lines (stems) connecting the data points to a baseline (usually y=0)
xlim Function - The xlim function in MATLAB is used to set or query the limits of
the x-axis for a plot.
ylim Function - The ylim function in MATLAB is used to set or query the limits of
the y-axis for a plot.
The specific export options available under File > Export depend on the software
being used. Here are five common ways files can typically be exported across most
applications (e.g., Excel, Word, Photoshop, etc.):
Export as PDF
Converts the file to a Portable Document Format (PDF), which is widely used
for sharing documents with consistent formatting.
Clc - When you use the clc command in MATLAB, it clears the command
window.
a = 10,
b = 20
>> sqrt(a+b)
ans = 5.4772
Description: The grid lines make it easier to read the values of the plot
by displaying horizontal and vertical grid lines across the axes.
Description: The x-axis will range from -10 to 10, and the y-axis will
range from -35 to 35. This command allows you to focus on a specific
portion of the plot.
c) xlabel("x")
Description: The label "x" will be displayed along the x-axis, which
helps identify what the x-axis represents.
d) ylabel("y")
Description: The label "y" will be displayed along the y-axis, which
helps identify what the y-axis represents.
e) title("Sample Plot")
Description: The title "Sample Plot" will be displayed at the top of the
plot, providing a descriptive heading for the plot.
f) clf
b) plot(x, y, '--')
c) plot(x, y, '-o')
Feature Added: Plots the data with a solid line and circle
markers at each data point.
Description: The '-' specifies a solid line, and the 'o' adds circular
markers at each data point. This makes it easier to see the
individual data points on the plot.
d) plot(x, y, '-.xg')
Feature Added: Plots the data with a dash-dot line, 'x' markers,
and green color.
Description:
Colors:
o 'b': Blue
o 'g': Green
o 'r': Red
o 'k': Black
o 'm': Magenta
o 'c': Cyan
o 'y': Yellow
1. recObj = audiorecorder
2. recObj = audiorecorder(44100,16,2);
3. recDuration = 5;
5. recordblocking(recObj,recDuration);
6. disp("End of Recording");
7. play(recObj);
8. y = getaudiodata(recObj);
Extracts the recorded audio data from the recObj object and stores it in the
variable y.
y is a numeric array containing the amplitude values of the recorded audio.
9. plot(y);
What happens when you change the value of the sample rate?
The sample rate determines how many audio samples are captured per second.
Changing it affects:
Better Quality: Captures more details and higher frequencies (up to half
the sample rate, per Nyquist theorem).
Larger File Size: More data points are stored.Used for music, high-
fidelity audio
Impact on Plots: Higher sample rates produce smoother waveforms, while lower
ones appear jagged due to fewer data points.
TASK 1:
1. Record two 10-seconds voice signal. (Use a sample rate of 44,100 Hz, 8-bit depth,
and one audio
channel).
2. Play the recorded audio simultaneously.
CODE:
USING SUBPLOT
>> subplot (2,1,1);
>> plot (audio1);
>> title ('First Signal');
>> xlabel('Sample Number');
>> ylabel('Amplitude');
ADDITION
>> subplot (2,2,1);
>> plot (audio1);
>> title ('First Signal');
>> xlabel('Sample Number');
>> ylabel('Amplitude');
>> subplot(2,2,2);
>> plot(audio2);
>> title ('Second Signal');
>> xlabel('Sample Number');
>> ylabel ('Amplitude')
SUBTRACTION
>> signal_sub = audio1 - audio2;
>> subplot(2, 3, 4);
>> plot(signal_sub);
>> title('Subtraction of Two Signals');
>> xlabel('Sample Number');
>> ylabel('Amplitude');
FLIPPING
>> flipped_audio2 = flip(audio2);
>> subplot(2, 3, 5);
>> plot(flipped_audio2);
>> title('Flipped Second Signal');
>> xlabel('Sample Number');
>> ylabel('Amplitude');
CONVOLUTION
>> signal_conv = conv(audio1, audio2);
>> subplot(2, 3, 6);
>> plot(signal_conv);
>> title('Convolution of Two Signals');
>> xlabel('Sample Number');
>> ylabel('Amplitude');
IMAGE RESAMPLING
- is the process of changing the spatial resolution of an image
by interpolating or down-sampling pixel values.
- It’s commonly used for resizing images, such as scaling them
up or down, rotating them, or correcting geometric
distortions. Resampling allows us to adjust the number of
pixels in an image while preserving as much detail as possible.
Imresize - IS USED FOR IMAGE RESAMPLING
>> img = imread('moon.tif');
>> subplot(1,3,1);
>> imagesc(img);
>> title('moon.tif');
>> axis tight equal
>> subplot(3,3,2);
>> filt = fspecial("gaussian",[90,90], 3);
>> surf(filt);
>> title('Sigma \sigma = 3');
>> subplot(3,3,3);
>> filt_img = conv2(img, filt, "same");
>> imagesc(filt_img);
>> axis tight equal
>> title('Filtered Image');
>> subplot(3,3,5);
>> filt = fspecial("gaussian",[90,90], 9);
>> surf(filt);
>> title('Sigma \sigma = 9');
>> subplot(3,3,6);
>> filt_img = conv2(img, filt, "same");
>> imagesc(filt_img);
>> axis tight equal
>> subplot(3,3,8);
>> filt = fspecial("gaussian",[90,90], 15);
>> surf(filt);
>> title('Sigma \sigma = 15');
>> subplot(3,3,9);
>> filt_img = conv2(img,filt,"same");
>> imagesc(filt_img);
>> axis tight equal
COLOR IMAGE IN MATLAB
>> subplot(3,3,2);
>> img = imread('peppers.png');
>> imagesc(img);
>> title ('pepper.png');
>> axis tight equal
>> red = img(:,:,1);
>> green = img(:,:,2);
>> blue = img(:, :, 3);
>> subplot(3,3,4);
>> imagesc(red);
>> colormap("gray");
>> axis equal tight
>> title ('red channel');
>> subplot (3,3,7);
>> imhist(red);
>> subplot(3,3,5);
>> imagesc(green);
>> colormap("gray");
>> axis tight equal
>> title ('green channel');
>> subplot(3,3,8);
>> imhist(green);
>> subplot(3,3,6);
>> imagesc(blue);
>> colormap("gray");
>> axis tight equal
>> title ('blue channel');
>> subplot(3,3,9);
>> imhist(blue);
HSV COLOR SPACE
% Sobel filters
>>sobelh = fspecial("sobel");
>>sobelv = sobelh';
% Horizontal Sobel
>>subplot(2, 4, 2);
>>img_sobelh = conv2(double(img), sobelh, "same");
>>image(abs(img_sobelh), 'CDataMapping', 'scaled');
>>axis equal tight;
>>title("Horizontal Sobel");
% Vertical Sobel
>>subplot(2, 4, 3);
>>img_sobelv = conv2(double(img), sobelv, "same");
>>image(abs(img_sobelv), 'CDataMapping', 'scaled');
>>axis equal tight;
>>title("Vertical Sobel");
% Cropped Original
>>subplot(2, 4, 5);
>>image(img);
>>axis equal tight;
>>axis([130, 250, 360, 480]);
Edge Detection