0% found this document useful (0 votes)
10 views3 pages

Lec 7

Uploaded by

ertc11m230269
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Lec 7

Uploaded by

ertc11m230269
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

clc,clear; % FT

Ts = 1/50;
t = 0:Ts:10-Ts;
x = (sin(2*pi*15*t) + sin(2*pi*20*t));
plot(t,x)
xlabel('Time (seconds)')
ylabel('Amplitude');
clc,clear;
Ts = 1/50;
t = 0:Ts:10-Ts;
x = (sin(2*pi*15*t) + sin(2*pi*20*t));
y = fft(x);
fs = 1/Ts;
f = (0:length(y)-1)*fs/length(y);
plot(f,abs(y));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude');
clc,clear;
Ts = 1/50;
t = 0:Ts:10-Ts;
x = (sin(2*pi*15*t) + sin(2*pi*20*t));
y = fft(x);
fs = 1/Ts;
n = length(x);
fshift = (-n/2:n/2-1)*(fs/n);
yshift = fftshift(y);
plot(fshift,abs(yshift));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
clc,clear;
Ts = 1/50;
t = 0:Ts:10-Ts;
x = (sin(2*pi*15*t) + sin(2*pi*20*t));
fs = 1/Ts;
n = length(x);
fshift = (-n/2:n/2-1)*(fs/n);
rng('default')
xnoise = x + 2.5*randn(size(t));
ynoise = fft(xnoise);
ynoiseshift = fftshift(ynoise);
power = abs(ynoiseshift).^2/n;
plot(fshift,power)
title('Power');
xlabel('Frequency (Hz)');
ylabel('Power');
clc,clear;
fs = 100;
t = 0:1/fs:1-1/fs;
x = cos(2*pi*15*t - pi/4) - sin(2*pi*40*t);
y = fft(x);
z = fftshift(y);
ly = length(y);
f = (-ly/2:ly/2-1)/ly*fs;
stem(f,abs(z));
xlabel('Frequency (Hz)');
ylabel('|y|');
grid
clc,clear;
fs = 100;
t = 0:1/fs:1-1/fs;
x = cos(2*pi*15*t - pi/4) - sin(2*pi*40*t);
y = fft(x);
z = fftshift(y);
ly = length(y);
f = (-ly/2:ly/2-1)/ly*fs;
tol = 1e-6;
z(abs(z) < tol) = 0;
theta = angle(z);
stem(f,theta/pi)
xlabel('Frequency (Hz)')
ylabel('Phase / \pi')
grid
clc,clear; % DFT
t = 0:1/100:10-1/100; % Time vector
x = sin(2*pi*15*t) + sin(2*pi*40*t); % Signal
y = fft(x); % Compute DFT of x
m = abs(y); % Magnitude
y(m<1e-6) = 0;
p = unwrap(angle(y)); % Phase
f = (0:length(y)-1)*100/length(y); % Frequency vector
subplot(2,1,1)
plot(f,m)
title('Magnitude')
ax = gca;
ax.XTick = [15 40 60 85];
subplot(2,1,2)
plot(f,p*180/pi)
title('Phase')
ax = gca;
ax.XTick = [15 40 60 85];
clc,clear;
n = 512;
y = fft(x,n);
m = abs(y);
p = unwrap(angle(y));
f = (0:length(y)-1)*100/length(y);
subplot(2,1,1)
plot(f,m)
title('Magnitude')
ax = gca;
ax.XTick = [15 40 60 85];
subplot(2,1,2)
plot(f,p*180/pi)
title('Phase')
ax = gca;
ax.XTick = [15 40 60 85];
clc,clear;
t = 0:1/255:1;
x = sin(2*pi*120*t);
y = real(ifft(fft(x)));
figure
plot(t,x-y)
clc,clear; % DCT
clc,clear,close all;
I = imread('cameraman.tif');
I = im2double(I);
T = dctmtx(8);
dct = @(block_struct) T * block_struct.data * T';
B = blockproc(I,[8 8],dct);
mask = [1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];
B2 = blockproc(B,[8 8],@(block_struct) mask .* block_struct.data);
invdct = @(block_struct) T' * block_struct.data * T;
I2 = blockproc(B2,[8 8],invdct);
imshow([I I2]);

You might also like