1.
Fs=1000;
N=1000;
n=0:N-1;
t=n/Fs;
x=sin(2*pi*50*t)+sin(2*pi*120*t)+rand(1,N);
y=abs(fft(x,N));
f=n*Fs/N;
subplot(211);
plot(f,y);
2.
fs=1*10^6;
t=0:1/fs:255/fs;
f1=200*10^3;
f2=400*10^3;
s1=sin(2*pi*f1*t);
s2=sin(2*pi*f2*t);
s=s1+s2;
N=256;
a=(abs(fft(s,N)));
fn=0:N-1;
fn=fn/N*fs;
stem(fn,a);
3.
hn=st
f1=200; %200Hz
f2=800; %800Hz
fs=2000; %2000Hz
t=0:1/fs:511/fs;
s=sin(2*pi*f1*t)+sin(2*pi*f2*t); %叠加信号
N1=512;
a=abs(fft(s,N1));
y=filter(hn,1,s);
xh=0:(fs/length(a)):fs/2;
subplot(311)
plot(t,s)
subplot(312)
plot(t,y);
subplot(313)
plot(xh,a(1:length(xh)));
s=s/max(abs(s));
da=round(s*2047);
N=12;
fid=fopen('d:\data.txt','w');
for i=1:length(da)
da1=dec2bin(da(i)+(da(i)<0)*2^N,N)
for j=1:N
if da1(j)=='1'
tb=1;
else
tb=0;
end
fprintf(fid,'%d',tb);
end
fprintf(fid,'\r\n');
end
fprintf(fid,':');
fclose(fid);