clear all
fo = 4; %frequency of the sine wave 
Fs = 100; %sampling rate 
Ts = 1/Fs; %sampling time interval 
t = 0:Ts:1-Ts; 
n = length(t); %number of samples 
y = 2*sin(2*pi*fo*t); 
plot(t,y)
xlabel('time (seconds)')
ylabel('y(t)')
title('Sample Sine Wave')
grid
figure
[YfreqDomain,frequencyRange] = positiveFFT(y,Fs);
stem(frequencyRange,abs(YfreqDomain),'LineWidth',2);
xlabel('Freq (Hz)')
ylabel('Amplitude')
title('Using the positiveFFT function')
grid
axis([0,20,0,1.5])
disp('Press any key to continue')
pause
load touchtone
Fs=y.fs
n = length(y.sig);     % Total number of samples
t = (0:n-1)/y.fs;      % Time for entire signal
y = double(y.sig)/128;
%sound(y) % This command will play tones through sound card
plot(t,y)
figure
t=t(1:8000)
y=y(1:8000)
plot(t,y)
[YfreqDomain,frequencyRange] = positiveFFT(y,Fs);
figure
stem(frequencyRange,abs(YfreqDomain),'LineWidth',2);
xlabel('Freq (Hz)')
ylabel('Amplitude')
title('Using the positiveFFT function')
disp('Press any key to continue')
pause
f1 = 4;   %frequency of the first sine wave
f2 = 4.5; %frequency of the second sine wave
Fs = 100; %sampling rate
Ts = 1/Fs; %sampling time interval
t = 0:Ts:2-Ts; %sampling period
y = 100*sin(2*pi*f1*t) + 100*sin(2*pi*f2*t); %sum of sine waves
plot(t,y)
title('Sample Signal', 'FontWeight','Bold')
xlabel('Time (seconds)')
ylabel('Amplitude')
grid
figure
[YfreqDomain,frequencyRange] = positiveFFT(y,Fs);
plot(frequencyRange,abs(YfreqDomain),'LineWidth',2);
xlabel('Freq (Hz)')
ylabel('Amplitude')
figure
zeroPadFactor = nextpow2(length(y)) + 3;
[a,b] = positiveFFT_zero_padding(y,Fs,2^zeroPadFactor);
plot(b,abs(a))
title('FFT of Sample Signal: Zero Padding up to N = 1024', 'FontWeight','Bold')
xlabel('Freq (Hz)')
ylabel('Magnitude')
disp('Press any key to continue')
pause
s = [1 2 1; 0 0 0; -1 -2 -1];
A = zeros(30);
A(10:20,10:20) = ones(11);
mesh(A)
H = conv2(A,s);
figure
mesh(H)
V = conv2(A,s');
figure
mesh(V)
disp('Press any key to continue')
pause
Fs=1000;
t=0:1/Fs:2
y=chirp(t,0,1,150)
%sound(y)
spectrogram(y,256,250,256,1E3,'yaxis')
[YfreqD,freqRng] = positiveFFT(y,Fs);
figure
stem(freqRng,abs(YfreqD));
[b,a]=butter(10,0.3,'low');
yfilt=filtfilt(b,a,y);
%sound(yfilt)
[YfreqD,freqRng] = positiveFFT(yfilt,1000);
figure
stem(freqRng,abs(YfreqD));
disp('Press any key to continue')
pause
h=spectrum.welch
mypower=msspectrum(h,y,'Fs',Fs)
plot(mypower)
mypowerfilt=msspectrum(h,yfilt,'Fs',Fs)
hold on
plot(mypowerfilt)
disp('Press any key to continue')
pause
RGB = imread('shuttle.jpg');
I = rgb2gray(RGB);
figure, imshow(I)
J = dct2(I);
n=numel(J);
fprintf('Original matrix has %i elements \n', n)
lows=find(abs(J)<10);
n=numel(lows);
fprintf('Original matrix has %i elements with abs < 10 \n', n)
J(abs(J) < 10) = 1e-8;
K = idct2(J);
figure, imshow(K,[0 255])
J = dct2(I);
lows=find(abs(J)<40);
n=numel(lows);
fprintf('Original matrix has %i elements with abs < 40 \n', n)
J(abs(J) < 40) = 1e-8;
K = idct2(J);
figure, imshow(K,[0 255])
