I want to write a code in which i could generate the hanning window with any frequency entered by the user
5 次查看(过去 30 天)
显示 更早的评论
I want to develop a code in which if i put the frequency in khz then repective hanning window or hanning wave could be genrated and corresponding wave plot should also generate the excel file.
0 个评论
回答(1 个)
Pratheek
2023-3-27
Hi Sanket Shivaji
You can use the below code to generate Hanning Window for a input wave form. You can go through the comments to understand the code.
f_khz = input('Enter the frequency in kHz: '); % Getting the frequency in kHz
Fs = 10 * f_khz; % Use Sampling frequency as 10 times that of input frequency
duration = 1; % Duration of the waveform in seconds
N = Fs * duration; % Number of samples
t = linspace(0, duration, N); % Generating the time vector
x = sin(2 * pi * f_khz * t); % Generating the waveform
w = hann(N); % Generating the Hanning window
x_w = x .* w'; % Applying Hanning window to waveform
% Ploting the waveform
subplot(2,1,1);
plot(t, x);
title('Original Waveform');
xlabel('Time (s)');
ylabel('Amplitude');
% Plotting the Hanning window
subplot(2,1,2);
plot(t, x_w);
title('Waveform with Hanning Window');
xlabel('Time (s)');
ylabel('Amplitude');
% Save the waveform data to an Excel file
filename = sprintf('waveform_%dkHz.xlsx', f_khz);
xlswrite(filename, x_w', 'Sheet1');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Feature Extraction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!