M=imread('dl011.jpg') %讀取MATLAB中的名為cameraman的圖像
subplot(3,3,1)
imshow(M) %顯示原始圖像
title('original')
P1=imnoise(M,'gaussian',0.02) %加入高斯躁聲
subplot(3,3,2)
imshow(P1) %加入高斯躁聲後顯示圖像
title('gaussian noise');
P2=imnoise(M,'salt & pepper',0.02) %加入椒鹽躁聲
subplot(3,3,3)
imshow(P2) %%加入椒鹽躁聲後顯示圖像
title('salt & pepper noise');
g=medfilt2(P1) %對高斯躁聲中值濾波
subplot(3,3,5)
imshow(g)
title('medfilter gaussian')
h=medfilt2(P2) %對椒鹽躁聲中值濾波
subplot(3,3,6)
imshow(h)
title('medfilter salt & pepper noise')
l=[1 1 1 %對高斯躁聲算術均值濾波
1 1 1
1 1 1];
l=l/9;
k=conv2(P1,l)
subplot(3,3,8)
imshow(k,[])
title('arithmeticfilter gaussian')
%對椒鹽躁聲算術均值濾波
d=conv2(P2,l)
subplot(3,3,9)
imshow(d,[])
title('arithmeticfilter salt & pepper noise')
我自己給你寫的幾個簡單加雜訊去雜訊的函數使用.
『貳』 求一個簡單的matlab程序代碼,只要符合要求即可
1、題目:
把1-10的整數,先判斷是否為偶數,並計算它們的和,最後做一下驗證
2、程序:內
clc;clear;
sum0=0;
for i=1:10 %循環
if(mod(i,2)==0)%分支容
sum0=sum0+i;
end
end
%檢測
test_data=[2:2:10];%順序
test=sum(test_data);
[sum0 test]
3、運行結果:
ans =
30 30
『叄』 求matlab代碼,實現如下功能
這個比較簡單 其實就是基於matlab的語音信號濾波處理
這是我剛做的,運行是正確的!ly是語音信號的名字,截圖自己運行就會有!
原語音信號程序
figure(1);
[y,fs,nbits]=wavread ('ly');
sound(y,fs,nbits); %回放語音信號
n = length (y) ; %求出語音信號的長度
Y=fft(y,n); %傅里葉變換
subplot(2,1,1);plot(y);title('原始信號波形');
subplot(2,1,2);plot(abs(Y));title('原始信號頻譜')
加噪語音信號程序
figure(2);
[y,fs,nbits]=wavread ('ly');
n = length (y) ; %求出語音信號的長度
t=[0:1/8000:2 zeros(1,23520-1)]';
noise=0.04*sin(10000*pi*t);%sin函數產生雜訊
s=y+noise; %語音信號加入雜訊
sound(s);
subplot(2,1,1);plot(s);title('加噪語音信號的時域波形');
S=fft(s); %傅里葉變換
subplot(2,1,2);plot(abs(S));title('加噪語音信號的頻域波形')
濾波後的信號程序
Ft=8000;
Fp=1000;
Fs=1200;
wp=2*pi*Fp/Ft;
ws=2*pi*Fs/Ft;
fp=2*Ft*tan(wp/2);
fs=2*Fs*tan(wp/2);
[n11,wn11]=buttord(wp,ws,1,50,'s'); %求低通濾波器的階數和截止頻率
[b11,a11]=butter(n11,wn11,'s'); %求S域的頻率響應的參數
[num11,den11]=bilinear(b11,a11,0.5); %利用雙線性變換實現頻率響應S域到Z域的變換
[y,fs,nbits]=wavread ('ly');
n = length (y) ; %求出語音信號的長度
t=[0:1/8000:2 zeros(1,23520-1)]';
noise=0.04*sin(10000*pi*t);%sin函數產生雜訊
s=y+noise; %語音信號加入雜訊
z11=filter(num11,den11,s);
sound(z11);
m11=fft(z11); %求濾波後的信號
figure(3);
subplot(2,1,1);plot(z11);title('濾波後的信號波形');
subplot(2,1,2);plot(abs(m11),'r');title('濾波後信號的頻譜');