i want to generate 1khz freq with hanning , the code is provided , tell me the input values.

2 views (last 30 days)
clear all;
signal_freq1=input('center-frequency of the signall in Hz/n');
num_cycles1=input('\n number of cycles1\n');
del_t1=input('\n Time increment1\n');
total_time1=input('\n total signal duration in secl\n');
offset_time1=input('\n Offset time_ actual starting time for signal1 \n');
signal_freq2=input('center-frequency of the signal2 in Hz\n');
num_cycles2=input('\n number of cycles2\n');
del_t2=input('\n Time increament2\n');
total_time2=input('\n total signal duration in sec2\n');
offset_time2=input('\n offset time- actual starting time for signal2 \n');
%-------------------------------------------------------------------------------%
signal_offset=round(offset_time1/del_t1);
hanning_duration1= (1/signal_freq1)*num_cycles1;
hanning_width1= round(hanning_duration1/del_t1);
signal_lengthl=round(total_time1/del_t1);
if signal_length1 < signal_offset1+hanning_width1
signal_length= signal_offset+hanning_width1;
end
%-----------------------------------------------------------------------------%
hanning_window1=hann(round(hanning_duration1/del_t1));
continuous_cosinel1=cos(2*pi*signal_freq1*(0:length(hanning_window1)-1)*del_t1);
time1=0:del_t1:del_t1*signal_length1;
output_signal1=zeros(1,length(time1));
output_signal1(signal_offset1+1:signal_offset1+round(hanning_duration1/del_t1))=hanning_window1.*continuous_cosinel';
%output_signal=hanning_window.*continuous_cosine';
%----------------------------------------------------------------------------%
figure(1),plot(time,output_signal1);
%--------------------------------------------------------------------------%

Answers (1)

Dev
Dev on 19 Aug 2025
There are two signals in the code provided in the question. I am assuming here that only the first signal is used and the second one is unused. Accordingly, I have mentioned some reference input values for the first signal, and these values can be referred for the second signal too (if used).
  • Center-frequency of signal1 in Hz-
signal_freq1 = 1000 % since we want to generate 1 khz frequency
  • num_cycles1 = 5 % since 5 is a common cycle number
  • Time increment1 (del_t1)-
For audio, a common sampling rate is 44100 Hz, so-
del_t1 = 1/44100
  • Total signal duration (total_time1)-
This must be at least as long as your window, ie, Window duration = num_cycles1 / signal_freq1
For 5 cycles at 1000 Hz:
total_time1 = 5 / 1000 = 0.005 sec
total_time1 = 0.01 (10 ms - approx)
  • Offset time-
If you want the signal to start at the beginning:
offset_time1 = 0
We can set the second signal parameters to 0 (if unused). On using the above input values, we can generate the following 1 khz frequency, as seen in the screenshot below.
I hope the above response answers the question.

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!