Error using plot Vectors must be the same length
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
% Define time range
t = -0.2:0.0001:0.2;
% Calculate signal s(t)
s = cos(2*pi*10*t).*cos(27*pi*200*t);
% Plot s(t)
figure(1);
plot(t, s);
xlabel('Time (s)');
ylabel('Amplitude');
title('AM Modulated Signal s(t)');
% Calculate Fourier transform of s(t)
Fs = 10000; % Sampling frequency
S = fftshift(fft(s))/length(s);
size(S)
f = (-Fs/2:Fs/2-1)/length(s);
size(f)
% Plot two-sided spectrum of S(f)
figure(2);
plot(f, abs(S));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Two-Sided Spectrum of S(f)');
0 comentarios
Respuestas (1)
Torsten
el 22 de Mzo. de 2023
Movida: Matt J
el 22 de Mzo. de 2023
As you can see above, S and f have a different number of elements. So they cannot be plotted against each other.
2 comentarios
Matt J
el 22 de Mzo. de 2023
As for S.f, they have the same number of elements as shown in the code.
It is puzzling that you think so. Running the code clearly shows that length(S)=4001 while length(f)=10000
% Define time range
t = -0.2:0.0001:0.2;
% Calculate signal s(t)
s = cos(2*pi*10*t).*cos(27*pi*200*t);
% Calculate Fourier transform of s(t)
Fs = 10000; % Sampling frequency
S = fftshift(fft(s))/length(s);
f = (-Fs/2:Fs/2-1)/length(s);
length(S)
length(f)
Ver también
Categorías
Más información sobre Discrete Fourier and Cosine Transforms en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!