njithjw的个人空间 https://blog.eetop.cn/505866 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

单音信号及其频谱

已有 5534 次阅读| 2012-3-12 23:22 |个人分类:matlab

clear
close all

f=100;
fs=1000;
Ts=1/fs;
time=5.0;              % freq, sampling interval, time
t=Ts:Ts:time;                            % define a time vector
w0=cos(2*pi*f*t);                         % define the sinusoid
w1=sin(2*pi*f*t);
w2=exp(j*(2*pi*f*t));
w3=exp(-j*(2*pi*f*t));
figure(1)
plot_spec(w0,fs)
figure(2)
plot_spec(w1,fs)
figure(3)
plot_spec(w2,fs)
figure(4)
plot_spec(w3,fs)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function plot_spec(data,fs)

N=length(data);                             % length of the signal x
Ts=1/fs;
t=Ts*(1:N);                                 % define a time vector
%ssf=((-N+1)/2:N/2)/(Ts*N);                  % frequency vector
ssf=(-N/2:N/2-1)/(Ts*N);                  % frequency vector
fx=fft(data(1:N));                          % do DFT/FFT
fxs=fftshift(fx);                           % shift it for plotting

data_db=10*log10(abs(fxs));                 %10*log10? 20*log10?

plot(ssf,data_db)                           % plot magnitude spectrum
grid on

xlabel('frequency');
ylabel('magnitude')    % label the axes


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 2

    粉丝
  • 0

    好友
  • 0

    获赞
  • 17

    评论
  • 3512

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-10 07:12 , Processed in 0.015275 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部