Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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 Kommentare
Naga Sai
Naga Sai am 22 Mai 2017
how to create an own fft function in matlab sir please help me in this case

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 8 Jun. 2017
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.

Community Treasure Hunt

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

Start Hunting!

Translated by