Obtaining correct frequency and normalisation using convolution function

26 ビュー (過去 30 日間)
Lorcan Conlon
Lorcan Conlon 2021 年 4 月 30 日
編集済み: Matt J 2021 年 4 月 30 日
I wish to better understand the matlab convolution function, conv. My signal is the product of two sin waves of different frequencies in the time domain and so this gives two more sin waves at the sum and difference frequencies. If I directly take the Fourier transform of my signal I see two peaks in the frequency domain as expected. However when I take the convolution of the two individual sin waves I do not get the same result as expected. I can still see the two peaks expected, but they are much more spaced. Is there some way to shift the convolution so it is at the correct frequency?
Here is a simple code to show what I have been trying
```
time=linspace(0,1,10000);
sig=sin(2*pi*10.*time)*100;
sig2=sin(2*pi*20.*time)*100;
sigT=sig.*sig2;
plot(sigT)
FTsig=fft(sig);
FTsig2=fft(sig2);
expFTtot=median(diff(time))*conv(FTsig,FTsig2,'full');
expFTtot2=conv(FTsig2,FTsig,'full');
ft=fft(sigT);
figure(2)
loglog(abs(ft(1:end/2)),'-.')
hold on
loglog(abs(expFTtot(1:end/2)))
loglog(abs(expFTtot2(1:end/2)))
```

採用された回答

Matt J
Matt J 2021 年 4 月 30 日
編集済み: Matt J 2021 年 4 月 30 日
It's usually a good idea to do things in a certain order. First, plan the sampling axes both for time and frequency. Note that because your final spectrum will have peaks at 10 Hz and 30 Hz, we want a frequency sampling interval dF that divides evenly into both of these,
N=10000;
dF=0.1; %frequency sampling interval
dT=1/N/dF; %time sampling interval
Axis = (0:N-1)-ceil((N-1)/2);
tAxis=Axis*dT; %time axis
fAxis=Axis*dF; %frequency axis
Next, we sample,
sig1=sin(2*pi*10.*tAxis)*100; %Sample the signals
sig2=sin(2*pi*20.*tAxis)*100;
sigT=sig1.*sig2;
Next, we do the Fourier analysis,
Fourier=@(z) ifftshift(fft( fftshift(z) ))*dT; %Fourier domain
FTsig1=Fourier(sig1);
FTsig2=Fourier(sig2);
FTsigT=Fourier(sigT);
expFTtot=conv(FTsig1,FTsig2,'same')*dF; %check with convolution
And finally plot. We can see below that there is nice agreement and the peaks are at the appropriate locations.
semilogy(fAxis,abs(FTsigT),'--b', fAxis, abs(expFTtot),'r:') %plot
legend('FFT','Convolution')
xlabel 'Frequency (Hz)'
xlim([-50,50])

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by