Need help using fft to create a real spectre

1 visualizzazione (ultimi 30 giorni)
Peter Cristian
Peter Cristian il 5 Apr 2022
Risposto: Chandra il 8 Apr 2022
Hi, I'm new to using MatLab, and in an exercise I have a problem. I have this code that has 2 signals, the modulated signal, and the parasitic signal. In the end I have to figure the spectrum without the imaginary frequencies of the composite signals.
ts=12000; ta=1/12000; T=0.02;
t=0:ta:T-ta;
tt=0:ta:T*8-ta;
A1=0.4; A2=0.3;
f1=100; f2=330;
x1=A1*sin(2*pi*f1*t);
x2=A2*sin(2*pi*f2*t);
s=[x1,x2,x1,x1,x2,x2,x1,x2];
y=sawtooth(2*pi*200*tt);
y=(y+1)/10;
w=s+y;
subplot(3,1,1);
sampleTimeMs = linspace(0,160,length(s));
plot(sampleTimeMs,s);
title("Modulated Signal");
xlabel("t[ms]");
ylabel("A[V]");
yticks([-0.4 -0.3 0.3 0.4]);
grid on;
subplot(3,1,2);
sampleTimeMs = linspace(0,160,length(y));
plot(sampleTimeMs, y)
title("Parasitic Signal");
xlabel("t[ms]");
ylabel("A[V]");
yticks([0 0.2]);
grid on;
subplot(3,1,3);
sampleTimeMs = linspace(0,160,length(w));
plot(sampleTimeMs, w)
title("Added Signals");
xlabel("t[ms]");
ylabel("A[V]");
yticks([-0.4 -0.3 0.3 0.4 0.5]);
grid on;
figure;
Y=abs(fft(w));
plot(t,Y)
.I know that i should use half of the sampling frequency(6000), but i dont know how or where to put that value.

Risposte (1)

Chandra
Chandra il 8 Apr 2022
Hi,
FFT for any signal has real and imaginary party, if input signal is even then fft is real and for odd signal fft is imaginary, so for composite signals fft has both real and imaginary signals
To observe real part of fft, use
>>Y=real(fft(w));
To observe imaginary part of fft, use
>>Y=imag(fft(w));
To observe both use abs to fft
>>Y=abs(fft(w));
To change the sampling frequency in the code change ta
ta=1/6000
Use the following to plot fft
t1 = linspace(-pi,pi,length(s)); % frequency spectrum is either -pi to pi or 0 to 2*pi
Y=real(fft(w));
Refer real, imaginary and abs

Categorie

Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by