Online · Live + on demand
February 9-11, 2027
Price goes up Jan 1: register now to lock in today's rate
Register Now →
RGB (JPEG) Image Separator
clf;
x = imread('input.jpg');
red = x(:,:,1);
green = x(:,:,2);
blue = x(:,:,3);
subplot(2,2,1);
imshow(x);
title('Original');
subplot(2,2,2);
imshow(red);
title('Red');
subplot(2,2,3);
imshow(green);
title('Green');
subplot(2,2,4);
imshow(blue);
title('Blue');Image denoising: Threshold calculation for vishushrink method
%function to calculate the threshold using Visushrink denoising method
function T = Visu_threshold(X)
[m,n] = size(X);
M = m*n;
T = sqrt(2*log(M));Exponential Audio Mute
function [y] = signal_mute(x, index, duration, Fs)
% Return the input vector with a mute that occurs at a specific
% index and with an exponential ramp-down to reduce "pop" sounds.
% The output will start off at 0dB gain and end at -100dB gain.
%
% Usage: y = SIGNAL_MUTE(x, index, duration, Fs);
%
% X is your one-dimensional input array
% INDEX is where in the input signal you want the mute to begin
% DURATION is how long (in seconds) to exponentially ramp down the
% input signal. 100ms is recommended.
% FS is the sample rate
%
% Example:
% You want to mute your signal at 0.5sec with a duration of 100ms
% and with a 48k Fs. (mute complete at 0.6sec)
% y = signal_mute(x, 24000, 0.1, 48000);
%
% Author: sparafucile17 7/29/2003
% Input must have some length
if(length(x) == 1)
error('ERROR: input signal must have more than one element');
end
% This function only supports one-dimensional arrays
if((size(x, 2) ~= 1) && (size(x, 1) ~= 1))
error('ERROR: Input must be one-dimensional');
end
% Make sure there are enough samples to complete the mute
if(length(x) < (index + duration*Fs))
error(['There are not enough samples in X to complete the mute. ' ...
'Either change the mute duration or move the index back.' ]);
end
% Flip vector (temporarily)
if((size(x, 2) ~= 1))
x = x';
flip_back = true;
else
flip_back = false;
end
% Calculate exponential coefficient
dB_atten = -100; %How much attenuation will be at time: index + duration
decayrate = -dB_atten / duration;
coeff = 1.0 - 10^(-decayrate/(20.0*Fs));
% Build the Gain array
gain = [ones(index, 1); zeros((length(x)-index), 1);];
b = [ coeff 0];
a = [ 1 (-1*(1-coeff))];
gain = filter(b,a,gain, [1]);
% Remove minor overshoot at the beginning of gain vector
gain(find(gain > 1)) = 1;
% Apply Mute (gain) to the input signal
y = gain .* x;
% Flip the vector (if required)
if(flip_back == true);
y = y';
endPassive direction finding
clc
clear all
close all
fs=20e7;
T=1/fs;
t=0:T:0.0000002;
f=10e6;
scanagle_deg=60;
step_deg=6;
theta=-deg2rad(scanagle_deg):deg2rad(step_deg):deg2rad(scanagle_deg);
for i=1:length(theta);
ant1=2*sin(2*pi*f*t);
ant2=2*sin(2*pi*f*t+theta(i));
[my,mx]=max(ant1);
sum_ant(i)=ant1(mx)+ant2(mx);
diff_ant(i)=ant1(mx)-ant2(mx);
ratio_ant(i)=diff_ant(i)/sum_ant(i);
% if diff_ant(i)==0
% diff_ant(i)=0.1;
% end
% ratio1_ant(i)=sum_ant(i)/diff_ant(i);
end
% subplot(311)
% plot(t,ant1,t,ant2)
subplot(211)
plot(rad2deg(theta),sum_ant,rad2deg(theta),diff_ant)
subplot(212)
plot(rad2deg(theta),ratio_ant)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sim_ant1=2*sin(2*pi*f*t);
sim_ant2=2*sin(2*pi*f*t+deg2rad(30));
[smy,smx]=max(sim_ant1);
%%%%also take for same sample value of data
sim_sum_ant=sim_ant1(mx)+sim_ant2(mx);
sim_diff_ant=sim_ant1(mx)-sim_ant2(mx);
sim_ratio_ant=sim_diff_ant/sim_sum_antImage denoising - Threshold calculation for Bishrink method
function T = bishrink2(CD,CY)
sigman = (median(median(abs(CD))))/0.6745;
[m,n] = size(CY);
sigmay = 0;
for i =1:m
for j = 1:n
sigmay = sigmay+((CY(i,j))^2);
end
end
sigmay = sqrt(2)*sigmay/(m*n);
sigma = sqrt(max((((sigmay))-((sigman)^2)),0)); % Variance calculation
if sigma~=0
T = sqrt(3)*(sigman^2)/sigma; %Threshold
else
T = max(max(abs(CY)));
endDWT filter generator - formfilter.m
% ------------------------------------------------------
% Title: formfilter.m
%
% Author: David Valencia
%
% Institution: UPIITA-IPN 2010
%
% for DSPrelated.com
%
% Published in: http://www.dsprelated.com/showcode/12.php
%
% Description: This program receives 2 basic ortogonal
% filters (one is high-pass and one is low-pass)
% the filtering level and the branch number.
% As a result it returns the equivalent filter
% of the specified branch.
%
% Dependencies: upsample2.m
% http://www.dsprelated.com/showcode/10.php
%
% Revision: v1.0a
% - Commented and translated in English
%
% For more details on this code and its implementation
% see the following blog posts:
%
% http://www.dsprelated.com/showarticle/115.php
% http://www.dsprelated.com/showarticle/116.php
%
% ------------------------------------------------------
function [hx] = formfilter(n_stages,branch,h0,h1)
p = branch;
% Seed vector
hx = 0;
hx(1) = 1;
switch n_stages
case 1
% If it is a single stage filter
% the branches are just the base filters
if mod(branch,2) ~= 0
hx = h0;
else
hx = h1;
end
case 2
% For a 2 stage filter bank, the
% equivalent filters are simply
% the convolution between the corresponding
% base filters, and one of them is upsampled
% The use of upsample2 is needed to avoid having
% a large quantitiy of zeros at the end of the vector
% which certainly difficults its usage to build a
% convolution matrix.
switch branch
case 1
hx = conv(h0,upsample2(h0,2));
case 2
hx = conv(h0,upsample2(h1,2));
case 3
hx = conv(h1,upsample2(h0,2));
case 4
hx = conv(h1,upsample2(h1,2));
otherwise
beep;
fprintf('\nFor a 2 stage filter bank there can not be a fifth branch');
end
otherwise
% For a n>2 stages filter bank, a more ellaborated
% process must be made. A series of upsamplings and convolutions
% are needed to get an equivalent vector.
for i=0:n_stages-2
q = floor(p /(2^(n_stages-1-i)));
if (q == 1)
hx = conv(hx,upsample2(h1,2^i));
else
hx = conv(hx,upsample2(h0,2^i));
end
p = mod(p,2^(n_stages-1-i));
end
% Depending on the parity of the branch number, the filter
% goes through a last convolution
t = mod(branch,2);
if(t == 1)
hx = conv(hx,upsample2(h0,2^(n_stages-1)));
else
hx = conv(hx,upsample2(h1,2^(n_stages-1)));
end
endgetsinc.m - TMX Transmultiplexer (MATLAB version)
function [sf] = getsinc(n_etapas, L)
% Experimentally obtained synchronization factors
if(n_etapas == 1)
sf = 2;
elseif (n_etapas == 2)
sf = L;
elseif L == 4
if(n_etapas == 3) % 8 branches
sf = 22;
elseif(n_etapas == 4) % 16 branches
sf = 36;
elseif(n_etapas == 5) % 32 branches
sf = 82;
end
elseif L == 6
if n_etapas == 3 % 8 branches
sf = 20;
elseif n_etapas == 4 % 16 branches
sf = 30;
elseif n_etapas == 5 % 32 branches
sf = 80;
end
elseif L == 8
if(n_etapas == 3) % 8 branches
sf = 26;
elseif(n_etapas == 4) % 16 branches
sf = 32;
end
elseif L == 10
if(n_etapas == 1)
sf = 2;
elseif(n_etapas == 2)
sf = 10;
end
end2D Image FIR Subsample
A = imread('in.jpg');
M = [ 1 4 6 4 1;
4 16 24 16 4;
6 24 36 24 6;
4 16 24 16 4;
1 4 6 4 1 ] / 256;
Y = filter2(M,A);
B = uint8(conv2(double(Y),M));
imwrite(B,'out.jpg','JPG');Power Computation of a Digital Stream
clear all;
%example vector having ac & dc power
x = complex(randn(1,2048)+.2,randn(1,2048)-.1);
%total power, three equivalent methods
pwr1_total = mean(abs(x).^2); %mean of squared values
pwr2_total = mean(real(x).^2 + imag(x).^2);
pwr3_total = mean(x .* conj(x));
%total expressed as rms
rms_total = sqrt(pwr1_total);
%dc power
pwr1_dc = mean(real(x))^2 + mean(imag(x))^2; %square of mean of values
%ac power
pwr1_ac = pwr1_total - pwr1_dc; %mean of squares - square of mean
%relation of ac power to statistical variance
pwr2_ac = var(x); %approximately
%ac expressed as rms
rms1_ac = sqrt(pwr1_ac);
%ac relation to standard of deviation, std = sqrt(var)
rms2_ac = std(x); %approximately
%dc relation to variance
pwr2_dc = pwr1_total - var(x); %approximately
fprintf('----------------------------------------------------\r');
fprintf('power(total), : %1.5f, %1.5f, %1.5f\r',pwr1_total,pwr2_total,pwr3_total);
fprintf('rms(total) : %1.5f\r',rms_total);
fprintf('power(ac), variance : %1.5f, %1.5f\r',pwr1_ac,pwr2_ac);
fprintf('rms(ac), std : %1.5f, %1.5f\r',rms1_ac,rms2_ac);
fprintf('power(dc), (total-var) : %1.5f, %1.5f\r',pwr1_dc,pwr2_dc);Least Squares fit to a linear equation
function [m, b] = ls_linear(x_observed, y_observed)
%
% Perform Least Squares curve-fitting techniques to solve the coefficients
% of the linear equation: y = m*x + b. Input and Output equation
% observations must be fed into the algorithm and a best fit equation will
% be calculated.
%
% Usage: [M,B] = ls_linear(observed_input, observed_output);
%
% observed_input is the x-vector observed data
% observed_output is the y-vector observed data
%
% Author: sparafucile17 06/04/03
%
if(length(x_observed) ~= length(y_observed))
error('ERROR: Both X and Y vectors must be the same size!');
end
%Calculate vector length once
vector_length = length(x_observed);
%
% Theta = [ x1 1 ]
% [ x2 1 ]
% [ x3 1 ]
% [ x4 1 ]
% [ ... ... ]
%
Theta = ones(vector_length, 2);
Theta(1:end, 1) = x_observed;
%
% Theta_0 = [ y1 ]
% [ y2 ]
% [ y3 ]
% [ y4 ]
% [ ... ]
%
Theta_0 = y_observed;
%
% Theta_LS = [ M ]
% [ B ]
%
Theta_LS = ((Theta' * Theta)^-1 ) * Theta' * Theta_0;
%Return the answer
m = Theta_LS(1);
b = Theta_LS(2);Image denoising: Threshold calculation for oraclesoft
function thr = oracleshrink1(CD,T)
%function used to calculate threshold for oracleshrink method
CD = CD(:)';
n = length(CD);
sx2 = (T-CD).^2;
b = cumsum(sx2);
[risk,best] = min(b);
hr = sqrt(sx2(best));Image denoising - Oracleshrink method
%Using oracle threshold alone
%subband dependent threshold
%Soft and Hard threshold
function [soft_X1,SOFT_PSNR] = Oracle_soft(X,Y)
%One -level decomposition
[CA,CH,CV,CD] = dwt2(Y,'haar');
[ca,ch,cv,cd] = dwt2(X,'haar');
%Call the function to calculate the threshold
T_CH = func_threshold(CH);
T1_CH = oracleshrink1(ca,T_CH);
T_CV = func_threshold(CV);
T1_CV = oracleshrink1(cv,T_CV);
T_CD = func_threshold(CD);
T1_CD = oracleshrink1(cd,T_CD);
HH = uint8(T1_CD);
HL = uint8(T1_CV);
LH = uint8(T1_CH);
% Call the function to perfom soft shrinkage
de_CH = soft1(CH,T1_CH);
de_CV = soft1(CV,T1_CV);
de_CD = soft1(CD,T1_CD);
%
%Two -level decomposition
[CA1,CH1,CV1,CD1] = dwt2(CA,'haar');
[ca1,ch1,cv1,cd1] = dwt2(ca,'haar');
%Call the function to calculate the threshold
T_CH1 = func_threshold(CH1);
T1_CH1 = oracleshrink1(ch1,T_CH1);
T_CV1 = func_threshold(CV1);
T1_CV1 = oracleshrink1(cv1,T_CV1);
T_CD1 = func_threshold(CD1);
T1_CD1 = oracleshrink1(cd1,T_CD1);
HH1 = uint8(T1_CD1);
HL1 = uint8(T1_CV1);
LH1 = uint8(T1_CH1);
% Call the function to perfom soft shrinkage
de_CH1 = soft1(CH1,T1_CH1);
de_CV1 = soft1(CV1,T1_CV1);
de_CD1 = soft1(CD1,T1_CD1);
%
%
%Reconstruction for soft shrinkage
X2 = idwt2(CA1,de_CH1,de_CV1,de_CD1,'haar');
X1 = idwt2(X2,de_CH,de_CV,de_CD,'haar');
SOFT_PSNR = PSNR(X,X1);
soft_X1 = uint8(X1);Image Denoising -threshold calculation using modified bivariate method
function [T,sigma1,sigma2] = model3_soft(CD,CH,CH1)
%function used to calculate the threshold and variance using modified
%bivariate model
%CD and CH : obtained after first stage wavelet decomposition
%CH1: obtained after second stage 2D-wavelet decomposition
sigman = (median(median(abs(CD))))/0.6745;
sigmay1 = 0;
sigmay2 = 0;
[m,n] = size(CD);
[m1,n1] = size(CH1);
%To calculate sigma1 value
for i =1:m
for j = 1:n
sigmay1 = sigmay1+((CH(i,j))^2);
end
end
sigmay1 = sqrt(2)*sigmay1/(m*n);
sigma1 = sqrt(max((((sigmay1))-((sigman)^2)),0));
if sigma1~=0
T = sqrt(3)*(sigman^2);
else
T = max(max(abs(CH)));
end
%To calculate sigma2 value
for i =1:m1
for j = 1:n1
sigmay2 = sigmay2+((CH1(i,j))^2);
end
end
sigmay2 = sqrt(2)*sigmay2/(m1*n1);
sigma2 = sqrt(max((((sigmay2))-((sigman)^2)),0));Image denoising - Bishrink method
% function [X1_denoise,DENOISE_PSNR] = Bivariate_soft(X1,Y)
clear all;
close all;
clc;
x = imread('lena.tif');
X =double(x);
[M,N] = size(X);
W =wgn(M,N,25);
Y = X+W;
[CA,CH,CV,CD] = dwt2(Y,'haar');
[CA1,CH1,CV1,CD1] = dwt2(CA,'haar');
[CA2,CH2,CV2,CD2] = dwt2(CA1,'haar');
[m,n] = size(CA);
[m2,n2] = size(CA1);
[m1,n1] = size(CA2);
%
k =1;
for i = 1:1:m2
for j = 1:1:n2
Y2_CH([2*i-1:2*i+k-1],[2*j-1:2*j+k-1])=CH1(i,j);
Y2_CV([2*i-1:2*i+k-1],[2*j-1:2*j+k-1]) =CV1(i,j);
Y2_CD([2*i-1:2*i+k-1],[2*j-1:2*j+k-1]) =CD1(i,j) ;
end
end
for i = 1:1:m1
for j = 1:1:n1
Y1_CH([2*i-1:2*i+k-1],[2*j-1:2*j+k-1])=CH2(i,j);
Y1_CV([2*i-1:2*i+k-1],[2*j-1:2*j+k-1]) =CV2(i,j);
Y1_CD([2*i-1:2*i+k-1],[2*j-1:2*j+k-1]) =CD2(i,j) ;
end
end
T1 = bishrink_threshold(CD,CH);
T2 = bishrink_threshold(CD,CV);
T3 = bishrink_threshold(CD,CD);
%
w1_ch = bishrink(CH,Y2_CH,T1);
w1_cv = bishrink(CV,Y2_CV,T2);
w1_cd = bishrink(CD,Y2_CD,T3);
T4 = bishrink_threshold(CD,CH);
T5 = bishrink_threshold(CD,CV);
T6 = bishrink_threshold(CD,CD);
%
w1_ch1 = bishrink(CH1,Y1_CH,T4);
w1_cv1 = bishrink(CV1,Y1_CV,T5);
w1_cd1 = bishrink(CD1,Y1_CD,T6);
%
X2 = idwt2(CA1,w1_ch1,w1_cv1,w1_cd1,'haar');
X1_denoise = idwt2(X2,w1_ch,w1_cv,w1_cd,'haar');
%modified estimate is used
T1 = bishrink_threshold1(CD,CH);
T2 = bishrink_threshold1(CD,CV);
T3 = bishrink_threshold1(CD,CD);
%
w1_ch = bishrink(CH,Y2_CH,T1);
w1_cv = bishrink(CV,Y2_CV,T2);
w1_cd = bishrink(CD,Y2_CD,T3);
T4 = bishrink_threshold1(CD,CH);
T5 = bishrink_threshold1(CD,CV);
T6 = bishrink_threshold1(CD,CD);
%
w1_ch1 = bishrink(CH1,Y1_CH,T4);
w1_cv1 = bishrink(CV1,Y1_CV,T5);
w1_cd1 = bishrink(CD1,Y1_CD,T6);
%
X4 = idwt2(CA1,w1_ch1,w1_cv1,w1_cd1,'haar');
X3_denoise = idwt2(X4,w1_ch,w1_cv,w1_cd,'haar');
noisy_PSNR = PSNR(X,Y)
% DENOISE_PSNR = PSNR(X,X1_denoise)
X1_PSNR = PSNR(X,X1_denoise)
X3_PSNR = PSNR(X,X3_denoise)
X1_denoise = uint8(X1_denoise);
X3_denoise = uint8(X3_denoise);
imshow(x)
figure;
imshow(uint8(Y))
figure;
imshow(X1_denoise)
figure;
imshow(X3_denoise)Image denoising - Threshold calculation for Bishrink method
function T = bishrink2(CD,CY)
sigman = (median(median(abs(CD))))/0.6745;
[m,n] = size(CY);
sigmay = 0;
for i =1:m
for j = 1:n
sigmay = sigmay+((CY(i,j))^2);
end
end
sigmay = sqrt(2)*sigmay/(m*n);
sigma = sqrt(max((((sigmay))-((sigman)^2)),0)); % Variance calculation
if sigma~=0
T = sqrt(3)*(sigman^2)/sigma; %Threshold
else
T = max(max(abs(CY)));
endImage denoising - Bishrink threshold calculation
function [w1] = bishrink1(y1,y2,T)
% Bivariate Shrinkage Function
% y1 - a noisy coefficient value
% y2 - the corresponding parent value
% T - threshold value
% w1 - the denoised coefficient
R = sqrt(abs(y1).^2 + abs(y2).^2);
R = R - T;
R = R .* (R > 0);
w1 = y1 .* R./(R+T);Image denoising -Bayeshrink threshold calculation
function T = bayeshrink(CD,CV)
[m,n] = size(CD);
sigma = (median(median(abs(CD))))/0.6745; %Standard deviation
var_sig = std_sig^2; % Variance
mean_sig = mean(mean(CH)); %mean value
sigmax = var_sig-(mean_sig^2);
sigmas = sqrt(max((sigmax-(sigma^2)),0));
%Calculation of threshold
if sigmas ~=0
T = ((sigma)^2)/(sigmas);
elseif sigmas == 0
T = max(max(abs(CV)));
endImage Denoising - Bayesshrink
%Using BAYESSHRINK
%subband dependent threshold
%Soft threshold
function [soft_X1,SOFT_PSNR] = Bayes_soft(X,Y)
%One -level decomposition
[CA,CH,CV,CD] = dwt2(Y,'haar');
%Call the function to calculate the threshold
CH =CH/1.2;
CV = CV/1.2;
CD = CD/1.2;
T1_CH = bayeshrink(CD,CH);
T1_CV = bayeshrink(CD,CV);
T1_CD = bayeshrink(CD,CD);
% Call the function to perfom soft shrinkage
de_CH = soft1(CH,T1_CH);
de_CV = soft1(CV,T1_CV);
de_CD = soft1(CD,T1_CD);
%Two -level decomposition
[CA1,CH1,CV1,CD1] = dwt2(CA,'haar');
CH1 = CH1/1.2;
CV1 = CV1/1.2;
CD1 = CD1/1.2;
%Call the function to calculate the threshold
T1_CH1 = bayeshrink(CD1,CH1);
T1_CV1 = bayeshrink(CD1,CV1);
T1_CD1 = bayeshrink(CD1,CD1);
% Call the function to perfom soft shrinkage
de_CH1 = soft1(CH1,T1_CH1);
de_CV1 = soft1(CV1,T1_CV1);
de_CD1 = soft1(CD1,T1_CD1);
%Reconstruction for soft shrinkage
X2 = idwt2(CA1,de_CH1,de_CV1,de_CD1,'haar');
X1 = idwt2(X2,de_CH,de_CV,de_CD,'haar');
SOFT_PSNR = PSNR(X,X1);
soft_X1 = uint8(X1);Phase changing Allpass IIR Filter
function [b,a] = allpass(order, Fc, Fs, Q)
% Returns allpass filter coefficients.
% Currently only 1st and 2nd orders are supported.
%
% Usage: [b,a] = ALLPASS(N, FC, FS, Q);
%
% N is the order of the allpass
% FC is the frequency a the 90deg phase shift point
% FS is the sampling rate
% Q is quality factor describing the slope of phase shift
%
% Author: sparafucile17 01/07/2004
if(order > 2)
error('Only 1st and 2nd orders are supported');
end
%Bilinear transform
g = tan(pi*(Fc/Fs));
if(order == 2)
d = 1/Q;
K = 1/(1 + d*g + g^2);
b0 = (1 - g*d + g^2) * K;
b1 = 2 * (g^2 - 1) * K;
b2 = 1;
a1 = b1;
a2 = b0;
else
b0 = (g-1)/(g+1);
b1 = 1;
b2 = 0;
a1 = b0;
a2 = 0;
end
b = [b0 b1 b2];
a = [1 a1 a2];Batch WAV file processing
%In this example we are going to apply a low-pass filter to all WAV files,
%but it could be a multitude of different "processing" methods. This is
%only used to illustrate the batch processing example.
Fs = 44100; %Hz
Fc = 1000; %Hz
[b,a] = butter(2, Fc/(Fs/2), 'low');
%These are the input and output directories relative to this M-file
input_directory = 'test_input_database\';
output_direcory = 'test_output\';
%What extensions are you looking for? In our case, we want to batch
%process audio files that are store in the uncompressed *.WAV format
extension = '*.wav';
%Get the files
files=dir([input_directory '*.wav']);
N_files=numel(files);
%Loop through one file at a time
for i=1:N_files
%This is a stereo file and for this example,
%I only care about channel number 1
x = wavread([input_directory files(i).name ]);
x = x(:,1);
%Process the data by applying our filter
y = filter(b,a,x);
%Output the data as a unique filename based on input
wavwrite(y, Fs, [output_directory 'processed' files(i).name]);
disp(['Processed File: ' input_directory files(i).name 'as: ' ...
output_directory 'processed' files(i).name]);
end






