Sir how to multiply a square wave and sinewave and generate power spectrum from the output of those singnal

2 次查看(过去 30 天)
sir i tried it i have that code
this is my code sir please correct my code sir i am getting errors regarding matrix
t=0:1:40;
f=500;
fs=8000;
x=sin(2*pi*f/fs*t);
figure(1);
stem(t,x,'r');
figure(2);
stem(t*1/fs*1000,x,'r');
hold on;
plot(t*1/fs*1000,x);
fftLength = 1024;
sigLength = length(x);
win = rectwin(sigLength);
y=fft(x.*win,fftLength);
figLength=fftLength/2+1;
plot([1:figLength]*fs/(2*figLength),abs(y(1:figLength)));
plot([1:figLength]*fs/(2*figLength),20*log10(abs(y(1:figLength))));
  3 个评论

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2017-6-8
Change
y=fft(x.*win,fftLength);
to
y=fft(x(:).*win(:), fftLength);
If you had "Please copy the entire error message -- everything in red." when requested then this could have been solved two weeks ago. The code you posted does not give an error in R2016b or later; if you had posted the error message then I would have immediately known that you are running R2016a or earlier and would have been able to suggest the solution.
"how to create an own fft function in matlab sir please help me in this case"
There are numerous posts in which people have implemented discrete fft. Search for them.

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by